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; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 58 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 59 | import android.provider.Telephony; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 60 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 61 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 62 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 63 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 64 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 65 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 66 | import android.telephony.CellInfoGsm; |
| 67 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 68 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 69 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 70 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 71 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 72 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 73 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 74 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 75 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 76 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 77 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 78 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 79 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 80 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 81 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 82 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 83 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 84 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 85 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 86 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 87 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 88 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 89 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 90 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 91 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 92 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 93 | import android.telephony.data.ApnSetting; |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 94 | import android.telephony.data.ApnSetting.ApnType; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 95 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 96 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 97 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 98 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 99 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 100 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 101 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 102 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 103 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 105 | import android.telephony.ims.feature.MmTelFeature; |
| 106 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 107 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 108 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 109 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 110 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 111 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 112 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 113 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 114 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 115 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 116 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 120 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 126 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 128 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 130 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.ServiceStateTracker; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.SmsApplication; |
| 143 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.ims.ImsResolver; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.uicc.IccIoResult; |
| 154 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 162 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 163 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 164 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 165 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 166 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 167 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 168 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 169 | import java.io.FileDescriptor; |
| 170 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 171 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 172 | import java.util.Arrays; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 173 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 174 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 175 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 176 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 177 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 178 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 179 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 180 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 181 | |
| 182 | /** |
| 183 | * Implementation of the ITelephony interface. |
| 184 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 185 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 186 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 187 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 188 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 189 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 190 | |
| 191 | // Message codes used with mMainThreadHandler |
| 192 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 193 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 194 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 195 | private static final int CMD_OPEN_CHANNEL = 9; |
| 196 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 197 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 198 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 199 | private static final int CMD_NV_READ_ITEM = 13; |
| 200 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 201 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 202 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 203 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 204 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 205 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 206 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 207 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 208 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 209 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 210 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 211 | private static final int CMD_SEND_ENVELOPE = 25; |
| 212 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 213 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 214 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 215 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 216 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 217 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 218 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 219 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 220 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 221 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 222 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 223 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 224 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 225 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 226 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 227 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 228 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 229 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 230 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 231 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 232 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 233 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 234 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 235 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 236 | private static final int CMD_SWITCH_SLOTS = 50; |
| 237 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 238 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 239 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 240 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 241 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 242 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 243 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 244 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 245 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 246 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 247 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 248 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 249 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 250 | private static final int CMD_MODEM_REBOOT = 64; |
| 251 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 252 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 253 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 254 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 255 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 256 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 257 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 258 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 259 | // Parameters of select command. |
| 260 | private static final int SELECT_COMMAND = 0xA4; |
| 261 | private static final int SELECT_P1 = 0x04; |
| 262 | private static final int SELECT_P2 = 0; |
| 263 | private static final int SELECT_P3 = 0x10; |
| 264 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 265 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 266 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 267 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 268 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 269 | /** The singleton instance. */ |
| 270 | private static PhoneInterfaceManager sInstance; |
| 271 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 272 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 273 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 274 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 275 | private AppOpsManager mAppOps; |
| 276 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 277 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 278 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 279 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 280 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 281 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 282 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 283 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 284 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 285 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 286 | // String to store multi SIM allowed |
| 287 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 288 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 289 | // The AID of ISD-R. |
| 290 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 291 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 292 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 293 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 294 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 295 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 296 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 297 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 298 | * A request object to use for transmitting data to an ICC. |
| 299 | */ |
| 300 | private static final class IccAPDUArgument { |
| 301 | public int channel, cla, command, p1, p2, p3; |
| 302 | public String data; |
| 303 | |
| 304 | public IccAPDUArgument(int channel, int cla, int command, |
| 305 | int p1, int p2, int p3, String data) { |
| 306 | this.channel = channel; |
| 307 | this.cla = cla; |
| 308 | this.command = command; |
| 309 | this.p1 = p1; |
| 310 | this.p2 = p2; |
| 311 | this.p3 = p3; |
| 312 | this.data = data; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 317 | * A request object to use for transmitting data to an ICC. |
| 318 | */ |
| 319 | private static final class ManualNetworkSelectionArgument { |
| 320 | public OperatorInfo operatorInfo; |
| 321 | public boolean persistSelection; |
| 322 | |
| 323 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 324 | this.operatorInfo = operatorInfo; |
| 325 | this.persistSelection = persistSelection; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 330 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 331 | * request after sending. The main thread will notify the request when it is complete. |
| 332 | */ |
| 333 | private static final class MainThreadRequest { |
| 334 | /** The argument to use for the request */ |
| 335 | public Object argument; |
| 336 | /** The result of the request that is run on the main thread */ |
| 337 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 338 | // The subscriber id that this request applies to. Defaults to |
| 339 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 340 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 341 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 342 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 343 | public Phone phone; |
| 344 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 345 | public WorkSource workSource; |
| 346 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 347 | public MainThreadRequest(Object argument) { |
| 348 | this.argument = argument; |
| 349 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 350 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 351 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 352 | this.argument = argument; |
| 353 | if (phone != null) { |
| 354 | this.phone = phone; |
| 355 | } |
| 356 | this.workSource = workSource; |
| 357 | } |
| 358 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 359 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 360 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 361 | if (subId != null) { |
| 362 | this.subId = subId; |
| 363 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 364 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 365 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 368 | private static final class IncomingThirdPartyCallArgs { |
| 369 | public final ComponentName component; |
| 370 | public final String callId; |
| 371 | public final String callerDisplayName; |
| 372 | |
| 373 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 374 | String callerDisplayName) { |
| 375 | this.component = component; |
| 376 | this.callId = callId; |
| 377 | this.callerDisplayName = callerDisplayName; |
| 378 | } |
| 379 | } |
| 380 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 381 | /** |
| 382 | * A handler that processes messages on the main thread in the phone process. Since many |
| 383 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 384 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 385 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 386 | * on, which will be notified when the operation completes and will contain the result of the |
| 387 | * request. |
| 388 | * |
| 389 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 390 | * note that request.result must be set to something non-null for the calling thread to |
| 391 | * unblock. |
| 392 | */ |
| 393 | private final class MainThreadHandler extends Handler { |
| 394 | @Override |
| 395 | public void handleMessage(Message msg) { |
| 396 | MainThreadRequest request; |
| 397 | Message onCompleted; |
| 398 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 399 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 400 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 401 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 402 | |
| 403 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 404 | case CMD_HANDLE_USSD_REQUEST: { |
| 405 | request = (MainThreadRequest) msg.obj; |
| 406 | final Phone phone = getPhoneFromRequest(request); |
| 407 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 408 | String ussdRequest = ussdObject.first; |
| 409 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 410 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 411 | if (!isUssdApiAllowed(request.subId)) { |
| 412 | // Carrier does not support use of this API, return failure. |
| 413 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 414 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 415 | Bundle returnData = new Bundle(); |
| 416 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 417 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 418 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 419 | request.result = true; |
| 420 | notifyRequester(request); |
| 421 | return; |
| 422 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 423 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 424 | try { |
| 425 | request.result = phone != null |
| 426 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 427 | } catch (CallStateException cse) { |
| 428 | request.result = false; |
| 429 | } |
| 430 | // Wake up the requesting thread |
| 431 | notifyRequester(request); |
| 432 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 435 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 436 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 437 | final Phone phone = getPhoneFromRequest(request); |
| 438 | request.result = phone != null ? |
| 439 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 440 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 441 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 442 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 443 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 444 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 445 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 446 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 447 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 448 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 449 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 450 | if (uiccCard == null) { |
| 451 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 452 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 453 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 454 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 455 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 456 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 457 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 458 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 459 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 460 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 461 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 462 | break; |
| 463 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 464 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 465 | ar = (AsyncResult) msg.obj; |
| 466 | request = (MainThreadRequest) ar.userObj; |
| 467 | if (ar.exception == null && ar.result != null) { |
| 468 | request.result = ar.result; |
| 469 | } else { |
| 470 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 471 | if (ar.result == null) { |
| 472 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 473 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 474 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 475 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 476 | } else { |
| 477 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 478 | } |
| 479 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 480 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 481 | break; |
| 482 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 483 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 484 | request = (MainThreadRequest) msg.obj; |
| 485 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 486 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 487 | if (uiccCard == null) { |
| 488 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 489 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 490 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 491 | } else { |
| 492 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 493 | request); |
| 494 | uiccCard.iccTransmitApduBasicChannel( |
| 495 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 496 | iccArgument.p3, iccArgument.data, onCompleted); |
| 497 | } |
| 498 | break; |
| 499 | |
| 500 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 501 | ar = (AsyncResult) msg.obj; |
| 502 | request = (MainThreadRequest) ar.userObj; |
| 503 | if (ar.exception == null && ar.result != null) { |
| 504 | request.result = ar.result; |
| 505 | } else { |
| 506 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 507 | if (ar.result == null) { |
| 508 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 509 | } else if (ar.exception instanceof CommandException) { |
| 510 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 511 | ar.exception); |
| 512 | } else { |
| 513 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 514 | } |
| 515 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 516 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 517 | break; |
| 518 | |
| 519 | case CMD_EXCHANGE_SIM_IO: |
| 520 | request = (MainThreadRequest) msg.obj; |
| 521 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 522 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 523 | if (uiccCard == null) { |
| 524 | loge("iccExchangeSimIO: No UICC"); |
| 525 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
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 | } else { |
| 528 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 529 | request); |
| 530 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 531 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 532 | iccArgument.data, onCompleted); |
| 533 | } |
| 534 | break; |
| 535 | |
| 536 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 537 | ar = (AsyncResult) msg.obj; |
| 538 | request = (MainThreadRequest) ar.userObj; |
| 539 | if (ar.exception == null && ar.result != null) { |
| 540 | request.result = ar.result; |
| 541 | } else { |
| 542 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 543 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 544 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 545 | break; |
| 546 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 547 | case CMD_SEND_ENVELOPE: |
| 548 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 549 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 550 | if (uiccCard == null) { |
| 551 | loge("sendEnvelopeWithStatus: No UICC"); |
| 552 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 553 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 554 | } else { |
| 555 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 556 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 557 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 558 | break; |
| 559 | |
| 560 | case EVENT_SEND_ENVELOPE_DONE: |
| 561 | ar = (AsyncResult) msg.obj; |
| 562 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 563 | if (ar.exception == null && ar.result != null) { |
| 564 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 565 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 566 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 567 | if (ar.result == null) { |
| 568 | loge("sendEnvelopeWithStatus: Empty response"); |
| 569 | } else if (ar.exception instanceof CommandException) { |
| 570 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 571 | ar.exception); |
| 572 | } else { |
| 573 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 574 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 575 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 576 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 577 | break; |
| 578 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 579 | case CMD_OPEN_CHANNEL: |
| 580 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 581 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 582 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 583 | if (uiccCard == null) { |
| 584 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 585 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 586 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 587 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 588 | } else { |
| 589 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 590 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 591 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 592 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 593 | break; |
| 594 | |
| 595 | case EVENT_OPEN_CHANNEL_DONE: |
| 596 | ar = (AsyncResult) msg.obj; |
| 597 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 598 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 599 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 600 | int[] result = (int[]) ar.result; |
| 601 | int channelId = result[0]; |
| 602 | byte[] selectResponse = null; |
| 603 | if (result.length > 1) { |
| 604 | selectResponse = new byte[result.length - 1]; |
| 605 | for (int i = 1; i < result.length; ++i) { |
| 606 | selectResponse[i - 1] = (byte) result[i]; |
| 607 | } |
| 608 | } |
| 609 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 610 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 611 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 612 | if (ar.result == null) { |
| 613 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 614 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 615 | if (ar.exception != null) { |
| 616 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 617 | } |
| 618 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 619 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 620 | if (ar.exception instanceof CommandException) { |
| 621 | CommandException.Error error = |
| 622 | ((CommandException) (ar.exception)).getCommandError(); |
| 623 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 624 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 625 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 626 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 630 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 631 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 632 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 633 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 634 | break; |
| 635 | |
| 636 | case CMD_CLOSE_CHANNEL: |
| 637 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 638 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 639 | if (uiccCard == null) { |
| 640 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 641 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 642 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 643 | } else { |
| 644 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 645 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 646 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | break; |
| 648 | |
| 649 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 650 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 651 | break; |
| 652 | |
| 653 | case CMD_NV_READ_ITEM: |
| 654 | request = (MainThreadRequest) msg.obj; |
| 655 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 656 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 657 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 658 | break; |
| 659 | |
| 660 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 661 | ar = (AsyncResult) msg.obj; |
| 662 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 663 | if (ar.exception == null && ar.result != null) { |
| 664 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 665 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 666 | request.result = ""; |
| 667 | if (ar.result == null) { |
| 668 | loge("nvReadItem: Empty response"); |
| 669 | } else if (ar.exception instanceof CommandException) { |
| 670 | loge("nvReadItem: CommandException: " + |
| 671 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 672 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 673 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | } |
| 675 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 676 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 677 | break; |
| 678 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 679 | case CMD_NV_WRITE_ITEM: |
| 680 | request = (MainThreadRequest) msg.obj; |
| 681 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 682 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 683 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 684 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 685 | break; |
| 686 | |
| 687 | case EVENT_NV_WRITE_ITEM_DONE: |
| 688 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 689 | break; |
| 690 | |
| 691 | case CMD_NV_WRITE_CDMA_PRL: |
| 692 | request = (MainThreadRequest) msg.obj; |
| 693 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 694 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 695 | break; |
| 696 | |
| 697 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 698 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 699 | break; |
| 700 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 701 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 702 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 703 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 704 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 705 | break; |
| 706 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 707 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 708 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 709 | break; |
| 710 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 711 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 712 | request = (MainThreadRequest) msg.obj; |
| 713 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 714 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 715 | break; |
| 716 | |
| 717 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 718 | ar = (AsyncResult) msg.obj; |
| 719 | request = (MainThreadRequest) ar.userObj; |
| 720 | if (ar.exception == null && ar.result != null) { |
| 721 | request.result = ar.result; // Integer |
| 722 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 723 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 724 | if (ar.result == null) { |
| 725 | loge("getPreferredNetworkType: Empty response"); |
| 726 | } else if (ar.exception instanceof CommandException) { |
| 727 | loge("getPreferredNetworkType: CommandException: " + |
| 728 | ar.exception); |
| 729 | } else { |
| 730 | loge("getPreferredNetworkType: Unknown exception"); |
| 731 | } |
| 732 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 733 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 737 | request = (MainThreadRequest) msg.obj; |
| 738 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 739 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 740 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 741 | break; |
| 742 | |
| 743 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 744 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 745 | break; |
| 746 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 747 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 748 | request = (MainThreadRequest)msg.obj; |
| 749 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 750 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 751 | break; |
| 752 | |
| 753 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 754 | ar = (AsyncResult)msg.obj; |
| 755 | request = (MainThreadRequest)ar.userObj; |
| 756 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 757 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 758 | break; |
| 759 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 760 | case CMD_SET_VOICEMAIL_NUMBER: |
| 761 | request = (MainThreadRequest) msg.obj; |
| 762 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 763 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 764 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 765 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 766 | break; |
| 767 | |
| 768 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 769 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 770 | break; |
| 771 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 772 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 773 | request = (MainThreadRequest) msg.obj; |
| 774 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 775 | request); |
| 776 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 777 | break; |
| 778 | |
| 779 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 780 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 781 | break; |
| 782 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 783 | case CMD_PERFORM_NETWORK_SCAN: |
| 784 | request = (MainThreadRequest) msg.obj; |
| 785 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 786 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 787 | break; |
| 788 | |
| 789 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 790 | ar = (AsyncResult) msg.obj; |
| 791 | request = (MainThreadRequest) ar.userObj; |
| 792 | CellNetworkScanResult cellScanResult; |
| 793 | if (ar.exception == null && ar.result != null) { |
| 794 | cellScanResult = new CellNetworkScanResult( |
| 795 | CellNetworkScanResult.STATUS_SUCCESS, |
| 796 | (List<OperatorInfo>) ar.result); |
| 797 | } else { |
| 798 | if (ar.result == null) { |
| 799 | loge("getCellNetworkScanResults: Empty response"); |
| 800 | } |
| 801 | if (ar.exception != null) { |
| 802 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 803 | } |
| 804 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 805 | if (ar.exception instanceof CommandException) { |
| 806 | CommandException.Error error = |
| 807 | ((CommandException) (ar.exception)).getCommandError(); |
| 808 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 809 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 810 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 811 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 812 | } |
| 813 | } |
| 814 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 815 | } |
| 816 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 817 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 818 | break; |
| 819 | |
| 820 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 821 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 822 | ManualNetworkSelectionArgument selArg = |
| 823 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 824 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 825 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 826 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 827 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 828 | break; |
| 829 | |
| 830 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 831 | ar = (AsyncResult) msg.obj; |
| 832 | request = (MainThreadRequest) ar.userObj; |
| 833 | if (ar.exception == null) { |
| 834 | request.result = true; |
| 835 | } else { |
| 836 | request.result = false; |
| 837 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 838 | } |
| 839 | notifyRequester(request); |
| 840 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 841 | break; |
| 842 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 843 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 844 | request = (MainThreadRequest) msg.obj; |
| 845 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 846 | if (defaultPhone != null) { |
| 847 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 848 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 849 | break; |
| 850 | |
| 851 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 852 | ar = (AsyncResult) msg.obj; |
| 853 | request = (MainThreadRequest) ar.userObj; |
| 854 | if (ar.exception == null && ar.result != null) { |
| 855 | request.result = ar.result; |
| 856 | } else { |
| 857 | if (ar.result == null) { |
| 858 | loge("queryModemActivityInfo: Empty response"); |
| 859 | } else if (ar.exception instanceof CommandException) { |
| 860 | loge("queryModemActivityInfo: CommandException: " + |
| 861 | ar.exception); |
| 862 | } else { |
| 863 | loge("queryModemActivityInfo: Unknown exception"); |
| 864 | } |
| 865 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 866 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 867 | if (request.result == null) { |
| 868 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 869 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 870 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 871 | break; |
| 872 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 873 | case CMD_SET_ALLOWED_CARRIERS: |
| 874 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 875 | CarrierRestrictionRules argument = |
| 876 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 877 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 878 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 879 | break; |
| 880 | |
| 881 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 882 | ar = (AsyncResult) msg.obj; |
| 883 | request = (MainThreadRequest) ar.userObj; |
| 884 | if (ar.exception == null && ar.result != null) { |
| 885 | request.result = ar.result; |
| 886 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 887 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 888 | if (ar.exception instanceof CommandException) { |
| 889 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 890 | CommandException.Error error = |
| 891 | ((CommandException) (ar.exception)).getCommandError(); |
| 892 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 893 | request.result = |
| 894 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 895 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 896 | } else { |
| 897 | loge("setAllowedCarriers: Unknown exception"); |
| 898 | } |
| 899 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 900 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 901 | break; |
| 902 | |
| 903 | case CMD_GET_ALLOWED_CARRIERS: |
| 904 | request = (MainThreadRequest) msg.obj; |
| 905 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 906 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 907 | break; |
| 908 | |
| 909 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 910 | ar = (AsyncResult) msg.obj; |
| 911 | request = (MainThreadRequest) ar.userObj; |
| 912 | if (ar.exception == null && ar.result != null) { |
| 913 | request.result = ar.result; |
| 914 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 915 | request.result = new IllegalStateException( |
| 916 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 917 | if (ar.result == null) { |
| 918 | loge("getAllowedCarriers: Empty response"); |
| 919 | } else if (ar.exception instanceof CommandException) { |
| 920 | loge("getAllowedCarriers: CommandException: " + |
| 921 | ar.exception); |
| 922 | } else { |
| 923 | loge("getAllowedCarriers: Unknown exception"); |
| 924 | } |
| 925 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 926 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 927 | break; |
| 928 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 929 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 930 | ar = (AsyncResult) msg.obj; |
| 931 | request = (MainThreadRequest) ar.userObj; |
| 932 | if (ar.exception == null && ar.result != null) { |
| 933 | request.result = ar.result; |
| 934 | } else { |
| 935 | request.result = new IllegalArgumentException( |
| 936 | "Failed to retrieve Forbidden Plmns"); |
| 937 | if (ar.result == null) { |
| 938 | loge("getForbiddenPlmns: Empty response"); |
| 939 | } else { |
| 940 | loge("getForbiddenPlmns: Unknown exception"); |
| 941 | } |
| 942 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 943 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 944 | break; |
| 945 | |
| 946 | case CMD_GET_FORBIDDEN_PLMNS: |
| 947 | request = (MainThreadRequest) msg.obj; |
| 948 | uiccCard = getUiccCardFromRequest(request); |
| 949 | if (uiccCard == null) { |
| 950 | loge("getForbiddenPlmns() UiccCard is null"); |
| 951 | request.result = new IllegalArgumentException( |
| 952 | "getForbiddenPlmns() UiccCard is null"); |
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 | Integer appType = (Integer) request.argument; |
| 957 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 958 | if (uiccApp == null) { |
| 959 | loge("getForbiddenPlmns() no app with specified type -- " |
| 960 | + appType); |
| 961 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 962 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 963 | break; |
| 964 | } else { |
| 965 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 966 | + " specified type -- " + appType); |
| 967 | } |
| 968 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 969 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 970 | onCompleted); |
| 971 | break; |
| 972 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 973 | case CMD_SWITCH_SLOTS: |
| 974 | request = (MainThreadRequest) msg.obj; |
| 975 | int[] physicalSlots = (int[]) request.argument; |
| 976 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 977 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 978 | break; |
| 979 | |
| 980 | case EVENT_SWITCH_SLOTS_DONE: |
| 981 | ar = (AsyncResult) msg.obj; |
| 982 | request = (MainThreadRequest) ar.userObj; |
| 983 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 984 | notifyRequester(request); |
| 985 | break; |
| 986 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 987 | request = (MainThreadRequest) msg.obj; |
| 988 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 989 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 990 | break; |
| 991 | |
| 992 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 993 | ar = (AsyncResult) msg.obj; |
| 994 | request = (MainThreadRequest) ar.userObj; |
| 995 | if (ar.exception != null) { |
| 996 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 997 | } else { |
| 998 | int mode = ((int[]) ar.result)[0]; |
| 999 | if (mode == 0) { |
| 1000 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1001 | } else { |
| 1002 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1003 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1004 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1005 | notifyRequester(request); |
| 1006 | break; |
| 1007 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1008 | request = (MainThreadRequest) msg.obj; |
| 1009 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1010 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1011 | break; |
| 1012 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1013 | ar = (AsyncResult) msg.obj; |
| 1014 | request = (MainThreadRequest) ar.userObj; |
| 1015 | if (ar.exception != null) { |
| 1016 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1017 | } else { |
| 1018 | request.result = ((int[]) ar.result)[0]; |
| 1019 | } |
| 1020 | notifyRequester(request); |
| 1021 | break; |
| 1022 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1023 | request = (MainThreadRequest) msg.obj; |
| 1024 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1025 | int mode = (int) request.argument; |
| 1026 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1027 | break; |
| 1028 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1029 | ar = (AsyncResult) msg.obj; |
| 1030 | request = (MainThreadRequest) ar.userObj; |
| 1031 | request.result = ar.exception == null; |
| 1032 | notifyRequester(request); |
| 1033 | break; |
| 1034 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1035 | request = (MainThreadRequest) msg.obj; |
| 1036 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1037 | int subscriptionMode = (int) request.argument; |
| 1038 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1039 | break; |
| 1040 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1041 | ar = (AsyncResult) msg.obj; |
| 1042 | request = (MainThreadRequest) ar.userObj; |
| 1043 | request.result = ar.exception == null; |
| 1044 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1045 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1046 | case CMD_GET_ALL_CELL_INFO: |
| 1047 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1048 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1049 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1050 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1051 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1052 | ar = (AsyncResult) msg.obj; |
| 1053 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1054 | // If a timeout occurs, the response will be null |
| 1055 | request.result = (ar.exception == null && ar.result != null) |
| 1056 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1057 | synchronized (request) { |
| 1058 | request.notifyAll(); |
| 1059 | } |
| 1060 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1061 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1062 | request = (MainThreadRequest) msg.obj; |
| 1063 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1064 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1065 | break; |
| 1066 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1067 | ar = (AsyncResult) msg.obj; |
| 1068 | request = (MainThreadRequest) ar.userObj; |
| 1069 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1070 | try { |
| 1071 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1072 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1073 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1074 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1075 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1076 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1077 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1078 | } else { |
| 1079 | // use the result as returned |
| 1080 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1081 | } |
| 1082 | } catch (RemoteException re) { |
| 1083 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1084 | } |
| 1085 | break; |
| 1086 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1087 | request = (MainThreadRequest) msg.obj; |
| 1088 | WorkSource ws = (WorkSource) request.argument; |
| 1089 | Phone phone = getPhoneFromRequest(request); |
| 1090 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1091 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1092 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1093 | ar = (AsyncResult) msg.obj; |
| 1094 | request = (MainThreadRequest) ar.userObj; |
| 1095 | if (ar.exception == null) { |
| 1096 | request.result = ar.result; |
| 1097 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1098 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1099 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1100 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1101 | } |
| 1102 | |
| 1103 | synchronized (request) { |
| 1104 | request.notifyAll(); |
| 1105 | } |
| 1106 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1107 | case CMD_MODEM_REBOOT: |
| 1108 | request = (MainThreadRequest) msg.obj; |
| 1109 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1110 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1111 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1112 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1113 | handleNullReturnEvent(msg, "rebootModem"); |
| 1114 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1115 | case CMD_REQUEST_ENABLE_MODEM: |
| 1116 | request = (MainThreadRequest) msg.obj; |
| 1117 | boolean enable = (boolean) request.argument; |
| 1118 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1119 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1120 | PhoneConfigurationManager.getInstance() |
| 1121 | .enablePhone(request.phone, enable, onCompleted); |
| 1122 | break; |
| 1123 | case EVENT_ENABLE_MODEM_DONE: |
| 1124 | ar = (AsyncResult) msg.obj; |
| 1125 | request = (MainThreadRequest) ar.userObj; |
| 1126 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1127 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1128 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1129 | if ((boolean) request.result) { |
| 1130 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1131 | updateModemStateMetrics(); |
| 1132 | } else { |
| 1133 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1134 | + ar.exception); |
| 1135 | } |
| 1136 | notifyRequester(request); |
| 1137 | break; |
| 1138 | case CMD_GET_MODEM_STATUS: |
| 1139 | request = (MainThreadRequest) msg.obj; |
| 1140 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1141 | PhoneConfigurationManager.getInstance() |
| 1142 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1143 | break; |
| 1144 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1145 | ar = (AsyncResult) msg.obj; |
| 1146 | request = (MainThreadRequest) ar.userObj; |
| 1147 | int id = request.phone.getPhoneId(); |
| 1148 | if (ar.exception == null && ar.result != null) { |
| 1149 | request.result = ar.result; |
| 1150 | //update the cache as modem status has changed |
| 1151 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1152 | (boolean) request.result); |
| 1153 | } else { |
| 1154 | // Return true if modem status cannot be retrieved. For most cases, |
| 1155 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1156 | // and disable modem are not supported. Modem is always on. |
| 1157 | // TODO: this should be fixed in R to support a third |
| 1158 | // status UNKNOWN b/131631629 |
| 1159 | request.result = true; |
| 1160 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1161 | + ar.exception); |
| 1162 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1163 | notifyRequester(request); |
| 1164 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1165 | default: |
| 1166 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1167 | break; |
| 1168 | } |
| 1169 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1170 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1171 | private void notifyRequester(MainThreadRequest request) { |
| 1172 | synchronized (request) { |
| 1173 | request.notifyAll(); |
| 1174 | } |
| 1175 | } |
| 1176 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1177 | private void handleNullReturnEvent(Message msg, String command) { |
| 1178 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1179 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1180 | if (ar.exception == null) { |
| 1181 | request.result = true; |
| 1182 | } else { |
| 1183 | request.result = false; |
| 1184 | if (ar.exception instanceof CommandException) { |
| 1185 | loge(command + ": CommandException: " + ar.exception); |
| 1186 | } else { |
| 1187 | loge(command + ": Unknown exception"); |
| 1188 | } |
| 1189 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1190 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1191 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | /** |
| 1195 | * Posts the specified command to be executed on the main thread, |
| 1196 | * waits for the request to complete, and returns the result. |
| 1197 | * @see #sendRequestAsync |
| 1198 | */ |
| 1199 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1200 | return sendRequest( |
| 1201 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /** |
| 1205 | * Posts the specified command to be executed on the main thread, |
| 1206 | * waits for the request to complete, and returns the result. |
| 1207 | * @see #sendRequestAsync |
| 1208 | */ |
| 1209 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1210 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1211 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | /** |
| 1215 | * Posts the specified command to be executed on the main thread, |
| 1216 | * waits for the request to complete, and returns the result. |
| 1217 | * @see #sendRequestAsync |
| 1218 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1219 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1220 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | /** |
| 1224 | * Posts the specified command to be executed on the main thread, |
| 1225 | * waits for the request to complete, and returns the result. |
| 1226 | * @see #sendRequestAsync |
| 1227 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1228 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1229 | return sendRequest(command, argument, subId, null, workSource); |
| 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 | */ |
| 1237 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1238 | return sendRequest( |
| 1239 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1240 | } |
| 1241 | |
| 1242 | /** |
| 1243 | * Posts the specified command to be executed on the main thread, |
| 1244 | * waits for the request to complete, and returns the result. |
| 1245 | * @see #sendRequestAsync |
| 1246 | */ |
| 1247 | private Object sendRequest( |
| 1248 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1249 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1250 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1251 | } |
| 1252 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1253 | MainThreadRequest request = null; |
| 1254 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1255 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1256 | } else if (phone != null) { |
| 1257 | request = new MainThreadRequest(argument, phone, workSource); |
| 1258 | } else { |
| 1259 | request = new MainThreadRequest(argument, subId, workSource); |
| 1260 | } |
| 1261 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1262 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1263 | msg.sendToTarget(); |
| 1264 | |
| 1265 | // Wait for the request to complete |
| 1266 | synchronized (request) { |
| 1267 | while (request.result == null) { |
| 1268 | try { |
| 1269 | request.wait(); |
| 1270 | } catch (InterruptedException e) { |
| 1271 | // Do nothing, go back and wait until the request is complete |
| 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | return request.result; |
| 1276 | } |
| 1277 | |
| 1278 | /** |
| 1279 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1280 | * Posts the specified command to be executed on the main thread, and |
| 1281 | * returns immediately. |
| 1282 | * @see #sendRequest |
| 1283 | */ |
| 1284 | private void sendRequestAsync(int command) { |
| 1285 | mMainThreadHandler.sendEmptyMessage(command); |
| 1286 | } |
| 1287 | |
| 1288 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1289 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1290 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1291 | */ |
| 1292 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1293 | sendRequestAsync(command, argument, null, null); |
| 1294 | } |
| 1295 | |
| 1296 | /** |
| 1297 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1298 | * @see {@link #sendRequest(int,Object)} |
| 1299 | */ |
| 1300 | private void sendRequestAsync( |
| 1301 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1302 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1303 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1304 | msg.sendToTarget(); |
| 1305 | } |
| 1306 | |
| 1307 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1308 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1309 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1310 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1311 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1312 | synchronized (PhoneInterfaceManager.class) { |
| 1313 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1314 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1315 | } else { |
| 1316 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1317 | } |
| 1318 | return sInstance; |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1323 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1324 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1325 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1326 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1327 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1328 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1329 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1330 | mTelephonySharedPreferences = |
| 1331 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1332 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1333 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1334 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1335 | publish(); |
| 1336 | } |
| 1337 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1338 | private Phone getDefaultPhone() { |
| 1339 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1340 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1341 | } |
| 1342 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1343 | private void publish() { |
| 1344 | if (DBG) log("publish: " + this); |
| 1345 | |
| 1346 | ServiceManager.addService("phone", this); |
| 1347 | } |
| 1348 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1349 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1350 | if (request.phone != null) { |
| 1351 | return request.phone; |
| 1352 | } else { |
| 1353 | return getPhoneFromSubId(request.subId); |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | private Phone getPhoneFromSubId(int subId) { |
| 1358 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1359 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1360 | } |
| 1361 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1362 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1363 | Phone phone = getPhoneFromRequest(request); |
| 1364 | return phone == null ? null : |
| 1365 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1366 | } |
| 1367 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1368 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1369 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1370 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1371 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1372 | |
| 1373 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1374 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1377 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1378 | if (DBG) log("dial: " + number); |
| 1379 | // No permission check needed here: This is just a wrapper around the |
| 1380 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1381 | // the UI before it does anything. |
| 1382 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1383 | final long identity = Binder.clearCallingIdentity(); |
| 1384 | try { |
| 1385 | String url = createTelUrl(number); |
| 1386 | if (url == null) { |
| 1387 | return; |
| 1388 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1389 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1390 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1391 | PhoneConstants.State state = mCM.getState(subId); |
| 1392 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1393 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1394 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1395 | mApp.startActivity(intent); |
| 1396 | } |
| 1397 | } finally { |
| 1398 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1403 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1406 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1407 | if (DBG) log("call: " + number); |
| 1408 | |
| 1409 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1410 | // need to do a permission check since we're calling startActivity() |
| 1411 | // from the context of the phone app. |
| 1412 | enforceCallPermission(); |
| 1413 | |
| 1414 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1415 | != AppOpsManager.MODE_ALLOWED) { |
| 1416 | return; |
| 1417 | } |
| 1418 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1419 | final long identity = Binder.clearCallingIdentity(); |
| 1420 | try { |
| 1421 | String url = createTelUrl(number); |
| 1422 | if (url == null) { |
| 1423 | return; |
| 1424 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1425 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1426 | boolean isValid = false; |
| 1427 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1428 | if (slist != null) { |
| 1429 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1430 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1431 | isValid = true; |
| 1432 | break; |
| 1433 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1434 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1435 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1436 | if (!isValid) { |
| 1437 | return; |
| 1438 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1439 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1440 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1441 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1442 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1443 | mApp.startActivity(intent); |
| 1444 | } finally { |
| 1445 | Binder.restoreCallingIdentity(identity); |
| 1446 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1449 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1450 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1451 | } |
| 1452 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1453 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1454 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1455 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1456 | } |
| 1457 | |
| 1458 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1459 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1462 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1463 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1464 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1465 | } |
| 1466 | |
| 1467 | /** {@hide} */ |
| 1468 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1469 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1472 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1473 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1474 | |
| 1475 | final long identity = Binder.clearCallingIdentity(); |
| 1476 | try { |
| 1477 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1478 | checkSimPin.start(); |
| 1479 | return checkSimPin.unlockSim(null, pin); |
| 1480 | } finally { |
| 1481 | Binder.restoreCallingIdentity(identity); |
| 1482 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1485 | /** {@hide} */ |
| 1486 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1487 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1490 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1491 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1492 | |
| 1493 | final long identity = Binder.clearCallingIdentity(); |
| 1494 | try { |
| 1495 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1496 | checkSimPuk.start(); |
| 1497 | return checkSimPuk.unlockSim(puk, pin); |
| 1498 | } finally { |
| 1499 | Binder.restoreCallingIdentity(identity); |
| 1500 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1504 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1505 | * a synchronous one. |
| 1506 | */ |
| 1507 | private static class UnlockSim extends Thread { |
| 1508 | |
| 1509 | private final IccCard mSimCard; |
| 1510 | |
| 1511 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1512 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1513 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1514 | |
| 1515 | // For replies from SimCard interface |
| 1516 | private Handler mHandler; |
| 1517 | |
| 1518 | // For async handler to identify request type |
| 1519 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1520 | |
| 1521 | public UnlockSim(IccCard simCard) { |
| 1522 | mSimCard = simCard; |
| 1523 | } |
| 1524 | |
| 1525 | @Override |
| 1526 | public void run() { |
| 1527 | Looper.prepare(); |
| 1528 | synchronized (UnlockSim.this) { |
| 1529 | mHandler = new Handler() { |
| 1530 | @Override |
| 1531 | public void handleMessage(Message msg) { |
| 1532 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1533 | switch (msg.what) { |
| 1534 | case SUPPLY_PIN_COMPLETE: |
| 1535 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1536 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1537 | mRetryCount = msg.arg1; |
| 1538 | if (ar.exception != null) { |
| 1539 | if (ar.exception instanceof CommandException && |
| 1540 | ((CommandException)(ar.exception)).getCommandError() |
| 1541 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1542 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1543 | } else { |
| 1544 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1545 | } |
| 1546 | } else { |
| 1547 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1548 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1549 | mDone = true; |
| 1550 | UnlockSim.this.notifyAll(); |
| 1551 | } |
| 1552 | break; |
| 1553 | } |
| 1554 | } |
| 1555 | }; |
| 1556 | UnlockSim.this.notifyAll(); |
| 1557 | } |
| 1558 | Looper.loop(); |
| 1559 | } |
| 1560 | |
| 1561 | /* |
| 1562 | * Use PIN or PUK to unlock SIM card |
| 1563 | * |
| 1564 | * If PUK is null, unlock SIM card with PIN |
| 1565 | * |
| 1566 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1567 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1568 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1569 | |
| 1570 | while (mHandler == null) { |
| 1571 | try { |
| 1572 | wait(); |
| 1573 | } catch (InterruptedException e) { |
| 1574 | Thread.currentThread().interrupt(); |
| 1575 | } |
| 1576 | } |
| 1577 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1578 | |
| 1579 | if (puk == null) { |
| 1580 | mSimCard.supplyPin(pin, callback); |
| 1581 | } else { |
| 1582 | mSimCard.supplyPuk(puk, pin, callback); |
| 1583 | } |
| 1584 | |
| 1585 | while (!mDone) { |
| 1586 | try { |
| 1587 | Log.d(LOG_TAG, "wait for done"); |
| 1588 | wait(); |
| 1589 | } catch (InterruptedException e) { |
| 1590 | // Restore the interrupted status |
| 1591 | Thread.currentThread().interrupt(); |
| 1592 | } |
| 1593 | } |
| 1594 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1595 | int[] resultArray = new int[2]; |
| 1596 | resultArray[0] = mResult; |
| 1597 | resultArray[1] = mRetryCount; |
| 1598 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1603 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1604 | |
| 1605 | } |
| 1606 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1607 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1608 | // No permission check needed here: this call is harmless, and it's |
| 1609 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1610 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1611 | final long identity = Binder.clearCallingIdentity(); |
| 1612 | try { |
| 1613 | final Phone phone = getPhone(subId); |
| 1614 | if (phone != null) { |
| 1615 | phone.updateServiceLocation(); |
| 1616 | } |
| 1617 | } finally { |
| 1618 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1619 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1620 | } |
| 1621 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1622 | @Override |
| 1623 | public boolean isRadioOn(String callingPackage) { |
| 1624 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1625 | } |
| 1626 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1627 | @Override |
| 1628 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1629 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1630 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1631 | return false; |
| 1632 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1633 | |
| 1634 | final long identity = Binder.clearCallingIdentity(); |
| 1635 | try { |
| 1636 | return isRadioOnForSubscriber(subId); |
| 1637 | } finally { |
| 1638 | Binder.restoreCallingIdentity(identity); |
| 1639 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1643 | final long identity = Binder.clearCallingIdentity(); |
| 1644 | try { |
| 1645 | final Phone phone = getPhone(subId); |
| 1646 | if (phone != null) { |
| 1647 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1648 | } else { |
| 1649 | return false; |
| 1650 | } |
| 1651 | } finally { |
| 1652 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1653 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1657 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1658 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1659 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1660 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1661 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1662 | |
| 1663 | final long identity = Binder.clearCallingIdentity(); |
| 1664 | try { |
| 1665 | final Phone phone = getPhone(subId); |
| 1666 | if (phone != null) { |
| 1667 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1668 | } |
| 1669 | } finally { |
| 1670 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1671 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1675 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1678 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1679 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1680 | |
| 1681 | final long identity = Binder.clearCallingIdentity(); |
| 1682 | try { |
| 1683 | final Phone phone = getPhone(subId); |
| 1684 | if (phone == null) { |
| 1685 | return false; |
| 1686 | } |
| 1687 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1688 | toggleRadioOnOffForSubscriber(subId); |
| 1689 | } |
| 1690 | return true; |
| 1691 | } finally { |
| 1692 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1693 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1694 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1695 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1696 | public boolean needMobileRadioShutdown() { |
| 1697 | /* |
| 1698 | * If any of the Radios are available, it will need to be |
| 1699 | * shutdown. So return true if any Radio is available. |
| 1700 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1701 | final long identity = Binder.clearCallingIdentity(); |
| 1702 | try { |
| 1703 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1704 | Phone phone = PhoneFactory.getPhone(i); |
| 1705 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1706 | } |
| 1707 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1708 | return false; |
| 1709 | } finally { |
| 1710 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1711 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1714 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1715 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1716 | enforceModifyPermission(); |
| 1717 | |
| 1718 | final long identity = Binder.clearCallingIdentity(); |
| 1719 | try { |
| 1720 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1721 | logv("Shutting down Phone " + i); |
| 1722 | shutdownRadioUsingPhoneId(i); |
| 1723 | } |
| 1724 | } finally { |
| 1725 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1730 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1731 | if (phone != null && phone.isRadioAvailable()) { |
| 1732 | phone.shutdownRadio(); |
| 1733 | } |
| 1734 | } |
| 1735 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1736 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1737 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1738 | |
| 1739 | final long identity = Binder.clearCallingIdentity(); |
| 1740 | try { |
| 1741 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1742 | if (defaultPhone != null) { |
| 1743 | defaultPhone.setRadioPower(turnOn); |
| 1744 | return true; |
| 1745 | } else { |
| 1746 | loge("There's no default phone."); |
| 1747 | return false; |
| 1748 | } |
| 1749 | } finally { |
| 1750 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1751 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1754 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1755 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1756 | |
| 1757 | final long identity = Binder.clearCallingIdentity(); |
| 1758 | try { |
| 1759 | final Phone phone = getPhone(subId); |
| 1760 | if (phone != null) { |
| 1761 | phone.setRadioPower(turnOn); |
| 1762 | return true; |
| 1763 | } else { |
| 1764 | return false; |
| 1765 | } |
| 1766 | } finally { |
| 1767 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1768 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1771 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1772 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1773 | public boolean enableDataConnectivity() { |
| 1774 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1775 | |
| 1776 | final long identity = Binder.clearCallingIdentity(); |
| 1777 | try { |
| 1778 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1779 | final Phone phone = getPhone(subId); |
| 1780 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1781 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1782 | return true; |
| 1783 | } else { |
| 1784 | return false; |
| 1785 | } |
| 1786 | } finally { |
| 1787 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1788 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1791 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1792 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1793 | public boolean disableDataConnectivity() { |
| 1794 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1795 | |
| 1796 | final long identity = Binder.clearCallingIdentity(); |
| 1797 | try { |
| 1798 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1799 | final Phone phone = getPhone(subId); |
| 1800 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1801 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1802 | return true; |
| 1803 | } else { |
| 1804 | return false; |
| 1805 | } |
| 1806 | } finally { |
| 1807 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1808 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1811 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1812 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1813 | final long identity = Binder.clearCallingIdentity(); |
| 1814 | try { |
| 1815 | final Phone phone = getPhone(subId); |
| 1816 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1817 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1818 | } else { |
| 1819 | return false; |
| 1820 | } |
| 1821 | } finally { |
| 1822 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1823 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1827 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1828 | } |
| 1829 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1830 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1831 | enforceCallPermission(); |
| 1832 | |
| 1833 | final long identity = Binder.clearCallingIdentity(); |
| 1834 | try { |
| 1835 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1836 | return; |
| 1837 | } |
| 1838 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1839 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1840 | } finally { |
| 1841 | Binder.restoreCallingIdentity(identity); |
| 1842 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1843 | }; |
| 1844 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1845 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1846 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1847 | |
| 1848 | final long identity = Binder.clearCallingIdentity(); |
| 1849 | try { |
| 1850 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1851 | return false; |
| 1852 | } |
| 1853 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 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 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1859 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1860 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1863 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1864 | final long identity = Binder.clearCallingIdentity(); |
| 1865 | try { |
| 1866 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1867 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1868 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1869 | } finally { |
| 1870 | Binder.restoreCallingIdentity(identity); |
| 1871 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1872 | } |
| 1873 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1874 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1875 | public int getDataState() { |
Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1876 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1877 | } |
| 1878 | |
| 1879 | @Override |
| 1880 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1881 | final long identity = Binder.clearCallingIdentity(); |
| 1882 | try { |
Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1883 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1884 | if (phone != null) { |
| 1885 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1886 | } else { |
| 1887 | return PhoneConstantConversions.convertDataState( |
| 1888 | PhoneConstants.DataState.DISCONNECTED); |
| 1889 | } |
| 1890 | } finally { |
| 1891 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1892 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1893 | } |
| 1894 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1895 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1896 | public int getDataActivity() { |
Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1897 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1898 | } |
| 1899 | |
| 1900 | @Override |
| 1901 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1902 | final long identity = Binder.clearCallingIdentity(); |
| 1903 | try { |
Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1904 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1905 | if (phone != null) { |
| 1906 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1907 | } else { |
| 1908 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1909 | } |
| 1910 | } finally { |
| 1911 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1912 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1916 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1917 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1918 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1919 | |
| 1920 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1921 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1922 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1923 | .setCallingPackage(callingPackage) |
| 1924 | .setCallingPid(Binder.getCallingPid()) |
| 1925 | .setCallingUid(Binder.getCallingUid()) |
| 1926 | .setMethod("getCellLocation") |
| 1927 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1928 | .build()); |
| 1929 | switch (locationResult) { |
| 1930 | case DENIED_HARD: |
| 1931 | throw new SecurityException("Not allowed to access cell location"); |
| 1932 | case DENIED_SOFT: |
| 1933 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1936 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1937 | final long identity = Binder.clearCallingIdentity(); |
| 1938 | try { |
| 1939 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1940 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1941 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1942 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1943 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1944 | return data; |
| 1945 | } finally { |
| 1946 | Binder.restoreCallingIdentity(identity); |
| 1947 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1950 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1951 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1952 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1953 | // registered cell info, so return a NULL country instead. |
| 1954 | final long identity = Binder.clearCallingIdentity(); |
| 1955 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1956 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1957 | // Get default phone in this case. |
| 1958 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1959 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1960 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1961 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1962 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1963 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1964 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1965 | return ""; |
| 1966 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1967 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1968 | if (phone != null) { |
| 1969 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 1970 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1971 | if (sst != null) { |
| 1972 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1973 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 1974 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 1975 | return lt.getCurrentCountry(); |
| 1976 | } else if (emergencyNumberTracker != null) { |
| 1977 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 1978 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1979 | } |
| 1980 | } |
| 1981 | } |
| 1982 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1983 | } finally { |
| 1984 | Binder.restoreCallingIdentity(identity); |
| 1985 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1989 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1990 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1993 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1994 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1995 | mApp.enforceCallingOrSelfPermission( |
| 1996 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1997 | |
| 1998 | final long identity = Binder.clearCallingIdentity(); |
| 1999 | try { |
| 2000 | final Phone phone = getPhone(subId); |
| 2001 | if (phone != null) { |
| 2002 | phone.enableLocationUpdates(); |
| 2003 | } |
| 2004 | } finally { |
| 2005 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2006 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | @Override |
| 2010 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2011 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2014 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2015 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2016 | mApp.enforceCallingOrSelfPermission( |
| 2017 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2018 | |
| 2019 | final long identity = Binder.clearCallingIdentity(); |
| 2020 | try { |
| 2021 | final Phone phone = getPhone(subId); |
| 2022 | if (phone != null) { |
| 2023 | phone.disableLocationUpdates(); |
| 2024 | } |
| 2025 | } finally { |
| 2026 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2027 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2030 | /** |
| 2031 | * Returns the target SDK version number for a given package name. |
| 2032 | * |
Nathan Harold | ba61eeb | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2033 | * This call MUST be invoked before clearing the calling UID. |
| 2034 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2035 | * @return target SDK if the package is found or INT_MAX. |
| 2036 | */ |
| 2037 | private int getTargetSdk(String packageName) { |
| 2038 | try { |
Nathan Harold | ba61eeb | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2039 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
| 2040 | packageName, 0, UserHandle.getUserId(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2041 | if (ai != null) return ai.targetSdkVersion; |
| 2042 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ba61eeb | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2043 | loge("Failed to get package info for pkg=" |
| 2044 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2045 | } |
| 2046 | return Integer.MAX_VALUE; |
| 2047 | } |
| 2048 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2049 | @Override |
| 2050 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2051 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2052 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2053 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2054 | throw new SecurityException( |
| 2055 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2056 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2057 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2058 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 2059 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2060 | return null; |
| 2061 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2062 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2063 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2064 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2065 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2066 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2067 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2068 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2069 | for (CellInfo ci : info) { |
| 2070 | if (ci instanceof CellInfoGsm) { |
| 2071 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2072 | } else if (ci instanceof CellInfoWcdma) { |
| 2073 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2074 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2075 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2076 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2079 | private List<CellInfo> getCachedCellInfo() { |
| 2080 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2081 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2082 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2083 | if (info != null) cellInfos.addAll(info); |
| 2084 | } |
| 2085 | return cellInfos; |
| 2086 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2087 | |
| 2088 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2089 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2090 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2091 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2092 | |
| 2093 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2094 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2095 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2096 | .setCallingPackage(callingPackage) |
| 2097 | .setCallingPid(Binder.getCallingPid()) |
| 2098 | .setCallingUid(Binder.getCallingUid()) |
| 2099 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2100 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2101 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2102 | .build()); |
| 2103 | switch (locationResult) { |
| 2104 | case DENIED_HARD: |
| 2105 | throw new SecurityException("Not allowed to access cell info"); |
| 2106 | case DENIED_SOFT: |
| 2107 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2110 | final int targetSdk = getTargetSdk(callingPackage); |
| 2111 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2112 | return getCachedCellInfo(); |
| 2113 | } |
| 2114 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2115 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2116 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2117 | final long identity = Binder.clearCallingIdentity(); |
| 2118 | try { |
| 2119 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2120 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2121 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2122 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2123 | if (info != null) cellInfos.addAll(info); |
| 2124 | } |
| 2125 | return cellInfos; |
| 2126 | } finally { |
| 2127 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2128 | } |
| 2129 | } |
| 2130 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2131 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2132 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2133 | requestCellInfoUpdateInternal( |
| 2134 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2135 | } |
| 2136 | |
| 2137 | @Override |
| 2138 | public void requestCellInfoUpdateWithWorkSource( |
| 2139 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2140 | enforceModifyPermission(); |
| 2141 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2142 | } |
| 2143 | |
| 2144 | private void requestCellInfoUpdateInternal( |
| 2145 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2146 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2147 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2148 | |
| 2149 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2150 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2151 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2152 | .setCallingPackage(callingPackage) |
| 2153 | .setCallingPid(Binder.getCallingPid()) |
| 2154 | .setCallingUid(Binder.getCallingUid()) |
| 2155 | .setMethod("requestCellInfoUpdate") |
| 2156 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2157 | .build()); |
| 2158 | switch (locationResult) { |
| 2159 | case DENIED_HARD: |
| 2160 | throw new SecurityException("Not allowed to access cell info"); |
| 2161 | case DENIED_SOFT: |
Nathan Harold | b3c5da4 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2162 | try { |
| 2163 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2164 | } catch (RemoteException re) { |
| 2165 | // Drop without consequences |
| 2166 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2167 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2168 | } |
| 2169 | |
Nathan Harold | 32e84c4 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2170 | |
| 2171 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2172 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2173 | |
| 2174 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2175 | } |
| 2176 | |
| 2177 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2178 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2179 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2180 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2181 | |
| 2182 | final long identity = Binder.clearCallingIdentity(); |
| 2183 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2184 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2185 | } finally { |
| 2186 | Binder.restoreCallingIdentity(identity); |
| 2187 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2188 | } |
| 2189 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2190 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2191 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2192 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2193 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2194 | return null; |
| 2195 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2196 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2197 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2198 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2199 | return null; |
| 2200 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2201 | |
| 2202 | final long identity = Binder.clearCallingIdentity(); |
| 2203 | try { |
| 2204 | return phone.getImei(); |
| 2205 | } finally { |
| 2206 | Binder.restoreCallingIdentity(identity); |
| 2207 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2211 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2212 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2213 | String tac = null; |
| 2214 | if (phone != null) { |
| 2215 | String imei = phone.getImei(); |
| 2216 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2217 | } |
| 2218 | return tac; |
| 2219 | } |
| 2220 | |
| 2221 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2222 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2223 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2224 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2225 | return null; |
| 2226 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2227 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2228 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2229 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2230 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2231 | return null; |
| 2232 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2233 | |
| 2234 | final long identity = Binder.clearCallingIdentity(); |
| 2235 | try { |
| 2236 | return phone.getMeid(); |
| 2237 | } finally { |
| 2238 | Binder.restoreCallingIdentity(identity); |
| 2239 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2240 | } |
| 2241 | |
| 2242 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2243 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2244 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2245 | String manufacturerCode = null; |
| 2246 | if (phone != null) { |
| 2247 | String meid = phone.getMeid(); |
| 2248 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2249 | } |
| 2250 | return manufacturerCode; |
| 2251 | } |
| 2252 | |
| 2253 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2254 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2255 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2256 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2257 | return null; |
| 2258 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2259 | int subId = phone.getSubId(); |
| 2260 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2261 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2262 | return null; |
| 2263 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2264 | |
| 2265 | final long identity = Binder.clearCallingIdentity(); |
| 2266 | try { |
| 2267 | return phone.getDeviceSvn(); |
| 2268 | } finally { |
| 2269 | Binder.restoreCallingIdentity(identity); |
| 2270 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2271 | } |
| 2272 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2273 | @Override |
| 2274 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2275 | final long identity = Binder.clearCallingIdentity(); |
| 2276 | try { |
| 2277 | final Phone phone = getPhone(subId); |
| 2278 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2279 | } finally { |
| 2280 | Binder.restoreCallingIdentity(identity); |
| 2281 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | @Override |
| 2285 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2286 | final long identity = Binder.clearCallingIdentity(); |
| 2287 | try { |
| 2288 | final Phone phone = getPhone(subId); |
| 2289 | return phone == null ? null : phone.getCarrierName(); |
| 2290 | } finally { |
| 2291 | Binder.restoreCallingIdentity(identity); |
| 2292 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2293 | } |
| 2294 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2295 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2296 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2297 | final long identity = Binder.clearCallingIdentity(); |
| 2298 | try { |
| 2299 | final Phone phone = getPhone(subId); |
| 2300 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2301 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2302 | } finally { |
| 2303 | Binder.restoreCallingIdentity(identity); |
| 2304 | } |
| 2305 | } |
| 2306 | |
| 2307 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2308 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2309 | final long identity = Binder.clearCallingIdentity(); |
| 2310 | try { |
| 2311 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2312 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2313 | } finally { |
| 2314 | Binder.restoreCallingIdentity(identity); |
| 2315 | } |
| 2316 | } |
| 2317 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2318 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2319 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2320 | if (!isSubscriptionMccMnc) { |
| 2321 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2322 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2323 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2324 | if (phone == null) { |
| 2325 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2326 | } |
| 2327 | final long identity = Binder.clearCallingIdentity(); |
| 2328 | try { |
| 2329 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2330 | } finally { |
| 2331 | Binder.restoreCallingIdentity(identity); |
| 2332 | } |
| 2333 | } |
| 2334 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2335 | // |
| 2336 | // Internal helper methods. |
| 2337 | // |
| 2338 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2339 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2340 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2341 | * |
| 2342 | * @throws SecurityException if the caller does not have the required permission |
| 2343 | */ |
| 2344 | private void enforceModifyPermission() { |
| 2345 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2346 | } |
| 2347 | |
| 2348 | /** |
| 2349 | * Make sure the caller has the CALL_PHONE permission. |
| 2350 | * |
| 2351 | * @throws SecurityException if the caller does not have the required permission |
| 2352 | */ |
| 2353 | private void enforceCallPermission() { |
| 2354 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2355 | } |
| 2356 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2357 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2358 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2359 | "ConnectivityService"); |
| 2360 | } |
| 2361 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2362 | private String createTelUrl(String number) { |
| 2363 | if (TextUtils.isEmpty(number)) { |
| 2364 | return null; |
| 2365 | } |
| 2366 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2367 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2368 | } |
| 2369 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2370 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2371 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2372 | } |
| 2373 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2374 | private static void logv(String msg) { |
| 2375 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2376 | } |
| 2377 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2378 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2379 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2380 | } |
| 2381 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2382 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2383 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2384 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2387 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2388 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2389 | final long identity = Binder.clearCallingIdentity(); |
| 2390 | try { |
| 2391 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2392 | if (phone == null) { |
| 2393 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2394 | } else { |
| 2395 | return phone.getPhoneType(); |
| 2396 | } |
| 2397 | } finally { |
| 2398 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2399 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | /** |
| 2403 | * Returns the CDMA ERI icon index to display |
| 2404 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2405 | @Override |
| 2406 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2407 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2408 | } |
| 2409 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2410 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2411 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2412 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2413 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2414 | return -1; |
| 2415 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2416 | |
| 2417 | final long identity = Binder.clearCallingIdentity(); |
| 2418 | try { |
| 2419 | final Phone phone = getPhone(subId); |
| 2420 | if (phone != null) { |
| 2421 | return phone.getCdmaEriIconIndex(); |
| 2422 | } else { |
| 2423 | return -1; |
| 2424 | } |
| 2425 | } finally { |
| 2426 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2427 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | /** |
| 2431 | * Returns the CDMA ERI icon mode, |
| 2432 | * 0 - ON |
| 2433 | * 1 - FLASHING |
| 2434 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2435 | @Override |
| 2436 | public int getCdmaEriIconMode(String callingPackage) { |
| 2437 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2440 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2441 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2442 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2443 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2444 | return -1; |
| 2445 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2446 | |
| 2447 | final long identity = Binder.clearCallingIdentity(); |
| 2448 | try { |
| 2449 | final Phone phone = getPhone(subId); |
| 2450 | if (phone != null) { |
| 2451 | return phone.getCdmaEriIconMode(); |
| 2452 | } else { |
| 2453 | return -1; |
| 2454 | } |
| 2455 | } finally { |
| 2456 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2457 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | /** |
| 2461 | * Returns the CDMA ERI text, |
| 2462 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2463 | @Override |
| 2464 | public String getCdmaEriText(String callingPackage) { |
| 2465 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2466 | } |
| 2467 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2468 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2469 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2470 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2471 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2472 | return null; |
| 2473 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2474 | |
| 2475 | final long identity = Binder.clearCallingIdentity(); |
| 2476 | try { |
| 2477 | final Phone phone = getPhone(subId); |
| 2478 | if (phone != null) { |
| 2479 | return phone.getCdmaEriText(); |
| 2480 | } else { |
| 2481 | return null; |
| 2482 | } |
| 2483 | } finally { |
| 2484 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2485 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2489 | * Returns the CDMA MDN. |
| 2490 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2491 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2492 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2493 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2494 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2495 | |
| 2496 | final long identity = Binder.clearCallingIdentity(); |
| 2497 | try { |
| 2498 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2499 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2500 | return phone.getLine1Number(); |
| 2501 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2502 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2503 | return null; |
| 2504 | } |
| 2505 | } finally { |
| 2506 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2507 | } |
| 2508 | } |
| 2509 | |
| 2510 | /** |
| 2511 | * Returns the CDMA MIN. |
| 2512 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2513 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2514 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2515 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2516 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2517 | |
| 2518 | final long identity = Binder.clearCallingIdentity(); |
| 2519 | try { |
| 2520 | final Phone phone = getPhone(subId); |
| 2521 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2522 | return phone.getCdmaMin(); |
| 2523 | } else { |
| 2524 | return null; |
| 2525 | } |
| 2526 | } finally { |
| 2527 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2528 | } |
| 2529 | } |
| 2530 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2531 | @Override |
| 2532 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2533 | INumberVerificationCallback callback, String callingPackage) { |
| 2534 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2535 | != PERMISSION_GRANTED) { |
| 2536 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2537 | } |
| 2538 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2539 | |
| 2540 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2541 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2542 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2543 | } |
| 2544 | |
| 2545 | if (range == null) { |
| 2546 | throw new NullPointerException("Range must be non-null"); |
| 2547 | } |
| 2548 | |
| 2549 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2550 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2551 | |
| 2552 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2553 | } |
| 2554 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2555 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2556 | * Returns true if CDMA provisioning needs to run. |
| 2557 | */ |
| 2558 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2559 | final long identity = Binder.clearCallingIdentity(); |
| 2560 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2561 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2562 | } finally { |
| 2563 | Binder.restoreCallingIdentity(identity); |
| 2564 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2568 | * Sets the voice mail number of a given subId. |
| 2569 | */ |
| 2570 | @Override |
| 2571 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2572 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2573 | |
| 2574 | final long identity = Binder.clearCallingIdentity(); |
| 2575 | try { |
| 2576 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2577 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2578 | return success; |
| 2579 | } finally { |
| 2580 | Binder.restoreCallingIdentity(identity); |
| 2581 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2582 | } |
| 2583 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2584 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2585 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2586 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2587 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2588 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2589 | throw new SecurityException("caller must be system dialer"); |
| 2590 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2591 | |
| 2592 | final long identity = Binder.clearCallingIdentity(); |
| 2593 | try { |
| 2594 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2595 | if (phoneAccountHandle == null) { |
| 2596 | return null; |
| 2597 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2598 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2599 | } finally { |
| 2600 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2601 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2605 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2606 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2607 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2608 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2609 | return null; |
| 2610 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2611 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2612 | final long identity = Binder.clearCallingIdentity(); |
| 2613 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2614 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2615 | } finally { |
| 2616 | Binder.restoreCallingIdentity(identity); |
| 2617 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2621 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2622 | VisualVoicemailSmsFilterSettings settings) { |
| 2623 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2624 | |
| 2625 | final long identity = Binder.clearCallingIdentity(); |
| 2626 | try { |
| 2627 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2628 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2629 | } finally { |
| 2630 | Binder.restoreCallingIdentity(identity); |
| 2631 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2635 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2636 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2637 | |
| 2638 | final long identity = Binder.clearCallingIdentity(); |
| 2639 | try { |
| 2640 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2641 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2642 | } finally { |
| 2643 | Binder.restoreCallingIdentity(identity); |
| 2644 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
| 2647 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2648 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2649 | String callingPackage, int subId) { |
| 2650 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2651 | |
| 2652 | final long identity = Binder.clearCallingIdentity(); |
| 2653 | try { |
| 2654 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2655 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2656 | } finally { |
| 2657 | Binder.restoreCallingIdentity(identity); |
| 2658 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2662 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2663 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2664 | |
| 2665 | final long identity = Binder.clearCallingIdentity(); |
| 2666 | try { |
| 2667 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2668 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2669 | } finally { |
| 2670 | Binder.restoreCallingIdentity(identity); |
| 2671 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | @Override |
| 2675 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2676 | String number, int port, String text, PendingIntent sentIntent) { |
| 2677 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2678 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2679 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2680 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2681 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2682 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2683 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2684 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2685 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2686 | * Sets the voice activation state of a given subId. |
| 2687 | */ |
| 2688 | @Override |
| 2689 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2690 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2691 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2692 | |
| 2693 | final long identity = Binder.clearCallingIdentity(); |
| 2694 | try { |
| 2695 | final Phone phone = getPhone(subId); |
| 2696 | if (phone != null) { |
| 2697 | phone.setVoiceActivationState(activationState); |
| 2698 | } else { |
| 2699 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2700 | } |
| 2701 | } finally { |
| 2702 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2703 | } |
| 2704 | } |
| 2705 | |
| 2706 | /** |
| 2707 | * Sets the data activation state of a given subId. |
| 2708 | */ |
| 2709 | @Override |
| 2710 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2711 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2712 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2713 | |
| 2714 | final long identity = Binder.clearCallingIdentity(); |
| 2715 | try { |
| 2716 | final Phone phone = getPhone(subId); |
| 2717 | if (phone != null) { |
| 2718 | phone.setDataActivationState(activationState); |
| 2719 | } else { |
| 2720 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2721 | } |
| 2722 | } finally { |
| 2723 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2724 | } |
| 2725 | } |
| 2726 | |
| 2727 | /** |
| 2728 | * Returns the voice activation state of a given subId. |
| 2729 | */ |
| 2730 | @Override |
| 2731 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2732 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2733 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2734 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2735 | final long identity = Binder.clearCallingIdentity(); |
| 2736 | try { |
| 2737 | if (phone != null) { |
| 2738 | return phone.getVoiceActivationState(); |
| 2739 | } else { |
| 2740 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2741 | } |
| 2742 | } finally { |
| 2743 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2744 | } |
| 2745 | } |
| 2746 | |
| 2747 | /** |
| 2748 | * Returns the data activation state of a given subId. |
| 2749 | */ |
| 2750 | @Override |
| 2751 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2752 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2753 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2754 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2755 | final long identity = Binder.clearCallingIdentity(); |
| 2756 | try { |
| 2757 | if (phone != null) { |
| 2758 | return phone.getDataActivationState(); |
| 2759 | } else { |
| 2760 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2761 | } |
| 2762 | } finally { |
| 2763 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2764 | } |
| 2765 | } |
| 2766 | |
| 2767 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2768 | * Returns the unread count of voicemails for a subId |
| 2769 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2770 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2771 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2772 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2773 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2774 | return 0; |
| 2775 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2776 | final long identity = Binder.clearCallingIdentity(); |
| 2777 | try { |
| 2778 | final Phone phone = getPhone(subId); |
| 2779 | if (phone != null) { |
| 2780 | return phone.getVoiceMessageCount(); |
| 2781 | } else { |
| 2782 | return 0; |
| 2783 | } |
| 2784 | } finally { |
| 2785 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2786 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2790 | * returns true, if the device is in a state where both voice and data |
| 2791 | * are supported simultaneously. This can change based on location or network condition. |
| 2792 | */ |
| 2793 | @Override |
| 2794 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2795 | final long identity = Binder.clearCallingIdentity(); |
| 2796 | try { |
| 2797 | final Phone phone = getPhone(subId); |
| 2798 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2799 | } finally { |
| 2800 | Binder.restoreCallingIdentity(identity); |
| 2801 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2805 | * Send the dialer code if called from the current default dialer or the caller has |
| 2806 | * carrier privilege. |
| 2807 | * @param inputCode The dialer code to send |
| 2808 | */ |
| 2809 | @Override |
| 2810 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2811 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2812 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2813 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2814 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2815 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2816 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2817 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2818 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2819 | |
| 2820 | final long identity = Binder.clearCallingIdentity(); |
| 2821 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2822 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2823 | } finally { |
| 2824 | Binder.restoreCallingIdentity(identity); |
| 2825 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2826 | } |
| 2827 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2828 | @Override |
| 2829 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2830 | if (!isActiveSubscription(subId)) { |
| 2831 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2832 | } |
| 2833 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2834 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2835 | } |
| 2836 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2837 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2838 | public boolean isInEmergencySmsMode() { |
| 2839 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2840 | final long identity = Binder.clearCallingIdentity(); |
| 2841 | try { |
| 2842 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2843 | if (phone.isInEmergencySmsMode()) { |
| 2844 | return true; |
| 2845 | } |
| 2846 | } |
| 2847 | } finally { |
| 2848 | Binder.restoreCallingIdentity(identity); |
| 2849 | } |
| 2850 | return false; |
| 2851 | } |
| 2852 | |
| 2853 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2854 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2855 | throws RemoteException { |
| 2856 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2857 | final long token = Binder.clearCallingIdentity(); |
| 2858 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2859 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2860 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2861 | .addRegistrationCallbackForSubscription(c, subId); |
| 2862 | } finally { |
| 2863 | Binder.restoreCallingIdentity(token); |
| 2864 | } |
| 2865 | } |
| 2866 | |
| 2867 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2868 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2869 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2870 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2871 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2872 | } |
| 2873 | Binder.withCleanCallingIdentity(() -> { |
| 2874 | try { |
| 2875 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2876 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2877 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2878 | } catch (IllegalArgumentException e) { |
| 2879 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2880 | + "is inactive, ignoring unregister."); |
| 2881 | // If the subscription is no longer active, just return, since the callback |
| 2882 | // will already have been removed internally. |
| 2883 | } |
| 2884 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2888 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2889 | throws RemoteException { |
| 2890 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2891 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2892 | final long token = Binder.clearCallingIdentity(); |
| 2893 | try { |
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 | .addCapabilitiesCallbackForSubscription(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 unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2903 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2904 | |
| 2905 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2906 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2907 | } |
| 2908 | Binder.withCleanCallingIdentity(() -> { |
| 2909 | try { |
| 2910 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2911 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2912 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2913 | } catch (IllegalArgumentException e) { |
| 2914 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2915 | + "is inactive, ignoring unregister."); |
| 2916 | // If the subscription is no longer active, just return, since the callback |
| 2917 | // will already have been removed internally. |
| 2918 | } |
| 2919 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
| 2922 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2923 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2924 | enforceReadPrivilegedPermission("isCapable"); |
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 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2929 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2930 | } catch (ImsException e) { |
| 2931 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2932 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2933 | } catch (IllegalArgumentException e) { |
| 2934 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2935 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2936 | } finally { |
| 2937 | Binder.restoreCallingIdentity(token); |
| 2938 | } |
| 2939 | } |
| 2940 | |
| 2941 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2942 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2943 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2944 | final long token = Binder.clearCallingIdentity(); |
| 2945 | try { |
| 2946 | Phone phone = getPhone(subId); |
| 2947 | if (phone == null) return false; |
| 2948 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2949 | } finally { |
| 2950 | Binder.restoreCallingIdentity(token); |
| 2951 | } |
| 2952 | } |
| 2953 | |
| 2954 | @Override |
| 2955 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2956 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2957 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2958 | final long token = Binder.clearCallingIdentity(); |
| 2959 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2960 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2961 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2962 | } finally { |
| 2963 | Binder.restoreCallingIdentity(token); |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2968 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2969 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2970 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2971 | final long identity = Binder.clearCallingIdentity(); |
| 2972 | try { |
| 2973 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2974 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2975 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2976 | } finally { |
| 2977 | Binder.restoreCallingIdentity(identity); |
| 2978 | } |
| 2979 | } |
| 2980 | |
| 2981 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2982 | public boolean isVtSettingEnabled(int subId) { |
| 2983 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2984 | final long identity = Binder.clearCallingIdentity(); |
| 2985 | try { |
| 2986 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2987 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2988 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2989 | } finally { |
| 2990 | Binder.restoreCallingIdentity(identity); |
| 2991 | } |
| 2992 | } |
| 2993 | |
| 2994 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2995 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2996 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2997 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2998 | final long identity = Binder.clearCallingIdentity(); |
| 2999 | try { |
| 3000 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3001 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3002 | } finally { |
| 3003 | Binder.restoreCallingIdentity(identity); |
| 3004 | } |
| 3005 | } |
| 3006 | |
| 3007 | @Override |
| 3008 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3009 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3010 | final long identity = Binder.clearCallingIdentity(); |
| 3011 | try { |
| 3012 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3013 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3014 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 3015 | } finally { |
| 3016 | Binder.restoreCallingIdentity(identity); |
| 3017 | } |
| 3018 | } |
| 3019 | |
| 3020 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3021 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3022 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3023 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3024 | final long identity = Binder.clearCallingIdentity(); |
| 3025 | try { |
| 3026 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3027 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3028 | } finally { |
| 3029 | Binder.restoreCallingIdentity(identity); |
| 3030 | } |
| 3031 | } |
| 3032 | |
| 3033 | @Override |
| 3034 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3035 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3036 | final long identity = Binder.clearCallingIdentity(); |
| 3037 | try { |
| 3038 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3039 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3040 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 3041 | } finally { |
| 3042 | Binder.restoreCallingIdentity(identity); |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3047 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3048 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3049 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3050 | final long identity = Binder.clearCallingIdentity(); |
| 3051 | try { |
| 3052 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3053 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3054 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 3055 | } finally { |
| 3056 | Binder.restoreCallingIdentity(identity); |
| 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | @Override |
| 3061 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3062 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3063 | "setVoWiFiNonPersistent"); |
| 3064 | final long identity = Binder.clearCallingIdentity(); |
| 3065 | try { |
| 3066 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3067 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3068 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3069 | } finally { |
| 3070 | Binder.restoreCallingIdentity(identity); |
| 3071 | } |
| 3072 | } |
| 3073 | |
| 3074 | @Override |
| 3075 | public int getVoWiFiModeSetting(int subId) { |
| 3076 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3077 | final long identity = Binder.clearCallingIdentity(); |
| 3078 | try { |
| 3079 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3080 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3081 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3082 | } finally { |
| 3083 | Binder.restoreCallingIdentity(identity); |
| 3084 | } |
| 3085 | } |
| 3086 | |
| 3087 | @Override |
| 3088 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3089 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3090 | "setVoWiFiModeSetting"); |
| 3091 | final long identity = Binder.clearCallingIdentity(); |
| 3092 | try { |
| 3093 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3094 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3095 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3096 | } finally { |
| 3097 | Binder.restoreCallingIdentity(identity); |
| 3098 | } |
| 3099 | } |
| 3100 | |
| 3101 | @Override |
| 3102 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3103 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3104 | final long identity = Binder.clearCallingIdentity(); |
| 3105 | try { |
| 3106 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3107 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3108 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3109 | } finally { |
| 3110 | Binder.restoreCallingIdentity(identity); |
| 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | @Override |
| 3115 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3116 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3117 | "setVoWiFiRoamingModeSetting"); |
| 3118 | final long identity = Binder.clearCallingIdentity(); |
| 3119 | try { |
| 3120 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3121 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3122 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3123 | } finally { |
| 3124 | Binder.restoreCallingIdentity(identity); |
| 3125 | } |
| 3126 | } |
| 3127 | |
| 3128 | @Override |
| 3129 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3130 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3131 | "setRttCapabilityEnabled"); |
| 3132 | final long identity = Binder.clearCallingIdentity(); |
| 3133 | try { |
| 3134 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3135 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3136 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3137 | } finally { |
| 3138 | Binder.restoreCallingIdentity(identity); |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | @Override |
| 3143 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3144 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3145 | final long identity = Binder.clearCallingIdentity(); |
| 3146 | try { |
| 3147 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3148 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3149 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3150 | } finally { |
| 3151 | Binder.restoreCallingIdentity(identity); |
| 3152 | } |
| 3153 | } |
| 3154 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3155 | @Override |
| 3156 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3157 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3158 | final long identity = Binder.clearCallingIdentity(); |
| 3159 | try { |
| 3160 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3161 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3162 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3163 | } finally { |
| 3164 | Binder.restoreCallingIdentity(identity); |
| 3165 | } |
| 3166 | } |
| 3167 | |
| 3168 | @Override |
| 3169 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3170 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3171 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3172 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3173 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3174 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3175 | try { |
| 3176 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3177 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3178 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3179 | } catch (IllegalArgumentException e) { |
| 3180 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3181 | + "is inactive, ignoring unregister."); |
| 3182 | // If the subscription is no longer active, just return, since the callback will already |
| 3183 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3184 | } finally { |
| 3185 | Binder.restoreCallingIdentity(identity); |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3190 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3191 | boolean isProvisioned) { |
| 3192 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3193 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3194 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3195 | } |
| 3196 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3197 | "setProvisioningStatusForCapability"); |
| 3198 | final long identity = Binder.clearCallingIdentity(); |
| 3199 | try { |
| 3200 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3201 | Phone phone = getPhone(subId); |
| 3202 | if (phone == null) { |
| 3203 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3204 | + subId); |
| 3205 | return; |
| 3206 | } |
| 3207 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3208 | return; |
| 3209 | } |
| 3210 | |
| 3211 | // this capability requires provisioning, route to the correct API. |
| 3212 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3213 | switch (capability) { |
| 3214 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3215 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3216 | ims.setVolteProvisioned(isProvisioned); |
| 3217 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3218 | ims.setWfcProvisioned(isProvisioned); |
| 3219 | } |
| 3220 | break; |
| 3221 | } |
| 3222 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3223 | // There is currently no difference in VT provisioning type. |
| 3224 | ims.setVtProvisioned(isProvisioned); |
| 3225 | break; |
| 3226 | } |
| 3227 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3228 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3229 | // change the capability of the feature instead if needed. |
| 3230 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3231 | == isProvisioned) { |
| 3232 | // No change in provisioning. |
| 3233 | return; |
| 3234 | } |
| 3235 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3236 | try { |
| 3237 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3238 | } catch (ImsException e) { |
| 3239 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3240 | + ", Exception" + e.getMessage()); |
| 3241 | } |
| 3242 | break; |
| 3243 | } |
| 3244 | default: { |
| 3245 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3246 | + capability + "', which does not require provisioning."); |
| 3247 | } |
| 3248 | } |
| 3249 | |
| 3250 | } finally { |
| 3251 | Binder.restoreCallingIdentity(identity); |
| 3252 | } |
| 3253 | } |
| 3254 | |
| 3255 | @Override |
| 3256 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3257 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3258 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3259 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3260 | } |
| 3261 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3262 | final long identity = Binder.clearCallingIdentity(); |
| 3263 | try { |
| 3264 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3265 | Phone phone = getPhone(subId); |
| 3266 | if (phone == null) { |
| 3267 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3268 | + subId); |
| 3269 | // We will fail with "true" as the provisioning status because this is the default |
| 3270 | // if we do not require provisioning. |
| 3271 | return true; |
| 3272 | } |
| 3273 | |
| 3274 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3275 | return true; |
| 3276 | } |
| 3277 | |
| 3278 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3279 | switch (capability) { |
| 3280 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3281 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3282 | return ims.isVolteProvisionedOnDevice(); |
| 3283 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3284 | return ims.isWfcProvisionedOnDevice(); |
| 3285 | } |
| 3286 | // This should never happen, since we are checking tech above to make sure it |
| 3287 | // is either LTE or IWLAN. |
| 3288 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3289 | + "capability."); |
| 3290 | } |
| 3291 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3292 | // There is currently no difference in VT provisioning type. |
| 3293 | return ims.isVtProvisionedOnDevice(); |
| 3294 | } |
| 3295 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3296 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3297 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3298 | } |
| 3299 | default: { |
| 3300 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3301 | + capability + "', which does not require provisioning."); |
| 3302 | } |
| 3303 | } |
| 3304 | |
| 3305 | } finally { |
| 3306 | Binder.restoreCallingIdentity(identity); |
| 3307 | } |
| 3308 | } |
| 3309 | |
| 3310 | @Override |
| 3311 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3312 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3313 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3314 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3315 | } |
| 3316 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3317 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3318 | return (provisionedBits & capability) > 0; |
| 3319 | } |
| 3320 | |
| 3321 | @Override |
| 3322 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3323 | boolean isProvisioned) { |
| 3324 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3325 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3326 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3327 | } |
| 3328 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3329 | "setProvisioningStatusForCapability"); |
| 3330 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3331 | // If the current provisioning status for capability already matches isProvisioned, |
| 3332 | // do nothing. |
| 3333 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3334 | return; |
| 3335 | } |
| 3336 | if (isProvisioned) { |
| 3337 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3338 | } else { |
| 3339 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | /** |
| 3344 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3345 | * technology. The bitfield should mirror the bitfield defined by |
| 3346 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3347 | */ |
| 3348 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3349 | String key = getMmTelProvisioningKey(subId, tech); |
| 3350 | // Default is no capabilities are provisioned. |
| 3351 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3352 | } |
| 3353 | |
| 3354 | /** |
| 3355 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3356 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3357 | * technology specified. |
| 3358 | * |
| 3359 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3360 | */ |
| 3361 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3362 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3363 | String key = getMmTelProvisioningKey(subId, tech); |
| 3364 | editor.putInt(key, newField); |
| 3365 | editor.commit(); |
| 3366 | } |
| 3367 | |
| 3368 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3369 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3370 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3371 | } |
| 3372 | |
| 3373 | /** |
| 3374 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3375 | * carrier associated with the subscription id. |
| 3376 | */ |
| 3377 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3378 | int capability) { |
| 3379 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3380 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3381 | boolean requireUtProvisioning = c.getBoolean( |
| 3382 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3383 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3384 | // the no-SIM case, where we would normally shortcut this to false. |
| 3385 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3386 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3387 | false); |
| 3388 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3389 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3390 | |
| 3391 | // First check to make sure that the capability requires provisioning. |
| 3392 | switch (capability) { |
| 3393 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3394 | // intentional fallthrough |
| 3395 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3396 | if (requireVoiceVtProvisioning) { |
| 3397 | // Voice and Video requires provisioning |
| 3398 | return true; |
| 3399 | } |
| 3400 | break; |
| 3401 | } |
| 3402 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3403 | if (requireUtProvisioning) { |
| 3404 | // UT requires provisioning |
| 3405 | return true; |
| 3406 | } |
| 3407 | break; |
| 3408 | } |
| 3409 | } |
| 3410 | return false; |
| 3411 | } |
| 3412 | |
| 3413 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3414 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3415 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3416 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3417 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3418 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3419 | final long identity = Binder.clearCallingIdentity(); |
| 3420 | try { |
| 3421 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3422 | int slotId = getSlotIndex(subId); |
| 3423 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3424 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3425 | + subId + "' for key:" + key); |
| 3426 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3427 | } |
| 3428 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3429 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3430 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3431 | + subId + "' for key:" + key); |
| 3432 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3433 | } finally { |
| 3434 | Binder.restoreCallingIdentity(identity); |
| 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | @Override |
| 3439 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3440 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3441 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3442 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3443 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3444 | final long identity = Binder.clearCallingIdentity(); |
| 3445 | try { |
| 3446 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3447 | int slotId = getSlotIndex(subId); |
| 3448 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3449 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3450 | + subId + "' for key:" + key); |
| 3451 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3452 | } |
| 3453 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3454 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3455 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3456 | + subId + "' for key:" + key); |
| 3457 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3458 | } finally { |
| 3459 | Binder.restoreCallingIdentity(identity); |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | @Override |
| 3464 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3465 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3466 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3467 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3468 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3469 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3470 | final long identity = Binder.clearCallingIdentity(); |
| 3471 | try { |
| 3472 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3473 | int slotId = getSlotIndex(subId); |
| 3474 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3475 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3476 | + subId + "' for key:" + key); |
| 3477 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3478 | } |
| 3479 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3480 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3481 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3482 | + "' for key:" + key); |
| 3483 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3484 | } finally { |
| 3485 | Binder.restoreCallingIdentity(identity); |
| 3486 | } |
| 3487 | } |
| 3488 | |
| 3489 | @Override |
| 3490 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3491 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3492 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3493 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3494 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3495 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3496 | final long identity = Binder.clearCallingIdentity(); |
| 3497 | try { |
| 3498 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3499 | int slotId = getSlotIndex(subId); |
| 3500 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3501 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3502 | + subId + "' for key:" + key); |
| 3503 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3504 | } |
| 3505 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3506 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3507 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3508 | + "' for key:" + key); |
| 3509 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3510 | } finally { |
| 3511 | Binder.restoreCallingIdentity(identity); |
| 3512 | } |
| 3513 | } |
| 3514 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3515 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3516 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3517 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3518 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3519 | } |
| 3520 | return slotId; |
| 3521 | } |
| 3522 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3523 | private int getSlotIndex(int subId) { |
| 3524 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3525 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3526 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3527 | } |
| 3528 | return slotId; |
| 3529 | } |
| 3530 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3531 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3532 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3533 | */ |
| 3534 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3535 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3536 | if (getTargetSdk(callingPackage) >= android.os.Build.VERSION_CODES.Q |
| 3537 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
| 3538 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3539 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3540 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3541 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3542 | final long identity = Binder.clearCallingIdentity(); |
| 3543 | try { |
| 3544 | final Phone phone = getPhone(subId); |
| 3545 | if (phone != null) { |
| 3546 | return phone.getServiceState().getDataNetworkType(); |
| 3547 | } else { |
| 3548 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3549 | } |
| 3550 | } finally { |
| 3551 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3552 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | /** |
| 3556 | * Returns the data network type |
| 3557 | */ |
| 3558 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3559 | public int getDataNetworkType(String callingPackage) { |
| 3560 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | /** |
| 3564 | * Returns the data network type for a subId |
| 3565 | */ |
| 3566 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3567 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3568 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3569 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3570 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3571 | } |
| 3572 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3573 | final long identity = Binder.clearCallingIdentity(); |
| 3574 | try { |
| 3575 | final Phone phone = getPhone(subId); |
| 3576 | if (phone != null) { |
| 3577 | return phone.getServiceState().getDataNetworkType(); |
| 3578 | } else { |
| 3579 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3580 | } |
| 3581 | } finally { |
| 3582 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3583 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3584 | } |
| 3585 | |
| 3586 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3587 | * Returns the Voice network type for a subId |
| 3588 | */ |
| 3589 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3590 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3591 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3592 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3593 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3594 | } |
| 3595 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3596 | final long identity = Binder.clearCallingIdentity(); |
| 3597 | try { |
| 3598 | final Phone phone = getPhone(subId); |
| 3599 | if (phone != null) { |
| 3600 | return phone.getServiceState().getVoiceNetworkType(); |
| 3601 | } else { |
| 3602 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3603 | } |
| 3604 | } finally { |
| 3605 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3606 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3607 | } |
| 3608 | |
| 3609 | /** |
| 3610 | * @return true if a ICC card is present |
| 3611 | */ |
| 3612 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3613 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3614 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3615 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3619 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3620 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3621 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3622 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3623 | final long identity = Binder.clearCallingIdentity(); |
| 3624 | try { |
| 3625 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3626 | if (phone != null) { |
| 3627 | return phone.getIccCard().hasIccCard(); |
| 3628 | } else { |
| 3629 | return false; |
| 3630 | } |
| 3631 | } finally { |
| 3632 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3633 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3634 | } |
| 3635 | |
| 3636 | /** |
| 3637 | * Return if the current radio is LTE on CDMA. This |
| 3638 | * is a tri-state return value as for a period of time |
| 3639 | * the mode may be unknown. |
| 3640 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3641 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3642 | * @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] | 3643 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3644 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3645 | @Override |
| 3646 | public int getLteOnCdmaMode(String callingPackage) { |
| 3647 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3648 | } |
| 3649 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3650 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3651 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3652 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3653 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3654 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3655 | } |
| 3656 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3657 | final long identity = Binder.clearCallingIdentity(); |
| 3658 | try { |
| 3659 | final Phone phone = getPhone(subId); |
| 3660 | if (phone == null) { |
| 3661 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3662 | } else { |
| 3663 | return phone.getLteOnCdmaMode(); |
| 3664 | } |
| 3665 | } finally { |
| 3666 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3667 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3668 | } |
| 3669 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3670 | /** |
| 3671 | * {@hide} |
| 3672 | * Returns Default subId, 0 in the case of single standby. |
| 3673 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3674 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3675 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3676 | } |
| 3677 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3678 | private int getSlotForDefaultSubscription() { |
| 3679 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3680 | } |
| 3681 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3682 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3683 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3684 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3685 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3686 | private boolean isActiveSubscription(int subId) { |
| 3687 | return mSubscriptionController.isActiveSubId(subId); |
| 3688 | } |
| 3689 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3690 | /** |
| 3691 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3692 | */ |
| 3693 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3694 | final long identity = Binder.clearCallingIdentity(); |
| 3695 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3696 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3697 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3698 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3699 | } finally { |
| 3700 | Binder.restoreCallingIdentity(identity); |
| 3701 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | /** |
| 3705 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3706 | */ |
| 3707 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3708 | final long identity = Binder.clearCallingIdentity(); |
| 3709 | try { |
| 3710 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3711 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3712 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3713 | } finally { |
| 3714 | Binder.restoreCallingIdentity(identity); |
| 3715 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3716 | } |
| 3717 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3718 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3719 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3720 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3721 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3722 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3723 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3724 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3725 | if (phoneId == -1) { |
| 3726 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3727 | + " does not correspond to an active phone"); |
| 3728 | } |
| 3729 | return PhoneFactory.getPhone(phoneId); |
| 3730 | } |
| 3731 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3732 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3733 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3734 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3735 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3736 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3737 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3738 | if (DBG) { |
| 3739 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3740 | } |
| 3741 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3742 | p2); |
| 3743 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3744 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3745 | |
| 3746 | @Override |
| 3747 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3748 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3749 | enforceModifyPermission(); |
| 3750 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3751 | if (DBG) { |
| 3752 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3753 | } |
| 3754 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3755 | callingPackage, aid, p2); |
| 3756 | } |
| 3757 | |
| 3758 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3759 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3760 | final long identity = Binder.clearCallingIdentity(); |
| 3761 | try { |
| 3762 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3763 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3764 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3765 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3766 | if (bestComponent == null |
| 3767 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3768 | loge("The calling package is not allowed to access ISD-R."); |
| 3769 | throw new SecurityException( |
| 3770 | "The calling package is not allowed to access ISD-R."); |
| 3771 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3772 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3773 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3774 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3775 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3776 | null /* workSource */); |
| 3777 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3778 | return response; |
| 3779 | } finally { |
| 3780 | Binder.restoreCallingIdentity(identity); |
| 3781 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3785 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3786 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3787 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3788 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3789 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3790 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3791 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3792 | @Override |
| 3793 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3794 | enforceModifyPermission(); |
| 3795 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3796 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3797 | channel); |
| 3798 | } |
| 3799 | |
| 3800 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3801 | final long identity = Binder.clearCallingIdentity(); |
| 3802 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3803 | if (channel < 0) { |
| 3804 | return false; |
| 3805 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3806 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3807 | null /* workSource */); |
| 3808 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3809 | return success; |
| 3810 | } finally { |
| 3811 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3812 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3813 | } |
| 3814 | |
| 3815 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3816 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3817 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3818 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3819 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3820 | if (DBG) { |
| 3821 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3822 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3823 | + p3 + " data=" + data); |
| 3824 | } |
| 3825 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3826 | command, p1, p2, p3, data); |
| 3827 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3828 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3829 | @Override |
| 3830 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3831 | int command, int p1, int p2, int p3, String data) { |
| 3832 | enforceModifyPermission(); |
| 3833 | if (DBG) { |
| 3834 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3835 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3836 | + p3 + " data=" + data); |
| 3837 | } |
| 3838 | return iccTransmitApduLogicalChannelWithPermission( |
| 3839 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3840 | data); |
| 3841 | } |
| 3842 | |
| 3843 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3844 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3845 | final long identity = Binder.clearCallingIdentity(); |
| 3846 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 3847 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3848 | return ""; |
| 3849 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3850 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3851 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3852 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3853 | null /* workSource */); |
| 3854 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3855 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3856 | // Append the returned status code to the end of the response payload. |
| 3857 | String s = Integer.toHexString( |
| 3858 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3859 | if (response.payload != null) { |
| 3860 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3861 | } |
| 3862 | return s; |
| 3863 | } finally { |
| 3864 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3865 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3866 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3867 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3868 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3869 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3870 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3871 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3872 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3873 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3874 | if (DBG) { |
| 3875 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3876 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3877 | } |
| 3878 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3879 | cla, command, p1, p2, p3, data); |
| 3880 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3881 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3882 | @Override |
| 3883 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3884 | int command, int p1, int p2, int p3, String data) { |
| 3885 | enforceModifyPermission(); |
| 3886 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3887 | if (DBG) { |
| 3888 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3889 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3890 | + " data=" + data); |
| 3891 | } |
| 3892 | |
| 3893 | return iccTransmitApduBasicChannelWithPermission( |
| 3894 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3895 | p2, p3, data); |
| 3896 | } |
| 3897 | |
| 3898 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3899 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3900 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3901 | final long identity = Binder.clearCallingIdentity(); |
| 3902 | try { |
| 3903 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3904 | && TextUtils.equals(ISDR_AID, data)) { |
| 3905 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3906 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3907 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3908 | if (bestComponent == null |
| 3909 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3910 | loge("The calling package is not allowed to select ISD-R."); |
| 3911 | throw new SecurityException( |
| 3912 | "The calling package is not allowed to select ISD-R."); |
| 3913 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3914 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3915 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3916 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3917 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 3918 | null /* workSource */); |
| 3919 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3920 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3921 | // Append the returned status code to the end of the response payload. |
| 3922 | String s = Integer.toHexString( |
| 3923 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3924 | if (response.payload != null) { |
| 3925 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3926 | } |
| 3927 | return s; |
| 3928 | } finally { |
| 3929 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3930 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3931 | } |
| 3932 | |
| 3933 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3934 | 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] | 3935 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3936 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3937 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3938 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3939 | final long identity = Binder.clearCallingIdentity(); |
| 3940 | try { |
| 3941 | if (DBG) { |
| 3942 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3943 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3944 | } |
| 3945 | |
| 3946 | IccIoResult response = |
| 3947 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3948 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3949 | subId); |
| 3950 | |
| 3951 | if (DBG) { |
| 3952 | log("Exchange SIM_IO [R]" + response); |
| 3953 | } |
| 3954 | |
| 3955 | byte[] result = null; |
| 3956 | int length = 2; |
| 3957 | if (response.payload != null) { |
| 3958 | length = 2 + response.payload.length; |
| 3959 | result = new byte[length]; |
| 3960 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3961 | } else { |
| 3962 | result = new byte[length]; |
| 3963 | } |
| 3964 | |
| 3965 | result[length - 1] = (byte) response.sw2; |
| 3966 | result[length - 2] = (byte) response.sw1; |
| 3967 | return result; |
| 3968 | } finally { |
| 3969 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3970 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3971 | } |
| 3972 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3973 | /** |
| 3974 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3975 | * on a particular subscription |
| 3976 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3977 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3978 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3979 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3980 | return null; |
| 3981 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3982 | |
| 3983 | final long identity = Binder.clearCallingIdentity(); |
| 3984 | try { |
| 3985 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3986 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3987 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3988 | return null; |
| 3989 | } |
| 3990 | Object response = sendRequest( |
| 3991 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3992 | if (response instanceof String[]) { |
| 3993 | return (String[]) response; |
| 3994 | } |
| 3995 | // Response is an Exception of some kind, |
| 3996 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3997 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3998 | } finally { |
| 3999 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4000 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4001 | } |
| 4002 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4003 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4004 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4005 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4006 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4007 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4008 | final long identity = Binder.clearCallingIdentity(); |
| 4009 | try { |
| 4010 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4011 | if (response.payload == null) { |
| 4012 | return ""; |
| 4013 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4014 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4015 | // Append the returned status code to the end of the response payload. |
| 4016 | String s = Integer.toHexString( |
| 4017 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4018 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4019 | return s; |
| 4020 | } finally { |
| 4021 | Binder.restoreCallingIdentity(identity); |
| 4022 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4023 | } |
| 4024 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4025 | /** |
| 4026 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4027 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4028 | * |
| 4029 | * @param itemID the ID of the item to read |
| 4030 | * @return the NV item as a String, or null on error. |
| 4031 | */ |
| 4032 | @Override |
| 4033 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4034 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4035 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4036 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4037 | |
| 4038 | final long identity = Binder.clearCallingIdentity(); |
| 4039 | try { |
| 4040 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4041 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4042 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4043 | return value; |
| 4044 | } finally { |
| 4045 | Binder.restoreCallingIdentity(identity); |
| 4046 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4047 | } |
| 4048 | |
| 4049 | /** |
| 4050 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4051 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4052 | * |
| 4053 | * @param itemID the ID of the item to read |
| 4054 | * @param itemValue the value to write, as a String |
| 4055 | * @return true on success; false on any failure |
| 4056 | */ |
| 4057 | @Override |
| 4058 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4059 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4060 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4061 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4062 | |
| 4063 | final long identity = Binder.clearCallingIdentity(); |
| 4064 | try { |
| 4065 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4066 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4067 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4068 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4069 | return success; |
| 4070 | } finally { |
| 4071 | Binder.restoreCallingIdentity(identity); |
| 4072 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4073 | } |
| 4074 | |
| 4075 | /** |
| 4076 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4077 | * Used for device configuration by some CDMA operators. |
| 4078 | * |
| 4079 | * @param preferredRoamingList byte array containing the new PRL |
| 4080 | * @return true on success; false on any failure |
| 4081 | */ |
| 4082 | @Override |
| 4083 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4084 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4085 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4086 | |
| 4087 | final long identity = Binder.clearCallingIdentity(); |
| 4088 | try { |
| 4089 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4090 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4091 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4092 | return success; |
| 4093 | } finally { |
| 4094 | Binder.restoreCallingIdentity(identity); |
| 4095 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4099 | * 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] | 4100 | * Used for device configuration by some CDMA operators. |
| 4101 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4102 | * @param slotIndex - device slot. |
| 4103 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4104 | * @return true on success; false on any failure |
| 4105 | */ |
| 4106 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4107 | public boolean resetModemConfig(int slotIndex) { |
| 4108 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4109 | if (phone != null) { |
| 4110 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4111 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4112 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4113 | final long identity = Binder.clearCallingIdentity(); |
| 4114 | try { |
| 4115 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4116 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4117 | return success; |
| 4118 | } finally { |
| 4119 | Binder.restoreCallingIdentity(identity); |
| 4120 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4121 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4122 | return false; |
| 4123 | } |
| 4124 | |
| 4125 | /** |
| 4126 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4127 | * |
| 4128 | * @param slotIndex - device slot. |
| 4129 | * |
| 4130 | * @return true on success; false on any failure |
| 4131 | */ |
| 4132 | @Override |
| 4133 | public boolean rebootModem(int slotIndex) { |
| 4134 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4135 | if (phone != null) { |
| 4136 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4137 | mApp, phone.getSubId(), "rebootModem"); |
| 4138 | |
| 4139 | final long identity = Binder.clearCallingIdentity(); |
| 4140 | try { |
| 4141 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4142 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4143 | return success; |
| 4144 | } finally { |
| 4145 | Binder.restoreCallingIdentity(identity); |
| 4146 | } |
| 4147 | } |
| 4148 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4149 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4150 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4151 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4152 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4153 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4154 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4155 | return new String[0]; |
| 4156 | } |
| 4157 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4158 | final long identity = Binder.clearCallingIdentity(); |
| 4159 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4160 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4161 | } finally { |
| 4162 | Binder.restoreCallingIdentity(identity); |
| 4163 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4164 | } |
| 4165 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4166 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4167 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4168 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4169 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4170 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4171 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4172 | |
| 4173 | final long identity = Binder.clearCallingIdentity(); |
| 4174 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4175 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4176 | if (resolver == null) { |
| 4177 | // may happen if the device does not support IMS. |
| 4178 | return; |
| 4179 | } |
| 4180 | resolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4181 | } finally { |
| 4182 | Binder.restoreCallingIdentity(identity); |
| 4183 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4187 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4188 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4189 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4190 | public void disableIms(int slotId) { |
| 4191 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4192 | |
| 4193 | final long identity = Binder.clearCallingIdentity(); |
| 4194 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4195 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4196 | if (resolver == null) { |
| 4197 | // may happen if the device does not support IMS. |
| 4198 | return; |
| 4199 | } |
| 4200 | resolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4201 | } finally { |
| 4202 | Binder.restoreCallingIdentity(identity); |
| 4203 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4204 | } |
| 4205 | |
| 4206 | /** |
| 4207 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4208 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4209 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4210 | */ |
| 4211 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4212 | IImsServiceFeatureCallback callback) { |
| 4213 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4214 | |
| 4215 | final long identity = Binder.clearCallingIdentity(); |
| 4216 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4217 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4218 | if (resolver == null) { |
| 4219 | // may happen if the device does not support IMS. |
| 4220 | return null; |
| 4221 | } |
| 4222 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4223 | } finally { |
| 4224 | Binder.restoreCallingIdentity(identity); |
| 4225 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | /** |
| 4229 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4230 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4231 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4232 | * listener for feature updates. |
| 4233 | */ |
| 4234 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4235 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4236 | |
| 4237 | final long identity = Binder.clearCallingIdentity(); |
| 4238 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4239 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4240 | if (resolver == null) { |
| 4241 | // may happen if the device does not support IMS. |
| 4242 | return null; |
| 4243 | } |
| 4244 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4245 | } finally { |
| 4246 | Binder.restoreCallingIdentity(identity); |
| 4247 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4248 | } |
| 4249 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4250 | /** |
| 4251 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4252 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4253 | */ |
| 4254 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4255 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4256 | |
| 4257 | final long identity = Binder.clearCallingIdentity(); |
| 4258 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4259 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4260 | if (resolver == null) { |
| 4261 | // may happen if the device does not support IMS. |
| 4262 | return null; |
| 4263 | } |
| 4264 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4265 | } finally { |
| 4266 | Binder.restoreCallingIdentity(identity); |
| 4267 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4268 | } |
| 4269 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4270 | /** |
| 4271 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4272 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4273 | */ |
| 4274 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4275 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4276 | |
| 4277 | final long identity = Binder.clearCallingIdentity(); |
| 4278 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4279 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4280 | if (resolver == null) { |
| 4281 | // may happen if the device does not support IMS. |
| 4282 | return null; |
| 4283 | } |
| 4284 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4285 | } finally { |
| 4286 | Binder.restoreCallingIdentity(identity); |
| 4287 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4288 | } |
| 4289 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4290 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4291 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4292 | * |
| 4293 | * @param slotId the slot ID that the ImsService should bind for. |
| 4294 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4295 | * ImsService is the device default ImsService. |
| 4296 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4297 | * to. |
| 4298 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4299 | * @hide |
| 4300 | */ |
| 4301 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4302 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4303 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4304 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4305 | "setImsService"); |
| 4306 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4307 | final long identity = Binder.clearCallingIdentity(); |
| 4308 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4309 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4310 | if (resolver == null) { |
| 4311 | // may happen if the device does not support IMS. |
| 4312 | return false; |
| 4313 | } |
| 4314 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4315 | packageName); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4316 | } finally { |
| 4317 | Binder.restoreCallingIdentity(identity); |
| 4318 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | /** |
| 4322 | * Return the ImsService configuration. |
| 4323 | * |
| 4324 | * @param slotId The slot that the ImsService is associated with. |
| 4325 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4326 | * the device default. |
| 4327 | * @return the package name of the ImsService configuration. |
| 4328 | */ |
| 4329 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4330 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4331 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4332 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4333 | "getImsService"); |
| 4334 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4335 | final long identity = Binder.clearCallingIdentity(); |
| 4336 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4337 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4338 | if (resolver == null) { |
| 4339 | // may happen if the device does not support IMS. |
| 4340 | return ""; |
| 4341 | } |
| 4342 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4343 | } finally { |
| 4344 | Binder.restoreCallingIdentity(identity); |
| 4345 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4346 | } |
| 4347 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4348 | public void setImsRegistrationState(boolean registered) { |
| 4349 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4350 | |
| 4351 | final long identity = Binder.clearCallingIdentity(); |
| 4352 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4353 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4354 | } finally { |
| 4355 | Binder.restoreCallingIdentity(identity); |
| 4356 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4360 | * Set the network selection mode to automatic. |
| 4361 | * |
| 4362 | */ |
| 4363 | @Override |
| 4364 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4365 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4366 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4367 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4368 | if (!isActiveSubscription(subId)) { |
| 4369 | return; |
| 4370 | } |
| 4371 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4372 | final long identity = Binder.clearCallingIdentity(); |
| 4373 | try { |
| 4374 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4375 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4376 | } finally { |
| 4377 | Binder.restoreCallingIdentity(identity); |
| 4378 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4379 | } |
| 4380 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4381 | /** |
| 4382 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4383 | * |
| 4384 | * @param subId the id of the subscription. |
| 4385 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4386 | * the operator to attach to. |
| 4387 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4388 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4389 | * normal network selection next time. |
| 4390 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4391 | */ |
| 4392 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4393 | public boolean setNetworkSelectionModeManual( |
| 4394 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4395 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4396 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4397 | |
| 4398 | if (!isActiveSubscription(subId)) { |
| 4399 | return false; |
| 4400 | } |
| 4401 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4402 | final long identity = Binder.clearCallingIdentity(); |
| 4403 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4404 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4405 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4406 | if (DBG) { |
| 4407 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4408 | + " operator: " + operatorInfo); |
| 4409 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4410 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4411 | } finally { |
| 4412 | Binder.restoreCallingIdentity(identity); |
| 4413 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4414 | } |
| 4415 | |
| 4416 | /** |
| 4417 | * Scans for available networks. |
| 4418 | */ |
| 4419 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4420 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4421 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4422 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4423 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4424 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4425 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4426 | .setCallingPackage(callingPackage) |
| 4427 | .setCallingPid(Binder.getCallingPid()) |
| 4428 | .setCallingUid(Binder.getCallingUid()) |
| 4429 | .setMethod("getCellNetworkScanResults") |
| 4430 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4431 | .build()); |
| 4432 | switch (locationResult) { |
| 4433 | case DENIED_HARD: |
| 4434 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4435 | case DENIED_SOFT: |
| 4436 | return null; |
| 4437 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4438 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4439 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4440 | try { |
| 4441 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4442 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4443 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4444 | } finally { |
| 4445 | Binder.restoreCallingIdentity(identity); |
| 4446 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4450 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4451 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4452 | * @param subId id of the subscription |
| 4453 | * @param request contains the radio access networks with bands/channels to scan |
| 4454 | * @param messenger callback messenger for scan results or errors |
| 4455 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4456 | * @return the id of the requested scan which can be used to stop the scan. |
| 4457 | */ |
| 4458 | @Override |
| 4459 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4460 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4461 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4462 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4463 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4464 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4465 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4466 | .setCallingPackage(callingPackage) |
| 4467 | .setCallingPid(Binder.getCallingPid()) |
| 4468 | .setCallingUid(Binder.getCallingUid()) |
| 4469 | .setMethod("requestNetworkScan") |
| 4470 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4471 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4472 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4473 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4474 | if (e != null) { |
| 4475 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4476 | throw e; |
| 4477 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4478 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4479 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4480 | } |
| 4481 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4482 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4483 | int callingUid = Binder.getCallingUid(); |
| 4484 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4485 | final long identity = Binder.clearCallingIdentity(); |
| 4486 | try { |
| 4487 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4488 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4489 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4490 | } finally { |
| 4491 | Binder.restoreCallingIdentity(identity); |
| 4492 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4493 | } |
| 4494 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4495 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4496 | NetworkScanRequest request, int subId) { |
| 4497 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4498 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4499 | boolean hasNetworkScanPermission = |
| 4500 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4501 | == PERMISSION_GRANTED; |
| 4502 | |
| 4503 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4504 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4505 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4506 | } |
| 4507 | |
| 4508 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4509 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4510 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4511 | return new SecurityException("Specific channels must not be" |
| 4512 | + " scanned without location access."); |
| 4513 | } |
| 4514 | } |
| 4515 | } |
| 4516 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4517 | return null; |
| 4518 | } |
| 4519 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4520 | /** |
| 4521 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4522 | * |
| 4523 | * @param subId id of the subscription |
| 4524 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4525 | */ |
| 4526 | @Override |
| 4527 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4528 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4529 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4530 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4531 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4532 | final long identity = Binder.clearCallingIdentity(); |
| 4533 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4534 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4535 | } finally { |
| 4536 | Binder.restoreCallingIdentity(identity); |
| 4537 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4541 | * Get the calculated preferred network type. |
| 4542 | * Used for debugging incorrect network type. |
| 4543 | * |
| 4544 | * @return the preferred network type, defined in RILConstants.java. |
| 4545 | */ |
| 4546 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4547 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4548 | final Phone defaultPhone = getDefaultPhone(); |
| 4549 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4550 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4551 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4552 | } |
| 4553 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4554 | final long identity = Binder.clearCallingIdentity(); |
| 4555 | try { |
| 4556 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4557 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4558 | } finally { |
| 4559 | Binder.restoreCallingIdentity(identity); |
| 4560 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4561 | } |
| 4562 | |
| 4563 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4564 | * Get the preferred network type. |
| 4565 | * Used for device configuration by some CDMA operators. |
| 4566 | * |
| 4567 | * @return the preferred network type, defined in RILConstants.java. |
| 4568 | */ |
| 4569 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4570 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4571 | TelephonyPermissions |
| 4572 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4573 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4574 | |
| 4575 | final long identity = Binder.clearCallingIdentity(); |
| 4576 | try { |
| 4577 | if (DBG) log("getPreferredNetworkType"); |
| 4578 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4579 | int networkType = (result != null ? result[0] : -1); |
| 4580 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4581 | return networkType; |
| 4582 | } finally { |
| 4583 | Binder.restoreCallingIdentity(identity); |
| 4584 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | /** |
| 4588 | * Set the preferred network type. |
| 4589 | * Used for device configuration by some CDMA operators. |
| 4590 | * |
| 4591 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4592 | * @return true on success; false on any failure. |
| 4593 | */ |
| 4594 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4595 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4596 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4597 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4598 | |
| 4599 | final long identity = Binder.clearCallingIdentity(); |
| 4600 | try { |
| 4601 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4602 | Boolean success = (Boolean) sendRequest( |
| 4603 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4604 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4605 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4606 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4607 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4608 | } |
| 4609 | return success; |
| 4610 | } finally { |
| 4611 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4612 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4613 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4614 | |
| 4615 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4616 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4617 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4618 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4619 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4620 | * @hide |
| 4621 | */ |
| 4622 | @Override |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4623 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4624 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4625 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4626 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4627 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4628 | if (phone != null) { |
| 4629 | return phone.hasMatchedTetherApnSetting(); |
| 4630 | } else { |
| 4631 | return false; |
| 4632 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4633 | } finally { |
| 4634 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4635 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4636 | } |
| 4637 | |
| 4638 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4639 | * Set mobile data enabled |
| 4640 | * Used by the user through settings etc to turn on/off mobile data |
| 4641 | * |
| 4642 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4643 | */ |
| 4644 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4645 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4646 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4647 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4648 | |
| 4649 | final long identity = Binder.clearCallingIdentity(); |
| 4650 | try { |
| 4651 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4652 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4653 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4654 | if (phone != null) { |
| 4655 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4656 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4657 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4658 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4659 | } |
| 4660 | } finally { |
| 4661 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4662 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4666 | * Get the user enabled state of Mobile Data. |
| 4667 | * |
| 4668 | * TODO: remove and use isUserDataEnabled. |
| 4669 | * This can't be removed now because some vendor codes |
| 4670 | * calls through ITelephony directly while they should |
| 4671 | * use TelephonyManager. |
| 4672 | * |
| 4673 | * @return true on enabled |
| 4674 | */ |
| 4675 | @Override |
| 4676 | public boolean getDataEnabled(int subId) { |
| 4677 | return isUserDataEnabled(subId); |
| 4678 | } |
| 4679 | |
| 4680 | /** |
| 4681 | * Get whether mobile data is enabled per user setting. |
| 4682 | * |
| 4683 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4684 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4685 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4686 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4687 | * |
| 4688 | * @return {@code true} if data is enabled else {@code false} |
| 4689 | */ |
| 4690 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4691 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4692 | try { |
| 4693 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4694 | null); |
| 4695 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4696 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4697 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4698 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4699 | |
| 4700 | final long identity = Binder.clearCallingIdentity(); |
| 4701 | try { |
| 4702 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4703 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4704 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4705 | if (phone != null) { |
| 4706 | boolean retVal = phone.isUserDataEnabled(); |
| 4707 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4708 | return retVal; |
| 4709 | } else { |
| 4710 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4711 | return false; |
| 4712 | } |
| 4713 | } finally { |
| 4714 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4715 | } |
| 4716 | } |
| 4717 | |
| 4718 | /** |
| 4719 | * Get whether mobile data is enabled. |
| 4720 | * |
| 4721 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4722 | * whether mobile data is actually enabled. |
| 4723 | * |
| 4724 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4725 | * |
| 4726 | * @return {@code true} if data is enabled else {@code false} |
| 4727 | */ |
| 4728 | @Override |
| 4729 | public boolean isDataEnabled(int subId) { |
| 4730 | try { |
| 4731 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4732 | null); |
| 4733 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4734 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4735 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4736 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4737 | |
| 4738 | final long identity = Binder.clearCallingIdentity(); |
| 4739 | try { |
| 4740 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4741 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4742 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4743 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4744 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4745 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4746 | return retVal; |
| 4747 | } else { |
| 4748 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4749 | return false; |
| 4750 | } |
| 4751 | } finally { |
| 4752 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4753 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4754 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4755 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4756 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 4757 | Phone phone) { |
| 4758 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 4759 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 4760 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 4761 | || subController == null) return privilegeFromSim; |
| 4762 | |
| 4763 | int uid = Binder.getCallingUid(); |
| 4764 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 4765 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 4766 | |
| 4767 | final long identity = Binder.clearCallingIdentity(); |
| 4768 | try { |
| 4769 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 4770 | SubscriptionManager subManager = (SubscriptionManager) |
| 4771 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 4772 | for (String pkg : packages) { |
| 4773 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 4774 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4775 | } |
| 4776 | } |
| 4777 | return privilegeFromSim; |
| 4778 | } finally { |
| 4779 | Binder.restoreCallingIdentity(identity); |
| 4780 | } |
| 4781 | } |
| 4782 | |
| 4783 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 4784 | String pkgName) { |
| 4785 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 4786 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 4787 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 4788 | || subController == null) return privilegeFromSim; |
| 4789 | |
| 4790 | final long identity = Binder.clearCallingIdentity(); |
| 4791 | try { |
| 4792 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 4793 | SubscriptionManager subManager = (SubscriptionManager) |
| 4794 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 4795 | return subManager.canManageSubscription(subInfo, pkgName) |
| 4796 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 4797 | } finally { |
| 4798 | Binder.restoreCallingIdentity(identity); |
| 4799 | } |
| 4800 | } |
| 4801 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4802 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4803 | public int getCarrierPrivilegeStatus(int subId) { |
| 4804 | final Phone phone = getPhone(subId); |
| 4805 | if (phone == null) { |
| 4806 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4807 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4808 | } |
| 4809 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4810 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4811 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4812 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4813 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4814 | |
| 4815 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4816 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 4817 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4818 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4819 | |
| 4820 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4821 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4822 | final Phone phone = getPhone(subId); |
| 4823 | if (phone == null) { |
| 4824 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4825 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4826 | } |
| 4827 | UiccProfile profile = |
| 4828 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4829 | if (profile == null) { |
| 4830 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4831 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4832 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4833 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4834 | profile.getCarrierPrivilegeStatusForUid( |
| 4835 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4836 | } |
| 4837 | |
| 4838 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4839 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 4840 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4841 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4842 | } |
| 4843 | |
| 4844 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 4845 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4846 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4847 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4848 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4849 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4850 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4851 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 4852 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4853 | } |
| 4854 | |
| 4855 | @Override |
| 4856 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4857 | if (TextUtils.isEmpty(pkgName)) |
| 4858 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4859 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4860 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4861 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4862 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4863 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4864 | continue; |
| 4865 | } |
| 4866 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4867 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4868 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 4869 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4870 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4871 | break; |
| 4872 | } |
| 4873 | } |
| 4874 | |
| 4875 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4876 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4877 | |
| 4878 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4879 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4880 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4881 | loge("phoneId " + phoneId + " is not valid."); |
| 4882 | return null; |
| 4883 | } |
| 4884 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4885 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4886 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4887 | return null ; |
| 4888 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4889 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4890 | } |
| 4891 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4892 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4893 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4894 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4895 | List<String> privilegedPackages = new ArrayList<>(); |
| 4896 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4897 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 4898 | // has UICC in that slot. |
| 4899 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4900 | if (card.hasCarrierPrivilegeRules()) { |
| 4901 | if (packages == null) { |
| 4902 | // Only check packages in user 0 for now |
| 4903 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4904 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4905 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4906 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4907 | } |
| 4908 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4909 | PackageInfo pkgInfo = packages.get(p); |
| 4910 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4911 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4912 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4913 | privilegedPackages.add(pkgInfo.packageName); |
| 4914 | } |
| 4915 | } |
| 4916 | } |
| 4917 | } |
| 4918 | return privilegedPackages; |
| 4919 | } |
| 4920 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4921 | @Override |
| 4922 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
| 4923 | List<String> privilegedPackages = new ArrayList<>(); |
| 4924 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4925 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 4926 | } |
| 4927 | return privilegedPackages; |
| 4928 | } |
| 4929 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4930 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4931 | final Phone phone = getPhone(subId); |
| 4932 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4933 | if (card == null) { |
| 4934 | loge("getIccId: No UICC"); |
| 4935 | return null; |
| 4936 | } |
| 4937 | String iccId = card.getIccId(); |
| 4938 | if (TextUtils.isEmpty(iccId)) { |
| 4939 | loge("getIccId: ICC ID is null or empty."); |
| 4940 | return null; |
| 4941 | } |
| 4942 | return iccId; |
| 4943 | } |
| 4944 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4945 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4946 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4947 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4948 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4949 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4950 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4951 | final long identity = Binder.clearCallingIdentity(); |
| 4952 | try { |
| 4953 | final String iccId = getIccId(subId); |
| 4954 | final Phone phone = getPhone(subId); |
| 4955 | if (phone == null) { |
| 4956 | return false; |
| 4957 | } |
| 4958 | final String subscriberId = phone.getSubscriberId(); |
| 4959 | |
| 4960 | if (DBG_MERGE) { |
| 4961 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4962 | + subscriberId + " to " + number); |
| 4963 | } |
| 4964 | |
| 4965 | if (TextUtils.isEmpty(iccId)) { |
| 4966 | return false; |
| 4967 | } |
| 4968 | |
| 4969 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4970 | |
| 4971 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4972 | if (alphaTag == null) { |
| 4973 | editor.remove(alphaTagPrefKey); |
| 4974 | } else { |
| 4975 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4976 | } |
| 4977 | |
| 4978 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4979 | // track all merged IMSIs based on line number |
| 4980 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4981 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4982 | if (number == null) { |
| 4983 | editor.remove(numberPrefKey); |
| 4984 | editor.remove(subscriberPrefKey); |
| 4985 | } else { |
| 4986 | editor.putString(numberPrefKey, number); |
| 4987 | editor.putString(subscriberPrefKey, subscriberId); |
| 4988 | } |
| 4989 | |
| 4990 | editor.commit(); |
| 4991 | return true; |
| 4992 | } finally { |
| 4993 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4994 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4995 | } |
| 4996 | |
| 4997 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4998 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4999 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5000 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5001 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5002 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5003 | return null; |
| 5004 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5005 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5006 | final long identity = Binder.clearCallingIdentity(); |
| 5007 | try { |
| 5008 | String iccId = getIccId(subId); |
| 5009 | if (iccId != null) { |
| 5010 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5011 | if (DBG_MERGE) { |
| 5012 | log("getLine1NumberForDisplay returning " |
| 5013 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5014 | } |
| 5015 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5016 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5017 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5018 | return null; |
| 5019 | } finally { |
| 5020 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5021 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5022 | } |
| 5023 | |
| 5024 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5025 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5026 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5027 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5028 | return null; |
| 5029 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5030 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5031 | final long identity = Binder.clearCallingIdentity(); |
| 5032 | try { |
| 5033 | String iccId = getIccId(subId); |
| 5034 | if (iccId != null) { |
| 5035 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5036 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5037 | } |
| 5038 | return null; |
| 5039 | } finally { |
| 5040 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5041 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5042 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5043 | |
| 5044 | @Override |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5045 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5046 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5047 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5048 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5049 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 5050 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5051 | return null; |
| 5052 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5053 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5054 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5055 | // the process, where TelephonyManager was instantiated. |
| 5056 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5057 | final long identity = Binder.clearCallingIdentity(); |
| 5058 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5059 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5060 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5061 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5062 | |
| 5063 | // Figure out what subscribers are currently active |
| 5064 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5065 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5066 | // Only consider subs which match the current subId |
| 5067 | // This logic can be simplified. See b/131189269 for progress. |
| 5068 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5069 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5070 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5071 | |
| 5072 | // First pass, find a number override for an active subscriber |
| 5073 | String mergeNumber = null; |
| 5074 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5075 | for (String key : prefs.keySet()) { |
| 5076 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5077 | final String subscriberId = (String) prefs.get(key); |
| 5078 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5079 | final String iccId = key.substring( |
| 5080 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5081 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5082 | mergeNumber = (String) prefs.get(numberKey); |
| 5083 | if (DBG_MERGE) { |
| 5084 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5085 | + " for active subscriber " + subscriberId); |
| 5086 | } |
| 5087 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5088 | break; |
| 5089 | } |
| 5090 | } |
| 5091 | } |
| 5092 | } |
| 5093 | |
| 5094 | // Shortcut when no active merged subscribers |
| 5095 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5096 | return null; |
| 5097 | } |
| 5098 | |
| 5099 | // Second pass, find all subscribers under that line override |
| 5100 | final ArraySet<String> result = new ArraySet<>(); |
| 5101 | for (String key : prefs.keySet()) { |
| 5102 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5103 | final String number = (String) prefs.get(key); |
| 5104 | if (mergeNumber.equals(number)) { |
| 5105 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5106 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5107 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5108 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5109 | result.add(subscriberId); |
| 5110 | } |
| 5111 | } |
| 5112 | } |
| 5113 | } |
| 5114 | |
| 5115 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5116 | Arrays.sort(resultArray); |
| 5117 | if (DBG_MERGE) { |
| 5118 | Slog.d(LOG_TAG, |
| 5119 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5120 | } |
| 5121 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5122 | } finally { |
| 5123 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5124 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5125 | } |
| 5126 | |
| 5127 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5128 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 5129 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 5130 | |
| 5131 | final long identity = Binder.clearCallingIdentity(); |
| 5132 | try { |
| 5133 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5134 | TelephonyManager.class); |
| 5135 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5136 | if (subscriberId == null) { |
| 5137 | if (DBG) { |
| 5138 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 5139 | + subId); |
| 5140 | } |
| 5141 | return null; |
| 5142 | } |
| 5143 | |
| 5144 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5145 | .getSubscriptionInfo(subId); |
| 5146 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5147 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5148 | if (groupUuid == null) { |
| 5149 | return new String[]{subscriberId}; |
| 5150 | } |
| 5151 | |
| 5152 | // Get all subscriberIds from the group. |
| 5153 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5154 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
| 5155 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName()); |
| 5156 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5157 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5158 | if (subscriberId != null) { |
| 5159 | mergedSubscriberIds.add(subscriberId); |
| 5160 | } |
| 5161 | } |
| 5162 | |
| 5163 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5164 | } finally { |
| 5165 | Binder.restoreCallingIdentity(identity); |
| 5166 | |
| 5167 | } |
| 5168 | } |
| 5169 | |
| 5170 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5171 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5172 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5173 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5174 | |
| 5175 | final long identity = Binder.clearCallingIdentity(); |
| 5176 | try { |
| 5177 | final Phone phone = getPhone(subId); |
| 5178 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5179 | } finally { |
| 5180 | Binder.restoreCallingIdentity(identity); |
| 5181 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5182 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5183 | |
| 5184 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5185 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5186 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5187 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5188 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5189 | |
| 5190 | final long identity = Binder.clearCallingIdentity(); |
| 5191 | try { |
| 5192 | final Phone phone = getPhone(subId); |
| 5193 | if (phone == null) { |
| 5194 | return false; |
| 5195 | } |
| 5196 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5197 | cdmaNonRoamingList); |
| 5198 | } finally { |
| 5199 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5200 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5204 | @Deprecated |
| 5205 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5206 | enforceModifyPermission(); |
| 5207 | |
| 5208 | int returnValue = 0; |
| 5209 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5210 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5211 | if(result.exception == null) { |
| 5212 | if (result.result != null) { |
| 5213 | byte[] responseData = (byte[])(result.result); |
| 5214 | if(responseData.length > oemResp.length) { |
| 5215 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5216 | responseData.length + "bytes. Buffer Size is " + |
| 5217 | oemResp.length + "bytes."); |
| 5218 | } |
| 5219 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5220 | returnValue = responseData.length; |
| 5221 | } |
| 5222 | } else { |
| 5223 | CommandException ex = (CommandException) result.exception; |
| 5224 | returnValue = ex.getCommandError().ordinal(); |
| 5225 | if(returnValue > 0) returnValue *= -1; |
| 5226 | } |
| 5227 | } catch (RuntimeException e) { |
| 5228 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5229 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5230 | if(returnValue > 0) returnValue *= -1; |
| 5231 | } |
| 5232 | |
| 5233 | return returnValue; |
| 5234 | } |
| 5235 | |
| 5236 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5237 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5238 | try { |
| 5239 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5240 | } catch (RuntimeException e) { |
| 5241 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5242 | } |
| 5243 | } |
| 5244 | |
| 5245 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5246 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5247 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5248 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5249 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5250 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5251 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5252 | final long identity = Binder.clearCallingIdentity(); |
| 5253 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5254 | TelephonyPermissions |
| 5255 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5256 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5257 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5258 | } finally { |
| 5259 | Binder.restoreCallingIdentity(identity); |
| 5260 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5261 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5262 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5263 | |
| 5264 | @Override |
| 5265 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5266 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5267 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5268 | |
| 5269 | final long identity = Binder.clearCallingIdentity(); |
| 5270 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5271 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5272 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5273 | } finally { |
| 5274 | Binder.restoreCallingIdentity(identity); |
| 5275 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5276 | } |
| 5277 | |
| 5278 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5279 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5280 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5281 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5282 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5283 | return false; |
| 5284 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5285 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5286 | final long identity = Binder.clearCallingIdentity(); |
| 5287 | try { |
| 5288 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5289 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5290 | // In the long run, we may instead need to check if there exists a connection service |
| 5291 | // which can support video calling. |
| 5292 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5293 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5294 | return imsManager.isVtEnabledByPlatform() |
| 5295 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5296 | && imsManager.isVtEnabledByUser(); |
| 5297 | } finally { |
| 5298 | Binder.restoreCallingIdentity(identity); |
| 5299 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5300 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5301 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5302 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5303 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5304 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5305 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5306 | return false; |
| 5307 | } |
| 5308 | |
| 5309 | final long identity = Binder.clearCallingIdentity(); |
| 5310 | try { |
| 5311 | CarrierConfigManager configManager = |
| 5312 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5313 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5314 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5315 | } finally { |
| 5316 | Binder.restoreCallingIdentity(identity); |
| 5317 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5318 | } |
| 5319 | |
| 5320 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5321 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5322 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5323 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5324 | return false; |
| 5325 | } |
| 5326 | |
| 5327 | final long identity = Binder.clearCallingIdentity(); |
| 5328 | try { |
| 5329 | CarrierConfigManager configManager = |
| 5330 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5331 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5332 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5333 | } finally { |
| 5334 | Binder.restoreCallingIdentity(identity); |
| 5335 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5336 | } |
| 5337 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5338 | @Override |
| 5339 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5340 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5341 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | @Override |
| 5345 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5346 | final long identity = Binder.clearCallingIdentity(); |
| 5347 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5348 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5349 | } finally { |
| 5350 | Binder.restoreCallingIdentity(identity); |
| 5351 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5352 | } |
| 5353 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5354 | /** |
| 5355 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5356 | * support for the feature and device firmware support. |
| 5357 | * |
| 5358 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5359 | */ |
| 5360 | @Override |
| 5361 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5362 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5363 | final Phone phone = getPhone(subscriptionId); |
| 5364 | if (phone == null) { |
| 5365 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5366 | return false; |
| 5367 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5368 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5369 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5370 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5371 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5372 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5373 | return isCarrierSupported && isDeviceSupported; |
| 5374 | } finally { |
| 5375 | Binder.restoreCallingIdentity(identity); |
| 5376 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5377 | } |
| 5378 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5379 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5380 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 5381 | * RTT setting, will return true if the device and carrier both support RTT. |
| 5382 | * 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] | 5383 | */ |
| 5384 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5385 | final long identity = Binder.clearCallingIdentity(); |
| 5386 | try { |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5387 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 5388 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5389 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5390 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 5391 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 5392 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5393 | } finally { |
| 5394 | Binder.restoreCallingIdentity(identity); |
| 5395 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5396 | } |
| 5397 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5398 | /** |
| 5399 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5400 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5401 | * |
| 5402 | * <p>Requires Permission: |
| 5403 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5404 | */ |
| 5405 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5406 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5407 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5408 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5409 | return null; |
| 5410 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5411 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5412 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5413 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5414 | return null; |
| 5415 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5416 | |
| 5417 | final long identity = Binder.clearCallingIdentity(); |
| 5418 | try { |
| 5419 | return phone.getDeviceId(); |
| 5420 | } finally { |
| 5421 | Binder.restoreCallingIdentity(identity); |
| 5422 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5423 | } |
| 5424 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5425 | /** |
| 5426 | * {@hide} |
| 5427 | * Returns the IMS Registration Status on a particular subid |
| 5428 | * |
| 5429 | * @param subId |
| 5430 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5431 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5432 | Phone phone = getPhone(subId); |
| 5433 | if (phone != null) { |
| 5434 | return phone.isImsRegistered(); |
| 5435 | } else { |
| 5436 | return false; |
| 5437 | } |
| 5438 | } |
| 5439 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5440 | @Override |
| 5441 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5442 | final long identity = Binder.clearCallingIdentity(); |
| 5443 | try { |
| 5444 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5445 | } finally { |
| 5446 | Binder.restoreCallingIdentity(identity); |
| 5447 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5448 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5449 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5450 | @Override |
| 5451 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5452 | final long identity = Binder.clearCallingIdentity(); |
| 5453 | try { |
| 5454 | Phone phone = getPhone(subscriptionId); |
| 5455 | if (phone == null) { |
| 5456 | return null; |
| 5457 | } |
| 5458 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5459 | } finally { |
| 5460 | Binder.restoreCallingIdentity(identity); |
| 5461 | } |
| 5462 | } |
| 5463 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5464 | /** |
| 5465 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5466 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5467 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5468 | final long identity = Binder.clearCallingIdentity(); |
| 5469 | try { |
| 5470 | Phone phone = getPhone(subId); |
| 5471 | if (phone != null) { |
| 5472 | return phone.isWifiCallingEnabled(); |
| 5473 | } else { |
| 5474 | return false; |
| 5475 | } |
| 5476 | } finally { |
| 5477 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5478 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5479 | } |
| 5480 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5481 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5482 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5483 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5484 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5485 | final long identity = Binder.clearCallingIdentity(); |
| 5486 | try { |
| 5487 | Phone phone = getPhone(subId); |
| 5488 | if (phone != null) { |
| 5489 | return phone.isVideoEnabled(); |
| 5490 | } else { |
| 5491 | return false; |
| 5492 | } |
| 5493 | } finally { |
| 5494 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5495 | } |
| 5496 | } |
| 5497 | |
| 5498 | /** |
| 5499 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5500 | * defined in {@link ImsRegistrationImplBase}. |
| 5501 | */ |
| 5502 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(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.getImsRegistrationTech(); |
| 5508 | } else { |
| 5509 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5510 | } |
| 5511 | } finally { |
| 5512 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5513 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5514 | } |
| 5515 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5516 | @Override |
| 5517 | public void factoryReset(int subId) { |
| 5518 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5519 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5520 | return; |
| 5521 | } |
| 5522 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5523 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5524 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5525 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5526 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5527 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5528 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5529 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5530 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5531 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5532 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5533 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5534 | // There has been issues when Sms raw table somehow stores orphan |
| 5535 | // fragments. They lead to garbled message when new fragments come |
| 5536 | // in and combined with those stale ones. In case this happens again, |
| 5537 | // user can reset all network settings which will clean up this table. |
| 5538 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5539 | } finally { |
| 5540 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5541 | } |
| 5542 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5543 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5544 | private void cleanUpSmsRawTable(Context context) { |
| 5545 | ContentResolver resolver = context.getContentResolver(); |
| 5546 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5547 | resolver.delete(uri, null, null); |
| 5548 | } |
| 5549 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5550 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5551 | public String getSimLocaleForSubscriber(int subId) { |
| 5552 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5553 | final Phone phone = getPhone(subId); |
| 5554 | if (phone == null) { |
| 5555 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5556 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5557 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5558 | final long identity = Binder.clearCallingIdentity(); |
| 5559 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5560 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5561 | phone.getContext().getOpPackageName()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5562 | if (info == null) { |
| 5563 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5564 | return null; |
| 5565 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5566 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5567 | // preferences (EF-PL and EF-LI)... |
| 5568 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5569 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5570 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5571 | if (localeFromDefaultSim != null) { |
| 5572 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5573 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5574 | + localeFromDefaultSim); |
| 5575 | return localeFromDefaultSim.toLanguageTag(); |
| 5576 | } else { |
| 5577 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5578 | } |
| 5579 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5580 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5581 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5582 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5583 | // the SIM and carrier preferences does not include a country we add the country |
| 5584 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5585 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5586 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5587 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5588 | return mccLocale.toLanguageTag(); |
| 5589 | } |
| 5590 | |
| 5591 | if (DBG) log("No locale found - returning null"); |
| 5592 | return null; |
| 5593 | } finally { |
| 5594 | Binder.restoreCallingIdentity(identity); |
| 5595 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5596 | } |
| 5597 | |
| 5598 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5599 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5600 | } |
| 5601 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5602 | /** |
| 5603 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5604 | */ |
| 5605 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5606 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5607 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5608 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5609 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5610 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5611 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5612 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5613 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5614 | * representing the state of the modem. |
| 5615 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5616 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5617 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5618 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5619 | */ |
| 5620 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5621 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5622 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5623 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5624 | |
| 5625 | final long identity = Binder.clearCallingIdentity(); |
| 5626 | try { |
| 5627 | ModemActivityInfo ret = null; |
| 5628 | synchronized (mLastModemActivityInfo) { |
| 5629 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5630 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5631 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5632 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5633 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5634 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5635 | mergedTxTimeMs[i] = info.getTxTimeMillis()[i] |
| 5636 | + mLastModemActivityInfo.getTxTimeMillis()[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5637 | } |
| 5638 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5639 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 5640 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5641 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5642 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5643 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5644 | mLastModemActivityInfo.setRxTimeMillis( |
| 5645 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5646 | mLastModemActivityInfo.setEnergyUsed( |
| 5647 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5648 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5649 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5650 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5651 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5652 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5653 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5654 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5655 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5656 | Bundle bundle = new Bundle(); |
| 5657 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5658 | result.send(0, bundle); |
| 5659 | } finally { |
| 5660 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5661 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5662 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5663 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5664 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5665 | // less than total activity duration. |
| 5666 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5667 | if (info == null) { |
| 5668 | return false; |
| 5669 | } |
| 5670 | int activityDurationMs = |
| 5671 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5672 | int totalTxTimeMs = 0; |
| 5673 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5674 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5675 | } |
| 5676 | return (info.isValid() |
| 5677 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5678 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5679 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5680 | && (totalTxTimeMs <= activityDurationMs)); |
| 5681 | } |
| 5682 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5683 | /** |
| 5684 | * {@hide} |
| 5685 | * Returns the service state information on specified subscription. |
| 5686 | */ |
| 5687 | @Override |
| 5688 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5689 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5690 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5691 | return null; |
| 5692 | } |
| 5693 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5694 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5695 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5696 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5697 | .setCallingPackage(callingPackage) |
| 5698 | .setCallingPid(Binder.getCallingPid()) |
| 5699 | .setCallingUid(Binder.getCallingUid()) |
| 5700 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5701 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5702 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5703 | .build()); |
| 5704 | |
| 5705 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5706 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5707 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5708 | .setCallingPackage(callingPackage) |
| 5709 | .setCallingPid(Binder.getCallingPid()) |
| 5710 | .setCallingUid(Binder.getCallingUid()) |
| 5711 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5712 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5713 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5714 | .build()); |
| 5715 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5716 | boolean hasFinePermission = |
| 5717 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5718 | boolean hasCoarsePermission = |
| 5719 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5720 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5721 | final long identity = Binder.clearCallingIdentity(); |
| 5722 | try { |
| 5723 | final Phone phone = getPhone(subId); |
| 5724 | if (phone == null) { |
| 5725 | return null; |
| 5726 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5727 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5728 | ServiceState ss = phone.getServiceState(); |
| 5729 | |
| 5730 | // Scrub out the location info in ServiceState depending on what level of access |
| 5731 | // the caller has. |
| 5732 | if (hasFinePermission) return ss; |
| 5733 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5734 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5735 | } finally { |
| 5736 | Binder.restoreCallingIdentity(identity); |
| 5737 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5738 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5739 | |
| 5740 | /** |
| 5741 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5742 | * |
| 5743 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5744 | * voicemail ringtone. |
| 5745 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5746 | * PhoneAccount. |
| 5747 | */ |
| 5748 | @Override |
| 5749 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5750 | final long identity = Binder.clearCallingIdentity(); |
| 5751 | try { |
| 5752 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5753 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5754 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5755 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5756 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5757 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5758 | } finally { |
| 5759 | Binder.restoreCallingIdentity(identity); |
| 5760 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5761 | } |
| 5762 | |
| 5763 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5764 | * Sets the per-account voicemail ringtone. |
| 5765 | * |
| 5766 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5767 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5768 | * |
| 5769 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5770 | * voicemail ringtone. |
| 5771 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5772 | * PhoneAccount. |
| 5773 | */ |
| 5774 | @Override |
| 5775 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5776 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5777 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5778 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5779 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5780 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5781 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5782 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5783 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5784 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5785 | |
| 5786 | final long identity = Binder.clearCallingIdentity(); |
| 5787 | try { |
| 5788 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5789 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5790 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5791 | } |
| 5792 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5793 | } finally { |
| 5794 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5795 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5796 | } |
| 5797 | |
| 5798 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5799 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5800 | * |
| 5801 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5802 | * voicemail vibration setting. |
| 5803 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5804 | */ |
| 5805 | @Override |
| 5806 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5807 | final long identity = Binder.clearCallingIdentity(); |
| 5808 | try { |
| 5809 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5810 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5811 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5812 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5813 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5814 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5815 | } finally { |
| 5816 | Binder.restoreCallingIdentity(identity); |
| 5817 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5818 | } |
| 5819 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5820 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5821 | * Sets the per-account voicemail vibration. |
| 5822 | * |
| 5823 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5824 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5825 | * |
| 5826 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5827 | * voicemail vibration setting. |
| 5828 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5829 | * specific PhoneAccount. |
| 5830 | */ |
| 5831 | @Override |
| 5832 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5833 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5834 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5835 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5836 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5837 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5838 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5839 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5840 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5841 | } |
| 5842 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5843 | final long identity = Binder.clearCallingIdentity(); |
| 5844 | try { |
| 5845 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5846 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5847 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5848 | } |
| 5849 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5850 | } finally { |
| 5851 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5852 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5853 | } |
| 5854 | |
| 5855 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5856 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5857 | * |
| 5858 | * @throws SecurityException if the caller does not have the required permission |
| 5859 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5860 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5861 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5862 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5863 | } |
| 5864 | |
| 5865 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5866 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5867 | * permission. |
| 5868 | * |
| 5869 | * @throws SecurityException if the caller does not have the required permission |
| 5870 | */ |
| 5871 | private void enforceSendSmsPermission() { |
| 5872 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5873 | } |
| 5874 | |
| 5875 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5876 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5877 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5878 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5879 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5880 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5881 | final long identity = Binder.clearCallingIdentity(); |
| 5882 | try { |
| 5883 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5884 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5885 | if (componentName == null) { |
| 5886 | throw new SecurityException( |
| 5887 | "Caller not current active visual voicemail package[null]"); |
| 5888 | } |
| 5889 | String vvmPackage = componentName.getPackageName(); |
| 5890 | if (!callingPackage.equals(vvmPackage)) { |
| 5891 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5892 | + vvmPackage + "]"); |
| 5893 | } |
| 5894 | } finally { |
| 5895 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5896 | } |
| 5897 | } |
| 5898 | |
| 5899 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5900 | * Return the application ID for the app type. |
| 5901 | * |
| 5902 | * @param subId the subscription ID that this request applies to. |
| 5903 | * @param appType the uicc app type. |
| 5904 | * @return Application ID for specificied app type, or null if no uicc. |
| 5905 | */ |
| 5906 | @Override |
| 5907 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5908 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5909 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5910 | |
| 5911 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5912 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5913 | if (phone == null) { |
| 5914 | return null; |
| 5915 | } |
| 5916 | String aid = null; |
| 5917 | try { |
| 5918 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5919 | .getApplicationByType(appType).getAid(); |
| 5920 | } catch (Exception e) { |
| 5921 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5922 | } |
| 5923 | return aid; |
| 5924 | } finally { |
| 5925 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5926 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5927 | } |
| 5928 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5929 | /** |
| 5930 | * Return the Electronic Serial Number. |
| 5931 | * |
| 5932 | * @param subId the subscription ID that this request applies to. |
| 5933 | * @return ESN or null if error. |
| 5934 | */ |
| 5935 | @Override |
| 5936 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5937 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5938 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5939 | |
| 5940 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5941 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5942 | if (phone == null) { |
| 5943 | return null; |
| 5944 | } |
| 5945 | String esn = null; |
| 5946 | try { |
| 5947 | esn = phone.getEsn(); |
| 5948 | } catch (Exception e) { |
| 5949 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5950 | } |
| 5951 | return esn; |
| 5952 | } finally { |
| 5953 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5954 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5955 | } |
| 5956 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5957 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5958 | * Return the Preferred Roaming List Version. |
| 5959 | * |
| 5960 | * @param subId the subscription ID that this request applies to. |
| 5961 | * @return PRLVersion or null if error. |
| 5962 | */ |
| 5963 | @Override |
| 5964 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5965 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5966 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5967 | |
| 5968 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5969 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5970 | if (phone == null) { |
| 5971 | return null; |
| 5972 | } |
| 5973 | String cdmaPrlVersion = null; |
| 5974 | try { |
| 5975 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5976 | } catch (Exception e) { |
| 5977 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5978 | } |
| 5979 | return cdmaPrlVersion; |
| 5980 | } finally { |
| 5981 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5982 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5983 | } |
| 5984 | |
| 5985 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5986 | * Get snapshot of Telephony histograms |
| 5987 | * @return List of Telephony histograms |
| 5988 | * @hide |
| 5989 | */ |
| 5990 | @Override |
| 5991 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5992 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5993 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5994 | |
| 5995 | final long identity = Binder.clearCallingIdentity(); |
| 5996 | try { |
| 5997 | return RIL.getTelephonyRILTimingHistograms(); |
| 5998 | } finally { |
| 5999 | Binder.restoreCallingIdentity(identity); |
| 6000 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6001 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6002 | |
| 6003 | /** |
| 6004 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6005 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6006 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6007 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6008 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6009 | * @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] | 6010 | */ |
| 6011 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6012 | @TelephonyManager.SetCarrierRestrictionResult |
| 6013 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6014 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6015 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6016 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6017 | if (carrierRestrictionRules == null) { |
| 6018 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6019 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6020 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6021 | final long identity = Binder.clearCallingIdentity(); |
| 6022 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6023 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6024 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6025 | } finally { |
| 6026 | Binder.restoreCallingIdentity(identity); |
| 6027 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6028 | } |
| 6029 | |
| 6030 | /** |
| 6031 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6032 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6033 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6034 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6035 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6036 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6037 | */ |
| 6038 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6039 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6040 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6041 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6042 | |
| 6043 | final long identity = Binder.clearCallingIdentity(); |
| 6044 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6045 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6046 | if (response instanceof CarrierRestrictionRules) { |
| 6047 | return (CarrierRestrictionRules) response; |
| 6048 | } |
| 6049 | // Response is an Exception of some kind, |
| 6050 | // which is signalled to the user as a NULL retval |
| 6051 | return null; |
| 6052 | } catch (Exception e) { |
| 6053 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6054 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6055 | } finally { |
| 6056 | Binder.restoreCallingIdentity(identity); |
| 6057 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6058 | } |
| 6059 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6060 | /** |
| 6061 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6062 | * @param subId the subscription ID that this action applies to. |
| 6063 | * @param enabled control enable or disable metered apns. |
| 6064 | * {@hide} |
| 6065 | */ |
| 6066 | @Override |
| 6067 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6068 | enforceModifyPermission(); |
| 6069 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6070 | |
| 6071 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6072 | if (phone == null) { |
| 6073 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6074 | return; |
| 6075 | } |
| 6076 | try { |
| 6077 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6078 | } catch (Exception e) { |
| 6079 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6080 | } finally { |
| 6081 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6082 | } |
| 6083 | } |
| 6084 | |
| 6085 | /** |
| 6086 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6087 | * @param subId the subscription ID that this action applies to. |
| 6088 | * @param enabled control enable or disable radio. |
| 6089 | * {@hide} |
| 6090 | */ |
| 6091 | @Override |
| 6092 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6093 | enforceModifyPermission(); |
| 6094 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6095 | |
| 6096 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6097 | if (phone == null) { |
| 6098 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6099 | return; |
| 6100 | } |
| 6101 | try { |
| 6102 | phone.carrierActionSetRadioEnabled(enabled); |
| 6103 | } catch (Exception e) { |
| 6104 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6105 | } finally { |
| 6106 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6107 | } |
| 6108 | } |
| 6109 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6110 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6111 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6112 | * network status based on which carrier apps could apply actions accordingly, |
| 6113 | * enable/disable default url handler for example. |
| 6114 | * |
| 6115 | * @param subId the subscription ID that this action applies to. |
| 6116 | * @param report control start/stop reporting the default network status. |
| 6117 | * {@hide} |
| 6118 | */ |
| 6119 | @Override |
| 6120 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6121 | enforceModifyPermission(); |
| 6122 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6123 | |
| 6124 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6125 | if (phone == null) { |
| 6126 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6127 | return; |
| 6128 | } |
| 6129 | try { |
| 6130 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6131 | } catch (Exception e) { |
| 6132 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6133 | } finally { |
| 6134 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6135 | } |
| 6136 | } |
| 6137 | |
| 6138 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6139 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6140 | * @param subId the subscription ID that this action applies to. |
| 6141 | * {@hide} |
| 6142 | */ |
| 6143 | @Override |
| 6144 | public void carrierActionResetAll(int subId) { |
| 6145 | enforceModifyPermission(); |
| 6146 | final Phone phone = getPhone(subId); |
| 6147 | if (phone == null) { |
| 6148 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6149 | return; |
| 6150 | } |
| 6151 | try { |
| 6152 | phone.carrierActionResetAll(); |
| 6153 | } catch (Exception e) { |
| 6154 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6155 | } |
| 6156 | } |
| 6157 | |
| 6158 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6159 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6160 | * bug report is being generated. |
| 6161 | */ |
| 6162 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6163 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6164 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6165 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6166 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6167 | + Binder.getCallingPid() |
| 6168 | + ", uid=" + Binder.getCallingUid() |
| 6169 | + "without permission " |
| 6170 | + android.Manifest.permission.DUMP); |
| 6171 | return; |
| 6172 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6173 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6174 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6175 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6176 | @Override |
| 6177 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6178 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6179 | throws RemoteException { |
| 6180 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 6181 | } |
| 6182 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6183 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6184 | * Get aggregated video call data usage since boot. |
| 6185 | * |
| 6186 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6187 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6188 | * {@hide} |
| 6189 | */ |
| 6190 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6191 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6192 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6193 | null); |
| 6194 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6195 | final long identity = Binder.clearCallingIdentity(); |
| 6196 | try { |
| 6197 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6198 | // records the delta with the corresponding network identity. |
| 6199 | // We just return the total video call data usage snapshot since boot. |
| 6200 | Phone phone = getPhone(subId); |
| 6201 | if (phone != null) { |
| 6202 | return phone.getVtDataUsage(perUidStats); |
| 6203 | } |
| 6204 | return null; |
| 6205 | } finally { |
| 6206 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6207 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6208 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6209 | |
| 6210 | /** |
| 6211 | * Policy control of data connection. Usually used when data limit is passed. |
| 6212 | * @param enabled True if enabling the data, otherwise disabling. |
| 6213 | * @param subId Subscription index |
| 6214 | * {@hide} |
| 6215 | */ |
| 6216 | @Override |
| 6217 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6218 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6219 | |
| 6220 | final long identity = Binder.clearCallingIdentity(); |
| 6221 | try { |
| 6222 | Phone phone = getPhone(subId); |
| 6223 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6224 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6225 | } |
| 6226 | } finally { |
| 6227 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6228 | } |
| 6229 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6230 | |
| 6231 | /** |
| 6232 | * Get Client request stats |
| 6233 | * @return List of Client Request Stats |
| 6234 | * @hide |
| 6235 | */ |
| 6236 | @Override |
| 6237 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6238 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6239 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6240 | return null; |
| 6241 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6242 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6243 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6244 | final long identity = Binder.clearCallingIdentity(); |
| 6245 | try { |
| 6246 | if (phone != null) { |
| 6247 | return phone.getClientRequestStats(); |
| 6248 | } |
| 6249 | |
| 6250 | return null; |
| 6251 | } finally { |
| 6252 | Binder.restoreCallingIdentity(identity); |
| 6253 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6254 | } |
| 6255 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6256 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6257 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6258 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6259 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6260 | |
| 6261 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6262 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6263 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6264 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6265 | * @param state State of SIM (power down, power up, pass through) |
| 6266 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6267 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6268 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6269 | * |
| 6270 | **/ |
| 6271 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6272 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6273 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6274 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6275 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6276 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6277 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6278 | final long identity = Binder.clearCallingIdentity(); |
| 6279 | try { |
| 6280 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6281 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6282 | } |
| 6283 | } finally { |
| 6284 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6285 | } |
| 6286 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6287 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6288 | private boolean isUssdApiAllowed(int subId) { |
| 6289 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6290 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6291 | if (configManager == null) { |
| 6292 | return false; |
| 6293 | } |
| 6294 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6295 | if (pb == null) { |
| 6296 | return false; |
| 6297 | } |
| 6298 | return pb.getBoolean( |
| 6299 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6300 | } |
| 6301 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6302 | /** |
| 6303 | * Check if phone is in emergency callback mode |
| 6304 | * @return true if phone is in emergency callback mode |
| 6305 | * @param subId sub id |
| 6306 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6307 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6308 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6309 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6310 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6311 | |
| 6312 | final long identity = Binder.clearCallingIdentity(); |
| 6313 | try { |
| 6314 | if (phone != null) { |
| 6315 | return phone.isInEcm(); |
| 6316 | } else { |
| 6317 | return false; |
| 6318 | } |
| 6319 | } finally { |
| 6320 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6321 | } |
| 6322 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6323 | |
| 6324 | /** |
| 6325 | * Get the current signal strength information for the given subscription. |
| 6326 | * Because this information is not updated when the device is in a low power state |
| 6327 | * it should not be relied-upon to be current. |
| 6328 | * @param subId Subscription index |
| 6329 | * @return the most recent cached signal strength info from the modem |
| 6330 | */ |
| 6331 | @Override |
| 6332 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6333 | final long identity = Binder.clearCallingIdentity(); |
| 6334 | try { |
| 6335 | Phone p = getPhone(subId); |
| 6336 | if (p == null) { |
| 6337 | return null; |
| 6338 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6339 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6340 | return p.getSignalStrength(); |
| 6341 | } finally { |
| 6342 | Binder.restoreCallingIdentity(identity); |
| 6343 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6344 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6345 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6346 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6347 | * Get the current modem radio state for the given slot. |
| 6348 | * @param slotIndex slot index. |
| 6349 | * @param callingPackage the name of the package making the call. |
| 6350 | * @return the current radio power state from the modem |
| 6351 | */ |
| 6352 | @Override |
| 6353 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6354 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6355 | if (phone != null) { |
| 6356 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6357 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6358 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6359 | } |
| 6360 | |
| 6361 | final long identity = Binder.clearCallingIdentity(); |
| 6362 | try { |
| 6363 | return phone.getRadioPowerState(); |
| 6364 | } finally { |
| 6365 | Binder.restoreCallingIdentity(identity); |
| 6366 | } |
| 6367 | } |
| 6368 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6369 | } |
| 6370 | |
| 6371 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6372 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6373 | * |
| 6374 | * <p>Requires one of the following permissions: |
| 6375 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6376 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6377 | * privileges. |
| 6378 | * |
| 6379 | * @param subId subscription id |
| 6380 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6381 | * {@code false}. |
| 6382 | */ |
| 6383 | @Override |
| 6384 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6385 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6386 | null /* message */); |
| 6387 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6388 | boolean isEnabled = false; |
| 6389 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6390 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6391 | Phone phone = getPhone(subId); |
| 6392 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6393 | } catch (Exception e) { |
| 6394 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6395 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6396 | } finally { |
| 6397 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6398 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6399 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6400 | } |
| 6401 | |
| 6402 | |
| 6403 | /** |
| 6404 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6405 | * |
| 6406 | * <p> Requires permission: |
| 6407 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6408 | * privileges. |
| 6409 | * |
| 6410 | * @param subId subscription id |
| 6411 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6412 | */ |
| 6413 | @Override |
| 6414 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6415 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6416 | mApp, subId, "setDataRoamingEnabled"); |
| 6417 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6418 | final long identity = Binder.clearCallingIdentity(); |
| 6419 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6420 | Phone phone = getPhone(subId); |
| 6421 | if (phone != null) { |
| 6422 | phone.setDataRoamingEnabled(isEnabled); |
| 6423 | } |
| 6424 | } finally { |
| 6425 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6426 | } |
| 6427 | } |
| 6428 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6429 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6430 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6431 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6432 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6433 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6434 | boolean isAllowed = true; |
| 6435 | final long identity = Binder.clearCallingIdentity(); |
| 6436 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6437 | Phone phone = getPhone(subId); |
| 6438 | if (phone != null) { |
| 6439 | isAllowed = phone.isCspPlmnEnabled(); |
| 6440 | } |
| 6441 | } finally { |
| 6442 | Binder.restoreCallingIdentity(identity); |
| 6443 | } |
| 6444 | return isAllowed; |
| 6445 | } |
| 6446 | |
| 6447 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6448 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6449 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6450 | try { |
| 6451 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6452 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6453 | } catch (SecurityException e) { |
| 6454 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6455 | // has carrier privileges on an active UICC |
| 6456 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6457 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6458 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6459 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6460 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6461 | |
| 6462 | final long identity = Binder.clearCallingIdentity(); |
| 6463 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6464 | UiccController uiccController = UiccController.getInstance(); |
| 6465 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6466 | if (hasReadPermission) { |
| 6467 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6468 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6469 | |
| 6470 | // Remove private info if the caller doesn't have access |
| 6471 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6472 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6473 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6474 | // is available |
| 6475 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6476 | if (card == null || card.getUiccProfile() == null) { |
| 6477 | // assume no access if the card or profile is unavailable |
| 6478 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6479 | continue; |
| 6480 | } |
| 6481 | UiccProfile profile = card.getUiccProfile(); |
| 6482 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6483 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6484 | filteredInfos.add(cardInfo); |
| 6485 | } else { |
| 6486 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6487 | } |
| 6488 | } |
| 6489 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6490 | } finally { |
| 6491 | Binder.restoreCallingIdentity(identity); |
| 6492 | } |
| 6493 | } |
| 6494 | |
| 6495 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6496 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6497 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6498 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6499 | final long identity = Binder.clearCallingIdentity(); |
| 6500 | try { |
| 6501 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6502 | if (slots == null) { |
| 6503 | Rlog.i(LOG_TAG, "slots is null."); |
| 6504 | return null; |
| 6505 | } |
| 6506 | |
| 6507 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6508 | for (int i = 0; i < slots.length; i++) { |
| 6509 | UiccSlot slot = slots[i]; |
| 6510 | if (slot == null) { |
| 6511 | continue; |
| 6512 | } |
| 6513 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6514 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6515 | UiccCard card = slot.getUiccCard(); |
| 6516 | if (card != null) { |
| 6517 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6518 | } else { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6519 | cardId = slot.getIccId(); |
| 6520 | } |
| 6521 | |
| 6522 | int cardState = 0; |
| 6523 | switch (slot.getCardState()) { |
| 6524 | case CARDSTATE_ABSENT: |
| 6525 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6526 | break; |
| 6527 | case CARDSTATE_PRESENT: |
| 6528 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6529 | break; |
| 6530 | case CARDSTATE_ERROR: |
| 6531 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6532 | break; |
| 6533 | case CARDSTATE_RESTRICTED: |
| 6534 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6535 | break; |
| 6536 | default: |
| 6537 | break; |
| 6538 | |
| 6539 | } |
| 6540 | |
| 6541 | infos[i] = new UiccSlotInfo( |
| 6542 | slot.isActive(), |
| 6543 | slot.isEuicc(), |
| 6544 | cardId, |
| 6545 | cardState, |
| 6546 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6547 | slot.isExtendedApduSupported(), |
| 6548 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6549 | } |
| 6550 | return infos; |
| 6551 | } finally { |
| 6552 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6553 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6554 | } |
| 6555 | |
| 6556 | @Override |
| 6557 | public boolean switchSlots(int[] physicalSlots) { |
| 6558 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6559 | |
| 6560 | final long identity = Binder.clearCallingIdentity(); |
| 6561 | try { |
| 6562 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6563 | } finally { |
| 6564 | Binder.restoreCallingIdentity(identity); |
| 6565 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6566 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6567 | |
| 6568 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6569 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6570 | final long identity = Binder.clearCallingIdentity(); |
| 6571 | try { |
| 6572 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6573 | } finally { |
| 6574 | Binder.restoreCallingIdentity(identity); |
| 6575 | } |
| 6576 | } |
| 6577 | |
| 6578 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6579 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6580 | enforceModifyPermission(); |
| 6581 | final Phone phone = getPhone(subId); |
| 6582 | if (phone == null) { |
| 6583 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6584 | return; |
| 6585 | } |
| 6586 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6587 | final long identity = Binder.clearCallingIdentity(); |
| 6588 | try { |
| 6589 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6590 | } finally { |
| 6591 | Binder.restoreCallingIdentity(identity); |
| 6592 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6593 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6594 | |
| 6595 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6596 | * A test API to reload the UICC profile. |
| 6597 | * |
| 6598 | * <p>Requires that the calling app has permission |
| 6599 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6600 | * @hide |
| 6601 | */ |
| 6602 | @Override |
| 6603 | public void refreshUiccProfile(int subId) { |
| 6604 | enforceModifyPermission(); |
| 6605 | |
| 6606 | final long identity = Binder.clearCallingIdentity(); |
| 6607 | try { |
| 6608 | Phone phone = getPhone(subId); |
| 6609 | if (phone == null) { |
| 6610 | return; |
| 6611 | } |
| 6612 | UiccCard uiccCard = phone.getUiccCard(); |
| 6613 | if (uiccCard == null) { |
| 6614 | return; |
| 6615 | } |
| 6616 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6617 | if (uiccProfile == null) { |
| 6618 | return; |
| 6619 | } |
| 6620 | uiccProfile.refresh(); |
| 6621 | } finally { |
| 6622 | Binder.restoreCallingIdentity(identity); |
| 6623 | } |
| 6624 | } |
| 6625 | |
| 6626 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6627 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6628 | */ |
| 6629 | private boolean getDefaultDataEnabled() { |
| 6630 | return "true".equalsIgnoreCase( |
| 6631 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6632 | } |
| 6633 | |
| 6634 | /** |
| 6635 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6636 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6637 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6638 | */ |
| 6639 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6640 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6641 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6642 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6643 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6644 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6645 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6646 | return isDataRoamingEnabled; |
| 6647 | } |
| 6648 | |
| 6649 | /** |
| 6650 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6651 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6652 | */ |
| 6653 | private int getDefaultNetworkType(int subId) { |
| 6654 | return Integer.parseInt( |
| 6655 | TelephonyManager.getTelephonyProperty( |
| 6656 | mSubscriptionController.getPhoneId(subId), |
| 6657 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6658 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6659 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6660 | |
| 6661 | @Override |
| 6662 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6663 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6664 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6665 | |
| 6666 | final long identity = Binder.clearCallingIdentity(); |
| 6667 | try { |
| 6668 | final Phone phone = getPhone(subId); |
| 6669 | if (phone == null) { |
| 6670 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6671 | return; |
| 6672 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6673 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 6674 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6675 | } finally { |
| 6676 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6677 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6678 | } |
| 6679 | |
| 6680 | @Override |
| 6681 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6682 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6683 | |
| 6684 | final long identity = Binder.clearCallingIdentity(); |
| 6685 | try { |
| 6686 | final Phone phone = getPhone(subId); |
| 6687 | if (phone == null) { |
| 6688 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6689 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6690 | } |
| 6691 | return phone.getCarrierIdListVersion(); |
| 6692 | } finally { |
| 6693 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6694 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6695 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6696 | |
| 6697 | @Override |
| 6698 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6699 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6700 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6701 | return -1; |
| 6702 | } |
| 6703 | |
| 6704 | final long identity = Binder.clearCallingIdentity(); |
| 6705 | try { |
| 6706 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6707 | } finally { |
| 6708 | Binder.restoreCallingIdentity(identity); |
| 6709 | } |
| 6710 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6711 | |
| 6712 | @Override |
| 6713 | public int getCdmaRoamingMode(int subId) { |
| 6714 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6715 | mApp, subId, "getCdmaRoamingMode"); |
| 6716 | |
| 6717 | final long identity = Binder.clearCallingIdentity(); |
| 6718 | try { |
| 6719 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6720 | } finally { |
| 6721 | Binder.restoreCallingIdentity(identity); |
| 6722 | } |
| 6723 | } |
| 6724 | |
| 6725 | @Override |
| 6726 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6727 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6728 | mApp, subId, "setCdmaRoamingMode"); |
| 6729 | |
| 6730 | final long identity = Binder.clearCallingIdentity(); |
| 6731 | try { |
| 6732 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6733 | } finally { |
| 6734 | Binder.restoreCallingIdentity(identity); |
| 6735 | } |
| 6736 | } |
| 6737 | |
| 6738 | @Override |
| 6739 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6740 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6741 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6742 | |
| 6743 | final long identity = Binder.clearCallingIdentity(); |
| 6744 | try { |
| 6745 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6746 | } finally { |
| 6747 | Binder.restoreCallingIdentity(identity); |
| 6748 | } |
| 6749 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 6750 | |
| 6751 | private void ensureUserRunning(int userId) { |
| 6752 | if (!mUserManager.isUserRunning(userId)) { |
| 6753 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6754 | } |
| 6755 | } |
| 6756 | |
| 6757 | /** |
| 6758 | * Returns a list of SMS apps on a given user. |
| 6759 | * |
| 6760 | * Only the shell user (UID 2000 or 0) can call it. |
| 6761 | * Target user must be running. |
| 6762 | */ |
| 6763 | @Override |
| 6764 | public String[] getSmsApps(int userId) { |
| 6765 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6766 | ensureUserRunning(userId); |
| 6767 | |
| 6768 | final Collection<SmsApplicationData> apps = |
| 6769 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6770 | |
| 6771 | String[] ret = new String[apps.size()]; |
| 6772 | int i = 0; |
| 6773 | for (SmsApplicationData app : apps) { |
| 6774 | ret[i++] = app.mPackageName; |
| 6775 | } |
| 6776 | return ret; |
| 6777 | } |
| 6778 | |
| 6779 | /** |
| 6780 | * Returns the default SMS app package name on a given user. |
| 6781 | * |
| 6782 | * Only the shell user (UID 2000 or 0) can call it. |
| 6783 | * Target user must be running. |
| 6784 | */ |
| 6785 | @Override |
| 6786 | public String getDefaultSmsApp(int userId) { |
| 6787 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6788 | ensureUserRunning(userId); |
| 6789 | |
| 6790 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6791 | /* updateIfNeeded= */ true, userId); |
| 6792 | return cn == null ? null : cn.getPackageName(); |
| 6793 | } |
| 6794 | |
| 6795 | /** |
| 6796 | * Set a package as the default SMS app on a given user. |
| 6797 | * |
| 6798 | * Only the shell user (UID 2000 or 0) can call it. |
| 6799 | * Target user must be running. |
| 6800 | */ |
| 6801 | @Override |
| 6802 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6803 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6804 | ensureUserRunning(userId); |
| 6805 | |
| 6806 | boolean found = false; |
| 6807 | for (String pkg : getSmsApps(userId)) { |
| 6808 | if (TextUtils.equals(packageName, pkg)) { |
| 6809 | found = true; |
| 6810 | break; |
| 6811 | } |
| 6812 | } |
| 6813 | if (!found) { |
| 6814 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6815 | } |
| 6816 | |
| 6817 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6818 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6819 | |
| 6820 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6821 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6822 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6823 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6824 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6825 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6826 | } |
| 6827 | final long identity = Binder.clearCallingIdentity(); |
| 6828 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6829 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6830 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6831 | if (phone.getEmergencyNumberTracker() != null |
| 6832 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6833 | emergencyNumberListInternal.put( |
| 6834 | phone.getSubId(), |
| 6835 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6836 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6837 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6838 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6839 | } finally { |
| 6840 | Binder.restoreCallingIdentity(identity); |
| 6841 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6842 | } |
| 6843 | |
| 6844 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6845 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6846 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6847 | if (!exactMatch) { |
| 6848 | TelephonyPermissions |
| 6849 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6850 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6851 | } |
| 6852 | final long identity = Binder.clearCallingIdentity(); |
| 6853 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6854 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6855 | if (phone.getEmergencyNumberTracker() != null |
| 6856 | && phone.getEmergencyNumberTracker() != null) { |
| 6857 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6858 | number, exactMatch)) { |
| 6859 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6860 | } |
| 6861 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6862 | } |
| 6863 | return false; |
| 6864 | } finally { |
| 6865 | Binder.restoreCallingIdentity(identity); |
| 6866 | } |
| 6867 | } |
| 6868 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6869 | /** |
| 6870 | * Update emergency number list for test mode. |
| 6871 | */ |
| 6872 | @Override |
| 6873 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6874 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6875 | "updateEmergencyNumberListTestMode"); |
| 6876 | |
| 6877 | final long identity = Binder.clearCallingIdentity(); |
| 6878 | try { |
| 6879 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6880 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6881 | if (tracker != null) { |
| 6882 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6883 | } |
| 6884 | } |
| 6885 | } finally { |
| 6886 | Binder.restoreCallingIdentity(identity); |
| 6887 | } |
| 6888 | } |
| 6889 | |
| 6890 | /** |
| 6891 | * Get the full emergency number list for test mode. |
| 6892 | */ |
| 6893 | @Override |
| 6894 | public List<String> getEmergencyNumberListTestMode() { |
| 6895 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6896 | "getEmergencyNumberListTestMode"); |
| 6897 | |
| 6898 | final long identity = Binder.clearCallingIdentity(); |
| 6899 | try { |
| 6900 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6901 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6902 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6903 | if (tracker != null) { |
| 6904 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6905 | emergencyNumbers.add(num.getNumber()); |
| 6906 | } |
| 6907 | } |
| 6908 | } |
| 6909 | return new ArrayList<>(emergencyNumbers); |
| 6910 | } finally { |
| 6911 | Binder.restoreCallingIdentity(identity); |
| 6912 | } |
| 6913 | } |
| 6914 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6915 | @Override |
| 6916 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6917 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6918 | Phone phone = getPhone(subId); |
| 6919 | if (phone == null) { |
| 6920 | return null; |
| 6921 | } |
| 6922 | final long identity = Binder.clearCallingIdentity(); |
| 6923 | try { |
| 6924 | UiccProfile profile = UiccController.getInstance() |
| 6925 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6926 | if (profile != null) { |
| 6927 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6928 | } |
| 6929 | } finally { |
| 6930 | Binder.restoreCallingIdentity(identity); |
| 6931 | } |
| 6932 | return null; |
| 6933 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6934 | |
| 6935 | /** |
| 6936 | * Enable or disable a modem stack. |
| 6937 | */ |
| 6938 | @Override |
| 6939 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6940 | enforceModifyPermission(); |
| 6941 | |
| 6942 | final long identity = Binder.clearCallingIdentity(); |
| 6943 | try { |
| 6944 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6945 | if (phone == null) { |
| 6946 | return false; |
| 6947 | } else { |
| 6948 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6949 | } |
| 6950 | } finally { |
| 6951 | Binder.restoreCallingIdentity(identity); |
| 6952 | } |
| 6953 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6954 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6955 | /** |
| 6956 | * Whether a modem stack is enabled or not. |
| 6957 | */ |
| 6958 | @Override |
| 6959 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 6960 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6961 | if (phone == null) return false; |
| 6962 | |
| 6963 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6964 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 6965 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6966 | } |
| 6967 | |
| 6968 | final long identity = Binder.clearCallingIdentity(); |
| 6969 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 6970 | try { |
| 6971 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 6972 | } catch (NoSuchElementException ex) { |
| 6973 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 6974 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6975 | } finally { |
| 6976 | Binder.restoreCallingIdentity(identity); |
| 6977 | } |
| 6978 | } |
| 6979 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6980 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6981 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6982 | enforceModifyPermission(); |
| 6983 | |
| 6984 | final long identity = Binder.clearCallingIdentity(); |
| 6985 | try { |
| 6986 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6987 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6988 | .commit(); |
| 6989 | } finally { |
| 6990 | Binder.restoreCallingIdentity(identity); |
| 6991 | } |
| 6992 | } |
| 6993 | |
| 6994 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6995 | @TelephonyManager.IsMultiSimSupportedResult |
| 6996 | public int isMultiSimSupported(String callingPackage) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6997 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6998 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 6999 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7000 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7001 | |
| 7002 | final long identity = Binder.clearCallingIdentity(); |
| 7003 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7004 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7005 | } finally { |
| 7006 | Binder.restoreCallingIdentity(identity); |
| 7007 | } |
| 7008 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7009 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7010 | @TelephonyManager.IsMultiSimSupportedResult |
| 7011 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7012 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7013 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7014 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7015 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7016 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7017 | } |
| 7018 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7019 | // supported by the modem, indicate that it is restricted. |
| 7020 | PhoneCapability staticCapability = |
| 7021 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7022 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7023 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7024 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7025 | } |
| 7026 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7027 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7028 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7029 | } |
| 7030 | // Check if support of multiple SIMs is restricted by carrier |
| 7031 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7032 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7033 | } |
| 7034 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7035 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7036 | } |
| 7037 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7038 | /** |
| 7039 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7040 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7041 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7042 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7043 | * @param numOfSims number of active sims we want to switch to |
| 7044 | */ |
| 7045 | @Override |
| 7046 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7047 | if (numOfSims == 1) { |
| 7048 | enforceModifyPermission(); |
| 7049 | } else { |
| 7050 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7051 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7052 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7053 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7054 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7055 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7056 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7057 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7058 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7059 | return; |
| 7060 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7061 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7062 | } finally { |
| 7063 | Binder.restoreCallingIdentity(identity); |
| 7064 | } |
| 7065 | } |
| 7066 | |
| 7067 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7068 | * Get whether making changes to modem configurations will trigger reboot. |
| 7069 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7070 | */ |
| 7071 | @Override |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7072 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) { |
| 7073 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7074 | mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) { |
| 7075 | return false; |
| 7076 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7077 | final long identity = Binder.clearCallingIdentity(); |
| 7078 | try { |
| 7079 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7080 | } finally { |
| 7081 | Binder.restoreCallingIdentity(identity); |
| 7082 | } |
| 7083 | } |
| 7084 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7085 | private void updateModemStateMetrics() { |
| 7086 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7087 | // TODO: check the state for each modem if the api is ready. |
| 7088 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7089 | } |
| 7090 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7091 | @Override |
| 7092 | public int[] getSlotsMapping() { |
| 7093 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7094 | |
| 7095 | final long identity = Binder.clearCallingIdentity(); |
| 7096 | try { |
| 7097 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7098 | // All logical slots should have a mapping to a physical slot. |
| 7099 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7100 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7101 | for (int i = 0; i < slotInfos.length; i++) { |
| 7102 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7103 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7104 | } |
| 7105 | } |
| 7106 | return logicalSlotsMapping; |
| 7107 | } finally { |
| 7108 | Binder.restoreCallingIdentity(identity); |
| 7109 | } |
| 7110 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7111 | |
| 7112 | /** |
| 7113 | * Get the IRadio HAL Version |
| 7114 | */ |
| 7115 | @Override |
| 7116 | public int getRadioHalVersion() { |
| 7117 | Phone phone = getDefaultPhone(); |
| 7118 | if (phone == null) return -1; |
| 7119 | HalVersion hv = phone.getHalVersion(); |
| 7120 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7121 | return hv.major * 100 + hv.minor; |
| 7122 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7123 | |
| 7124 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7125 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7126 | * corresponding network requests on a subId. |
| 7127 | * |
| 7128 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7129 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7130 | * 2) APN is un-metered for this subscription, or |
| 7131 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7132 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7133 | * |
| 7134 | * @return whether data is allowed for a apn type. |
| 7135 | * |
| 7136 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7137 | */ |
| 7138 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7139 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7140 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7141 | mApp, subId, callingPackage, "isDataEnabledForApn")) { |
| 7142 | throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7143 | } |
| 7144 | |
| 7145 | // Now that all security checks passes, perform the operation as ourselves. |
| 7146 | final long identity = Binder.clearCallingIdentity(); |
| 7147 | try { |
| 7148 | Phone phone = getPhone(subId); |
| 7149 | if (phone == null) return false; |
| 7150 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7151 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7152 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7153 | } finally { |
| 7154 | Binder.restoreCallingIdentity(identity); |
| 7155 | } |
| 7156 | } |
| 7157 | |
| 7158 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7159 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7160 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7161 | |
| 7162 | // Now that all security checks passes, perform the operation as ourselves. |
| 7163 | final long identity = Binder.clearCallingIdentity(); |
| 7164 | try { |
| 7165 | Phone phone = getPhone(subId); |
| 7166 | if (phone == null) return true; // By default return true. |
| 7167 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7168 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7169 | } finally { |
| 7170 | Binder.restoreCallingIdentity(identity); |
| 7171 | } |
| 7172 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7173 | |
| 7174 | @Override |
| 7175 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7176 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7177 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7178 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7179 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7180 | } |
| 7181 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7182 | Intent intent = new Intent(); |
| 7183 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7184 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7185 | // Bring up choose default SMS subscription dialog right now |
| 7186 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7187 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7188 | mApp.startActivity(intent); |
| 7189 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7190 | |
| 7191 | @Override |
| 7192 | public String getMmsUAProfUrl(int subId) { |
| 7193 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7194 | final long identity = Binder.clearCallingIdentity(); |
| 7195 | try { |
| 7196 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7197 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7198 | } finally { |
| 7199 | Binder.restoreCallingIdentity(identity); |
| 7200 | } |
| 7201 | } |
| 7202 | |
| 7203 | @Override |
| 7204 | public String getMmsUserAgent(int subId) { |
| 7205 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7206 | final long identity = Binder.clearCallingIdentity(); |
| 7207 | try { |
| 7208 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7209 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7210 | } finally { |
| 7211 | Binder.restoreCallingIdentity(identity); |
| 7212 | } |
| 7213 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7214 | |
| 7215 | @Override |
| 7216 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7217 | enforceModifyPermission(); |
| 7218 | |
| 7219 | // Now that all security checks passes, perform the operation as ourselves. |
| 7220 | final long identity = Binder.clearCallingIdentity(); |
| 7221 | try { |
| 7222 | Phone phone = getPhone(subId); |
| 7223 | if (phone == null) return false; |
| 7224 | |
| 7225 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7226 | } finally { |
| 7227 | Binder.restoreCallingIdentity(identity); |
| 7228 | } |
| 7229 | } |
| 7230 | |
| 7231 | @Override |
| 7232 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7233 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7234 | |
| 7235 | // Now that all security checks passes, perform the operation as ourselves. |
| 7236 | final long identity = Binder.clearCallingIdentity(); |
| 7237 | try { |
| 7238 | Phone phone = getPhone(subId); |
| 7239 | if (phone == null) return false; |
| 7240 | |
| 7241 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7242 | } finally { |
| 7243 | Binder.restoreCallingIdentity(identity); |
| 7244 | } |
| 7245 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7246 | } |