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 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 22 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 23 | import android.Manifest.permission; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 24 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 26 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 27 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 28 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 31 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 32 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 33 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 34 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 36 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.Uri; |
| 38 | import android.os.AsyncResult; |
| 39 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 40 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
| 42 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.Looper; |
| 45 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 46 | import android.os.Messenger; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 47 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 48 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 49 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 50 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 52 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 53 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 55 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 56 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 57 | import android.preference.PreferenceManager; |
Naina Nalluri | 1264a9f | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 58 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 59 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 60 | import android.provider.Telephony; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 61 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 62 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 63 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 64 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 65 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 66 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 67 | import android.telephony.CellInfoGsm; |
| 68 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 69 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 70 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 71 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 72 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 73 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 74 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 75 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 76 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 77 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 78 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 79 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 80 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 81 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 82 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 83 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 84 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 85 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 86 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 87 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 88 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 89 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 90 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 91 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 92 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 93 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 94 | import android.telephony.data.ApnSetting; |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 95 | import android.telephony.data.ApnSetting.ApnType; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 96 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 97 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 98 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 99 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 100 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 101 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 102 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 103 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 104 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 106 | import android.telephony.ims.feature.MmTelFeature; |
| 107 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 108 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 109 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 110 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 111 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 112 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 113 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 114 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 115 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 116 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 117 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Jordan Liu | a39e6c1 | 2020-03-04 13:59:23 -0800 | [diff] [blame] | 118 | import com.android.internal.annotations.VisibleForTesting; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 122 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 126 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 128 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 132 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.ServiceStateTracker; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.SmsApplication; |
| 145 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.ims.ImsResolver; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.uicc.IccIoResult; |
| 156 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 164 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 165 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 166 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 167 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 168 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 169 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 170 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 171 | import java.io.FileDescriptor; |
| 172 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 173 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 174 | import java.util.Arrays; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 175 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 176 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 177 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 178 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 179 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 180 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 181 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 182 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 183 | |
| 184 | /** |
| 185 | * Implementation of the ITelephony interface. |
| 186 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 187 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 188 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 189 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 190 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 191 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | |
| 193 | // Message codes used with mMainThreadHandler |
| 194 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 195 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 196 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 197 | private static final int CMD_OPEN_CHANNEL = 9; |
| 198 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 199 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 200 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 201 | private static final int CMD_NV_READ_ITEM = 13; |
| 202 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 203 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 204 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 205 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 206 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 207 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 208 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 209 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 210 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 211 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 212 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 213 | private static final int CMD_SEND_ENVELOPE = 25; |
| 214 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 215 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 216 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 217 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 218 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 219 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 220 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 221 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 222 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 223 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 224 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 225 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 226 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 227 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 228 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 229 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 230 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 231 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 232 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 233 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 234 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 235 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 236 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 237 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 238 | private static final int CMD_SWITCH_SLOTS = 50; |
| 239 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 240 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 241 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 242 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 243 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 244 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 245 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 246 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 247 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 248 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 249 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 250 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 251 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 252 | private static final int CMD_MODEM_REBOOT = 64; |
| 253 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 254 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 255 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 256 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 257 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 258 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 259 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
Naina Nalluri | 1264a9f | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 260 | private static final int CMD_ERASE_MODEM_CONFIG = 72; |
| 261 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 73; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 262 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 263 | // Parameters of select command. |
| 264 | private static final int SELECT_COMMAND = 0xA4; |
| 265 | private static final int SELECT_P1 = 0x04; |
| 266 | private static final int SELECT_P2 = 0; |
| 267 | private static final int SELECT_P3 = 0x10; |
| 268 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 269 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 270 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 271 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 272 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 273 | /** The singleton instance. */ |
| 274 | private static PhoneInterfaceManager sInstance; |
| 275 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 276 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 277 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 278 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 279 | private AppOpsManager mAppOps; |
| 280 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 281 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 282 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 283 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 284 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 285 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 286 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 287 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 288 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 289 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 290 | // String to store multi SIM allowed |
| 291 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 292 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 293 | // The AID of ISD-R. |
| 294 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 295 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 296 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 297 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 298 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 299 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 300 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 301 | /** |
Naina Nalluri | 1264a9f | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 302 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 303 | */ |
| 304 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 305 | "reset_network_erase_modem_config_enabled"; |
| 306 | |
| 307 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 308 | * A request object to use for transmitting data to an ICC. |
| 309 | */ |
| 310 | private static final class IccAPDUArgument { |
| 311 | public int channel, cla, command, p1, p2, p3; |
| 312 | public String data; |
| 313 | |
| 314 | public IccAPDUArgument(int channel, int cla, int command, |
| 315 | int p1, int p2, int p3, String data) { |
| 316 | this.channel = channel; |
| 317 | this.cla = cla; |
| 318 | this.command = command; |
| 319 | this.p1 = p1; |
| 320 | this.p2 = p2; |
| 321 | this.p3 = p3; |
| 322 | this.data = data; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 327 | * A request object to use for transmitting data to an ICC. |
| 328 | */ |
| 329 | private static final class ManualNetworkSelectionArgument { |
| 330 | public OperatorInfo operatorInfo; |
| 331 | public boolean persistSelection; |
| 332 | |
| 333 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 334 | this.operatorInfo = operatorInfo; |
| 335 | this.persistSelection = persistSelection; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 340 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 341 | * request after sending. The main thread will notify the request when it is complete. |
| 342 | */ |
| 343 | private static final class MainThreadRequest { |
| 344 | /** The argument to use for the request */ |
| 345 | public Object argument; |
| 346 | /** The result of the request that is run on the main thread */ |
| 347 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 348 | // The subscriber id that this request applies to. Defaults to |
| 349 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 350 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 351 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 352 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 353 | public Phone phone; |
| 354 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 355 | public WorkSource workSource; |
| 356 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 357 | public MainThreadRequest(Object argument) { |
| 358 | this.argument = argument; |
| 359 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 360 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 361 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 362 | this.argument = argument; |
| 363 | if (phone != null) { |
| 364 | this.phone = phone; |
| 365 | } |
| 366 | this.workSource = workSource; |
| 367 | } |
| 368 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 369 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 370 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 371 | if (subId != null) { |
| 372 | this.subId = subId; |
| 373 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 374 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 375 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 378 | private static final class IncomingThirdPartyCallArgs { |
| 379 | public final ComponentName component; |
| 380 | public final String callId; |
| 381 | public final String callerDisplayName; |
| 382 | |
| 383 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 384 | String callerDisplayName) { |
| 385 | this.component = component; |
| 386 | this.callId = callId; |
| 387 | this.callerDisplayName = callerDisplayName; |
| 388 | } |
| 389 | } |
| 390 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 391 | /** |
| 392 | * A handler that processes messages on the main thread in the phone process. Since many |
| 393 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 394 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 395 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 396 | * on, which will be notified when the operation completes and will contain the result of the |
| 397 | * request. |
| 398 | * |
| 399 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 400 | * note that request.result must be set to something non-null for the calling thread to |
| 401 | * unblock. |
| 402 | */ |
| 403 | private final class MainThreadHandler extends Handler { |
| 404 | @Override |
| 405 | public void handleMessage(Message msg) { |
| 406 | MainThreadRequest request; |
| 407 | Message onCompleted; |
| 408 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 409 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 410 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 411 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 412 | |
| 413 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 414 | case CMD_HANDLE_USSD_REQUEST: { |
| 415 | request = (MainThreadRequest) msg.obj; |
| 416 | final Phone phone = getPhoneFromRequest(request); |
| 417 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 418 | String ussdRequest = ussdObject.first; |
| 419 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 420 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 421 | if (!isUssdApiAllowed(request.subId)) { |
| 422 | // Carrier does not support use of this API, return failure. |
| 423 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 424 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 425 | Bundle returnData = new Bundle(); |
| 426 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 427 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 428 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 429 | request.result = true; |
| 430 | notifyRequester(request); |
| 431 | return; |
| 432 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 433 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 434 | try { |
| 435 | request.result = phone != null |
| 436 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 437 | } catch (CallStateException cse) { |
| 438 | request.result = false; |
| 439 | } |
| 440 | // Wake up the requesting thread |
| 441 | notifyRequester(request); |
| 442 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 445 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 446 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 447 | final Phone phone = getPhoneFromRequest(request); |
| 448 | request.result = phone != null ? |
| 449 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 450 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 451 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 452 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 453 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 454 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 455 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 456 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 457 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 458 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 459 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 460 | if (uiccCard == null) { |
| 461 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 462 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 463 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 464 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 465 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 466 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 467 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 468 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 469 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 470 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 471 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 472 | break; |
| 473 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 474 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 475 | ar = (AsyncResult) msg.obj; |
| 476 | request = (MainThreadRequest) ar.userObj; |
| 477 | if (ar.exception == null && ar.result != null) { |
| 478 | request.result = ar.result; |
| 479 | } else { |
| 480 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 481 | if (ar.result == null) { |
| 482 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 483 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 484 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 485 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 486 | } else { |
| 487 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 488 | } |
| 489 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 490 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 491 | break; |
| 492 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 493 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 494 | request = (MainThreadRequest) msg.obj; |
| 495 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 496 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 497 | if (uiccCard == null) { |
| 498 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 499 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 500 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 501 | } else { |
| 502 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 503 | request); |
| 504 | uiccCard.iccTransmitApduBasicChannel( |
| 505 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 506 | iccArgument.p3, iccArgument.data, onCompleted); |
| 507 | } |
| 508 | break; |
| 509 | |
| 510 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 511 | ar = (AsyncResult) msg.obj; |
| 512 | request = (MainThreadRequest) ar.userObj; |
| 513 | if (ar.exception == null && ar.result != null) { |
| 514 | request.result = ar.result; |
| 515 | } else { |
| 516 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 517 | if (ar.result == null) { |
| 518 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 519 | } else if (ar.exception instanceof CommandException) { |
| 520 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 521 | ar.exception); |
| 522 | } else { |
| 523 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 524 | } |
| 525 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 526 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 527 | break; |
| 528 | |
| 529 | case CMD_EXCHANGE_SIM_IO: |
| 530 | request = (MainThreadRequest) msg.obj; |
| 531 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 532 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 533 | if (uiccCard == null) { |
| 534 | loge("iccExchangeSimIO: No UICC"); |
| 535 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 536 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 537 | } else { |
| 538 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 539 | request); |
| 540 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 541 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 542 | iccArgument.data, onCompleted); |
| 543 | } |
| 544 | break; |
| 545 | |
| 546 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 547 | ar = (AsyncResult) msg.obj; |
| 548 | request = (MainThreadRequest) ar.userObj; |
| 549 | if (ar.exception == null && ar.result != null) { |
| 550 | request.result = ar.result; |
| 551 | } else { |
| 552 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 553 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 554 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 555 | break; |
| 556 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 557 | case CMD_SEND_ENVELOPE: |
| 558 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 559 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 560 | if (uiccCard == null) { |
| 561 | loge("sendEnvelopeWithStatus: No UICC"); |
| 562 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 563 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 564 | } else { |
| 565 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 566 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 567 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 568 | break; |
| 569 | |
| 570 | case EVENT_SEND_ENVELOPE_DONE: |
| 571 | ar = (AsyncResult) msg.obj; |
| 572 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 573 | if (ar.exception == null && ar.result != null) { |
| 574 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 575 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 576 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 577 | if (ar.result == null) { |
| 578 | loge("sendEnvelopeWithStatus: Empty response"); |
| 579 | } else if (ar.exception instanceof CommandException) { |
| 580 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 581 | ar.exception); |
| 582 | } else { |
| 583 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 584 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 585 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 586 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 587 | break; |
| 588 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 589 | case CMD_OPEN_CHANNEL: |
| 590 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 591 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 592 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 593 | if (uiccCard == null) { |
| 594 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 595 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 596 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 597 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 598 | } else { |
| 599 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 600 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 601 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 602 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 603 | break; |
| 604 | |
| 605 | case EVENT_OPEN_CHANNEL_DONE: |
| 606 | ar = (AsyncResult) msg.obj; |
| 607 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 608 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 609 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 610 | int[] result = (int[]) ar.result; |
| 611 | int channelId = result[0]; |
| 612 | byte[] selectResponse = null; |
| 613 | if (result.length > 1) { |
| 614 | selectResponse = new byte[result.length - 1]; |
| 615 | for (int i = 1; i < result.length; ++i) { |
| 616 | selectResponse[i - 1] = (byte) result[i]; |
| 617 | } |
| 618 | } |
| 619 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 620 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 621 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 622 | if (ar.result == null) { |
| 623 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 624 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 625 | if (ar.exception != null) { |
| 626 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 627 | } |
| 628 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 629 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 630 | if (ar.exception instanceof CommandException) { |
| 631 | CommandException.Error error = |
| 632 | ((CommandException) (ar.exception)).getCommandError(); |
| 633 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 634 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 635 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 636 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 640 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 641 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 642 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 643 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | break; |
| 645 | |
| 646 | case CMD_CLOSE_CHANNEL: |
| 647 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 648 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 649 | if (uiccCard == null) { |
| 650 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 651 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 652 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 653 | } else { |
| 654 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 655 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 656 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | break; |
| 658 | |
| 659 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 660 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 661 | break; |
| 662 | |
| 663 | case CMD_NV_READ_ITEM: |
| 664 | request = (MainThreadRequest) msg.obj; |
| 665 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 666 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 667 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 668 | break; |
| 669 | |
| 670 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 671 | ar = (AsyncResult) msg.obj; |
| 672 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 673 | if (ar.exception == null && ar.result != null) { |
| 674 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 675 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 676 | request.result = ""; |
| 677 | if (ar.result == null) { |
| 678 | loge("nvReadItem: Empty response"); |
| 679 | } else if (ar.exception instanceof CommandException) { |
| 680 | loge("nvReadItem: CommandException: " + |
| 681 | ar.exception); |
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 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 684 | } |
| 685 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 686 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | break; |
| 688 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 689 | case CMD_NV_WRITE_ITEM: |
| 690 | request = (MainThreadRequest) msg.obj; |
| 691 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 692 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 693 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 694 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 695 | break; |
| 696 | |
| 697 | case EVENT_NV_WRITE_ITEM_DONE: |
| 698 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 699 | break; |
| 700 | |
| 701 | case CMD_NV_WRITE_CDMA_PRL: |
| 702 | request = (MainThreadRequest) msg.obj; |
| 703 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 704 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 705 | break; |
| 706 | |
| 707 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 708 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 709 | break; |
| 710 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 711 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 712 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 713 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 714 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 715 | break; |
| 716 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 717 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 718 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 719 | break; |
| 720 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 721 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 722 | request = (MainThreadRequest) msg.obj; |
| 723 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 724 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 725 | break; |
| 726 | |
| 727 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 728 | ar = (AsyncResult) msg.obj; |
| 729 | request = (MainThreadRequest) ar.userObj; |
| 730 | if (ar.exception == null && ar.result != null) { |
| 731 | request.result = ar.result; // Integer |
| 732 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 733 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 734 | if (ar.result == null) { |
| 735 | loge("getPreferredNetworkType: Empty response"); |
| 736 | } else if (ar.exception instanceof CommandException) { |
| 737 | loge("getPreferredNetworkType: CommandException: " + |
| 738 | ar.exception); |
| 739 | } else { |
| 740 | loge("getPreferredNetworkType: Unknown exception"); |
| 741 | } |
| 742 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 743 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 747 | request = (MainThreadRequest) msg.obj; |
| 748 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 749 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 750 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 751 | break; |
| 752 | |
| 753 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 754 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 755 | break; |
| 756 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 757 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 758 | request = (MainThreadRequest)msg.obj; |
| 759 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 760 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 761 | break; |
| 762 | |
| 763 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 764 | ar = (AsyncResult)msg.obj; |
| 765 | request = (MainThreadRequest)ar.userObj; |
| 766 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 767 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 768 | break; |
| 769 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 770 | case CMD_SET_VOICEMAIL_NUMBER: |
| 771 | request = (MainThreadRequest) msg.obj; |
| 772 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 773 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 774 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 775 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 776 | break; |
| 777 | |
| 778 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 779 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 780 | break; |
| 781 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 782 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 783 | request = (MainThreadRequest) msg.obj; |
| 784 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 785 | request); |
| 786 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 787 | break; |
| 788 | |
| 789 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 790 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 791 | break; |
| 792 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 793 | case CMD_PERFORM_NETWORK_SCAN: |
| 794 | request = (MainThreadRequest) msg.obj; |
| 795 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 796 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 797 | break; |
| 798 | |
| 799 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 800 | ar = (AsyncResult) msg.obj; |
| 801 | request = (MainThreadRequest) ar.userObj; |
| 802 | CellNetworkScanResult cellScanResult; |
| 803 | if (ar.exception == null && ar.result != null) { |
| 804 | cellScanResult = new CellNetworkScanResult( |
| 805 | CellNetworkScanResult.STATUS_SUCCESS, |
| 806 | (List<OperatorInfo>) ar.result); |
| 807 | } else { |
| 808 | if (ar.result == null) { |
| 809 | loge("getCellNetworkScanResults: Empty response"); |
| 810 | } |
| 811 | if (ar.exception != null) { |
| 812 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 813 | } |
| 814 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 815 | if (ar.exception instanceof CommandException) { |
| 816 | CommandException.Error error = |
| 817 | ((CommandException) (ar.exception)).getCommandError(); |
| 818 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 819 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 820 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 821 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 822 | } |
| 823 | } |
| 824 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 825 | } |
| 826 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 827 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 828 | break; |
| 829 | |
| 830 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 831 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 832 | ManualNetworkSelectionArgument selArg = |
| 833 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 834 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 835 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 836 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 837 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 838 | break; |
| 839 | |
| 840 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 841 | ar = (AsyncResult) msg.obj; |
| 842 | request = (MainThreadRequest) ar.userObj; |
| 843 | if (ar.exception == null) { |
| 844 | request.result = true; |
| 845 | } else { |
| 846 | request.result = false; |
| 847 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 848 | } |
| 849 | notifyRequester(request); |
| 850 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 851 | break; |
| 852 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 853 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 854 | request = (MainThreadRequest) msg.obj; |
| 855 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 856 | if (defaultPhone != null) { |
| 857 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 858 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 859 | break; |
| 860 | |
| 861 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 862 | ar = (AsyncResult) msg.obj; |
| 863 | request = (MainThreadRequest) ar.userObj; |
| 864 | if (ar.exception == null && ar.result != null) { |
| 865 | request.result = ar.result; |
| 866 | } else { |
| 867 | if (ar.result == null) { |
| 868 | loge("queryModemActivityInfo: Empty response"); |
| 869 | } else if (ar.exception instanceof CommandException) { |
| 870 | loge("queryModemActivityInfo: CommandException: " + |
| 871 | ar.exception); |
| 872 | } else { |
| 873 | loge("queryModemActivityInfo: Unknown exception"); |
| 874 | } |
| 875 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 876 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 877 | if (request.result == null) { |
| 878 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 879 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 880 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 881 | break; |
| 882 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 883 | case CMD_SET_ALLOWED_CARRIERS: |
| 884 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 885 | CarrierRestrictionRules argument = |
| 886 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 887 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 888 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 889 | break; |
| 890 | |
| 891 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 892 | ar = (AsyncResult) msg.obj; |
| 893 | request = (MainThreadRequest) ar.userObj; |
| 894 | if (ar.exception == null && ar.result != null) { |
| 895 | request.result = ar.result; |
| 896 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 897 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 898 | if (ar.exception instanceof CommandException) { |
| 899 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 900 | CommandException.Error error = |
| 901 | ((CommandException) (ar.exception)).getCommandError(); |
| 902 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 903 | request.result = |
| 904 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 905 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 906 | } else { |
| 907 | loge("setAllowedCarriers: Unknown exception"); |
| 908 | } |
| 909 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 910 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 911 | break; |
| 912 | |
| 913 | case CMD_GET_ALLOWED_CARRIERS: |
| 914 | request = (MainThreadRequest) msg.obj; |
| 915 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 916 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 917 | break; |
| 918 | |
| 919 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 920 | ar = (AsyncResult) msg.obj; |
| 921 | request = (MainThreadRequest) ar.userObj; |
| 922 | if (ar.exception == null && ar.result != null) { |
| 923 | request.result = ar.result; |
| 924 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 925 | request.result = new IllegalStateException( |
| 926 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 927 | if (ar.result == null) { |
| 928 | loge("getAllowedCarriers: Empty response"); |
| 929 | } else if (ar.exception instanceof CommandException) { |
| 930 | loge("getAllowedCarriers: CommandException: " + |
| 931 | ar.exception); |
| 932 | } else { |
| 933 | loge("getAllowedCarriers: Unknown exception"); |
| 934 | } |
| 935 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 936 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 937 | break; |
| 938 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 939 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 940 | ar = (AsyncResult) msg.obj; |
| 941 | request = (MainThreadRequest) ar.userObj; |
| 942 | if (ar.exception == null && ar.result != null) { |
| 943 | request.result = ar.result; |
| 944 | } else { |
| 945 | request.result = new IllegalArgumentException( |
| 946 | "Failed to retrieve Forbidden Plmns"); |
| 947 | if (ar.result == null) { |
| 948 | loge("getForbiddenPlmns: Empty response"); |
| 949 | } else { |
| 950 | loge("getForbiddenPlmns: Unknown exception"); |
| 951 | } |
| 952 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 953 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 954 | break; |
| 955 | |
| 956 | case CMD_GET_FORBIDDEN_PLMNS: |
| 957 | request = (MainThreadRequest) msg.obj; |
| 958 | uiccCard = getUiccCardFromRequest(request); |
| 959 | if (uiccCard == null) { |
| 960 | loge("getForbiddenPlmns() UiccCard is null"); |
| 961 | request.result = new IllegalArgumentException( |
| 962 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 963 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 964 | break; |
| 965 | } |
| 966 | Integer appType = (Integer) request.argument; |
| 967 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 968 | if (uiccApp == null) { |
| 969 | loge("getForbiddenPlmns() no app with specified type -- " |
| 970 | + appType); |
| 971 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 972 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 973 | break; |
| 974 | } else { |
| 975 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 976 | + " specified type -- " + appType); |
| 977 | } |
| 978 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 979 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 980 | onCompleted); |
| 981 | break; |
| 982 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 983 | case CMD_SWITCH_SLOTS: |
| 984 | request = (MainThreadRequest) msg.obj; |
| 985 | int[] physicalSlots = (int[]) request.argument; |
| 986 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 987 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 988 | break; |
| 989 | |
| 990 | case EVENT_SWITCH_SLOTS_DONE: |
| 991 | ar = (AsyncResult) msg.obj; |
| 992 | request = (MainThreadRequest) ar.userObj; |
| 993 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 994 | notifyRequester(request); |
| 995 | break; |
| 996 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 997 | request = (MainThreadRequest) msg.obj; |
| 998 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 999 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1000 | break; |
| 1001 | |
| 1002 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1003 | ar = (AsyncResult) msg.obj; |
| 1004 | request = (MainThreadRequest) ar.userObj; |
| 1005 | if (ar.exception != null) { |
| 1006 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1007 | } else { |
| 1008 | int mode = ((int[]) ar.result)[0]; |
| 1009 | if (mode == 0) { |
| 1010 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1011 | } else { |
| 1012 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1013 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1014 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1015 | notifyRequester(request); |
| 1016 | break; |
| 1017 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1018 | request = (MainThreadRequest) msg.obj; |
| 1019 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1020 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1021 | break; |
| 1022 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1023 | ar = (AsyncResult) msg.obj; |
| 1024 | request = (MainThreadRequest) ar.userObj; |
| 1025 | if (ar.exception != null) { |
| 1026 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1027 | } else { |
| 1028 | request.result = ((int[]) ar.result)[0]; |
| 1029 | } |
| 1030 | notifyRequester(request); |
| 1031 | break; |
| 1032 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1033 | request = (MainThreadRequest) msg.obj; |
| 1034 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1035 | int mode = (int) request.argument; |
| 1036 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1037 | break; |
| 1038 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1039 | ar = (AsyncResult) msg.obj; |
| 1040 | request = (MainThreadRequest) ar.userObj; |
| 1041 | request.result = ar.exception == null; |
| 1042 | notifyRequester(request); |
| 1043 | break; |
| 1044 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1045 | request = (MainThreadRequest) msg.obj; |
| 1046 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1047 | int subscriptionMode = (int) request.argument; |
| 1048 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1049 | break; |
| 1050 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1051 | ar = (AsyncResult) msg.obj; |
| 1052 | request = (MainThreadRequest) ar.userObj; |
| 1053 | request.result = ar.exception == null; |
| 1054 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1055 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1056 | case CMD_GET_ALL_CELL_INFO: |
| 1057 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1058 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1059 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1060 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1061 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1062 | ar = (AsyncResult) msg.obj; |
| 1063 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1064 | // If a timeout occurs, the response will be null |
| 1065 | request.result = (ar.exception == null && ar.result != null) |
| 1066 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1067 | synchronized (request) { |
| 1068 | request.notifyAll(); |
| 1069 | } |
| 1070 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1071 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1072 | request = (MainThreadRequest) msg.obj; |
| 1073 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1074 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1075 | break; |
| 1076 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1077 | ar = (AsyncResult) msg.obj; |
| 1078 | request = (MainThreadRequest) ar.userObj; |
| 1079 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1080 | try { |
| 1081 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1082 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1083 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1084 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1085 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1086 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1087 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1088 | } else { |
| 1089 | // use the result as returned |
| 1090 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1091 | } |
| 1092 | } catch (RemoteException re) { |
| 1093 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1094 | } |
| 1095 | break; |
| 1096 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1097 | request = (MainThreadRequest) msg.obj; |
| 1098 | WorkSource ws = (WorkSource) request.argument; |
| 1099 | Phone phone = getPhoneFromRequest(request); |
| 1100 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1101 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1102 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1103 | ar = (AsyncResult) msg.obj; |
| 1104 | request = (MainThreadRequest) ar.userObj; |
| 1105 | if (ar.exception == null) { |
| 1106 | request.result = ar.result; |
| 1107 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1108 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1109 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1110 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1111 | } |
| 1112 | |
| 1113 | synchronized (request) { |
| 1114 | request.notifyAll(); |
| 1115 | } |
| 1116 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1117 | case CMD_MODEM_REBOOT: |
| 1118 | request = (MainThreadRequest) msg.obj; |
| 1119 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1120 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1121 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1122 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1123 | handleNullReturnEvent(msg, "rebootModem"); |
| 1124 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1125 | case CMD_REQUEST_ENABLE_MODEM: |
| 1126 | request = (MainThreadRequest) msg.obj; |
| 1127 | boolean enable = (boolean) request.argument; |
| 1128 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1129 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1130 | PhoneConfigurationManager.getInstance() |
| 1131 | .enablePhone(request.phone, enable, onCompleted); |
| 1132 | break; |
| 1133 | case EVENT_ENABLE_MODEM_DONE: |
| 1134 | ar = (AsyncResult) msg.obj; |
| 1135 | request = (MainThreadRequest) ar.userObj; |
| 1136 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1137 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1138 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1139 | if ((boolean) request.result) { |
| 1140 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1141 | updateModemStateMetrics(); |
| 1142 | } else { |
| 1143 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1144 | + ar.exception); |
| 1145 | } |
| 1146 | notifyRequester(request); |
| 1147 | break; |
| 1148 | case CMD_GET_MODEM_STATUS: |
| 1149 | request = (MainThreadRequest) msg.obj; |
| 1150 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1151 | PhoneConfigurationManager.getInstance() |
| 1152 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1153 | break; |
| 1154 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1155 | ar = (AsyncResult) msg.obj; |
| 1156 | request = (MainThreadRequest) ar.userObj; |
| 1157 | int id = request.phone.getPhoneId(); |
| 1158 | if (ar.exception == null && ar.result != null) { |
| 1159 | request.result = ar.result; |
| 1160 | //update the cache as modem status has changed |
| 1161 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1162 | (boolean) request.result); |
| 1163 | } else { |
| 1164 | // Return true if modem status cannot be retrieved. For most cases, |
| 1165 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1166 | // and disable modem are not supported. Modem is always on. |
| 1167 | // TODO: this should be fixed in R to support a third |
| 1168 | // status UNKNOWN b/131631629 |
| 1169 | request.result = true; |
| 1170 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1171 | + ar.exception); |
| 1172 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1173 | notifyRequester(request); |
| 1174 | break; |
Naina Nalluri | 1264a9f | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1175 | case CMD_ERASE_MODEM_CONFIG: |
| 1176 | request = (MainThreadRequest) msg.obj; |
| 1177 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1178 | defaultPhone.eraseModemConfig(onCompleted); |
| 1179 | break; |
| 1180 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1181 | handleNullReturnEvent(msg, "eraseModemConfig"); |
| 1182 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1183 | default: |
| 1184 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1185 | break; |
| 1186 | } |
| 1187 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1188 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1189 | private void notifyRequester(MainThreadRequest request) { |
| 1190 | synchronized (request) { |
| 1191 | request.notifyAll(); |
| 1192 | } |
| 1193 | } |
| 1194 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1195 | private void handleNullReturnEvent(Message msg, String command) { |
| 1196 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1197 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1198 | if (ar.exception == null) { |
| 1199 | request.result = true; |
| 1200 | } else { |
| 1201 | request.result = false; |
| 1202 | if (ar.exception instanceof CommandException) { |
| 1203 | loge(command + ": CommandException: " + ar.exception); |
| 1204 | } else { |
| 1205 | loge(command + ": Unknown exception"); |
| 1206 | } |
| 1207 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1208 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1209 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | /** |
| 1213 | * Posts the specified command to be executed on the main thread, |
| 1214 | * waits for the request to complete, and returns the result. |
| 1215 | * @see #sendRequestAsync |
| 1216 | */ |
| 1217 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1218 | return sendRequest( |
| 1219 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | /** |
| 1223 | * Posts the specified command to be executed on the main thread, |
| 1224 | * waits for the request to complete, and returns the result. |
| 1225 | * @see #sendRequestAsync |
| 1226 | */ |
| 1227 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1228 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1229 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | /** |
| 1233 | * Posts the specified command to be executed on the main thread, |
| 1234 | * waits for the request to complete, and returns the result. |
| 1235 | * @see #sendRequestAsync |
| 1236 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1237 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1238 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * Posts the specified command to be executed on the main thread, |
| 1243 | * waits for the request to complete, and returns the result. |
| 1244 | * @see #sendRequestAsync |
| 1245 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1246 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1247 | return sendRequest(command, argument, subId, null, workSource); |
| 1248 | } |
| 1249 | |
| 1250 | /** |
| 1251 | * Posts the specified command to be executed on the main thread, |
| 1252 | * waits for the request to complete, and returns the result. |
| 1253 | * @see #sendRequestAsync |
| 1254 | */ |
| 1255 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1256 | return sendRequest( |
| 1257 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1258 | } |
| 1259 | |
| 1260 | /** |
| 1261 | * Posts the specified command to be executed on the main thread, |
| 1262 | * waits for the request to complete, and returns the result. |
| 1263 | * @see #sendRequestAsync |
| 1264 | */ |
| 1265 | private Object sendRequest( |
| 1266 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1267 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1268 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1269 | } |
| 1270 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1271 | MainThreadRequest request = null; |
| 1272 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1273 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1274 | } else if (phone != null) { |
| 1275 | request = new MainThreadRequest(argument, phone, workSource); |
| 1276 | } else { |
| 1277 | request = new MainThreadRequest(argument, subId, workSource); |
| 1278 | } |
| 1279 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1280 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1281 | msg.sendToTarget(); |
| 1282 | |
| 1283 | // Wait for the request to complete |
| 1284 | synchronized (request) { |
| 1285 | while (request.result == null) { |
| 1286 | try { |
| 1287 | request.wait(); |
| 1288 | } catch (InterruptedException e) { |
| 1289 | // Do nothing, go back and wait until the request is complete |
| 1290 | } |
| 1291 | } |
| 1292 | } |
| 1293 | return request.result; |
| 1294 | } |
| 1295 | |
| 1296 | /** |
| 1297 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1298 | * Posts the specified command to be executed on the main thread, and |
| 1299 | * returns immediately. |
| 1300 | * @see #sendRequest |
| 1301 | */ |
| 1302 | private void sendRequestAsync(int command) { |
| 1303 | mMainThreadHandler.sendEmptyMessage(command); |
| 1304 | } |
| 1305 | |
| 1306 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1307 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1308 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1309 | */ |
| 1310 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1311 | sendRequestAsync(command, argument, null, null); |
| 1312 | } |
| 1313 | |
| 1314 | /** |
| 1315 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1316 | * @see {@link #sendRequest(int,Object)} |
| 1317 | */ |
| 1318 | private void sendRequestAsync( |
| 1319 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1320 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1321 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1322 | msg.sendToTarget(); |
| 1323 | } |
| 1324 | |
| 1325 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1326 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1327 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1328 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1329 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1330 | synchronized (PhoneInterfaceManager.class) { |
| 1331 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1332 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1333 | } else { |
| 1334 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1335 | } |
| 1336 | return sInstance; |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | /** Private constructor; @see init() */ |
Jordan Liu | a39e6c1 | 2020-03-04 13:59:23 -0800 | [diff] [blame] | 1341 | @VisibleForTesting |
| 1342 | /* package */ PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1343 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1344 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1345 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1346 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1347 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1348 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1349 | mTelephonySharedPreferences = |
| 1350 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1351 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1352 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1353 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1354 | publish(); |
| 1355 | } |
| 1356 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1357 | private Phone getDefaultPhone() { |
| 1358 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1359 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1360 | } |
| 1361 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1362 | private void publish() { |
| 1363 | if (DBG) log("publish: " + this); |
| 1364 | |
| 1365 | ServiceManager.addService("phone", this); |
| 1366 | } |
| 1367 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1368 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1369 | if (request.phone != null) { |
| 1370 | return request.phone; |
| 1371 | } else { |
| 1372 | return getPhoneFromSubId(request.subId); |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | private Phone getPhoneFromSubId(int subId) { |
| 1377 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1378 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1381 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1382 | Phone phone = getPhoneFromRequest(request); |
| 1383 | return phone == null ? null : |
| 1384 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1385 | } |
| 1386 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1387 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1388 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1389 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1390 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1391 | |
Naina Nalluri | 1264a9f | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1392 | private void sendEraseModemConfig(Phone phone) { |
| 1393 | if (phone != null) { |
| 1394 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1395 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1396 | final long identity = Binder.clearCallingIdentity(); |
| 1397 | try { |
| 1398 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1399 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1400 | } finally { |
| 1401 | Binder.restoreCallingIdentity(identity); |
| 1402 | } |
| 1403 | } |
| 1404 | } |
| 1405 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1406 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1407 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1410 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1411 | if (DBG) log("dial: " + number); |
| 1412 | // No permission check needed here: This is just a wrapper around the |
| 1413 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1414 | // the UI before it does anything. |
| 1415 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1416 | final long identity = Binder.clearCallingIdentity(); |
| 1417 | try { |
| 1418 | String url = createTelUrl(number); |
| 1419 | if (url == null) { |
| 1420 | return; |
| 1421 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1422 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1423 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1424 | PhoneConstants.State state = mCM.getState(subId); |
| 1425 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1426 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1427 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1428 | mApp.startActivity(intent); |
| 1429 | } |
| 1430 | } finally { |
| 1431 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1436 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1437 | } |
| 1438 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1439 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1440 | if (DBG) log("call: " + number); |
| 1441 | |
| 1442 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1443 | // need to do a permission check since we're calling startActivity() |
| 1444 | // from the context of the phone app. |
| 1445 | enforceCallPermission(); |
| 1446 | |
| 1447 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1448 | != AppOpsManager.MODE_ALLOWED) { |
| 1449 | return; |
| 1450 | } |
| 1451 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1452 | final long identity = Binder.clearCallingIdentity(); |
| 1453 | try { |
| 1454 | String url = createTelUrl(number); |
| 1455 | if (url == null) { |
| 1456 | return; |
| 1457 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1458 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1459 | boolean isValid = false; |
| 1460 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1461 | if (slist != null) { |
| 1462 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1463 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1464 | isValid = true; |
| 1465 | break; |
| 1466 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1467 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1468 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1469 | if (!isValid) { |
| 1470 | return; |
| 1471 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1472 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1473 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1474 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1475 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1476 | mApp.startActivity(intent); |
| 1477 | } finally { |
| 1478 | Binder.restoreCallingIdentity(identity); |
| 1479 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1482 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1483 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1486 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1487 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1488 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1489 | } |
| 1490 | |
| 1491 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1492 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1495 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1496 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1497 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1498 | } |
| 1499 | |
| 1500 | /** {@hide} */ |
| 1501 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1502 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1505 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1506 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1507 | |
| 1508 | final long identity = Binder.clearCallingIdentity(); |
| 1509 | try { |
| 1510 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1511 | checkSimPin.start(); |
| 1512 | return checkSimPin.unlockSim(null, pin); |
| 1513 | } finally { |
| 1514 | Binder.restoreCallingIdentity(identity); |
| 1515 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1518 | /** {@hide} */ |
| 1519 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1520 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1523 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1524 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1525 | |
| 1526 | final long identity = Binder.clearCallingIdentity(); |
| 1527 | try { |
| 1528 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1529 | checkSimPuk.start(); |
| 1530 | return checkSimPuk.unlockSim(puk, pin); |
| 1531 | } finally { |
| 1532 | Binder.restoreCallingIdentity(identity); |
| 1533 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1537 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1538 | * a synchronous one. |
| 1539 | */ |
| 1540 | private static class UnlockSim extends Thread { |
| 1541 | |
| 1542 | private final IccCard mSimCard; |
| 1543 | |
| 1544 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1545 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1546 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1547 | |
| 1548 | // For replies from SimCard interface |
| 1549 | private Handler mHandler; |
| 1550 | |
| 1551 | // For async handler to identify request type |
| 1552 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1553 | |
| 1554 | public UnlockSim(IccCard simCard) { |
| 1555 | mSimCard = simCard; |
| 1556 | } |
| 1557 | |
| 1558 | @Override |
| 1559 | public void run() { |
| 1560 | Looper.prepare(); |
| 1561 | synchronized (UnlockSim.this) { |
| 1562 | mHandler = new Handler() { |
| 1563 | @Override |
| 1564 | public void handleMessage(Message msg) { |
| 1565 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1566 | switch (msg.what) { |
| 1567 | case SUPPLY_PIN_COMPLETE: |
| 1568 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1569 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1570 | mRetryCount = msg.arg1; |
| 1571 | if (ar.exception != null) { |
| 1572 | if (ar.exception instanceof CommandException && |
| 1573 | ((CommandException)(ar.exception)).getCommandError() |
| 1574 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1575 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1576 | } else { |
| 1577 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1578 | } |
| 1579 | } else { |
| 1580 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1581 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1582 | mDone = true; |
| 1583 | UnlockSim.this.notifyAll(); |
| 1584 | } |
| 1585 | break; |
| 1586 | } |
| 1587 | } |
| 1588 | }; |
| 1589 | UnlockSim.this.notifyAll(); |
| 1590 | } |
| 1591 | Looper.loop(); |
| 1592 | } |
| 1593 | |
| 1594 | /* |
| 1595 | * Use PIN or PUK to unlock SIM card |
| 1596 | * |
| 1597 | * If PUK is null, unlock SIM card with PIN |
| 1598 | * |
| 1599 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1600 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1601 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1602 | |
| 1603 | while (mHandler == null) { |
| 1604 | try { |
| 1605 | wait(); |
| 1606 | } catch (InterruptedException e) { |
| 1607 | Thread.currentThread().interrupt(); |
| 1608 | } |
| 1609 | } |
| 1610 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1611 | |
| 1612 | if (puk == null) { |
| 1613 | mSimCard.supplyPin(pin, callback); |
| 1614 | } else { |
| 1615 | mSimCard.supplyPuk(puk, pin, callback); |
| 1616 | } |
| 1617 | |
| 1618 | while (!mDone) { |
| 1619 | try { |
| 1620 | Log.d(LOG_TAG, "wait for done"); |
| 1621 | wait(); |
| 1622 | } catch (InterruptedException e) { |
| 1623 | // Restore the interrupted status |
| 1624 | Thread.currentThread().interrupt(); |
| 1625 | } |
| 1626 | } |
| 1627 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1628 | int[] resultArray = new int[2]; |
| 1629 | resultArray[0] = mResult; |
| 1630 | resultArray[1] = mRetryCount; |
| 1631 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1636 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1637 | |
| 1638 | } |
| 1639 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1640 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1641 | // No permission check needed here: this call is harmless, and it's |
| 1642 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1643 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1644 | final long identity = Binder.clearCallingIdentity(); |
| 1645 | try { |
| 1646 | final Phone phone = getPhone(subId); |
| 1647 | if (phone != null) { |
| 1648 | phone.updateServiceLocation(); |
| 1649 | } |
| 1650 | } finally { |
| 1651 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1652 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1655 | @Override |
| 1656 | public boolean isRadioOn(String callingPackage) { |
| 1657 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1660 | @Override |
| 1661 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1662 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1663 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1664 | return false; |
| 1665 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1666 | |
| 1667 | final long identity = Binder.clearCallingIdentity(); |
| 1668 | try { |
| 1669 | return isRadioOnForSubscriber(subId); |
| 1670 | } finally { |
| 1671 | Binder.restoreCallingIdentity(identity); |
| 1672 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1676 | final long identity = Binder.clearCallingIdentity(); |
| 1677 | try { |
| 1678 | final Phone phone = getPhone(subId); |
| 1679 | if (phone != null) { |
| 1680 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1681 | } else { |
| 1682 | return false; |
| 1683 | } |
| 1684 | } finally { |
| 1685 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1686 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1690 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1691 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1692 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1693 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1694 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1695 | |
| 1696 | final long identity = Binder.clearCallingIdentity(); |
| 1697 | try { |
| 1698 | final Phone phone = getPhone(subId); |
| 1699 | if (phone != null) { |
| 1700 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1701 | } |
| 1702 | } finally { |
| 1703 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1704 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1708 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1709 | } |
| 1710 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1711 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1712 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1713 | |
| 1714 | final long identity = Binder.clearCallingIdentity(); |
| 1715 | try { |
| 1716 | final Phone phone = getPhone(subId); |
| 1717 | if (phone == null) { |
| 1718 | return false; |
| 1719 | } |
| 1720 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1721 | toggleRadioOnOffForSubscriber(subId); |
| 1722 | } |
| 1723 | return true; |
| 1724 | } finally { |
| 1725 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1726 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1727 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1728 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1729 | public boolean needMobileRadioShutdown() { |
| 1730 | /* |
| 1731 | * If any of the Radios are available, it will need to be |
| 1732 | * shutdown. So return true if any Radio is available. |
| 1733 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1734 | final long identity = Binder.clearCallingIdentity(); |
| 1735 | try { |
| 1736 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1737 | Phone phone = PhoneFactory.getPhone(i); |
| 1738 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1739 | } |
| 1740 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1741 | return false; |
| 1742 | } finally { |
| 1743 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1744 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1747 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1748 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1749 | enforceModifyPermission(); |
| 1750 | |
| 1751 | final long identity = Binder.clearCallingIdentity(); |
| 1752 | try { |
| 1753 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1754 | logv("Shutting down Phone " + i); |
| 1755 | shutdownRadioUsingPhoneId(i); |
| 1756 | } |
| 1757 | } finally { |
| 1758 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1763 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1764 | if (phone != null && phone.isRadioAvailable()) { |
| 1765 | phone.shutdownRadio(); |
| 1766 | } |
| 1767 | } |
| 1768 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1769 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1770 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1771 | |
| 1772 | final long identity = Binder.clearCallingIdentity(); |
| 1773 | try { |
| 1774 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1775 | if (defaultPhone != null) { |
| 1776 | defaultPhone.setRadioPower(turnOn); |
| 1777 | return true; |
| 1778 | } else { |
| 1779 | loge("There's no default phone."); |
| 1780 | return false; |
| 1781 | } |
| 1782 | } finally { |
| 1783 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1784 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1787 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1788 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1789 | |
| 1790 | final long identity = Binder.clearCallingIdentity(); |
| 1791 | try { |
| 1792 | final Phone phone = getPhone(subId); |
| 1793 | if (phone != null) { |
| 1794 | phone.setRadioPower(turnOn); |
| 1795 | return true; |
| 1796 | } else { |
| 1797 | return false; |
| 1798 | } |
| 1799 | } finally { |
| 1800 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1801 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1804 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1805 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1806 | public boolean enableDataConnectivity() { |
| 1807 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1808 | |
| 1809 | final long identity = Binder.clearCallingIdentity(); |
| 1810 | try { |
| 1811 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1812 | final Phone phone = getPhone(subId); |
| 1813 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1814 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1815 | return true; |
| 1816 | } else { |
| 1817 | return false; |
| 1818 | } |
| 1819 | } finally { |
| 1820 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1821 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1824 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1825 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1826 | public boolean disableDataConnectivity() { |
| 1827 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1828 | |
| 1829 | final long identity = Binder.clearCallingIdentity(); |
| 1830 | try { |
| 1831 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1832 | final Phone phone = getPhone(subId); |
| 1833 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1834 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1835 | return true; |
| 1836 | } else { |
| 1837 | return false; |
| 1838 | } |
| 1839 | } finally { |
| 1840 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1841 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1844 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1845 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1846 | final long identity = Binder.clearCallingIdentity(); |
| 1847 | try { |
| 1848 | final Phone phone = getPhone(subId); |
| 1849 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1850 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1851 | } else { |
| 1852 | return false; |
| 1853 | } |
| 1854 | } finally { |
| 1855 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1856 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1860 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1863 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1864 | enforceCallPermission(); |
| 1865 | |
| 1866 | final long identity = Binder.clearCallingIdentity(); |
| 1867 | try { |
| 1868 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1869 | return; |
| 1870 | } |
| 1871 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1872 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1873 | } finally { |
| 1874 | Binder.restoreCallingIdentity(identity); |
| 1875 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1876 | }; |
| 1877 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1878 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1879 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1880 | |
| 1881 | final long identity = Binder.clearCallingIdentity(); |
| 1882 | try { |
| 1883 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1884 | return false; |
| 1885 | } |
| 1886 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1887 | } finally { |
| 1888 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1889 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1890 | } |
| 1891 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1892 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1893 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1896 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1897 | final long identity = Binder.clearCallingIdentity(); |
| 1898 | try { |
| 1899 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1900 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1901 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1902 | } finally { |
| 1903 | Binder.restoreCallingIdentity(identity); |
| 1904 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1905 | } |
| 1906 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1907 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1908 | public int getDataState() { |
Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1909 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1910 | } |
| 1911 | |
| 1912 | @Override |
| 1913 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1914 | final long identity = Binder.clearCallingIdentity(); |
| 1915 | try { |
Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1916 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1917 | if (phone != null) { |
| 1918 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1919 | } else { |
| 1920 | return PhoneConstantConversions.convertDataState( |
| 1921 | PhoneConstants.DataState.DISCONNECTED); |
| 1922 | } |
| 1923 | } finally { |
| 1924 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1925 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1928 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1929 | public int getDataActivity() { |
Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1930 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1931 | } |
| 1932 | |
| 1933 | @Override |
| 1934 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1935 | final long identity = Binder.clearCallingIdentity(); |
| 1936 | try { |
Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1937 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1938 | if (phone != null) { |
| 1939 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1940 | } else { |
| 1941 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1942 | } |
| 1943 | } finally { |
| 1944 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1945 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1949 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1950 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1951 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1952 | |
| 1953 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1954 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1955 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1956 | .setCallingPackage(callingPackage) |
| 1957 | .setCallingPid(Binder.getCallingPid()) |
| 1958 | .setCallingUid(Binder.getCallingUid()) |
| 1959 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 1960 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1961 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1962 | .build()); |
| 1963 | switch (locationResult) { |
| 1964 | case DENIED_HARD: |
| 1965 | throw new SecurityException("Not allowed to access cell location"); |
| 1966 | case DENIED_SOFT: |
| 1967 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1970 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1971 | final long identity = Binder.clearCallingIdentity(); |
| 1972 | try { |
| 1973 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1974 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1975 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1976 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1977 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1978 | return data; |
| 1979 | } finally { |
| 1980 | Binder.restoreCallingIdentity(identity); |
| 1981 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1984 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1985 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1986 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1987 | // registered cell info, so return a NULL country instead. |
| 1988 | final long identity = Binder.clearCallingIdentity(); |
| 1989 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1990 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1991 | // Get default phone in this case. |
| 1992 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1993 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1994 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1995 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1996 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1997 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1998 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1999 | return ""; |
| 2000 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2001 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2002 | if (phone != null) { |
| 2003 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2004 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2005 | if (sst != null) { |
| 2006 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2007 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2008 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2009 | return lt.getCurrentCountry(); |
| 2010 | } else if (emergencyNumberTracker != null) { |
| 2011 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2012 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2013 | } |
| 2014 | } |
| 2015 | } |
| 2016 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2017 | } finally { |
| 2018 | Binder.restoreCallingIdentity(identity); |
| 2019 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2023 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2024 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2027 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2028 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2029 | mApp.enforceCallingOrSelfPermission( |
| 2030 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2031 | |
| 2032 | final long identity = Binder.clearCallingIdentity(); |
| 2033 | try { |
| 2034 | final Phone phone = getPhone(subId); |
| 2035 | if (phone != null) { |
| 2036 | phone.enableLocationUpdates(); |
| 2037 | } |
| 2038 | } finally { |
| 2039 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2040 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | @Override |
| 2044 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2045 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2048 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2049 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2050 | mApp.enforceCallingOrSelfPermission( |
| 2051 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2052 | |
| 2053 | final long identity = Binder.clearCallingIdentity(); |
| 2054 | try { |
| 2055 | final Phone phone = getPhone(subId); |
| 2056 | if (phone != null) { |
| 2057 | phone.disableLocationUpdates(); |
| 2058 | } |
| 2059 | } finally { |
| 2060 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2061 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2064 | /** |
| 2065 | * Returns the target SDK version number for a given package name. |
| 2066 | * |
Nathan Harold | ba61eeb | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2067 | * This call MUST be invoked before clearing the calling UID. |
| 2068 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2069 | * @return target SDK if the package is found or INT_MAX. |
| 2070 | */ |
| 2071 | private int getTargetSdk(String packageName) { |
| 2072 | try { |
Nathan Harold | ba61eeb | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2073 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
| 2074 | packageName, 0, UserHandle.getUserId(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2075 | if (ai != null) return ai.targetSdkVersion; |
| 2076 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ba61eeb | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2077 | loge("Failed to get package info for pkg=" |
| 2078 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2079 | } |
| 2080 | return Integer.MAX_VALUE; |
| 2081 | } |
| 2082 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2083 | @Override |
| 2084 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2085 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2086 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2087 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2088 | throw new SecurityException( |
| 2089 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2090 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2091 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2092 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 2093 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2094 | return null; |
| 2095 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2096 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2097 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2098 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2099 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2100 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2101 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2102 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2103 | for (CellInfo ci : info) { |
| 2104 | if (ci instanceof CellInfoGsm) { |
| 2105 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2106 | } else if (ci instanceof CellInfoWcdma) { |
| 2107 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2108 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2109 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2110 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2113 | private List<CellInfo> getCachedCellInfo() { |
| 2114 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2115 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2116 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2117 | if (info != null) cellInfos.addAll(info); |
| 2118 | } |
| 2119 | return cellInfos; |
| 2120 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2121 | |
| 2122 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2123 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2124 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2125 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2126 | |
| 2127 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2128 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2129 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2130 | .setCallingPackage(callingPackage) |
| 2131 | .setCallingPid(Binder.getCallingPid()) |
| 2132 | .setCallingUid(Binder.getCallingUid()) |
| 2133 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2134 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2135 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2136 | .build()); |
| 2137 | switch (locationResult) { |
| 2138 | case DENIED_HARD: |
| 2139 | throw new SecurityException("Not allowed to access cell info"); |
| 2140 | case DENIED_SOFT: |
| 2141 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2144 | final int targetSdk = getTargetSdk(callingPackage); |
| 2145 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2146 | return getCachedCellInfo(); |
| 2147 | } |
| 2148 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2149 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2150 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2151 | final long identity = Binder.clearCallingIdentity(); |
| 2152 | try { |
| 2153 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2154 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2155 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2156 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2157 | if (info != null) cellInfos.addAll(info); |
| 2158 | } |
| 2159 | return cellInfos; |
| 2160 | } finally { |
| 2161 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2162 | } |
| 2163 | } |
| 2164 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2165 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2166 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2167 | requestCellInfoUpdateInternal( |
| 2168 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2169 | } |
| 2170 | |
| 2171 | @Override |
| 2172 | public void requestCellInfoUpdateWithWorkSource( |
| 2173 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2174 | enforceModifyPermission(); |
| 2175 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2176 | } |
| 2177 | |
| 2178 | private void requestCellInfoUpdateInternal( |
| 2179 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2180 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2181 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2182 | |
| 2183 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2184 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2185 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2186 | .setCallingPackage(callingPackage) |
| 2187 | .setCallingPid(Binder.getCallingPid()) |
| 2188 | .setCallingUid(Binder.getCallingUid()) |
| 2189 | .setMethod("requestCellInfoUpdate") |
| 2190 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2191 | .build()); |
| 2192 | switch (locationResult) { |
| 2193 | case DENIED_HARD: |
| 2194 | throw new SecurityException("Not allowed to access cell info"); |
| 2195 | case DENIED_SOFT: |
Nathan Harold | b3c5da4 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2196 | try { |
| 2197 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2198 | } catch (RemoteException re) { |
| 2199 | // Drop without consequences |
| 2200 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2201 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
Nathan Harold | 32e84c4 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2204 | |
| 2205 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2206 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2207 | |
| 2208 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2209 | } |
| 2210 | |
| 2211 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2212 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2213 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2214 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2215 | |
| 2216 | final long identity = Binder.clearCallingIdentity(); |
| 2217 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2218 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2219 | } finally { |
| 2220 | Binder.restoreCallingIdentity(identity); |
| 2221 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2222 | } |
| 2223 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2224 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2225 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2226 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2227 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2228 | return null; |
| 2229 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2230 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2231 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2232 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2233 | return null; |
| 2234 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2235 | |
| 2236 | final long identity = Binder.clearCallingIdentity(); |
| 2237 | try { |
| 2238 | return phone.getImei(); |
| 2239 | } finally { |
| 2240 | Binder.restoreCallingIdentity(identity); |
| 2241 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2245 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2246 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2247 | String tac = null; |
| 2248 | if (phone != null) { |
| 2249 | String imei = phone.getImei(); |
| 2250 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2251 | } |
| 2252 | return tac; |
| 2253 | } |
| 2254 | |
| 2255 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2256 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2257 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2258 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2259 | return null; |
| 2260 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2261 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2262 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2263 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2264 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2265 | return null; |
| 2266 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2267 | |
| 2268 | final long identity = Binder.clearCallingIdentity(); |
| 2269 | try { |
| 2270 | return phone.getMeid(); |
| 2271 | } finally { |
| 2272 | Binder.restoreCallingIdentity(identity); |
| 2273 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2277 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2278 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2279 | String manufacturerCode = null; |
| 2280 | if (phone != null) { |
| 2281 | String meid = phone.getMeid(); |
| 2282 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2283 | } |
| 2284 | return manufacturerCode; |
| 2285 | } |
| 2286 | |
| 2287 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2288 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2289 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2290 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2291 | return null; |
| 2292 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2293 | int subId = phone.getSubId(); |
| 2294 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2295 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2296 | return null; |
| 2297 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2298 | |
| 2299 | final long identity = Binder.clearCallingIdentity(); |
| 2300 | try { |
| 2301 | return phone.getDeviceSvn(); |
| 2302 | } finally { |
| 2303 | Binder.restoreCallingIdentity(identity); |
| 2304 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2307 | @Override |
| 2308 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2309 | final long identity = Binder.clearCallingIdentity(); |
| 2310 | try { |
| 2311 | final Phone phone = getPhone(subId); |
| 2312 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2313 | } finally { |
| 2314 | Binder.restoreCallingIdentity(identity); |
| 2315 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2316 | } |
| 2317 | |
| 2318 | @Override |
| 2319 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2320 | final long identity = Binder.clearCallingIdentity(); |
| 2321 | try { |
| 2322 | final Phone phone = getPhone(subId); |
| 2323 | return phone == null ? null : phone.getCarrierName(); |
| 2324 | } finally { |
| 2325 | Binder.restoreCallingIdentity(identity); |
| 2326 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2327 | } |
| 2328 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2329 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2330 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2331 | final long identity = Binder.clearCallingIdentity(); |
| 2332 | try { |
| 2333 | final Phone phone = getPhone(subId); |
| 2334 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2335 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2336 | } finally { |
| 2337 | Binder.restoreCallingIdentity(identity); |
| 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2342 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2343 | final long identity = Binder.clearCallingIdentity(); |
| 2344 | try { |
| 2345 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2346 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2347 | } finally { |
| 2348 | Binder.restoreCallingIdentity(identity); |
| 2349 | } |
| 2350 | } |
| 2351 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2352 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2353 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2354 | if (!isSubscriptionMccMnc) { |
| 2355 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2356 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2357 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2358 | if (phone == null) { |
| 2359 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2360 | } |
| 2361 | final long identity = Binder.clearCallingIdentity(); |
| 2362 | try { |
| 2363 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2364 | } finally { |
| 2365 | Binder.restoreCallingIdentity(identity); |
| 2366 | } |
| 2367 | } |
| 2368 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2369 | // |
| 2370 | // Internal helper methods. |
| 2371 | // |
| 2372 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2373 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2374 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2375 | * |
| 2376 | * @throws SecurityException if the caller does not have the required permission |
| 2377 | */ |
| 2378 | private void enforceModifyPermission() { |
| 2379 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2380 | } |
| 2381 | |
| 2382 | /** |
| 2383 | * Make sure the caller has the CALL_PHONE permission. |
| 2384 | * |
| 2385 | * @throws SecurityException if the caller does not have the required permission |
| 2386 | */ |
| 2387 | private void enforceCallPermission() { |
| 2388 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2389 | } |
| 2390 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2391 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2392 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2393 | "ConnectivityService"); |
| 2394 | } |
| 2395 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2396 | private String createTelUrl(String number) { |
| 2397 | if (TextUtils.isEmpty(number)) { |
| 2398 | return null; |
| 2399 | } |
| 2400 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2401 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2402 | } |
| 2403 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2404 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2405 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2406 | } |
| 2407 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2408 | private static void logv(String msg) { |
| 2409 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2410 | } |
| 2411 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2412 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2413 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2414 | } |
| 2415 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2416 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2417 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2418 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2419 | } |
| 2420 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2421 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2422 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2423 | final long identity = Binder.clearCallingIdentity(); |
| 2424 | try { |
| 2425 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2426 | if (phone == null) { |
| 2427 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2428 | } else { |
| 2429 | return phone.getPhoneType(); |
| 2430 | } |
| 2431 | } finally { |
| 2432 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2433 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | /** |
| 2437 | * Returns the CDMA ERI icon index to display |
| 2438 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2439 | @Override |
| 2440 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2441 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2442 | } |
| 2443 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2444 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2445 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2446 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2447 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2448 | return -1; |
| 2449 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2450 | |
| 2451 | final long identity = Binder.clearCallingIdentity(); |
| 2452 | try { |
| 2453 | final Phone phone = getPhone(subId); |
| 2454 | if (phone != null) { |
| 2455 | return phone.getCdmaEriIconIndex(); |
| 2456 | } else { |
| 2457 | return -1; |
| 2458 | } |
| 2459 | } finally { |
| 2460 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2461 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | /** |
| 2465 | * Returns the CDMA ERI icon mode, |
| 2466 | * 0 - ON |
| 2467 | * 1 - FLASHING |
| 2468 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2469 | @Override |
| 2470 | public int getCdmaEriIconMode(String callingPackage) { |
| 2471 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2474 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2475 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2476 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2477 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2478 | return -1; |
| 2479 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2480 | |
| 2481 | final long identity = Binder.clearCallingIdentity(); |
| 2482 | try { |
| 2483 | final Phone phone = getPhone(subId); |
| 2484 | if (phone != null) { |
| 2485 | return phone.getCdmaEriIconMode(); |
| 2486 | } else { |
| 2487 | return -1; |
| 2488 | } |
| 2489 | } finally { |
| 2490 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2491 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | /** |
| 2495 | * Returns the CDMA ERI text, |
| 2496 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2497 | @Override |
| 2498 | public String getCdmaEriText(String callingPackage) { |
| 2499 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2500 | } |
| 2501 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2502 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2503 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2504 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2505 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2506 | return null; |
| 2507 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2508 | |
| 2509 | final long identity = Binder.clearCallingIdentity(); |
| 2510 | try { |
| 2511 | final Phone phone = getPhone(subId); |
| 2512 | if (phone != null) { |
| 2513 | return phone.getCdmaEriText(); |
| 2514 | } else { |
| 2515 | return null; |
| 2516 | } |
| 2517 | } finally { |
| 2518 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2519 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2523 | * Returns the CDMA MDN. |
| 2524 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2525 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2526 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2527 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2528 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2529 | |
| 2530 | final long identity = Binder.clearCallingIdentity(); |
| 2531 | try { |
| 2532 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2533 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2534 | return phone.getLine1Number(); |
| 2535 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2536 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2537 | return null; |
| 2538 | } |
| 2539 | } finally { |
| 2540 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2541 | } |
| 2542 | } |
| 2543 | |
| 2544 | /** |
| 2545 | * Returns the CDMA MIN. |
| 2546 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2547 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2548 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2549 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2550 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2551 | |
| 2552 | final long identity = Binder.clearCallingIdentity(); |
| 2553 | try { |
| 2554 | final Phone phone = getPhone(subId); |
| 2555 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2556 | return phone.getCdmaMin(); |
| 2557 | } else { |
| 2558 | return null; |
| 2559 | } |
| 2560 | } finally { |
| 2561 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2562 | } |
| 2563 | } |
| 2564 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2565 | @Override |
| 2566 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2567 | INumberVerificationCallback callback, String callingPackage) { |
| 2568 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2569 | != PERMISSION_GRANTED) { |
| 2570 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2571 | } |
| 2572 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2573 | |
| 2574 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2575 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2576 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2577 | } |
| 2578 | |
| 2579 | if (range == null) { |
| 2580 | throw new NullPointerException("Range must be non-null"); |
| 2581 | } |
| 2582 | |
| 2583 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2584 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2585 | |
| 2586 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2587 | } |
| 2588 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2589 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2590 | * Returns true if CDMA provisioning needs to run. |
| 2591 | */ |
| 2592 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2593 | final long identity = Binder.clearCallingIdentity(); |
| 2594 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2595 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2596 | } finally { |
| 2597 | Binder.restoreCallingIdentity(identity); |
| 2598 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2602 | * Sets the voice mail number of a given subId. |
| 2603 | */ |
| 2604 | @Override |
| 2605 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2606 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2607 | |
| 2608 | final long identity = Binder.clearCallingIdentity(); |
| 2609 | try { |
| 2610 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2611 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2612 | return success; |
| 2613 | } finally { |
| 2614 | Binder.restoreCallingIdentity(identity); |
| 2615 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2616 | } |
| 2617 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2618 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2619 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2620 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2621 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2622 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2623 | throw new SecurityException("caller must be system dialer"); |
| 2624 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2625 | |
| 2626 | final long identity = Binder.clearCallingIdentity(); |
| 2627 | try { |
| 2628 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2629 | if (phoneAccountHandle == null) { |
| 2630 | return null; |
| 2631 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2632 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2633 | } finally { |
| 2634 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2635 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2639 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2640 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2641 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2642 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2643 | return null; |
| 2644 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2645 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2646 | final long identity = Binder.clearCallingIdentity(); |
| 2647 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2648 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2649 | } finally { |
| 2650 | Binder.restoreCallingIdentity(identity); |
| 2651 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2655 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2656 | VisualVoicemailSmsFilterSettings settings) { |
| 2657 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2658 | |
| 2659 | final long identity = Binder.clearCallingIdentity(); |
| 2660 | try { |
| 2661 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2662 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2663 | } finally { |
| 2664 | Binder.restoreCallingIdentity(identity); |
| 2665 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2666 | } |
| 2667 | |
| 2668 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2669 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2670 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2671 | |
| 2672 | final long identity = Binder.clearCallingIdentity(); |
| 2673 | try { |
| 2674 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2675 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2676 | } finally { |
| 2677 | Binder.restoreCallingIdentity(identity); |
| 2678 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2682 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2683 | String callingPackage, int subId) { |
| 2684 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2685 | |
| 2686 | final long identity = Binder.clearCallingIdentity(); |
| 2687 | try { |
| 2688 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2689 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2690 | } finally { |
| 2691 | Binder.restoreCallingIdentity(identity); |
| 2692 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2696 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2697 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2698 | |
| 2699 | final long identity = Binder.clearCallingIdentity(); |
| 2700 | try { |
| 2701 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2702 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2703 | } finally { |
| 2704 | Binder.restoreCallingIdentity(identity); |
| 2705 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | @Override |
| 2709 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2710 | String number, int port, String text, PendingIntent sentIntent) { |
| 2711 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2712 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2713 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2714 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2715 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2716 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2717 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2718 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2719 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2720 | * Sets the voice activation state of a given subId. |
| 2721 | */ |
| 2722 | @Override |
| 2723 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2724 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2725 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2726 | |
| 2727 | final long identity = Binder.clearCallingIdentity(); |
| 2728 | try { |
| 2729 | final Phone phone = getPhone(subId); |
| 2730 | if (phone != null) { |
| 2731 | phone.setVoiceActivationState(activationState); |
| 2732 | } else { |
| 2733 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2734 | } |
| 2735 | } finally { |
| 2736 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2737 | } |
| 2738 | } |
| 2739 | |
| 2740 | /** |
| 2741 | * Sets the data activation state of a given subId. |
| 2742 | */ |
| 2743 | @Override |
| 2744 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2745 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2746 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2747 | |
| 2748 | final long identity = Binder.clearCallingIdentity(); |
| 2749 | try { |
| 2750 | final Phone phone = getPhone(subId); |
| 2751 | if (phone != null) { |
| 2752 | phone.setDataActivationState(activationState); |
| 2753 | } else { |
| 2754 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2755 | } |
| 2756 | } finally { |
| 2757 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2758 | } |
| 2759 | } |
| 2760 | |
| 2761 | /** |
| 2762 | * Returns the voice activation state of a given subId. |
| 2763 | */ |
| 2764 | @Override |
| 2765 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2766 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2767 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2768 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2769 | final long identity = Binder.clearCallingIdentity(); |
| 2770 | try { |
| 2771 | if (phone != null) { |
| 2772 | return phone.getVoiceActivationState(); |
| 2773 | } else { |
| 2774 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2775 | } |
| 2776 | } finally { |
| 2777 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2778 | } |
| 2779 | } |
| 2780 | |
| 2781 | /** |
| 2782 | * Returns the data activation state of a given subId. |
| 2783 | */ |
| 2784 | @Override |
| 2785 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2786 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2787 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2788 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2789 | final long identity = Binder.clearCallingIdentity(); |
| 2790 | try { |
| 2791 | if (phone != null) { |
| 2792 | return phone.getDataActivationState(); |
| 2793 | } else { |
| 2794 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2795 | } |
| 2796 | } finally { |
| 2797 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2798 | } |
| 2799 | } |
| 2800 | |
| 2801 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2802 | * Returns the unread count of voicemails for a subId |
| 2803 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2804 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2805 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2806 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2807 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2808 | return 0; |
| 2809 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2810 | final long identity = Binder.clearCallingIdentity(); |
| 2811 | try { |
| 2812 | final Phone phone = getPhone(subId); |
| 2813 | if (phone != null) { |
| 2814 | return phone.getVoiceMessageCount(); |
| 2815 | } else { |
| 2816 | return 0; |
| 2817 | } |
| 2818 | } finally { |
| 2819 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2820 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2824 | * returns true, if the device is in a state where both voice and data |
| 2825 | * are supported simultaneously. This can change based on location or network condition. |
| 2826 | */ |
| 2827 | @Override |
| 2828 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2829 | final long identity = Binder.clearCallingIdentity(); |
| 2830 | try { |
| 2831 | final Phone phone = getPhone(subId); |
| 2832 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2833 | } finally { |
| 2834 | Binder.restoreCallingIdentity(identity); |
| 2835 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2839 | * Send the dialer code if called from the current default dialer or the caller has |
| 2840 | * carrier privilege. |
| 2841 | * @param inputCode The dialer code to send |
| 2842 | */ |
| 2843 | @Override |
| 2844 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2845 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2846 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2847 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2848 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2849 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2850 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2851 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2852 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2853 | |
| 2854 | final long identity = Binder.clearCallingIdentity(); |
| 2855 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2856 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2857 | } finally { |
| 2858 | Binder.restoreCallingIdentity(identity); |
| 2859 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2860 | } |
| 2861 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2862 | @Override |
| 2863 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2864 | if (!isActiveSubscription(subId)) { |
| 2865 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2866 | } |
| 2867 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2868 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2869 | } |
| 2870 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2871 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2872 | public boolean isInEmergencySmsMode() { |
| 2873 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2874 | final long identity = Binder.clearCallingIdentity(); |
| 2875 | try { |
| 2876 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2877 | if (phone.isInEmergencySmsMode()) { |
| 2878 | return true; |
| 2879 | } |
| 2880 | } |
| 2881 | } finally { |
| 2882 | Binder.restoreCallingIdentity(identity); |
| 2883 | } |
| 2884 | return false; |
| 2885 | } |
| 2886 | |
| 2887 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2888 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2889 | throws RemoteException { |
| 2890 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2891 | final long token = Binder.clearCallingIdentity(); |
| 2892 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2893 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2894 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2895 | .addRegistrationCallbackForSubscription(c, subId); |
| 2896 | } finally { |
| 2897 | Binder.restoreCallingIdentity(token); |
| 2898 | } |
| 2899 | } |
| 2900 | |
| 2901 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2902 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2903 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2904 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2905 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2906 | } |
| 2907 | Binder.withCleanCallingIdentity(() -> { |
| 2908 | try { |
| 2909 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2910 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2911 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2912 | } catch (IllegalArgumentException e) { |
| 2913 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2914 | + "is inactive, ignoring unregister."); |
| 2915 | // If the subscription is no longer active, just return, since the callback |
| 2916 | // will already have been removed internally. |
| 2917 | } |
| 2918 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2922 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2923 | throws RemoteException { |
| 2924 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2925 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2926 | final long token = Binder.clearCallingIdentity(); |
| 2927 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2928 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2929 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2930 | } finally { |
| 2931 | Binder.restoreCallingIdentity(token); |
| 2932 | } |
| 2933 | } |
| 2934 | |
| 2935 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2936 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2937 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2938 | |
| 2939 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2940 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2941 | } |
| 2942 | Binder.withCleanCallingIdentity(() -> { |
| 2943 | try { |
| 2944 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2945 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2946 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2947 | } catch (IllegalArgumentException e) { |
| 2948 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2949 | + "is inactive, ignoring unregister."); |
| 2950 | // If the subscription is no longer active, just return, since the callback |
| 2951 | // will already have been removed internally. |
| 2952 | } |
| 2953 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2957 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2958 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2959 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2960 | final long token = Binder.clearCallingIdentity(); |
| 2961 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2962 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2963 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2964 | } catch (ImsException e) { |
| 2965 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2966 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2967 | } catch (IllegalArgumentException e) { |
| 2968 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2969 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2970 | } finally { |
| 2971 | Binder.restoreCallingIdentity(token); |
| 2972 | } |
| 2973 | } |
| 2974 | |
| 2975 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2976 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2977 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2978 | final long token = Binder.clearCallingIdentity(); |
| 2979 | try { |
| 2980 | Phone phone = getPhone(subId); |
| 2981 | if (phone == null) return false; |
| 2982 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2983 | } finally { |
| 2984 | Binder.restoreCallingIdentity(token); |
| 2985 | } |
| 2986 | } |
| 2987 | |
| 2988 | @Override |
| 2989 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2990 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2991 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2992 | final long token = Binder.clearCallingIdentity(); |
| 2993 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2994 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2995 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2996 | } finally { |
| 2997 | Binder.restoreCallingIdentity(token); |
| 2998 | } |
| 2999 | } |
| 3000 | |
| 3001 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3002 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3004 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3005 | final long identity = Binder.clearCallingIdentity(); |
| 3006 | try { |
| 3007 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3008 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3009 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 3010 | } finally { |
| 3011 | Binder.restoreCallingIdentity(identity); |
| 3012 | } |
| 3013 | } |
| 3014 | |
| 3015 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3016 | public boolean isVtSettingEnabled(int subId) { |
| 3017 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3018 | final long identity = Binder.clearCallingIdentity(); |
| 3019 | try { |
| 3020 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3021 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3022 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3023 | } finally { |
| 3024 | Binder.restoreCallingIdentity(identity); |
| 3025 | } |
| 3026 | } |
| 3027 | |
| 3028 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3029 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3030 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3031 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3032 | final long identity = Binder.clearCallingIdentity(); |
| 3033 | try { |
| 3034 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3035 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3036 | } finally { |
| 3037 | Binder.restoreCallingIdentity(identity); |
| 3038 | } |
| 3039 | } |
| 3040 | |
| 3041 | @Override |
| 3042 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3043 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3044 | final long identity = Binder.clearCallingIdentity(); |
| 3045 | try { |
| 3046 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3047 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3048 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 3049 | } finally { |
| 3050 | Binder.restoreCallingIdentity(identity); |
| 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3055 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3056 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3057 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3058 | final long identity = Binder.clearCallingIdentity(); |
| 3059 | try { |
| 3060 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3061 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3062 | } finally { |
| 3063 | Binder.restoreCallingIdentity(identity); |
| 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | @Override |
| 3068 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3069 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3070 | final long identity = Binder.clearCallingIdentity(); |
| 3071 | try { |
| 3072 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3073 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3074 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 3075 | } finally { |
| 3076 | Binder.restoreCallingIdentity(identity); |
| 3077 | } |
| 3078 | } |
| 3079 | |
| 3080 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3081 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3082 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3083 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3084 | final long identity = Binder.clearCallingIdentity(); |
| 3085 | try { |
| 3086 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3087 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3088 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 3089 | } finally { |
| 3090 | Binder.restoreCallingIdentity(identity); |
| 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | @Override |
| 3095 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3096 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3097 | "setVoWiFiNonPersistent"); |
| 3098 | final long identity = Binder.clearCallingIdentity(); |
| 3099 | try { |
| 3100 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3101 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3102 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3103 | } finally { |
| 3104 | Binder.restoreCallingIdentity(identity); |
| 3105 | } |
| 3106 | } |
| 3107 | |
| 3108 | @Override |
| 3109 | public int getVoWiFiModeSetting(int subId) { |
| 3110 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3111 | final long identity = Binder.clearCallingIdentity(); |
| 3112 | try { |
| 3113 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3114 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3115 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3116 | } finally { |
| 3117 | Binder.restoreCallingIdentity(identity); |
| 3118 | } |
| 3119 | } |
| 3120 | |
| 3121 | @Override |
| 3122 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3123 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3124 | "setVoWiFiModeSetting"); |
| 3125 | final long identity = Binder.clearCallingIdentity(); |
| 3126 | try { |
| 3127 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3128 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3129 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3130 | } finally { |
| 3131 | Binder.restoreCallingIdentity(identity); |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | @Override |
| 3136 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3137 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3138 | final long identity = Binder.clearCallingIdentity(); |
| 3139 | try { |
| 3140 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3141 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3142 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3143 | } finally { |
| 3144 | Binder.restoreCallingIdentity(identity); |
| 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | @Override |
| 3149 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3150 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3151 | "setVoWiFiRoamingModeSetting"); |
| 3152 | final long identity = Binder.clearCallingIdentity(); |
| 3153 | try { |
| 3154 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3155 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3156 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3157 | } finally { |
| 3158 | Binder.restoreCallingIdentity(identity); |
| 3159 | } |
| 3160 | } |
| 3161 | |
| 3162 | @Override |
| 3163 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3164 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3165 | "setRttCapabilityEnabled"); |
| 3166 | final long identity = Binder.clearCallingIdentity(); |
| 3167 | try { |
| 3168 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3169 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3170 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3171 | } finally { |
| 3172 | Binder.restoreCallingIdentity(identity); |
| 3173 | } |
| 3174 | } |
| 3175 | |
| 3176 | @Override |
| 3177 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3178 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3179 | final long identity = Binder.clearCallingIdentity(); |
| 3180 | try { |
| 3181 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3182 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3183 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3184 | } finally { |
| 3185 | Binder.restoreCallingIdentity(identity); |
| 3186 | } |
| 3187 | } |
| 3188 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3189 | @Override |
| 3190 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3191 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3192 | final long identity = Binder.clearCallingIdentity(); |
| 3193 | try { |
| 3194 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3195 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3196 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3197 | } finally { |
| 3198 | Binder.restoreCallingIdentity(identity); |
| 3199 | } |
| 3200 | } |
| 3201 | |
| 3202 | @Override |
| 3203 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3204 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3205 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3206 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3207 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3208 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3209 | try { |
| 3210 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3211 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3212 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3213 | } catch (IllegalArgumentException e) { |
| 3214 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3215 | + "is inactive, ignoring unregister."); |
| 3216 | // If the subscription is no longer active, just return, since the callback will already |
| 3217 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3218 | } finally { |
| 3219 | Binder.restoreCallingIdentity(identity); |
| 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3224 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3225 | boolean isProvisioned) { |
| 3226 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3227 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3228 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3229 | } |
| 3230 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3231 | "setProvisioningStatusForCapability"); |
| 3232 | final long identity = Binder.clearCallingIdentity(); |
| 3233 | try { |
| 3234 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3235 | Phone phone = getPhone(subId); |
| 3236 | if (phone == null) { |
| 3237 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3238 | + subId); |
| 3239 | return; |
| 3240 | } |
| 3241 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3242 | return; |
| 3243 | } |
| 3244 | |
| 3245 | // this capability requires provisioning, route to the correct API. |
| 3246 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3247 | switch (capability) { |
| 3248 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3249 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3250 | ims.setVolteProvisioned(isProvisioned); |
| 3251 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3252 | ims.setWfcProvisioned(isProvisioned); |
| 3253 | } |
| 3254 | break; |
| 3255 | } |
| 3256 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3257 | // There is currently no difference in VT provisioning type. |
| 3258 | ims.setVtProvisioned(isProvisioned); |
| 3259 | break; |
| 3260 | } |
| 3261 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3262 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3263 | // change the capability of the feature instead if needed. |
| 3264 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3265 | == isProvisioned) { |
| 3266 | // No change in provisioning. |
| 3267 | return; |
| 3268 | } |
| 3269 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3270 | try { |
| 3271 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3272 | } catch (ImsException e) { |
| 3273 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3274 | + ", Exception" + e.getMessage()); |
| 3275 | } |
| 3276 | break; |
| 3277 | } |
| 3278 | default: { |
| 3279 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3280 | + capability + "', which does not require provisioning."); |
| 3281 | } |
| 3282 | } |
| 3283 | |
| 3284 | } finally { |
| 3285 | Binder.restoreCallingIdentity(identity); |
| 3286 | } |
| 3287 | } |
| 3288 | |
| 3289 | @Override |
| 3290 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3291 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3292 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3293 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3294 | } |
| 3295 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3296 | final long identity = Binder.clearCallingIdentity(); |
| 3297 | try { |
| 3298 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3299 | Phone phone = getPhone(subId); |
| 3300 | if (phone == null) { |
| 3301 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3302 | + subId); |
| 3303 | // We will fail with "true" as the provisioning status because this is the default |
| 3304 | // if we do not require provisioning. |
| 3305 | return true; |
| 3306 | } |
| 3307 | |
| 3308 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3309 | return true; |
| 3310 | } |
| 3311 | |
| 3312 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3313 | switch (capability) { |
| 3314 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3315 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3316 | return ims.isVolteProvisionedOnDevice(); |
| 3317 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3318 | return ims.isWfcProvisionedOnDevice(); |
| 3319 | } |
| 3320 | // This should never happen, since we are checking tech above to make sure it |
| 3321 | // is either LTE or IWLAN. |
| 3322 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3323 | + "capability."); |
| 3324 | } |
| 3325 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3326 | // There is currently no difference in VT provisioning type. |
| 3327 | return ims.isVtProvisionedOnDevice(); |
| 3328 | } |
| 3329 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3330 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3331 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3332 | } |
| 3333 | default: { |
| 3334 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3335 | + capability + "', which does not require provisioning."); |
| 3336 | } |
| 3337 | } |
| 3338 | |
| 3339 | } finally { |
| 3340 | Binder.restoreCallingIdentity(identity); |
| 3341 | } |
| 3342 | } |
| 3343 | |
| 3344 | @Override |
| 3345 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3346 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3347 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3348 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3349 | } |
| 3350 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3351 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3352 | return (provisionedBits & capability) > 0; |
| 3353 | } |
| 3354 | |
| 3355 | @Override |
| 3356 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3357 | boolean isProvisioned) { |
| 3358 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3359 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3360 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3361 | } |
| 3362 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3363 | "setProvisioningStatusForCapability"); |
| 3364 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3365 | // If the current provisioning status for capability already matches isProvisioned, |
| 3366 | // do nothing. |
| 3367 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3368 | return; |
| 3369 | } |
| 3370 | if (isProvisioned) { |
| 3371 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3372 | } else { |
| 3373 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | /** |
| 3378 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3379 | * technology. The bitfield should mirror the bitfield defined by |
| 3380 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3381 | */ |
| 3382 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3383 | String key = getMmTelProvisioningKey(subId, tech); |
| 3384 | // Default is no capabilities are provisioned. |
| 3385 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3386 | } |
| 3387 | |
| 3388 | /** |
| 3389 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3390 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3391 | * technology specified. |
| 3392 | * |
| 3393 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3394 | */ |
| 3395 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3396 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3397 | String key = getMmTelProvisioningKey(subId, tech); |
| 3398 | editor.putInt(key, newField); |
| 3399 | editor.commit(); |
| 3400 | } |
| 3401 | |
| 3402 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3403 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3404 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3405 | } |
| 3406 | |
| 3407 | /** |
| 3408 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3409 | * carrier associated with the subscription id. |
| 3410 | */ |
| 3411 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3412 | int capability) { |
| 3413 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3414 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3415 | boolean requireUtProvisioning = c.getBoolean( |
| 3416 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3417 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3418 | // the no-SIM case, where we would normally shortcut this to false. |
| 3419 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3420 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3421 | false); |
| 3422 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3423 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3424 | |
| 3425 | // First check to make sure that the capability requires provisioning. |
| 3426 | switch (capability) { |
| 3427 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3428 | // intentional fallthrough |
| 3429 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3430 | if (requireVoiceVtProvisioning) { |
| 3431 | // Voice and Video requires provisioning |
| 3432 | return true; |
| 3433 | } |
| 3434 | break; |
| 3435 | } |
| 3436 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3437 | if (requireUtProvisioning) { |
| 3438 | // UT requires provisioning |
| 3439 | return true; |
| 3440 | } |
| 3441 | break; |
| 3442 | } |
| 3443 | } |
| 3444 | return false; |
| 3445 | } |
| 3446 | |
| 3447 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3448 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3449 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3450 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3451 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3452 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3453 | final long identity = Binder.clearCallingIdentity(); |
| 3454 | try { |
| 3455 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3456 | int slotId = getSlotIndex(subId); |
| 3457 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3458 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3459 | + subId + "' for key:" + key); |
| 3460 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3461 | } |
| 3462 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3463 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3464 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3465 | + subId + "' for key:" + key); |
| 3466 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3467 | } finally { |
| 3468 | Binder.restoreCallingIdentity(identity); |
| 3469 | } |
| 3470 | } |
| 3471 | |
| 3472 | @Override |
| 3473 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3474 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3475 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3476 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3477 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3478 | final long identity = Binder.clearCallingIdentity(); |
| 3479 | try { |
| 3480 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3481 | int slotId = getSlotIndex(subId); |
| 3482 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3483 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3484 | + subId + "' for key:" + key); |
| 3485 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3486 | } |
| 3487 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3488 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3489 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3490 | + subId + "' for key:" + key); |
| 3491 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3492 | } finally { |
| 3493 | Binder.restoreCallingIdentity(identity); |
| 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | @Override |
| 3498 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3499 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3500 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3501 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3503 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3504 | final long identity = Binder.clearCallingIdentity(); |
| 3505 | try { |
| 3506 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3507 | int slotId = getSlotIndex(subId); |
| 3508 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3509 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3510 | + subId + "' for key:" + key); |
| 3511 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3512 | } |
| 3513 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3514 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3515 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3516 | + "' for key:" + key); |
| 3517 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3518 | } finally { |
| 3519 | Binder.restoreCallingIdentity(identity); |
| 3520 | } |
| 3521 | } |
| 3522 | |
| 3523 | @Override |
| 3524 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3525 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3526 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3527 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3528 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3529 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3530 | final long identity = Binder.clearCallingIdentity(); |
| 3531 | try { |
| 3532 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3533 | int slotId = getSlotIndex(subId); |
| 3534 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3535 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3536 | + subId + "' for key:" + key); |
| 3537 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3538 | } |
| 3539 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3540 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3541 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3542 | + "' for key:" + key); |
| 3543 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3544 | } finally { |
| 3545 | Binder.restoreCallingIdentity(identity); |
| 3546 | } |
| 3547 | } |
| 3548 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3549 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3550 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3551 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3552 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3553 | } |
| 3554 | return slotId; |
| 3555 | } |
| 3556 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3557 | private int getSlotIndex(int subId) { |
| 3558 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3559 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3560 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3561 | } |
| 3562 | return slotId; |
| 3563 | } |
| 3564 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3565 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3566 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3567 | */ |
| 3568 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3569 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3570 | if (getTargetSdk(callingPackage) >= android.os.Build.VERSION_CODES.Q |
| 3571 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
| 3572 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3573 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3574 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3575 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3576 | final long identity = Binder.clearCallingIdentity(); |
| 3577 | try { |
| 3578 | final Phone phone = getPhone(subId); |
| 3579 | if (phone != null) { |
| 3580 | return phone.getServiceState().getDataNetworkType(); |
| 3581 | } else { |
| 3582 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3583 | } |
| 3584 | } finally { |
| 3585 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3586 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | /** |
| 3590 | * Returns the data network type |
| 3591 | */ |
| 3592 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3593 | public int getDataNetworkType(String callingPackage) { |
| 3594 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | /** |
| 3598 | * Returns the data network type for a subId |
| 3599 | */ |
| 3600 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3601 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3602 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3603 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3604 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3605 | } |
| 3606 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3607 | final long identity = Binder.clearCallingIdentity(); |
| 3608 | try { |
| 3609 | final Phone phone = getPhone(subId); |
| 3610 | if (phone != null) { |
| 3611 | return phone.getServiceState().getDataNetworkType(); |
| 3612 | } else { |
| 3613 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3614 | } |
| 3615 | } finally { |
| 3616 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3617 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3621 | * Returns the Voice network type for a subId |
| 3622 | */ |
| 3623 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3624 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3625 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3626 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3627 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3628 | } |
| 3629 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3630 | final long identity = Binder.clearCallingIdentity(); |
| 3631 | try { |
| 3632 | final Phone phone = getPhone(subId); |
| 3633 | if (phone != null) { |
| 3634 | return phone.getServiceState().getVoiceNetworkType(); |
| 3635 | } else { |
| 3636 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3637 | } |
| 3638 | } finally { |
| 3639 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3640 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | /** |
| 3644 | * @return true if a ICC card is present |
| 3645 | */ |
| 3646 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3647 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3648 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3649 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3653 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3654 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3655 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3656 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3657 | final long identity = Binder.clearCallingIdentity(); |
| 3658 | try { |
| 3659 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3660 | if (phone != null) { |
| 3661 | return phone.getIccCard().hasIccCard(); |
| 3662 | } else { |
| 3663 | return false; |
| 3664 | } |
| 3665 | } finally { |
| 3666 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3667 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3668 | } |
| 3669 | |
| 3670 | /** |
| 3671 | * Return if the current radio is LTE on CDMA. This |
| 3672 | * is a tri-state return value as for a period of time |
| 3673 | * the mode may be unknown. |
| 3674 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3675 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3676 | * @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] | 3677 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3678 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3679 | @Override |
| 3680 | public int getLteOnCdmaMode(String callingPackage) { |
| 3681 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3682 | } |
| 3683 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3684 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3685 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3686 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3687 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3688 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3689 | } |
| 3690 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3691 | final long identity = Binder.clearCallingIdentity(); |
| 3692 | try { |
| 3693 | final Phone phone = getPhone(subId); |
| 3694 | if (phone == null) { |
| 3695 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3696 | } else { |
| 3697 | return phone.getLteOnCdmaMode(); |
| 3698 | } |
| 3699 | } finally { |
| 3700 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3701 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3702 | } |
| 3703 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3704 | /** |
| 3705 | * {@hide} |
| 3706 | * Returns Default subId, 0 in the case of single standby. |
| 3707 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3708 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3709 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3712 | private int getSlotForDefaultSubscription() { |
| 3713 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3714 | } |
| 3715 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3716 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3717 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3718 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3719 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3720 | private boolean isActiveSubscription(int subId) { |
| 3721 | return mSubscriptionController.isActiveSubId(subId); |
| 3722 | } |
| 3723 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3724 | /** |
| 3725 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3726 | */ |
| 3727 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3728 | final long identity = Binder.clearCallingIdentity(); |
| 3729 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3730 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3731 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3732 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3733 | } finally { |
| 3734 | Binder.restoreCallingIdentity(identity); |
| 3735 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | /** |
| 3739 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3740 | */ |
| 3741 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3742 | final long identity = Binder.clearCallingIdentity(); |
| 3743 | try { |
| 3744 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3745 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3746 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3747 | } finally { |
| 3748 | Binder.restoreCallingIdentity(identity); |
| 3749 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3750 | } |
| 3751 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3752 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3753 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3754 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3755 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3756 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3757 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3758 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3759 | if (phoneId == -1) { |
| 3760 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3761 | + " does not correspond to an active phone"); |
| 3762 | } |
| 3763 | return PhoneFactory.getPhone(phoneId); |
| 3764 | } |
| 3765 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3766 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3767 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3768 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3769 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3770 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3771 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3772 | if (DBG) { |
| 3773 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3774 | } |
| 3775 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3776 | p2); |
| 3777 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3778 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3779 | |
| 3780 | @Override |
| 3781 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3782 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3783 | enforceModifyPermission(); |
| 3784 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3785 | if (DBG) { |
| 3786 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3787 | } |
| 3788 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3789 | callingPackage, aid, p2); |
| 3790 | } |
| 3791 | |
| 3792 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3793 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3794 | final long identity = Binder.clearCallingIdentity(); |
| 3795 | try { |
| 3796 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3797 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3798 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3799 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3800 | if (bestComponent == null |
| 3801 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3802 | loge("The calling package is not allowed to access ISD-R."); |
| 3803 | throw new SecurityException( |
| 3804 | "The calling package is not allowed to access ISD-R."); |
| 3805 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3806 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3807 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3808 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3809 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3810 | null /* workSource */); |
| 3811 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3812 | return response; |
| 3813 | } finally { |
| 3814 | Binder.restoreCallingIdentity(identity); |
| 3815 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3819 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3820 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3821 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3822 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3823 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3824 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3825 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3826 | @Override |
| 3827 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3828 | enforceModifyPermission(); |
| 3829 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3830 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3831 | channel); |
| 3832 | } |
| 3833 | |
| 3834 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3835 | final long identity = Binder.clearCallingIdentity(); |
| 3836 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3837 | if (channel < 0) { |
| 3838 | return false; |
| 3839 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3840 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3841 | null /* workSource */); |
| 3842 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3843 | return success; |
| 3844 | } finally { |
| 3845 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3846 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3850 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3851 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3852 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3853 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3854 | if (DBG) { |
| 3855 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3856 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3857 | + p3 + " data=" + data); |
| 3858 | } |
| 3859 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3860 | command, p1, p2, p3, data); |
| 3861 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3862 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3863 | @Override |
| 3864 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3865 | int command, int p1, int p2, int p3, String data) { |
| 3866 | enforceModifyPermission(); |
| 3867 | if (DBG) { |
| 3868 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3869 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3870 | + p3 + " data=" + data); |
| 3871 | } |
| 3872 | return iccTransmitApduLogicalChannelWithPermission( |
| 3873 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3874 | data); |
| 3875 | } |
| 3876 | |
| 3877 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3878 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3879 | final long identity = Binder.clearCallingIdentity(); |
| 3880 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 3881 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3882 | return ""; |
| 3883 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3884 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3885 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3886 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3887 | null /* workSource */); |
| 3888 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3889 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3890 | // Append the returned status code to the end of the response payload. |
| 3891 | String s = Integer.toHexString( |
| 3892 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3893 | if (response.payload != null) { |
| 3894 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3895 | } |
| 3896 | return s; |
| 3897 | } finally { |
| 3898 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3899 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3900 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3901 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3902 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3903 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3904 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3905 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3906 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3907 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3908 | if (DBG) { |
| 3909 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3910 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3911 | } |
| 3912 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3913 | cla, command, p1, p2, p3, data); |
| 3914 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3915 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3916 | @Override |
| 3917 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3918 | int command, int p1, int p2, int p3, String data) { |
| 3919 | enforceModifyPermission(); |
| 3920 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3921 | if (DBG) { |
| 3922 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3923 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3924 | + " data=" + data); |
| 3925 | } |
| 3926 | |
| 3927 | return iccTransmitApduBasicChannelWithPermission( |
| 3928 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3929 | p2, p3, data); |
| 3930 | } |
| 3931 | |
| 3932 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3933 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3934 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3935 | final long identity = Binder.clearCallingIdentity(); |
| 3936 | try { |
| 3937 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3938 | && TextUtils.equals(ISDR_AID, data)) { |
| 3939 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3940 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3941 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3942 | if (bestComponent == null |
| 3943 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3944 | loge("The calling package is not allowed to select ISD-R."); |
| 3945 | throw new SecurityException( |
| 3946 | "The calling package is not allowed to select ISD-R."); |
| 3947 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3948 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3949 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3950 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3951 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 3952 | null /* workSource */); |
| 3953 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3954 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3955 | // Append the returned status code to the end of the response payload. |
| 3956 | String s = Integer.toHexString( |
| 3957 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3958 | if (response.payload != null) { |
| 3959 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3960 | } |
| 3961 | return s; |
| 3962 | } finally { |
| 3963 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3964 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3968 | 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] | 3969 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3970 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3971 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3972 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3973 | final long identity = Binder.clearCallingIdentity(); |
| 3974 | try { |
| 3975 | if (DBG) { |
| 3976 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3977 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3978 | } |
| 3979 | |
| 3980 | IccIoResult response = |
| 3981 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3982 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3983 | subId); |
| 3984 | |
| 3985 | if (DBG) { |
| 3986 | log("Exchange SIM_IO [R]" + response); |
| 3987 | } |
| 3988 | |
| 3989 | byte[] result = null; |
| 3990 | int length = 2; |
| 3991 | if (response.payload != null) { |
| 3992 | length = 2 + response.payload.length; |
| 3993 | result = new byte[length]; |
| 3994 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3995 | } else { |
| 3996 | result = new byte[length]; |
| 3997 | } |
| 3998 | |
| 3999 | result[length - 1] = (byte) response.sw2; |
| 4000 | result[length - 2] = (byte) response.sw1; |
| 4001 | return result; |
| 4002 | } finally { |
| 4003 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4004 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4005 | } |
| 4006 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4007 | /** |
| 4008 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4009 | * on a particular subscription |
| 4010 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4011 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 4012 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4013 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 4014 | return null; |
| 4015 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4016 | |
| 4017 | final long identity = Binder.clearCallingIdentity(); |
| 4018 | try { |
| 4019 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4020 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4021 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4022 | return null; |
| 4023 | } |
| 4024 | Object response = sendRequest( |
| 4025 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4026 | if (response instanceof String[]) { |
| 4027 | return (String[]) response; |
| 4028 | } |
| 4029 | // Response is an Exception of some kind, |
| 4030 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4031 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4032 | } finally { |
| 4033 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4034 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4035 | } |
| 4036 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4037 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4038 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4039 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4040 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4041 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4042 | final long identity = Binder.clearCallingIdentity(); |
| 4043 | try { |
| 4044 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4045 | if (response.payload == null) { |
| 4046 | return ""; |
| 4047 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4048 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4049 | // Append the returned status code to the end of the response payload. |
| 4050 | String s = Integer.toHexString( |
| 4051 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4052 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4053 | return s; |
| 4054 | } finally { |
| 4055 | Binder.restoreCallingIdentity(identity); |
| 4056 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4057 | } |
| 4058 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4059 | /** |
| 4060 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4061 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4062 | * |
| 4063 | * @param itemID the ID of the item to read |
| 4064 | * @return the NV item as a String, or null on error. |
| 4065 | */ |
| 4066 | @Override |
| 4067 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4068 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4069 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4070 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4071 | |
| 4072 | final long identity = Binder.clearCallingIdentity(); |
| 4073 | try { |
| 4074 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4075 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4076 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4077 | return value; |
| 4078 | } finally { |
| 4079 | Binder.restoreCallingIdentity(identity); |
| 4080 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | /** |
| 4084 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4085 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4086 | * |
| 4087 | * @param itemID the ID of the item to read |
| 4088 | * @param itemValue the value to write, as a String |
| 4089 | * @return true on success; false on any failure |
| 4090 | */ |
| 4091 | @Override |
| 4092 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4093 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4095 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4096 | |
| 4097 | final long identity = Binder.clearCallingIdentity(); |
| 4098 | try { |
| 4099 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4100 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4101 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4102 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4103 | return success; |
| 4104 | } finally { |
| 4105 | Binder.restoreCallingIdentity(identity); |
| 4106 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4107 | } |
| 4108 | |
| 4109 | /** |
| 4110 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4111 | * Used for device configuration by some CDMA operators. |
| 4112 | * |
| 4113 | * @param preferredRoamingList byte array containing the new PRL |
| 4114 | * @return true on success; false on any failure |
| 4115 | */ |
| 4116 | @Override |
| 4117 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4118 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4119 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4120 | |
| 4121 | final long identity = Binder.clearCallingIdentity(); |
| 4122 | try { |
| 4123 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4124 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4125 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4126 | return success; |
| 4127 | } finally { |
| 4128 | Binder.restoreCallingIdentity(identity); |
| 4129 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4130 | } |
| 4131 | |
| 4132 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4133 | * 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] | 4134 | * Used for device configuration by some CDMA operators. |
| 4135 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4136 | * @param slotIndex - device slot. |
| 4137 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4138 | * @return true on success; false on any failure |
| 4139 | */ |
| 4140 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4141 | public boolean resetModemConfig(int slotIndex) { |
| 4142 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4143 | if (phone != null) { |
| 4144 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4145 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4146 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4147 | final long identity = Binder.clearCallingIdentity(); |
| 4148 | try { |
| 4149 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4150 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4151 | return success; |
| 4152 | } finally { |
| 4153 | Binder.restoreCallingIdentity(identity); |
| 4154 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4155 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4156 | return false; |
| 4157 | } |
| 4158 | |
| 4159 | /** |
| 4160 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4161 | * |
| 4162 | * @param slotIndex - device slot. |
| 4163 | * |
| 4164 | * @return true on success; false on any failure |
| 4165 | */ |
| 4166 | @Override |
| 4167 | public boolean rebootModem(int slotIndex) { |
| 4168 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4169 | if (phone != null) { |
| 4170 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4171 | mApp, phone.getSubId(), "rebootModem"); |
| 4172 | |
| 4173 | final long identity = Binder.clearCallingIdentity(); |
| 4174 | try { |
| 4175 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4176 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4177 | return success; |
| 4178 | } finally { |
| 4179 | Binder.restoreCallingIdentity(identity); |
| 4180 | } |
| 4181 | } |
| 4182 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4183 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4184 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4185 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4186 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4187 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4188 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4189 | return new String[0]; |
| 4190 | } |
| 4191 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4192 | final long identity = Binder.clearCallingIdentity(); |
| 4193 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4194 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4195 | } finally { |
| 4196 | Binder.restoreCallingIdentity(identity); |
| 4197 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4198 | } |
| 4199 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4200 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4201 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4202 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4203 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4204 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4205 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4206 | |
| 4207 | final long identity = Binder.clearCallingIdentity(); |
| 4208 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4209 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4210 | if (resolver == null) { |
| 4211 | // may happen if the device does not support IMS. |
| 4212 | return; |
| 4213 | } |
| 4214 | resolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4215 | } finally { |
| 4216 | Binder.restoreCallingIdentity(identity); |
| 4217 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4218 | } |
| 4219 | |
| 4220 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4221 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4222 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4223 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4224 | public void disableIms(int slotId) { |
| 4225 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4226 | |
| 4227 | final long identity = Binder.clearCallingIdentity(); |
| 4228 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4229 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4230 | if (resolver == null) { |
| 4231 | // may happen if the device does not support IMS. |
| 4232 | return; |
| 4233 | } |
| 4234 | resolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4235 | } finally { |
| 4236 | Binder.restoreCallingIdentity(identity); |
| 4237 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4238 | } |
| 4239 | |
| 4240 | /** |
| 4241 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4242 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4243 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4244 | */ |
| 4245 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4246 | IImsServiceFeatureCallback callback) { |
| 4247 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4248 | |
| 4249 | final long identity = Binder.clearCallingIdentity(); |
| 4250 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4251 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4252 | if (resolver == null) { |
| 4253 | // may happen if the device does not support IMS. |
| 4254 | return null; |
| 4255 | } |
| 4256 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4257 | } finally { |
| 4258 | Binder.restoreCallingIdentity(identity); |
| 4259 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4260 | } |
| 4261 | |
| 4262 | /** |
| 4263 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4264 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4265 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4266 | * listener for feature updates. |
| 4267 | */ |
| 4268 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4269 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4270 | |
| 4271 | final long identity = Binder.clearCallingIdentity(); |
| 4272 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4273 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4274 | if (resolver == null) { |
| 4275 | // may happen if the device does not support IMS. |
| 4276 | return null; |
| 4277 | } |
| 4278 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4279 | } finally { |
| 4280 | Binder.restoreCallingIdentity(identity); |
| 4281 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4282 | } |
| 4283 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4284 | /** |
| 4285 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4286 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4287 | */ |
| 4288 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4289 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4290 | |
| 4291 | final long identity = Binder.clearCallingIdentity(); |
| 4292 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4293 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4294 | if (resolver == null) { |
| 4295 | // may happen if the device does not support IMS. |
| 4296 | return null; |
| 4297 | } |
| 4298 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4299 | } finally { |
| 4300 | Binder.restoreCallingIdentity(identity); |
| 4301 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4302 | } |
| 4303 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4304 | /** |
| 4305 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4306 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4307 | */ |
| 4308 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4309 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4310 | |
| 4311 | final long identity = Binder.clearCallingIdentity(); |
| 4312 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4313 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4314 | if (resolver == null) { |
| 4315 | // may happen if the device does not support IMS. |
| 4316 | return null; |
| 4317 | } |
| 4318 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4319 | } finally { |
| 4320 | Binder.restoreCallingIdentity(identity); |
| 4321 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4322 | } |
| 4323 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4324 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4325 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4326 | * |
| 4327 | * @param slotId the slot ID that the ImsService should bind for. |
| 4328 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4329 | * ImsService is the device default ImsService. |
| 4330 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4331 | * to. |
| 4332 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4333 | * @hide |
| 4334 | */ |
| 4335 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4336 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4337 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4338 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4339 | "setImsService"); |
| 4340 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4341 | final long identity = Binder.clearCallingIdentity(); |
| 4342 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4343 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4344 | if (resolver == null) { |
| 4345 | // may happen if the device does not support IMS. |
| 4346 | return false; |
| 4347 | } |
| 4348 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4349 | packageName); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4350 | } finally { |
| 4351 | Binder.restoreCallingIdentity(identity); |
| 4352 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4353 | } |
| 4354 | |
| 4355 | /** |
| 4356 | * Return the ImsService configuration. |
| 4357 | * |
| 4358 | * @param slotId The slot that the ImsService is associated with. |
| 4359 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4360 | * the device default. |
| 4361 | * @return the package name of the ImsService configuration. |
| 4362 | */ |
| 4363 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4364 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4365 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4366 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4367 | "getImsService"); |
| 4368 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4369 | final long identity = Binder.clearCallingIdentity(); |
| 4370 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4371 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4372 | if (resolver == null) { |
| 4373 | // may happen if the device does not support IMS. |
| 4374 | return ""; |
| 4375 | } |
| 4376 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4377 | } finally { |
| 4378 | Binder.restoreCallingIdentity(identity); |
| 4379 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4380 | } |
| 4381 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4382 | public void setImsRegistrationState(boolean registered) { |
| 4383 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4384 | |
| 4385 | final long identity = Binder.clearCallingIdentity(); |
| 4386 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4387 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4388 | } finally { |
| 4389 | Binder.restoreCallingIdentity(identity); |
| 4390 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4391 | } |
| 4392 | |
| 4393 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4394 | * Set the network selection mode to automatic. |
| 4395 | * |
| 4396 | */ |
| 4397 | @Override |
| 4398 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4399 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4400 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4401 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4402 | if (!isActiveSubscription(subId)) { |
| 4403 | return; |
| 4404 | } |
| 4405 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4406 | final long identity = Binder.clearCallingIdentity(); |
| 4407 | try { |
| 4408 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4409 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4410 | } finally { |
| 4411 | Binder.restoreCallingIdentity(identity); |
| 4412 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4413 | } |
| 4414 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4415 | /** |
| 4416 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4417 | * |
| 4418 | * @param subId the id of the subscription. |
| 4419 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4420 | * the operator to attach to. |
| 4421 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4422 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4423 | * normal network selection next time. |
| 4424 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4425 | */ |
| 4426 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4427 | public boolean setNetworkSelectionModeManual( |
| 4428 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4429 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4430 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4431 | |
| 4432 | if (!isActiveSubscription(subId)) { |
| 4433 | return false; |
| 4434 | } |
| 4435 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4436 | final long identity = Binder.clearCallingIdentity(); |
| 4437 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4438 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4439 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4440 | if (DBG) { |
| 4441 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4442 | + " operator: " + operatorInfo); |
| 4443 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4444 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4445 | } finally { |
| 4446 | Binder.restoreCallingIdentity(identity); |
| 4447 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4448 | } |
| 4449 | |
| 4450 | /** |
| 4451 | * Scans for available networks. |
| 4452 | */ |
| 4453 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4454 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4456 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4457 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4458 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4459 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4460 | .setCallingPackage(callingPackage) |
| 4461 | .setCallingPid(Binder.getCallingPid()) |
| 4462 | .setCallingUid(Binder.getCallingUid()) |
| 4463 | .setMethod("getCellNetworkScanResults") |
| 4464 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4465 | .build()); |
| 4466 | switch (locationResult) { |
| 4467 | case DENIED_HARD: |
| 4468 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4469 | case DENIED_SOFT: |
| 4470 | return null; |
| 4471 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4472 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4473 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4474 | try { |
| 4475 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4476 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4477 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4478 | } finally { |
| 4479 | Binder.restoreCallingIdentity(identity); |
| 4480 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4481 | } |
| 4482 | |
| 4483 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4484 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4485 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4486 | * @param subId id of the subscription |
| 4487 | * @param request contains the radio access networks with bands/channels to scan |
| 4488 | * @param messenger callback messenger for scan results or errors |
| 4489 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4490 | * @return the id of the requested scan which can be used to stop the scan. |
| 4491 | */ |
| 4492 | @Override |
| 4493 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4494 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4495 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4496 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4497 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4498 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4499 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4500 | .setCallingPackage(callingPackage) |
| 4501 | .setCallingPid(Binder.getCallingPid()) |
| 4502 | .setCallingUid(Binder.getCallingUid()) |
| 4503 | .setMethod("requestNetworkScan") |
| 4504 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4505 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4506 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4507 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4508 | if (e != null) { |
| 4509 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4510 | throw e; |
| 4511 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4512 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4513 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4514 | } |
| 4515 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4516 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4517 | int callingUid = Binder.getCallingUid(); |
| 4518 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4519 | final long identity = Binder.clearCallingIdentity(); |
| 4520 | try { |
| 4521 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4522 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4523 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4524 | } finally { |
| 4525 | Binder.restoreCallingIdentity(identity); |
| 4526 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4529 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4530 | NetworkScanRequest request, int subId) { |
| 4531 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4532 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4533 | boolean hasNetworkScanPermission = |
| 4534 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4535 | == PERMISSION_GRANTED; |
| 4536 | |
| 4537 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4538 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4539 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4540 | } |
| 4541 | |
| 4542 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4543 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4544 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4545 | return new SecurityException("Specific channels must not be" |
| 4546 | + " scanned without location access."); |
| 4547 | } |
| 4548 | } |
| 4549 | } |
| 4550 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4551 | return null; |
| 4552 | } |
| 4553 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4554 | /** |
| 4555 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4556 | * |
| 4557 | * @param subId id of the subscription |
| 4558 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4559 | */ |
| 4560 | @Override |
| 4561 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4562 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4563 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4564 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4565 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4566 | final long identity = Binder.clearCallingIdentity(); |
| 4567 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4568 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4569 | } finally { |
| 4570 | Binder.restoreCallingIdentity(identity); |
| 4571 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4572 | } |
| 4573 | |
| 4574 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4575 | * Get the calculated preferred network type. |
| 4576 | * Used for debugging incorrect network type. |
| 4577 | * |
| 4578 | * @return the preferred network type, defined in RILConstants.java. |
| 4579 | */ |
| 4580 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4581 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4582 | final Phone defaultPhone = getDefaultPhone(); |
| 4583 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4584 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4585 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4586 | } |
| 4587 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4588 | final long identity = Binder.clearCallingIdentity(); |
| 4589 | try { |
| 4590 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4591 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4592 | } finally { |
| 4593 | Binder.restoreCallingIdentity(identity); |
| 4594 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4595 | } |
| 4596 | |
| 4597 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4598 | * Get the preferred network type. |
| 4599 | * Used for device configuration by some CDMA operators. |
| 4600 | * |
| 4601 | * @return the preferred network type, defined in RILConstants.java. |
| 4602 | */ |
| 4603 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4604 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4605 | TelephonyPermissions |
| 4606 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4607 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4608 | |
| 4609 | final long identity = Binder.clearCallingIdentity(); |
| 4610 | try { |
| 4611 | if (DBG) log("getPreferredNetworkType"); |
| 4612 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4613 | int networkType = (result != null ? result[0] : -1); |
| 4614 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4615 | return networkType; |
| 4616 | } finally { |
| 4617 | Binder.restoreCallingIdentity(identity); |
| 4618 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4619 | } |
| 4620 | |
| 4621 | /** |
| 4622 | * Set the preferred network type. |
| 4623 | * Used for device configuration by some CDMA operators. |
| 4624 | * |
| 4625 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4626 | * @return true on success; false on any failure. |
| 4627 | */ |
| 4628 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4629 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4631 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4632 | |
| 4633 | final long identity = Binder.clearCallingIdentity(); |
| 4634 | try { |
| 4635 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4636 | Boolean success = (Boolean) sendRequest( |
| 4637 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4638 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4639 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4640 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4641 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4642 | } |
| 4643 | return success; |
| 4644 | } finally { |
| 4645 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4646 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4647 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4648 | |
| 4649 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4650 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4651 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4652 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4653 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4654 | * @hide |
| 4655 | */ |
| 4656 | @Override |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4657 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4658 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4659 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4660 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4661 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4662 | if (phone != null) { |
| 4663 | return phone.hasMatchedTetherApnSetting(); |
| 4664 | } else { |
| 4665 | return false; |
| 4666 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4667 | } finally { |
| 4668 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4669 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4670 | } |
| 4671 | |
| 4672 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4673 | * Set mobile data enabled |
| 4674 | * Used by the user through settings etc to turn on/off mobile data |
| 4675 | * |
| 4676 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4677 | */ |
| 4678 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4679 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4680 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4681 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4682 | |
| 4683 | final long identity = Binder.clearCallingIdentity(); |
| 4684 | try { |
| 4685 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4686 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4687 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4688 | if (phone != null) { |
| 4689 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4690 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4691 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4692 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4693 | } |
| 4694 | } finally { |
| 4695 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4696 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4700 | * Get the user enabled state of Mobile Data. |
| 4701 | * |
| 4702 | * TODO: remove and use isUserDataEnabled. |
| 4703 | * This can't be removed now because some vendor codes |
| 4704 | * calls through ITelephony directly while they should |
| 4705 | * use TelephonyManager. |
| 4706 | * |
| 4707 | * @return true on enabled |
| 4708 | */ |
| 4709 | @Override |
| 4710 | public boolean getDataEnabled(int subId) { |
| 4711 | return isUserDataEnabled(subId); |
| 4712 | } |
| 4713 | |
| 4714 | /** |
| 4715 | * Get whether mobile data is enabled per user setting. |
| 4716 | * |
| 4717 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4718 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4719 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4720 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4721 | * |
| 4722 | * @return {@code true} if data is enabled else {@code false} |
| 4723 | */ |
| 4724 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4725 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4726 | try { |
| 4727 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4728 | null); |
| 4729 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4730 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4731 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4732 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4733 | |
| 4734 | final long identity = Binder.clearCallingIdentity(); |
| 4735 | try { |
| 4736 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4737 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4738 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4739 | if (phone != null) { |
| 4740 | boolean retVal = phone.isUserDataEnabled(); |
| 4741 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4742 | return retVal; |
| 4743 | } else { |
| 4744 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4745 | return false; |
| 4746 | } |
| 4747 | } finally { |
| 4748 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4749 | } |
| 4750 | } |
| 4751 | |
| 4752 | /** |
| 4753 | * Get whether mobile data is enabled. |
| 4754 | * |
| 4755 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4756 | * whether mobile data is actually enabled. |
| 4757 | * |
| 4758 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4759 | * |
| 4760 | * @return {@code true} if data is enabled else {@code false} |
| 4761 | */ |
| 4762 | @Override |
| 4763 | public boolean isDataEnabled(int subId) { |
| 4764 | try { |
| 4765 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4766 | null); |
| 4767 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4768 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4769 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4770 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4771 | |
| 4772 | final long identity = Binder.clearCallingIdentity(); |
| 4773 | try { |
| 4774 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4775 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4776 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4777 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4778 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4779 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4780 | return retVal; |
| 4781 | } else { |
| 4782 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4783 | return false; |
| 4784 | } |
| 4785 | } finally { |
| 4786 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4787 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4788 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4789 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4790 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 4791 | Phone phone) { |
| 4792 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 4793 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 4794 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 4795 | || subController == null) return privilegeFromSim; |
| 4796 | |
| 4797 | int uid = Binder.getCallingUid(); |
| 4798 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 4799 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 4800 | |
| 4801 | final long identity = Binder.clearCallingIdentity(); |
| 4802 | try { |
| 4803 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 4804 | SubscriptionManager subManager = (SubscriptionManager) |
| 4805 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 4806 | for (String pkg : packages) { |
| 4807 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 4808 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4809 | } |
| 4810 | } |
| 4811 | return privilegeFromSim; |
| 4812 | } finally { |
| 4813 | Binder.restoreCallingIdentity(identity); |
| 4814 | } |
| 4815 | } |
| 4816 | |
| 4817 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 4818 | String pkgName) { |
| 4819 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 4820 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 4821 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 4822 | || subController == null) return privilegeFromSim; |
| 4823 | |
| 4824 | final long identity = Binder.clearCallingIdentity(); |
| 4825 | try { |
| 4826 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 4827 | SubscriptionManager subManager = (SubscriptionManager) |
| 4828 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 4829 | return subManager.canManageSubscription(subInfo, pkgName) |
| 4830 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 4831 | } finally { |
| 4832 | Binder.restoreCallingIdentity(identity); |
| 4833 | } |
| 4834 | } |
| 4835 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4836 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4837 | public int getCarrierPrivilegeStatus(int subId) { |
| 4838 | final Phone phone = getPhone(subId); |
| 4839 | if (phone == null) { |
| 4840 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4841 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4842 | } |
| 4843 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4844 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4845 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4846 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4847 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4848 | |
| 4849 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4850 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 4851 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4852 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4853 | |
| 4854 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4855 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4856 | final Phone phone = getPhone(subId); |
| 4857 | if (phone == null) { |
| 4858 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4859 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4860 | } |
| 4861 | UiccProfile profile = |
| 4862 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4863 | if (profile == null) { |
| 4864 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4865 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4866 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4867 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4868 | profile.getCarrierPrivilegeStatusForUid( |
| 4869 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4870 | } |
| 4871 | |
| 4872 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4873 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 4874 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4875 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4876 | } |
| 4877 | |
| 4878 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 4879 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4880 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4881 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4882 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4883 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4884 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4885 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 4886 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4887 | } |
| 4888 | |
| 4889 | @Override |
| 4890 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4891 | if (TextUtils.isEmpty(pkgName)) |
| 4892 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4893 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4894 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4895 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4896 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4897 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4898 | continue; |
| 4899 | } |
| 4900 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4901 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4902 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 4903 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4904 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4905 | break; |
| 4906 | } |
| 4907 | } |
| 4908 | |
| 4909 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4910 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4911 | |
| 4912 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4913 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4914 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4915 | loge("phoneId " + phoneId + " is not valid."); |
| 4916 | return null; |
| 4917 | } |
| 4918 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4919 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4920 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4921 | return null ; |
| 4922 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4923 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4924 | } |
| 4925 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4926 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4927 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4928 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4929 | List<String> privilegedPackages = new ArrayList<>(); |
| 4930 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4931 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 4932 | // has UICC in that slot. |
| 4933 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4934 | if (card.hasCarrierPrivilegeRules()) { |
| 4935 | if (packages == null) { |
| 4936 | // Only check packages in user 0 for now |
| 4937 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4938 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4939 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 4940 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 4941 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4942 | } |
| 4943 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4944 | PackageInfo pkgInfo = packages.get(p); |
| 4945 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4946 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4947 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4948 | privilegedPackages.add(pkgInfo.packageName); |
| 4949 | } |
| 4950 | } |
| 4951 | } |
| 4952 | } |
| 4953 | return privilegedPackages; |
| 4954 | } |
| 4955 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4956 | @Override |
| 4957 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
| 4958 | List<String> privilegedPackages = new ArrayList<>(); |
| 4959 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4960 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 4961 | } |
| 4962 | return privilegedPackages; |
| 4963 | } |
| 4964 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4965 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4966 | final Phone phone = getPhone(subId); |
| 4967 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4968 | if (card == null) { |
| 4969 | loge("getIccId: No UICC"); |
| 4970 | return null; |
| 4971 | } |
| 4972 | String iccId = card.getIccId(); |
| 4973 | if (TextUtils.isEmpty(iccId)) { |
| 4974 | loge("getIccId: ICC ID is null or empty."); |
| 4975 | return null; |
| 4976 | } |
| 4977 | return iccId; |
| 4978 | } |
| 4979 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4980 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4981 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4982 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4983 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4984 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4985 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4986 | final long identity = Binder.clearCallingIdentity(); |
| 4987 | try { |
| 4988 | final String iccId = getIccId(subId); |
| 4989 | final Phone phone = getPhone(subId); |
| 4990 | if (phone == null) { |
| 4991 | return false; |
| 4992 | } |
| 4993 | final String subscriberId = phone.getSubscriberId(); |
| 4994 | |
| 4995 | if (DBG_MERGE) { |
| 4996 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4997 | + subscriberId + " to " + number); |
| 4998 | } |
| 4999 | |
| 5000 | if (TextUtils.isEmpty(iccId)) { |
| 5001 | return false; |
| 5002 | } |
| 5003 | |
| 5004 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5005 | |
| 5006 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5007 | if (alphaTag == null) { |
| 5008 | editor.remove(alphaTagPrefKey); |
| 5009 | } else { |
| 5010 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5011 | } |
| 5012 | |
| 5013 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5014 | // track all merged IMSIs based on line number |
| 5015 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5016 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5017 | if (number == null) { |
| 5018 | editor.remove(numberPrefKey); |
| 5019 | editor.remove(subscriberPrefKey); |
| 5020 | } else { |
| 5021 | editor.putString(numberPrefKey, number); |
| 5022 | editor.putString(subscriberPrefKey, subscriberId); |
| 5023 | } |
| 5024 | |
| 5025 | editor.commit(); |
| 5026 | return true; |
| 5027 | } finally { |
| 5028 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5029 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5033 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5034 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5035 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5036 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5037 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5038 | return null; |
| 5039 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5040 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5041 | final long identity = Binder.clearCallingIdentity(); |
| 5042 | try { |
| 5043 | String iccId = getIccId(subId); |
| 5044 | if (iccId != null) { |
| 5045 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5046 | if (DBG_MERGE) { |
| 5047 | log("getLine1NumberForDisplay returning " |
| 5048 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5049 | } |
| 5050 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5051 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5052 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5053 | return null; |
| 5054 | } finally { |
| 5055 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5056 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5057 | } |
| 5058 | |
| 5059 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5060 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5061 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5062 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5063 | return null; |
| 5064 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5065 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5066 | final long identity = Binder.clearCallingIdentity(); |
| 5067 | try { |
| 5068 | String iccId = getIccId(subId); |
| 5069 | if (iccId != null) { |
| 5070 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5071 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5072 | } |
| 5073 | return null; |
| 5074 | } finally { |
| 5075 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5076 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5077 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5078 | |
| 5079 | @Override |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5080 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5081 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5082 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5083 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5084 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 5085 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5086 | return null; |
| 5087 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5088 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5089 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5090 | // the process, where TelephonyManager was instantiated. |
| 5091 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5092 | final long identity = Binder.clearCallingIdentity(); |
| 5093 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5094 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5095 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5096 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5097 | |
| 5098 | // Figure out what subscribers are currently active |
| 5099 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5100 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5101 | // Only consider subs which match the current subId |
| 5102 | // This logic can be simplified. See b/131189269 for progress. |
| 5103 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5104 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5105 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5106 | |
| 5107 | // First pass, find a number override for an active subscriber |
| 5108 | String mergeNumber = null; |
| 5109 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5110 | for (String key : prefs.keySet()) { |
| 5111 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5112 | final String subscriberId = (String) prefs.get(key); |
| 5113 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5114 | final String iccId = key.substring( |
| 5115 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5116 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5117 | mergeNumber = (String) prefs.get(numberKey); |
| 5118 | if (DBG_MERGE) { |
| 5119 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5120 | + " for active subscriber " + subscriberId); |
| 5121 | } |
| 5122 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5123 | break; |
| 5124 | } |
| 5125 | } |
| 5126 | } |
| 5127 | } |
| 5128 | |
| 5129 | // Shortcut when no active merged subscribers |
| 5130 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5131 | return null; |
| 5132 | } |
| 5133 | |
| 5134 | // Second pass, find all subscribers under that line override |
| 5135 | final ArraySet<String> result = new ArraySet<>(); |
| 5136 | for (String key : prefs.keySet()) { |
| 5137 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5138 | final String number = (String) prefs.get(key); |
| 5139 | if (mergeNumber.equals(number)) { |
| 5140 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5141 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5142 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5143 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5144 | result.add(subscriberId); |
| 5145 | } |
| 5146 | } |
| 5147 | } |
| 5148 | } |
| 5149 | |
| 5150 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5151 | Arrays.sort(resultArray); |
| 5152 | if (DBG_MERGE) { |
| 5153 | Slog.d(LOG_TAG, |
| 5154 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5155 | } |
| 5156 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5157 | } finally { |
| 5158 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5159 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5160 | } |
| 5161 | |
| 5162 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5163 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 5164 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 5165 | |
| 5166 | final long identity = Binder.clearCallingIdentity(); |
| 5167 | try { |
| 5168 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5169 | TelephonyManager.class); |
| 5170 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5171 | if (subscriberId == null) { |
| 5172 | if (DBG) { |
| 5173 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 5174 | + subId); |
| 5175 | } |
| 5176 | return null; |
| 5177 | } |
| 5178 | |
| 5179 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5180 | .getSubscriptionInfo(subId); |
| 5181 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5182 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5183 | if (groupUuid == null) { |
| 5184 | return new String[]{subscriberId}; |
| 5185 | } |
| 5186 | |
| 5187 | // Get all subscriberIds from the group. |
| 5188 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5189 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
| 5190 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName()); |
| 5191 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5192 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5193 | if (subscriberId != null) { |
| 5194 | mergedSubscriberIds.add(subscriberId); |
| 5195 | } |
| 5196 | } |
| 5197 | |
| 5198 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5199 | } finally { |
| 5200 | Binder.restoreCallingIdentity(identity); |
| 5201 | |
| 5202 | } |
| 5203 | } |
| 5204 | |
| 5205 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5206 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5207 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5208 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5209 | |
| 5210 | final long identity = Binder.clearCallingIdentity(); |
| 5211 | try { |
| 5212 | final Phone phone = getPhone(subId); |
| 5213 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5214 | } finally { |
| 5215 | Binder.restoreCallingIdentity(identity); |
| 5216 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5217 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5218 | |
| 5219 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5220 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5221 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5222 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5223 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5224 | |
| 5225 | final long identity = Binder.clearCallingIdentity(); |
| 5226 | try { |
| 5227 | final Phone phone = getPhone(subId); |
| 5228 | if (phone == null) { |
| 5229 | return false; |
| 5230 | } |
| 5231 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5232 | cdmaNonRoamingList); |
| 5233 | } finally { |
| 5234 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5235 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5236 | } |
| 5237 | |
| 5238 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5239 | @Deprecated |
| 5240 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5241 | enforceModifyPermission(); |
| 5242 | |
| 5243 | int returnValue = 0; |
| 5244 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5245 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5246 | if(result.exception == null) { |
| 5247 | if (result.result != null) { |
| 5248 | byte[] responseData = (byte[])(result.result); |
| 5249 | if(responseData.length > oemResp.length) { |
| 5250 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5251 | responseData.length + "bytes. Buffer Size is " + |
| 5252 | oemResp.length + "bytes."); |
| 5253 | } |
| 5254 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5255 | returnValue = responseData.length; |
| 5256 | } |
| 5257 | } else { |
| 5258 | CommandException ex = (CommandException) result.exception; |
| 5259 | returnValue = ex.getCommandError().ordinal(); |
| 5260 | if(returnValue > 0) returnValue *= -1; |
| 5261 | } |
| 5262 | } catch (RuntimeException e) { |
| 5263 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5264 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5265 | if(returnValue > 0) returnValue *= -1; |
| 5266 | } |
| 5267 | |
| 5268 | return returnValue; |
| 5269 | } |
| 5270 | |
| 5271 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5272 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5273 | try { |
| 5274 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5275 | } catch (RuntimeException e) { |
| 5276 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5277 | } |
| 5278 | } |
| 5279 | |
| 5280 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5281 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5282 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5283 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5284 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5285 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5286 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5287 | final long identity = Binder.clearCallingIdentity(); |
| 5288 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5289 | TelephonyPermissions |
| 5290 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5291 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5292 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5293 | } finally { |
| 5294 | Binder.restoreCallingIdentity(identity); |
| 5295 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5296 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5297 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5298 | |
| 5299 | @Override |
| 5300 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5301 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5302 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5303 | |
| 5304 | final long identity = Binder.clearCallingIdentity(); |
| 5305 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5306 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5307 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5308 | } finally { |
| 5309 | Binder.restoreCallingIdentity(identity); |
| 5310 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5311 | } |
| 5312 | |
| 5313 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5314 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5315 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5316 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5317 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5318 | return false; |
| 5319 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5320 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5321 | final long identity = Binder.clearCallingIdentity(); |
| 5322 | try { |
| 5323 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5324 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5325 | // In the long run, we may instead need to check if there exists a connection service |
| 5326 | // which can support video calling. |
| 5327 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5328 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5329 | return imsManager.isVtEnabledByPlatform() |
| 5330 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5331 | && imsManager.isVtEnabledByUser(); |
| 5332 | } finally { |
| 5333 | Binder.restoreCallingIdentity(identity); |
| 5334 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5335 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5336 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5337 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5338 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5339 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5340 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5341 | return false; |
| 5342 | } |
| 5343 | |
| 5344 | final long identity = Binder.clearCallingIdentity(); |
| 5345 | try { |
| 5346 | CarrierConfigManager configManager = |
| 5347 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5348 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5349 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5350 | } finally { |
| 5351 | Binder.restoreCallingIdentity(identity); |
| 5352 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5353 | } |
| 5354 | |
| 5355 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5356 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5357 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5358 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5359 | return false; |
| 5360 | } |
| 5361 | |
| 5362 | final long identity = Binder.clearCallingIdentity(); |
| 5363 | try { |
| 5364 | CarrierConfigManager configManager = |
| 5365 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5366 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5367 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5368 | } finally { |
| 5369 | Binder.restoreCallingIdentity(identity); |
| 5370 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5371 | } |
| 5372 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5373 | @Override |
| 5374 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5375 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5376 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5377 | } |
| 5378 | |
| 5379 | @Override |
| 5380 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5381 | final long identity = Binder.clearCallingIdentity(); |
| 5382 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5383 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5384 | } finally { |
| 5385 | Binder.restoreCallingIdentity(identity); |
| 5386 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5387 | } |
| 5388 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5389 | /** |
| 5390 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5391 | * support for the feature and device firmware support. |
| 5392 | * |
| 5393 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5394 | */ |
| 5395 | @Override |
| 5396 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5397 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5398 | final Phone phone = getPhone(subscriptionId); |
| 5399 | if (phone == null) { |
| 5400 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5401 | return false; |
| 5402 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5403 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5404 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5405 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5406 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5407 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5408 | return isCarrierSupported && isDeviceSupported; |
| 5409 | } finally { |
| 5410 | Binder.restoreCallingIdentity(identity); |
| 5411 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5412 | } |
| 5413 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5414 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5415 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 5416 | * RTT setting, will return true if the device and carrier both support RTT. |
| 5417 | * 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] | 5418 | */ |
| 5419 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5420 | final long identity = Binder.clearCallingIdentity(); |
| 5421 | try { |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5422 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 5423 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5424 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5425 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 5426 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 5427 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5428 | } finally { |
| 5429 | Binder.restoreCallingIdentity(identity); |
| 5430 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5431 | } |
| 5432 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5433 | /** |
| 5434 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5435 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5436 | * |
| 5437 | * <p>Requires Permission: |
| 5438 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5439 | */ |
| 5440 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5441 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5442 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5443 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5444 | return null; |
| 5445 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5446 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5447 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5448 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5449 | return null; |
| 5450 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5451 | |
| 5452 | final long identity = Binder.clearCallingIdentity(); |
| 5453 | try { |
| 5454 | return phone.getDeviceId(); |
| 5455 | } finally { |
| 5456 | Binder.restoreCallingIdentity(identity); |
| 5457 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5458 | } |
| 5459 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5460 | /** |
| 5461 | * {@hide} |
| 5462 | * Returns the IMS Registration Status on a particular subid |
| 5463 | * |
| 5464 | * @param subId |
| 5465 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5466 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5467 | Phone phone = getPhone(subId); |
| 5468 | if (phone != null) { |
| 5469 | return phone.isImsRegistered(); |
| 5470 | } else { |
| 5471 | return false; |
| 5472 | } |
| 5473 | } |
| 5474 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5475 | @Override |
| 5476 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5477 | final long identity = Binder.clearCallingIdentity(); |
| 5478 | try { |
| 5479 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5480 | } finally { |
| 5481 | Binder.restoreCallingIdentity(identity); |
| 5482 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5483 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5484 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5485 | @Override |
| 5486 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5487 | final long identity = Binder.clearCallingIdentity(); |
| 5488 | try { |
| 5489 | Phone phone = getPhone(subscriptionId); |
| 5490 | if (phone == null) { |
| 5491 | return null; |
| 5492 | } |
| 5493 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5494 | } finally { |
| 5495 | Binder.restoreCallingIdentity(identity); |
| 5496 | } |
| 5497 | } |
| 5498 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5499 | /** |
| 5500 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5501 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5502 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5503 | final long identity = Binder.clearCallingIdentity(); |
| 5504 | try { |
| 5505 | Phone phone = getPhone(subId); |
| 5506 | if (phone != null) { |
| 5507 | return phone.isWifiCallingEnabled(); |
| 5508 | } else { |
| 5509 | return false; |
| 5510 | } |
| 5511 | } finally { |
| 5512 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5513 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5514 | } |
| 5515 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5516 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5517 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5518 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5519 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5520 | final long identity = Binder.clearCallingIdentity(); |
| 5521 | try { |
| 5522 | Phone phone = getPhone(subId); |
| 5523 | if (phone != null) { |
| 5524 | return phone.isVideoEnabled(); |
| 5525 | } else { |
| 5526 | return false; |
| 5527 | } |
| 5528 | } finally { |
| 5529 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5530 | } |
| 5531 | } |
| 5532 | |
| 5533 | /** |
| 5534 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5535 | * defined in {@link ImsRegistrationImplBase}. |
| 5536 | */ |
| 5537 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5538 | final long identity = Binder.clearCallingIdentity(); |
| 5539 | try { |
| 5540 | Phone phone = getPhone(subId); |
| 5541 | if (phone != null) { |
| 5542 | return phone.getImsRegistrationTech(); |
| 5543 | } else { |
| 5544 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5545 | } |
| 5546 | } finally { |
| 5547 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5548 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5549 | } |
| 5550 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5551 | @Override |
| 5552 | public void factoryReset(int subId) { |
| 5553 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5554 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5555 | return; |
| 5556 | } |
| 5557 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5558 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5559 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5560 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5561 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5562 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5563 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5564 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5565 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5566 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5567 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5568 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5569 | // There has been issues when Sms raw table somehow stores orphan |
| 5570 | // fragments. They lead to garbled message when new fragments come |
| 5571 | // in and combined with those stale ones. In case this happens again, |
| 5572 | // user can reset all network settings which will clean up this table. |
| 5573 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Naina Nalluri | 1264a9f | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 5574 | |
| 5575 | // Erase modem config if erase modem on network setting is enabled. |
| 5576 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 5577 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 5578 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 5579 | sendEraseModemConfig(getDefaultPhone()); |
| 5580 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5581 | } finally { |
| 5582 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5583 | } |
| 5584 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5585 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5586 | private void cleanUpSmsRawTable(Context context) { |
| 5587 | ContentResolver resolver = context.getContentResolver(); |
| 5588 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5589 | resolver.delete(uri, null, null); |
| 5590 | } |
| 5591 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5592 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5593 | public String getSimLocaleForSubscriber(int subId) { |
| 5594 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5595 | final Phone phone = getPhone(subId); |
| 5596 | if (phone == null) { |
| 5597 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5598 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5599 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5600 | final long identity = Binder.clearCallingIdentity(); |
| 5601 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5602 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5603 | phone.getContext().getOpPackageName()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5604 | if (info == null) { |
| 5605 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5606 | return null; |
| 5607 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5608 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5609 | // preferences (EF-PL and EF-LI)... |
| 5610 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5611 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5612 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5613 | if (localeFromDefaultSim != null) { |
| 5614 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5615 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5616 | + localeFromDefaultSim); |
| 5617 | return localeFromDefaultSim.toLanguageTag(); |
| 5618 | } else { |
| 5619 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5620 | } |
| 5621 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5622 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5623 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5624 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5625 | // the SIM and carrier preferences does not include a country we add the country |
| 5626 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5627 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5628 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5629 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5630 | return mccLocale.toLanguageTag(); |
| 5631 | } |
| 5632 | |
| 5633 | if (DBG) log("No locale found - returning null"); |
| 5634 | return null; |
| 5635 | } finally { |
| 5636 | Binder.restoreCallingIdentity(identity); |
| 5637 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5638 | } |
| 5639 | |
| 5640 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5641 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5642 | } |
| 5643 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5644 | /** |
| 5645 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5646 | */ |
| 5647 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5648 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5649 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5650 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5651 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5652 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5653 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5654 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5655 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5656 | * representing the state of the modem. |
| 5657 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5658 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5659 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5660 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5661 | */ |
| 5662 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5663 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5664 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5665 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5666 | |
| 5667 | final long identity = Binder.clearCallingIdentity(); |
| 5668 | try { |
| 5669 | ModemActivityInfo ret = null; |
| 5670 | synchronized (mLastModemActivityInfo) { |
| 5671 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5672 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5673 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5674 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5675 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5676 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5677 | mergedTxTimeMs[i] = info.getTxTimeMillis()[i] |
| 5678 | + mLastModemActivityInfo.getTxTimeMillis()[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5679 | } |
| 5680 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5681 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 5682 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5683 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5684 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5685 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5686 | mLastModemActivityInfo.setRxTimeMillis( |
| 5687 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5688 | mLastModemActivityInfo.setEnergyUsed( |
| 5689 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5690 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5691 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5692 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5693 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5694 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5695 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5696 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5697 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5698 | Bundle bundle = new Bundle(); |
| 5699 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5700 | result.send(0, bundle); |
| 5701 | } finally { |
| 5702 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5703 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5704 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5705 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5706 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5707 | // less than total activity duration. |
| 5708 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5709 | if (info == null) { |
| 5710 | return false; |
| 5711 | } |
| 5712 | int activityDurationMs = |
| 5713 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5714 | int totalTxTimeMs = 0; |
| 5715 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5716 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5717 | } |
| 5718 | return (info.isValid() |
| 5719 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5720 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5721 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5722 | && (totalTxTimeMs <= activityDurationMs)); |
| 5723 | } |
| 5724 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5725 | /** |
| 5726 | * {@hide} |
| 5727 | * Returns the service state information on specified subscription. |
| 5728 | */ |
| 5729 | @Override |
| 5730 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5731 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5732 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5733 | return null; |
| 5734 | } |
| 5735 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5736 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5737 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5738 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5739 | .setCallingPackage(callingPackage) |
| 5740 | .setCallingPid(Binder.getCallingPid()) |
| 5741 | .setCallingUid(Binder.getCallingUid()) |
| 5742 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5743 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5744 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5745 | .build()); |
| 5746 | |
| 5747 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5748 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5749 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5750 | .setCallingPackage(callingPackage) |
| 5751 | .setCallingPid(Binder.getCallingPid()) |
| 5752 | .setCallingUid(Binder.getCallingUid()) |
| 5753 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5754 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5755 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5756 | .build()); |
| 5757 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5758 | boolean hasFinePermission = |
| 5759 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5760 | boolean hasCoarsePermission = |
| 5761 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5762 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5763 | final long identity = Binder.clearCallingIdentity(); |
| 5764 | try { |
| 5765 | final Phone phone = getPhone(subId); |
| 5766 | if (phone == null) { |
| 5767 | return null; |
| 5768 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5769 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5770 | ServiceState ss = phone.getServiceState(); |
| 5771 | |
| 5772 | // Scrub out the location info in ServiceState depending on what level of access |
| 5773 | // the caller has. |
| 5774 | if (hasFinePermission) return ss; |
| 5775 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5776 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5777 | } finally { |
| 5778 | Binder.restoreCallingIdentity(identity); |
| 5779 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5780 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5781 | |
| 5782 | /** |
| 5783 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5784 | * |
| 5785 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5786 | * voicemail ringtone. |
| 5787 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5788 | * PhoneAccount. |
| 5789 | */ |
| 5790 | @Override |
| 5791 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5792 | final long identity = Binder.clearCallingIdentity(); |
| 5793 | try { |
| 5794 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5795 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5796 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5797 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5798 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5799 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5800 | } finally { |
| 5801 | Binder.restoreCallingIdentity(identity); |
| 5802 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5803 | } |
| 5804 | |
| 5805 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5806 | * Sets the per-account voicemail ringtone. |
| 5807 | * |
| 5808 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5809 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5810 | * |
| 5811 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5812 | * voicemail ringtone. |
| 5813 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5814 | * PhoneAccount. |
| 5815 | */ |
| 5816 | @Override |
| 5817 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5818 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5819 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5820 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5821 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5822 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5823 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5824 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5825 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5826 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5827 | |
| 5828 | final long identity = Binder.clearCallingIdentity(); |
| 5829 | try { |
| 5830 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5831 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5832 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5833 | } |
| 5834 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5835 | } finally { |
| 5836 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5837 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5841 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5842 | * |
| 5843 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5844 | * voicemail vibration setting. |
| 5845 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5846 | */ |
| 5847 | @Override |
| 5848 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5849 | final long identity = Binder.clearCallingIdentity(); |
| 5850 | try { |
| 5851 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5852 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5853 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5854 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5855 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5856 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5857 | } finally { |
| 5858 | Binder.restoreCallingIdentity(identity); |
| 5859 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5860 | } |
| 5861 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5862 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5863 | * Sets the per-account voicemail vibration. |
| 5864 | * |
| 5865 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5866 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5867 | * |
| 5868 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5869 | * voicemail vibration setting. |
| 5870 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5871 | * specific PhoneAccount. |
| 5872 | */ |
| 5873 | @Override |
| 5874 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5875 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5876 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5877 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5878 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5879 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5880 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5881 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5882 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5883 | } |
| 5884 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5885 | final long identity = Binder.clearCallingIdentity(); |
| 5886 | try { |
| 5887 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5888 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5889 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5890 | } |
| 5891 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5892 | } finally { |
| 5893 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5894 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5895 | } |
| 5896 | |
| 5897 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5898 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5899 | * |
| 5900 | * @throws SecurityException if the caller does not have the required permission |
| 5901 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5902 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5903 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5904 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5905 | } |
| 5906 | |
| 5907 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5908 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5909 | * permission. |
| 5910 | * |
| 5911 | * @throws SecurityException if the caller does not have the required permission |
| 5912 | */ |
| 5913 | private void enforceSendSmsPermission() { |
| 5914 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5915 | } |
| 5916 | |
| 5917 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5918 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5919 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5920 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5921 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5922 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5923 | final long identity = Binder.clearCallingIdentity(); |
| 5924 | try { |
| 5925 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5926 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5927 | if (componentName == null) { |
| 5928 | throw new SecurityException( |
| 5929 | "Caller not current active visual voicemail package[null]"); |
| 5930 | } |
| 5931 | String vvmPackage = componentName.getPackageName(); |
| 5932 | if (!callingPackage.equals(vvmPackage)) { |
| 5933 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5934 | + vvmPackage + "]"); |
| 5935 | } |
| 5936 | } finally { |
| 5937 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5938 | } |
| 5939 | } |
| 5940 | |
| 5941 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5942 | * Return the application ID for the app type. |
| 5943 | * |
| 5944 | * @param subId the subscription ID that this request applies to. |
| 5945 | * @param appType the uicc app type. |
| 5946 | * @return Application ID for specificied app type, or null if no uicc. |
| 5947 | */ |
| 5948 | @Override |
| 5949 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5950 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5951 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5952 | |
| 5953 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5954 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5955 | if (phone == null) { |
| 5956 | return null; |
| 5957 | } |
| 5958 | String aid = null; |
| 5959 | try { |
| 5960 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5961 | .getApplicationByType(appType).getAid(); |
| 5962 | } catch (Exception e) { |
| 5963 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5964 | } |
| 5965 | return aid; |
| 5966 | } finally { |
| 5967 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5968 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5969 | } |
| 5970 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5971 | /** |
| 5972 | * Return the Electronic Serial Number. |
| 5973 | * |
| 5974 | * @param subId the subscription ID that this request applies to. |
| 5975 | * @return ESN or null if error. |
| 5976 | */ |
| 5977 | @Override |
| 5978 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5979 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5980 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5981 | |
| 5982 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5983 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5984 | if (phone == null) { |
| 5985 | return null; |
| 5986 | } |
| 5987 | String esn = null; |
| 5988 | try { |
| 5989 | esn = phone.getEsn(); |
| 5990 | } catch (Exception e) { |
| 5991 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5992 | } |
| 5993 | return esn; |
| 5994 | } finally { |
| 5995 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5996 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5997 | } |
| 5998 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5999 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6000 | * Return the Preferred Roaming List Version. |
| 6001 | * |
| 6002 | * @param subId the subscription ID that this request applies to. |
| 6003 | * @return PRLVersion or null if error. |
| 6004 | */ |
| 6005 | @Override |
| 6006 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6007 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6008 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6009 | |
| 6010 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6011 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6012 | if (phone == null) { |
| 6013 | return null; |
| 6014 | } |
| 6015 | String cdmaPrlVersion = null; |
| 6016 | try { |
| 6017 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6018 | } catch (Exception e) { |
| 6019 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6020 | } |
| 6021 | return cdmaPrlVersion; |
| 6022 | } finally { |
| 6023 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6024 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6025 | } |
| 6026 | |
| 6027 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6028 | * Get snapshot of Telephony histograms |
| 6029 | * @return List of Telephony histograms |
| 6030 | * @hide |
| 6031 | */ |
| 6032 | @Override |
| 6033 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6034 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6035 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6036 | |
| 6037 | final long identity = Binder.clearCallingIdentity(); |
| 6038 | try { |
| 6039 | return RIL.getTelephonyRILTimingHistograms(); |
| 6040 | } finally { |
| 6041 | Binder.restoreCallingIdentity(identity); |
| 6042 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6043 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6044 | |
| 6045 | /** |
| 6046 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6047 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6048 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6049 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6050 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6051 | * @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] | 6052 | */ |
| 6053 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6054 | @TelephonyManager.SetCarrierRestrictionResult |
| 6055 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6056 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6057 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6058 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6059 | if (carrierRestrictionRules == null) { |
| 6060 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6061 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6062 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6063 | final long identity = Binder.clearCallingIdentity(); |
| 6064 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6065 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6066 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6067 | } finally { |
| 6068 | Binder.restoreCallingIdentity(identity); |
| 6069 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6070 | } |
| 6071 | |
| 6072 | /** |
| 6073 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6074 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6075 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6076 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6077 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6078 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6079 | */ |
| 6080 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6081 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6082 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6083 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6084 | |
| 6085 | final long identity = Binder.clearCallingIdentity(); |
| 6086 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6087 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6088 | if (response instanceof CarrierRestrictionRules) { |
| 6089 | return (CarrierRestrictionRules) response; |
| 6090 | } |
| 6091 | // Response is an Exception of some kind, |
| 6092 | // which is signalled to the user as a NULL retval |
| 6093 | return null; |
| 6094 | } catch (Exception e) { |
| 6095 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6096 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6097 | } finally { |
| 6098 | Binder.restoreCallingIdentity(identity); |
| 6099 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6100 | } |
| 6101 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6102 | /** |
| 6103 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6104 | * @param subId the subscription ID that this action applies to. |
| 6105 | * @param enabled control enable or disable metered apns. |
| 6106 | * {@hide} |
| 6107 | */ |
| 6108 | @Override |
| 6109 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6110 | enforceModifyPermission(); |
| 6111 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6112 | |
| 6113 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6114 | if (phone == null) { |
| 6115 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6116 | return; |
| 6117 | } |
| 6118 | try { |
| 6119 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6120 | } catch (Exception e) { |
| 6121 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6122 | } finally { |
| 6123 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6124 | } |
| 6125 | } |
| 6126 | |
| 6127 | /** |
| 6128 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6129 | * @param subId the subscription ID that this action applies to. |
| 6130 | * @param enabled control enable or disable radio. |
| 6131 | * {@hide} |
| 6132 | */ |
| 6133 | @Override |
| 6134 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6135 | enforceModifyPermission(); |
| 6136 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6137 | |
| 6138 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6139 | if (phone == null) { |
| 6140 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6141 | return; |
| 6142 | } |
| 6143 | try { |
| 6144 | phone.carrierActionSetRadioEnabled(enabled); |
| 6145 | } catch (Exception e) { |
| 6146 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6147 | } finally { |
| 6148 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6149 | } |
| 6150 | } |
| 6151 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6152 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6153 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6154 | * network status based on which carrier apps could apply actions accordingly, |
| 6155 | * enable/disable default url handler for example. |
| 6156 | * |
| 6157 | * @param subId the subscription ID that this action applies to. |
| 6158 | * @param report control start/stop reporting the default network status. |
| 6159 | * {@hide} |
| 6160 | */ |
| 6161 | @Override |
| 6162 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6163 | enforceModifyPermission(); |
| 6164 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6165 | |
| 6166 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6167 | if (phone == null) { |
| 6168 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6169 | return; |
| 6170 | } |
| 6171 | try { |
| 6172 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6173 | } catch (Exception e) { |
| 6174 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6175 | } finally { |
| 6176 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6177 | } |
| 6178 | } |
| 6179 | |
| 6180 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6181 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6182 | * @param subId the subscription ID that this action applies to. |
| 6183 | * {@hide} |
| 6184 | */ |
| 6185 | @Override |
| 6186 | public void carrierActionResetAll(int subId) { |
| 6187 | enforceModifyPermission(); |
| 6188 | final Phone phone = getPhone(subId); |
| 6189 | if (phone == null) { |
| 6190 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6191 | return; |
| 6192 | } |
| 6193 | try { |
| 6194 | phone.carrierActionResetAll(); |
| 6195 | } catch (Exception e) { |
| 6196 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6197 | } |
| 6198 | } |
| 6199 | |
| 6200 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6201 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6202 | * bug report is being generated. |
| 6203 | */ |
| 6204 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6205 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6206 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6207 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6208 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6209 | + Binder.getCallingPid() |
| 6210 | + ", uid=" + Binder.getCallingUid() |
| 6211 | + "without permission " |
| 6212 | + android.Manifest.permission.DUMP); |
| 6213 | return; |
| 6214 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6215 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6216 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6217 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6218 | @Override |
| 6219 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6220 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6221 | throws RemoteException { |
| 6222 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 6223 | } |
| 6224 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6225 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6226 | * Get aggregated video call data usage since boot. |
| 6227 | * |
| 6228 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6229 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6230 | * {@hide} |
| 6231 | */ |
| 6232 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6233 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6234 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6235 | null); |
| 6236 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6237 | final long identity = Binder.clearCallingIdentity(); |
| 6238 | try { |
| 6239 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6240 | // records the delta with the corresponding network identity. |
| 6241 | // We just return the total video call data usage snapshot since boot. |
| 6242 | Phone phone = getPhone(subId); |
| 6243 | if (phone != null) { |
| 6244 | return phone.getVtDataUsage(perUidStats); |
| 6245 | } |
| 6246 | return null; |
| 6247 | } finally { |
| 6248 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6249 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6250 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6251 | |
| 6252 | /** |
| 6253 | * Policy control of data connection. Usually used when data limit is passed. |
| 6254 | * @param enabled True if enabling the data, otherwise disabling. |
| 6255 | * @param subId Subscription index |
| 6256 | * {@hide} |
| 6257 | */ |
| 6258 | @Override |
| 6259 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6260 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6261 | |
| 6262 | final long identity = Binder.clearCallingIdentity(); |
| 6263 | try { |
| 6264 | Phone phone = getPhone(subId); |
| 6265 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6266 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6267 | } |
| 6268 | } finally { |
| 6269 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6270 | } |
| 6271 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6272 | |
| 6273 | /** |
| 6274 | * Get Client request stats |
| 6275 | * @return List of Client Request Stats |
| 6276 | * @hide |
| 6277 | */ |
| 6278 | @Override |
| 6279 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6280 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6281 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6282 | return null; |
| 6283 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6284 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6285 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6286 | final long identity = Binder.clearCallingIdentity(); |
| 6287 | try { |
| 6288 | if (phone != null) { |
| 6289 | return phone.getClientRequestStats(); |
| 6290 | } |
| 6291 | |
| 6292 | return null; |
| 6293 | } finally { |
| 6294 | Binder.restoreCallingIdentity(identity); |
| 6295 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6296 | } |
| 6297 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6298 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6299 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6300 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6301 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6302 | |
| 6303 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6304 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6305 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6306 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6307 | * @param state State of SIM (power down, power up, pass through) |
| 6308 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6309 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6310 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6311 | * |
| 6312 | **/ |
| 6313 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6314 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6315 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6316 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6317 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6318 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6319 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6320 | final long identity = Binder.clearCallingIdentity(); |
| 6321 | try { |
| 6322 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6323 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6324 | } |
| 6325 | } finally { |
| 6326 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6327 | } |
| 6328 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6329 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6330 | private boolean isUssdApiAllowed(int subId) { |
| 6331 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6332 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6333 | if (configManager == null) { |
| 6334 | return false; |
| 6335 | } |
| 6336 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6337 | if (pb == null) { |
| 6338 | return false; |
| 6339 | } |
| 6340 | return pb.getBoolean( |
| 6341 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6342 | } |
| 6343 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6344 | /** |
| 6345 | * Check if phone is in emergency callback mode |
| 6346 | * @return true if phone is in emergency callback mode |
| 6347 | * @param subId sub id |
| 6348 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6349 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6350 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6351 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6352 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6353 | |
| 6354 | final long identity = Binder.clearCallingIdentity(); |
| 6355 | try { |
| 6356 | if (phone != null) { |
| 6357 | return phone.isInEcm(); |
| 6358 | } else { |
| 6359 | return false; |
| 6360 | } |
| 6361 | } finally { |
| 6362 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6363 | } |
| 6364 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6365 | |
| 6366 | /** |
| 6367 | * Get the current signal strength information for the given subscription. |
| 6368 | * Because this information is not updated when the device is in a low power state |
| 6369 | * it should not be relied-upon to be current. |
| 6370 | * @param subId Subscription index |
| 6371 | * @return the most recent cached signal strength info from the modem |
| 6372 | */ |
| 6373 | @Override |
| 6374 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6375 | final long identity = Binder.clearCallingIdentity(); |
| 6376 | try { |
| 6377 | Phone p = getPhone(subId); |
| 6378 | if (p == null) { |
| 6379 | return null; |
| 6380 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6381 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6382 | return p.getSignalStrength(); |
| 6383 | } finally { |
| 6384 | Binder.restoreCallingIdentity(identity); |
| 6385 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6386 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6387 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6388 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6389 | * Get the current modem radio state for the given slot. |
| 6390 | * @param slotIndex slot index. |
| 6391 | * @param callingPackage the name of the package making the call. |
| 6392 | * @return the current radio power state from the modem |
| 6393 | */ |
| 6394 | @Override |
| 6395 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6396 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6397 | if (phone != null) { |
| 6398 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6399 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6400 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6401 | } |
| 6402 | |
| 6403 | final long identity = Binder.clearCallingIdentity(); |
| 6404 | try { |
| 6405 | return phone.getRadioPowerState(); |
| 6406 | } finally { |
| 6407 | Binder.restoreCallingIdentity(identity); |
| 6408 | } |
| 6409 | } |
| 6410 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6411 | } |
| 6412 | |
| 6413 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6414 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6415 | * |
| 6416 | * <p>Requires one of the following permissions: |
| 6417 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6418 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6419 | * privileges. |
| 6420 | * |
| 6421 | * @param subId subscription id |
| 6422 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6423 | * {@code false}. |
| 6424 | */ |
| 6425 | @Override |
| 6426 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6427 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6428 | null /* message */); |
| 6429 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6430 | boolean isEnabled = false; |
| 6431 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6432 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6433 | Phone phone = getPhone(subId); |
| 6434 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6435 | } catch (Exception e) { |
| 6436 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6437 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6438 | } finally { |
| 6439 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6440 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6441 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6442 | } |
| 6443 | |
| 6444 | |
| 6445 | /** |
| 6446 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6447 | * |
| 6448 | * <p> Requires permission: |
| 6449 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6450 | * privileges. |
| 6451 | * |
| 6452 | * @param subId subscription id |
| 6453 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6454 | */ |
| 6455 | @Override |
| 6456 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6457 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6458 | mApp, subId, "setDataRoamingEnabled"); |
| 6459 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6460 | final long identity = Binder.clearCallingIdentity(); |
| 6461 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6462 | Phone phone = getPhone(subId); |
| 6463 | if (phone != null) { |
| 6464 | phone.setDataRoamingEnabled(isEnabled); |
| 6465 | } |
| 6466 | } finally { |
| 6467 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6468 | } |
| 6469 | } |
| 6470 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6471 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6472 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6473 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6474 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6475 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6476 | boolean isAllowed = true; |
| 6477 | final long identity = Binder.clearCallingIdentity(); |
| 6478 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6479 | Phone phone = getPhone(subId); |
| 6480 | if (phone != null) { |
| 6481 | isAllowed = phone.isCspPlmnEnabled(); |
| 6482 | } |
| 6483 | } finally { |
| 6484 | Binder.restoreCallingIdentity(identity); |
| 6485 | } |
| 6486 | return isAllowed; |
| 6487 | } |
| 6488 | |
| 6489 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6490 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame^] | 6491 | // Verify that tha callingPackage belongs to the calling UID |
| 6492 | mApp.getSystemService(AppOpsManager.class) |
| 6493 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 6494 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6495 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6496 | try { |
| 6497 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6498 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6499 | } catch (SecurityException e) { |
| 6500 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6501 | // has carrier privileges on an active UICC |
| 6502 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6503 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6504 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6505 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6506 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6507 | |
| 6508 | final long identity = Binder.clearCallingIdentity(); |
| 6509 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6510 | UiccController uiccController = UiccController.getInstance(); |
| 6511 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6512 | if (hasReadPermission) { |
| 6513 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6514 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6515 | |
| 6516 | // Remove private info if the caller doesn't have access |
| 6517 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6518 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6519 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6520 | // is available |
| 6521 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6522 | if (card == null || card.getUiccProfile() == null) { |
| 6523 | // assume no access if the card or profile is unavailable |
| 6524 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6525 | continue; |
| 6526 | } |
| 6527 | UiccProfile profile = card.getUiccProfile(); |
| 6528 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6529 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6530 | filteredInfos.add(cardInfo); |
| 6531 | } else { |
| 6532 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6533 | } |
| 6534 | } |
| 6535 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6536 | } finally { |
| 6537 | Binder.restoreCallingIdentity(identity); |
| 6538 | } |
| 6539 | } |
| 6540 | |
| 6541 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6542 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6543 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6544 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6545 | final long identity = Binder.clearCallingIdentity(); |
| 6546 | try { |
| 6547 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6548 | if (slots == null) { |
| 6549 | Rlog.i(LOG_TAG, "slots is null."); |
| 6550 | return null; |
| 6551 | } |
| 6552 | |
| 6553 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6554 | for (int i = 0; i < slots.length; i++) { |
| 6555 | UiccSlot slot = slots[i]; |
| 6556 | if (slot == null) { |
| 6557 | continue; |
| 6558 | } |
| 6559 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6560 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6561 | UiccCard card = slot.getUiccCard(); |
| 6562 | if (card != null) { |
| 6563 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6564 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 6565 | cardId = slot.getEid(); |
| 6566 | if (TextUtils.isEmpty(cardId)) { |
| 6567 | cardId = slot.getIccId(); |
| 6568 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6569 | } |
| 6570 | |
| 6571 | int cardState = 0; |
| 6572 | switch (slot.getCardState()) { |
| 6573 | case CARDSTATE_ABSENT: |
| 6574 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6575 | break; |
| 6576 | case CARDSTATE_PRESENT: |
| 6577 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6578 | break; |
| 6579 | case CARDSTATE_ERROR: |
| 6580 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6581 | break; |
| 6582 | case CARDSTATE_RESTRICTED: |
| 6583 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6584 | break; |
| 6585 | default: |
| 6586 | break; |
| 6587 | |
| 6588 | } |
| 6589 | |
| 6590 | infos[i] = new UiccSlotInfo( |
| 6591 | slot.isActive(), |
| 6592 | slot.isEuicc(), |
| 6593 | cardId, |
| 6594 | cardState, |
| 6595 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6596 | slot.isExtendedApduSupported(), |
| 6597 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6598 | } |
| 6599 | return infos; |
| 6600 | } finally { |
| 6601 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6602 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6603 | } |
| 6604 | |
| 6605 | @Override |
| 6606 | public boolean switchSlots(int[] physicalSlots) { |
| 6607 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6608 | |
| 6609 | final long identity = Binder.clearCallingIdentity(); |
| 6610 | try { |
| 6611 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6612 | } finally { |
| 6613 | Binder.restoreCallingIdentity(identity); |
| 6614 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6615 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6616 | |
| 6617 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6618 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6619 | final long identity = Binder.clearCallingIdentity(); |
| 6620 | try { |
| 6621 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6622 | } finally { |
| 6623 | Binder.restoreCallingIdentity(identity); |
| 6624 | } |
| 6625 | } |
| 6626 | |
| 6627 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6628 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6629 | enforceModifyPermission(); |
| 6630 | final Phone phone = getPhone(subId); |
| 6631 | if (phone == null) { |
| 6632 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6633 | return; |
| 6634 | } |
| 6635 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6636 | final long identity = Binder.clearCallingIdentity(); |
| 6637 | try { |
| 6638 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6639 | } finally { |
| 6640 | Binder.restoreCallingIdentity(identity); |
| 6641 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6642 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6643 | |
| 6644 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6645 | * A test API to reload the UICC profile. |
| 6646 | * |
| 6647 | * <p>Requires that the calling app has permission |
| 6648 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6649 | * @hide |
| 6650 | */ |
| 6651 | @Override |
| 6652 | public void refreshUiccProfile(int subId) { |
| 6653 | enforceModifyPermission(); |
| 6654 | |
| 6655 | final long identity = Binder.clearCallingIdentity(); |
| 6656 | try { |
| 6657 | Phone phone = getPhone(subId); |
| 6658 | if (phone == null) { |
| 6659 | return; |
| 6660 | } |
| 6661 | UiccCard uiccCard = phone.getUiccCard(); |
| 6662 | if (uiccCard == null) { |
| 6663 | return; |
| 6664 | } |
| 6665 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6666 | if (uiccProfile == null) { |
| 6667 | return; |
| 6668 | } |
| 6669 | uiccProfile.refresh(); |
| 6670 | } finally { |
| 6671 | Binder.restoreCallingIdentity(identity); |
| 6672 | } |
| 6673 | } |
| 6674 | |
| 6675 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6676 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6677 | */ |
| 6678 | private boolean getDefaultDataEnabled() { |
| 6679 | return "true".equalsIgnoreCase( |
| 6680 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6681 | } |
| 6682 | |
| 6683 | /** |
| 6684 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6685 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6686 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6687 | */ |
| 6688 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6689 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6690 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6691 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6692 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6693 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6694 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6695 | return isDataRoamingEnabled; |
| 6696 | } |
| 6697 | |
| 6698 | /** |
| 6699 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6700 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6701 | */ |
| 6702 | private int getDefaultNetworkType(int subId) { |
| 6703 | return Integer.parseInt( |
| 6704 | TelephonyManager.getTelephonyProperty( |
| 6705 | mSubscriptionController.getPhoneId(subId), |
| 6706 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6707 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6708 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6709 | |
| 6710 | @Override |
| 6711 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6712 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6713 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6714 | |
| 6715 | final long identity = Binder.clearCallingIdentity(); |
| 6716 | try { |
| 6717 | final Phone phone = getPhone(subId); |
| 6718 | if (phone == null) { |
| 6719 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6720 | return; |
| 6721 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6722 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 6723 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6724 | } finally { |
| 6725 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6726 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6727 | } |
| 6728 | |
| 6729 | @Override |
| 6730 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6731 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6732 | |
| 6733 | final long identity = Binder.clearCallingIdentity(); |
| 6734 | try { |
| 6735 | final Phone phone = getPhone(subId); |
| 6736 | if (phone == null) { |
| 6737 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6738 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6739 | } |
| 6740 | return phone.getCarrierIdListVersion(); |
| 6741 | } finally { |
| 6742 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6743 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6744 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6745 | |
| 6746 | @Override |
| 6747 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6748 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6749 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6750 | return -1; |
| 6751 | } |
| 6752 | |
| 6753 | final long identity = Binder.clearCallingIdentity(); |
| 6754 | try { |
| 6755 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6756 | } finally { |
| 6757 | Binder.restoreCallingIdentity(identity); |
| 6758 | } |
| 6759 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6760 | |
| 6761 | @Override |
| 6762 | public int getCdmaRoamingMode(int subId) { |
| 6763 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6764 | mApp, subId, "getCdmaRoamingMode"); |
| 6765 | |
| 6766 | final long identity = Binder.clearCallingIdentity(); |
| 6767 | try { |
| 6768 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6769 | } finally { |
| 6770 | Binder.restoreCallingIdentity(identity); |
| 6771 | } |
| 6772 | } |
| 6773 | |
| 6774 | @Override |
| 6775 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6776 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6777 | mApp, subId, "setCdmaRoamingMode"); |
| 6778 | |
| 6779 | final long identity = Binder.clearCallingIdentity(); |
| 6780 | try { |
| 6781 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6782 | } finally { |
| 6783 | Binder.restoreCallingIdentity(identity); |
| 6784 | } |
| 6785 | } |
| 6786 | |
| 6787 | @Override |
| 6788 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6789 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6790 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6791 | |
| 6792 | final long identity = Binder.clearCallingIdentity(); |
| 6793 | try { |
| 6794 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6795 | } finally { |
| 6796 | Binder.restoreCallingIdentity(identity); |
| 6797 | } |
| 6798 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 6799 | |
| 6800 | private void ensureUserRunning(int userId) { |
| 6801 | if (!mUserManager.isUserRunning(userId)) { |
| 6802 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6803 | } |
| 6804 | } |
| 6805 | |
| 6806 | /** |
| 6807 | * Returns a list of SMS apps on a given user. |
| 6808 | * |
| 6809 | * Only the shell user (UID 2000 or 0) can call it. |
| 6810 | * Target user must be running. |
| 6811 | */ |
| 6812 | @Override |
| 6813 | public String[] getSmsApps(int userId) { |
| 6814 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6815 | ensureUserRunning(userId); |
| 6816 | |
| 6817 | final Collection<SmsApplicationData> apps = |
| 6818 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6819 | |
| 6820 | String[] ret = new String[apps.size()]; |
| 6821 | int i = 0; |
| 6822 | for (SmsApplicationData app : apps) { |
| 6823 | ret[i++] = app.mPackageName; |
| 6824 | } |
| 6825 | return ret; |
| 6826 | } |
| 6827 | |
| 6828 | /** |
| 6829 | * Returns the default SMS app package name on a given user. |
| 6830 | * |
| 6831 | * Only the shell user (UID 2000 or 0) can call it. |
| 6832 | * Target user must be running. |
| 6833 | */ |
| 6834 | @Override |
| 6835 | public String getDefaultSmsApp(int userId) { |
| 6836 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6837 | ensureUserRunning(userId); |
| 6838 | |
| 6839 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6840 | /* updateIfNeeded= */ true, userId); |
| 6841 | return cn == null ? null : cn.getPackageName(); |
| 6842 | } |
| 6843 | |
| 6844 | /** |
| 6845 | * Set a package as the default SMS app on a given user. |
| 6846 | * |
| 6847 | * Only the shell user (UID 2000 or 0) can call it. |
| 6848 | * Target user must be running. |
| 6849 | */ |
| 6850 | @Override |
| 6851 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6852 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6853 | ensureUserRunning(userId); |
| 6854 | |
| 6855 | boolean found = false; |
| 6856 | for (String pkg : getSmsApps(userId)) { |
| 6857 | if (TextUtils.equals(packageName, pkg)) { |
| 6858 | found = true; |
| 6859 | break; |
| 6860 | } |
| 6861 | } |
| 6862 | if (!found) { |
| 6863 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6864 | } |
| 6865 | |
| 6866 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6867 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6868 | |
| 6869 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6870 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6871 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6872 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6873 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6874 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6875 | } |
| 6876 | final long identity = Binder.clearCallingIdentity(); |
| 6877 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6878 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6879 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6880 | if (phone.getEmergencyNumberTracker() != null |
| 6881 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6882 | emergencyNumberListInternal.put( |
| 6883 | phone.getSubId(), |
| 6884 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6885 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6886 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6887 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6888 | } finally { |
| 6889 | Binder.restoreCallingIdentity(identity); |
| 6890 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6891 | } |
| 6892 | |
| 6893 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6894 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6895 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6896 | if (!exactMatch) { |
| 6897 | TelephonyPermissions |
| 6898 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6899 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6900 | } |
| 6901 | final long identity = Binder.clearCallingIdentity(); |
| 6902 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6903 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6904 | if (phone.getEmergencyNumberTracker() != null |
| 6905 | && phone.getEmergencyNumberTracker() != null) { |
| 6906 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6907 | number, exactMatch)) { |
| 6908 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6909 | } |
| 6910 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6911 | } |
| 6912 | return false; |
| 6913 | } finally { |
| 6914 | Binder.restoreCallingIdentity(identity); |
| 6915 | } |
| 6916 | } |
| 6917 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6918 | /** |
| 6919 | * Update emergency number list for test mode. |
| 6920 | */ |
| 6921 | @Override |
| 6922 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6923 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6924 | "updateEmergencyNumberListTestMode"); |
| 6925 | |
| 6926 | final long identity = Binder.clearCallingIdentity(); |
| 6927 | try { |
| 6928 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6929 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6930 | if (tracker != null) { |
| 6931 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6932 | } |
| 6933 | } |
| 6934 | } finally { |
| 6935 | Binder.restoreCallingIdentity(identity); |
| 6936 | } |
| 6937 | } |
| 6938 | |
| 6939 | /** |
| 6940 | * Get the full emergency number list for test mode. |
| 6941 | */ |
| 6942 | @Override |
| 6943 | public List<String> getEmergencyNumberListTestMode() { |
| 6944 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6945 | "getEmergencyNumberListTestMode"); |
| 6946 | |
| 6947 | final long identity = Binder.clearCallingIdentity(); |
| 6948 | try { |
| 6949 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6950 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6951 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6952 | if (tracker != null) { |
| 6953 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6954 | emergencyNumbers.add(num.getNumber()); |
| 6955 | } |
| 6956 | } |
| 6957 | } |
| 6958 | return new ArrayList<>(emergencyNumbers); |
| 6959 | } finally { |
| 6960 | Binder.restoreCallingIdentity(identity); |
| 6961 | } |
| 6962 | } |
| 6963 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6964 | @Override |
| 6965 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6966 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6967 | Phone phone = getPhone(subId); |
| 6968 | if (phone == null) { |
| 6969 | return null; |
| 6970 | } |
| 6971 | final long identity = Binder.clearCallingIdentity(); |
| 6972 | try { |
| 6973 | UiccProfile profile = UiccController.getInstance() |
| 6974 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6975 | if (profile != null) { |
| 6976 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6977 | } |
| 6978 | } finally { |
| 6979 | Binder.restoreCallingIdentity(identity); |
| 6980 | } |
| 6981 | return null; |
| 6982 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6983 | |
| 6984 | /** |
| 6985 | * Enable or disable a modem stack. |
| 6986 | */ |
| 6987 | @Override |
| 6988 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6989 | enforceModifyPermission(); |
| 6990 | |
| 6991 | final long identity = Binder.clearCallingIdentity(); |
| 6992 | try { |
| 6993 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6994 | if (phone == null) { |
| 6995 | return false; |
| 6996 | } else { |
| 6997 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6998 | } |
| 6999 | } finally { |
| 7000 | Binder.restoreCallingIdentity(identity); |
| 7001 | } |
| 7002 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7003 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7004 | /** |
| 7005 | * Whether a modem stack is enabled or not. |
| 7006 | */ |
| 7007 | @Override |
| 7008 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 7009 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7010 | if (phone == null) return false; |
| 7011 | |
| 7012 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7013 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 7014 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7015 | } |
| 7016 | |
| 7017 | final long identity = Binder.clearCallingIdentity(); |
| 7018 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7019 | try { |
| 7020 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7021 | } catch (NoSuchElementException ex) { |
| 7022 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7023 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7024 | } finally { |
| 7025 | Binder.restoreCallingIdentity(identity); |
| 7026 | } |
| 7027 | } |
| 7028 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7029 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7030 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7031 | enforceModifyPermission(); |
| 7032 | |
| 7033 | final long identity = Binder.clearCallingIdentity(); |
| 7034 | try { |
| 7035 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7036 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7037 | .commit(); |
| 7038 | } finally { |
| 7039 | Binder.restoreCallingIdentity(identity); |
| 7040 | } |
| 7041 | } |
| 7042 | |
| 7043 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7044 | @TelephonyManager.IsMultiSimSupportedResult |
| 7045 | public int isMultiSimSupported(String callingPackage) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7046 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7047 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 7048 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7049 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7050 | |
| 7051 | final long identity = Binder.clearCallingIdentity(); |
| 7052 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7053 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7054 | } finally { |
| 7055 | Binder.restoreCallingIdentity(identity); |
| 7056 | } |
| 7057 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7058 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7059 | @TelephonyManager.IsMultiSimSupportedResult |
| 7060 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7061 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7062 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7063 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7064 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7065 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7066 | } |
| 7067 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7068 | // supported by the modem, indicate that it is restricted. |
| 7069 | PhoneCapability staticCapability = |
| 7070 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7071 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7072 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7073 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7074 | } |
| 7075 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7076 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7077 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7078 | } |
| 7079 | // Check if support of multiple SIMs is restricted by carrier |
| 7080 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7081 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7082 | } |
| 7083 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7084 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7085 | } |
| 7086 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7087 | /** |
| 7088 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7089 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7090 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7091 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7092 | * @param numOfSims number of active sims we want to switch to |
| 7093 | */ |
| 7094 | @Override |
| 7095 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7096 | if (numOfSims == 1) { |
| 7097 | enforceModifyPermission(); |
| 7098 | } else { |
| 7099 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7100 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7101 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7102 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7103 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7104 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7105 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7106 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7107 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7108 | return; |
| 7109 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7110 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7111 | } finally { |
| 7112 | Binder.restoreCallingIdentity(identity); |
| 7113 | } |
| 7114 | } |
| 7115 | |
| 7116 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7117 | * Get whether making changes to modem configurations will trigger reboot. |
| 7118 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7119 | */ |
| 7120 | @Override |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7121 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) { |
| 7122 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7123 | mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) { |
| 7124 | return false; |
| 7125 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7126 | final long identity = Binder.clearCallingIdentity(); |
| 7127 | try { |
| 7128 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7129 | } finally { |
| 7130 | Binder.restoreCallingIdentity(identity); |
| 7131 | } |
| 7132 | } |
| 7133 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7134 | private void updateModemStateMetrics() { |
| 7135 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7136 | // TODO: check the state for each modem if the api is ready. |
| 7137 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7138 | } |
| 7139 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7140 | @Override |
| 7141 | public int[] getSlotsMapping() { |
| 7142 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7143 | |
| 7144 | final long identity = Binder.clearCallingIdentity(); |
| 7145 | try { |
| 7146 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7147 | // All logical slots should have a mapping to a physical slot. |
| 7148 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7149 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7150 | for (int i = 0; i < slotInfos.length; i++) { |
| 7151 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7152 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7153 | } |
| 7154 | } |
| 7155 | return logicalSlotsMapping; |
| 7156 | } finally { |
| 7157 | Binder.restoreCallingIdentity(identity); |
| 7158 | } |
| 7159 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7160 | |
| 7161 | /** |
| 7162 | * Get the IRadio HAL Version |
| 7163 | */ |
| 7164 | @Override |
| 7165 | public int getRadioHalVersion() { |
| 7166 | Phone phone = getDefaultPhone(); |
| 7167 | if (phone == null) return -1; |
| 7168 | HalVersion hv = phone.getHalVersion(); |
| 7169 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7170 | return hv.major * 100 + hv.minor; |
| 7171 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7172 | |
| 7173 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7174 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7175 | * corresponding network requests on a subId. |
| 7176 | * |
| 7177 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7178 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7179 | * 2) APN is un-metered for this subscription, or |
| 7180 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7181 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7182 | * |
| 7183 | * @return whether data is allowed for a apn type. |
| 7184 | * |
| 7185 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7186 | */ |
| 7187 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7188 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7189 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7190 | mApp, subId, callingPackage, "isDataEnabledForApn")) { |
| 7191 | throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7192 | } |
| 7193 | |
| 7194 | // Now that all security checks passes, perform the operation as ourselves. |
| 7195 | final long identity = Binder.clearCallingIdentity(); |
| 7196 | try { |
| 7197 | Phone phone = getPhone(subId); |
| 7198 | if (phone == null) return false; |
| 7199 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7200 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7201 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7202 | } finally { |
| 7203 | Binder.restoreCallingIdentity(identity); |
| 7204 | } |
| 7205 | } |
| 7206 | |
| 7207 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7208 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7209 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7210 | |
| 7211 | // Now that all security checks passes, perform the operation as ourselves. |
| 7212 | final long identity = Binder.clearCallingIdentity(); |
| 7213 | try { |
| 7214 | Phone phone = getPhone(subId); |
| 7215 | if (phone == null) return true; // By default return true. |
| 7216 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7217 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7218 | } finally { |
| 7219 | Binder.restoreCallingIdentity(identity); |
| 7220 | } |
| 7221 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7222 | |
| 7223 | @Override |
| 7224 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7225 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7226 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7227 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7228 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7229 | } |
| 7230 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7231 | Intent intent = new Intent(); |
| 7232 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7233 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7234 | // Bring up choose default SMS subscription dialog right now |
| 7235 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7236 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7237 | mApp.startActivity(intent); |
| 7238 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7239 | |
| 7240 | @Override |
| 7241 | public String getMmsUAProfUrl(int subId) { |
| 7242 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7243 | final long identity = Binder.clearCallingIdentity(); |
| 7244 | try { |
| 7245 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7246 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7247 | } finally { |
| 7248 | Binder.restoreCallingIdentity(identity); |
| 7249 | } |
| 7250 | } |
| 7251 | |
| 7252 | @Override |
| 7253 | public String getMmsUserAgent(int subId) { |
| 7254 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7255 | final long identity = Binder.clearCallingIdentity(); |
| 7256 | try { |
| 7257 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7258 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7259 | } finally { |
| 7260 | Binder.restoreCallingIdentity(identity); |
| 7261 | } |
| 7262 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7263 | |
| 7264 | @Override |
| 7265 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7266 | enforceModifyPermission(); |
| 7267 | |
| 7268 | // Now that all security checks passes, perform the operation as ourselves. |
| 7269 | final long identity = Binder.clearCallingIdentity(); |
| 7270 | try { |
| 7271 | Phone phone = getPhone(subId); |
| 7272 | if (phone == null) return false; |
| 7273 | |
| 7274 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7275 | } finally { |
| 7276 | Binder.restoreCallingIdentity(identity); |
| 7277 | } |
| 7278 | } |
| 7279 | |
| 7280 | @Override |
| 7281 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7282 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7283 | |
| 7284 | // Now that all security checks passes, perform the operation as ourselves. |
| 7285 | final long identity = Binder.clearCallingIdentity(); |
| 7286 | try { |
| 7287 | Phone phone = getPhone(subId); |
| 7288 | if (phone == null) return false; |
| 7289 | |
| 7290 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7291 | } finally { |
| 7292 | Binder.restoreCallingIdentity(identity); |
| 7293 | } |
| 7294 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7295 | } |