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; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 47 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 48 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 49 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 51 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 52 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 54 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 55 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 56 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 57 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 58 | import android.provider.Telephony; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 59 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 60 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 61 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 62 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 63 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 65 | import android.telephony.CellInfoGsm; |
| 66 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 67 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 68 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 69 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 70 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 71 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 72 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 73 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 74 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 75 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 76 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 77 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 78 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 79 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 80 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 81 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 82 | import android.telephony.SmsManager; |
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; |
| 94 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 95 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 96 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 97 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 98 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 99 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 100 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 101 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 102 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 103 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 104 | import android.telephony.ims.feature.MmTelFeature; |
| 105 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 106 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 107 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 108 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 109 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 110 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 111 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 112 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 113 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 114 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 115 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 119 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 126 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 128 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.ServiceStateTracker; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.SmsApplication; |
| 141 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.ims.ImsResolver; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.uicc.IccIoResult; |
| 150 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 156 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 158 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 159 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 160 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 161 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 162 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 163 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 164 | import java.io.FileDescriptor; |
| 165 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 166 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 167 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 168 | import java.util.Arrays; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 169 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 170 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 171 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 172 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 173 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 174 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 175 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 176 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 177 | |
| 178 | /** |
| 179 | * Implementation of the ITelephony interface. |
| 180 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 181 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 182 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 183 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 184 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 185 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 186 | |
| 187 | // Message codes used with mMainThreadHandler |
| 188 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 189 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 190 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 191 | private static final int CMD_OPEN_CHANNEL = 9; |
| 192 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 193 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 194 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 195 | private static final int CMD_NV_READ_ITEM = 13; |
| 196 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 197 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 198 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 199 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 200 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 201 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 202 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 203 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 204 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 205 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 206 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 207 | private static final int CMD_SEND_ENVELOPE = 25; |
| 208 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 209 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 210 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 211 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 212 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 213 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 214 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 215 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 216 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 217 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 218 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 219 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 220 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 221 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 222 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 223 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 224 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 225 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 226 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 227 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 228 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 229 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 230 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 231 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 232 | private static final int CMD_SWITCH_SLOTS = 50; |
| 233 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 234 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 235 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 236 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 237 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 238 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 239 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 240 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 241 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 242 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 243 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 244 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 245 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 246 | private static final int CMD_MODEM_REBOOT = 64; |
| 247 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 248 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 249 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 250 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 251 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 252 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 253 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 254 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 255 | // Parameters of select command. |
| 256 | private static final int SELECT_COMMAND = 0xA4; |
| 257 | private static final int SELECT_P1 = 0x04; |
| 258 | private static final int SELECT_P2 = 0; |
| 259 | private static final int SELECT_P3 = 0x10; |
| 260 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 261 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 262 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 263 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 264 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 265 | /** The singleton instance. */ |
| 266 | private static PhoneInterfaceManager sInstance; |
| 267 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 268 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 269 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 270 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 271 | private AppOpsManager mAppOps; |
| 272 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 273 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 274 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 275 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 276 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 277 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 278 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 279 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 280 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 281 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 282 | // String to store multi SIM allowed |
| 283 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 284 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 285 | // The AID of ISD-R. |
| 286 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 287 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 288 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 289 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 290 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 291 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 292 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 293 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 294 | * A request object to use for transmitting data to an ICC. |
| 295 | */ |
| 296 | private static final class IccAPDUArgument { |
| 297 | public int channel, cla, command, p1, p2, p3; |
| 298 | public String data; |
| 299 | |
| 300 | public IccAPDUArgument(int channel, int cla, int command, |
| 301 | int p1, int p2, int p3, String data) { |
| 302 | this.channel = channel; |
| 303 | this.cla = cla; |
| 304 | this.command = command; |
| 305 | this.p1 = p1; |
| 306 | this.p2 = p2; |
| 307 | this.p3 = p3; |
| 308 | this.data = data; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 313 | * A request object to use for transmitting data to an ICC. |
| 314 | */ |
| 315 | private static final class ManualNetworkSelectionArgument { |
| 316 | public OperatorInfo operatorInfo; |
| 317 | public boolean persistSelection; |
| 318 | |
| 319 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 320 | this.operatorInfo = operatorInfo; |
| 321 | this.persistSelection = persistSelection; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 326 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 327 | * request after sending. The main thread will notify the request when it is complete. |
| 328 | */ |
| 329 | private static final class MainThreadRequest { |
| 330 | /** The argument to use for the request */ |
| 331 | public Object argument; |
| 332 | /** The result of the request that is run on the main thread */ |
| 333 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 334 | // The subscriber id that this request applies to. Defaults to |
| 335 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 336 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 337 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 338 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 339 | public Phone phone; |
| 340 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 341 | public WorkSource workSource; |
| 342 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 343 | public MainThreadRequest(Object argument) { |
| 344 | this.argument = argument; |
| 345 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 346 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 347 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 348 | this.argument = argument; |
| 349 | if (phone != null) { |
| 350 | this.phone = phone; |
| 351 | } |
| 352 | this.workSource = workSource; |
| 353 | } |
| 354 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 355 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 356 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 357 | if (subId != null) { |
| 358 | this.subId = subId; |
| 359 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 360 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 361 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 364 | private static final class IncomingThirdPartyCallArgs { |
| 365 | public final ComponentName component; |
| 366 | public final String callId; |
| 367 | public final String callerDisplayName; |
| 368 | |
| 369 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 370 | String callerDisplayName) { |
| 371 | this.component = component; |
| 372 | this.callId = callId; |
| 373 | this.callerDisplayName = callerDisplayName; |
| 374 | } |
| 375 | } |
| 376 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 377 | /** |
| 378 | * A handler that processes messages on the main thread in the phone process. Since many |
| 379 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 380 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 381 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 382 | * on, which will be notified when the operation completes and will contain the result of the |
| 383 | * request. |
| 384 | * |
| 385 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 386 | * note that request.result must be set to something non-null for the calling thread to |
| 387 | * unblock. |
| 388 | */ |
| 389 | private final class MainThreadHandler extends Handler { |
| 390 | @Override |
| 391 | public void handleMessage(Message msg) { |
| 392 | MainThreadRequest request; |
| 393 | Message onCompleted; |
| 394 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 395 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 396 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 397 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 398 | |
| 399 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 400 | case CMD_HANDLE_USSD_REQUEST: { |
| 401 | request = (MainThreadRequest) msg.obj; |
| 402 | final Phone phone = getPhoneFromRequest(request); |
| 403 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 404 | String ussdRequest = ussdObject.first; |
| 405 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 406 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 407 | if (!isUssdApiAllowed(request.subId)) { |
| 408 | // Carrier does not support use of this API, return failure. |
| 409 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 410 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 411 | Bundle returnData = new Bundle(); |
| 412 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 413 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 414 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 415 | request.result = true; |
| 416 | notifyRequester(request); |
| 417 | return; |
| 418 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 419 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 420 | try { |
| 421 | request.result = phone != null |
| 422 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 423 | } catch (CallStateException cse) { |
| 424 | request.result = false; |
| 425 | } |
| 426 | // Wake up the requesting thread |
| 427 | notifyRequester(request); |
| 428 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 431 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 432 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 433 | final Phone phone = getPhoneFromRequest(request); |
| 434 | request.result = phone != null ? |
| 435 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 436 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 437 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 438 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 439 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 440 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 441 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 442 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 443 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 444 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 445 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 446 | if (uiccCard == null) { |
| 447 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 448 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 449 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 450 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 451 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 452 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 453 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 454 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 455 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 456 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 457 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 458 | break; |
| 459 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 460 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 461 | ar = (AsyncResult) msg.obj; |
| 462 | request = (MainThreadRequest) ar.userObj; |
| 463 | if (ar.exception == null && ar.result != null) { |
| 464 | request.result = ar.result; |
| 465 | } else { |
| 466 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 467 | if (ar.result == null) { |
| 468 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 469 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 470 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 471 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 472 | } else { |
| 473 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 474 | } |
| 475 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 476 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 477 | break; |
| 478 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 479 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 480 | request = (MainThreadRequest) msg.obj; |
| 481 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 482 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 483 | if (uiccCard == null) { |
| 484 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 485 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 486 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 487 | } else { |
| 488 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 489 | request); |
| 490 | uiccCard.iccTransmitApduBasicChannel( |
| 491 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 492 | iccArgument.p3, iccArgument.data, onCompleted); |
| 493 | } |
| 494 | break; |
| 495 | |
| 496 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 497 | ar = (AsyncResult) msg.obj; |
| 498 | request = (MainThreadRequest) ar.userObj; |
| 499 | if (ar.exception == null && ar.result != null) { |
| 500 | request.result = ar.result; |
| 501 | } else { |
| 502 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 503 | if (ar.result == null) { |
| 504 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 505 | } else if (ar.exception instanceof CommandException) { |
| 506 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 507 | ar.exception); |
| 508 | } else { |
| 509 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 510 | } |
| 511 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 512 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 513 | break; |
| 514 | |
| 515 | case CMD_EXCHANGE_SIM_IO: |
| 516 | request = (MainThreadRequest) msg.obj; |
| 517 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 518 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 519 | if (uiccCard == null) { |
| 520 | loge("iccExchangeSimIO: No UICC"); |
| 521 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 522 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 523 | } else { |
| 524 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 525 | request); |
| 526 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 527 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 528 | iccArgument.data, onCompleted); |
| 529 | } |
| 530 | break; |
| 531 | |
| 532 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 533 | ar = (AsyncResult) msg.obj; |
| 534 | request = (MainThreadRequest) ar.userObj; |
| 535 | if (ar.exception == null && ar.result != null) { |
| 536 | request.result = ar.result; |
| 537 | } else { |
| 538 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 539 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 540 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 541 | break; |
| 542 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 543 | case CMD_SEND_ENVELOPE: |
| 544 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 545 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 546 | if (uiccCard == null) { |
| 547 | loge("sendEnvelopeWithStatus: No UICC"); |
| 548 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 549 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 550 | } else { |
| 551 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 552 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 553 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 554 | break; |
| 555 | |
| 556 | case EVENT_SEND_ENVELOPE_DONE: |
| 557 | ar = (AsyncResult) msg.obj; |
| 558 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 559 | if (ar.exception == null && ar.result != null) { |
| 560 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 561 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 562 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 563 | if (ar.result == null) { |
| 564 | loge("sendEnvelopeWithStatus: Empty response"); |
| 565 | } else if (ar.exception instanceof CommandException) { |
| 566 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 567 | ar.exception); |
| 568 | } else { |
| 569 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 570 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 571 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 572 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 573 | break; |
| 574 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 575 | case CMD_OPEN_CHANNEL: |
| 576 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 577 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 578 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 579 | if (uiccCard == null) { |
| 580 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 581 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 582 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 583 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 584 | } else { |
| 585 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 586 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 587 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 588 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 589 | break; |
| 590 | |
| 591 | case EVENT_OPEN_CHANNEL_DONE: |
| 592 | ar = (AsyncResult) msg.obj; |
| 593 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 594 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 595 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 596 | int[] result = (int[]) ar.result; |
| 597 | int channelId = result[0]; |
| 598 | byte[] selectResponse = null; |
| 599 | if (result.length > 1) { |
| 600 | selectResponse = new byte[result.length - 1]; |
| 601 | for (int i = 1; i < result.length; ++i) { |
| 602 | selectResponse[i - 1] = (byte) result[i]; |
| 603 | } |
| 604 | } |
| 605 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 606 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 607 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 608 | if (ar.result == null) { |
| 609 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 610 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 611 | if (ar.exception != null) { |
| 612 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 613 | } |
| 614 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 615 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 616 | if (ar.exception instanceof CommandException) { |
| 617 | CommandException.Error error = |
| 618 | ((CommandException) (ar.exception)).getCommandError(); |
| 619 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 620 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 621 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 622 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 626 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 627 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 628 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 630 | break; |
| 631 | |
| 632 | case CMD_CLOSE_CHANNEL: |
| 633 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 634 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 635 | if (uiccCard == null) { |
| 636 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 637 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 638 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 639 | } else { |
| 640 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 641 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 642 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 643 | break; |
| 644 | |
| 645 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 646 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 647 | break; |
| 648 | |
| 649 | case CMD_NV_READ_ITEM: |
| 650 | request = (MainThreadRequest) msg.obj; |
| 651 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 652 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 653 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 654 | break; |
| 655 | |
| 656 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | ar = (AsyncResult) msg.obj; |
| 658 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 659 | if (ar.exception == null && ar.result != null) { |
| 660 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 661 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 662 | request.result = ""; |
| 663 | if (ar.result == null) { |
| 664 | loge("nvReadItem: Empty response"); |
| 665 | } else if (ar.exception instanceof CommandException) { |
| 666 | loge("nvReadItem: CommandException: " + |
| 667 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 668 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 669 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 670 | } |
| 671 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 672 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 673 | break; |
| 674 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 675 | case CMD_NV_WRITE_ITEM: |
| 676 | request = (MainThreadRequest) msg.obj; |
| 677 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 678 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 679 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 680 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 681 | break; |
| 682 | |
| 683 | case EVENT_NV_WRITE_ITEM_DONE: |
| 684 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 685 | break; |
| 686 | |
| 687 | case CMD_NV_WRITE_CDMA_PRL: |
| 688 | request = (MainThreadRequest) msg.obj; |
| 689 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 690 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 691 | break; |
| 692 | |
| 693 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 694 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 695 | break; |
| 696 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 697 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 699 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 700 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 701 | break; |
| 702 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 703 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 704 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 705 | break; |
| 706 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 707 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 708 | request = (MainThreadRequest) msg.obj; |
| 709 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 710 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 711 | break; |
| 712 | |
| 713 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 714 | ar = (AsyncResult) msg.obj; |
| 715 | request = (MainThreadRequest) ar.userObj; |
| 716 | if (ar.exception == null && ar.result != null) { |
| 717 | request.result = ar.result; // Integer |
| 718 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 719 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 720 | if (ar.result == null) { |
| 721 | loge("getPreferredNetworkType: Empty response"); |
| 722 | } else if (ar.exception instanceof CommandException) { |
| 723 | loge("getPreferredNetworkType: CommandException: " + |
| 724 | ar.exception); |
| 725 | } else { |
| 726 | loge("getPreferredNetworkType: Unknown exception"); |
| 727 | } |
| 728 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 729 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 730 | break; |
| 731 | |
| 732 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 733 | request = (MainThreadRequest) msg.obj; |
| 734 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 735 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 736 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 737 | break; |
| 738 | |
| 739 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 740 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 741 | break; |
| 742 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 743 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 744 | request = (MainThreadRequest)msg.obj; |
| 745 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 746 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 747 | break; |
| 748 | |
| 749 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 750 | ar = (AsyncResult)msg.obj; |
| 751 | request = (MainThreadRequest)ar.userObj; |
| 752 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 753 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 754 | break; |
| 755 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 756 | case CMD_SET_VOICEMAIL_NUMBER: |
| 757 | request = (MainThreadRequest) msg.obj; |
| 758 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 759 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 760 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 761 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 762 | break; |
| 763 | |
| 764 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 765 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 766 | break; |
| 767 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 768 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 769 | request = (MainThreadRequest) msg.obj; |
| 770 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 771 | request); |
| 772 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 773 | break; |
| 774 | |
| 775 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 776 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 777 | break; |
| 778 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 779 | case CMD_PERFORM_NETWORK_SCAN: |
| 780 | request = (MainThreadRequest) msg.obj; |
| 781 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 782 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 783 | break; |
| 784 | |
| 785 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 786 | ar = (AsyncResult) msg.obj; |
| 787 | request = (MainThreadRequest) ar.userObj; |
| 788 | CellNetworkScanResult cellScanResult; |
| 789 | if (ar.exception == null && ar.result != null) { |
| 790 | cellScanResult = new CellNetworkScanResult( |
| 791 | CellNetworkScanResult.STATUS_SUCCESS, |
| 792 | (List<OperatorInfo>) ar.result); |
| 793 | } else { |
| 794 | if (ar.result == null) { |
| 795 | loge("getCellNetworkScanResults: Empty response"); |
| 796 | } |
| 797 | if (ar.exception != null) { |
| 798 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 799 | } |
| 800 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 801 | if (ar.exception instanceof CommandException) { |
| 802 | CommandException.Error error = |
| 803 | ((CommandException) (ar.exception)).getCommandError(); |
| 804 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 805 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 806 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 807 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 808 | } |
| 809 | } |
| 810 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 811 | } |
| 812 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 813 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 814 | break; |
| 815 | |
| 816 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 817 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 818 | ManualNetworkSelectionArgument selArg = |
| 819 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 820 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 821 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 822 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 823 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 824 | break; |
| 825 | |
| 826 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 827 | ar = (AsyncResult) msg.obj; |
| 828 | request = (MainThreadRequest) ar.userObj; |
| 829 | if (ar.exception == null) { |
| 830 | request.result = true; |
| 831 | } else { |
| 832 | request.result = false; |
| 833 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 834 | } |
| 835 | notifyRequester(request); |
| 836 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 837 | break; |
| 838 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 839 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 840 | request = (MainThreadRequest) msg.obj; |
| 841 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 842 | if (defaultPhone != null) { |
| 843 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 844 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 845 | break; |
| 846 | |
| 847 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 848 | ar = (AsyncResult) msg.obj; |
| 849 | request = (MainThreadRequest) ar.userObj; |
| 850 | if (ar.exception == null && ar.result != null) { |
| 851 | request.result = ar.result; |
| 852 | } else { |
| 853 | if (ar.result == null) { |
| 854 | loge("queryModemActivityInfo: Empty response"); |
| 855 | } else if (ar.exception instanceof CommandException) { |
| 856 | loge("queryModemActivityInfo: CommandException: " + |
| 857 | ar.exception); |
| 858 | } else { |
| 859 | loge("queryModemActivityInfo: Unknown exception"); |
| 860 | } |
| 861 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 862 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 863 | if (request.result == null) { |
| 864 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 865 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 866 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 867 | break; |
| 868 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 869 | case CMD_SET_ALLOWED_CARRIERS: |
| 870 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 871 | CarrierRestrictionRules argument = |
| 872 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 873 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 874 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 875 | break; |
| 876 | |
| 877 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 878 | ar = (AsyncResult) msg.obj; |
| 879 | request = (MainThreadRequest) ar.userObj; |
| 880 | if (ar.exception == null && ar.result != null) { |
| 881 | request.result = ar.result; |
| 882 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 883 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 884 | if (ar.exception instanceof CommandException) { |
| 885 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 886 | CommandException.Error error = |
| 887 | ((CommandException) (ar.exception)).getCommandError(); |
| 888 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 889 | request.result = |
| 890 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 891 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 892 | } else { |
| 893 | loge("setAllowedCarriers: Unknown exception"); |
| 894 | } |
| 895 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 896 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 897 | break; |
| 898 | |
| 899 | case CMD_GET_ALLOWED_CARRIERS: |
| 900 | request = (MainThreadRequest) msg.obj; |
| 901 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 902 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 903 | break; |
| 904 | |
| 905 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 906 | ar = (AsyncResult) msg.obj; |
| 907 | request = (MainThreadRequest) ar.userObj; |
| 908 | if (ar.exception == null && ar.result != null) { |
| 909 | request.result = ar.result; |
| 910 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 911 | request.result = new IllegalStateException( |
| 912 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 913 | if (ar.result == null) { |
| 914 | loge("getAllowedCarriers: Empty response"); |
| 915 | } else if (ar.exception instanceof CommandException) { |
| 916 | loge("getAllowedCarriers: CommandException: " + |
| 917 | ar.exception); |
| 918 | } else { |
| 919 | loge("getAllowedCarriers: Unknown exception"); |
| 920 | } |
| 921 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 922 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 923 | break; |
| 924 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 925 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 926 | ar = (AsyncResult) msg.obj; |
| 927 | request = (MainThreadRequest) ar.userObj; |
| 928 | if (ar.exception == null && ar.result != null) { |
| 929 | request.result = ar.result; |
| 930 | } else { |
| 931 | request.result = new IllegalArgumentException( |
| 932 | "Failed to retrieve Forbidden Plmns"); |
| 933 | if (ar.result == null) { |
| 934 | loge("getForbiddenPlmns: Empty response"); |
| 935 | } else { |
| 936 | loge("getForbiddenPlmns: Unknown exception"); |
| 937 | } |
| 938 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 939 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 940 | break; |
| 941 | |
| 942 | case CMD_GET_FORBIDDEN_PLMNS: |
| 943 | request = (MainThreadRequest) msg.obj; |
| 944 | uiccCard = getUiccCardFromRequest(request); |
| 945 | if (uiccCard == null) { |
| 946 | loge("getForbiddenPlmns() UiccCard is null"); |
| 947 | request.result = new IllegalArgumentException( |
| 948 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 949 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 950 | break; |
| 951 | } |
| 952 | Integer appType = (Integer) request.argument; |
| 953 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 954 | if (uiccApp == null) { |
| 955 | loge("getForbiddenPlmns() no app with specified type -- " |
| 956 | + appType); |
| 957 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 958 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 959 | break; |
| 960 | } else { |
| 961 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 962 | + " specified type -- " + appType); |
| 963 | } |
| 964 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 965 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 966 | onCompleted); |
| 967 | break; |
| 968 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 969 | case CMD_SWITCH_SLOTS: |
| 970 | request = (MainThreadRequest) msg.obj; |
| 971 | int[] physicalSlots = (int[]) request.argument; |
| 972 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 973 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 974 | break; |
| 975 | |
| 976 | case EVENT_SWITCH_SLOTS_DONE: |
| 977 | ar = (AsyncResult) msg.obj; |
| 978 | request = (MainThreadRequest) ar.userObj; |
| 979 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 980 | notifyRequester(request); |
| 981 | break; |
| 982 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 983 | request = (MainThreadRequest) msg.obj; |
| 984 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 985 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 986 | break; |
| 987 | |
| 988 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 989 | ar = (AsyncResult) msg.obj; |
| 990 | request = (MainThreadRequest) ar.userObj; |
| 991 | if (ar.exception != null) { |
| 992 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 993 | } else { |
| 994 | int mode = ((int[]) ar.result)[0]; |
| 995 | if (mode == 0) { |
| 996 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 997 | } else { |
| 998 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 999 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1000 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1001 | notifyRequester(request); |
| 1002 | break; |
| 1003 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1004 | request = (MainThreadRequest) msg.obj; |
| 1005 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1006 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1007 | break; |
| 1008 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1009 | ar = (AsyncResult) msg.obj; |
| 1010 | request = (MainThreadRequest) ar.userObj; |
| 1011 | if (ar.exception != null) { |
| 1012 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1013 | } else { |
| 1014 | request.result = ((int[]) ar.result)[0]; |
| 1015 | } |
| 1016 | notifyRequester(request); |
| 1017 | break; |
| 1018 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1019 | request = (MainThreadRequest) msg.obj; |
| 1020 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1021 | int mode = (int) request.argument; |
| 1022 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1023 | break; |
| 1024 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1025 | ar = (AsyncResult) msg.obj; |
| 1026 | request = (MainThreadRequest) ar.userObj; |
| 1027 | request.result = ar.exception == null; |
| 1028 | notifyRequester(request); |
| 1029 | break; |
| 1030 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1031 | request = (MainThreadRequest) msg.obj; |
| 1032 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1033 | int subscriptionMode = (int) request.argument; |
| 1034 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1035 | break; |
| 1036 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1037 | ar = (AsyncResult) msg.obj; |
| 1038 | request = (MainThreadRequest) ar.userObj; |
| 1039 | request.result = ar.exception == null; |
| 1040 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1041 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1042 | case CMD_GET_ALL_CELL_INFO: |
| 1043 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1044 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1045 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1046 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1047 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1048 | ar = (AsyncResult) msg.obj; |
| 1049 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1050 | // If a timeout occurs, the response will be null |
| 1051 | request.result = (ar.exception == null && ar.result != null) |
| 1052 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1053 | synchronized (request) { |
| 1054 | request.notifyAll(); |
| 1055 | } |
| 1056 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1057 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1058 | request = (MainThreadRequest) msg.obj; |
| 1059 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1060 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1061 | break; |
| 1062 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1063 | ar = (AsyncResult) msg.obj; |
| 1064 | request = (MainThreadRequest) ar.userObj; |
| 1065 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1066 | try { |
| 1067 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1068 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1069 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1070 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1071 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1072 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1073 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1074 | } else { |
| 1075 | // use the result as returned |
| 1076 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1077 | } |
| 1078 | } catch (RemoteException re) { |
| 1079 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1080 | } |
| 1081 | break; |
| 1082 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1083 | request = (MainThreadRequest) msg.obj; |
| 1084 | WorkSource ws = (WorkSource) request.argument; |
| 1085 | Phone phone = getPhoneFromRequest(request); |
| 1086 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1087 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1088 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1089 | ar = (AsyncResult) msg.obj; |
| 1090 | request = (MainThreadRequest) ar.userObj; |
| 1091 | if (ar.exception == null) { |
| 1092 | request.result = ar.result; |
| 1093 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1094 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1095 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1096 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1097 | } |
| 1098 | |
| 1099 | synchronized (request) { |
| 1100 | request.notifyAll(); |
| 1101 | } |
| 1102 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1103 | case CMD_MODEM_REBOOT: |
| 1104 | request = (MainThreadRequest) msg.obj; |
| 1105 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1106 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1107 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1108 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1109 | handleNullReturnEvent(msg, "rebootModem"); |
| 1110 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1111 | case CMD_REQUEST_ENABLE_MODEM: |
| 1112 | request = (MainThreadRequest) msg.obj; |
| 1113 | boolean enable = (boolean) request.argument; |
| 1114 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1115 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1116 | PhoneConfigurationManager.getInstance() |
| 1117 | .enablePhone(request.phone, enable, onCompleted); |
| 1118 | break; |
| 1119 | case EVENT_ENABLE_MODEM_DONE: |
| 1120 | ar = (AsyncResult) msg.obj; |
| 1121 | request = (MainThreadRequest) ar.userObj; |
| 1122 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1123 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1124 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1125 | if ((boolean) request.result) { |
| 1126 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1127 | updateModemStateMetrics(); |
| 1128 | } else { |
| 1129 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1130 | + ar.exception); |
| 1131 | } |
| 1132 | notifyRequester(request); |
| 1133 | break; |
| 1134 | case CMD_GET_MODEM_STATUS: |
| 1135 | request = (MainThreadRequest) msg.obj; |
| 1136 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1137 | PhoneConfigurationManager.getInstance() |
| 1138 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1139 | break; |
| 1140 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1141 | ar = (AsyncResult) msg.obj; |
| 1142 | request = (MainThreadRequest) ar.userObj; |
| 1143 | int id = request.phone.getPhoneId(); |
| 1144 | if (ar.exception == null && ar.result != null) { |
| 1145 | request.result = ar.result; |
| 1146 | //update the cache as modem status has changed |
| 1147 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1148 | (boolean) request.result); |
| 1149 | } else { |
| 1150 | // Return true if modem status cannot be retrieved. For most cases, |
| 1151 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1152 | // and disable modem are not supported. Modem is always on. |
| 1153 | // TODO: this should be fixed in R to support a third |
| 1154 | // status UNKNOWN b/131631629 |
| 1155 | request.result = true; |
| 1156 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1157 | + ar.exception); |
| 1158 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1159 | notifyRequester(request); |
| 1160 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1161 | default: |
| 1162 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1163 | break; |
| 1164 | } |
| 1165 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1166 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1167 | private void notifyRequester(MainThreadRequest request) { |
| 1168 | synchronized (request) { |
| 1169 | request.notifyAll(); |
| 1170 | } |
| 1171 | } |
| 1172 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1173 | private void handleNullReturnEvent(Message msg, String command) { |
| 1174 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1175 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1176 | if (ar.exception == null) { |
| 1177 | request.result = true; |
| 1178 | } else { |
| 1179 | request.result = false; |
| 1180 | if (ar.exception instanceof CommandException) { |
| 1181 | loge(command + ": CommandException: " + ar.exception); |
| 1182 | } else { |
| 1183 | loge(command + ": Unknown exception"); |
| 1184 | } |
| 1185 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1186 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1187 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | /** |
| 1191 | * Posts the specified command to be executed on the main thread, |
| 1192 | * waits for the request to complete, and returns the result. |
| 1193 | * @see #sendRequestAsync |
| 1194 | */ |
| 1195 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1196 | return sendRequest( |
| 1197 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | /** |
| 1201 | * Posts the specified command to be executed on the main thread, |
| 1202 | * waits for the request to complete, and returns the result. |
| 1203 | * @see #sendRequestAsync |
| 1204 | */ |
| 1205 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1206 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1207 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | /** |
| 1211 | * Posts the specified command to be executed on the main thread, |
| 1212 | * waits for the request to complete, and returns the result. |
| 1213 | * @see #sendRequestAsync |
| 1214 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1215 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1216 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | /** |
| 1220 | * Posts the specified command to be executed on the main thread, |
| 1221 | * waits for the request to complete, and returns the result. |
| 1222 | * @see #sendRequestAsync |
| 1223 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1224 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1225 | return sendRequest(command, argument, subId, null, workSource); |
| 1226 | } |
| 1227 | |
| 1228 | /** |
| 1229 | * Posts the specified command to be executed on the main thread, |
| 1230 | * waits for the request to complete, and returns the result. |
| 1231 | * @see #sendRequestAsync |
| 1232 | */ |
| 1233 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1234 | return sendRequest( |
| 1235 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1236 | } |
| 1237 | |
| 1238 | /** |
| 1239 | * Posts the specified command to be executed on the main thread, |
| 1240 | * waits for the request to complete, and returns the result. |
| 1241 | * @see #sendRequestAsync |
| 1242 | */ |
| 1243 | private Object sendRequest( |
| 1244 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1245 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1246 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1247 | } |
| 1248 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1249 | MainThreadRequest request = null; |
| 1250 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1251 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1252 | } else if (phone != null) { |
| 1253 | request = new MainThreadRequest(argument, phone, workSource); |
| 1254 | } else { |
| 1255 | request = new MainThreadRequest(argument, subId, workSource); |
| 1256 | } |
| 1257 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1258 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1259 | msg.sendToTarget(); |
| 1260 | |
| 1261 | // Wait for the request to complete |
| 1262 | synchronized (request) { |
| 1263 | while (request.result == null) { |
| 1264 | try { |
| 1265 | request.wait(); |
| 1266 | } catch (InterruptedException e) { |
| 1267 | // Do nothing, go back and wait until the request is complete |
| 1268 | } |
| 1269 | } |
| 1270 | } |
| 1271 | return request.result; |
| 1272 | } |
| 1273 | |
| 1274 | /** |
| 1275 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1276 | * Posts the specified command to be executed on the main thread, and |
| 1277 | * returns immediately. |
| 1278 | * @see #sendRequest |
| 1279 | */ |
| 1280 | private void sendRequestAsync(int command) { |
| 1281 | mMainThreadHandler.sendEmptyMessage(command); |
| 1282 | } |
| 1283 | |
| 1284 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1285 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1286 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1287 | */ |
| 1288 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1289 | sendRequestAsync(command, argument, null, null); |
| 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1294 | * @see {@link #sendRequest(int,Object)} |
| 1295 | */ |
| 1296 | private void sendRequestAsync( |
| 1297 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1298 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1299 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1300 | msg.sendToTarget(); |
| 1301 | } |
| 1302 | |
| 1303 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1304 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1305 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1306 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1307 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1308 | synchronized (PhoneInterfaceManager.class) { |
| 1309 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1310 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1311 | } else { |
| 1312 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1313 | } |
| 1314 | return sInstance; |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1319 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1320 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1321 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1322 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1323 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1324 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1325 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1326 | mTelephonySharedPreferences = |
| 1327 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1328 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1329 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1330 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1331 | publish(); |
| 1332 | } |
| 1333 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1334 | private Phone getDefaultPhone() { |
| 1335 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1336 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1337 | } |
| 1338 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1339 | private void publish() { |
| 1340 | if (DBG) log("publish: " + this); |
| 1341 | |
| 1342 | ServiceManager.addService("phone", this); |
| 1343 | } |
| 1344 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1345 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1346 | if (request.phone != null) { |
| 1347 | return request.phone; |
| 1348 | } else { |
| 1349 | return getPhoneFromSubId(request.subId); |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | private Phone getPhoneFromSubId(int subId) { |
| 1354 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1355 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1358 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1359 | Phone phone = getPhoneFromRequest(request); |
| 1360 | return phone == null ? null : |
| 1361 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1362 | } |
| 1363 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1364 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1365 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1366 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1367 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1368 | |
| 1369 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1370 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1373 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1374 | if (DBG) log("dial: " + number); |
| 1375 | // No permission check needed here: This is just a wrapper around the |
| 1376 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1377 | // the UI before it does anything. |
| 1378 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1379 | final long identity = Binder.clearCallingIdentity(); |
| 1380 | try { |
| 1381 | String url = createTelUrl(number); |
| 1382 | if (url == null) { |
| 1383 | return; |
| 1384 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1385 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1386 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1387 | PhoneConstants.State state = mCM.getState(subId); |
| 1388 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1389 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1390 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1391 | mApp.startActivity(intent); |
| 1392 | } |
| 1393 | } finally { |
| 1394 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1399 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1402 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1403 | if (DBG) log("call: " + number); |
| 1404 | |
| 1405 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1406 | // need to do a permission check since we're calling startActivity() |
| 1407 | // from the context of the phone app. |
| 1408 | enforceCallPermission(); |
| 1409 | |
| 1410 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1411 | != AppOpsManager.MODE_ALLOWED) { |
| 1412 | return; |
| 1413 | } |
| 1414 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1415 | final long identity = Binder.clearCallingIdentity(); |
| 1416 | try { |
| 1417 | String url = createTelUrl(number); |
| 1418 | if (url == null) { |
| 1419 | return; |
| 1420 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1421 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1422 | boolean isValid = false; |
| 1423 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1424 | if (slist != null) { |
| 1425 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1426 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1427 | isValid = true; |
| 1428 | break; |
| 1429 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1430 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1431 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1432 | if (!isValid) { |
| 1433 | return; |
| 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 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1437 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1438 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1439 | mApp.startActivity(intent); |
| 1440 | } finally { |
| 1441 | Binder.restoreCallingIdentity(identity); |
| 1442 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1445 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1446 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1449 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1450 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1451 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1452 | } |
| 1453 | |
| 1454 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1455 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1458 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1459 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1460 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1461 | } |
| 1462 | |
| 1463 | /** {@hide} */ |
| 1464 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1465 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1468 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1469 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1470 | |
| 1471 | final long identity = Binder.clearCallingIdentity(); |
| 1472 | try { |
| 1473 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1474 | checkSimPin.start(); |
| 1475 | return checkSimPin.unlockSim(null, pin); |
| 1476 | } finally { |
| 1477 | Binder.restoreCallingIdentity(identity); |
| 1478 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1481 | /** {@hide} */ |
| 1482 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1483 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1486 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1487 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1488 | |
| 1489 | final long identity = Binder.clearCallingIdentity(); |
| 1490 | try { |
| 1491 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1492 | checkSimPuk.start(); |
| 1493 | return checkSimPuk.unlockSim(puk, pin); |
| 1494 | } finally { |
| 1495 | Binder.restoreCallingIdentity(identity); |
| 1496 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1500 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1501 | * a synchronous one. |
| 1502 | */ |
| 1503 | private static class UnlockSim extends Thread { |
| 1504 | |
| 1505 | private final IccCard mSimCard; |
| 1506 | |
| 1507 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1508 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1509 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1510 | |
| 1511 | // For replies from SimCard interface |
| 1512 | private Handler mHandler; |
| 1513 | |
| 1514 | // For async handler to identify request type |
| 1515 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1516 | |
| 1517 | public UnlockSim(IccCard simCard) { |
| 1518 | mSimCard = simCard; |
| 1519 | } |
| 1520 | |
| 1521 | @Override |
| 1522 | public void run() { |
| 1523 | Looper.prepare(); |
| 1524 | synchronized (UnlockSim.this) { |
| 1525 | mHandler = new Handler() { |
| 1526 | @Override |
| 1527 | public void handleMessage(Message msg) { |
| 1528 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1529 | switch (msg.what) { |
| 1530 | case SUPPLY_PIN_COMPLETE: |
| 1531 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1532 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1533 | mRetryCount = msg.arg1; |
| 1534 | if (ar.exception != null) { |
| 1535 | if (ar.exception instanceof CommandException && |
| 1536 | ((CommandException)(ar.exception)).getCommandError() |
| 1537 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1538 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1539 | } else { |
| 1540 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1541 | } |
| 1542 | } else { |
| 1543 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1544 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1545 | mDone = true; |
| 1546 | UnlockSim.this.notifyAll(); |
| 1547 | } |
| 1548 | break; |
| 1549 | } |
| 1550 | } |
| 1551 | }; |
| 1552 | UnlockSim.this.notifyAll(); |
| 1553 | } |
| 1554 | Looper.loop(); |
| 1555 | } |
| 1556 | |
| 1557 | /* |
| 1558 | * Use PIN or PUK to unlock SIM card |
| 1559 | * |
| 1560 | * If PUK is null, unlock SIM card with PIN |
| 1561 | * |
| 1562 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1563 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1564 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1565 | |
| 1566 | while (mHandler == null) { |
| 1567 | try { |
| 1568 | wait(); |
| 1569 | } catch (InterruptedException e) { |
| 1570 | Thread.currentThread().interrupt(); |
| 1571 | } |
| 1572 | } |
| 1573 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1574 | |
| 1575 | if (puk == null) { |
| 1576 | mSimCard.supplyPin(pin, callback); |
| 1577 | } else { |
| 1578 | mSimCard.supplyPuk(puk, pin, callback); |
| 1579 | } |
| 1580 | |
| 1581 | while (!mDone) { |
| 1582 | try { |
| 1583 | Log.d(LOG_TAG, "wait for done"); |
| 1584 | wait(); |
| 1585 | } catch (InterruptedException e) { |
| 1586 | // Restore the interrupted status |
| 1587 | Thread.currentThread().interrupt(); |
| 1588 | } |
| 1589 | } |
| 1590 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1591 | int[] resultArray = new int[2]; |
| 1592 | resultArray[0] = mResult; |
| 1593 | resultArray[1] = mRetryCount; |
| 1594 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1595 | } |
| 1596 | } |
| 1597 | |
| 1598 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1599 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1600 | |
| 1601 | } |
| 1602 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1603 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1604 | // No permission check needed here: this call is harmless, and it's |
| 1605 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1606 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1607 | final long identity = Binder.clearCallingIdentity(); |
| 1608 | try { |
| 1609 | final Phone phone = getPhone(subId); |
| 1610 | if (phone != null) { |
| 1611 | phone.updateServiceLocation(); |
| 1612 | } |
| 1613 | } finally { |
| 1614 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1615 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1618 | @Override |
| 1619 | public boolean isRadioOn(String callingPackage) { |
| 1620 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1623 | @Override |
| 1624 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1625 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1626 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1627 | return false; |
| 1628 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1629 | |
| 1630 | final long identity = Binder.clearCallingIdentity(); |
| 1631 | try { |
| 1632 | return isRadioOnForSubscriber(subId); |
| 1633 | } finally { |
| 1634 | Binder.restoreCallingIdentity(identity); |
| 1635 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1639 | final long identity = Binder.clearCallingIdentity(); |
| 1640 | try { |
| 1641 | final Phone phone = getPhone(subId); |
| 1642 | if (phone != null) { |
| 1643 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1644 | } else { |
| 1645 | return false; |
| 1646 | } |
| 1647 | } finally { |
| 1648 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1649 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1653 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1654 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1655 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1656 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1657 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1658 | |
| 1659 | final long identity = Binder.clearCallingIdentity(); |
| 1660 | try { |
| 1661 | final Phone phone = getPhone(subId); |
| 1662 | if (phone != null) { |
| 1663 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1664 | } |
| 1665 | } finally { |
| 1666 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1667 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1671 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1674 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1675 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1676 | |
| 1677 | final long identity = Binder.clearCallingIdentity(); |
| 1678 | try { |
| 1679 | final Phone phone = getPhone(subId); |
| 1680 | if (phone == null) { |
| 1681 | return false; |
| 1682 | } |
| 1683 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1684 | toggleRadioOnOffForSubscriber(subId); |
| 1685 | } |
| 1686 | return true; |
| 1687 | } finally { |
| 1688 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1689 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1690 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1691 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1692 | public boolean needMobileRadioShutdown() { |
| 1693 | /* |
| 1694 | * If any of the Radios are available, it will need to be |
| 1695 | * shutdown. So return true if any Radio is available. |
| 1696 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1697 | final long identity = Binder.clearCallingIdentity(); |
| 1698 | try { |
| 1699 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1700 | Phone phone = PhoneFactory.getPhone(i); |
| 1701 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1702 | } |
| 1703 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1704 | return false; |
| 1705 | } finally { |
| 1706 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1707 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1710 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1711 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1712 | enforceModifyPermission(); |
| 1713 | |
| 1714 | final long identity = Binder.clearCallingIdentity(); |
| 1715 | try { |
| 1716 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1717 | logv("Shutting down Phone " + i); |
| 1718 | shutdownRadioUsingPhoneId(i); |
| 1719 | } |
| 1720 | } finally { |
| 1721 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1726 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1727 | if (phone != null && phone.isRadioAvailable()) { |
| 1728 | phone.shutdownRadio(); |
| 1729 | } |
| 1730 | } |
| 1731 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1732 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1733 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1734 | |
| 1735 | final long identity = Binder.clearCallingIdentity(); |
| 1736 | try { |
| 1737 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1738 | if (defaultPhone != null) { |
| 1739 | defaultPhone.setRadioPower(turnOn); |
| 1740 | return true; |
| 1741 | } else { |
| 1742 | loge("There's no default phone."); |
| 1743 | return false; |
| 1744 | } |
| 1745 | } finally { |
| 1746 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1747 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1750 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1751 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1752 | |
| 1753 | final long identity = Binder.clearCallingIdentity(); |
| 1754 | try { |
| 1755 | final Phone phone = getPhone(subId); |
| 1756 | if (phone != null) { |
| 1757 | phone.setRadioPower(turnOn); |
| 1758 | return true; |
| 1759 | } else { |
| 1760 | return false; |
| 1761 | } |
| 1762 | } finally { |
| 1763 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1764 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1767 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1768 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1769 | public boolean enableDataConnectivity() { |
| 1770 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1771 | |
| 1772 | final long identity = Binder.clearCallingIdentity(); |
| 1773 | try { |
| 1774 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1775 | final Phone phone = getPhone(subId); |
| 1776 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1777 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1778 | return true; |
| 1779 | } else { |
| 1780 | return false; |
| 1781 | } |
| 1782 | } finally { |
| 1783 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1784 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1787 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1788 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1789 | public boolean disableDataConnectivity() { |
| 1790 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1791 | |
| 1792 | final long identity = Binder.clearCallingIdentity(); |
| 1793 | try { |
| 1794 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1795 | final Phone phone = getPhone(subId); |
| 1796 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1797 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1798 | return true; |
| 1799 | } else { |
| 1800 | return false; |
| 1801 | } |
| 1802 | } finally { |
| 1803 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1804 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1807 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1808 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1809 | final long identity = Binder.clearCallingIdentity(); |
| 1810 | try { |
| 1811 | final Phone phone = getPhone(subId); |
| 1812 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1813 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1814 | } else { |
| 1815 | return false; |
| 1816 | } |
| 1817 | } finally { |
| 1818 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1819 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1823 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1826 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1827 | enforceCallPermission(); |
| 1828 | |
| 1829 | final long identity = Binder.clearCallingIdentity(); |
| 1830 | try { |
| 1831 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1832 | return; |
| 1833 | } |
| 1834 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1835 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1836 | } finally { |
| 1837 | Binder.restoreCallingIdentity(identity); |
| 1838 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1839 | }; |
| 1840 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1841 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1842 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1843 | |
| 1844 | final long identity = Binder.clearCallingIdentity(); |
| 1845 | try { |
| 1846 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1847 | return false; |
| 1848 | } |
| 1849 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1850 | } finally { |
| 1851 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1852 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1855 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1856 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1859 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1860 | final long identity = Binder.clearCallingIdentity(); |
| 1861 | try { |
| 1862 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1863 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1864 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1865 | } finally { |
| 1866 | Binder.restoreCallingIdentity(identity); |
| 1867 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1870 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1871 | public int getDataState() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1872 | final long identity = Binder.clearCallingIdentity(); |
| 1873 | try { |
| 1874 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1875 | if (phone != null) { |
| 1876 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1877 | } else { |
| 1878 | return PhoneConstantConversions.convertDataState( |
| 1879 | PhoneConstants.DataState.DISCONNECTED); |
| 1880 | } |
| 1881 | } finally { |
| 1882 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1883 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1886 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1887 | public int getDataActivity() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1888 | final long identity = Binder.clearCallingIdentity(); |
| 1889 | try { |
| 1890 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1891 | if (phone != null) { |
| 1892 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1893 | } else { |
| 1894 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1895 | } |
| 1896 | } finally { |
| 1897 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1898 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1902 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1903 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1904 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1905 | |
| 1906 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1907 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1908 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1909 | .setCallingPackage(callingPackage) |
| 1910 | .setCallingPid(Binder.getCallingPid()) |
| 1911 | .setCallingUid(Binder.getCallingUid()) |
| 1912 | .setMethod("getCellLocation") |
| 1913 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1914 | .build()); |
| 1915 | switch (locationResult) { |
| 1916 | case DENIED_HARD: |
| 1917 | throw new SecurityException("Not allowed to access cell location"); |
| 1918 | case DENIED_SOFT: |
| 1919 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1920 | } |
| 1921 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1922 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1923 | final long identity = Binder.clearCallingIdentity(); |
| 1924 | try { |
| 1925 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1926 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1927 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1928 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1929 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1930 | return data; |
| 1931 | } finally { |
| 1932 | Binder.restoreCallingIdentity(identity); |
| 1933 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1936 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1937 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1938 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1939 | // registered cell info, so return a NULL country instead. |
| 1940 | final long identity = Binder.clearCallingIdentity(); |
| 1941 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1942 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1943 | // Get default phone in this case. |
| 1944 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1945 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1946 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1947 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1948 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1949 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1950 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1951 | return ""; |
| 1952 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1953 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1954 | if (phone != null) { |
| 1955 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1956 | if (sst != null) { |
| 1957 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1958 | if (lt != null) { |
| 1959 | return lt.getCurrentCountry(); |
| 1960 | } |
| 1961 | } |
| 1962 | } |
| 1963 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1964 | } finally { |
| 1965 | Binder.restoreCallingIdentity(identity); |
| 1966 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1970 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1971 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1974 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1975 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1976 | mApp.enforceCallingOrSelfPermission( |
| 1977 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1978 | |
| 1979 | final long identity = Binder.clearCallingIdentity(); |
| 1980 | try { |
| 1981 | final Phone phone = getPhone(subId); |
| 1982 | if (phone != null) { |
| 1983 | phone.enableLocationUpdates(); |
| 1984 | } |
| 1985 | } finally { |
| 1986 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1987 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | @Override |
| 1991 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1992 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1995 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1996 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1997 | mApp.enforceCallingOrSelfPermission( |
| 1998 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1999 | |
| 2000 | final long identity = Binder.clearCallingIdentity(); |
| 2001 | try { |
| 2002 | final Phone phone = getPhone(subId); |
| 2003 | if (phone != null) { |
| 2004 | phone.disableLocationUpdates(); |
| 2005 | } |
| 2006 | } finally { |
| 2007 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2008 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2011 | /** |
| 2012 | * Returns the target SDK version number for a given package name. |
| 2013 | * |
| 2014 | * @return target SDK if the package is found or INT_MAX. |
| 2015 | */ |
| 2016 | private int getTargetSdk(String packageName) { |
| 2017 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2018 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 2019 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2020 | if (ai != null) return ai.targetSdkVersion; |
| 2021 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 2022 | } |
| 2023 | return Integer.MAX_VALUE; |
| 2024 | } |
| 2025 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2026 | @Override |
| 2027 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2028 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2029 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2030 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2031 | throw new SecurityException( |
| 2032 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2033 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2034 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2035 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 2036 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2037 | return null; |
| 2038 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2039 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2040 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2041 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2042 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2043 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2044 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2045 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2046 | for (CellInfo ci : info) { |
| 2047 | if (ci instanceof CellInfoGsm) { |
| 2048 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2049 | } else if (ci instanceof CellInfoWcdma) { |
| 2050 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2051 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2052 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2053 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2054 | } |
| 2055 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2056 | private List<CellInfo> getCachedCellInfo() { |
| 2057 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2058 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2059 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2060 | if (info != null) cellInfos.addAll(info); |
| 2061 | } |
| 2062 | return cellInfos; |
| 2063 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2064 | |
| 2065 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2066 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2067 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2068 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2069 | |
| 2070 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2071 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2072 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2073 | .setCallingPackage(callingPackage) |
| 2074 | .setCallingPid(Binder.getCallingPid()) |
| 2075 | .setCallingUid(Binder.getCallingUid()) |
| 2076 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2077 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2078 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2079 | .build()); |
| 2080 | switch (locationResult) { |
| 2081 | case DENIED_HARD: |
| 2082 | throw new SecurityException("Not allowed to access cell info"); |
| 2083 | case DENIED_SOFT: |
| 2084 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2087 | final int targetSdk = getTargetSdk(callingPackage); |
| 2088 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2089 | return getCachedCellInfo(); |
| 2090 | } |
| 2091 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2092 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2093 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2094 | final long identity = Binder.clearCallingIdentity(); |
| 2095 | try { |
| 2096 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2097 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2098 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2099 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2100 | if (info != null) cellInfos.addAll(info); |
| 2101 | } |
| 2102 | return cellInfos; |
| 2103 | } finally { |
| 2104 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2105 | } |
| 2106 | } |
| 2107 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2108 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2109 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2110 | requestCellInfoUpdateInternal( |
| 2111 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2112 | } |
| 2113 | |
| 2114 | @Override |
| 2115 | public void requestCellInfoUpdateWithWorkSource( |
| 2116 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2117 | enforceModifyPermission(); |
| 2118 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2119 | } |
| 2120 | |
| 2121 | private void requestCellInfoUpdateInternal( |
| 2122 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2123 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2124 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2125 | |
| 2126 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2127 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2128 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2129 | .setCallingPackage(callingPackage) |
| 2130 | .setCallingPid(Binder.getCallingPid()) |
| 2131 | .setCallingUid(Binder.getCallingUid()) |
| 2132 | .setMethod("requestCellInfoUpdate") |
| 2133 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2134 | .build()); |
| 2135 | switch (locationResult) { |
| 2136 | case DENIED_HARD: |
| 2137 | throw new SecurityException("Not allowed to access cell info"); |
| 2138 | case DENIED_SOFT: |
| 2139 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | final Phone phone = getPhone(subId); |
| 2143 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2144 | |
| 2145 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2146 | } |
| 2147 | |
| 2148 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2149 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2150 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2151 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2152 | |
| 2153 | final long identity = Binder.clearCallingIdentity(); |
| 2154 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2155 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2156 | } finally { |
| 2157 | Binder.restoreCallingIdentity(identity); |
| 2158 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2161 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2162 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2163 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2164 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2165 | return null; |
| 2166 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2167 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2168 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2169 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2170 | return null; |
| 2171 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2172 | |
| 2173 | final long identity = Binder.clearCallingIdentity(); |
| 2174 | try { |
| 2175 | return phone.getImei(); |
| 2176 | } finally { |
| 2177 | Binder.restoreCallingIdentity(identity); |
| 2178 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2182 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2183 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2184 | String tac = null; |
| 2185 | if (phone != null) { |
| 2186 | String imei = phone.getImei(); |
| 2187 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2188 | } |
| 2189 | return tac; |
| 2190 | } |
| 2191 | |
| 2192 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2193 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2194 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2195 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2196 | return null; |
| 2197 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2198 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2199 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2200 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2201 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2202 | return null; |
| 2203 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2204 | |
| 2205 | final long identity = Binder.clearCallingIdentity(); |
| 2206 | try { |
| 2207 | return phone.getMeid(); |
| 2208 | } finally { |
| 2209 | Binder.restoreCallingIdentity(identity); |
| 2210 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2214 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2215 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2216 | String manufacturerCode = null; |
| 2217 | if (phone != null) { |
| 2218 | String meid = phone.getMeid(); |
| 2219 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2220 | } |
| 2221 | return manufacturerCode; |
| 2222 | } |
| 2223 | |
| 2224 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2225 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2226 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2227 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2228 | return null; |
| 2229 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2230 | int subId = phone.getSubId(); |
| 2231 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2232 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2233 | return null; |
| 2234 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2235 | |
| 2236 | final long identity = Binder.clearCallingIdentity(); |
| 2237 | try { |
| 2238 | return phone.getDeviceSvn(); |
| 2239 | } finally { |
| 2240 | Binder.restoreCallingIdentity(identity); |
| 2241 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2242 | } |
| 2243 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2244 | @Override |
| 2245 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2246 | final long identity = Binder.clearCallingIdentity(); |
| 2247 | try { |
| 2248 | final Phone phone = getPhone(subId); |
| 2249 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2250 | } finally { |
| 2251 | Binder.restoreCallingIdentity(identity); |
| 2252 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | @Override |
| 2256 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2257 | final long identity = Binder.clearCallingIdentity(); |
| 2258 | try { |
| 2259 | final Phone phone = getPhone(subId); |
| 2260 | return phone == null ? null : phone.getCarrierName(); |
| 2261 | } finally { |
| 2262 | Binder.restoreCallingIdentity(identity); |
| 2263 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2264 | } |
| 2265 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2266 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2267 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2268 | final long identity = Binder.clearCallingIdentity(); |
| 2269 | try { |
| 2270 | final Phone phone = getPhone(subId); |
| 2271 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2272 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2273 | } finally { |
| 2274 | Binder.restoreCallingIdentity(identity); |
| 2275 | } |
| 2276 | } |
| 2277 | |
| 2278 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2279 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2280 | final long identity = Binder.clearCallingIdentity(); |
| 2281 | try { |
| 2282 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2283 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2284 | } finally { |
| 2285 | Binder.restoreCallingIdentity(identity); |
| 2286 | } |
| 2287 | } |
| 2288 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2289 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2290 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2291 | if (!isSubscriptionMccMnc) { |
| 2292 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2293 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2294 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2295 | if (phone == null) { |
| 2296 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2297 | } |
| 2298 | final long identity = Binder.clearCallingIdentity(); |
| 2299 | try { |
| 2300 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2301 | } finally { |
| 2302 | Binder.restoreCallingIdentity(identity); |
| 2303 | } |
| 2304 | } |
| 2305 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2306 | // |
| 2307 | // Internal helper methods. |
| 2308 | // |
| 2309 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2310 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2311 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2312 | * |
| 2313 | * @throws SecurityException if the caller does not have the required permission |
| 2314 | */ |
| 2315 | private void enforceModifyPermission() { |
| 2316 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2317 | } |
| 2318 | |
| 2319 | /** |
| 2320 | * Make sure the caller has the CALL_PHONE permission. |
| 2321 | * |
| 2322 | * @throws SecurityException if the caller does not have the required permission |
| 2323 | */ |
| 2324 | private void enforceCallPermission() { |
| 2325 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2326 | } |
| 2327 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2328 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2329 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2330 | "ConnectivityService"); |
| 2331 | } |
| 2332 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2333 | private String createTelUrl(String number) { |
| 2334 | if (TextUtils.isEmpty(number)) { |
| 2335 | return null; |
| 2336 | } |
| 2337 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2338 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2341 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2342 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2343 | } |
| 2344 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2345 | private static void logv(String msg) { |
| 2346 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2347 | } |
| 2348 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2349 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2350 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2351 | } |
| 2352 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2353 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2354 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2355 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2356 | } |
| 2357 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2358 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2359 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2360 | final long identity = Binder.clearCallingIdentity(); |
| 2361 | try { |
| 2362 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2363 | if (phone == null) { |
| 2364 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2365 | } else { |
| 2366 | return phone.getPhoneType(); |
| 2367 | } |
| 2368 | } finally { |
| 2369 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2370 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | /** |
| 2374 | * Returns the CDMA ERI icon index to display |
| 2375 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2376 | @Override |
| 2377 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2378 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2379 | } |
| 2380 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2381 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2382 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2383 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2384 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2385 | return -1; |
| 2386 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2387 | |
| 2388 | final long identity = Binder.clearCallingIdentity(); |
| 2389 | try { |
| 2390 | final Phone phone = getPhone(subId); |
| 2391 | if (phone != null) { |
| 2392 | return phone.getCdmaEriIconIndex(); |
| 2393 | } else { |
| 2394 | return -1; |
| 2395 | } |
| 2396 | } finally { |
| 2397 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2398 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | /** |
| 2402 | * Returns the CDMA ERI icon mode, |
| 2403 | * 0 - ON |
| 2404 | * 1 - FLASHING |
| 2405 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2406 | @Override |
| 2407 | public int getCdmaEriIconMode(String callingPackage) { |
| 2408 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2409 | } |
| 2410 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2411 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2412 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2413 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2414 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2415 | return -1; |
| 2416 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2417 | |
| 2418 | final long identity = Binder.clearCallingIdentity(); |
| 2419 | try { |
| 2420 | final Phone phone = getPhone(subId); |
| 2421 | if (phone != null) { |
| 2422 | return phone.getCdmaEriIconMode(); |
| 2423 | } else { |
| 2424 | return -1; |
| 2425 | } |
| 2426 | } finally { |
| 2427 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2428 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
| 2431 | /** |
| 2432 | * Returns the CDMA ERI text, |
| 2433 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2434 | @Override |
| 2435 | public String getCdmaEriText(String callingPackage) { |
| 2436 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2439 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2440 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2441 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2442 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2443 | return null; |
| 2444 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2445 | |
| 2446 | final long identity = Binder.clearCallingIdentity(); |
| 2447 | try { |
| 2448 | final Phone phone = getPhone(subId); |
| 2449 | if (phone != null) { |
| 2450 | return phone.getCdmaEriText(); |
| 2451 | } else { |
| 2452 | return null; |
| 2453 | } |
| 2454 | } finally { |
| 2455 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2456 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2460 | * Returns the CDMA MDN. |
| 2461 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2462 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2463 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2464 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2465 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2466 | |
| 2467 | final long identity = Binder.clearCallingIdentity(); |
| 2468 | try { |
| 2469 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2470 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2471 | return phone.getLine1Number(); |
| 2472 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2473 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2474 | return null; |
| 2475 | } |
| 2476 | } finally { |
| 2477 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | /** |
| 2482 | * Returns the CDMA MIN. |
| 2483 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2484 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2485 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2486 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2487 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2488 | |
| 2489 | final long identity = Binder.clearCallingIdentity(); |
| 2490 | try { |
| 2491 | final Phone phone = getPhone(subId); |
| 2492 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2493 | return phone.getCdmaMin(); |
| 2494 | } else { |
| 2495 | return null; |
| 2496 | } |
| 2497 | } finally { |
| 2498 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2499 | } |
| 2500 | } |
| 2501 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2502 | @Override |
| 2503 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2504 | INumberVerificationCallback callback, String callingPackage) { |
| 2505 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2506 | != PERMISSION_GRANTED) { |
| 2507 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2508 | } |
| 2509 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2510 | |
| 2511 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2512 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2513 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2514 | } |
| 2515 | |
| 2516 | if (range == null) { |
| 2517 | throw new NullPointerException("Range must be non-null"); |
| 2518 | } |
| 2519 | |
| 2520 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2521 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2522 | |
| 2523 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2524 | } |
| 2525 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2526 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2527 | * Returns true if CDMA provisioning needs to run. |
| 2528 | */ |
| 2529 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2530 | final long identity = Binder.clearCallingIdentity(); |
| 2531 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2532 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2533 | } finally { |
| 2534 | Binder.restoreCallingIdentity(identity); |
| 2535 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2539 | * Sets the voice mail number of a given subId. |
| 2540 | */ |
| 2541 | @Override |
| 2542 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2543 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2544 | |
| 2545 | final long identity = Binder.clearCallingIdentity(); |
| 2546 | try { |
| 2547 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2548 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2549 | return success; |
| 2550 | } finally { |
| 2551 | Binder.restoreCallingIdentity(identity); |
| 2552 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2553 | } |
| 2554 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2555 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2556 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2557 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2558 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2559 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2560 | throw new SecurityException("caller must be system dialer"); |
| 2561 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2562 | |
| 2563 | final long identity = Binder.clearCallingIdentity(); |
| 2564 | try { |
| 2565 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2566 | if (phoneAccountHandle == null) { |
| 2567 | return null; |
| 2568 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2569 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2570 | } finally { |
| 2571 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2572 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2576 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2577 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2578 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2579 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2580 | return null; |
| 2581 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2582 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2583 | final long identity = Binder.clearCallingIdentity(); |
| 2584 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2585 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2586 | } finally { |
| 2587 | Binder.restoreCallingIdentity(identity); |
| 2588 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2592 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2593 | VisualVoicemailSmsFilterSettings settings) { |
| 2594 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2595 | |
| 2596 | final long identity = Binder.clearCallingIdentity(); |
| 2597 | try { |
| 2598 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2599 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2600 | } finally { |
| 2601 | Binder.restoreCallingIdentity(identity); |
| 2602 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2606 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2607 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2608 | |
| 2609 | final long identity = Binder.clearCallingIdentity(); |
| 2610 | try { |
| 2611 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2612 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2613 | } finally { |
| 2614 | Binder.restoreCallingIdentity(identity); |
| 2615 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2619 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2620 | String callingPackage, int subId) { |
| 2621 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2622 | |
| 2623 | final long identity = Binder.clearCallingIdentity(); |
| 2624 | try { |
| 2625 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2626 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2627 | } finally { |
| 2628 | Binder.restoreCallingIdentity(identity); |
| 2629 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2633 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2634 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2635 | |
| 2636 | final long identity = Binder.clearCallingIdentity(); |
| 2637 | try { |
| 2638 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2639 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2640 | } finally { |
| 2641 | Binder.restoreCallingIdentity(identity); |
| 2642 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | @Override |
| 2646 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2647 | String number, int port, String text, PendingIntent sentIntent) { |
| 2648 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2649 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2650 | enforceSendSmsPermission(); |
| 2651 | // Make the calls as the phone process. |
| 2652 | final long identity = Binder.clearCallingIdentity(); |
| 2653 | try { |
| 2654 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2655 | if (port == 0) { |
| 2656 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2657 | sentIntent, null, false); |
| 2658 | } else { |
| 2659 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2660 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2661 | (short) port, data, sentIntent, null); |
| 2662 | } |
| 2663 | } finally { |
| 2664 | Binder.restoreCallingIdentity(identity); |
| 2665 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2666 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2667 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2668 | * Sets the voice activation state of a given subId. |
| 2669 | */ |
| 2670 | @Override |
| 2671 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2672 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2673 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2674 | |
| 2675 | final long identity = Binder.clearCallingIdentity(); |
| 2676 | try { |
| 2677 | final Phone phone = getPhone(subId); |
| 2678 | if (phone != null) { |
| 2679 | phone.setVoiceActivationState(activationState); |
| 2680 | } else { |
| 2681 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2682 | } |
| 2683 | } finally { |
| 2684 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | /** |
| 2689 | * Sets the data activation state of a given subId. |
| 2690 | */ |
| 2691 | @Override |
| 2692 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2693 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2694 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2695 | |
| 2696 | final long identity = Binder.clearCallingIdentity(); |
| 2697 | try { |
| 2698 | final Phone phone = getPhone(subId); |
| 2699 | if (phone != null) { |
| 2700 | phone.setDataActivationState(activationState); |
| 2701 | } else { |
| 2702 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2703 | } |
| 2704 | } finally { |
| 2705 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | /** |
| 2710 | * Returns the voice activation state of a given subId. |
| 2711 | */ |
| 2712 | @Override |
| 2713 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2714 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2715 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2716 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2717 | final long identity = Binder.clearCallingIdentity(); |
| 2718 | try { |
| 2719 | if (phone != null) { |
| 2720 | return phone.getVoiceActivationState(); |
| 2721 | } else { |
| 2722 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2723 | } |
| 2724 | } finally { |
| 2725 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2726 | } |
| 2727 | } |
| 2728 | |
| 2729 | /** |
| 2730 | * Returns the data activation state of a given subId. |
| 2731 | */ |
| 2732 | @Override |
| 2733 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2734 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2735 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2736 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2737 | final long identity = Binder.clearCallingIdentity(); |
| 2738 | try { |
| 2739 | if (phone != null) { |
| 2740 | return phone.getDataActivationState(); |
| 2741 | } else { |
| 2742 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2743 | } |
| 2744 | } finally { |
| 2745 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2746 | } |
| 2747 | } |
| 2748 | |
| 2749 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2750 | * Returns the unread count of voicemails for a subId |
| 2751 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2752 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2753 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2754 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2755 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2756 | return 0; |
| 2757 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2758 | final long identity = Binder.clearCallingIdentity(); |
| 2759 | try { |
| 2760 | final Phone phone = getPhone(subId); |
| 2761 | if (phone != null) { |
| 2762 | return phone.getVoiceMessageCount(); |
| 2763 | } else { |
| 2764 | return 0; |
| 2765 | } |
| 2766 | } finally { |
| 2767 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2768 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2772 | * returns true, if the device is in a state where both voice and data |
| 2773 | * are supported simultaneously. This can change based on location or network condition. |
| 2774 | */ |
| 2775 | @Override |
| 2776 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2777 | final long identity = Binder.clearCallingIdentity(); |
| 2778 | try { |
| 2779 | final Phone phone = getPhone(subId); |
| 2780 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2781 | } finally { |
| 2782 | Binder.restoreCallingIdentity(identity); |
| 2783 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2787 | * Send the dialer code if called from the current default dialer or the caller has |
| 2788 | * carrier privilege. |
| 2789 | * @param inputCode The dialer code to send |
| 2790 | */ |
| 2791 | @Override |
| 2792 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2793 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2794 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2795 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2796 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2797 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2798 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2799 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2800 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2801 | |
| 2802 | final long identity = Binder.clearCallingIdentity(); |
| 2803 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2804 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2805 | } finally { |
| 2806 | Binder.restoreCallingIdentity(identity); |
| 2807 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2811 | * Returns the data network type. |
| 2812 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2813 | * |
| 2814 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2815 | */ |
| 2816 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2817 | public int getNetworkType() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2818 | final long identity = Binder.clearCallingIdentity(); |
| 2819 | try { |
| 2820 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2821 | if (phone != null) { |
| 2822 | return phone.getServiceState().getDataNetworkType(); |
| 2823 | } else { |
| 2824 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2825 | } |
| 2826 | } finally { |
| 2827 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2828 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2829 | } |
| 2830 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2831 | @Override |
| 2832 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2833 | if (!isActiveSubscription(subId)) { |
| 2834 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2835 | } |
| 2836 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2837 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2838 | } |
| 2839 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2840 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2841 | public boolean isInEmergencySmsMode() { |
| 2842 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2843 | final long identity = Binder.clearCallingIdentity(); |
| 2844 | try { |
| 2845 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2846 | if (phone.isInEmergencySmsMode()) { |
| 2847 | return true; |
| 2848 | } |
| 2849 | } |
| 2850 | } finally { |
| 2851 | Binder.restoreCallingIdentity(identity); |
| 2852 | } |
| 2853 | return false; |
| 2854 | } |
| 2855 | |
| 2856 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2857 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2858 | throws RemoteException { |
| 2859 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2860 | final long token = Binder.clearCallingIdentity(); |
| 2861 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2862 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2863 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2864 | .addRegistrationCallbackForSubscription(c, subId); |
| 2865 | } finally { |
| 2866 | Binder.restoreCallingIdentity(token); |
| 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2871 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2872 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2873 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2874 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2875 | } |
| 2876 | Binder.withCleanCallingIdentity(() -> { |
| 2877 | try { |
| 2878 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2879 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2880 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2881 | } catch (IllegalArgumentException e) { |
| 2882 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2883 | + "is inactive, ignoring unregister."); |
| 2884 | // If the subscription is no longer active, just return, since the callback |
| 2885 | // will already have been removed internally. |
| 2886 | } |
| 2887 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2891 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2892 | throws RemoteException { |
| 2893 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2894 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2895 | final long token = Binder.clearCallingIdentity(); |
| 2896 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2897 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2898 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2899 | } finally { |
| 2900 | Binder.restoreCallingIdentity(token); |
| 2901 | } |
| 2902 | } |
| 2903 | |
| 2904 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2905 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2906 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2907 | |
| 2908 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2909 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2910 | } |
| 2911 | Binder.withCleanCallingIdentity(() -> { |
| 2912 | try { |
| 2913 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2914 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2915 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2916 | } catch (IllegalArgumentException e) { |
| 2917 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2918 | + "is inactive, ignoring unregister."); |
| 2919 | // If the subscription is no longer active, just return, since the callback |
| 2920 | // will already have been removed internally. |
| 2921 | } |
| 2922 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2926 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2927 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2928 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2929 | final long token = Binder.clearCallingIdentity(); |
| 2930 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2931 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2932 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2933 | } catch (ImsException e) { |
| 2934 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2935 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2936 | } catch (IllegalArgumentException e) { |
| 2937 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2938 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2939 | } finally { |
| 2940 | Binder.restoreCallingIdentity(token); |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2945 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2946 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2947 | final long token = Binder.clearCallingIdentity(); |
| 2948 | try { |
| 2949 | Phone phone = getPhone(subId); |
| 2950 | if (phone == null) return false; |
| 2951 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2952 | } finally { |
| 2953 | Binder.restoreCallingIdentity(token); |
| 2954 | } |
| 2955 | } |
| 2956 | |
| 2957 | @Override |
| 2958 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2959 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2960 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2961 | final long token = Binder.clearCallingIdentity(); |
| 2962 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2963 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2964 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2965 | } finally { |
| 2966 | Binder.restoreCallingIdentity(token); |
| 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2971 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2972 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2973 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2974 | final long identity = Binder.clearCallingIdentity(); |
| 2975 | try { |
| 2976 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2977 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2978 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2979 | } finally { |
| 2980 | Binder.restoreCallingIdentity(identity); |
| 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2985 | public boolean isVtSettingEnabled(int subId) { |
| 2986 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2987 | final long identity = Binder.clearCallingIdentity(); |
| 2988 | try { |
| 2989 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2990 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2991 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2992 | } finally { |
| 2993 | Binder.restoreCallingIdentity(identity); |
| 2994 | } |
| 2995 | } |
| 2996 | |
| 2997 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2998 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3000 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3001 | final long identity = Binder.clearCallingIdentity(); |
| 3002 | try { |
| 3003 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3004 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3005 | } finally { |
| 3006 | Binder.restoreCallingIdentity(identity); |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | @Override |
| 3011 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3012 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3013 | final long identity = Binder.clearCallingIdentity(); |
| 3014 | try { |
| 3015 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3016 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3017 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 3018 | } finally { |
| 3019 | Binder.restoreCallingIdentity(identity); |
| 3020 | } |
| 3021 | } |
| 3022 | |
| 3023 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3024 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3025 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3026 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3027 | final long identity = Binder.clearCallingIdentity(); |
| 3028 | try { |
| 3029 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3030 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3031 | } finally { |
| 3032 | Binder.restoreCallingIdentity(identity); |
| 3033 | } |
| 3034 | } |
| 3035 | |
| 3036 | @Override |
| 3037 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3038 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3039 | final long identity = Binder.clearCallingIdentity(); |
| 3040 | try { |
| 3041 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3042 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3043 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 3044 | } finally { |
| 3045 | Binder.restoreCallingIdentity(identity); |
| 3046 | } |
| 3047 | } |
| 3048 | |
| 3049 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3050 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3051 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3052 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3053 | final long identity = Binder.clearCallingIdentity(); |
| 3054 | try { |
| 3055 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3056 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3057 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 3058 | } finally { |
| 3059 | Binder.restoreCallingIdentity(identity); |
| 3060 | } |
| 3061 | } |
| 3062 | |
| 3063 | @Override |
| 3064 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3065 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3066 | "setVoWiFiNonPersistent"); |
| 3067 | final long identity = Binder.clearCallingIdentity(); |
| 3068 | try { |
| 3069 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3070 | boolean isRoaming = TelephonyManager.from( |
| 3071 | getPhone(subId).getContext()).isNetworkRoaming(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3072 | ImsManager.getInstance(mApp, |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3073 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3074 | } finally { |
| 3075 | Binder.restoreCallingIdentity(identity); |
| 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | @Override |
| 3080 | public int getVoWiFiModeSetting(int subId) { |
| 3081 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3082 | final long identity = Binder.clearCallingIdentity(); |
| 3083 | try { |
| 3084 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3085 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3086 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3087 | } finally { |
| 3088 | Binder.restoreCallingIdentity(identity); |
| 3089 | } |
| 3090 | } |
| 3091 | |
| 3092 | @Override |
| 3093 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3095 | "setVoWiFiModeSetting"); |
| 3096 | final long identity = Binder.clearCallingIdentity(); |
| 3097 | try { |
| 3098 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3099 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3100 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3101 | } finally { |
| 3102 | Binder.restoreCallingIdentity(identity); |
| 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | @Override |
| 3107 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3108 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3109 | final long identity = Binder.clearCallingIdentity(); |
| 3110 | try { |
| 3111 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3112 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3113 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3114 | } finally { |
| 3115 | Binder.restoreCallingIdentity(identity); |
| 3116 | } |
| 3117 | } |
| 3118 | |
| 3119 | @Override |
| 3120 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3121 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3122 | "setVoWiFiRoamingModeSetting"); |
| 3123 | final long identity = Binder.clearCallingIdentity(); |
| 3124 | try { |
| 3125 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3126 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3127 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3128 | } finally { |
| 3129 | Binder.restoreCallingIdentity(identity); |
| 3130 | } |
| 3131 | } |
| 3132 | |
| 3133 | @Override |
| 3134 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3135 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3136 | "setRttCapabilityEnabled"); |
| 3137 | final long identity = Binder.clearCallingIdentity(); |
| 3138 | try { |
| 3139 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3140 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3141 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3142 | } finally { |
| 3143 | Binder.restoreCallingIdentity(identity); |
| 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | @Override |
| 3148 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3149 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3150 | final long identity = Binder.clearCallingIdentity(); |
| 3151 | try { |
| 3152 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3153 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3154 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3155 | } finally { |
| 3156 | Binder.restoreCallingIdentity(identity); |
| 3157 | } |
| 3158 | } |
| 3159 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3160 | @Override |
| 3161 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3162 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3163 | final long identity = Binder.clearCallingIdentity(); |
| 3164 | try { |
| 3165 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3166 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3167 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3168 | } finally { |
| 3169 | Binder.restoreCallingIdentity(identity); |
| 3170 | } |
| 3171 | } |
| 3172 | |
| 3173 | @Override |
| 3174 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3175 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3176 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3177 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3178 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3179 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3180 | try { |
| 3181 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3182 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3183 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3184 | } catch (IllegalArgumentException e) { |
| 3185 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3186 | + "is inactive, ignoring unregister."); |
| 3187 | // If the subscription is no longer active, just return, since the callback will already |
| 3188 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3189 | } finally { |
| 3190 | Binder.restoreCallingIdentity(identity); |
| 3191 | } |
| 3192 | } |
| 3193 | |
| 3194 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3195 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3196 | boolean isProvisioned) { |
| 3197 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3198 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3199 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3200 | } |
| 3201 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3202 | "setProvisioningStatusForCapability"); |
| 3203 | final long identity = Binder.clearCallingIdentity(); |
| 3204 | try { |
| 3205 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3206 | Phone phone = getPhone(subId); |
| 3207 | if (phone == null) { |
| 3208 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3209 | + subId); |
| 3210 | return; |
| 3211 | } |
| 3212 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3213 | return; |
| 3214 | } |
| 3215 | |
| 3216 | // this capability requires provisioning, route to the correct API. |
| 3217 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3218 | switch (capability) { |
| 3219 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3220 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3221 | ims.setVolteProvisioned(isProvisioned); |
| 3222 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3223 | ims.setWfcProvisioned(isProvisioned); |
| 3224 | } |
| 3225 | break; |
| 3226 | } |
| 3227 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3228 | // There is currently no difference in VT provisioning type. |
| 3229 | ims.setVtProvisioned(isProvisioned); |
| 3230 | break; |
| 3231 | } |
| 3232 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3233 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3234 | // change the capability of the feature instead if needed. |
| 3235 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3236 | == isProvisioned) { |
| 3237 | // No change in provisioning. |
| 3238 | return; |
| 3239 | } |
| 3240 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3241 | try { |
| 3242 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3243 | } catch (ImsException e) { |
| 3244 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3245 | + ", Exception" + e.getMessage()); |
| 3246 | } |
| 3247 | break; |
| 3248 | } |
| 3249 | default: { |
| 3250 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3251 | + capability + "', which does not require provisioning."); |
| 3252 | } |
| 3253 | } |
| 3254 | |
| 3255 | } finally { |
| 3256 | Binder.restoreCallingIdentity(identity); |
| 3257 | } |
| 3258 | } |
| 3259 | |
| 3260 | @Override |
| 3261 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3262 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3263 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3264 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3265 | } |
| 3266 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3267 | final long identity = Binder.clearCallingIdentity(); |
| 3268 | try { |
| 3269 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3270 | Phone phone = getPhone(subId); |
| 3271 | if (phone == null) { |
| 3272 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3273 | + subId); |
| 3274 | // We will fail with "true" as the provisioning status because this is the default |
| 3275 | // if we do not require provisioning. |
| 3276 | return true; |
| 3277 | } |
| 3278 | |
| 3279 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3280 | return true; |
| 3281 | } |
| 3282 | |
| 3283 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3284 | switch (capability) { |
| 3285 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3286 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3287 | return ims.isVolteProvisionedOnDevice(); |
| 3288 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3289 | return ims.isWfcProvisionedOnDevice(); |
| 3290 | } |
| 3291 | // This should never happen, since we are checking tech above to make sure it |
| 3292 | // is either LTE or IWLAN. |
| 3293 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3294 | + "capability."); |
| 3295 | } |
| 3296 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3297 | // There is currently no difference in VT provisioning type. |
| 3298 | return ims.isVtProvisionedOnDevice(); |
| 3299 | } |
| 3300 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3301 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3302 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3303 | } |
| 3304 | default: { |
| 3305 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3306 | + capability + "', which does not require provisioning."); |
| 3307 | } |
| 3308 | } |
| 3309 | |
| 3310 | } finally { |
| 3311 | Binder.restoreCallingIdentity(identity); |
| 3312 | } |
| 3313 | } |
| 3314 | |
| 3315 | @Override |
| 3316 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3317 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3318 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3319 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3320 | } |
| 3321 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3322 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3323 | return (provisionedBits & capability) > 0; |
| 3324 | } |
| 3325 | |
| 3326 | @Override |
| 3327 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3328 | boolean isProvisioned) { |
| 3329 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3330 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3331 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3332 | } |
| 3333 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3334 | "setProvisioningStatusForCapability"); |
| 3335 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3336 | // If the current provisioning status for capability already matches isProvisioned, |
| 3337 | // do nothing. |
| 3338 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3339 | return; |
| 3340 | } |
| 3341 | if (isProvisioned) { |
| 3342 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3343 | } else { |
| 3344 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3345 | } |
| 3346 | } |
| 3347 | |
| 3348 | /** |
| 3349 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3350 | * technology. The bitfield should mirror the bitfield defined by |
| 3351 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3352 | */ |
| 3353 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3354 | String key = getMmTelProvisioningKey(subId, tech); |
| 3355 | // Default is no capabilities are provisioned. |
| 3356 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3357 | } |
| 3358 | |
| 3359 | /** |
| 3360 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3361 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3362 | * technology specified. |
| 3363 | * |
| 3364 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3365 | */ |
| 3366 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3367 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3368 | String key = getMmTelProvisioningKey(subId, tech); |
| 3369 | editor.putInt(key, newField); |
| 3370 | editor.commit(); |
| 3371 | } |
| 3372 | |
| 3373 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3374 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3375 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3376 | } |
| 3377 | |
| 3378 | /** |
| 3379 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3380 | * carrier associated with the subscription id. |
| 3381 | */ |
| 3382 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3383 | int capability) { |
| 3384 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3385 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3386 | boolean requireUtProvisioning = c.getBoolean( |
| 3387 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3388 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3389 | // the no-SIM case, where we would normally shortcut this to false. |
| 3390 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3391 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3392 | false); |
| 3393 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3394 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3395 | |
| 3396 | // First check to make sure that the capability requires provisioning. |
| 3397 | switch (capability) { |
| 3398 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3399 | // intentional fallthrough |
| 3400 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3401 | if (requireVoiceVtProvisioning) { |
| 3402 | // Voice and Video requires provisioning |
| 3403 | return true; |
| 3404 | } |
| 3405 | break; |
| 3406 | } |
| 3407 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3408 | if (requireUtProvisioning) { |
| 3409 | // UT requires provisioning |
| 3410 | return true; |
| 3411 | } |
| 3412 | break; |
| 3413 | } |
| 3414 | } |
| 3415 | return false; |
| 3416 | } |
| 3417 | |
| 3418 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3419 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3420 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3421 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3422 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3423 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3424 | final long identity = Binder.clearCallingIdentity(); |
| 3425 | try { |
| 3426 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3427 | int slotId = getSlotIndex(subId); |
| 3428 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3429 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3430 | + subId + "' for key:" + key); |
| 3431 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3432 | } |
| 3433 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3434 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3435 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3436 | + subId + "' for key:" + key); |
| 3437 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3438 | } finally { |
| 3439 | Binder.restoreCallingIdentity(identity); |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | @Override |
| 3444 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3445 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3446 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3447 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3448 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3449 | final long identity = Binder.clearCallingIdentity(); |
| 3450 | try { |
| 3451 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3452 | int slotId = getSlotIndex(subId); |
| 3453 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3454 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3455 | + subId + "' for key:" + key); |
| 3456 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3457 | } |
| 3458 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3459 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3460 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3461 | + subId + "' for key:" + key); |
| 3462 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3463 | } finally { |
| 3464 | Binder.restoreCallingIdentity(identity); |
| 3465 | } |
| 3466 | } |
| 3467 | |
| 3468 | @Override |
| 3469 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3470 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3471 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3472 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3473 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3474 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3475 | final long identity = Binder.clearCallingIdentity(); |
| 3476 | try { |
| 3477 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3478 | int slotId = getSlotIndex(subId); |
| 3479 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3480 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3481 | + subId + "' for key:" + key); |
| 3482 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3483 | } |
| 3484 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3485 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3486 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3487 | + "' for key:" + key); |
| 3488 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3489 | } finally { |
| 3490 | Binder.restoreCallingIdentity(identity); |
| 3491 | } |
| 3492 | } |
| 3493 | |
| 3494 | @Override |
| 3495 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3496 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3497 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3498 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3499 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3500 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3501 | final long identity = Binder.clearCallingIdentity(); |
| 3502 | try { |
| 3503 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3504 | int slotId = getSlotIndex(subId); |
| 3505 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3506 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3507 | + subId + "' for key:" + key); |
| 3508 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3509 | } |
| 3510 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3511 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3512 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3513 | + "' for key:" + key); |
| 3514 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3515 | } finally { |
| 3516 | Binder.restoreCallingIdentity(identity); |
| 3517 | } |
| 3518 | } |
| 3519 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3520 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3521 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3522 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3523 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3524 | } |
| 3525 | return slotId; |
| 3526 | } |
| 3527 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3528 | private int getSlotIndex(int subId) { |
| 3529 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3530 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3531 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3532 | } |
| 3533 | return slotId; |
| 3534 | } |
| 3535 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3536 | /** |
| 3537 | * Returns the network type for a subId |
| 3538 | */ |
| 3539 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3540 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3541 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3542 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3543 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3544 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3545 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3546 | final long identity = Binder.clearCallingIdentity(); |
| 3547 | try { |
| 3548 | final Phone phone = getPhone(subId); |
| 3549 | if (phone != null) { |
| 3550 | return phone.getServiceState().getDataNetworkType(); |
| 3551 | } else { |
| 3552 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3553 | } |
| 3554 | } finally { |
| 3555 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3556 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | /** |
| 3560 | * Returns the data network type |
| 3561 | */ |
| 3562 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3563 | public int getDataNetworkType(String callingPackage) { |
| 3564 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | /** |
| 3568 | * Returns the data network type for a subId |
| 3569 | */ |
| 3570 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3571 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3572 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3573 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3574 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3575 | } |
| 3576 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3577 | final long identity = Binder.clearCallingIdentity(); |
| 3578 | try { |
| 3579 | final Phone phone = getPhone(subId); |
| 3580 | if (phone != null) { |
| 3581 | return phone.getServiceState().getDataNetworkType(); |
| 3582 | } else { |
| 3583 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3584 | } |
| 3585 | } finally { |
| 3586 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3587 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3588 | } |
| 3589 | |
| 3590 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3591 | * Returns the Voice network type for a subId |
| 3592 | */ |
| 3593 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3594 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3595 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3596 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3597 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3598 | } |
| 3599 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3600 | final long identity = Binder.clearCallingIdentity(); |
| 3601 | try { |
| 3602 | final Phone phone = getPhone(subId); |
| 3603 | if (phone != null) { |
| 3604 | return phone.getServiceState().getVoiceNetworkType(); |
| 3605 | } else { |
| 3606 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3607 | } |
| 3608 | } finally { |
| 3609 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3610 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | /** |
| 3614 | * @return true if a ICC card is present |
| 3615 | */ |
| 3616 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3617 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3618 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3619 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3623 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3624 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3625 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3626 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3627 | final long identity = Binder.clearCallingIdentity(); |
| 3628 | try { |
| 3629 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3630 | if (phone != null) { |
| 3631 | return phone.getIccCard().hasIccCard(); |
| 3632 | } else { |
| 3633 | return false; |
| 3634 | } |
| 3635 | } finally { |
| 3636 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3637 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3638 | } |
| 3639 | |
| 3640 | /** |
| 3641 | * Return if the current radio is LTE on CDMA. This |
| 3642 | * is a tri-state return value as for a period of time |
| 3643 | * the mode may be unknown. |
| 3644 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3645 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3646 | * @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] | 3647 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3648 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3649 | @Override |
| 3650 | public int getLteOnCdmaMode(String callingPackage) { |
| 3651 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3652 | } |
| 3653 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3654 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3655 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3656 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3657 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3658 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3659 | } |
| 3660 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3661 | final long identity = Binder.clearCallingIdentity(); |
| 3662 | try { |
| 3663 | final Phone phone = getPhone(subId); |
| 3664 | if (phone == null) { |
| 3665 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3666 | } else { |
| 3667 | return phone.getLteOnCdmaMode(); |
| 3668 | } |
| 3669 | } finally { |
| 3670 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3671 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3672 | } |
| 3673 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3674 | /** |
| 3675 | * {@hide} |
| 3676 | * Returns Default subId, 0 in the case of single standby. |
| 3677 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3678 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3679 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3680 | } |
| 3681 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3682 | private int getSlotForDefaultSubscription() { |
| 3683 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3684 | } |
| 3685 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3686 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3687 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3688 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3689 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3690 | private boolean isActiveSubscription(int subId) { |
| 3691 | return mSubscriptionController.isActiveSubId(subId); |
| 3692 | } |
| 3693 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3694 | /** |
| 3695 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3696 | */ |
| 3697 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3698 | final long identity = Binder.clearCallingIdentity(); |
| 3699 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3700 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3701 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3702 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3703 | } finally { |
| 3704 | Binder.restoreCallingIdentity(identity); |
| 3705 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3706 | } |
| 3707 | |
| 3708 | /** |
| 3709 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3710 | */ |
| 3711 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3712 | final long identity = Binder.clearCallingIdentity(); |
| 3713 | try { |
| 3714 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3715 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3716 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3717 | } finally { |
| 3718 | Binder.restoreCallingIdentity(identity); |
| 3719 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3720 | } |
| 3721 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3722 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3723 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3724 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3725 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3726 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3727 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3728 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3729 | if (phoneId == -1) { |
| 3730 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3731 | + " does not correspond to an active phone"); |
| 3732 | } |
| 3733 | return PhoneFactory.getPhone(phoneId); |
| 3734 | } |
| 3735 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3736 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3737 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3738 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3739 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3740 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3741 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3742 | if (DBG) { |
| 3743 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3744 | } |
| 3745 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3746 | p2); |
| 3747 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3748 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3749 | |
| 3750 | @Override |
| 3751 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3752 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3753 | enforceModifyPermission(); |
| 3754 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3755 | if (DBG) { |
| 3756 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3757 | } |
| 3758 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3759 | callingPackage, aid, p2); |
| 3760 | } |
| 3761 | |
| 3762 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3763 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3764 | final long identity = Binder.clearCallingIdentity(); |
| 3765 | try { |
| 3766 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3767 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3768 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3769 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3770 | if (bestComponent == null |
| 3771 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3772 | loge("The calling package is not allowed to access ISD-R."); |
| 3773 | throw new SecurityException( |
| 3774 | "The calling package is not allowed to access ISD-R."); |
| 3775 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3776 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3777 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3778 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3779 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3780 | null /* workSource */); |
| 3781 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3782 | return response; |
| 3783 | } finally { |
| 3784 | Binder.restoreCallingIdentity(identity); |
| 3785 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3786 | } |
| 3787 | |
| 3788 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3789 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3791 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3792 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3793 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3794 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3795 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3796 | @Override |
| 3797 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3798 | enforceModifyPermission(); |
| 3799 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3800 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3801 | channel); |
| 3802 | } |
| 3803 | |
| 3804 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3805 | final long identity = Binder.clearCallingIdentity(); |
| 3806 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3807 | if (channel < 0) { |
| 3808 | return false; |
| 3809 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3810 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3811 | null /* workSource */); |
| 3812 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3813 | return success; |
| 3814 | } finally { |
| 3815 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3816 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3820 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3821 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3822 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3823 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3824 | if (DBG) { |
| 3825 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3826 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3827 | + p3 + " data=" + data); |
| 3828 | } |
| 3829 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3830 | command, p1, p2, p3, data); |
| 3831 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3832 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3833 | @Override |
| 3834 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3835 | int command, int p1, int p2, int p3, String data) { |
| 3836 | enforceModifyPermission(); |
| 3837 | if (DBG) { |
| 3838 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3839 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3840 | + p3 + " data=" + data); |
| 3841 | } |
| 3842 | return iccTransmitApduLogicalChannelWithPermission( |
| 3843 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3844 | data); |
| 3845 | } |
| 3846 | |
| 3847 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3848 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3849 | final long identity = Binder.clearCallingIdentity(); |
| 3850 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3851 | if (channel < 0) { |
| 3852 | return ""; |
| 3853 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3854 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3855 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3856 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3857 | null /* workSource */); |
| 3858 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3859 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3860 | // Append the returned status code to the end of the response payload. |
| 3861 | String s = Integer.toHexString( |
| 3862 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3863 | if (response.payload != null) { |
| 3864 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3865 | } |
| 3866 | return s; |
| 3867 | } finally { |
| 3868 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3869 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3870 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3871 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3872 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3873 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3874 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3875 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3876 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3877 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3878 | if (DBG) { |
| 3879 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3880 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3881 | } |
| 3882 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3883 | cla, command, p1, p2, p3, data); |
| 3884 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3885 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3886 | @Override |
| 3887 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3888 | int command, int p1, int p2, int p3, String data) { |
| 3889 | enforceModifyPermission(); |
| 3890 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3891 | if (DBG) { |
| 3892 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3893 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3894 | + " data=" + data); |
| 3895 | } |
| 3896 | |
| 3897 | return iccTransmitApduBasicChannelWithPermission( |
| 3898 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3899 | p2, p3, data); |
| 3900 | } |
| 3901 | |
| 3902 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3903 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3904 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3905 | final long identity = Binder.clearCallingIdentity(); |
| 3906 | try { |
| 3907 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3908 | && TextUtils.equals(ISDR_AID, data)) { |
| 3909 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3910 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3911 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3912 | if (bestComponent == null |
| 3913 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3914 | loge("The calling package is not allowed to select ISD-R."); |
| 3915 | throw new SecurityException( |
| 3916 | "The calling package is not allowed to select ISD-R."); |
| 3917 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3918 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3919 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3920 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3921 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 3922 | null /* workSource */); |
| 3923 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3924 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3925 | // Append the returned status code to the end of the response payload. |
| 3926 | String s = Integer.toHexString( |
| 3927 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3928 | if (response.payload != null) { |
| 3929 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3930 | } |
| 3931 | return s; |
| 3932 | } finally { |
| 3933 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3934 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3935 | } |
| 3936 | |
| 3937 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3938 | 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] | 3939 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3940 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3941 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3942 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3943 | final long identity = Binder.clearCallingIdentity(); |
| 3944 | try { |
| 3945 | if (DBG) { |
| 3946 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3947 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3948 | } |
| 3949 | |
| 3950 | IccIoResult response = |
| 3951 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3952 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3953 | subId); |
| 3954 | |
| 3955 | if (DBG) { |
| 3956 | log("Exchange SIM_IO [R]" + response); |
| 3957 | } |
| 3958 | |
| 3959 | byte[] result = null; |
| 3960 | int length = 2; |
| 3961 | if (response.payload != null) { |
| 3962 | length = 2 + response.payload.length; |
| 3963 | result = new byte[length]; |
| 3964 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3965 | } else { |
| 3966 | result = new byte[length]; |
| 3967 | } |
| 3968 | |
| 3969 | result[length - 1] = (byte) response.sw2; |
| 3970 | result[length - 2] = (byte) response.sw1; |
| 3971 | return result; |
| 3972 | } finally { |
| 3973 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3974 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3975 | } |
| 3976 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3977 | /** |
| 3978 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3979 | * on a particular subscription |
| 3980 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3981 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3982 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3983 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3984 | return null; |
| 3985 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3986 | |
| 3987 | final long identity = Binder.clearCallingIdentity(); |
| 3988 | try { |
| 3989 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3990 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3991 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3992 | return null; |
| 3993 | } |
| 3994 | Object response = sendRequest( |
| 3995 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3996 | if (response instanceof String[]) { |
| 3997 | return (String[]) response; |
| 3998 | } |
| 3999 | // Response is an Exception of some kind, |
| 4000 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4001 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4002 | } finally { |
| 4003 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4004 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4005 | } |
| 4006 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4007 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4008 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4009 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4010 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4011 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4012 | final long identity = Binder.clearCallingIdentity(); |
| 4013 | try { |
| 4014 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4015 | if (response.payload == null) { |
| 4016 | return ""; |
| 4017 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4018 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4019 | // Append the returned status code to the end of the response payload. |
| 4020 | String s = Integer.toHexString( |
| 4021 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4022 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4023 | return s; |
| 4024 | } finally { |
| 4025 | Binder.restoreCallingIdentity(identity); |
| 4026 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4029 | /** |
| 4030 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4031 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4032 | * |
| 4033 | * @param itemID the ID of the item to read |
| 4034 | * @return the NV item as a String, or null on error. |
| 4035 | */ |
| 4036 | @Override |
| 4037 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4038 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4039 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4040 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4041 | |
| 4042 | final long identity = Binder.clearCallingIdentity(); |
| 4043 | try { |
| 4044 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4045 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4046 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4047 | return value; |
| 4048 | } finally { |
| 4049 | Binder.restoreCallingIdentity(identity); |
| 4050 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | /** |
| 4054 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4055 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4056 | * |
| 4057 | * @param itemID the ID of the item to read |
| 4058 | * @param itemValue the value to write, as a String |
| 4059 | * @return true on success; false on any failure |
| 4060 | */ |
| 4061 | @Override |
| 4062 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4063 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4064 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4065 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4066 | |
| 4067 | final long identity = Binder.clearCallingIdentity(); |
| 4068 | try { |
| 4069 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4070 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4071 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4072 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4073 | return success; |
| 4074 | } finally { |
| 4075 | Binder.restoreCallingIdentity(identity); |
| 4076 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4077 | } |
| 4078 | |
| 4079 | /** |
| 4080 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4081 | * Used for device configuration by some CDMA operators. |
| 4082 | * |
| 4083 | * @param preferredRoamingList byte array containing the new PRL |
| 4084 | * @return true on success; false on any failure |
| 4085 | */ |
| 4086 | @Override |
| 4087 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4088 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4089 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4090 | |
| 4091 | final long identity = Binder.clearCallingIdentity(); |
| 4092 | try { |
| 4093 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4094 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4095 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4096 | return success; |
| 4097 | } finally { |
| 4098 | Binder.restoreCallingIdentity(identity); |
| 4099 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4103 | * 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] | 4104 | * Used for device configuration by some CDMA operators. |
| 4105 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4106 | * @param slotIndex - device slot. |
| 4107 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4108 | * @return true on success; false on any failure |
| 4109 | */ |
| 4110 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4111 | public boolean resetModemConfig(int slotIndex) { |
| 4112 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4113 | if (phone != null) { |
| 4114 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4115 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4116 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4117 | final long identity = Binder.clearCallingIdentity(); |
| 4118 | try { |
| 4119 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4120 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4121 | return success; |
| 4122 | } finally { |
| 4123 | Binder.restoreCallingIdentity(identity); |
| 4124 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4125 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4126 | return false; |
| 4127 | } |
| 4128 | |
| 4129 | /** |
| 4130 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4131 | * |
| 4132 | * @param slotIndex - device slot. |
| 4133 | * |
| 4134 | * @return true on success; false on any failure |
| 4135 | */ |
| 4136 | @Override |
| 4137 | public boolean rebootModem(int slotIndex) { |
| 4138 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4139 | if (phone != null) { |
| 4140 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4141 | mApp, phone.getSubId(), "rebootModem"); |
| 4142 | |
| 4143 | final long identity = Binder.clearCallingIdentity(); |
| 4144 | try { |
| 4145 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4146 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4147 | return success; |
| 4148 | } finally { |
| 4149 | Binder.restoreCallingIdentity(identity); |
| 4150 | } |
| 4151 | } |
| 4152 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4153 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4154 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4155 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4156 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4157 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4158 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4159 | return new String[0]; |
| 4160 | } |
| 4161 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4162 | final long identity = Binder.clearCallingIdentity(); |
| 4163 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4164 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4165 | } finally { |
| 4166 | Binder.restoreCallingIdentity(identity); |
| 4167 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4168 | } |
| 4169 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4170 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4171 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4172 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4173 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4174 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4175 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4176 | |
| 4177 | final long identity = Binder.clearCallingIdentity(); |
| 4178 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4179 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4180 | if (resolver == null) { |
| 4181 | // may happen if the device does not support IMS. |
| 4182 | return; |
| 4183 | } |
| 4184 | resolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4185 | } finally { |
| 4186 | Binder.restoreCallingIdentity(identity); |
| 4187 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4191 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4192 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4193 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4194 | public void disableIms(int slotId) { |
| 4195 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4196 | |
| 4197 | final long identity = Binder.clearCallingIdentity(); |
| 4198 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4199 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4200 | if (resolver == null) { |
| 4201 | // may happen if the device does not support IMS. |
| 4202 | return; |
| 4203 | } |
| 4204 | resolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4205 | } finally { |
| 4206 | Binder.restoreCallingIdentity(identity); |
| 4207 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | /** |
| 4211 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4212 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4213 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4214 | */ |
| 4215 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4216 | IImsServiceFeatureCallback callback) { |
| 4217 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4218 | |
| 4219 | final long identity = Binder.clearCallingIdentity(); |
| 4220 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4221 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4222 | if (resolver == null) { |
| 4223 | // may happen if the device does not support IMS. |
| 4224 | return null; |
| 4225 | } |
| 4226 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4227 | } finally { |
| 4228 | Binder.restoreCallingIdentity(identity); |
| 4229 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | /** |
| 4233 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4234 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4235 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4236 | * listener for feature updates. |
| 4237 | */ |
| 4238 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4239 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4240 | |
| 4241 | final long identity = Binder.clearCallingIdentity(); |
| 4242 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4243 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4244 | if (resolver == null) { |
| 4245 | // may happen if the device does not support IMS. |
| 4246 | return null; |
| 4247 | } |
| 4248 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4249 | } finally { |
| 4250 | Binder.restoreCallingIdentity(identity); |
| 4251 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4252 | } |
| 4253 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4254 | /** |
| 4255 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4256 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4257 | */ |
| 4258 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4259 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4260 | |
| 4261 | final long identity = Binder.clearCallingIdentity(); |
| 4262 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4263 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4264 | if (resolver == null) { |
| 4265 | // may happen if the device does not support IMS. |
| 4266 | return null; |
| 4267 | } |
| 4268 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4269 | } finally { |
| 4270 | Binder.restoreCallingIdentity(identity); |
| 4271 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4272 | } |
| 4273 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4274 | /** |
| 4275 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4276 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4277 | */ |
| 4278 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4279 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4280 | |
| 4281 | final long identity = Binder.clearCallingIdentity(); |
| 4282 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4283 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4284 | if (resolver == null) { |
| 4285 | // may happen if the device does not support IMS. |
| 4286 | return null; |
| 4287 | } |
| 4288 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4289 | } finally { |
| 4290 | Binder.restoreCallingIdentity(identity); |
| 4291 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4292 | } |
| 4293 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4294 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4295 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4296 | * |
| 4297 | * @param slotId the slot ID that the ImsService should bind for. |
| 4298 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4299 | * ImsService is the device default ImsService. |
| 4300 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4301 | * to. |
| 4302 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4303 | * @hide |
| 4304 | */ |
| 4305 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4306 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4307 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4308 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4309 | "setImsService"); |
| 4310 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4311 | final long identity = Binder.clearCallingIdentity(); |
| 4312 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4313 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4314 | if (resolver == null) { |
| 4315 | // may happen if the device does not support IMS. |
| 4316 | return false; |
| 4317 | } |
| 4318 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4319 | packageName); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4320 | } finally { |
| 4321 | Binder.restoreCallingIdentity(identity); |
| 4322 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4323 | } |
| 4324 | |
| 4325 | /** |
| 4326 | * Return the ImsService configuration. |
| 4327 | * |
| 4328 | * @param slotId The slot that the ImsService is associated with. |
| 4329 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4330 | * the device default. |
| 4331 | * @return the package name of the ImsService configuration. |
| 4332 | */ |
| 4333 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4334 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4335 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4336 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4337 | "getImsService"); |
| 4338 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4339 | final long identity = Binder.clearCallingIdentity(); |
| 4340 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4341 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4342 | if (resolver == null) { |
| 4343 | // may happen if the device does not support IMS. |
| 4344 | return ""; |
| 4345 | } |
| 4346 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4347 | } finally { |
| 4348 | Binder.restoreCallingIdentity(identity); |
| 4349 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4350 | } |
| 4351 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4352 | public void setImsRegistrationState(boolean registered) { |
| 4353 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4354 | |
| 4355 | final long identity = Binder.clearCallingIdentity(); |
| 4356 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4357 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4358 | } finally { |
| 4359 | Binder.restoreCallingIdentity(identity); |
| 4360 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4364 | * Set the network selection mode to automatic. |
| 4365 | * |
| 4366 | */ |
| 4367 | @Override |
| 4368 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4369 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4370 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4371 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4372 | if (!isActiveSubscription(subId)) { |
| 4373 | return; |
| 4374 | } |
| 4375 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4376 | final long identity = Binder.clearCallingIdentity(); |
| 4377 | try { |
| 4378 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4379 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4380 | } finally { |
| 4381 | Binder.restoreCallingIdentity(identity); |
| 4382 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4383 | } |
| 4384 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4385 | /** |
| 4386 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4387 | * |
| 4388 | * @param subId the id of the subscription. |
| 4389 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4390 | * the operator to attach to. |
| 4391 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4392 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4393 | * normal network selection next time. |
| 4394 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4395 | */ |
| 4396 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4397 | public boolean setNetworkSelectionModeManual( |
| 4398 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4399 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4400 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4401 | |
| 4402 | if (!isActiveSubscription(subId)) { |
| 4403 | return false; |
| 4404 | } |
| 4405 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4406 | final long identity = Binder.clearCallingIdentity(); |
| 4407 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4408 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4409 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4410 | if (DBG) { |
| 4411 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4412 | + " operator: " + operatorInfo); |
| 4413 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4414 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4415 | } finally { |
| 4416 | Binder.restoreCallingIdentity(identity); |
| 4417 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | /** |
| 4421 | * Scans for available networks. |
| 4422 | */ |
| 4423 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4424 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4425 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4426 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4427 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4428 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4429 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4430 | .setCallingPackage(callingPackage) |
| 4431 | .setCallingPid(Binder.getCallingPid()) |
| 4432 | .setCallingUid(Binder.getCallingUid()) |
| 4433 | .setMethod("getCellNetworkScanResults") |
| 4434 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4435 | .build()); |
| 4436 | switch (locationResult) { |
| 4437 | case DENIED_HARD: |
| 4438 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4439 | case DENIED_SOFT: |
| 4440 | return null; |
| 4441 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4442 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4443 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4444 | try { |
| 4445 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4446 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4447 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4448 | } finally { |
| 4449 | Binder.restoreCallingIdentity(identity); |
| 4450 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4451 | } |
| 4452 | |
| 4453 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4454 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4455 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4456 | * @param subId id of the subscription |
| 4457 | * @param request contains the radio access networks with bands/channels to scan |
| 4458 | * @param messenger callback messenger for scan results or errors |
| 4459 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4460 | * @return the id of the requested scan which can be used to stop the scan. |
| 4461 | */ |
| 4462 | @Override |
| 4463 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4464 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4465 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4466 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4467 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4468 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4469 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4470 | .setCallingPackage(callingPackage) |
| 4471 | .setCallingPid(Binder.getCallingPid()) |
| 4472 | .setCallingUid(Binder.getCallingUid()) |
| 4473 | .setMethod("requestNetworkScan") |
| 4474 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4475 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4476 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
| 4477 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request); |
| 4478 | if (e != null) { |
| 4479 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4480 | throw e; |
| 4481 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4482 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4483 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4484 | } |
| 4485 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4486 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4487 | int callingUid = Binder.getCallingUid(); |
| 4488 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4489 | final long identity = Binder.clearCallingIdentity(); |
| 4490 | try { |
| 4491 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4492 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4493 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4494 | } finally { |
| 4495 | Binder.restoreCallingIdentity(identity); |
| 4496 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4497 | } |
| 4498 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4499 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
| 4500 | NetworkScanRequest request) { |
| 4501 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4502 | != PERMISSION_GRANTED) { |
| 4503 | return new SecurityException("permission.NETWORK_SCAN is needed for network scans" |
| 4504 | + " without location access."); |
| 4505 | } |
| 4506 | |
| 4507 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4508 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4509 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4510 | return new SecurityException("Specific channels must not be" |
| 4511 | + " scanned without location access."); |
| 4512 | } |
| 4513 | } |
| 4514 | } |
| 4515 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4516 | return null; |
| 4517 | } |
| 4518 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4519 | /** |
| 4520 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4521 | * |
| 4522 | * @param subId id of the subscription |
| 4523 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4524 | */ |
| 4525 | @Override |
| 4526 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4527 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4528 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4529 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4530 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4531 | final long identity = Binder.clearCallingIdentity(); |
| 4532 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4533 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4534 | } finally { |
| 4535 | Binder.restoreCallingIdentity(identity); |
| 4536 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4537 | } |
| 4538 | |
| 4539 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4540 | * Get the calculated preferred network type. |
| 4541 | * Used for debugging incorrect network type. |
| 4542 | * |
| 4543 | * @return the preferred network type, defined in RILConstants.java. |
| 4544 | */ |
| 4545 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4546 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4547 | final Phone defaultPhone = getDefaultPhone(); |
| 4548 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4549 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4550 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4551 | } |
| 4552 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4553 | final long identity = Binder.clearCallingIdentity(); |
| 4554 | try { |
| 4555 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4556 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4557 | } finally { |
| 4558 | Binder.restoreCallingIdentity(identity); |
| 4559 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4560 | } |
| 4561 | |
| 4562 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4563 | * Get the preferred network type. |
| 4564 | * Used for device configuration by some CDMA operators. |
| 4565 | * |
| 4566 | * @return the preferred network type, defined in RILConstants.java. |
| 4567 | */ |
| 4568 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4569 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4570 | TelephonyPermissions |
| 4571 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4572 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4573 | |
| 4574 | final long identity = Binder.clearCallingIdentity(); |
| 4575 | try { |
| 4576 | if (DBG) log("getPreferredNetworkType"); |
| 4577 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4578 | int networkType = (result != null ? result[0] : -1); |
| 4579 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4580 | return networkType; |
| 4581 | } finally { |
| 4582 | Binder.restoreCallingIdentity(identity); |
| 4583 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4584 | } |
| 4585 | |
| 4586 | /** |
| 4587 | * Set the preferred network type. |
| 4588 | * Used for device configuration by some CDMA operators. |
| 4589 | * |
| 4590 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4591 | * @return true on success; false on any failure. |
| 4592 | */ |
| 4593 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4594 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4595 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4596 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4597 | |
| 4598 | final long identity = Binder.clearCallingIdentity(); |
| 4599 | try { |
| 4600 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4601 | Boolean success = (Boolean) sendRequest( |
| 4602 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4603 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4604 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4605 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4606 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4607 | } |
| 4608 | return success; |
| 4609 | } finally { |
| 4610 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4611 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4612 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4613 | |
| 4614 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4615 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4616 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4617 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4618 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4619 | * @hide |
| 4620 | */ |
| 4621 | @Override |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4622 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4623 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4624 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4625 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4626 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4627 | if (phone != null) { |
| 4628 | return phone.hasMatchedTetherApnSetting(); |
| 4629 | } else { |
| 4630 | return false; |
| 4631 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4632 | } finally { |
| 4633 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4634 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4638 | * Set mobile data enabled |
| 4639 | * Used by the user through settings etc to turn on/off mobile data |
| 4640 | * |
| 4641 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4642 | */ |
| 4643 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4644 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4645 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4646 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4647 | |
| 4648 | final long identity = Binder.clearCallingIdentity(); |
| 4649 | try { |
| 4650 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4651 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4652 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4653 | if (phone != null) { |
| 4654 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4655 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4656 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4657 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4658 | } |
| 4659 | } finally { |
| 4660 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4661 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4662 | } |
| 4663 | |
| 4664 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4665 | * Get the user enabled state of Mobile Data. |
| 4666 | * |
| 4667 | * TODO: remove and use isUserDataEnabled. |
| 4668 | * This can't be removed now because some vendor codes |
| 4669 | * calls through ITelephony directly while they should |
| 4670 | * use TelephonyManager. |
| 4671 | * |
| 4672 | * @return true on enabled |
| 4673 | */ |
| 4674 | @Override |
| 4675 | public boolean getDataEnabled(int subId) { |
| 4676 | return isUserDataEnabled(subId); |
| 4677 | } |
| 4678 | |
| 4679 | /** |
| 4680 | * Get whether mobile data is enabled per user setting. |
| 4681 | * |
| 4682 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4683 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4684 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4685 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4686 | * |
| 4687 | * @return {@code true} if data is enabled else {@code false} |
| 4688 | */ |
| 4689 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4690 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4691 | try { |
| 4692 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4693 | null); |
| 4694 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4695 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4696 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4697 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4698 | |
| 4699 | final long identity = Binder.clearCallingIdentity(); |
| 4700 | try { |
| 4701 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4702 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4703 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4704 | if (phone != null) { |
| 4705 | boolean retVal = phone.isUserDataEnabled(); |
| 4706 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4707 | return retVal; |
| 4708 | } else { |
| 4709 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4710 | return false; |
| 4711 | } |
| 4712 | } finally { |
| 4713 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4714 | } |
| 4715 | } |
| 4716 | |
| 4717 | /** |
| 4718 | * Get whether mobile data is enabled. |
| 4719 | * |
| 4720 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4721 | * whether mobile data is actually enabled. |
| 4722 | * |
| 4723 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4724 | * |
| 4725 | * @return {@code true} if data is enabled else {@code false} |
| 4726 | */ |
| 4727 | @Override |
| 4728 | public boolean isDataEnabled(int subId) { |
| 4729 | try { |
| 4730 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4731 | null); |
| 4732 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4733 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4734 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4735 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4736 | |
| 4737 | final long identity = Binder.clearCallingIdentity(); |
| 4738 | try { |
| 4739 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4740 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4741 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4742 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4743 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4744 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4745 | return retVal; |
| 4746 | } else { |
| 4747 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4748 | return false; |
| 4749 | } |
| 4750 | } finally { |
| 4751 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4752 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4753 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4754 | |
| 4755 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4756 | public int getCarrierPrivilegeStatus(int subId) { |
| 4757 | final Phone phone = getPhone(subId); |
| 4758 | if (phone == null) { |
| 4759 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4760 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4761 | } |
| 4762 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4763 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4764 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4765 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4766 | } |
| 4767 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4768 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4769 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4770 | |
| 4771 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4772 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4773 | final Phone phone = getPhone(subId); |
| 4774 | if (phone == null) { |
| 4775 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4776 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4777 | } |
| 4778 | UiccProfile profile = |
| 4779 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4780 | if (profile == null) { |
| 4781 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4782 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4783 | } |
| 4784 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4785 | } |
| 4786 | |
| 4787 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4788 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4789 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4790 | if (TextUtils.isEmpty(pkgName)) |
| 4791 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4792 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4793 | if (card == null) { |
| 4794 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4795 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4796 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4797 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4798 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | @Override |
| 4802 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4803 | if (TextUtils.isEmpty(pkgName)) |
| 4804 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4805 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4806 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4807 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4808 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4809 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4810 | continue; |
| 4811 | } |
| 4812 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4813 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4814 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4815 | break; |
| 4816 | } |
| 4817 | } |
| 4818 | |
| 4819 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4820 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4821 | |
| 4822 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4823 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4824 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4825 | loge("phoneId " + phoneId + " is not valid."); |
| 4826 | return null; |
| 4827 | } |
| 4828 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4829 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4830 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4831 | return null ; |
| 4832 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4833 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4834 | } |
| 4835 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4836 | @Override |
| 4837 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4838 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4839 | List<String> privilegedPackages = new ArrayList<>(); |
| 4840 | List<PackageInfo> packages = null; |
| 4841 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4842 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4843 | if (card == null) { |
| 4844 | // No UICC in that slot. |
| 4845 | continue; |
| 4846 | } |
| 4847 | if (card.hasCarrierPrivilegeRules()) { |
| 4848 | if (packages == null) { |
| 4849 | // Only check packages in user 0 for now |
| 4850 | packages = pm.getInstalledPackagesAsUser( |
| 4851 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4852 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4853 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4854 | } |
| 4855 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4856 | PackageInfo pkgInfo = packages.get(p); |
| 4857 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4858 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4859 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4860 | privilegedPackages.add(pkgInfo.packageName); |
| 4861 | } |
| 4862 | } |
| 4863 | } |
| 4864 | } |
| 4865 | return privilegedPackages; |
| 4866 | } |
| 4867 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4868 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4869 | final Phone phone = getPhone(subId); |
| 4870 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4871 | if (card == null) { |
| 4872 | loge("getIccId: No UICC"); |
| 4873 | return null; |
| 4874 | } |
| 4875 | String iccId = card.getIccId(); |
| 4876 | if (TextUtils.isEmpty(iccId)) { |
| 4877 | loge("getIccId: ICC ID is null or empty."); |
| 4878 | return null; |
| 4879 | } |
| 4880 | return iccId; |
| 4881 | } |
| 4882 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4883 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4884 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4885 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4886 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4887 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4888 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4889 | final long identity = Binder.clearCallingIdentity(); |
| 4890 | try { |
| 4891 | final String iccId = getIccId(subId); |
| 4892 | final Phone phone = getPhone(subId); |
| 4893 | if (phone == null) { |
| 4894 | return false; |
| 4895 | } |
| 4896 | final String subscriberId = phone.getSubscriberId(); |
| 4897 | |
| 4898 | if (DBG_MERGE) { |
| 4899 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4900 | + subscriberId + " to " + number); |
| 4901 | } |
| 4902 | |
| 4903 | if (TextUtils.isEmpty(iccId)) { |
| 4904 | return false; |
| 4905 | } |
| 4906 | |
| 4907 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4908 | |
| 4909 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4910 | if (alphaTag == null) { |
| 4911 | editor.remove(alphaTagPrefKey); |
| 4912 | } else { |
| 4913 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4914 | } |
| 4915 | |
| 4916 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4917 | // track all merged IMSIs based on line number |
| 4918 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4919 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4920 | if (number == null) { |
| 4921 | editor.remove(numberPrefKey); |
| 4922 | editor.remove(subscriberPrefKey); |
| 4923 | } else { |
| 4924 | editor.putString(numberPrefKey, number); |
| 4925 | editor.putString(subscriberPrefKey, subscriberId); |
| 4926 | } |
| 4927 | |
| 4928 | editor.commit(); |
| 4929 | return true; |
| 4930 | } finally { |
| 4931 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4932 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4933 | } |
| 4934 | |
| 4935 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4936 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4937 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4938 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4939 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4940 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4941 | return null; |
| 4942 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4943 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4944 | final long identity = Binder.clearCallingIdentity(); |
| 4945 | try { |
| 4946 | String iccId = getIccId(subId); |
| 4947 | if (iccId != null) { |
| 4948 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4949 | if (DBG_MERGE) { |
| 4950 | log("getLine1NumberForDisplay returning " |
| 4951 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4952 | } |
| 4953 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4954 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4955 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4956 | return null; |
| 4957 | } finally { |
| 4958 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4959 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4960 | } |
| 4961 | |
| 4962 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4963 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4964 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4965 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4966 | return null; |
| 4967 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4968 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4969 | final long identity = Binder.clearCallingIdentity(); |
| 4970 | try { |
| 4971 | String iccId = getIccId(subId); |
| 4972 | if (iccId != null) { |
| 4973 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4974 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4975 | } |
| 4976 | return null; |
| 4977 | } finally { |
| 4978 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4979 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4980 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4981 | |
| 4982 | @Override |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame^] | 4983 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4984 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4985 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4986 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4987 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4988 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4989 | return null; |
| 4990 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4991 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame^] | 4992 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4993 | // the process, where TelephonyManager was instantiated. |
| 4994 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4995 | final long identity = Binder.clearCallingIdentity(); |
| 4996 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4997 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4998 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4999 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5000 | |
| 5001 | // Figure out what subscribers are currently active |
| 5002 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5003 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame^] | 5004 | // Only consider subs which match the current subId |
| 5005 | // This logic can be simplified. See b/131189269 for progress. |
| 5006 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5007 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5008 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5009 | |
| 5010 | // First pass, find a number override for an active subscriber |
| 5011 | String mergeNumber = null; |
| 5012 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5013 | for (String key : prefs.keySet()) { |
| 5014 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5015 | final String subscriberId = (String) prefs.get(key); |
| 5016 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5017 | final String iccId = key.substring( |
| 5018 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5019 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5020 | mergeNumber = (String) prefs.get(numberKey); |
| 5021 | if (DBG_MERGE) { |
| 5022 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5023 | + " for active subscriber " + subscriberId); |
| 5024 | } |
| 5025 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5026 | break; |
| 5027 | } |
| 5028 | } |
| 5029 | } |
| 5030 | } |
| 5031 | |
| 5032 | // Shortcut when no active merged subscribers |
| 5033 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5034 | return null; |
| 5035 | } |
| 5036 | |
| 5037 | // Second pass, find all subscribers under that line override |
| 5038 | final ArraySet<String> result = new ArraySet<>(); |
| 5039 | for (String key : prefs.keySet()) { |
| 5040 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5041 | final String number = (String) prefs.get(key); |
| 5042 | if (mergeNumber.equals(number)) { |
| 5043 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5044 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5045 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5046 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5047 | result.add(subscriberId); |
| 5048 | } |
| 5049 | } |
| 5050 | } |
| 5051 | } |
| 5052 | |
| 5053 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5054 | Arrays.sort(resultArray); |
| 5055 | if (DBG_MERGE) { |
| 5056 | Slog.d(LOG_TAG, |
| 5057 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5058 | } |
| 5059 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5060 | } finally { |
| 5061 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5062 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5063 | } |
| 5064 | |
| 5065 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5066 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5067 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5068 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5069 | |
| 5070 | final long identity = Binder.clearCallingIdentity(); |
| 5071 | try { |
| 5072 | final Phone phone = getPhone(subId); |
| 5073 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5074 | } finally { |
| 5075 | Binder.restoreCallingIdentity(identity); |
| 5076 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5077 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5078 | |
| 5079 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5080 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5081 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5082 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5083 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5084 | |
| 5085 | final long identity = Binder.clearCallingIdentity(); |
| 5086 | try { |
| 5087 | final Phone phone = getPhone(subId); |
| 5088 | if (phone == null) { |
| 5089 | return false; |
| 5090 | } |
| 5091 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5092 | cdmaNonRoamingList); |
| 5093 | } finally { |
| 5094 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5095 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5096 | } |
| 5097 | |
| 5098 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5099 | @Deprecated |
| 5100 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5101 | enforceModifyPermission(); |
| 5102 | |
| 5103 | int returnValue = 0; |
| 5104 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5105 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5106 | if(result.exception == null) { |
| 5107 | if (result.result != null) { |
| 5108 | byte[] responseData = (byte[])(result.result); |
| 5109 | if(responseData.length > oemResp.length) { |
| 5110 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5111 | responseData.length + "bytes. Buffer Size is " + |
| 5112 | oemResp.length + "bytes."); |
| 5113 | } |
| 5114 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5115 | returnValue = responseData.length; |
| 5116 | } |
| 5117 | } else { |
| 5118 | CommandException ex = (CommandException) result.exception; |
| 5119 | returnValue = ex.getCommandError().ordinal(); |
| 5120 | if(returnValue > 0) returnValue *= -1; |
| 5121 | } |
| 5122 | } catch (RuntimeException e) { |
| 5123 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5124 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5125 | if(returnValue > 0) returnValue *= -1; |
| 5126 | } |
| 5127 | |
| 5128 | return returnValue; |
| 5129 | } |
| 5130 | |
| 5131 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5132 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5133 | try { |
| 5134 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5135 | } catch (RuntimeException e) { |
| 5136 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5137 | } |
| 5138 | } |
| 5139 | |
| 5140 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5141 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5142 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5143 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5144 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5145 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5146 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5147 | final long identity = Binder.clearCallingIdentity(); |
| 5148 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5149 | TelephonyPermissions |
| 5150 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5151 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5152 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5153 | } finally { |
| 5154 | Binder.restoreCallingIdentity(identity); |
| 5155 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5156 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5157 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5158 | |
| 5159 | @Override |
| 5160 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5161 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5162 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5163 | |
| 5164 | final long identity = Binder.clearCallingIdentity(); |
| 5165 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5166 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5167 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5168 | } finally { |
| 5169 | Binder.restoreCallingIdentity(identity); |
| 5170 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5171 | } |
| 5172 | |
| 5173 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5174 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5175 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5176 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5177 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5178 | return false; |
| 5179 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5180 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5181 | final long identity = Binder.clearCallingIdentity(); |
| 5182 | try { |
| 5183 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5184 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5185 | // In the long run, we may instead need to check if there exists a connection service |
| 5186 | // which can support video calling. |
| 5187 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5188 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5189 | return imsManager.isVtEnabledByPlatform() |
| 5190 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5191 | && imsManager.isVtEnabledByUser(); |
| 5192 | } finally { |
| 5193 | Binder.restoreCallingIdentity(identity); |
| 5194 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5195 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5196 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5197 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5198 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5199 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5200 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5201 | return false; |
| 5202 | } |
| 5203 | |
| 5204 | final long identity = Binder.clearCallingIdentity(); |
| 5205 | try { |
| 5206 | CarrierConfigManager configManager = |
| 5207 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5208 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5209 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5210 | } finally { |
| 5211 | Binder.restoreCallingIdentity(identity); |
| 5212 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5213 | } |
| 5214 | |
| 5215 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5216 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5217 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5218 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5219 | return false; |
| 5220 | } |
| 5221 | |
| 5222 | final long identity = Binder.clearCallingIdentity(); |
| 5223 | try { |
| 5224 | CarrierConfigManager configManager = |
| 5225 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5226 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5227 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5228 | } finally { |
| 5229 | Binder.restoreCallingIdentity(identity); |
| 5230 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5231 | } |
| 5232 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5233 | @Override |
| 5234 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5235 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5236 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5237 | } |
| 5238 | |
| 5239 | @Override |
| 5240 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5241 | final long identity = Binder.clearCallingIdentity(); |
| 5242 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5243 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5244 | } finally { |
| 5245 | Binder.restoreCallingIdentity(identity); |
| 5246 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5247 | } |
| 5248 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5249 | /** |
| 5250 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5251 | * support for the feature and device firmware support. |
| 5252 | * |
| 5253 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5254 | */ |
| 5255 | @Override |
| 5256 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5257 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5258 | final Phone phone = getPhone(subscriptionId); |
| 5259 | if (phone == null) { |
| 5260 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5261 | return false; |
| 5262 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5263 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5264 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5265 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5266 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5267 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5268 | return isCarrierSupported && isDeviceSupported; |
| 5269 | } finally { |
| 5270 | Binder.restoreCallingIdentity(identity); |
| 5271 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5272 | } |
| 5273 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5274 | /** |
| 5275 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 5276 | * both also support RTT. |
| 5277 | */ |
| 5278 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5279 | final long identity = Binder.clearCallingIdentity(); |
| 5280 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5281 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5282 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5283 | } finally { |
| 5284 | Binder.restoreCallingIdentity(identity); |
| 5285 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5286 | } |
| 5287 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5288 | /** |
| 5289 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5290 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5291 | * |
| 5292 | * <p>Requires Permission: |
| 5293 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5294 | */ |
| 5295 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5296 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5297 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5298 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5299 | return null; |
| 5300 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5301 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5302 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5303 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5304 | return null; |
| 5305 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5306 | |
| 5307 | final long identity = Binder.clearCallingIdentity(); |
| 5308 | try { |
| 5309 | return phone.getDeviceId(); |
| 5310 | } finally { |
| 5311 | Binder.restoreCallingIdentity(identity); |
| 5312 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5313 | } |
| 5314 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5315 | /** |
| 5316 | * {@hide} |
| 5317 | * Returns the IMS Registration Status on a particular subid |
| 5318 | * |
| 5319 | * @param subId |
| 5320 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5321 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5322 | Phone phone = getPhone(subId); |
| 5323 | if (phone != null) { |
| 5324 | return phone.isImsRegistered(); |
| 5325 | } else { |
| 5326 | return false; |
| 5327 | } |
| 5328 | } |
| 5329 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5330 | @Override |
| 5331 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5332 | final long identity = Binder.clearCallingIdentity(); |
| 5333 | try { |
| 5334 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5335 | } finally { |
| 5336 | Binder.restoreCallingIdentity(identity); |
| 5337 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5338 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5339 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5340 | @Override |
| 5341 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5342 | final long identity = Binder.clearCallingIdentity(); |
| 5343 | try { |
| 5344 | Phone phone = getPhone(subscriptionId); |
| 5345 | if (phone == null) { |
| 5346 | return null; |
| 5347 | } |
| 5348 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5349 | } finally { |
| 5350 | Binder.restoreCallingIdentity(identity); |
| 5351 | } |
| 5352 | } |
| 5353 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5354 | /** |
| 5355 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5356 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5357 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5358 | final long identity = Binder.clearCallingIdentity(); |
| 5359 | try { |
| 5360 | Phone phone = getPhone(subId); |
| 5361 | if (phone != null) { |
| 5362 | return phone.isWifiCallingEnabled(); |
| 5363 | } else { |
| 5364 | return false; |
| 5365 | } |
| 5366 | } finally { |
| 5367 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5368 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5369 | } |
| 5370 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5371 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5372 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5373 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5374 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5375 | final long identity = Binder.clearCallingIdentity(); |
| 5376 | try { |
| 5377 | Phone phone = getPhone(subId); |
| 5378 | if (phone != null) { |
| 5379 | return phone.isVideoEnabled(); |
| 5380 | } else { |
| 5381 | return false; |
| 5382 | } |
| 5383 | } finally { |
| 5384 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5385 | } |
| 5386 | } |
| 5387 | |
| 5388 | /** |
| 5389 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5390 | * defined in {@link ImsRegistrationImplBase}. |
| 5391 | */ |
| 5392 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5393 | final long identity = Binder.clearCallingIdentity(); |
| 5394 | try { |
| 5395 | Phone phone = getPhone(subId); |
| 5396 | if (phone != null) { |
| 5397 | return phone.getImsRegistrationTech(); |
| 5398 | } else { |
| 5399 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5400 | } |
| 5401 | } finally { |
| 5402 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5403 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5404 | } |
| 5405 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5406 | @Override |
| 5407 | public void factoryReset(int subId) { |
| 5408 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5409 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5410 | return; |
| 5411 | } |
| 5412 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5413 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5414 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5415 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5416 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5417 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5418 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5419 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5420 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5421 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5422 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5423 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5424 | // There has been issues when Sms raw table somehow stores orphan |
| 5425 | // fragments. They lead to garbled message when new fragments come |
| 5426 | // in and combined with those stale ones. In case this happens again, |
| 5427 | // user can reset all network settings which will clean up this table. |
| 5428 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5429 | } finally { |
| 5430 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5431 | } |
| 5432 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5433 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5434 | private void cleanUpSmsRawTable(Context context) { |
| 5435 | ContentResolver resolver = context.getContentResolver(); |
| 5436 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5437 | resolver.delete(uri, null, null); |
| 5438 | } |
| 5439 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5440 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5441 | public String getSimLocaleForSubscriber(int subId) { |
| 5442 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5443 | final Phone phone = getPhone(subId); |
| 5444 | if (phone == null) { |
| 5445 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5446 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5447 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5448 | final long identity = Binder.clearCallingIdentity(); |
| 5449 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5450 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5451 | phone.getContext().getOpPackageName()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5452 | if (info == null) { |
| 5453 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5454 | return null; |
| 5455 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5456 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5457 | // preferences (EF-PL and EF-LI)... |
| 5458 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5459 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5460 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5461 | if (localeFromDefaultSim != null) { |
| 5462 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5463 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5464 | + localeFromDefaultSim); |
| 5465 | return localeFromDefaultSim.toLanguageTag(); |
| 5466 | } else { |
| 5467 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5468 | } |
| 5469 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5470 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5471 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5472 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5473 | // the SIM and carrier preferences does not include a country we add the country |
| 5474 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5475 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5476 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5477 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5478 | return mccLocale.toLanguageTag(); |
| 5479 | } |
| 5480 | |
| 5481 | if (DBG) log("No locale found - returning null"); |
| 5482 | return null; |
| 5483 | } finally { |
| 5484 | Binder.restoreCallingIdentity(identity); |
| 5485 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5486 | } |
| 5487 | |
| 5488 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5489 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5490 | } |
| 5491 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5492 | /** |
| 5493 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5494 | */ |
| 5495 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5496 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5497 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5498 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5499 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5500 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5501 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5502 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5503 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5504 | * representing the state of the modem. |
| 5505 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5506 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5507 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5508 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5509 | */ |
| 5510 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5511 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5512 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5513 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5514 | |
| 5515 | final long identity = Binder.clearCallingIdentity(); |
| 5516 | try { |
| 5517 | ModemActivityInfo ret = null; |
| 5518 | synchronized (mLastModemActivityInfo) { |
| 5519 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5520 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5521 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5522 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5523 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5524 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5525 | mergedTxTimeMs[i] = info.getTxTimeMillis()[i] |
| 5526 | + mLastModemActivityInfo.getTxTimeMillis()[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5527 | } |
| 5528 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5529 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 5530 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5531 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5532 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5533 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5534 | mLastModemActivityInfo.setRxTimeMillis( |
| 5535 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5536 | mLastModemActivityInfo.setEnergyUsed( |
| 5537 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5538 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5539 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5540 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5541 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5542 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5543 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5544 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5545 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5546 | Bundle bundle = new Bundle(); |
| 5547 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5548 | result.send(0, bundle); |
| 5549 | } finally { |
| 5550 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5551 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5552 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5553 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5554 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5555 | // less than total activity duration. |
| 5556 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5557 | if (info == null) { |
| 5558 | return false; |
| 5559 | } |
| 5560 | int activityDurationMs = |
| 5561 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5562 | int totalTxTimeMs = 0; |
| 5563 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5564 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5565 | } |
| 5566 | return (info.isValid() |
| 5567 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5568 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5569 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5570 | && (totalTxTimeMs <= activityDurationMs)); |
| 5571 | } |
| 5572 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5573 | /** |
| 5574 | * {@hide} |
| 5575 | * Returns the service state information on specified subscription. |
| 5576 | */ |
| 5577 | @Override |
| 5578 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5579 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5580 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5581 | return null; |
| 5582 | } |
| 5583 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5584 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5585 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5586 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5587 | .setCallingPackage(callingPackage) |
| 5588 | .setCallingPid(Binder.getCallingPid()) |
| 5589 | .setCallingUid(Binder.getCallingUid()) |
| 5590 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5591 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5592 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5593 | .build()); |
| 5594 | |
| 5595 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5596 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5597 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5598 | .setCallingPackage(callingPackage) |
| 5599 | .setCallingPid(Binder.getCallingPid()) |
| 5600 | .setCallingUid(Binder.getCallingUid()) |
| 5601 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5602 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5603 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5604 | .build()); |
| 5605 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5606 | boolean hasFinePermission = |
| 5607 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5608 | boolean hasCoarsePermission = |
| 5609 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5610 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5611 | final long identity = Binder.clearCallingIdentity(); |
| 5612 | try { |
| 5613 | final Phone phone = getPhone(subId); |
| 5614 | if (phone == null) { |
| 5615 | return null; |
| 5616 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5617 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5618 | ServiceState ss = phone.getServiceState(); |
| 5619 | |
| 5620 | // Scrub out the location info in ServiceState depending on what level of access |
| 5621 | // the caller has. |
| 5622 | if (hasFinePermission) return ss; |
| 5623 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5624 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5625 | } finally { |
| 5626 | Binder.restoreCallingIdentity(identity); |
| 5627 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5628 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5629 | |
| 5630 | /** |
| 5631 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5632 | * |
| 5633 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5634 | * voicemail ringtone. |
| 5635 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5636 | * PhoneAccount. |
| 5637 | */ |
| 5638 | @Override |
| 5639 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5640 | final long identity = Binder.clearCallingIdentity(); |
| 5641 | try { |
| 5642 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5643 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5644 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5645 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5646 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5647 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5648 | } finally { |
| 5649 | Binder.restoreCallingIdentity(identity); |
| 5650 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5651 | } |
| 5652 | |
| 5653 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5654 | * Sets the per-account voicemail ringtone. |
| 5655 | * |
| 5656 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5657 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5658 | * |
| 5659 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5660 | * voicemail ringtone. |
| 5661 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5662 | * PhoneAccount. |
| 5663 | */ |
| 5664 | @Override |
| 5665 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5666 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5667 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5668 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5669 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5670 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5671 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5672 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5673 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5674 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5675 | |
| 5676 | final long identity = Binder.clearCallingIdentity(); |
| 5677 | try { |
| 5678 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5679 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5680 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5681 | } |
| 5682 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5683 | } finally { |
| 5684 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5685 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5686 | } |
| 5687 | |
| 5688 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5689 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5690 | * |
| 5691 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5692 | * voicemail vibration setting. |
| 5693 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5694 | */ |
| 5695 | @Override |
| 5696 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5697 | final long identity = Binder.clearCallingIdentity(); |
| 5698 | try { |
| 5699 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5700 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5701 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5702 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5703 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5704 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5705 | } finally { |
| 5706 | Binder.restoreCallingIdentity(identity); |
| 5707 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5708 | } |
| 5709 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5710 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5711 | * Sets the per-account voicemail vibration. |
| 5712 | * |
| 5713 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5714 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5715 | * |
| 5716 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5717 | * voicemail vibration setting. |
| 5718 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5719 | * specific PhoneAccount. |
| 5720 | */ |
| 5721 | @Override |
| 5722 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5723 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5724 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5725 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5726 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5727 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5728 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5729 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5730 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5731 | } |
| 5732 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5733 | final long identity = Binder.clearCallingIdentity(); |
| 5734 | try { |
| 5735 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5736 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5737 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5738 | } |
| 5739 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5740 | } finally { |
| 5741 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5742 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5743 | } |
| 5744 | |
| 5745 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5746 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5747 | * |
| 5748 | * @throws SecurityException if the caller does not have the required permission |
| 5749 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5750 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5751 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5752 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5753 | } |
| 5754 | |
| 5755 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5756 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5757 | * permission. |
| 5758 | * |
| 5759 | * @throws SecurityException if the caller does not have the required permission |
| 5760 | */ |
| 5761 | private void enforceSendSmsPermission() { |
| 5762 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5763 | } |
| 5764 | |
| 5765 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5766 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5767 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5768 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5769 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5770 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5771 | final long identity = Binder.clearCallingIdentity(); |
| 5772 | try { |
| 5773 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5774 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5775 | if (componentName == null) { |
| 5776 | throw new SecurityException( |
| 5777 | "Caller not current active visual voicemail package[null]"); |
| 5778 | } |
| 5779 | String vvmPackage = componentName.getPackageName(); |
| 5780 | if (!callingPackage.equals(vvmPackage)) { |
| 5781 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5782 | + vvmPackage + "]"); |
| 5783 | } |
| 5784 | } finally { |
| 5785 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5786 | } |
| 5787 | } |
| 5788 | |
| 5789 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5790 | * Return the application ID for the app type. |
| 5791 | * |
| 5792 | * @param subId the subscription ID that this request applies to. |
| 5793 | * @param appType the uicc app type. |
| 5794 | * @return Application ID for specificied app type, or null if no uicc. |
| 5795 | */ |
| 5796 | @Override |
| 5797 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5798 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5799 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5800 | |
| 5801 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5802 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5803 | if (phone == null) { |
| 5804 | return null; |
| 5805 | } |
| 5806 | String aid = null; |
| 5807 | try { |
| 5808 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5809 | .getApplicationByType(appType).getAid(); |
| 5810 | } catch (Exception e) { |
| 5811 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5812 | } |
| 5813 | return aid; |
| 5814 | } finally { |
| 5815 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5816 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5817 | } |
| 5818 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5819 | /** |
| 5820 | * Return the Electronic Serial Number. |
| 5821 | * |
| 5822 | * @param subId the subscription ID that this request applies to. |
| 5823 | * @return ESN or null if error. |
| 5824 | */ |
| 5825 | @Override |
| 5826 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5827 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5828 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5829 | |
| 5830 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5831 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5832 | if (phone == null) { |
| 5833 | return null; |
| 5834 | } |
| 5835 | String esn = null; |
| 5836 | try { |
| 5837 | esn = phone.getEsn(); |
| 5838 | } catch (Exception e) { |
| 5839 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5840 | } |
| 5841 | return esn; |
| 5842 | } finally { |
| 5843 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5844 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5845 | } |
| 5846 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5847 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5848 | * Return the Preferred Roaming List Version. |
| 5849 | * |
| 5850 | * @param subId the subscription ID that this request applies to. |
| 5851 | * @return PRLVersion or null if error. |
| 5852 | */ |
| 5853 | @Override |
| 5854 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5855 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5856 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5857 | |
| 5858 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5859 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5860 | if (phone == null) { |
| 5861 | return null; |
| 5862 | } |
| 5863 | String cdmaPrlVersion = null; |
| 5864 | try { |
| 5865 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5866 | } catch (Exception e) { |
| 5867 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5868 | } |
| 5869 | return cdmaPrlVersion; |
| 5870 | } finally { |
| 5871 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5872 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5873 | } |
| 5874 | |
| 5875 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5876 | * Get snapshot of Telephony histograms |
| 5877 | * @return List of Telephony histograms |
| 5878 | * @hide |
| 5879 | */ |
| 5880 | @Override |
| 5881 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5882 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5883 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5884 | |
| 5885 | final long identity = Binder.clearCallingIdentity(); |
| 5886 | try { |
| 5887 | return RIL.getTelephonyRILTimingHistograms(); |
| 5888 | } finally { |
| 5889 | Binder.restoreCallingIdentity(identity); |
| 5890 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5891 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5892 | |
| 5893 | /** |
| 5894 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5895 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5896 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5897 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5898 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5899 | * @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] | 5900 | */ |
| 5901 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5902 | @TelephonyManager.SetCarrierRestrictionResult |
| 5903 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5904 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5905 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5906 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5907 | if (carrierRestrictionRules == null) { |
| 5908 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5909 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5910 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5911 | final long identity = Binder.clearCallingIdentity(); |
| 5912 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5913 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5914 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5915 | } finally { |
| 5916 | Binder.restoreCallingIdentity(identity); |
| 5917 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5918 | } |
| 5919 | |
| 5920 | /** |
| 5921 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5922 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5923 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5924 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5925 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5926 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5927 | */ |
| 5928 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5929 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5930 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5931 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5932 | |
| 5933 | final long identity = Binder.clearCallingIdentity(); |
| 5934 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5935 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5936 | if (response instanceof CarrierRestrictionRules) { |
| 5937 | return (CarrierRestrictionRules) response; |
| 5938 | } |
| 5939 | // Response is an Exception of some kind, |
| 5940 | // which is signalled to the user as a NULL retval |
| 5941 | return null; |
| 5942 | } catch (Exception e) { |
| 5943 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5944 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5945 | } finally { |
| 5946 | Binder.restoreCallingIdentity(identity); |
| 5947 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5948 | } |
| 5949 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5950 | /** |
| 5951 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5952 | * @param subId the subscription ID that this action applies to. |
| 5953 | * @param enabled control enable or disable metered apns. |
| 5954 | * {@hide} |
| 5955 | */ |
| 5956 | @Override |
| 5957 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5958 | enforceModifyPermission(); |
| 5959 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5960 | |
| 5961 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5962 | if (phone == null) { |
| 5963 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5964 | return; |
| 5965 | } |
| 5966 | try { |
| 5967 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5968 | } catch (Exception e) { |
| 5969 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5970 | } finally { |
| 5971 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5972 | } |
| 5973 | } |
| 5974 | |
| 5975 | /** |
| 5976 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5977 | * @param subId the subscription ID that this action applies to. |
| 5978 | * @param enabled control enable or disable radio. |
| 5979 | * {@hide} |
| 5980 | */ |
| 5981 | @Override |
| 5982 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5983 | enforceModifyPermission(); |
| 5984 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5985 | |
| 5986 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5987 | if (phone == null) { |
| 5988 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5989 | return; |
| 5990 | } |
| 5991 | try { |
| 5992 | phone.carrierActionSetRadioEnabled(enabled); |
| 5993 | } catch (Exception e) { |
| 5994 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5995 | } finally { |
| 5996 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5997 | } |
| 5998 | } |
| 5999 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6000 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6001 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6002 | * network status based on which carrier apps could apply actions accordingly, |
| 6003 | * enable/disable default url handler for example. |
| 6004 | * |
| 6005 | * @param subId the subscription ID that this action applies to. |
| 6006 | * @param report control start/stop reporting the default network status. |
| 6007 | * {@hide} |
| 6008 | */ |
| 6009 | @Override |
| 6010 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6011 | enforceModifyPermission(); |
| 6012 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6013 | |
| 6014 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6015 | if (phone == null) { |
| 6016 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6017 | return; |
| 6018 | } |
| 6019 | try { |
| 6020 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6021 | } catch (Exception e) { |
| 6022 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6023 | } finally { |
| 6024 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6025 | } |
| 6026 | } |
| 6027 | |
| 6028 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6029 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6030 | * @param subId the subscription ID that this action applies to. |
| 6031 | * {@hide} |
| 6032 | */ |
| 6033 | @Override |
| 6034 | public void carrierActionResetAll(int subId) { |
| 6035 | enforceModifyPermission(); |
| 6036 | final Phone phone = getPhone(subId); |
| 6037 | if (phone == null) { |
| 6038 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6039 | return; |
| 6040 | } |
| 6041 | try { |
| 6042 | phone.carrierActionResetAll(); |
| 6043 | } catch (Exception e) { |
| 6044 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6045 | } |
| 6046 | } |
| 6047 | |
| 6048 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6049 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6050 | * bug report is being generated. |
| 6051 | */ |
| 6052 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6053 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6054 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6055 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6056 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6057 | + Binder.getCallingPid() |
| 6058 | + ", uid=" + Binder.getCallingUid() |
| 6059 | + "without permission " |
| 6060 | + android.Manifest.permission.DUMP); |
| 6061 | return; |
| 6062 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6063 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6064 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6065 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6066 | @Override |
| 6067 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6068 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6069 | throws RemoteException { |
| 6070 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 6071 | } |
| 6072 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6073 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6074 | * Get aggregated video call data usage since boot. |
| 6075 | * |
| 6076 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6077 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6078 | * {@hide} |
| 6079 | */ |
| 6080 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6081 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6082 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6083 | null); |
| 6084 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6085 | final long identity = Binder.clearCallingIdentity(); |
| 6086 | try { |
| 6087 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6088 | // records the delta with the corresponding network identity. |
| 6089 | // We just return the total video call data usage snapshot since boot. |
| 6090 | Phone phone = getPhone(subId); |
| 6091 | if (phone != null) { |
| 6092 | return phone.getVtDataUsage(perUidStats); |
| 6093 | } |
| 6094 | return null; |
| 6095 | } finally { |
| 6096 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6097 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6098 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6099 | |
| 6100 | /** |
| 6101 | * Policy control of data connection. Usually used when data limit is passed. |
| 6102 | * @param enabled True if enabling the data, otherwise disabling. |
| 6103 | * @param subId Subscription index |
| 6104 | * {@hide} |
| 6105 | */ |
| 6106 | @Override |
| 6107 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6108 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6109 | |
| 6110 | final long identity = Binder.clearCallingIdentity(); |
| 6111 | try { |
| 6112 | Phone phone = getPhone(subId); |
| 6113 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6114 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6115 | } |
| 6116 | } finally { |
| 6117 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6118 | } |
| 6119 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6120 | |
| 6121 | /** |
| 6122 | * Get Client request stats |
| 6123 | * @return List of Client Request Stats |
| 6124 | * @hide |
| 6125 | */ |
| 6126 | @Override |
| 6127 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6128 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6129 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6130 | return null; |
| 6131 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6132 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6133 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6134 | final long identity = Binder.clearCallingIdentity(); |
| 6135 | try { |
| 6136 | if (phone != null) { |
| 6137 | return phone.getClientRequestStats(); |
| 6138 | } |
| 6139 | |
| 6140 | return null; |
| 6141 | } finally { |
| 6142 | Binder.restoreCallingIdentity(identity); |
| 6143 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6144 | } |
| 6145 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6146 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6147 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6148 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6149 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6150 | |
| 6151 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6152 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6153 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6154 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6155 | * @param state State of SIM (power down, power up, pass through) |
| 6156 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6157 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6158 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6159 | * |
| 6160 | **/ |
| 6161 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6162 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6163 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6164 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6165 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6166 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6167 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6168 | final long identity = Binder.clearCallingIdentity(); |
| 6169 | try { |
| 6170 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6171 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6172 | } |
| 6173 | } finally { |
| 6174 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6175 | } |
| 6176 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6177 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6178 | private boolean isUssdApiAllowed(int subId) { |
| 6179 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6180 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6181 | if (configManager == null) { |
| 6182 | return false; |
| 6183 | } |
| 6184 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6185 | if (pb == null) { |
| 6186 | return false; |
| 6187 | } |
| 6188 | return pb.getBoolean( |
| 6189 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6190 | } |
| 6191 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6192 | /** |
| 6193 | * Check if phone is in emergency callback mode |
| 6194 | * @return true if phone is in emergency callback mode |
| 6195 | * @param subId sub id |
| 6196 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6197 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6198 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6199 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6200 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6201 | |
| 6202 | final long identity = Binder.clearCallingIdentity(); |
| 6203 | try { |
| 6204 | if (phone != null) { |
| 6205 | return phone.isInEcm(); |
| 6206 | } else { |
| 6207 | return false; |
| 6208 | } |
| 6209 | } finally { |
| 6210 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6211 | } |
| 6212 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6213 | |
| 6214 | /** |
| 6215 | * Get the current signal strength information for the given subscription. |
| 6216 | * Because this information is not updated when the device is in a low power state |
| 6217 | * it should not be relied-upon to be current. |
| 6218 | * @param subId Subscription index |
| 6219 | * @return the most recent cached signal strength info from the modem |
| 6220 | */ |
| 6221 | @Override |
| 6222 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6223 | final long identity = Binder.clearCallingIdentity(); |
| 6224 | try { |
| 6225 | Phone p = getPhone(subId); |
| 6226 | if (p == null) { |
| 6227 | return null; |
| 6228 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6229 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6230 | return p.getSignalStrength(); |
| 6231 | } finally { |
| 6232 | Binder.restoreCallingIdentity(identity); |
| 6233 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6234 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6235 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6236 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6237 | * Get the current modem radio state for the given slot. |
| 6238 | * @param slotIndex slot index. |
| 6239 | * @param callingPackage the name of the package making the call. |
| 6240 | * @return the current radio power state from the modem |
| 6241 | */ |
| 6242 | @Override |
| 6243 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6244 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6245 | if (phone != null) { |
| 6246 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6247 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6248 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6249 | } |
| 6250 | |
| 6251 | final long identity = Binder.clearCallingIdentity(); |
| 6252 | try { |
| 6253 | return phone.getRadioPowerState(); |
| 6254 | } finally { |
| 6255 | Binder.restoreCallingIdentity(identity); |
| 6256 | } |
| 6257 | } |
| 6258 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6259 | } |
| 6260 | |
| 6261 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6262 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6263 | * |
| 6264 | * <p>Requires one of the following permissions: |
| 6265 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6266 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6267 | * privileges. |
| 6268 | * |
| 6269 | * @param subId subscription id |
| 6270 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6271 | * {@code false}. |
| 6272 | */ |
| 6273 | @Override |
| 6274 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6275 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6276 | null /* message */); |
| 6277 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6278 | boolean isEnabled = false; |
| 6279 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6280 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6281 | Phone phone = getPhone(subId); |
| 6282 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6283 | } catch (Exception e) { |
| 6284 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6285 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6286 | } finally { |
| 6287 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6288 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6289 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6290 | } |
| 6291 | |
| 6292 | |
| 6293 | /** |
| 6294 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6295 | * |
| 6296 | * <p> Requires permission: |
| 6297 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6298 | * privileges. |
| 6299 | * |
| 6300 | * @param subId subscription id |
| 6301 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6302 | */ |
| 6303 | @Override |
| 6304 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6305 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6306 | mApp, subId, "setDataRoamingEnabled"); |
| 6307 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6308 | final long identity = Binder.clearCallingIdentity(); |
| 6309 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6310 | Phone phone = getPhone(subId); |
| 6311 | if (phone != null) { |
| 6312 | phone.setDataRoamingEnabled(isEnabled); |
| 6313 | } |
| 6314 | } finally { |
| 6315 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6316 | } |
| 6317 | } |
| 6318 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6319 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6320 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6321 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6322 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6323 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6324 | boolean isAllowed = true; |
| 6325 | final long identity = Binder.clearCallingIdentity(); |
| 6326 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6327 | Phone phone = getPhone(subId); |
| 6328 | if (phone != null) { |
| 6329 | isAllowed = phone.isCspPlmnEnabled(); |
| 6330 | } |
| 6331 | } finally { |
| 6332 | Binder.restoreCallingIdentity(identity); |
| 6333 | } |
| 6334 | return isAllowed; |
| 6335 | } |
| 6336 | |
| 6337 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6338 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6339 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6340 | try { |
| 6341 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6342 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6343 | } catch (SecurityException e) { |
| 6344 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6345 | // has carrier privileges on an active UICC |
| 6346 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6347 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6348 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6349 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6350 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6351 | |
| 6352 | final long identity = Binder.clearCallingIdentity(); |
| 6353 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6354 | UiccController uiccController = UiccController.getInstance(); |
| 6355 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6356 | if (hasReadPermission) { |
| 6357 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6358 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6359 | |
| 6360 | // Remove private info if the caller doesn't have access |
| 6361 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6362 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6363 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6364 | // is available |
| 6365 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6366 | if (card == null || card.getUiccProfile() == null) { |
| 6367 | // assume no access if the card or profile is unavailable |
| 6368 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6369 | continue; |
| 6370 | } |
| 6371 | UiccProfile profile = card.getUiccProfile(); |
| 6372 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6373 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6374 | filteredInfos.add(cardInfo); |
| 6375 | } else { |
| 6376 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6377 | } |
| 6378 | } |
| 6379 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6380 | } finally { |
| 6381 | Binder.restoreCallingIdentity(identity); |
| 6382 | } |
| 6383 | } |
| 6384 | |
| 6385 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6386 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6387 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6388 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6389 | final long identity = Binder.clearCallingIdentity(); |
| 6390 | try { |
| 6391 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6392 | if (slots == null) { |
| 6393 | Rlog.i(LOG_TAG, "slots is null."); |
| 6394 | return null; |
| 6395 | } |
| 6396 | |
| 6397 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6398 | for (int i = 0; i < slots.length; i++) { |
| 6399 | UiccSlot slot = slots[i]; |
| 6400 | if (slot == null) { |
| 6401 | continue; |
| 6402 | } |
| 6403 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6404 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6405 | UiccCard card = slot.getUiccCard(); |
| 6406 | if (card != null) { |
| 6407 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6408 | } else { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6409 | cardId = slot.getIccId(); |
| 6410 | } |
| 6411 | |
| 6412 | int cardState = 0; |
| 6413 | switch (slot.getCardState()) { |
| 6414 | case CARDSTATE_ABSENT: |
| 6415 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6416 | break; |
| 6417 | case CARDSTATE_PRESENT: |
| 6418 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6419 | break; |
| 6420 | case CARDSTATE_ERROR: |
| 6421 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6422 | break; |
| 6423 | case CARDSTATE_RESTRICTED: |
| 6424 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6425 | break; |
| 6426 | default: |
| 6427 | break; |
| 6428 | |
| 6429 | } |
| 6430 | |
| 6431 | infos[i] = new UiccSlotInfo( |
| 6432 | slot.isActive(), |
| 6433 | slot.isEuicc(), |
| 6434 | cardId, |
| 6435 | cardState, |
| 6436 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6437 | slot.isExtendedApduSupported(), |
| 6438 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6439 | } |
| 6440 | return infos; |
| 6441 | } finally { |
| 6442 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6443 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6444 | } |
| 6445 | |
| 6446 | @Override |
| 6447 | public boolean switchSlots(int[] physicalSlots) { |
| 6448 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6449 | |
| 6450 | final long identity = Binder.clearCallingIdentity(); |
| 6451 | try { |
| 6452 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6453 | } finally { |
| 6454 | Binder.restoreCallingIdentity(identity); |
| 6455 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6456 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6457 | |
| 6458 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6459 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6460 | final long identity = Binder.clearCallingIdentity(); |
| 6461 | try { |
| 6462 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6463 | } finally { |
| 6464 | Binder.restoreCallingIdentity(identity); |
| 6465 | } |
| 6466 | } |
| 6467 | |
| 6468 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6469 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6470 | enforceModifyPermission(); |
| 6471 | final Phone phone = getPhone(subId); |
| 6472 | if (phone == null) { |
| 6473 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6474 | return; |
| 6475 | } |
| 6476 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6477 | final long identity = Binder.clearCallingIdentity(); |
| 6478 | try { |
| 6479 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6480 | } finally { |
| 6481 | Binder.restoreCallingIdentity(identity); |
| 6482 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6483 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6484 | |
| 6485 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6486 | * A test API to reload the UICC profile. |
| 6487 | * |
| 6488 | * <p>Requires that the calling app has permission |
| 6489 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6490 | * @hide |
| 6491 | */ |
| 6492 | @Override |
| 6493 | public void refreshUiccProfile(int subId) { |
| 6494 | enforceModifyPermission(); |
| 6495 | |
| 6496 | final long identity = Binder.clearCallingIdentity(); |
| 6497 | try { |
| 6498 | Phone phone = getPhone(subId); |
| 6499 | if (phone == null) { |
| 6500 | return; |
| 6501 | } |
| 6502 | UiccCard uiccCard = phone.getUiccCard(); |
| 6503 | if (uiccCard == null) { |
| 6504 | return; |
| 6505 | } |
| 6506 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6507 | if (uiccProfile == null) { |
| 6508 | return; |
| 6509 | } |
| 6510 | uiccProfile.refresh(); |
| 6511 | } finally { |
| 6512 | Binder.restoreCallingIdentity(identity); |
| 6513 | } |
| 6514 | } |
| 6515 | |
| 6516 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6517 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6518 | */ |
| 6519 | private boolean getDefaultDataEnabled() { |
| 6520 | return "true".equalsIgnoreCase( |
| 6521 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6522 | } |
| 6523 | |
| 6524 | /** |
| 6525 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6526 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6527 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6528 | */ |
| 6529 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6530 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6531 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6532 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6533 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6534 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6535 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6536 | return isDataRoamingEnabled; |
| 6537 | } |
| 6538 | |
| 6539 | /** |
| 6540 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6541 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6542 | */ |
| 6543 | private int getDefaultNetworkType(int subId) { |
| 6544 | return Integer.parseInt( |
| 6545 | TelephonyManager.getTelephonyProperty( |
| 6546 | mSubscriptionController.getPhoneId(subId), |
| 6547 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6548 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6549 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6550 | |
| 6551 | @Override |
| 6552 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6553 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6554 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6555 | |
| 6556 | final long identity = Binder.clearCallingIdentity(); |
| 6557 | try { |
| 6558 | final Phone phone = getPhone(subId); |
| 6559 | if (phone == null) { |
| 6560 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6561 | return; |
| 6562 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6563 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 6564 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6565 | } finally { |
| 6566 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6567 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6568 | } |
| 6569 | |
| 6570 | @Override |
| 6571 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6572 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6573 | |
| 6574 | final long identity = Binder.clearCallingIdentity(); |
| 6575 | try { |
| 6576 | final Phone phone = getPhone(subId); |
| 6577 | if (phone == null) { |
| 6578 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6579 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6580 | } |
| 6581 | return phone.getCarrierIdListVersion(); |
| 6582 | } finally { |
| 6583 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6584 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6585 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6586 | |
| 6587 | @Override |
| 6588 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6589 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6590 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6591 | return -1; |
| 6592 | } |
| 6593 | |
| 6594 | final long identity = Binder.clearCallingIdentity(); |
| 6595 | try { |
| 6596 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6597 | } finally { |
| 6598 | Binder.restoreCallingIdentity(identity); |
| 6599 | } |
| 6600 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6601 | |
| 6602 | @Override |
| 6603 | public int getCdmaRoamingMode(int subId) { |
| 6604 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6605 | mApp, subId, "getCdmaRoamingMode"); |
| 6606 | |
| 6607 | final long identity = Binder.clearCallingIdentity(); |
| 6608 | try { |
| 6609 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6610 | } finally { |
| 6611 | Binder.restoreCallingIdentity(identity); |
| 6612 | } |
| 6613 | } |
| 6614 | |
| 6615 | @Override |
| 6616 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6617 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6618 | mApp, subId, "setCdmaRoamingMode"); |
| 6619 | |
| 6620 | final long identity = Binder.clearCallingIdentity(); |
| 6621 | try { |
| 6622 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6623 | } finally { |
| 6624 | Binder.restoreCallingIdentity(identity); |
| 6625 | } |
| 6626 | } |
| 6627 | |
| 6628 | @Override |
| 6629 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6631 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6632 | |
| 6633 | final long identity = Binder.clearCallingIdentity(); |
| 6634 | try { |
| 6635 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6636 | } finally { |
| 6637 | Binder.restoreCallingIdentity(identity); |
| 6638 | } |
| 6639 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 6640 | |
| 6641 | private void ensureUserRunning(int userId) { |
| 6642 | if (!mUserManager.isUserRunning(userId)) { |
| 6643 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6644 | } |
| 6645 | } |
| 6646 | |
| 6647 | /** |
| 6648 | * Returns a list of SMS apps on a given user. |
| 6649 | * |
| 6650 | * Only the shell user (UID 2000 or 0) can call it. |
| 6651 | * Target user must be running. |
| 6652 | */ |
| 6653 | @Override |
| 6654 | public String[] getSmsApps(int userId) { |
| 6655 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6656 | ensureUserRunning(userId); |
| 6657 | |
| 6658 | final Collection<SmsApplicationData> apps = |
| 6659 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6660 | |
| 6661 | String[] ret = new String[apps.size()]; |
| 6662 | int i = 0; |
| 6663 | for (SmsApplicationData app : apps) { |
| 6664 | ret[i++] = app.mPackageName; |
| 6665 | } |
| 6666 | return ret; |
| 6667 | } |
| 6668 | |
| 6669 | /** |
| 6670 | * Returns the default SMS app package name on a given user. |
| 6671 | * |
| 6672 | * Only the shell user (UID 2000 or 0) can call it. |
| 6673 | * Target user must be running. |
| 6674 | */ |
| 6675 | @Override |
| 6676 | public String getDefaultSmsApp(int userId) { |
| 6677 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6678 | ensureUserRunning(userId); |
| 6679 | |
| 6680 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6681 | /* updateIfNeeded= */ true, userId); |
| 6682 | return cn == null ? null : cn.getPackageName(); |
| 6683 | } |
| 6684 | |
| 6685 | /** |
| 6686 | * Set a package as the default SMS app on a given user. |
| 6687 | * |
| 6688 | * Only the shell user (UID 2000 or 0) can call it. |
| 6689 | * Target user must be running. |
| 6690 | */ |
| 6691 | @Override |
| 6692 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6693 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6694 | ensureUserRunning(userId); |
| 6695 | |
| 6696 | boolean found = false; |
| 6697 | for (String pkg : getSmsApps(userId)) { |
| 6698 | if (TextUtils.equals(packageName, pkg)) { |
| 6699 | found = true; |
| 6700 | break; |
| 6701 | } |
| 6702 | } |
| 6703 | if (!found) { |
| 6704 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6705 | } |
| 6706 | |
| 6707 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6708 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6709 | |
| 6710 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6711 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6712 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6713 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6714 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6715 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6716 | } |
| 6717 | final long identity = Binder.clearCallingIdentity(); |
| 6718 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6719 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6720 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6721 | if (phone.getEmergencyNumberTracker() != null |
| 6722 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6723 | emergencyNumberListInternal.put( |
| 6724 | phone.getSubId(), |
| 6725 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6726 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6727 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6728 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6729 | } finally { |
| 6730 | Binder.restoreCallingIdentity(identity); |
| 6731 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6732 | } |
| 6733 | |
| 6734 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6735 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6736 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6737 | if (!exactMatch) { |
| 6738 | TelephonyPermissions |
| 6739 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6740 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6741 | } |
| 6742 | final long identity = Binder.clearCallingIdentity(); |
| 6743 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6744 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6745 | if (phone.getEmergencyNumberTracker() != null |
| 6746 | && phone.getEmergencyNumberTracker() != null) { |
| 6747 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6748 | number, exactMatch)) { |
| 6749 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6750 | } |
| 6751 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6752 | } |
| 6753 | return false; |
| 6754 | } finally { |
| 6755 | Binder.restoreCallingIdentity(identity); |
| 6756 | } |
| 6757 | } |
| 6758 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6759 | /** |
| 6760 | * Update emergency number list for test mode. |
| 6761 | */ |
| 6762 | @Override |
| 6763 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6764 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6765 | "updateEmergencyNumberListTestMode"); |
| 6766 | |
| 6767 | final long identity = Binder.clearCallingIdentity(); |
| 6768 | try { |
| 6769 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6770 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6771 | if (tracker != null) { |
| 6772 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6773 | } |
| 6774 | } |
| 6775 | } finally { |
| 6776 | Binder.restoreCallingIdentity(identity); |
| 6777 | } |
| 6778 | } |
| 6779 | |
| 6780 | /** |
| 6781 | * Get the full emergency number list for test mode. |
| 6782 | */ |
| 6783 | @Override |
| 6784 | public List<String> getEmergencyNumberListTestMode() { |
| 6785 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6786 | "getEmergencyNumberListTestMode"); |
| 6787 | |
| 6788 | final long identity = Binder.clearCallingIdentity(); |
| 6789 | try { |
| 6790 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6791 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6792 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6793 | if (tracker != null) { |
| 6794 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6795 | emergencyNumbers.add(num.getNumber()); |
| 6796 | } |
| 6797 | } |
| 6798 | } |
| 6799 | return new ArrayList<>(emergencyNumbers); |
| 6800 | } finally { |
| 6801 | Binder.restoreCallingIdentity(identity); |
| 6802 | } |
| 6803 | } |
| 6804 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6805 | @Override |
| 6806 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6807 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6808 | Phone phone = getPhone(subId); |
| 6809 | if (phone == null) { |
| 6810 | return null; |
| 6811 | } |
| 6812 | final long identity = Binder.clearCallingIdentity(); |
| 6813 | try { |
| 6814 | UiccProfile profile = UiccController.getInstance() |
| 6815 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6816 | if (profile != null) { |
| 6817 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6818 | } |
| 6819 | } finally { |
| 6820 | Binder.restoreCallingIdentity(identity); |
| 6821 | } |
| 6822 | return null; |
| 6823 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6824 | |
| 6825 | /** |
| 6826 | * Enable or disable a modem stack. |
| 6827 | */ |
| 6828 | @Override |
| 6829 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6830 | enforceModifyPermission(); |
| 6831 | |
| 6832 | final long identity = Binder.clearCallingIdentity(); |
| 6833 | try { |
| 6834 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6835 | if (phone == null) { |
| 6836 | return false; |
| 6837 | } else { |
| 6838 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6839 | } |
| 6840 | } finally { |
| 6841 | Binder.restoreCallingIdentity(identity); |
| 6842 | } |
| 6843 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6844 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6845 | /** |
| 6846 | * Whether a modem stack is enabled or not. |
| 6847 | */ |
| 6848 | @Override |
| 6849 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 6850 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6851 | if (phone == null) return false; |
| 6852 | |
| 6853 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6854 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 6855 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6856 | } |
| 6857 | |
| 6858 | final long identity = Binder.clearCallingIdentity(); |
| 6859 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 6860 | try { |
| 6861 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 6862 | } catch (NoSuchElementException ex) { |
| 6863 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 6864 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6865 | } finally { |
| 6866 | Binder.restoreCallingIdentity(identity); |
| 6867 | } |
| 6868 | } |
| 6869 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6870 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6871 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6872 | enforceModifyPermission(); |
| 6873 | |
| 6874 | final long identity = Binder.clearCallingIdentity(); |
| 6875 | try { |
| 6876 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6877 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6878 | .commit(); |
| 6879 | } finally { |
| 6880 | Binder.restoreCallingIdentity(identity); |
| 6881 | } |
| 6882 | } |
| 6883 | |
| 6884 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6885 | @TelephonyManager.IsMultiSimSupportedResult |
| 6886 | public int isMultiSimSupported(String callingPackage) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6887 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6888 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 6889 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6890 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6891 | |
| 6892 | final long identity = Binder.clearCallingIdentity(); |
| 6893 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6894 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6895 | } finally { |
| 6896 | Binder.restoreCallingIdentity(identity); |
| 6897 | } |
| 6898 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6899 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6900 | @TelephonyManager.IsMultiSimSupportedResult |
| 6901 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6902 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6903 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6904 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6905 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 6906 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6907 | } |
| 6908 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 6909 | // supported by the modem, indicate that it is restricted. |
| 6910 | PhoneCapability staticCapability = |
| 6911 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 6912 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6913 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 6914 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6915 | } |
| 6916 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6917 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 6918 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6919 | } |
| 6920 | // Check if support of multiple SIMs is restricted by carrier |
| 6921 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6922 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6923 | } |
| 6924 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6925 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6926 | } |
| 6927 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6928 | /** |
| 6929 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6930 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 6931 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 6932 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6933 | * @param numOfSims number of active sims we want to switch to |
| 6934 | */ |
| 6935 | @Override |
| 6936 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6937 | if (numOfSims == 1) { |
| 6938 | enforceModifyPermission(); |
| 6939 | } else { |
| 6940 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6941 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6942 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6943 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6944 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6945 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6946 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6947 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6948 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 6949 | return; |
| 6950 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6951 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 6952 | } finally { |
| 6953 | Binder.restoreCallingIdentity(identity); |
| 6954 | } |
| 6955 | } |
| 6956 | |
| 6957 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 6958 | * Get whether making changes to modem configurations will trigger reboot. |
| 6959 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6960 | */ |
| 6961 | @Override |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 6962 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) { |
| 6963 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6964 | mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) { |
| 6965 | return false; |
| 6966 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6967 | final long identity = Binder.clearCallingIdentity(); |
| 6968 | try { |
| 6969 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 6970 | } finally { |
| 6971 | Binder.restoreCallingIdentity(identity); |
| 6972 | } |
| 6973 | } |
| 6974 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 6975 | private void updateModemStateMetrics() { |
| 6976 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 6977 | // TODO: check the state for each modem if the api is ready. |
| 6978 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 6979 | } |
| 6980 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 6981 | @Override |
| 6982 | public int[] getSlotsMapping() { |
| 6983 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 6984 | |
| 6985 | final long identity = Binder.clearCallingIdentity(); |
| 6986 | try { |
| 6987 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 6988 | // All logical slots should have a mapping to a physical slot. |
| 6989 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 6990 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 6991 | for (int i = 0; i < slotInfos.length; i++) { |
| 6992 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 6993 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 6994 | } |
| 6995 | } |
| 6996 | return logicalSlotsMapping; |
| 6997 | } finally { |
| 6998 | Binder.restoreCallingIdentity(identity); |
| 6999 | } |
| 7000 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7001 | |
| 7002 | /** |
| 7003 | * Get the IRadio HAL Version |
| 7004 | */ |
| 7005 | @Override |
| 7006 | public int getRadioHalVersion() { |
| 7007 | Phone phone = getDefaultPhone(); |
| 7008 | if (phone == null) return -1; |
| 7009 | HalVersion hv = phone.getHalVersion(); |
| 7010 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7011 | return hv.major * 100 + hv.minor; |
| 7012 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7013 | |
| 7014 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7015 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7016 | * corresponding network requests on a subId. |
| 7017 | * |
| 7018 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7019 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7020 | * 2) APN is un-metered for this subscription, or |
| 7021 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7022 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7023 | * |
| 7024 | * @return whether data is allowed for a apn type. |
| 7025 | * |
| 7026 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7027 | */ |
| 7028 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7029 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7030 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7031 | mApp, subId, callingPackage, "isDataEnabledForApn")) { |
| 7032 | throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7033 | } |
| 7034 | |
| 7035 | // Now that all security checks passes, perform the operation as ourselves. |
| 7036 | final long identity = Binder.clearCallingIdentity(); |
| 7037 | try { |
| 7038 | Phone phone = getPhone(subId); |
| 7039 | if (phone == null) return false; |
| 7040 | |
| 7041 | boolean isMetered = ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString( |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7042 | apnType), phone); |
| 7043 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7044 | } finally { |
| 7045 | Binder.restoreCallingIdentity(identity); |
| 7046 | } |
| 7047 | } |
| 7048 | |
| 7049 | @Override |
| 7050 | public boolean isApnMetered(int apnType, int subId) { |
| 7051 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7052 | |
| 7053 | // Now that all security checks passes, perform the operation as ourselves. |
| 7054 | final long identity = Binder.clearCallingIdentity(); |
| 7055 | try { |
| 7056 | Phone phone = getPhone(subId); |
| 7057 | if (phone == null) return true; // By default return true. |
| 7058 | |
| 7059 | return ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString( |
| 7060 | apnType), phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7061 | } finally { |
| 7062 | Binder.restoreCallingIdentity(identity); |
| 7063 | } |
| 7064 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7065 | } |