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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 25 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 26 | import android.content.ComponentName; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 29 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 30 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 31 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 32 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 33 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 34 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.net.Uri; |
| 36 | import android.os.AsyncResult; |
| 37 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 38 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.os.Bundle; |
| 40 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 41 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Looper; |
| 43 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 45 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 46 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 47 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 49 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 50 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 52 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 53 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 54 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 55 | import android.provider.Settings; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 56 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 57 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 58 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 59 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 60 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 61 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 62 | import android.telephony.CellInfoGsm; |
| 63 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 64 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 65 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 66 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 67 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 68 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 69 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 70 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 71 | import android.telephony.NetworkScanRequest; |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 72 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 73 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 74 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 75 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 76 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 77 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 78 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 79 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 80 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 81 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 82 | import android.telephony.TelephonyManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 83 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 84 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 85 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 86 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 87 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 88 | import android.telephony.data.ApnSetting; |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 89 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 90 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 91 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 92 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 93 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 94 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 95 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 96 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 97 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 98 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 99 | import android.telephony.ims.feature.MmTelFeature; |
| 100 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 101 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 102 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 103 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 105 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 106 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 107 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 108 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 109 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 110 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 111 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 112 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 113 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 114 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 115 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 118 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 119 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 121 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 123 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.Phone; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 128 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.ServiceStateTracker; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.SmsApplication; |
| 136 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.TelephonyPermissions; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.euicc.EuiccConnector; |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.uicc.IccIoResult; |
| 143 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 149 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 151 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 152 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 153 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 154 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 155 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 156 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 157 | import java.io.FileDescriptor; |
| 158 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 159 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 160 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 161 | import java.util.Arrays; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 162 | import java.util.Collection; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 163 | import java.util.HashMap; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 164 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 165 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 166 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 167 | import java.util.Map; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 168 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 169 | |
| 170 | /** |
| 171 | * Implementation of the ITelephony interface. |
| 172 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 173 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 174 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 175 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 176 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 177 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 178 | |
| 179 | // Message codes used with mMainThreadHandler |
| 180 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 181 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 182 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 183 | private static final int CMD_OPEN_CHANNEL = 9; |
| 184 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 185 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 186 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 187 | private static final int CMD_NV_READ_ITEM = 13; |
| 188 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 189 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 190 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 191 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 192 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 193 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 194 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 195 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 196 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 197 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 198 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 199 | private static final int CMD_SEND_ENVELOPE = 25; |
| 200 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 201 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 202 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 203 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 204 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 205 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 206 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 207 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 208 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 209 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 210 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 211 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 212 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 213 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 214 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 215 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 216 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 217 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 218 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 219 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 220 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 221 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 222 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 223 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 224 | private static final int CMD_SWITCH_SLOTS = 50; |
| 225 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 226 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 227 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 228 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 229 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 230 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 231 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 232 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 233 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 234 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 235 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 236 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 237 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 238 | private static final int CMD_MODEM_REBOOT = 64; |
| 239 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 240 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 241 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 242 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 243 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 244 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 245 | // Parameters of select command. |
| 246 | private static final int SELECT_COMMAND = 0xA4; |
| 247 | private static final int SELECT_P1 = 0x04; |
| 248 | private static final int SELECT_P2 = 0; |
| 249 | private static final int SELECT_P3 = 0x10; |
| 250 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 251 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 252 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 253 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 254 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 255 | /** The singleton instance. */ |
| 256 | private static PhoneInterfaceManager sInstance; |
| 257 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 258 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 259 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 260 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 261 | private AppOpsManager mAppOps; |
| 262 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 263 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 264 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 265 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 266 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 267 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 268 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 269 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 270 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 271 | |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 272 | // String to store multi SIM allowed |
| 273 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 274 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 275 | // The AID of ISD-R. |
| 276 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 277 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 278 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 279 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 280 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 281 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 282 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 283 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 284 | * A request object to use for transmitting data to an ICC. |
| 285 | */ |
| 286 | private static final class IccAPDUArgument { |
| 287 | public int channel, cla, command, p1, p2, p3; |
| 288 | public String data; |
| 289 | |
| 290 | public IccAPDUArgument(int channel, int cla, int command, |
| 291 | int p1, int p2, int p3, String data) { |
| 292 | this.channel = channel; |
| 293 | this.cla = cla; |
| 294 | this.command = command; |
| 295 | this.p1 = p1; |
| 296 | this.p2 = p2; |
| 297 | this.p3 = p3; |
| 298 | this.data = data; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 303 | * A request object to use for transmitting data to an ICC. |
| 304 | */ |
| 305 | private static final class ManualNetworkSelectionArgument { |
| 306 | public OperatorInfo operatorInfo; |
| 307 | public boolean persistSelection; |
| 308 | |
| 309 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 310 | this.operatorInfo = operatorInfo; |
| 311 | this.persistSelection = persistSelection; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 316 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 317 | * request after sending. The main thread will notify the request when it is complete. |
| 318 | */ |
| 319 | private static final class MainThreadRequest { |
| 320 | /** The argument to use for the request */ |
| 321 | public Object argument; |
| 322 | /** The result of the request that is run on the main thread */ |
| 323 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 324 | // The subscriber id that this request applies to. Defaults to |
| 325 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 326 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 327 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 328 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 329 | public Phone phone; |
| 330 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 331 | public WorkSource workSource; |
| 332 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 333 | public MainThreadRequest(Object argument) { |
| 334 | this.argument = argument; |
| 335 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 336 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 337 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 338 | this.argument = argument; |
| 339 | if (phone != null) { |
| 340 | this.phone = phone; |
| 341 | } |
| 342 | this.workSource = workSource; |
| 343 | } |
| 344 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 345 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 346 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 347 | if (subId != null) { |
| 348 | this.subId = subId; |
| 349 | } |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 350 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 351 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 354 | private static final class IncomingThirdPartyCallArgs { |
| 355 | public final ComponentName component; |
| 356 | public final String callId; |
| 357 | public final String callerDisplayName; |
| 358 | |
| 359 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 360 | String callerDisplayName) { |
| 361 | this.component = component; |
| 362 | this.callId = callId; |
| 363 | this.callerDisplayName = callerDisplayName; |
| 364 | } |
| 365 | } |
| 366 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 367 | /** |
| 368 | * A handler that processes messages on the main thread in the phone process. Since many |
| 369 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 370 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 371 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 372 | * on, which will be notified when the operation completes and will contain the result of the |
| 373 | * request. |
| 374 | * |
| 375 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 376 | * note that request.result must be set to something non-null for the calling thread to |
| 377 | * unblock. |
| 378 | */ |
| 379 | private final class MainThreadHandler extends Handler { |
| 380 | @Override |
| 381 | public void handleMessage(Message msg) { |
| 382 | MainThreadRequest request; |
| 383 | Message onCompleted; |
| 384 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 385 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 386 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 387 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 388 | |
| 389 | switch (msg.what) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 390 | case CMD_HANDLE_USSD_REQUEST: { |
| 391 | request = (MainThreadRequest) msg.obj; |
| 392 | final Phone phone = getPhoneFromRequest(request); |
| 393 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 394 | String ussdRequest = ussdObject.first; |
| 395 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 396 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 397 | if (!isUssdApiAllowed(request.subId)) { |
| 398 | // Carrier does not support use of this API, return failure. |
| 399 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 400 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 401 | Bundle returnData = new Bundle(); |
| 402 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 403 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 404 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 405 | request.result = true; |
| 406 | notifyRequester(request); |
| 407 | return; |
| 408 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 409 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 410 | try { |
| 411 | request.result = phone != null |
| 412 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 413 | } catch (CallStateException cse) { |
| 414 | request.result = false; |
| 415 | } |
| 416 | // Wake up the requesting thread |
| 417 | notifyRequester(request); |
| 418 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 421 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 422 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 423 | final Phone phone = getPhoneFromRequest(request); |
| 424 | request.result = phone != null ? |
| 425 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 426 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | // Wake up the requesting thread |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 428 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 429 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 430 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 431 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 432 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 433 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 434 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 435 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 436 | if (uiccCard == null) { |
| 437 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 438 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 439 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 440 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 441 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 442 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 443 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 444 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 445 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 446 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 447 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 448 | break; |
| 449 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 450 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 451 | ar = (AsyncResult) msg.obj; |
| 452 | request = (MainThreadRequest) ar.userObj; |
| 453 | if (ar.exception == null && ar.result != null) { |
| 454 | request.result = ar.result; |
| 455 | } else { |
| 456 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 457 | if (ar.result == null) { |
| 458 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 459 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 460 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 461 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 462 | } else { |
| 463 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 464 | } |
| 465 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 466 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 467 | break; |
| 468 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 469 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 470 | request = (MainThreadRequest) msg.obj; |
| 471 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 472 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 473 | if (uiccCard == null) { |
| 474 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 475 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 476 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 477 | } else { |
| 478 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 479 | request); |
| 480 | uiccCard.iccTransmitApduBasicChannel( |
| 481 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 482 | iccArgument.p3, iccArgument.data, onCompleted); |
| 483 | } |
| 484 | break; |
| 485 | |
| 486 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 487 | ar = (AsyncResult) msg.obj; |
| 488 | request = (MainThreadRequest) ar.userObj; |
| 489 | if (ar.exception == null && ar.result != null) { |
| 490 | request.result = ar.result; |
| 491 | } else { |
| 492 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 493 | if (ar.result == null) { |
| 494 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 495 | } else if (ar.exception instanceof CommandException) { |
| 496 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 497 | ar.exception); |
| 498 | } else { |
| 499 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 500 | } |
| 501 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 502 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 503 | break; |
| 504 | |
| 505 | case CMD_EXCHANGE_SIM_IO: |
| 506 | request = (MainThreadRequest) msg.obj; |
| 507 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 508 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 509 | if (uiccCard == null) { |
| 510 | loge("iccExchangeSimIO: No UICC"); |
| 511 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 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 | } else { |
| 514 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 515 | request); |
| 516 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 517 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 518 | iccArgument.data, onCompleted); |
| 519 | } |
| 520 | break; |
| 521 | |
| 522 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 523 | ar = (AsyncResult) msg.obj; |
| 524 | request = (MainThreadRequest) ar.userObj; |
| 525 | if (ar.exception == null && ar.result != null) { |
| 526 | request.result = ar.result; |
| 527 | } else { |
| 528 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 529 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 530 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 531 | break; |
| 532 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 533 | case CMD_SEND_ENVELOPE: |
| 534 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 535 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 536 | if (uiccCard == null) { |
| 537 | loge("sendEnvelopeWithStatus: No UICC"); |
| 538 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 539 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 540 | } else { |
| 541 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 542 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 543 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 544 | break; |
| 545 | |
| 546 | case EVENT_SEND_ENVELOPE_DONE: |
| 547 | ar = (AsyncResult) msg.obj; |
| 548 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 549 | if (ar.exception == null && ar.result != null) { |
| 550 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 551 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 552 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 553 | if (ar.result == null) { |
| 554 | loge("sendEnvelopeWithStatus: Empty response"); |
| 555 | } else if (ar.exception instanceof CommandException) { |
| 556 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 557 | ar.exception); |
| 558 | } else { |
| 559 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 560 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 561 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 562 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 563 | break; |
| 564 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 565 | case CMD_OPEN_CHANNEL: |
| 566 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 567 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 568 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 569 | if (uiccCard == null) { |
| 570 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 571 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 572 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 573 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 574 | } else { |
| 575 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 576 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 577 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 578 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 579 | break; |
| 580 | |
| 581 | case EVENT_OPEN_CHANNEL_DONE: |
| 582 | ar = (AsyncResult) msg.obj; |
| 583 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 584 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 585 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 586 | int[] result = (int[]) ar.result; |
| 587 | int channelId = result[0]; |
| 588 | byte[] selectResponse = null; |
| 589 | if (result.length > 1) { |
| 590 | selectResponse = new byte[result.length - 1]; |
| 591 | for (int i = 1; i < result.length; ++i) { |
| 592 | selectResponse[i - 1] = (byte) result[i]; |
| 593 | } |
| 594 | } |
| 595 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 596 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 597 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 598 | if (ar.result == null) { |
| 599 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 600 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 601 | if (ar.exception != null) { |
| 602 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 603 | } |
| 604 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 605 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 606 | if (ar.exception instanceof CommandException) { |
| 607 | CommandException.Error error = |
| 608 | ((CommandException) (ar.exception)).getCommandError(); |
| 609 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 610 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 611 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 612 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 616 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 617 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 618 | request.result = openChannelResp; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 619 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 620 | break; |
| 621 | |
| 622 | case CMD_CLOSE_CHANNEL: |
| 623 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 624 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 625 | if (uiccCard == null) { |
| 626 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 627 | request.result = false; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 628 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 629 | } else { |
| 630 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 631 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 632 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 633 | break; |
| 634 | |
| 635 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 636 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 637 | break; |
| 638 | |
| 639 | case CMD_NV_READ_ITEM: |
| 640 | request = (MainThreadRequest) msg.obj; |
| 641 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 642 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 643 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 644 | break; |
| 645 | |
| 646 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | ar = (AsyncResult) msg.obj; |
| 648 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 649 | if (ar.exception == null && ar.result != null) { |
| 650 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 651 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 652 | request.result = ""; |
| 653 | if (ar.result == null) { |
| 654 | loge("nvReadItem: Empty response"); |
| 655 | } else if (ar.exception instanceof CommandException) { |
| 656 | loge("nvReadItem: CommandException: " + |
| 657 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 658 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 659 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | } |
| 661 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 662 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | break; |
| 664 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 665 | case CMD_NV_WRITE_ITEM: |
| 666 | request = (MainThreadRequest) msg.obj; |
| 667 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 668 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 669 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 670 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 671 | break; |
| 672 | |
| 673 | case EVENT_NV_WRITE_ITEM_DONE: |
| 674 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 675 | break; |
| 676 | |
| 677 | case CMD_NV_WRITE_CDMA_PRL: |
| 678 | request = (MainThreadRequest) msg.obj; |
| 679 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 680 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 681 | break; |
| 682 | |
| 683 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 684 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 685 | break; |
| 686 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 687 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 688 | request = (MainThreadRequest) msg.obj; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 689 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 690 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 691 | break; |
| 692 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 693 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 694 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 695 | break; |
| 696 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 697 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 698 | request = (MainThreadRequest) msg.obj; |
| 699 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 700 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 701 | break; |
| 702 | |
| 703 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 704 | ar = (AsyncResult) msg.obj; |
| 705 | request = (MainThreadRequest) ar.userObj; |
| 706 | if (ar.exception == null && ar.result != null) { |
| 707 | request.result = ar.result; // Integer |
| 708 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 709 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 710 | if (ar.result == null) { |
| 711 | loge("getPreferredNetworkType: Empty response"); |
| 712 | } else if (ar.exception instanceof CommandException) { |
| 713 | loge("getPreferredNetworkType: CommandException: " + |
| 714 | ar.exception); |
| 715 | } else { |
| 716 | loge("getPreferredNetworkType: Unknown exception"); |
| 717 | } |
| 718 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 719 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 720 | break; |
| 721 | |
| 722 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 723 | request = (MainThreadRequest) msg.obj; |
| 724 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 725 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 726 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 730 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 731 | break; |
| 732 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 733 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 734 | request = (MainThreadRequest)msg.obj; |
| 735 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 736 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 737 | break; |
| 738 | |
| 739 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 740 | ar = (AsyncResult)msg.obj; |
| 741 | request = (MainThreadRequest)ar.userObj; |
| 742 | request.result = ar; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 743 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 744 | break; |
| 745 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 746 | case CMD_SET_VOICEMAIL_NUMBER: |
| 747 | request = (MainThreadRequest) msg.obj; |
| 748 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 749 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 750 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 751 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 752 | break; |
| 753 | |
| 754 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 755 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 756 | break; |
| 757 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 758 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 759 | request = (MainThreadRequest) msg.obj; |
| 760 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 761 | request); |
| 762 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 763 | break; |
| 764 | |
| 765 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 766 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 767 | break; |
| 768 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 769 | case CMD_PERFORM_NETWORK_SCAN: |
| 770 | request = (MainThreadRequest) msg.obj; |
| 771 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 772 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 773 | break; |
| 774 | |
| 775 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 776 | ar = (AsyncResult) msg.obj; |
| 777 | request = (MainThreadRequest) ar.userObj; |
| 778 | CellNetworkScanResult cellScanResult; |
| 779 | if (ar.exception == null && ar.result != null) { |
| 780 | cellScanResult = new CellNetworkScanResult( |
| 781 | CellNetworkScanResult.STATUS_SUCCESS, |
| 782 | (List<OperatorInfo>) ar.result); |
| 783 | } else { |
| 784 | if (ar.result == null) { |
| 785 | loge("getCellNetworkScanResults: Empty response"); |
| 786 | } |
| 787 | if (ar.exception != null) { |
| 788 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 789 | } |
| 790 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 791 | if (ar.exception instanceof CommandException) { |
| 792 | CommandException.Error error = |
| 793 | ((CommandException) (ar.exception)).getCommandError(); |
| 794 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 795 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 796 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 797 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 798 | } |
| 799 | } |
| 800 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 801 | } |
| 802 | request.result = cellScanResult; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 803 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 804 | break; |
| 805 | |
| 806 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 807 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 808 | ManualNetworkSelectionArgument selArg = |
| 809 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 810 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 811 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 812 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 813 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 814 | break; |
| 815 | |
| 816 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 817 | ar = (AsyncResult) msg.obj; |
| 818 | request = (MainThreadRequest) ar.userObj; |
| 819 | if (ar.exception == null) { |
| 820 | request.result = true; |
| 821 | } else { |
| 822 | request.result = false; |
| 823 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 824 | } |
| 825 | notifyRequester(request); |
| 826 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 827 | break; |
| 828 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 829 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 830 | request = (MainThreadRequest) msg.obj; |
| 831 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 832 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 833 | break; |
| 834 | |
| 835 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 836 | ar = (AsyncResult) msg.obj; |
| 837 | request = (MainThreadRequest) ar.userObj; |
| 838 | if (ar.exception == null && ar.result != null) { |
| 839 | request.result = ar.result; |
| 840 | } else { |
| 841 | if (ar.result == null) { |
| 842 | loge("queryModemActivityInfo: Empty response"); |
| 843 | } else if (ar.exception instanceof CommandException) { |
| 844 | loge("queryModemActivityInfo: CommandException: " + |
| 845 | ar.exception); |
| 846 | } else { |
| 847 | loge("queryModemActivityInfo: Unknown exception"); |
| 848 | } |
| 849 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 850 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 851 | if (request.result == null) { |
| 852 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 853 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 854 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 855 | break; |
| 856 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 857 | case CMD_SET_ALLOWED_CARRIERS: |
| 858 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 859 | CarrierRestrictionRules argument = |
| 860 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 861 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 862 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 863 | break; |
| 864 | |
| 865 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 866 | ar = (AsyncResult) msg.obj; |
| 867 | request = (MainThreadRequest) ar.userObj; |
| 868 | if (ar.exception == null && ar.result != null) { |
| 869 | request.result = ar.result; |
| 870 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 871 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 872 | if (ar.exception instanceof CommandException) { |
| 873 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 874 | CommandException.Error error = |
| 875 | ((CommandException) (ar.exception)).getCommandError(); |
| 876 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 877 | request.result = |
| 878 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 879 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 880 | } else { |
| 881 | loge("setAllowedCarriers: Unknown exception"); |
| 882 | } |
| 883 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 884 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 885 | break; |
| 886 | |
| 887 | case CMD_GET_ALLOWED_CARRIERS: |
| 888 | request = (MainThreadRequest) msg.obj; |
| 889 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 890 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 891 | break; |
| 892 | |
| 893 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 894 | ar = (AsyncResult) msg.obj; |
| 895 | request = (MainThreadRequest) ar.userObj; |
| 896 | if (ar.exception == null && ar.result != null) { |
| 897 | request.result = ar.result; |
| 898 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 899 | request.result = new IllegalStateException( |
| 900 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 901 | if (ar.result == null) { |
| 902 | loge("getAllowedCarriers: Empty response"); |
| 903 | } else if (ar.exception instanceof CommandException) { |
| 904 | loge("getAllowedCarriers: CommandException: " + |
| 905 | ar.exception); |
| 906 | } else { |
| 907 | loge("getAllowedCarriers: Unknown exception"); |
| 908 | } |
| 909 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 910 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 911 | break; |
| 912 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 913 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 914 | ar = (AsyncResult) msg.obj; |
| 915 | request = (MainThreadRequest) ar.userObj; |
| 916 | if (ar.exception == null && ar.result != null) { |
| 917 | request.result = ar.result; |
| 918 | } else { |
| 919 | request.result = new IllegalArgumentException( |
| 920 | "Failed to retrieve Forbidden Plmns"); |
| 921 | if (ar.result == null) { |
| 922 | loge("getForbiddenPlmns: Empty response"); |
| 923 | } else { |
| 924 | loge("getForbiddenPlmns: Unknown exception"); |
| 925 | } |
| 926 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 927 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 928 | break; |
| 929 | |
| 930 | case CMD_GET_FORBIDDEN_PLMNS: |
| 931 | request = (MainThreadRequest) msg.obj; |
| 932 | uiccCard = getUiccCardFromRequest(request); |
| 933 | if (uiccCard == null) { |
| 934 | loge("getForbiddenPlmns() UiccCard is null"); |
| 935 | request.result = new IllegalArgumentException( |
| 936 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 937 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 938 | break; |
| 939 | } |
| 940 | Integer appType = (Integer) request.argument; |
| 941 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 942 | if (uiccApp == null) { |
| 943 | loge("getForbiddenPlmns() no app with specified type -- " |
| 944 | + appType); |
| 945 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 946 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 947 | break; |
| 948 | } else { |
| 949 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 950 | + " specified type -- " + appType); |
| 951 | } |
| 952 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 953 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 954 | onCompleted); |
| 955 | break; |
| 956 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 957 | case CMD_SWITCH_SLOTS: |
| 958 | request = (MainThreadRequest) msg.obj; |
| 959 | int[] physicalSlots = (int[]) request.argument; |
| 960 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 961 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 962 | break; |
| 963 | |
| 964 | case EVENT_SWITCH_SLOTS_DONE: |
| 965 | ar = (AsyncResult) msg.obj; |
| 966 | request = (MainThreadRequest) ar.userObj; |
| 967 | request.result = (ar.exception == null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 968 | notifyRequester(request); |
| 969 | break; |
| 970 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 971 | request = (MainThreadRequest) msg.obj; |
| 972 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 973 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 974 | break; |
| 975 | |
| 976 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 977 | ar = (AsyncResult) msg.obj; |
| 978 | request = (MainThreadRequest) ar.userObj; |
| 979 | if (ar.exception != null) { |
| 980 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 981 | } else { |
| 982 | int mode = ((int[]) ar.result)[0]; |
| 983 | if (mode == 0) { |
| 984 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 985 | } else { |
| 986 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 987 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 988 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 989 | notifyRequester(request); |
| 990 | break; |
| 991 | case CMD_GET_CDMA_ROAMING_MODE: |
| 992 | request = (MainThreadRequest) msg.obj; |
| 993 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 994 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 995 | break; |
| 996 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 997 | ar = (AsyncResult) msg.obj; |
| 998 | request = (MainThreadRequest) ar.userObj; |
| 999 | if (ar.exception != null) { |
| 1000 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1001 | } else { |
| 1002 | request.result = ((int[]) ar.result)[0]; |
| 1003 | } |
| 1004 | notifyRequester(request); |
| 1005 | break; |
| 1006 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1007 | request = (MainThreadRequest) msg.obj; |
| 1008 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1009 | int mode = (int) request.argument; |
| 1010 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1011 | break; |
| 1012 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1013 | ar = (AsyncResult) msg.obj; |
| 1014 | request = (MainThreadRequest) ar.userObj; |
| 1015 | request.result = ar.exception == null; |
| 1016 | notifyRequester(request); |
| 1017 | break; |
| 1018 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1019 | request = (MainThreadRequest) msg.obj; |
| 1020 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1021 | int subscriptionMode = (int) request.argument; |
| 1022 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1023 | break; |
| 1024 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1025 | ar = (AsyncResult) msg.obj; |
| 1026 | request = (MainThreadRequest) ar.userObj; |
| 1027 | request.result = ar.exception == null; |
| 1028 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1029 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1030 | case CMD_GET_ALL_CELL_INFO: |
| 1031 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1032 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1033 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1034 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1035 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1036 | ar = (AsyncResult) msg.obj; |
| 1037 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1038 | // If a timeout occurs, the response will be null |
| 1039 | request.result = (ar.exception == null && ar.result != null) |
| 1040 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1041 | synchronized (request) { |
| 1042 | request.notifyAll(); |
| 1043 | } |
| 1044 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1045 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1046 | request = (MainThreadRequest) msg.obj; |
| 1047 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1048 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1049 | break; |
| 1050 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1051 | ar = (AsyncResult) msg.obj; |
| 1052 | request = (MainThreadRequest) ar.userObj; |
| 1053 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1054 | try { |
| 1055 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1056 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1057 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1058 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1059 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1060 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1061 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1062 | } else { |
| 1063 | // use the result as returned |
| 1064 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1065 | } |
| 1066 | } catch (RemoteException re) { |
| 1067 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1068 | } |
| 1069 | break; |
| 1070 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1071 | request = (MainThreadRequest) msg.obj; |
| 1072 | WorkSource ws = (WorkSource) request.argument; |
| 1073 | Phone phone = getPhoneFromRequest(request); |
| 1074 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1075 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1076 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1077 | ar = (AsyncResult) msg.obj; |
| 1078 | request = (MainThreadRequest) ar.userObj; |
| 1079 | if (ar.exception == null) { |
| 1080 | request.result = ar.result; |
| 1081 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1082 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1083 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1084 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1085 | } |
| 1086 | |
| 1087 | synchronized (request) { |
| 1088 | request.notifyAll(); |
| 1089 | } |
| 1090 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1091 | case CMD_MODEM_REBOOT: |
| 1092 | request = (MainThreadRequest) msg.obj; |
| 1093 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1094 | defaultPhone.rebootModem(onCompleted); |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1095 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1096 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1097 | handleNullReturnEvent(msg, "rebootModem"); |
| 1098 | break; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1099 | case CMD_REQUEST_ENABLE_MODEM: |
| 1100 | request = (MainThreadRequest) msg.obj; |
| 1101 | boolean enable = (boolean) request.argument; |
| 1102 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1103 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1104 | PhoneConfigurationManager.getInstance() |
| 1105 | .enablePhone(request.phone, enable, onCompleted); |
| 1106 | break; |
| 1107 | case EVENT_ENABLE_MODEM_DONE: |
| 1108 | ar = (AsyncResult) msg.obj; |
| 1109 | request = (MainThreadRequest) ar.userObj; |
| 1110 | request.result = (ar.exception == null); |
Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1111 | //update the cache as modem status has changed |
| 1112 | mPhoneConfigurationManager.addToPhoneStatusCache( |
| 1113 | request.phone.getPhoneId(), msg.arg1 == 1); |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 1114 | updateModemStateMetrics(); |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1115 | notifyRequester(request); |
| 1116 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1117 | default: |
| 1118 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1119 | break; |
| 1120 | } |
| 1121 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1122 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1123 | private void notifyRequester(MainThreadRequest request) { |
| 1124 | synchronized (request) { |
| 1125 | request.notifyAll(); |
| 1126 | } |
| 1127 | } |
| 1128 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1129 | private void handleNullReturnEvent(Message msg, String command) { |
| 1130 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1131 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1132 | if (ar.exception == null) { |
| 1133 | request.result = true; |
| 1134 | } else { |
| 1135 | request.result = false; |
| 1136 | if (ar.exception instanceof CommandException) { |
| 1137 | loge(command + ": CommandException: " + ar.exception); |
| 1138 | } else { |
| 1139 | loge(command + ": Unknown exception"); |
| 1140 | } |
| 1141 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1142 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1143 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | /** |
| 1147 | * Posts the specified command to be executed on the main thread, |
| 1148 | * waits for the request to complete, and returns the result. |
| 1149 | * @see #sendRequestAsync |
| 1150 | */ |
| 1151 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1152 | return sendRequest( |
| 1153 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | /** |
| 1157 | * Posts the specified command to be executed on the main thread, |
| 1158 | * waits for the request to complete, and returns the result. |
| 1159 | * @see #sendRequestAsync |
| 1160 | */ |
| 1161 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1162 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1163 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | /** |
| 1167 | * Posts the specified command to be executed on the main thread, |
| 1168 | * waits for the request to complete, and returns the result. |
| 1169 | * @see #sendRequestAsync |
| 1170 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1171 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1172 | return sendRequest(command, argument, subId, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * Posts the specified command to be executed on the main thread, |
| 1177 | * waits for the request to complete, and returns the result. |
| 1178 | * @see #sendRequestAsync |
| 1179 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1180 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1181 | return sendRequest(command, argument, subId, null, workSource); |
| 1182 | } |
| 1183 | |
| 1184 | /** |
| 1185 | * Posts the specified command to be executed on the main thread, |
| 1186 | * waits for the request to complete, and returns the result. |
| 1187 | * @see #sendRequestAsync |
| 1188 | */ |
| 1189 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1190 | return sendRequest( |
| 1191 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1192 | } |
| 1193 | |
| 1194 | /** |
| 1195 | * Posts the specified command to be executed on the main thread, |
| 1196 | * waits for the request to complete, and returns the result. |
| 1197 | * @see #sendRequestAsync |
| 1198 | */ |
| 1199 | private Object sendRequest( |
| 1200 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1201 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1202 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1203 | } |
| 1204 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1205 | MainThreadRequest request = null; |
| 1206 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1207 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1208 | } else if (phone != null) { |
| 1209 | request = new MainThreadRequest(argument, phone, workSource); |
| 1210 | } else { |
| 1211 | request = new MainThreadRequest(argument, subId, workSource); |
| 1212 | } |
| 1213 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1214 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1215 | msg.sendToTarget(); |
| 1216 | |
| 1217 | // Wait for the request to complete |
| 1218 | synchronized (request) { |
| 1219 | while (request.result == null) { |
| 1220 | try { |
| 1221 | request.wait(); |
| 1222 | } catch (InterruptedException e) { |
| 1223 | // Do nothing, go back and wait until the request is complete |
| 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | return request.result; |
| 1228 | } |
| 1229 | |
| 1230 | /** |
| 1231 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1232 | * Posts the specified command to be executed on the main thread, and |
| 1233 | * returns immediately. |
| 1234 | * @see #sendRequest |
| 1235 | */ |
| 1236 | private void sendRequestAsync(int command) { |
| 1237 | mMainThreadHandler.sendEmptyMessage(command); |
| 1238 | } |
| 1239 | |
| 1240 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1241 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1242 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1243 | */ |
| 1244 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1245 | sendRequestAsync(command, argument, null, null); |
| 1246 | } |
| 1247 | |
| 1248 | /** |
| 1249 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1250 | * @see {@link #sendRequest(int,Object)} |
| 1251 | */ |
| 1252 | private void sendRequestAsync( |
| 1253 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1254 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1255 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1256 | msg.sendToTarget(); |
| 1257 | } |
| 1258 | |
| 1259 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1260 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1261 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1262 | */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1263 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1264 | synchronized (PhoneInterfaceManager.class) { |
| 1265 | if (sInstance == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1266 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1267 | } else { |
| 1268 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1269 | } |
| 1270 | return sInstance; |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1275 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1276 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1277 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1278 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1279 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1280 | mMainThreadHandler = new MainThreadHandler(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1281 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1282 | mTelephonySharedPreferences = |
| 1283 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1284 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1285 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1286 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1287 | publish(); |
| 1288 | } |
| 1289 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1290 | private Phone getDefaultPhone() { |
| 1291 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1292 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1293 | } |
| 1294 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1295 | private void publish() { |
| 1296 | if (DBG) log("publish: " + this); |
| 1297 | |
| 1298 | ServiceManager.addService("phone", this); |
| 1299 | } |
| 1300 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1301 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1302 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1303 | ? getDefaultPhone() : getPhone(request.subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1304 | } |
| 1305 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1306 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1307 | Phone phone = getPhoneFromRequest(request); |
| 1308 | return phone == null ? null : |
| 1309 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1310 | } |
| 1311 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1312 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1313 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1314 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1315 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1316 | |
| 1317 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1318 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1321 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1322 | if (DBG) log("dial: " + number); |
| 1323 | // No permission check needed here: This is just a wrapper around the |
| 1324 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1325 | // the UI before it does anything. |
| 1326 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1327 | final long identity = Binder.clearCallingIdentity(); |
| 1328 | try { |
| 1329 | String url = createTelUrl(number); |
| 1330 | if (url == null) { |
| 1331 | return; |
| 1332 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1333 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1334 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1335 | PhoneConstants.State state = mCM.getState(subId); |
| 1336 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1337 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1338 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1339 | mApp.startActivity(intent); |
| 1340 | } |
| 1341 | } finally { |
| 1342 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1347 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1350 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1351 | if (DBG) log("call: " + number); |
| 1352 | |
| 1353 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1354 | // need to do a permission check since we're calling startActivity() |
| 1355 | // from the context of the phone app. |
| 1356 | enforceCallPermission(); |
| 1357 | |
| 1358 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1359 | != AppOpsManager.MODE_ALLOWED) { |
| 1360 | return; |
| 1361 | } |
| 1362 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1363 | final long identity = Binder.clearCallingIdentity(); |
| 1364 | try { |
| 1365 | String url = createTelUrl(number); |
| 1366 | if (url == null) { |
| 1367 | return; |
| 1368 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1369 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1370 | boolean isValid = false; |
| 1371 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1372 | if (slist != null) { |
| 1373 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1374 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1375 | isValid = true; |
| 1376 | break; |
| 1377 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1378 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1379 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1380 | if (!isValid) { |
| 1381 | return; |
| 1382 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1383 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1384 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1385 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1386 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1387 | mApp.startActivity(intent); |
| 1388 | } finally { |
| 1389 | Binder.restoreCallingIdentity(identity); |
| 1390 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1391 | } |
| 1392 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1393 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1394 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1397 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1398 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1399 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1400 | } |
| 1401 | |
| 1402 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1403 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1406 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1407 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1408 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1409 | } |
| 1410 | |
| 1411 | /** {@hide} */ |
| 1412 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1413 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1416 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1417 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1418 | |
| 1419 | final long identity = Binder.clearCallingIdentity(); |
| 1420 | try { |
| 1421 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1422 | checkSimPin.start(); |
| 1423 | return checkSimPin.unlockSim(null, pin); |
| 1424 | } finally { |
| 1425 | Binder.restoreCallingIdentity(identity); |
| 1426 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1429 | /** {@hide} */ |
| 1430 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1431 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1434 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1435 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1436 | |
| 1437 | final long identity = Binder.clearCallingIdentity(); |
| 1438 | try { |
| 1439 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1440 | checkSimPuk.start(); |
| 1441 | return checkSimPuk.unlockSim(puk, pin); |
| 1442 | } finally { |
| 1443 | Binder.restoreCallingIdentity(identity); |
| 1444 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1448 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1449 | * a synchronous one. |
| 1450 | */ |
| 1451 | private static class UnlockSim extends Thread { |
| 1452 | |
| 1453 | private final IccCard mSimCard; |
| 1454 | |
| 1455 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1456 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1457 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1458 | |
| 1459 | // For replies from SimCard interface |
| 1460 | private Handler mHandler; |
| 1461 | |
| 1462 | // For async handler to identify request type |
| 1463 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1464 | |
| 1465 | public UnlockSim(IccCard simCard) { |
| 1466 | mSimCard = simCard; |
| 1467 | } |
| 1468 | |
| 1469 | @Override |
| 1470 | public void run() { |
| 1471 | Looper.prepare(); |
| 1472 | synchronized (UnlockSim.this) { |
| 1473 | mHandler = new Handler() { |
| 1474 | @Override |
| 1475 | public void handleMessage(Message msg) { |
| 1476 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1477 | switch (msg.what) { |
| 1478 | case SUPPLY_PIN_COMPLETE: |
| 1479 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1480 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1481 | mRetryCount = msg.arg1; |
| 1482 | if (ar.exception != null) { |
| 1483 | if (ar.exception instanceof CommandException && |
| 1484 | ((CommandException)(ar.exception)).getCommandError() |
| 1485 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1486 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1487 | } else { |
| 1488 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1489 | } |
| 1490 | } else { |
| 1491 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1492 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1493 | mDone = true; |
| 1494 | UnlockSim.this.notifyAll(); |
| 1495 | } |
| 1496 | break; |
| 1497 | } |
| 1498 | } |
| 1499 | }; |
| 1500 | UnlockSim.this.notifyAll(); |
| 1501 | } |
| 1502 | Looper.loop(); |
| 1503 | } |
| 1504 | |
| 1505 | /* |
| 1506 | * Use PIN or PUK to unlock SIM card |
| 1507 | * |
| 1508 | * If PUK is null, unlock SIM card with PIN |
| 1509 | * |
| 1510 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1511 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1512 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1513 | |
| 1514 | while (mHandler == null) { |
| 1515 | try { |
| 1516 | wait(); |
| 1517 | } catch (InterruptedException e) { |
| 1518 | Thread.currentThread().interrupt(); |
| 1519 | } |
| 1520 | } |
| 1521 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1522 | |
| 1523 | if (puk == null) { |
| 1524 | mSimCard.supplyPin(pin, callback); |
| 1525 | } else { |
| 1526 | mSimCard.supplyPuk(puk, pin, callback); |
| 1527 | } |
| 1528 | |
| 1529 | while (!mDone) { |
| 1530 | try { |
| 1531 | Log.d(LOG_TAG, "wait for done"); |
| 1532 | wait(); |
| 1533 | } catch (InterruptedException e) { |
| 1534 | // Restore the interrupted status |
| 1535 | Thread.currentThread().interrupt(); |
| 1536 | } |
| 1537 | } |
| 1538 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1539 | int[] resultArray = new int[2]; |
| 1540 | resultArray[0] = mResult; |
| 1541 | resultArray[1] = mRetryCount; |
| 1542 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1543 | } |
| 1544 | } |
| 1545 | |
| 1546 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1547 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1548 | |
| 1549 | } |
| 1550 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1551 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1552 | // No permission check needed here: this call is harmless, and it's |
| 1553 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1554 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1555 | final long identity = Binder.clearCallingIdentity(); |
| 1556 | try { |
| 1557 | final Phone phone = getPhone(subId); |
| 1558 | if (phone != null) { |
| 1559 | phone.updateServiceLocation(); |
| 1560 | } |
| 1561 | } finally { |
| 1562 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1563 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1566 | @Override |
| 1567 | public boolean isRadioOn(String callingPackage) { |
| 1568 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1571 | @Override |
| 1572 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1573 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1574 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1575 | return false; |
| 1576 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1577 | |
| 1578 | final long identity = Binder.clearCallingIdentity(); |
| 1579 | try { |
| 1580 | return isRadioOnForSubscriber(subId); |
| 1581 | } finally { |
| 1582 | Binder.restoreCallingIdentity(identity); |
| 1583 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1587 | final long identity = Binder.clearCallingIdentity(); |
| 1588 | try { |
| 1589 | final Phone phone = getPhone(subId); |
| 1590 | if (phone != null) { |
| 1591 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1592 | } else { |
| 1593 | return false; |
| 1594 | } |
| 1595 | } finally { |
| 1596 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1597 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1601 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1602 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1603 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1604 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1605 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1606 | |
| 1607 | final long identity = Binder.clearCallingIdentity(); |
| 1608 | try { |
| 1609 | final Phone phone = getPhone(subId); |
| 1610 | if (phone != null) { |
| 1611 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1612 | } |
| 1613 | } finally { |
| 1614 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1615 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1619 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1620 | } |
| 1621 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1622 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1623 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1624 | |
| 1625 | final long identity = Binder.clearCallingIdentity(); |
| 1626 | try { |
| 1627 | final Phone phone = getPhone(subId); |
| 1628 | if (phone == null) { |
| 1629 | return false; |
| 1630 | } |
| 1631 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1632 | toggleRadioOnOffForSubscriber(subId); |
| 1633 | } |
| 1634 | return true; |
| 1635 | } finally { |
| 1636 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1637 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1638 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1639 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1640 | public boolean needMobileRadioShutdown() { |
| 1641 | /* |
| 1642 | * If any of the Radios are available, it will need to be |
| 1643 | * shutdown. So return true if any Radio is available. |
| 1644 | */ |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1645 | final long identity = Binder.clearCallingIdentity(); |
| 1646 | try { |
| 1647 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1648 | Phone phone = PhoneFactory.getPhone(i); |
| 1649 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1650 | } |
| 1651 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1652 | return false; |
| 1653 | } finally { |
| 1654 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1655 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1658 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1659 | public void shutdownMobileRadios() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1660 | enforceModifyPermission(); |
| 1661 | |
| 1662 | final long identity = Binder.clearCallingIdentity(); |
| 1663 | try { |
| 1664 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1665 | logv("Shutting down Phone " + i); |
| 1666 | shutdownRadioUsingPhoneId(i); |
| 1667 | } |
| 1668 | } finally { |
| 1669 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1674 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1675 | if (phone != null && phone.isRadioAvailable()) { |
| 1676 | phone.shutdownRadio(); |
| 1677 | } |
| 1678 | } |
| 1679 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1680 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1681 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1682 | |
| 1683 | final long identity = Binder.clearCallingIdentity(); |
| 1684 | try { |
| 1685 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1686 | if (defaultPhone != null) { |
| 1687 | defaultPhone.setRadioPower(turnOn); |
| 1688 | return true; |
| 1689 | } else { |
| 1690 | loge("There's no default phone."); |
| 1691 | return false; |
| 1692 | } |
| 1693 | } finally { |
| 1694 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1695 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1698 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1699 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1700 | |
| 1701 | final long identity = Binder.clearCallingIdentity(); |
| 1702 | try { |
| 1703 | final Phone phone = getPhone(subId); |
| 1704 | if (phone != null) { |
| 1705 | phone.setRadioPower(turnOn); |
| 1706 | return true; |
| 1707 | } else { |
| 1708 | return false; |
| 1709 | } |
| 1710 | } finally { |
| 1711 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1712 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1715 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1716 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1717 | public boolean enableDataConnectivity() { |
| 1718 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1719 | |
| 1720 | final long identity = Binder.clearCallingIdentity(); |
| 1721 | try { |
| 1722 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1723 | final Phone phone = getPhone(subId); |
| 1724 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1725 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1726 | return true; |
| 1727 | } else { |
| 1728 | return false; |
| 1729 | } |
| 1730 | } finally { |
| 1731 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1732 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1735 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1736 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1737 | public boolean disableDataConnectivity() { |
| 1738 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1739 | |
| 1740 | final long identity = Binder.clearCallingIdentity(); |
| 1741 | try { |
| 1742 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1743 | final Phone phone = getPhone(subId); |
| 1744 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1745 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1746 | return true; |
| 1747 | } else { |
| 1748 | return false; |
| 1749 | } |
| 1750 | } finally { |
| 1751 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1752 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1755 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1756 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1757 | final long identity = Binder.clearCallingIdentity(); |
| 1758 | try { |
| 1759 | final Phone phone = getPhone(subId); |
| 1760 | if (phone != null) { |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1761 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1762 | } else { |
| 1763 | return false; |
| 1764 | } |
| 1765 | } finally { |
| 1766 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1767 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1771 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1774 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1775 | enforceCallPermission(); |
| 1776 | |
| 1777 | final long identity = Binder.clearCallingIdentity(); |
| 1778 | try { |
| 1779 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1780 | return; |
| 1781 | } |
| 1782 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1783 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1784 | } finally { |
| 1785 | Binder.restoreCallingIdentity(identity); |
| 1786 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1787 | }; |
| 1788 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1789 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1790 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1791 | |
| 1792 | final long identity = Binder.clearCallingIdentity(); |
| 1793 | try { |
| 1794 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1795 | return false; |
| 1796 | } |
| 1797 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1798 | } finally { |
| 1799 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1800 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1803 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1804 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1807 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1808 | final long identity = Binder.clearCallingIdentity(); |
| 1809 | try { |
| 1810 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1811 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1812 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1813 | } finally { |
| 1814 | Binder.restoreCallingIdentity(identity); |
| 1815 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1818 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1819 | public int getDataState() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1820 | final long identity = Binder.clearCallingIdentity(); |
| 1821 | try { |
| 1822 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1823 | if (phone != null) { |
| 1824 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1825 | } else { |
| 1826 | return PhoneConstantConversions.convertDataState( |
| 1827 | PhoneConstants.DataState.DISCONNECTED); |
| 1828 | } |
| 1829 | } finally { |
| 1830 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1831 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1834 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1835 | public int getDataActivity() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1836 | final long identity = Binder.clearCallingIdentity(); |
| 1837 | try { |
| 1838 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1839 | if (phone != null) { |
| 1840 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1841 | } else { |
| 1842 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1843 | } |
| 1844 | } finally { |
| 1845 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1846 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1850 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1851 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1852 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1853 | |
| 1854 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1855 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1856 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1857 | .setCallingPackage(callingPackage) |
| 1858 | .setCallingPid(Binder.getCallingPid()) |
| 1859 | .setCallingUid(Binder.getCallingUid()) |
| 1860 | .setMethod("getCellLocation") |
| 1861 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1862 | .build()); |
| 1863 | switch (locationResult) { |
| 1864 | case DENIED_HARD: |
| 1865 | throw new SecurityException("Not allowed to access cell location"); |
| 1866 | case DENIED_SOFT: |
| 1867 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1870 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1871 | final long identity = Binder.clearCallingIdentity(); |
| 1872 | try { |
| 1873 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1874 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1875 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1876 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1877 | cl.fillInNotifierBundle(data); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1878 | return data; |
| 1879 | } finally { |
| 1880 | Binder.restoreCallingIdentity(identity); |
| 1881 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1882 | } |
| 1883 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1884 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1885 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1886 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1887 | // registered cell info, so return a NULL country instead. |
| 1888 | final long identity = Binder.clearCallingIdentity(); |
| 1889 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1890 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1891 | // Get default phone in this case. |
| 1892 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1893 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1894 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1895 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1896 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1897 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1898 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1899 | return ""; |
| 1900 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1901 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1902 | if (phone != null) { |
| 1903 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1904 | if (sst != null) { |
| 1905 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1906 | if (lt != null) { |
| 1907 | return lt.getCurrentCountry(); |
| 1908 | } |
| 1909 | } |
| 1910 | } |
| 1911 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1912 | } finally { |
| 1913 | Binder.restoreCallingIdentity(identity); |
| 1914 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1918 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1919 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1920 | } |
| 1921 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1922 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1923 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1924 | mApp.enforceCallingOrSelfPermission( |
| 1925 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1926 | |
| 1927 | final long identity = Binder.clearCallingIdentity(); |
| 1928 | try { |
| 1929 | final Phone phone = getPhone(subId); |
| 1930 | if (phone != null) { |
| 1931 | phone.enableLocationUpdates(); |
| 1932 | } |
| 1933 | } finally { |
| 1934 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1935 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | @Override |
| 1939 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1940 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1941 | } |
| 1942 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1943 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1944 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1945 | mApp.enforceCallingOrSelfPermission( |
| 1946 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1947 | |
| 1948 | final long identity = Binder.clearCallingIdentity(); |
| 1949 | try { |
| 1950 | final Phone phone = getPhone(subId); |
| 1951 | if (phone != null) { |
| 1952 | phone.disableLocationUpdates(); |
| 1953 | } |
| 1954 | } finally { |
| 1955 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1956 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1959 | /** |
| 1960 | * Returns the target SDK version number for a given package name. |
| 1961 | * |
| 1962 | * @return target SDK if the package is found or INT_MAX. |
| 1963 | */ |
| 1964 | private int getTargetSdk(String packageName) { |
| 1965 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1966 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 1967 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1968 | if (ai != null) return ai.targetSdkVersion; |
| 1969 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1970 | } |
| 1971 | return Integer.MAX_VALUE; |
| 1972 | } |
| 1973 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1974 | @Override |
| 1975 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1976 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1977 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1978 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1979 | throw new SecurityException( |
| 1980 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1981 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1982 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1983 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1984 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1985 | return null; |
| 1986 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1987 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1988 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1989 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1990 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 1991 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1992 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1993 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 1994 | for (CellInfo ci : info) { |
| 1995 | if (ci instanceof CellInfoGsm) { |
| 1996 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 1997 | } else if (ci instanceof CellInfoWcdma) { |
| 1998 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 1999 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2000 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2001 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2004 | private List<CellInfo> getCachedCellInfo() { |
| 2005 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2006 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2007 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2008 | if (info != null) cellInfos.addAll(info); |
| 2009 | } |
| 2010 | return cellInfos; |
| 2011 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2012 | |
| 2013 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2014 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2015 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2016 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2017 | |
| 2018 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2019 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2020 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2021 | .setCallingPackage(callingPackage) |
| 2022 | .setCallingPid(Binder.getCallingPid()) |
| 2023 | .setCallingUid(Binder.getCallingUid()) |
| 2024 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2025 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2026 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2027 | .build()); |
| 2028 | switch (locationResult) { |
| 2029 | case DENIED_HARD: |
| 2030 | throw new SecurityException("Not allowed to access cell info"); |
| 2031 | case DENIED_SOFT: |
| 2032 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2035 | final int targetSdk = getTargetSdk(callingPackage); |
| 2036 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2037 | return getCachedCellInfo(); |
| 2038 | } |
| 2039 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2040 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2041 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2042 | final long identity = Binder.clearCallingIdentity(); |
| 2043 | try { |
| 2044 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2045 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2046 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2047 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2048 | if (info != null) cellInfos.addAll(info); |
| 2049 | } |
| 2050 | return cellInfos; |
| 2051 | } finally { |
| 2052 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2053 | } |
| 2054 | } |
| 2055 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2056 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2057 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2058 | requestCellInfoUpdateInternal( |
| 2059 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2060 | } |
| 2061 | |
| 2062 | @Override |
| 2063 | public void requestCellInfoUpdateWithWorkSource( |
| 2064 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2065 | enforceModifyPermission(); |
| 2066 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2067 | } |
| 2068 | |
| 2069 | private void requestCellInfoUpdateInternal( |
| 2070 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2071 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2072 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2073 | |
| 2074 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2075 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2076 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2077 | .setCallingPackage(callingPackage) |
| 2078 | .setCallingPid(Binder.getCallingPid()) |
| 2079 | .setCallingUid(Binder.getCallingUid()) |
| 2080 | .setMethod("requestCellInfoUpdate") |
| 2081 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2082 | .build()); |
| 2083 | switch (locationResult) { |
| 2084 | case DENIED_HARD: |
| 2085 | throw new SecurityException("Not allowed to access cell info"); |
| 2086 | case DENIED_SOFT: |
| 2087 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | final Phone phone = getPhone(subId); |
| 2091 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2092 | |
| 2093 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2094 | } |
| 2095 | |
| 2096 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2097 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2098 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2099 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2100 | |
| 2101 | final long identity = Binder.clearCallingIdentity(); |
| 2102 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2103 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2104 | } finally { |
| 2105 | Binder.restoreCallingIdentity(identity); |
| 2106 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2109 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2110 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2111 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2112 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2113 | return null; |
| 2114 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2115 | int subId = phone.getSubId(); |
| 2116 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2117 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 2118 | return null; |
| 2119 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2120 | |
| 2121 | final long identity = Binder.clearCallingIdentity(); |
| 2122 | try { |
| 2123 | return phone.getImei(); |
| 2124 | } finally { |
| 2125 | Binder.restoreCallingIdentity(identity); |
| 2126 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2130 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2131 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2132 | String tac = null; |
| 2133 | if (phone != null) { |
| 2134 | String imei = phone.getImei(); |
| 2135 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2136 | } |
| 2137 | return tac; |
| 2138 | } |
| 2139 | |
| 2140 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2141 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2142 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2143 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2144 | return null; |
| 2145 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2146 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2147 | int subId = phone.getSubId(); |
| 2148 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2149 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 2150 | return null; |
| 2151 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2152 | |
| 2153 | final long identity = Binder.clearCallingIdentity(); |
| 2154 | try { |
| 2155 | return phone.getMeid(); |
| 2156 | } finally { |
| 2157 | Binder.restoreCallingIdentity(identity); |
| 2158 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2162 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2163 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2164 | String manufacturerCode = null; |
| 2165 | if (phone != null) { |
| 2166 | String meid = phone.getMeid(); |
| 2167 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2168 | } |
| 2169 | return manufacturerCode; |
| 2170 | } |
| 2171 | |
| 2172 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2173 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2174 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2175 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2176 | return null; |
| 2177 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2178 | int subId = phone.getSubId(); |
| 2179 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2180 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2181 | return null; |
| 2182 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2183 | |
| 2184 | final long identity = Binder.clearCallingIdentity(); |
| 2185 | try { |
| 2186 | return phone.getDeviceSvn(); |
| 2187 | } finally { |
| 2188 | Binder.restoreCallingIdentity(identity); |
| 2189 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2192 | @Override |
| 2193 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2194 | final long identity = Binder.clearCallingIdentity(); |
| 2195 | try { |
| 2196 | final Phone phone = getPhone(subId); |
| 2197 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2198 | } finally { |
| 2199 | Binder.restoreCallingIdentity(identity); |
| 2200 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | @Override |
| 2204 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2205 | final long identity = Binder.clearCallingIdentity(); |
| 2206 | try { |
| 2207 | final Phone phone = getPhone(subId); |
| 2208 | return phone == null ? null : phone.getCarrierName(); |
| 2209 | } finally { |
| 2210 | Binder.restoreCallingIdentity(identity); |
| 2211 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2212 | } |
| 2213 | |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2214 | @Override |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2215 | public int getSubscriptionPreciseCarrierId(int subId) { |
| 2216 | final long identity = Binder.clearCallingIdentity(); |
| 2217 | try { |
| 2218 | final Phone phone = getPhone(subId); |
| 2219 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
| 2220 | : phone.getPreciseCarrierId(); |
| 2221 | } finally { |
| 2222 | Binder.restoreCallingIdentity(identity); |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | @Override |
| 2227 | public String getSubscriptionPreciseCarrierName(int subId) { |
| 2228 | final long identity = Binder.clearCallingIdentity(); |
| 2229 | try { |
| 2230 | final Phone phone = getPhone(subId); |
| 2231 | return phone == null ? null : phone.getPreciseCarrierName(); |
| 2232 | } finally { |
| 2233 | Binder.restoreCallingIdentity(identity); |
| 2234 | } |
| 2235 | } |
| 2236 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2237 | @Override |
chen xu | 4ca4e69 | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2238 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2239 | if (!isSubscriptionMccMnc) { |
| 2240 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2241 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2242 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2243 | if (phone == null) { |
| 2244 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2245 | } |
| 2246 | final long identity = Binder.clearCallingIdentity(); |
| 2247 | try { |
| 2248 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2249 | } finally { |
| 2250 | Binder.restoreCallingIdentity(identity); |
| 2251 | } |
| 2252 | } |
| 2253 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2254 | // |
| 2255 | // Internal helper methods. |
| 2256 | // |
| 2257 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2258 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2259 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2260 | * |
| 2261 | * @throws SecurityException if the caller does not have the required permission |
| 2262 | */ |
| 2263 | private void enforceModifyPermission() { |
| 2264 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2265 | } |
| 2266 | |
| 2267 | /** |
| 2268 | * Make sure the caller has the CALL_PHONE permission. |
| 2269 | * |
| 2270 | * @throws SecurityException if the caller does not have the required permission |
| 2271 | */ |
| 2272 | private void enforceCallPermission() { |
| 2273 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2274 | } |
| 2275 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2276 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2277 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2278 | "ConnectivityService"); |
| 2279 | } |
| 2280 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2281 | private String createTelUrl(String number) { |
| 2282 | if (TextUtils.isEmpty(number)) { |
| 2283 | return null; |
| 2284 | } |
| 2285 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2286 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2287 | } |
| 2288 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2289 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2290 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2291 | } |
| 2292 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2293 | private static void logv(String msg) { |
| 2294 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2295 | } |
| 2296 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2297 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2298 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2299 | } |
| 2300 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2301 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2302 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2303 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2304 | } |
| 2305 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2306 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2307 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2308 | final long identity = Binder.clearCallingIdentity(); |
| 2309 | try { |
| 2310 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2311 | if (phone == null) { |
| 2312 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2313 | } else { |
| 2314 | return phone.getPhoneType(); |
| 2315 | } |
| 2316 | } finally { |
| 2317 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2318 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | /** |
| 2322 | * Returns the CDMA ERI icon index to display |
| 2323 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2324 | @Override |
| 2325 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2326 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2327 | } |
| 2328 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2329 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2330 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2331 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2332 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2333 | return -1; |
| 2334 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2335 | |
| 2336 | final long identity = Binder.clearCallingIdentity(); |
| 2337 | try { |
| 2338 | final Phone phone = getPhone(subId); |
| 2339 | if (phone != null) { |
| 2340 | return phone.getCdmaEriIconIndex(); |
| 2341 | } else { |
| 2342 | return -1; |
| 2343 | } |
| 2344 | } finally { |
| 2345 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2346 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | /** |
| 2350 | * Returns the CDMA ERI icon mode, |
| 2351 | * 0 - ON |
| 2352 | * 1 - FLASHING |
| 2353 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2354 | @Override |
| 2355 | public int getCdmaEriIconMode(String callingPackage) { |
| 2356 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2359 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2360 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2361 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2362 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2363 | return -1; |
| 2364 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2365 | |
| 2366 | final long identity = Binder.clearCallingIdentity(); |
| 2367 | try { |
| 2368 | final Phone phone = getPhone(subId); |
| 2369 | if (phone != null) { |
| 2370 | return phone.getCdmaEriIconMode(); |
| 2371 | } else { |
| 2372 | return -1; |
| 2373 | } |
| 2374 | } finally { |
| 2375 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2376 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | /** |
| 2380 | * Returns the CDMA ERI text, |
| 2381 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2382 | @Override |
| 2383 | public String getCdmaEriText(String callingPackage) { |
| 2384 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2387 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2388 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2389 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2390 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2391 | return null; |
| 2392 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2393 | |
| 2394 | final long identity = Binder.clearCallingIdentity(); |
| 2395 | try { |
| 2396 | final Phone phone = getPhone(subId); |
| 2397 | if (phone != null) { |
| 2398 | return phone.getCdmaEriText(); |
| 2399 | } else { |
| 2400 | return null; |
| 2401 | } |
| 2402 | } finally { |
| 2403 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2404 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2408 | * Returns the CDMA MDN. |
| 2409 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2410 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2411 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2412 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2413 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2414 | |
| 2415 | final long identity = Binder.clearCallingIdentity(); |
| 2416 | try { |
| 2417 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2418 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2419 | return phone.getLine1Number(); |
| 2420 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2421 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2422 | return null; |
| 2423 | } |
| 2424 | } finally { |
| 2425 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2426 | } |
| 2427 | } |
| 2428 | |
| 2429 | /** |
| 2430 | * Returns the CDMA MIN. |
| 2431 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2432 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2433 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2434 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2435 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2436 | |
| 2437 | final long identity = Binder.clearCallingIdentity(); |
| 2438 | try { |
| 2439 | final Phone phone = getPhone(subId); |
| 2440 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2441 | return phone.getCdmaMin(); |
| 2442 | } else { |
| 2443 | return null; |
| 2444 | } |
| 2445 | } finally { |
| 2446 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2447 | } |
| 2448 | } |
| 2449 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2450 | @Override |
| 2451 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2452 | INumberVerificationCallback callback, String callingPackage) { |
| 2453 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2454 | != PERMISSION_GRANTED) { |
| 2455 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2456 | } |
| 2457 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2458 | |
| 2459 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2460 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2461 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2462 | } |
| 2463 | |
| 2464 | if (range == null) { |
| 2465 | throw new NullPointerException("Range must be non-null"); |
| 2466 | } |
| 2467 | |
| 2468 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2469 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2470 | |
| 2471 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2472 | } |
| 2473 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2474 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2475 | * Returns true if CDMA provisioning needs to run. |
| 2476 | */ |
| 2477 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2478 | final long identity = Binder.clearCallingIdentity(); |
| 2479 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2480 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2481 | } finally { |
| 2482 | Binder.restoreCallingIdentity(identity); |
| 2483 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2487 | * Sets the voice mail number of a given subId. |
| 2488 | */ |
| 2489 | @Override |
| 2490 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2491 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2492 | |
| 2493 | final long identity = Binder.clearCallingIdentity(); |
| 2494 | try { |
| 2495 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2496 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2497 | return success; |
| 2498 | } finally { |
| 2499 | Binder.restoreCallingIdentity(identity); |
| 2500 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2501 | } |
| 2502 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2503 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2504 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2505 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2506 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2507 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2508 | throw new SecurityException("caller must be system dialer"); |
| 2509 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2510 | |
| 2511 | final long identity = Binder.clearCallingIdentity(); |
| 2512 | try { |
| 2513 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2514 | if (phoneAccountHandle == null) { |
| 2515 | return null; |
| 2516 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2517 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2518 | } finally { |
| 2519 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2520 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2524 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2525 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2526 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2527 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2528 | return null; |
| 2529 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2530 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2531 | final long identity = Binder.clearCallingIdentity(); |
| 2532 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2533 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2534 | } finally { |
| 2535 | Binder.restoreCallingIdentity(identity); |
| 2536 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2540 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2541 | VisualVoicemailSmsFilterSettings settings) { |
| 2542 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2543 | |
| 2544 | final long identity = Binder.clearCallingIdentity(); |
| 2545 | try { |
| 2546 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2547 | mApp, callingPackage, subId, settings); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2548 | } finally { |
| 2549 | Binder.restoreCallingIdentity(identity); |
| 2550 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2554 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2555 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2556 | |
| 2557 | final long identity = Binder.clearCallingIdentity(); |
| 2558 | try { |
| 2559 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2560 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2561 | } finally { |
| 2562 | Binder.restoreCallingIdentity(identity); |
| 2563 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2567 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2568 | String callingPackage, int subId) { |
| 2569 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2570 | |
| 2571 | final long identity = Binder.clearCallingIdentity(); |
| 2572 | try { |
| 2573 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2574 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2575 | } finally { |
| 2576 | Binder.restoreCallingIdentity(identity); |
| 2577 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2581 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2582 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2583 | |
| 2584 | final long identity = Binder.clearCallingIdentity(); |
| 2585 | try { |
| 2586 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2587 | mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2588 | } finally { |
| 2589 | Binder.restoreCallingIdentity(identity); |
| 2590 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2591 | } |
| 2592 | |
| 2593 | @Override |
| 2594 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2595 | String number, int port, String text, PendingIntent sentIntent) { |
| 2596 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2597 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2598 | enforceSendSmsPermission(); |
| 2599 | // Make the calls as the phone process. |
| 2600 | final long identity = Binder.clearCallingIdentity(); |
| 2601 | try { |
| 2602 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2603 | if (port == 0) { |
| 2604 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2605 | sentIntent, null, false); |
| 2606 | } else { |
| 2607 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2608 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2609 | (short) port, data, sentIntent, null); |
| 2610 | } |
| 2611 | } finally { |
| 2612 | Binder.restoreCallingIdentity(identity); |
| 2613 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2614 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2615 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2616 | * Sets the voice activation state of a given subId. |
| 2617 | */ |
| 2618 | @Override |
| 2619 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2620 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2621 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2622 | |
| 2623 | final long identity = Binder.clearCallingIdentity(); |
| 2624 | try { |
| 2625 | final Phone phone = getPhone(subId); |
| 2626 | if (phone != null) { |
| 2627 | phone.setVoiceActivationState(activationState); |
| 2628 | } else { |
| 2629 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2630 | } |
| 2631 | } finally { |
| 2632 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | /** |
| 2637 | * Sets the data activation state of a given subId. |
| 2638 | */ |
| 2639 | @Override |
| 2640 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2641 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2642 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2643 | |
| 2644 | final long identity = Binder.clearCallingIdentity(); |
| 2645 | try { |
| 2646 | final Phone phone = getPhone(subId); |
| 2647 | if (phone != null) { |
| 2648 | phone.setDataActivationState(activationState); |
| 2649 | } else { |
| 2650 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2651 | } |
| 2652 | } finally { |
| 2653 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2654 | } |
| 2655 | } |
| 2656 | |
| 2657 | /** |
| 2658 | * Returns the voice activation state of a given subId. |
| 2659 | */ |
| 2660 | @Override |
| 2661 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2662 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2663 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2664 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2665 | final long identity = Binder.clearCallingIdentity(); |
| 2666 | try { |
| 2667 | if (phone != null) { |
| 2668 | return phone.getVoiceActivationState(); |
| 2669 | } else { |
| 2670 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2671 | } |
| 2672 | } finally { |
| 2673 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2674 | } |
| 2675 | } |
| 2676 | |
| 2677 | /** |
| 2678 | * Returns the data activation state of a given subId. |
| 2679 | */ |
| 2680 | @Override |
| 2681 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2682 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2683 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2684 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2685 | final long identity = Binder.clearCallingIdentity(); |
| 2686 | try { |
| 2687 | if (phone != null) { |
| 2688 | return phone.getDataActivationState(); |
| 2689 | } else { |
| 2690 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2691 | } |
| 2692 | } finally { |
| 2693 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2694 | } |
| 2695 | } |
| 2696 | |
| 2697 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2698 | * Returns the unread count of voicemails for a subId |
| 2699 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2700 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2701 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2702 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2703 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2704 | return 0; |
| 2705 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2706 | final long identity = Binder.clearCallingIdentity(); |
| 2707 | try { |
| 2708 | final Phone phone = getPhone(subId); |
| 2709 | if (phone != null) { |
| 2710 | return phone.getVoiceMessageCount(); |
| 2711 | } else { |
| 2712 | return 0; |
| 2713 | } |
| 2714 | } finally { |
| 2715 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2716 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2720 | * returns true, if the device is in a state where both voice and data |
| 2721 | * are supported simultaneously. This can change based on location or network condition. |
| 2722 | */ |
| 2723 | @Override |
| 2724 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2725 | final long identity = Binder.clearCallingIdentity(); |
| 2726 | try { |
| 2727 | final Phone phone = getPhone(subId); |
| 2728 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2729 | } finally { |
| 2730 | Binder.restoreCallingIdentity(identity); |
| 2731 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2735 | * Send the dialer code if called from the current default dialer or the caller has |
| 2736 | * carrier privilege. |
| 2737 | * @param inputCode The dialer code to send |
| 2738 | */ |
| 2739 | @Override |
| 2740 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2741 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2742 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2743 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2744 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2745 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2746 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2747 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2748 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2749 | |
| 2750 | final long identity = Binder.clearCallingIdentity(); |
| 2751 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2752 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2753 | } finally { |
| 2754 | Binder.restoreCallingIdentity(identity); |
| 2755 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2759 | * Returns the data network type. |
| 2760 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2761 | * |
| 2762 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2763 | */ |
| 2764 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2765 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2766 | final long identity = Binder.clearCallingIdentity(); |
| 2767 | try { |
| 2768 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2769 | if (phone != null) { |
| 2770 | return phone.getServiceState().getDataNetworkType(); |
| 2771 | } else { |
| 2772 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2773 | } |
| 2774 | } finally { |
| 2775 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2776 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2779 | @Override |
| 2780 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2781 | if (!isActiveSubscription(subId)) { |
| 2782 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2783 | } |
| 2784 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2785 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2786 | } |
| 2787 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2788 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2789 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2790 | throws RemoteException { |
| 2791 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2792 | final long token = Binder.clearCallingIdentity(); |
| 2793 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2794 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2795 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2796 | .addRegistrationCallbackForSubscription(c, subId); |
| 2797 | } finally { |
| 2798 | Binder.restoreCallingIdentity(token); |
| 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2803 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2804 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2805 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2806 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2807 | } |
| 2808 | Binder.withCleanCallingIdentity(() -> { |
| 2809 | try { |
| 2810 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2811 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2812 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2813 | } catch (IllegalArgumentException e) { |
| 2814 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2815 | + "is inactive, ignoring unregister."); |
| 2816 | // If the subscription is no longer active, just return, since the callback |
| 2817 | // will already have been removed internally. |
| 2818 | } |
| 2819 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2823 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2824 | throws RemoteException { |
| 2825 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2826 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2827 | final long token = Binder.clearCallingIdentity(); |
| 2828 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2829 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2830 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2831 | } finally { |
| 2832 | Binder.restoreCallingIdentity(token); |
| 2833 | } |
| 2834 | } |
| 2835 | |
| 2836 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2837 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2838 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2839 | |
| 2840 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2841 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2842 | } |
| 2843 | Binder.withCleanCallingIdentity(() -> { |
| 2844 | try { |
| 2845 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2846 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2847 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2848 | } catch (IllegalArgumentException e) { |
| 2849 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2850 | + "is inactive, ignoring unregister."); |
| 2851 | // If the subscription is no longer active, just return, since the callback |
| 2852 | // will already have been removed internally. |
| 2853 | } |
| 2854 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2858 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2859 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2860 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2861 | final long token = Binder.clearCallingIdentity(); |
| 2862 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2863 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2864 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2865 | } catch (ImsException e) { |
| 2866 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2867 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2868 | } catch (IllegalArgumentException e) { |
| 2869 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2870 | return false; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2871 | } finally { |
| 2872 | Binder.restoreCallingIdentity(token); |
| 2873 | } |
| 2874 | } |
| 2875 | |
| 2876 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2877 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2878 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2879 | final long token = Binder.clearCallingIdentity(); |
| 2880 | try { |
| 2881 | Phone phone = getPhone(subId); |
| 2882 | if (phone == null) return false; |
| 2883 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2884 | } finally { |
| 2885 | Binder.restoreCallingIdentity(token); |
| 2886 | } |
| 2887 | } |
| 2888 | |
| 2889 | @Override |
| 2890 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2891 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2892 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2893 | final long token = Binder.clearCallingIdentity(); |
| 2894 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2895 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2896 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2897 | } finally { |
| 2898 | Binder.restoreCallingIdentity(token); |
| 2899 | } |
| 2900 | } |
| 2901 | |
| 2902 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2903 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2904 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2905 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2906 | final long identity = Binder.clearCallingIdentity(); |
| 2907 | try { |
| 2908 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2909 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2910 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2911 | } finally { |
| 2912 | Binder.restoreCallingIdentity(identity); |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2917 | public boolean isVtSettingEnabled(int subId) { |
| 2918 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2919 | final long identity = Binder.clearCallingIdentity(); |
| 2920 | try { |
| 2921 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2922 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2923 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2924 | } finally { |
| 2925 | Binder.restoreCallingIdentity(identity); |
| 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2930 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2931 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2932 | "setVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2933 | final long identity = Binder.clearCallingIdentity(); |
| 2934 | try { |
| 2935 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2936 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2937 | } finally { |
| 2938 | Binder.restoreCallingIdentity(identity); |
| 2939 | } |
| 2940 | } |
| 2941 | |
| 2942 | @Override |
| 2943 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2944 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2945 | final long identity = Binder.clearCallingIdentity(); |
| 2946 | try { |
| 2947 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2948 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2949 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2950 | } finally { |
| 2951 | Binder.restoreCallingIdentity(identity); |
| 2952 | } |
| 2953 | } |
| 2954 | |
| 2955 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2956 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2957 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2958 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2959 | final long identity = Binder.clearCallingIdentity(); |
| 2960 | try { |
| 2961 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2962 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2963 | } finally { |
| 2964 | Binder.restoreCallingIdentity(identity); |
| 2965 | } |
| 2966 | } |
| 2967 | |
| 2968 | @Override |
| 2969 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2970 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2971 | final long identity = Binder.clearCallingIdentity(); |
| 2972 | try { |
| 2973 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2974 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2975 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 2976 | } finally { |
| 2977 | Binder.restoreCallingIdentity(identity); |
| 2978 | } |
| 2979 | } |
| 2980 | |
| 2981 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2982 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2983 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2984 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2985 | final long identity = Binder.clearCallingIdentity(); |
| 2986 | try { |
| 2987 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2988 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2989 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 2990 | } finally { |
| 2991 | Binder.restoreCallingIdentity(identity); |
| 2992 | } |
| 2993 | } |
| 2994 | |
| 2995 | @Override |
| 2996 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 2997 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2998 | "setVoWiFiNonPersistent"); |
| 2999 | final long identity = Binder.clearCallingIdentity(); |
| 3000 | try { |
| 3001 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3002 | boolean isRoaming = TelephonyManager.from( |
| 3003 | getPhone(subId).getContext()).isNetworkRoaming(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3004 | ImsManager.getInstance(mApp, |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3005 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3006 | } finally { |
| 3007 | Binder.restoreCallingIdentity(identity); |
| 3008 | } |
| 3009 | } |
| 3010 | |
| 3011 | @Override |
| 3012 | public int getVoWiFiModeSetting(int subId) { |
| 3013 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3014 | final long identity = Binder.clearCallingIdentity(); |
| 3015 | try { |
| 3016 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3017 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3018 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3019 | } finally { |
| 3020 | Binder.restoreCallingIdentity(identity); |
| 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | @Override |
| 3025 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3026 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3027 | "setVoWiFiModeSetting"); |
| 3028 | final long identity = Binder.clearCallingIdentity(); |
| 3029 | try { |
| 3030 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3031 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3032 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3033 | } finally { |
| 3034 | Binder.restoreCallingIdentity(identity); |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | @Override |
| 3039 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3040 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3041 | final long identity = Binder.clearCallingIdentity(); |
| 3042 | try { |
| 3043 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3044 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3045 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3046 | } finally { |
| 3047 | Binder.restoreCallingIdentity(identity); |
| 3048 | } |
| 3049 | } |
| 3050 | |
| 3051 | @Override |
| 3052 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3053 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3054 | "setVoWiFiRoamingModeSetting"); |
| 3055 | final long identity = Binder.clearCallingIdentity(); |
| 3056 | try { |
| 3057 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3058 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3059 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3060 | } finally { |
| 3061 | Binder.restoreCallingIdentity(identity); |
| 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | @Override |
| 3066 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3067 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3068 | "setRttCapabilityEnabled"); |
| 3069 | final long identity = Binder.clearCallingIdentity(); |
| 3070 | try { |
| 3071 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3072 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3073 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3074 | } finally { |
| 3075 | Binder.restoreCallingIdentity(identity); |
| 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | @Override |
| 3080 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3081 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3082 | final long identity = Binder.clearCallingIdentity(); |
| 3083 | try { |
| 3084 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3085 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3086 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3087 | } finally { |
| 3088 | Binder.restoreCallingIdentity(identity); |
| 3089 | } |
| 3090 | } |
| 3091 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3092 | @Override |
| 3093 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3094 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3095 | final long identity = Binder.clearCallingIdentity(); |
| 3096 | try { |
| 3097 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3098 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3099 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3100 | } finally { |
| 3101 | Binder.restoreCallingIdentity(identity); |
| 3102 | } |
| 3103 | } |
| 3104 | |
| 3105 | @Override |
| 3106 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3107 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3108 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3109 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3110 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3111 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3112 | try { |
| 3113 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3114 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3115 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3116 | } catch (IllegalArgumentException e) { |
| 3117 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3118 | + "is inactive, ignoring unregister."); |
| 3119 | // If the subscription is no longer active, just return, since the callback will already |
| 3120 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3121 | } finally { |
| 3122 | Binder.restoreCallingIdentity(identity); |
| 3123 | } |
| 3124 | } |
| 3125 | |
| 3126 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3127 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3128 | boolean isProvisioned) { |
| 3129 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3130 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3131 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3132 | } |
| 3133 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3134 | "setProvisioningStatusForCapability"); |
| 3135 | final long identity = Binder.clearCallingIdentity(); |
| 3136 | try { |
| 3137 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3138 | Phone phone = getPhone(subId); |
| 3139 | if (phone == null) { |
| 3140 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3141 | + subId); |
| 3142 | return; |
| 3143 | } |
| 3144 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3145 | return; |
| 3146 | } |
| 3147 | |
| 3148 | // this capability requires provisioning, route to the correct API. |
| 3149 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3150 | switch (capability) { |
| 3151 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3152 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3153 | ims.setVolteProvisioned(isProvisioned); |
| 3154 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3155 | ims.setWfcProvisioned(isProvisioned); |
| 3156 | } |
| 3157 | break; |
| 3158 | } |
| 3159 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3160 | // There is currently no difference in VT provisioning type. |
| 3161 | ims.setVtProvisioned(isProvisioned); |
| 3162 | break; |
| 3163 | } |
| 3164 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3165 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3166 | // change the capability of the feature instead if needed. |
| 3167 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3168 | == isProvisioned) { |
| 3169 | // No change in provisioning. |
| 3170 | return; |
| 3171 | } |
| 3172 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3173 | try { |
| 3174 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3175 | } catch (ImsException e) { |
| 3176 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3177 | + ", Exception" + e.getMessage()); |
| 3178 | } |
| 3179 | break; |
| 3180 | } |
| 3181 | default: { |
| 3182 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3183 | + capability + "', which does not require provisioning."); |
| 3184 | } |
| 3185 | } |
| 3186 | |
| 3187 | } finally { |
| 3188 | Binder.restoreCallingIdentity(identity); |
| 3189 | } |
| 3190 | } |
| 3191 | |
| 3192 | @Override |
| 3193 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3194 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3195 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3196 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3197 | } |
| 3198 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3199 | final long identity = Binder.clearCallingIdentity(); |
| 3200 | try { |
| 3201 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3202 | Phone phone = getPhone(subId); |
| 3203 | if (phone == null) { |
| 3204 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3205 | + subId); |
| 3206 | // We will fail with "true" as the provisioning status because this is the default |
| 3207 | // if we do not require provisioning. |
| 3208 | return true; |
| 3209 | } |
| 3210 | |
| 3211 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3212 | return true; |
| 3213 | } |
| 3214 | |
| 3215 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3216 | switch (capability) { |
| 3217 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3218 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3219 | return ims.isVolteProvisionedOnDevice(); |
| 3220 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3221 | return ims.isWfcProvisionedOnDevice(); |
| 3222 | } |
| 3223 | // This should never happen, since we are checking tech above to make sure it |
| 3224 | // is either LTE or IWLAN. |
| 3225 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3226 | + "capability."); |
| 3227 | } |
| 3228 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3229 | // There is currently no difference in VT provisioning type. |
| 3230 | return ims.isVtProvisionedOnDevice(); |
| 3231 | } |
| 3232 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3233 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3234 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3235 | } |
| 3236 | default: { |
| 3237 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3238 | + capability + "', which does not require provisioning."); |
| 3239 | } |
| 3240 | } |
| 3241 | |
| 3242 | } finally { |
| 3243 | Binder.restoreCallingIdentity(identity); |
| 3244 | } |
| 3245 | } |
| 3246 | |
| 3247 | @Override |
| 3248 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3249 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3250 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3251 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3252 | } |
| 3253 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3254 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3255 | return (provisionedBits & capability) > 0; |
| 3256 | } |
| 3257 | |
| 3258 | @Override |
| 3259 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3260 | boolean isProvisioned) { |
| 3261 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3262 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3263 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3264 | } |
| 3265 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3266 | "setProvisioningStatusForCapability"); |
| 3267 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3268 | // If the current provisioning status for capability already matches isProvisioned, |
| 3269 | // do nothing. |
| 3270 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3271 | return; |
| 3272 | } |
| 3273 | if (isProvisioned) { |
| 3274 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3275 | } else { |
| 3276 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3277 | } |
| 3278 | } |
| 3279 | |
| 3280 | /** |
| 3281 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3282 | * technology. The bitfield should mirror the bitfield defined by |
| 3283 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3284 | */ |
| 3285 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3286 | String key = getMmTelProvisioningKey(subId, tech); |
| 3287 | // Default is no capabilities are provisioned. |
| 3288 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3289 | } |
| 3290 | |
| 3291 | /** |
| 3292 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3293 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3294 | * technology specified. |
| 3295 | * |
| 3296 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3297 | */ |
| 3298 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3299 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3300 | String key = getMmTelProvisioningKey(subId, tech); |
| 3301 | editor.putInt(key, newField); |
| 3302 | editor.commit(); |
| 3303 | } |
| 3304 | |
| 3305 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3306 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3307 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3308 | } |
| 3309 | |
| 3310 | /** |
| 3311 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3312 | * carrier associated with the subscription id. |
| 3313 | */ |
| 3314 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3315 | int capability) { |
| 3316 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3317 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3318 | boolean requireUtProvisioning = c.getBoolean( |
| 3319 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3320 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3321 | // the no-SIM case, where we would normally shortcut this to false. |
| 3322 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3323 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3324 | false); |
| 3325 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3326 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3327 | |
| 3328 | // First check to make sure that the capability requires provisioning. |
| 3329 | switch (capability) { |
| 3330 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3331 | // intentional fallthrough |
| 3332 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3333 | if (requireVoiceVtProvisioning) { |
| 3334 | // Voice and Video requires provisioning |
| 3335 | return true; |
| 3336 | } |
| 3337 | break; |
| 3338 | } |
| 3339 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3340 | if (requireUtProvisioning) { |
| 3341 | // UT requires provisioning |
| 3342 | return true; |
| 3343 | } |
| 3344 | break; |
| 3345 | } |
| 3346 | } |
| 3347 | return false; |
| 3348 | } |
| 3349 | |
| 3350 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3351 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3352 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3353 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3354 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3355 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3356 | final long identity = Binder.clearCallingIdentity(); |
| 3357 | try { |
| 3358 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3359 | int slotId = getSlotIndex(subId); |
| 3360 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3361 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3362 | + subId + "' for key:" + key); |
| 3363 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3364 | } |
| 3365 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3366 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3367 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3368 | + subId + "' for key:" + key); |
| 3369 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3370 | } finally { |
| 3371 | Binder.restoreCallingIdentity(identity); |
| 3372 | } |
| 3373 | } |
| 3374 | |
| 3375 | @Override |
| 3376 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3377 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3378 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3379 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3380 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3381 | final long identity = Binder.clearCallingIdentity(); |
| 3382 | try { |
| 3383 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3384 | int slotId = getSlotIndex(subId); |
| 3385 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3386 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3387 | + subId + "' for key:" + key); |
| 3388 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3389 | } |
| 3390 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3391 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3392 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3393 | + subId + "' for key:" + key); |
| 3394 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3395 | } finally { |
| 3396 | Binder.restoreCallingIdentity(identity); |
| 3397 | } |
| 3398 | } |
| 3399 | |
| 3400 | @Override |
| 3401 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3402 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3403 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3404 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3405 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3406 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3407 | final long identity = Binder.clearCallingIdentity(); |
| 3408 | try { |
| 3409 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3410 | int slotId = getSlotIndex(subId); |
| 3411 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3412 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3413 | + subId + "' for key:" + key); |
| 3414 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3415 | } |
| 3416 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3417 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3418 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3419 | + "' for key:" + key); |
| 3420 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3421 | } finally { |
| 3422 | Binder.restoreCallingIdentity(identity); |
| 3423 | } |
| 3424 | } |
| 3425 | |
| 3426 | @Override |
| 3427 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3428 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3429 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3430 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3431 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3432 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3433 | final long identity = Binder.clearCallingIdentity(); |
| 3434 | try { |
| 3435 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3436 | int slotId = getSlotIndex(subId); |
| 3437 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3438 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3439 | + subId + "' for key:" + key); |
| 3440 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3441 | } |
| 3442 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3443 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3444 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3445 | + "' for key:" + key); |
| 3446 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3447 | } finally { |
| 3448 | Binder.restoreCallingIdentity(identity); |
| 3449 | } |
| 3450 | } |
| 3451 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3452 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3453 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3454 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3455 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3456 | } |
| 3457 | return slotId; |
| 3458 | } |
| 3459 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3460 | private int getSlotIndex(int subId) { |
| 3461 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3462 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3463 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3464 | } |
| 3465 | return slotId; |
| 3466 | } |
| 3467 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3468 | /** |
| 3469 | * Returns the network type for a subId |
| 3470 | */ |
| 3471 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3472 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3473 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3474 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3475 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3476 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3477 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3478 | final long identity = Binder.clearCallingIdentity(); |
| 3479 | try { |
| 3480 | final Phone phone = getPhone(subId); |
| 3481 | if (phone != null) { |
| 3482 | return phone.getServiceState().getDataNetworkType(); |
| 3483 | } else { |
| 3484 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3485 | } |
| 3486 | } finally { |
| 3487 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3488 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3489 | } |
| 3490 | |
| 3491 | /** |
| 3492 | * Returns the data network type |
| 3493 | */ |
| 3494 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3495 | public int getDataNetworkType(String callingPackage) { |
| 3496 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | /** |
| 3500 | * Returns the data network type for a subId |
| 3501 | */ |
| 3502 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3503 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3504 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3505 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3506 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3507 | } |
| 3508 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3509 | final long identity = Binder.clearCallingIdentity(); |
| 3510 | try { |
| 3511 | final Phone phone = getPhone(subId); |
| 3512 | if (phone != null) { |
| 3513 | return phone.getServiceState().getDataNetworkType(); |
| 3514 | } else { |
| 3515 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3516 | } |
| 3517 | } finally { |
| 3518 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3519 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3523 | * Returns the Voice network type for a subId |
| 3524 | */ |
| 3525 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3526 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3527 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3528 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3529 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3530 | } |
| 3531 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3532 | final long identity = Binder.clearCallingIdentity(); |
| 3533 | try { |
| 3534 | final Phone phone = getPhone(subId); |
| 3535 | if (phone != null) { |
| 3536 | return phone.getServiceState().getVoiceNetworkType(); |
| 3537 | } else { |
| 3538 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3539 | } |
| 3540 | } finally { |
| 3541 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3542 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | /** |
| 3546 | * @return true if a ICC card is present |
| 3547 | */ |
| 3548 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3549 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3550 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3551 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3555 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3556 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3557 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3558 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3559 | final long identity = Binder.clearCallingIdentity(); |
| 3560 | try { |
| 3561 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3562 | if (phone != null) { |
| 3563 | return phone.getIccCard().hasIccCard(); |
| 3564 | } else { |
| 3565 | return false; |
| 3566 | } |
| 3567 | } finally { |
| 3568 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3569 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | /** |
| 3573 | * Return if the current radio is LTE on CDMA. This |
| 3574 | * is a tri-state return value as for a period of time |
| 3575 | * the mode may be unknown. |
| 3576 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3577 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3578 | * @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] | 3579 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3580 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3581 | @Override |
| 3582 | public int getLteOnCdmaMode(String callingPackage) { |
| 3583 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3584 | } |
| 3585 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3586 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3587 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3588 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3589 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3590 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3591 | } |
| 3592 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3593 | final long identity = Binder.clearCallingIdentity(); |
| 3594 | try { |
| 3595 | final Phone phone = getPhone(subId); |
| 3596 | if (phone == null) { |
| 3597 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3598 | } else { |
| 3599 | return phone.getLteOnCdmaMode(); |
| 3600 | } |
| 3601 | } finally { |
| 3602 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3603 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3604 | } |
| 3605 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3606 | /** |
| 3607 | * {@hide} |
| 3608 | * Returns Default subId, 0 in the case of single standby. |
| 3609 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3610 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3611 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3614 | private int getSlotForDefaultSubscription() { |
| 3615 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3616 | } |
| 3617 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3618 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3619 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3620 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3621 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3622 | private boolean isActiveSubscription(int subId) { |
| 3623 | return mSubscriptionController.isActiveSubId(subId); |
| 3624 | } |
| 3625 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3626 | /** |
| 3627 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3628 | */ |
| 3629 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3630 | final long identity = Binder.clearCallingIdentity(); |
| 3631 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3632 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3633 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3634 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3635 | } finally { |
| 3636 | Binder.restoreCallingIdentity(identity); |
| 3637 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3638 | } |
| 3639 | |
| 3640 | /** |
| 3641 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3642 | */ |
| 3643 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3644 | final long identity = Binder.clearCallingIdentity(); |
| 3645 | try { |
| 3646 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3647 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3648 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3649 | } finally { |
| 3650 | Binder.restoreCallingIdentity(identity); |
| 3651 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3652 | } |
| 3653 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3654 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3655 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3656 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3657 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3658 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3659 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3660 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3661 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3662 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3663 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3664 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3665 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3666 | final long identity = Binder.clearCallingIdentity(); |
| 3667 | try { |
| 3668 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3669 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3670 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3671 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3672 | if (bestComponent == null |
| 3673 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3674 | loge("The calling package is not allowed to access ISD-R."); |
| 3675 | throw new SecurityException( |
| 3676 | "The calling package is not allowed to access ISD-R."); |
| 3677 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3678 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3679 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3680 | if (DBG) { |
| 3681 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3682 | } |
| 3683 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| 3684 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
| 3685 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 3686 | return response; |
| 3687 | } finally { |
| 3688 | Binder.restoreCallingIdentity(identity); |
| 3689 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3690 | } |
| 3691 | |
| 3692 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3693 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3694 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3695 | mApp, subId, "iccCloseLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3696 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3697 | final long identity = Binder.clearCallingIdentity(); |
| 3698 | try { |
| 3699 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3700 | if (channel < 0) { |
| 3701 | return false; |
| 3702 | } |
| 3703 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
| 3704 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 3705 | return success; |
| 3706 | } finally { |
| 3707 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3708 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3712 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3713 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3714 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3715 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3716 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3717 | final long identity = Binder.clearCallingIdentity(); |
| 3718 | try { |
| 3719 | if (DBG) { |
| 3720 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3721 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3722 | + p3 + " data=" + data); |
| 3723 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3724 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3725 | if (channel < 0) { |
| 3726 | return ""; |
| 3727 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3728 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3729 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| 3730 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
| 3731 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3732 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3733 | // Append the returned status code to the end of the response payload. |
| 3734 | String s = Integer.toHexString( |
| 3735 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3736 | if (response.payload != null) { |
| 3737 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3738 | } |
| 3739 | return s; |
| 3740 | } finally { |
| 3741 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3742 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3743 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3744 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3745 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3746 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3747 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3748 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3749 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3750 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3751 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3752 | final long identity = Binder.clearCallingIdentity(); |
| 3753 | try { |
| 3754 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3755 | && TextUtils.equals(ISDR_AID, data)) { |
| 3756 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3757 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3758 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3759 | if (bestComponent == null |
| 3760 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3761 | loge("The calling package is not allowed to select ISD-R."); |
| 3762 | throw new SecurityException( |
| 3763 | "The calling package is not allowed to select ISD-R."); |
| 3764 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3765 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3766 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3767 | if (DBG) { |
| 3768 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3769 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3770 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3771 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3772 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 3773 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
| 3774 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3775 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3776 | // Append the returned status code to the end of the response payload. |
| 3777 | String s = Integer.toHexString( |
| 3778 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3779 | if (response.payload != null) { |
| 3780 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3781 | } |
| 3782 | return s; |
| 3783 | } finally { |
| 3784 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3785 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3786 | } |
| 3787 | |
| 3788 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3789 | 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] | 3790 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3791 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3792 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3793 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3794 | final long identity = Binder.clearCallingIdentity(); |
| 3795 | try { |
| 3796 | if (DBG) { |
| 3797 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3798 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3799 | } |
| 3800 | |
| 3801 | IccIoResult response = |
| 3802 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3803 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3804 | subId); |
| 3805 | |
| 3806 | if (DBG) { |
| 3807 | log("Exchange SIM_IO [R]" + response); |
| 3808 | } |
| 3809 | |
| 3810 | byte[] result = null; |
| 3811 | int length = 2; |
| 3812 | if (response.payload != null) { |
| 3813 | length = 2 + response.payload.length; |
| 3814 | result = new byte[length]; |
| 3815 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3816 | } else { |
| 3817 | result = new byte[length]; |
| 3818 | } |
| 3819 | |
| 3820 | result[length - 1] = (byte) response.sw2; |
| 3821 | result[length - 2] = (byte) response.sw1; |
| 3822 | return result; |
| 3823 | } finally { |
| 3824 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3825 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3826 | } |
| 3827 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3828 | /** |
| 3829 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3830 | * on a particular subscription |
| 3831 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3832 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3833 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3834 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3835 | return null; |
| 3836 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3837 | |
| 3838 | final long identity = Binder.clearCallingIdentity(); |
| 3839 | try { |
| 3840 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3841 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3842 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3843 | return null; |
| 3844 | } |
| 3845 | Object response = sendRequest( |
| 3846 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3847 | if (response instanceof String[]) { |
| 3848 | return (String[]) response; |
| 3849 | } |
| 3850 | // Response is an Exception of some kind, |
| 3851 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3852 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3853 | } finally { |
| 3854 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3855 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3856 | } |
| 3857 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3858 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3859 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3860 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3861 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3862 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3863 | final long identity = Binder.clearCallingIdentity(); |
| 3864 | try { |
| 3865 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3866 | if (response.payload == null) { |
| 3867 | return ""; |
| 3868 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3869 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3870 | // Append the returned status code to the end of the response payload. |
| 3871 | String s = Integer.toHexString( |
| 3872 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3873 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3874 | return s; |
| 3875 | } finally { |
| 3876 | Binder.restoreCallingIdentity(identity); |
| 3877 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3878 | } |
| 3879 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3880 | /** |
| 3881 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3882 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3883 | * |
| 3884 | * @param itemID the ID of the item to read |
| 3885 | * @return the NV item as a String, or null on error. |
| 3886 | */ |
| 3887 | @Override |
| 3888 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3889 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3890 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3891 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3892 | |
| 3893 | final long identity = Binder.clearCallingIdentity(); |
| 3894 | try { |
| 3895 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3896 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3897 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 3898 | return value; |
| 3899 | } finally { |
| 3900 | Binder.restoreCallingIdentity(identity); |
| 3901 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | /** |
| 3905 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3906 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3907 | * |
| 3908 | * @param itemID the ID of the item to read |
| 3909 | * @param itemValue the value to write, as a String |
| 3910 | * @return true on success; false on any failure |
| 3911 | */ |
| 3912 | @Override |
| 3913 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3914 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3915 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3916 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3917 | |
| 3918 | final long identity = Binder.clearCallingIdentity(); |
| 3919 | try { |
| 3920 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 3921 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3922 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3923 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 3924 | return success; |
| 3925 | } finally { |
| 3926 | Binder.restoreCallingIdentity(identity); |
| 3927 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3928 | } |
| 3929 | |
| 3930 | /** |
| 3931 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 3932 | * Used for device configuration by some CDMA operators. |
| 3933 | * |
| 3934 | * @param preferredRoamingList byte array containing the new PRL |
| 3935 | * @return true on success; false on any failure |
| 3936 | */ |
| 3937 | @Override |
| 3938 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3939 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3940 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3941 | |
| 3942 | final long identity = Binder.clearCallingIdentity(); |
| 3943 | try { |
| 3944 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 3945 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 3946 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 3947 | return success; |
| 3948 | } finally { |
| 3949 | Binder.restoreCallingIdentity(identity); |
| 3950 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3954 | * 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] | 3955 | * Used for device configuration by some CDMA operators. |
| 3956 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3957 | * @param slotIndex - device slot. |
| 3958 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3959 | * @return true on success; false on any failure |
| 3960 | */ |
| 3961 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3962 | public boolean resetModemConfig(int slotIndex) { |
| 3963 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3964 | if (phone != null) { |
| 3965 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3966 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3967 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3968 | final long identity = Binder.clearCallingIdentity(); |
| 3969 | try { |
| 3970 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 3971 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 3972 | return success; |
| 3973 | } finally { |
| 3974 | Binder.restoreCallingIdentity(identity); |
| 3975 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3976 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3977 | return false; |
| 3978 | } |
| 3979 | |
| 3980 | /** |
| 3981 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 3982 | * |
| 3983 | * @param slotIndex - device slot. |
| 3984 | * |
| 3985 | * @return true on success; false on any failure |
| 3986 | */ |
| 3987 | @Override |
| 3988 | public boolean rebootModem(int slotIndex) { |
| 3989 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3990 | if (phone != null) { |
| 3991 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3992 | mApp, phone.getSubId(), "rebootModem"); |
| 3993 | |
| 3994 | final long identity = Binder.clearCallingIdentity(); |
| 3995 | try { |
| 3996 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 3997 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 3998 | return success; |
| 3999 | } finally { |
| 4000 | Binder.restoreCallingIdentity(identity); |
| 4001 | } |
| 4002 | } |
| 4003 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4004 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4005 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4006 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4007 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4008 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4009 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4010 | return new String[0]; |
| 4011 | } |
| 4012 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4013 | final long identity = Binder.clearCallingIdentity(); |
| 4014 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4015 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4016 | } finally { |
| 4017 | Binder.restoreCallingIdentity(identity); |
| 4018 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4019 | } |
| 4020 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4021 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4022 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4023 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4024 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4025 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4026 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4027 | |
| 4028 | final long identity = Binder.clearCallingIdentity(); |
| 4029 | try { |
| 4030 | PhoneFactory.getImsResolver().enableIms(slotId); |
| 4031 | } finally { |
| 4032 | Binder.restoreCallingIdentity(identity); |
| 4033 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4034 | } |
| 4035 | |
| 4036 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4037 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4038 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4039 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4040 | public void disableIms(int slotId) { |
| 4041 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4042 | |
| 4043 | final long identity = Binder.clearCallingIdentity(); |
| 4044 | try { |
| 4045 | PhoneFactory.getImsResolver().disableIms(slotId); |
| 4046 | } finally { |
| 4047 | Binder.restoreCallingIdentity(identity); |
| 4048 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | /** |
| 4052 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4053 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4054 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4055 | */ |
| 4056 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4057 | IImsServiceFeatureCallback callback) { |
| 4058 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4059 | |
| 4060 | final long identity = Binder.clearCallingIdentity(); |
| 4061 | try { |
| 4062 | return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback); |
| 4063 | } finally { |
| 4064 | Binder.restoreCallingIdentity(identity); |
| 4065 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | /** |
| 4069 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4070 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4071 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4072 | * listener for feature updates. |
| 4073 | */ |
| 4074 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4075 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4076 | |
| 4077 | final long identity = Binder.clearCallingIdentity(); |
| 4078 | try { |
| 4079 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); |
| 4080 | } finally { |
| 4081 | Binder.restoreCallingIdentity(identity); |
| 4082 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4083 | } |
| 4084 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4085 | /** |
| 4086 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| 4087 | * specified. |
| 4088 | */ |
| 4089 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4090 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4091 | |
| 4092 | final long identity = Binder.clearCallingIdentity(); |
| 4093 | try { |
| 4094 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); |
| 4095 | } finally { |
| 4096 | Binder.restoreCallingIdentity(identity); |
| 4097 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4098 | } |
| 4099 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4100 | /** |
| 4101 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| 4102 | * specified. |
| 4103 | */ |
| 4104 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4105 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4106 | |
| 4107 | final long identity = Binder.clearCallingIdentity(); |
| 4108 | try { |
| 4109 | return PhoneFactory.getImsResolver().getImsConfig(slotId, feature); |
| 4110 | } finally { |
| 4111 | Binder.restoreCallingIdentity(identity); |
| 4112 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4113 | } |
| 4114 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4115 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4116 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4117 | * |
| 4118 | * @param slotId the slot ID that the ImsService should bind for. |
| 4119 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4120 | * ImsService is the device default ImsService. |
| 4121 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4122 | * to. |
| 4123 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4124 | * @hide |
| 4125 | */ |
| 4126 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4127 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4128 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4129 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4130 | "setImsService"); |
| 4131 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4132 | final long identity = Binder.clearCallingIdentity(); |
| 4133 | try { |
| 4134 | return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId, |
| 4135 | isCarrierImsService, packageName); |
| 4136 | } finally { |
| 4137 | Binder.restoreCallingIdentity(identity); |
| 4138 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4139 | } |
| 4140 | |
| 4141 | /** |
| 4142 | * Return the ImsService configuration. |
| 4143 | * |
| 4144 | * @param slotId The slot that the ImsService is associated with. |
| 4145 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4146 | * the device default. |
| 4147 | * @return the package name of the ImsService configuration. |
| 4148 | */ |
| 4149 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4150 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4151 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4152 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4153 | "getImsService"); |
| 4154 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4155 | final long identity = Binder.clearCallingIdentity(); |
| 4156 | try { |
| 4157 | return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId, |
| 4158 | isCarrierImsService); |
| 4159 | } finally { |
| 4160 | Binder.restoreCallingIdentity(identity); |
| 4161 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4162 | } |
| 4163 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4164 | public void setImsRegistrationState(boolean registered) { |
| 4165 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4166 | |
| 4167 | final long identity = Binder.clearCallingIdentity(); |
| 4168 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4169 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4170 | } finally { |
| 4171 | Binder.restoreCallingIdentity(identity); |
| 4172 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4173 | } |
| 4174 | |
| 4175 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4176 | * Set the network selection mode to automatic. |
| 4177 | * |
| 4178 | */ |
| 4179 | @Override |
| 4180 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4181 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4182 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4183 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4184 | if (!isActiveSubscription(subId)) { |
| 4185 | return; |
| 4186 | } |
| 4187 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4188 | final long identity = Binder.clearCallingIdentity(); |
| 4189 | try { |
| 4190 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4191 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4192 | } finally { |
| 4193 | Binder.restoreCallingIdentity(identity); |
| 4194 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4195 | } |
| 4196 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4197 | /** |
| 4198 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4199 | * |
| 4200 | * @param subId the id of the subscription. |
| 4201 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4202 | * the operator to attach to. |
| 4203 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4204 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4205 | * normal network selection next time. |
| 4206 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4207 | */ |
| 4208 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4209 | public boolean setNetworkSelectionModeManual( |
| 4210 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4211 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4212 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4213 | |
| 4214 | if (!isActiveSubscription(subId)) { |
| 4215 | return false; |
| 4216 | } |
| 4217 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4218 | final long identity = Binder.clearCallingIdentity(); |
| 4219 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4220 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4221 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4222 | if (DBG) { |
| 4223 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4224 | + " operator: " + operatorInfo); |
| 4225 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4226 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4227 | } finally { |
| 4228 | Binder.restoreCallingIdentity(identity); |
| 4229 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | /** |
| 4233 | * Scans for available networks. |
| 4234 | */ |
| 4235 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4236 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4237 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4238 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4239 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4240 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4241 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4242 | .setCallingPackage(callingPackage) |
| 4243 | .setCallingPid(Binder.getCallingPid()) |
| 4244 | .setCallingUid(Binder.getCallingUid()) |
| 4245 | .setMethod("getCellNetworkScanResults") |
| 4246 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4247 | .build()); |
| 4248 | switch (locationResult) { |
| 4249 | case DENIED_HARD: |
| 4250 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4251 | case DENIED_SOFT: |
| 4252 | return null; |
| 4253 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4254 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4255 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4256 | try { |
| 4257 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4258 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4259 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4260 | } finally { |
| 4261 | Binder.restoreCallingIdentity(identity); |
| 4262 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4266 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4267 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4268 | * @param subId id of the subscription |
| 4269 | * @param request contains the radio access networks with bands/channels to scan |
| 4270 | * @param messenger callback messenger for scan results or errors |
| 4271 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4272 | * @return the id of the requested scan which can be used to stop the scan. |
| 4273 | */ |
| 4274 | @Override |
| 4275 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4276 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4277 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4278 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4279 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4280 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4281 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4282 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4283 | .setCallingPackage(callingPackage) |
| 4284 | .setCallingPid(Binder.getCallingPid()) |
| 4285 | .setCallingUid(Binder.getCallingUid()) |
| 4286 | .setMethod("requestNetworkScan") |
| 4287 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4288 | .build()); |
| 4289 | switch (locationResult) { |
| 4290 | case DENIED_HARD: |
| 4291 | throw new SecurityException("Not allowed to request network scan -- location"); |
| 4292 | case DENIED_SOFT: |
| 4293 | return -1; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4294 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4295 | |
| 4296 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4297 | request, messenger, binder, getPhone(subId), |
| 4298 | callingPackage); |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | /** |
| 4302 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4303 | * |
| 4304 | * @param subId id of the subscription |
| 4305 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4306 | */ |
| 4307 | @Override |
| 4308 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4309 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4310 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4311 | |
| 4312 | final long identity = Binder.clearCallingIdentity(); |
| 4313 | try { |
| 4314 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 4315 | } finally { |
| 4316 | Binder.restoreCallingIdentity(identity); |
| 4317 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4321 | * Get the calculated preferred network type. |
| 4322 | * Used for debugging incorrect network type. |
| 4323 | * |
| 4324 | * @return the preferred network type, defined in RILConstants.java. |
| 4325 | */ |
| 4326 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4327 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4328 | final Phone defaultPhone = getDefaultPhone(); |
| 4329 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4330 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4331 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4332 | } |
| 4333 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4334 | final long identity = Binder.clearCallingIdentity(); |
| 4335 | try { |
| 4336 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4337 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4338 | } finally { |
| 4339 | Binder.restoreCallingIdentity(identity); |
| 4340 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4344 | * Get the preferred network type. |
| 4345 | * Used for device configuration by some CDMA operators. |
| 4346 | * |
| 4347 | * @return the preferred network type, defined in RILConstants.java. |
| 4348 | */ |
| 4349 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4350 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | 4848cd0 | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4351 | TelephonyPermissions |
| 4352 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4353 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4354 | |
| 4355 | final long identity = Binder.clearCallingIdentity(); |
| 4356 | try { |
| 4357 | if (DBG) log("getPreferredNetworkType"); |
| 4358 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4359 | int networkType = (result != null ? result[0] : -1); |
| 4360 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4361 | return networkType; |
| 4362 | } finally { |
| 4363 | Binder.restoreCallingIdentity(identity); |
| 4364 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4365 | } |
| 4366 | |
| 4367 | /** |
| 4368 | * Set the preferred network type. |
| 4369 | * Used for device configuration by some CDMA operators. |
| 4370 | * |
| 4371 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4372 | * @return true on success; false on any failure. |
| 4373 | */ |
| 4374 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4375 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4376 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4377 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4378 | |
| 4379 | final long identity = Binder.clearCallingIdentity(); |
| 4380 | try { |
| 4381 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4382 | Boolean success = (Boolean) sendRequest( |
| 4383 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4384 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4385 | if (success) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4386 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4387 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4388 | } |
| 4389 | return success; |
| 4390 | } finally { |
| 4391 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4392 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4393 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4394 | |
| 4395 | /** |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4396 | * Check whether DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4397 | * |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4398 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4399 | * @hide |
| 4400 | */ |
| 4401 | @Override |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4402 | public boolean getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4403 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4404 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4405 | final Phone defaultPhone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4406 | try { |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4407 | return defaultPhone.hasMatchedTetherApnSetting(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4408 | } finally { |
| 4409 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4410 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4411 | } |
| 4412 | |
| 4413 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4414 | * Set mobile data enabled |
| 4415 | * Used by the user through settings etc to turn on/off mobile data |
| 4416 | * |
| 4417 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4418 | */ |
| 4419 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4420 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4421 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4422 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4423 | |
| 4424 | final long identity = Binder.clearCallingIdentity(); |
| 4425 | try { |
| 4426 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4427 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4428 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4429 | if (phone != null) { |
| 4430 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4431 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4432 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4433 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4434 | } |
| 4435 | } finally { |
| 4436 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4437 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4438 | } |
| 4439 | |
| 4440 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4441 | * Get the user enabled state of Mobile Data. |
| 4442 | * |
| 4443 | * TODO: remove and use isUserDataEnabled. |
| 4444 | * This can't be removed now because some vendor codes |
| 4445 | * calls through ITelephony directly while they should |
| 4446 | * use TelephonyManager. |
| 4447 | * |
| 4448 | * @return true on enabled |
| 4449 | */ |
| 4450 | @Override |
| 4451 | public boolean getDataEnabled(int subId) { |
| 4452 | return isUserDataEnabled(subId); |
| 4453 | } |
| 4454 | |
| 4455 | /** |
| 4456 | * Get whether mobile data is enabled per user setting. |
| 4457 | * |
| 4458 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4459 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4460 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4461 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4462 | * |
| 4463 | * @return {@code true} if data is enabled else {@code false} |
| 4464 | */ |
| 4465 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4466 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4467 | try { |
| 4468 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4469 | null); |
| 4470 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4471 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4472 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4473 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4474 | |
| 4475 | final long identity = Binder.clearCallingIdentity(); |
| 4476 | try { |
| 4477 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4478 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4479 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4480 | if (phone != null) { |
| 4481 | boolean retVal = phone.isUserDataEnabled(); |
| 4482 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4483 | return retVal; |
| 4484 | } else { |
| 4485 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4486 | return false; |
| 4487 | } |
| 4488 | } finally { |
| 4489 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4490 | } |
| 4491 | } |
| 4492 | |
| 4493 | /** |
| 4494 | * Get whether mobile data is enabled. |
| 4495 | * |
| 4496 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4497 | * whether mobile data is actually enabled. |
| 4498 | * |
| 4499 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4500 | * |
| 4501 | * @return {@code true} if data is enabled else {@code false} |
| 4502 | */ |
| 4503 | @Override |
| 4504 | public boolean isDataEnabled(int subId) { |
| 4505 | try { |
| 4506 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4507 | null); |
| 4508 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4509 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4510 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4511 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4512 | |
| 4513 | final long identity = Binder.clearCallingIdentity(); |
| 4514 | try { |
| 4515 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4516 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4517 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4518 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4519 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4520 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4521 | return retVal; |
| 4522 | } else { |
| 4523 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4524 | return false; |
| 4525 | } |
| 4526 | } finally { |
| 4527 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4528 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4529 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4530 | |
| 4531 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4532 | public int getCarrierPrivilegeStatus(int subId) { |
| 4533 | final Phone phone = getPhone(subId); |
| 4534 | if (phone == null) { |
| 4535 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4536 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4537 | } |
| 4538 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4539 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4540 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4541 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4542 | } |
| 4543 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4544 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4545 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4546 | |
| 4547 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4548 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4549 | final Phone phone = getPhone(subId); |
| 4550 | if (phone == null) { |
| 4551 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4552 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4553 | } |
| 4554 | UiccProfile profile = |
| 4555 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4556 | if (profile == null) { |
| 4557 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4558 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4559 | } |
| 4560 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4561 | } |
| 4562 | |
| 4563 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4564 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4565 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4566 | if (TextUtils.isEmpty(pkgName)) |
| 4567 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4568 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4569 | if (card == null) { |
| 4570 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4571 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4572 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4573 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4574 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4575 | } |
| 4576 | |
| 4577 | @Override |
| 4578 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4579 | if (TextUtils.isEmpty(pkgName)) |
| 4580 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4581 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4582 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4583 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4584 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4585 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4586 | continue; |
| 4587 | } |
| 4588 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4589 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4590 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4591 | break; |
| 4592 | } |
| 4593 | } |
| 4594 | |
| 4595 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4596 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4597 | |
| 4598 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4599 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4600 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4601 | loge("phoneId " + phoneId + " is not valid."); |
| 4602 | return null; |
| 4603 | } |
| 4604 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4605 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4606 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4607 | return null ; |
| 4608 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4609 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4610 | } |
| 4611 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4612 | @Override |
| 4613 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4614 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4615 | List<String> privilegedPackages = new ArrayList<>(); |
| 4616 | List<PackageInfo> packages = null; |
| 4617 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4618 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4619 | if (card == null) { |
| 4620 | // No UICC in that slot. |
| 4621 | continue; |
| 4622 | } |
| 4623 | if (card.hasCarrierPrivilegeRules()) { |
| 4624 | if (packages == null) { |
| 4625 | // Only check packages in user 0 for now |
| 4626 | packages = pm.getInstalledPackagesAsUser( |
| 4627 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4628 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4629 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4630 | } |
| 4631 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4632 | PackageInfo pkgInfo = packages.get(p); |
| 4633 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4634 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4635 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4636 | privilegedPackages.add(pkgInfo.packageName); |
| 4637 | } |
| 4638 | } |
| 4639 | } |
| 4640 | } |
| 4641 | return privilegedPackages; |
| 4642 | } |
| 4643 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4644 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4645 | final Phone phone = getPhone(subId); |
| 4646 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4647 | if (card == null) { |
| 4648 | loge("getIccId: No UICC"); |
| 4649 | return null; |
| 4650 | } |
| 4651 | String iccId = card.getIccId(); |
| 4652 | if (TextUtils.isEmpty(iccId)) { |
| 4653 | loge("getIccId: ICC ID is null or empty."); |
| 4654 | return null; |
| 4655 | } |
| 4656 | return iccId; |
| 4657 | } |
| 4658 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4659 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4660 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4661 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4662 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4663 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4664 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4665 | final long identity = Binder.clearCallingIdentity(); |
| 4666 | try { |
| 4667 | final String iccId = getIccId(subId); |
| 4668 | final Phone phone = getPhone(subId); |
| 4669 | if (phone == null) { |
| 4670 | return false; |
| 4671 | } |
| 4672 | final String subscriberId = phone.getSubscriberId(); |
| 4673 | |
| 4674 | if (DBG_MERGE) { |
| 4675 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4676 | + subscriberId + " to " + number); |
| 4677 | } |
| 4678 | |
| 4679 | if (TextUtils.isEmpty(iccId)) { |
| 4680 | return false; |
| 4681 | } |
| 4682 | |
| 4683 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4684 | |
| 4685 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4686 | if (alphaTag == null) { |
| 4687 | editor.remove(alphaTagPrefKey); |
| 4688 | } else { |
| 4689 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4690 | } |
| 4691 | |
| 4692 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4693 | // track all merged IMSIs based on line number |
| 4694 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4695 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4696 | if (number == null) { |
| 4697 | editor.remove(numberPrefKey); |
| 4698 | editor.remove(subscriberPrefKey); |
| 4699 | } else { |
| 4700 | editor.putString(numberPrefKey, number); |
| 4701 | editor.putString(subscriberPrefKey, subscriberId); |
| 4702 | } |
| 4703 | |
| 4704 | editor.commit(); |
| 4705 | return true; |
| 4706 | } finally { |
| 4707 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4708 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4709 | } |
| 4710 | |
| 4711 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4712 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4713 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4714 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4715 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4716 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4717 | return null; |
| 4718 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4719 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4720 | final long identity = Binder.clearCallingIdentity(); |
| 4721 | try { |
| 4722 | String iccId = getIccId(subId); |
| 4723 | if (iccId != null) { |
| 4724 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4725 | if (DBG_MERGE) { |
| 4726 | log("getLine1NumberForDisplay returning " |
| 4727 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4728 | } |
| 4729 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4730 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4731 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4732 | return null; |
| 4733 | } finally { |
| 4734 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4735 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4739 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4740 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4741 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4742 | return null; |
| 4743 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4744 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4745 | final long identity = Binder.clearCallingIdentity(); |
| 4746 | try { |
| 4747 | String iccId = getIccId(subId); |
| 4748 | if (iccId != null) { |
| 4749 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4750 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4751 | } |
| 4752 | return null; |
| 4753 | } finally { |
| 4754 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4755 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4756 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4757 | |
| 4758 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4759 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4760 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4761 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4762 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4763 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4764 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4765 | return null; |
| 4766 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4767 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4768 | final long identity = Binder.clearCallingIdentity(); |
| 4769 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4770 | final Context context = mApp; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4771 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4772 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4773 | |
| 4774 | // Figure out what subscribers are currently active |
| 4775 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4776 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4777 | // the process, where TelephonyManager was instantiated. |
| 4778 | // Otherwise AppOps check will fail. |
| 4779 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4780 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4781 | for (int subId : subIds) { |
| 4782 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4783 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4784 | |
| 4785 | // First pass, find a number override for an active subscriber |
| 4786 | String mergeNumber = null; |
| 4787 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4788 | for (String key : prefs.keySet()) { |
| 4789 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4790 | final String subscriberId = (String) prefs.get(key); |
| 4791 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4792 | final String iccId = key.substring( |
| 4793 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4794 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4795 | mergeNumber = (String) prefs.get(numberKey); |
| 4796 | if (DBG_MERGE) { |
| 4797 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4798 | + " for active subscriber " + subscriberId); |
| 4799 | } |
| 4800 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4801 | break; |
| 4802 | } |
| 4803 | } |
| 4804 | } |
| 4805 | } |
| 4806 | |
| 4807 | // Shortcut when no active merged subscribers |
| 4808 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4809 | return null; |
| 4810 | } |
| 4811 | |
| 4812 | // Second pass, find all subscribers under that line override |
| 4813 | final ArraySet<String> result = new ArraySet<>(); |
| 4814 | for (String key : prefs.keySet()) { |
| 4815 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4816 | final String number = (String) prefs.get(key); |
| 4817 | if (mergeNumber.equals(number)) { |
| 4818 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4819 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4820 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4821 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4822 | result.add(subscriberId); |
| 4823 | } |
| 4824 | } |
| 4825 | } |
| 4826 | } |
| 4827 | |
| 4828 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4829 | Arrays.sort(resultArray); |
| 4830 | if (DBG_MERGE) { |
| 4831 | Slog.d(LOG_TAG, |
| 4832 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4833 | } |
| 4834 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4835 | } finally { |
| 4836 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4837 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4841 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4842 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4843 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4844 | |
| 4845 | final long identity = Binder.clearCallingIdentity(); |
| 4846 | try { |
| 4847 | final Phone phone = getPhone(subId); |
| 4848 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4849 | } finally { |
| 4850 | Binder.restoreCallingIdentity(identity); |
| 4851 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4852 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4853 | |
| 4854 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4855 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4856 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 4857 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4858 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4859 | |
| 4860 | final long identity = Binder.clearCallingIdentity(); |
| 4861 | try { |
| 4862 | final Phone phone = getPhone(subId); |
| 4863 | if (phone == null) { |
| 4864 | return false; |
| 4865 | } |
| 4866 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 4867 | cdmaNonRoamingList); |
| 4868 | } finally { |
| 4869 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4870 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4871 | } |
| 4872 | |
| 4873 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4874 | @Deprecated |
| 4875 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 4876 | enforceModifyPermission(); |
| 4877 | |
| 4878 | int returnValue = 0; |
| 4879 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4880 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4881 | if(result.exception == null) { |
| 4882 | if (result.result != null) { |
| 4883 | byte[] responseData = (byte[])(result.result); |
| 4884 | if(responseData.length > oemResp.length) { |
| 4885 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 4886 | responseData.length + "bytes. Buffer Size is " + |
| 4887 | oemResp.length + "bytes."); |
| 4888 | } |
| 4889 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 4890 | returnValue = responseData.length; |
| 4891 | } |
| 4892 | } else { |
| 4893 | CommandException ex = (CommandException) result.exception; |
| 4894 | returnValue = ex.getCommandError().ordinal(); |
| 4895 | if(returnValue > 0) returnValue *= -1; |
| 4896 | } |
| 4897 | } catch (RuntimeException e) { |
| 4898 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 4899 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 4900 | if(returnValue > 0) returnValue *= -1; |
| 4901 | } |
| 4902 | |
| 4903 | return returnValue; |
| 4904 | } |
| 4905 | |
| 4906 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4907 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 4908 | try { |
| 4909 | ProxyController.getInstance().setRadioCapability(rafs); |
| 4910 | } catch (RuntimeException e) { |
| 4911 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 4912 | } |
| 4913 | } |
| 4914 | |
| 4915 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4916 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4917 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4918 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4919 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4920 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4921 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4922 | final long identity = Binder.clearCallingIdentity(); |
| 4923 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4924 | TelephonyPermissions |
| 4925 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4926 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 4927 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4928 | } finally { |
| 4929 | Binder.restoreCallingIdentity(identity); |
| 4930 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4931 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4932 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4933 | |
| 4934 | @Override |
| 4935 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4936 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4937 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4938 | |
| 4939 | final long identity = Binder.clearCallingIdentity(); |
| 4940 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4941 | ImsManager.getInstance(defaultPhone.getContext(), |
| 4942 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4943 | } finally { |
| 4944 | Binder.restoreCallingIdentity(identity); |
| 4945 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4946 | } |
| 4947 | |
| 4948 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4949 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4950 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4951 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4952 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4953 | return false; |
| 4954 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4955 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4956 | final long identity = Binder.clearCallingIdentity(); |
| 4957 | try { |
| 4958 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 4959 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 4960 | // In the long run, we may instead need to check if there exists a connection service |
| 4961 | // which can support video calling. |
| 4962 | ImsManager imsManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4963 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4964 | return imsManager.isVtEnabledByPlatform() |
| 4965 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 4966 | && imsManager.isVtEnabledByUser(); |
| 4967 | } finally { |
| 4968 | Binder.restoreCallingIdentity(identity); |
| 4969 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4970 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 4971 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4972 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4973 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 4974 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4975 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4976 | return false; |
| 4977 | } |
| 4978 | |
| 4979 | final long identity = Binder.clearCallingIdentity(); |
| 4980 | try { |
| 4981 | CarrierConfigManager configManager = |
| 4982 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4983 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4984 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 4985 | } finally { |
| 4986 | Binder.restoreCallingIdentity(identity); |
| 4987 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4988 | } |
| 4989 | |
| 4990 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4991 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 4992 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4993 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4994 | return false; |
| 4995 | } |
| 4996 | |
| 4997 | final long identity = Binder.clearCallingIdentity(); |
| 4998 | try { |
| 4999 | CarrierConfigManager configManager = |
| 5000 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5001 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5002 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5003 | } finally { |
| 5004 | Binder.restoreCallingIdentity(identity); |
| 5005 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5006 | } |
| 5007 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5008 | @Override |
| 5009 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5010 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5011 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5012 | } |
| 5013 | |
| 5014 | @Override |
| 5015 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5016 | final long identity = Binder.clearCallingIdentity(); |
| 5017 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5018 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5019 | } finally { |
| 5020 | Binder.restoreCallingIdentity(identity); |
| 5021 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5022 | } |
| 5023 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5024 | /** |
| 5025 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5026 | * support for the feature and device firmware support. |
| 5027 | * |
| 5028 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5029 | */ |
| 5030 | @Override |
| 5031 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5032 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5033 | final Phone phone = getPhone(subscriptionId); |
| 5034 | if (phone == null) { |
| 5035 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5036 | return false; |
| 5037 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5038 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5039 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5040 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5041 | boolean isDeviceSupported = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5042 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5043 | return isCarrierSupported && isDeviceSupported; |
| 5044 | } finally { |
| 5045 | Binder.restoreCallingIdentity(identity); |
| 5046 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5047 | } |
| 5048 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5049 | /** |
| 5050 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 5051 | * both also support RTT. |
| 5052 | */ |
| 5053 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5054 | final long identity = Binder.clearCallingIdentity(); |
| 5055 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5056 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5057 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5058 | } finally { |
| 5059 | Binder.restoreCallingIdentity(identity); |
| 5060 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5061 | } |
| 5062 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5063 | /** |
| 5064 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5065 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5066 | * |
| 5067 | * <p>Requires Permission: |
| 5068 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5069 | */ |
| 5070 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5071 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5072 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5073 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5074 | return null; |
| 5075 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5076 | int subId = phone.getSubId(); |
| 5077 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5078 | mApp, subId, callingPackage, "getDeviceId")) { |
| 5079 | return null; |
| 5080 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5081 | |
| 5082 | final long identity = Binder.clearCallingIdentity(); |
| 5083 | try { |
| 5084 | return phone.getDeviceId(); |
| 5085 | } finally { |
| 5086 | Binder.restoreCallingIdentity(identity); |
| 5087 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5088 | } |
| 5089 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5090 | /** |
| 5091 | * {@hide} |
| 5092 | * Returns the IMS Registration Status on a particular subid |
| 5093 | * |
| 5094 | * @param subId |
| 5095 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5096 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5097 | Phone phone = getPhone(subId); |
| 5098 | if (phone != null) { |
| 5099 | return phone.isImsRegistered(); |
| 5100 | } else { |
| 5101 | return false; |
| 5102 | } |
| 5103 | } |
| 5104 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5105 | @Override |
| 5106 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5107 | final long identity = Binder.clearCallingIdentity(); |
| 5108 | try { |
| 5109 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5110 | } finally { |
| 5111 | Binder.restoreCallingIdentity(identity); |
| 5112 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5113 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5114 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5115 | /** |
| 5116 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5117 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5118 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5119 | final long identity = Binder.clearCallingIdentity(); |
| 5120 | try { |
| 5121 | Phone phone = getPhone(subId); |
| 5122 | if (phone != null) { |
| 5123 | return phone.isWifiCallingEnabled(); |
| 5124 | } else { |
| 5125 | return false; |
| 5126 | } |
| 5127 | } finally { |
| 5128 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5129 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5130 | } |
| 5131 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5132 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5133 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5134 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5135 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5136 | final long identity = Binder.clearCallingIdentity(); |
| 5137 | try { |
| 5138 | Phone phone = getPhone(subId); |
| 5139 | if (phone != null) { |
| 5140 | return phone.isVideoEnabled(); |
| 5141 | } else { |
| 5142 | return false; |
| 5143 | } |
| 5144 | } finally { |
| 5145 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5146 | } |
| 5147 | } |
| 5148 | |
| 5149 | /** |
| 5150 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5151 | * defined in {@link ImsRegistrationImplBase}. |
| 5152 | */ |
| 5153 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5154 | final long identity = Binder.clearCallingIdentity(); |
| 5155 | try { |
| 5156 | Phone phone = getPhone(subId); |
| 5157 | if (phone != null) { |
| 5158 | return phone.getImsRegistrationTech(); |
| 5159 | } else { |
| 5160 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5161 | } |
| 5162 | } finally { |
| 5163 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5164 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5165 | } |
| 5166 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5167 | @Override |
| 5168 | public void factoryReset(int subId) { |
| 5169 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5170 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5171 | return; |
| 5172 | } |
| 5173 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5174 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5175 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5176 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5177 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5178 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5179 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5180 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5181 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5182 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5183 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5184 | } |
| 5185 | } finally { |
| 5186 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5187 | } |
| 5188 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5189 | |
| 5190 | @Override |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5191 | public String getSimLocaleForSubscriber(int subId) { |
| 5192 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5193 | final Phone phone = getPhone(subId); |
| 5194 | if (phone == null) { |
| 5195 | log("getSimLocaleForSubscriber, invalid subId"); |
Pengquan Meng | 9c29148 | 2019-01-28 16:26:29 -0800 | [diff] [blame] | 5196 | return null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5197 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5198 | final long identity = Binder.clearCallingIdentity(); |
| 5199 | try { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5200 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5201 | phone.getContext().getOpPackageName()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5202 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5203 | // preferences (EF-PL and EF-LI)... |
| 5204 | final int mcc = info.getMcc(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5205 | String simLanguage = null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5206 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5207 | if (localeFromDefaultSim != null) { |
| 5208 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5209 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5210 | + localeFromDefaultSim); |
| 5211 | return localeFromDefaultSim.toLanguageTag(); |
| 5212 | } else { |
| 5213 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5214 | } |
| 5215 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5216 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5217 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5218 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5219 | // the SIM and carrier preferences does not include a country we add the country |
| 5220 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5221 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5222 | if (mccLocale != null) { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5223 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5224 | return mccLocale.toLanguageTag(); |
| 5225 | } |
| 5226 | |
| 5227 | if (DBG) log("No locale found - returning null"); |
| 5228 | return null; |
| 5229 | } finally { |
| 5230 | Binder.restoreCallingIdentity(identity); |
| 5231 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5232 | } |
| 5233 | |
| 5234 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5235 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5236 | } |
| 5237 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5238 | /** |
| 5239 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5240 | */ |
| 5241 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5242 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5243 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5244 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5245 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5246 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5247 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5248 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5249 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5250 | * representing the state of the modem. |
| 5251 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5252 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5253 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5254 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5255 | */ |
| 5256 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5257 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5258 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5259 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5260 | |
| 5261 | final long identity = Binder.clearCallingIdentity(); |
| 5262 | try { |
| 5263 | ModemActivityInfo ret = null; |
| 5264 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5265 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5266 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 5267 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5268 | if (isModemActivityInfoValid(info)) { |
| 5269 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5270 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 5271 | mergedTxTimeMs[i] = |
| 5272 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 5273 | } |
| 5274 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 5275 | mLastModemActivityInfo.setSleepTimeMillis( |
| 5276 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 5277 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5278 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5279 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5280 | mLastModemActivityInfo.setRxTimeMillis( |
| 5281 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5282 | mLastModemActivityInfo.setEnergyUsed( |
| 5283 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5284 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5285 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5286 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5287 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5288 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5289 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5290 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5291 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5292 | Bundle bundle = new Bundle(); |
| 5293 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5294 | result.send(0, bundle); |
| 5295 | } finally { |
| 5296 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5297 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5298 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5299 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5300 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5301 | // less than total activity duration. |
| 5302 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5303 | if (info == null) { |
| 5304 | return false; |
| 5305 | } |
| 5306 | int activityDurationMs = |
| 5307 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5308 | int totalTxTimeMs = 0; |
| 5309 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5310 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5311 | } |
| 5312 | return (info.isValid() |
| 5313 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5314 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5315 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5316 | && (totalTxTimeMs <= activityDurationMs)); |
| 5317 | } |
| 5318 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5319 | /** |
| 5320 | * {@hide} |
| 5321 | * Returns the service state information on specified subscription. |
| 5322 | */ |
| 5323 | @Override |
| 5324 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5325 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5326 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5327 | return null; |
| 5328 | } |
| 5329 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5330 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5331 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5332 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5333 | .setCallingPackage(callingPackage) |
| 5334 | .setCallingPid(Binder.getCallingPid()) |
| 5335 | .setCallingUid(Binder.getCallingUid()) |
| 5336 | .setMethod("getServiceStateForSubscriber") |
| 5337 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5338 | .build()); |
| 5339 | |
| 5340 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5341 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5342 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5343 | .setCallingPackage(callingPackage) |
| 5344 | .setCallingPid(Binder.getCallingPid()) |
| 5345 | .setCallingUid(Binder.getCallingUid()) |
| 5346 | .setMethod("getServiceStateForSubscriber") |
| 5347 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5348 | .build()); |
| 5349 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5350 | boolean hasFinePermission = |
| 5351 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5352 | boolean hasCoarsePermission = |
| 5353 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5354 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5355 | final long identity = Binder.clearCallingIdentity(); |
| 5356 | try { |
| 5357 | final Phone phone = getPhone(subId); |
| 5358 | if (phone == null) { |
| 5359 | return null; |
| 5360 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5361 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5362 | ServiceState ss = phone.getServiceState(); |
| 5363 | |
| 5364 | // Scrub out the location info in ServiceState depending on what level of access |
| 5365 | // the caller has. |
| 5366 | if (hasFinePermission) return ss; |
| 5367 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5368 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5369 | } finally { |
| 5370 | Binder.restoreCallingIdentity(identity); |
| 5371 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5372 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5373 | |
| 5374 | /** |
| 5375 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5376 | * |
| 5377 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5378 | * voicemail ringtone. |
| 5379 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5380 | * PhoneAccount. |
| 5381 | */ |
| 5382 | @Override |
| 5383 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5384 | final long identity = Binder.clearCallingIdentity(); |
| 5385 | try { |
| 5386 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5387 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5388 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5389 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5390 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5391 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5392 | } finally { |
| 5393 | Binder.restoreCallingIdentity(identity); |
| 5394 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5395 | } |
| 5396 | |
| 5397 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5398 | * Sets the per-account voicemail ringtone. |
| 5399 | * |
| 5400 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5401 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5402 | * |
| 5403 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5404 | * voicemail ringtone. |
| 5405 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5406 | * PhoneAccount. |
| 5407 | */ |
| 5408 | @Override |
| 5409 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5410 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5411 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5412 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5413 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5414 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5415 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5416 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5417 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5418 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5419 | |
| 5420 | final long identity = Binder.clearCallingIdentity(); |
| 5421 | try { |
| 5422 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5423 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5424 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5425 | } |
| 5426 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5427 | } finally { |
| 5428 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5429 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5430 | } |
| 5431 | |
| 5432 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5433 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5434 | * |
| 5435 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5436 | * voicemail vibration setting. |
| 5437 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5438 | */ |
| 5439 | @Override |
| 5440 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5441 | final long identity = Binder.clearCallingIdentity(); |
| 5442 | try { |
| 5443 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5444 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5445 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5446 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5447 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5448 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5449 | } finally { |
| 5450 | Binder.restoreCallingIdentity(identity); |
| 5451 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5452 | } |
| 5453 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5454 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5455 | * Sets the per-account voicemail vibration. |
| 5456 | * |
| 5457 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5458 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5459 | * |
| 5460 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5461 | * voicemail vibration setting. |
| 5462 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5463 | * specific PhoneAccount. |
| 5464 | */ |
| 5465 | @Override |
| 5466 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5467 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5468 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5469 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5470 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5471 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5472 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5473 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5474 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5475 | } |
| 5476 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5477 | final long identity = Binder.clearCallingIdentity(); |
| 5478 | try { |
| 5479 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5480 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5481 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5482 | } |
| 5483 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5484 | } finally { |
| 5485 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5486 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5487 | } |
| 5488 | |
| 5489 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5490 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5491 | * |
| 5492 | * @throws SecurityException if the caller does not have the required permission |
| 5493 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5494 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5495 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5496 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5497 | } |
| 5498 | |
| 5499 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5500 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5501 | * permission. |
| 5502 | * |
| 5503 | * @throws SecurityException if the caller does not have the required permission |
| 5504 | */ |
| 5505 | private void enforceSendSmsPermission() { |
| 5506 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5507 | } |
| 5508 | |
| 5509 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5510 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5511 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5512 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5513 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5514 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5515 | final long identity = Binder.clearCallingIdentity(); |
| 5516 | try { |
| 5517 | ComponentName componentName = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5518 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5519 | if (componentName == null) { |
| 5520 | throw new SecurityException( |
| 5521 | "Caller not current active visual voicemail package[null]"); |
| 5522 | } |
| 5523 | String vvmPackage = componentName.getPackageName(); |
| 5524 | if (!callingPackage.equals(vvmPackage)) { |
| 5525 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5526 | + vvmPackage + "]"); |
| 5527 | } |
| 5528 | } finally { |
| 5529 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5530 | } |
| 5531 | } |
| 5532 | |
| 5533 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5534 | * Return the application ID for the app type. |
| 5535 | * |
| 5536 | * @param subId the subscription ID that this request applies to. |
| 5537 | * @param appType the uicc app type. |
| 5538 | * @return Application ID for specificied app type, or null if no uicc. |
| 5539 | */ |
| 5540 | @Override |
| 5541 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5542 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5543 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5544 | |
| 5545 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5546 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5547 | if (phone == null) { |
| 5548 | return null; |
| 5549 | } |
| 5550 | String aid = null; |
| 5551 | try { |
| 5552 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5553 | .getApplicationByType(appType).getAid(); |
| 5554 | } catch (Exception e) { |
| 5555 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5556 | } |
| 5557 | return aid; |
| 5558 | } finally { |
| 5559 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5560 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5561 | } |
| 5562 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5563 | /** |
| 5564 | * Return the Electronic Serial Number. |
| 5565 | * |
| 5566 | * @param subId the subscription ID that this request applies to. |
| 5567 | * @return ESN or null if error. |
| 5568 | */ |
| 5569 | @Override |
| 5570 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5571 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5572 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5573 | |
| 5574 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5575 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5576 | if (phone == null) { |
| 5577 | return null; |
| 5578 | } |
| 5579 | String esn = null; |
| 5580 | try { |
| 5581 | esn = phone.getEsn(); |
| 5582 | } catch (Exception e) { |
| 5583 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5584 | } |
| 5585 | return esn; |
| 5586 | } finally { |
| 5587 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5588 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5589 | } |
| 5590 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5591 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5592 | * Return the Preferred Roaming List Version. |
| 5593 | * |
| 5594 | * @param subId the subscription ID that this request applies to. |
| 5595 | * @return PRLVersion or null if error. |
| 5596 | */ |
| 5597 | @Override |
| 5598 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5599 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5600 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5601 | |
| 5602 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5603 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5604 | if (phone == null) { |
| 5605 | return null; |
| 5606 | } |
| 5607 | String cdmaPrlVersion = null; |
| 5608 | try { |
| 5609 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5610 | } catch (Exception e) { |
| 5611 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5612 | } |
| 5613 | return cdmaPrlVersion; |
| 5614 | } finally { |
| 5615 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5616 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5620 | * Get snapshot of Telephony histograms |
| 5621 | * @return List of Telephony histograms |
| 5622 | * @hide |
| 5623 | */ |
| 5624 | @Override |
| 5625 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5626 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5627 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5628 | |
| 5629 | final long identity = Binder.clearCallingIdentity(); |
| 5630 | try { |
| 5631 | return RIL.getTelephonyRILTimingHistograms(); |
| 5632 | } finally { |
| 5633 | Binder.restoreCallingIdentity(identity); |
| 5634 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5635 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5636 | |
| 5637 | /** |
| 5638 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5639 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5640 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5641 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5642 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5643 | * @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] | 5644 | */ |
| 5645 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5646 | @TelephonyManager.SetCarrierRestrictionResult |
| 5647 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5648 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5649 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5650 | |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5651 | if (carrierRestrictionRules == null) { |
| 5652 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5653 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5654 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5655 | final long identity = Binder.clearCallingIdentity(); |
| 5656 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5657 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5658 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5659 | } finally { |
| 5660 | Binder.restoreCallingIdentity(identity); |
| 5661 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5662 | } |
| 5663 | |
| 5664 | /** |
| 5665 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5666 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5667 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5668 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5669 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5670 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5671 | */ |
| 5672 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5673 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5674 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5675 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5676 | |
| 5677 | final long identity = Binder.clearCallingIdentity(); |
| 5678 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5679 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5680 | if (response instanceof CarrierRestrictionRules) { |
| 5681 | return (CarrierRestrictionRules) response; |
| 5682 | } |
| 5683 | // Response is an Exception of some kind, |
| 5684 | // which is signalled to the user as a NULL retval |
| 5685 | return null; |
| 5686 | } catch (Exception e) { |
| 5687 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5688 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5689 | } finally { |
| 5690 | Binder.restoreCallingIdentity(identity); |
| 5691 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5692 | } |
| 5693 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5694 | /** |
| 5695 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5696 | * @param subId the subscription ID that this action applies to. |
| 5697 | * @param enabled control enable or disable metered apns. |
| 5698 | * {@hide} |
| 5699 | */ |
| 5700 | @Override |
| 5701 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5702 | enforceModifyPermission(); |
| 5703 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5704 | |
| 5705 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5706 | if (phone == null) { |
| 5707 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5708 | return; |
| 5709 | } |
| 5710 | try { |
| 5711 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5712 | } catch (Exception e) { |
| 5713 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5714 | } finally { |
| 5715 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5716 | } |
| 5717 | } |
| 5718 | |
| 5719 | /** |
| 5720 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5721 | * @param subId the subscription ID that this action applies to. |
| 5722 | * @param enabled control enable or disable radio. |
| 5723 | * {@hide} |
| 5724 | */ |
| 5725 | @Override |
| 5726 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5727 | enforceModifyPermission(); |
| 5728 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5729 | |
| 5730 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5731 | if (phone == null) { |
| 5732 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5733 | return; |
| 5734 | } |
| 5735 | try { |
| 5736 | phone.carrierActionSetRadioEnabled(enabled); |
| 5737 | } catch (Exception e) { |
| 5738 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5739 | } finally { |
| 5740 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5741 | } |
| 5742 | } |
| 5743 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5744 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5745 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5746 | * network status based on which carrier apps could apply actions accordingly, |
| 5747 | * enable/disable default url handler for example. |
| 5748 | * |
| 5749 | * @param subId the subscription ID that this action applies to. |
| 5750 | * @param report control start/stop reporting the default network status. |
| 5751 | * {@hide} |
| 5752 | */ |
| 5753 | @Override |
| 5754 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5755 | enforceModifyPermission(); |
| 5756 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5757 | |
| 5758 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5759 | if (phone == null) { |
| 5760 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5761 | return; |
| 5762 | } |
| 5763 | try { |
| 5764 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5765 | } catch (Exception e) { |
| 5766 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5767 | } finally { |
| 5768 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5769 | } |
| 5770 | } |
| 5771 | |
| 5772 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5773 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5774 | * bug report is being generated. |
| 5775 | */ |
| 5776 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5777 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5778 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5779 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5780 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5781 | + Binder.getCallingPid() |
| 5782 | + ", uid=" + Binder.getCallingUid() |
| 5783 | + "without permission " |
| 5784 | + android.Manifest.permission.DUMP); |
| 5785 | return; |
| 5786 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5787 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5788 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5789 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5790 | @Override |
| 5791 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5792 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5793 | throws RemoteException { |
| 5794 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5795 | } |
| 5796 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5797 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5798 | * Get aggregated video call data usage since boot. |
| 5799 | * |
| 5800 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5801 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5802 | * {@hide} |
| 5803 | */ |
| 5804 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5805 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5806 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5807 | null); |
| 5808 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5809 | final long identity = Binder.clearCallingIdentity(); |
| 5810 | try { |
| 5811 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5812 | // records the delta with the corresponding network identity. |
| 5813 | // We just return the total video call data usage snapshot since boot. |
| 5814 | Phone phone = getPhone(subId); |
| 5815 | if (phone != null) { |
| 5816 | return phone.getVtDataUsage(perUidStats); |
| 5817 | } |
| 5818 | return null; |
| 5819 | } finally { |
| 5820 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5821 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5822 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5823 | |
| 5824 | /** |
| 5825 | * Policy control of data connection. Usually used when data limit is passed. |
| 5826 | * @param enabled True if enabling the data, otherwise disabling. |
| 5827 | * @param subId Subscription index |
| 5828 | * {@hide} |
| 5829 | */ |
| 5830 | @Override |
| 5831 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 5832 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5833 | |
| 5834 | final long identity = Binder.clearCallingIdentity(); |
| 5835 | try { |
| 5836 | Phone phone = getPhone(subId); |
| 5837 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5838 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5839 | } |
| 5840 | } finally { |
| 5841 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5842 | } |
| 5843 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5844 | |
| 5845 | /** |
| 5846 | * Get Client request stats |
| 5847 | * @return List of Client Request Stats |
| 5848 | * @hide |
| 5849 | */ |
| 5850 | @Override |
| 5851 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5852 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5853 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5854 | return null; |
| 5855 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5856 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5857 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5858 | final long identity = Binder.clearCallingIdentity(); |
| 5859 | try { |
| 5860 | if (phone != null) { |
| 5861 | return phone.getClientRequestStats(); |
| 5862 | } |
| 5863 | |
| 5864 | return null; |
| 5865 | } finally { |
| 5866 | Binder.restoreCallingIdentity(identity); |
| 5867 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5868 | } |
| 5869 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5870 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5871 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5872 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5873 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5874 | |
| 5875 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5876 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5877 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5878 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5879 | * @param state State of SIM (power down, power up, pass through) |
| 5880 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 5881 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 5882 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5883 | * |
| 5884 | **/ |
| 5885 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5886 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5887 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5888 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5889 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5890 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5891 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5892 | final long identity = Binder.clearCallingIdentity(); |
| 5893 | try { |
| 5894 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5895 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5896 | } |
| 5897 | } finally { |
| 5898 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5899 | } |
| 5900 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5901 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5902 | private boolean isUssdApiAllowed(int subId) { |
| 5903 | CarrierConfigManager configManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5904 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5905 | if (configManager == null) { |
| 5906 | return false; |
| 5907 | } |
| 5908 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 5909 | if (pb == null) { |
| 5910 | return false; |
| 5911 | } |
| 5912 | return pb.getBoolean( |
| 5913 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 5914 | } |
| 5915 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5916 | /** |
| 5917 | * Check if phone is in emergency callback mode |
| 5918 | * @return true if phone is in emergency callback mode |
| 5919 | * @param subId sub id |
| 5920 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 5921 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5922 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5923 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5924 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5925 | |
| 5926 | final long identity = Binder.clearCallingIdentity(); |
| 5927 | try { |
| 5928 | if (phone != null) { |
| 5929 | return phone.isInEcm(); |
| 5930 | } else { |
| 5931 | return false; |
| 5932 | } |
| 5933 | } finally { |
| 5934 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5935 | } |
| 5936 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5937 | |
| 5938 | /** |
| 5939 | * Get the current signal strength information for the given subscription. |
| 5940 | * Because this information is not updated when the device is in a low power state |
| 5941 | * it should not be relied-upon to be current. |
| 5942 | * @param subId Subscription index |
| 5943 | * @return the most recent cached signal strength info from the modem |
| 5944 | */ |
| 5945 | @Override |
| 5946 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5947 | final long identity = Binder.clearCallingIdentity(); |
| 5948 | try { |
| 5949 | Phone p = getPhone(subId); |
| 5950 | if (p == null) { |
| 5951 | return null; |
| 5952 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5953 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5954 | return p.getSignalStrength(); |
| 5955 | } finally { |
| 5956 | Binder.restoreCallingIdentity(identity); |
| 5957 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5958 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5959 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5960 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 5961 | * Get the current modem radio state for the given slot. |
| 5962 | * @param slotIndex slot index. |
| 5963 | * @param callingPackage the name of the package making the call. |
| 5964 | * @return the current radio power state from the modem |
| 5965 | */ |
| 5966 | @Override |
| 5967 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 5968 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5969 | if (phone != null) { |
| 5970 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5971 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 5972 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5973 | } |
| 5974 | |
| 5975 | final long identity = Binder.clearCallingIdentity(); |
| 5976 | try { |
| 5977 | return phone.getRadioPowerState(); |
| 5978 | } finally { |
| 5979 | Binder.restoreCallingIdentity(identity); |
| 5980 | } |
| 5981 | } |
| 5982 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5983 | } |
| 5984 | |
| 5985 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5986 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 5987 | * |
| 5988 | * <p>Requires one of the following permissions: |
| 5989 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 5990 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 5991 | * privileges. |
| 5992 | * |
| 5993 | * @param subId subscription id |
| 5994 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 5995 | * {@code false}. |
| 5996 | */ |
| 5997 | @Override |
| 5998 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5999 | boolean isEnabled = false; |
| 6000 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6001 | try { |
| 6002 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6003 | null /* message */); |
| 6004 | Phone phone = getPhone(subId); |
| 6005 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6006 | } catch (Exception e) { |
| 6007 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6008 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6009 | } finally { |
| 6010 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6011 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6012 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6013 | } |
| 6014 | |
| 6015 | |
| 6016 | /** |
| 6017 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6018 | * |
| 6019 | * <p> Requires permission: |
| 6020 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6021 | * privileges. |
| 6022 | * |
| 6023 | * @param subId subscription id |
| 6024 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6025 | */ |
| 6026 | @Override |
| 6027 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6028 | final long identity = Binder.clearCallingIdentity(); |
| 6029 | try { |
| 6030 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6031 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6032 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6033 | Phone phone = getPhone(subId); |
| 6034 | if (phone != null) { |
| 6035 | phone.setDataRoamingEnabled(isEnabled); |
| 6036 | } |
| 6037 | } finally { |
| 6038 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6039 | } |
| 6040 | } |
| 6041 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6042 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6043 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 6044 | boolean isAllowed = true; |
| 6045 | final long identity = Binder.clearCallingIdentity(); |
| 6046 | try { |
| 6047 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6048 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6049 | Phone phone = getPhone(subId); |
| 6050 | if (phone != null) { |
| 6051 | isAllowed = phone.isCspPlmnEnabled(); |
| 6052 | } |
| 6053 | } finally { |
| 6054 | Binder.restoreCallingIdentity(identity); |
| 6055 | } |
| 6056 | return isAllowed; |
| 6057 | } |
| 6058 | |
| 6059 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6060 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6061 | try { |
| 6062 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
| 6063 | } catch (SecurityException e) { |
| 6064 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6065 | // has carrier privileges on an active UICC |
| 6066 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6067 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6068 | throw new SecurityException("Caller does not have carrier privileges on any UICC"); |
| 6069 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6070 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6071 | |
| 6072 | final long identity = Binder.clearCallingIdentity(); |
| 6073 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6074 | UiccController uiccController = UiccController.getInstance(); |
| 6075 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
| 6076 | |
| 6077 | ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0); |
| 6078 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 6079 | // Remove private info if the caller doesn't have access |
| 6080 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6081 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6082 | UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex()); |
| 6083 | UiccProfile profile = card.getUiccProfile(); |
| 6084 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6085 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6086 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6087 | } else { |
| 6088 | filteredInfos.add(cardInfo); |
| 6089 | } |
| 6090 | } |
| 6091 | return filteredInfos; |
| 6092 | } |
| 6093 | return cardInfos; |
| 6094 | } catch (PackageManager.NameNotFoundException e) { |
| 6095 | // This should not happen since we pass the package info in from TelephonyManager |
| 6096 | throw new SecurityException("Invalid calling package."); |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6097 | } finally { |
| 6098 | Binder.restoreCallingIdentity(identity); |
| 6099 | } |
| 6100 | } |
| 6101 | |
| 6102 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6103 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6104 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6105 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6106 | final long identity = Binder.clearCallingIdentity(); |
| 6107 | try { |
| 6108 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6109 | if (slots == null) { |
| 6110 | Rlog.i(LOG_TAG, "slots is null."); |
| 6111 | return null; |
| 6112 | } |
| 6113 | |
| 6114 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6115 | for (int i = 0; i < slots.length; i++) { |
| 6116 | UiccSlot slot = slots[i]; |
| 6117 | if (slot == null) { |
| 6118 | continue; |
| 6119 | } |
| 6120 | |
| 6121 | String cardId; |
| 6122 | UiccCard card = slot.getUiccCard(); |
| 6123 | if (card != null) { |
| 6124 | cardId = card.getCardId(); |
| 6125 | } else { |
| 6126 | cardId = slot.getIccId(); |
| 6127 | } |
| 6128 | |
| 6129 | int cardState = 0; |
| 6130 | switch (slot.getCardState()) { |
| 6131 | case CARDSTATE_ABSENT: |
| 6132 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6133 | break; |
| 6134 | case CARDSTATE_PRESENT: |
| 6135 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6136 | break; |
| 6137 | case CARDSTATE_ERROR: |
| 6138 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6139 | break; |
| 6140 | case CARDSTATE_RESTRICTED: |
| 6141 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6142 | break; |
| 6143 | default: |
| 6144 | break; |
| 6145 | |
| 6146 | } |
| 6147 | |
| 6148 | infos[i] = new UiccSlotInfo( |
| 6149 | slot.isActive(), |
| 6150 | slot.isEuicc(), |
| 6151 | cardId, |
| 6152 | cardState, |
| 6153 | slot.getPhoneId(), |
Jordan Liu | ef65d87 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6154 | slot.isExtendedApduSupported(), |
| 6155 | slot.isRemovable()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6156 | } |
| 6157 | return infos; |
| 6158 | } finally { |
| 6159 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6160 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6161 | } |
| 6162 | |
| 6163 | @Override |
| 6164 | public boolean switchSlots(int[] physicalSlots) { |
| 6165 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6166 | |
| 6167 | final long identity = Binder.clearCallingIdentity(); |
| 6168 | try { |
| 6169 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6170 | } finally { |
| 6171 | Binder.restoreCallingIdentity(identity); |
| 6172 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6173 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6174 | |
| 6175 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6176 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6177 | final long identity = Binder.clearCallingIdentity(); |
| 6178 | try { |
| 6179 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6180 | } finally { |
| 6181 | Binder.restoreCallingIdentity(identity); |
| 6182 | } |
| 6183 | } |
| 6184 | |
| 6185 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6186 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6187 | enforceModifyPermission(); |
| 6188 | final Phone phone = getPhone(subId); |
| 6189 | if (phone == null) { |
| 6190 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6191 | return; |
| 6192 | } |
| 6193 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6194 | final long identity = Binder.clearCallingIdentity(); |
| 6195 | try { |
| 6196 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6197 | } finally { |
| 6198 | Binder.restoreCallingIdentity(identity); |
| 6199 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6200 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6201 | |
| 6202 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6203 | * A test API to reload the UICC profile. |
| 6204 | * |
| 6205 | * <p>Requires that the calling app has permission |
| 6206 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6207 | * @hide |
| 6208 | */ |
| 6209 | @Override |
| 6210 | public void refreshUiccProfile(int subId) { |
| 6211 | enforceModifyPermission(); |
| 6212 | |
| 6213 | final long identity = Binder.clearCallingIdentity(); |
| 6214 | try { |
| 6215 | Phone phone = getPhone(subId); |
| 6216 | if (phone == null) { |
| 6217 | return; |
| 6218 | } |
| 6219 | UiccCard uiccCard = phone.getUiccCard(); |
| 6220 | if (uiccCard == null) { |
| 6221 | return; |
| 6222 | } |
| 6223 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6224 | if (uiccProfile == null) { |
| 6225 | return; |
| 6226 | } |
| 6227 | uiccProfile.refresh(); |
| 6228 | } finally { |
| 6229 | Binder.restoreCallingIdentity(identity); |
| 6230 | } |
| 6231 | } |
| 6232 | |
| 6233 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6234 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6235 | */ |
| 6236 | private boolean getDefaultDataEnabled() { |
| 6237 | return "true".equalsIgnoreCase( |
| 6238 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6239 | } |
| 6240 | |
| 6241 | /** |
| 6242 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6243 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6244 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6245 | */ |
| 6246 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6247 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6248 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6249 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6250 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6251 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6252 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6253 | return isDataRoamingEnabled; |
| 6254 | } |
| 6255 | |
| 6256 | /** |
| 6257 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6258 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6259 | */ |
| 6260 | private int getDefaultNetworkType(int subId) { |
| 6261 | return Integer.parseInt( |
| 6262 | TelephonyManager.getTelephonyProperty( |
| 6263 | mSubscriptionController.getPhoneId(subId), |
| 6264 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6265 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6266 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6267 | |
| 6268 | @Override |
| 6269 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 6270 | gid1, String gid2, String plmn, String spn) { |
| 6271 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6272 | |
| 6273 | final long identity = Binder.clearCallingIdentity(); |
| 6274 | try { |
| 6275 | final Phone phone = getPhone(subId); |
| 6276 | if (phone == null) { |
| 6277 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6278 | return; |
| 6279 | } |
| 6280 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 6281 | } finally { |
| 6282 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6283 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6284 | } |
| 6285 | |
| 6286 | @Override |
| 6287 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6288 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6289 | |
| 6290 | final long identity = Binder.clearCallingIdentity(); |
| 6291 | try { |
| 6292 | final Phone phone = getPhone(subId); |
| 6293 | if (phone == null) { |
| 6294 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6295 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6296 | } |
| 6297 | return phone.getCarrierIdListVersion(); |
| 6298 | } finally { |
| 6299 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6300 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6301 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6302 | |
| 6303 | @Override |
| 6304 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6305 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6306 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6307 | return -1; |
| 6308 | } |
| 6309 | |
| 6310 | final long identity = Binder.clearCallingIdentity(); |
| 6311 | try { |
| 6312 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6313 | } finally { |
| 6314 | Binder.restoreCallingIdentity(identity); |
| 6315 | } |
| 6316 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6317 | |
| 6318 | @Override |
| 6319 | public int getCdmaRoamingMode(int subId) { |
| 6320 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6321 | mApp, subId, "getCdmaRoamingMode"); |
| 6322 | |
| 6323 | final long identity = Binder.clearCallingIdentity(); |
| 6324 | try { |
| 6325 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6326 | } finally { |
| 6327 | Binder.restoreCallingIdentity(identity); |
| 6328 | } |
| 6329 | } |
| 6330 | |
| 6331 | @Override |
| 6332 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6333 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6334 | mApp, subId, "setCdmaRoamingMode"); |
| 6335 | |
| 6336 | final long identity = Binder.clearCallingIdentity(); |
| 6337 | try { |
| 6338 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6339 | } finally { |
| 6340 | Binder.restoreCallingIdentity(identity); |
| 6341 | } |
| 6342 | } |
| 6343 | |
| 6344 | @Override |
| 6345 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6346 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6347 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6348 | |
| 6349 | final long identity = Binder.clearCallingIdentity(); |
| 6350 | try { |
| 6351 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6352 | } finally { |
| 6353 | Binder.restoreCallingIdentity(identity); |
| 6354 | } |
| 6355 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6356 | |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 6357 | private void ensureUserRunning(int userId) { |
| 6358 | if (!mUserManager.isUserRunning(userId)) { |
| 6359 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6360 | } |
| 6361 | } |
| 6362 | |
| 6363 | /** |
| 6364 | * Returns a list of SMS apps on a given user. |
| 6365 | * |
| 6366 | * Only the shell user (UID 2000 or 0) can call it. |
| 6367 | * Target user must be running. |
| 6368 | */ |
| 6369 | @Override |
| 6370 | public String[] getSmsApps(int userId) { |
| 6371 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6372 | ensureUserRunning(userId); |
| 6373 | |
| 6374 | final Collection<SmsApplicationData> apps = |
| 6375 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6376 | |
| 6377 | String[] ret = new String[apps.size()]; |
| 6378 | int i = 0; |
| 6379 | for (SmsApplicationData app : apps) { |
| 6380 | ret[i++] = app.mPackageName; |
| 6381 | } |
| 6382 | return ret; |
| 6383 | } |
| 6384 | |
| 6385 | /** |
| 6386 | * Returns the default SMS app package name on a given user. |
| 6387 | * |
| 6388 | * Only the shell user (UID 2000 or 0) can call it. |
| 6389 | * Target user must be running. |
| 6390 | */ |
| 6391 | @Override |
| 6392 | public String getDefaultSmsApp(int userId) { |
| 6393 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6394 | ensureUserRunning(userId); |
| 6395 | |
| 6396 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6397 | /* updateIfNeeded= */ true, userId); |
| 6398 | return cn == null ? null : cn.getPackageName(); |
| 6399 | } |
| 6400 | |
| 6401 | /** |
| 6402 | * Set a package as the default SMS app on a given user. |
| 6403 | * |
| 6404 | * Only the shell user (UID 2000 or 0) can call it. |
| 6405 | * Target user must be running. |
| 6406 | */ |
| 6407 | @Override |
| 6408 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6409 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6410 | ensureUserRunning(userId); |
| 6411 | |
| 6412 | boolean found = false; |
| 6413 | for (String pkg : getSmsApps(userId)) { |
| 6414 | if (TextUtils.equals(packageName, pkg)) { |
| 6415 | found = true; |
| 6416 | break; |
| 6417 | } |
| 6418 | } |
| 6419 | if (!found) { |
| 6420 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6421 | } |
| 6422 | |
| 6423 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6424 | } |
| 6425 | |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6426 | @Override |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6427 | public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList( |
| 6428 | String callingPackage) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6429 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6430 | mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) { |
| 6431 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6432 | } |
| 6433 | final long identity = Binder.clearCallingIdentity(); |
| 6434 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6435 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6436 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6437 | if (phone.getEmergencyNumberTracker() != null |
| 6438 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6439 | emergencyNumberListInternal.put( |
| 6440 | phone.getSubId(), |
| 6441 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6442 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6443 | } |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6444 | return emergencyNumberListInternal; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6445 | } finally { |
| 6446 | Binder.restoreCallingIdentity(identity); |
| 6447 | } |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6448 | } |
| 6449 | |
| 6450 | @Override |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6451 | public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) { |
| 6452 | final Phone defaultPhone = getDefaultPhone(); |
| 6453 | if (!exactMatch) { |
| 6454 | TelephonyPermissions |
| 6455 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6456 | mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)"); |
| 6457 | } |
| 6458 | final long identity = Binder.clearCallingIdentity(); |
| 6459 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6460 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6461 | if (phone.getEmergencyNumberTracker() != null |
| 6462 | && phone.getEmergencyNumberTracker() != null) { |
| 6463 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6464 | number, exactMatch)) { |
| 6465 | return true; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6466 | } |
| 6467 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6468 | } |
| 6469 | return false; |
| 6470 | } finally { |
| 6471 | Binder.restoreCallingIdentity(identity); |
| 6472 | } |
| 6473 | } |
| 6474 | |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6475 | /** |
| 6476 | * Update emergency number list for test mode. |
| 6477 | */ |
| 6478 | @Override |
| 6479 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6480 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6481 | "updateEmergencyNumberListTestMode"); |
| 6482 | |
| 6483 | final long identity = Binder.clearCallingIdentity(); |
| 6484 | try { |
| 6485 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6486 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6487 | if (tracker != null) { |
| 6488 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6489 | } |
| 6490 | } |
| 6491 | } finally { |
| 6492 | Binder.restoreCallingIdentity(identity); |
| 6493 | } |
| 6494 | } |
| 6495 | |
| 6496 | /** |
| 6497 | * Get the full emergency number list for test mode. |
| 6498 | */ |
| 6499 | @Override |
| 6500 | public List<String> getEmergencyNumberListTestMode() { |
| 6501 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6502 | "getEmergencyNumberListTestMode"); |
| 6503 | |
| 6504 | final long identity = Binder.clearCallingIdentity(); |
| 6505 | try { |
| 6506 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6507 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6508 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6509 | if (tracker != null) { |
| 6510 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6511 | emergencyNumbers.add(num.getNumber()); |
| 6512 | } |
| 6513 | } |
| 6514 | } |
| 6515 | return new ArrayList<>(emergencyNumbers); |
| 6516 | } finally { |
| 6517 | Binder.restoreCallingIdentity(identity); |
| 6518 | } |
| 6519 | } |
| 6520 | |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6521 | @Override |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6522 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6523 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6524 | Phone phone = getPhone(subId); |
| 6525 | if (phone == null) { |
| 6526 | return null; |
| 6527 | } |
| 6528 | final long identity = Binder.clearCallingIdentity(); |
| 6529 | try { |
| 6530 | UiccProfile profile = UiccController.getInstance() |
| 6531 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6532 | if (profile != null) { |
| 6533 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6534 | } |
| 6535 | } finally { |
| 6536 | Binder.restoreCallingIdentity(identity); |
| 6537 | } |
| 6538 | return null; |
| 6539 | } |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6540 | |
| 6541 | /** |
| 6542 | * Enable or disable a modem stack. |
| 6543 | */ |
| 6544 | @Override |
| 6545 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6546 | enforceModifyPermission(); |
| 6547 | |
| 6548 | final long identity = Binder.clearCallingIdentity(); |
| 6549 | try { |
| 6550 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6551 | if (phone == null) { |
| 6552 | return false; |
| 6553 | } else { |
| 6554 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6555 | } |
| 6556 | } finally { |
| 6557 | Binder.restoreCallingIdentity(identity); |
| 6558 | } |
| 6559 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6560 | |
| 6561 | @Override |
| 6562 | public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) { |
| 6563 | enforceModifyPermission(); |
| 6564 | |
| 6565 | final long identity = Binder.clearCallingIdentity(); |
| 6566 | try { |
| 6567 | mTelephonySharedPreferences.edit() |
| 6568 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted) |
| 6569 | .commit(); |
| 6570 | } finally { |
| 6571 | Binder.restoreCallingIdentity(identity); |
| 6572 | } |
| 6573 | } |
| 6574 | |
| 6575 | @Override |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6576 | public boolean isMultisimSupported(String callingPackage) { |
| 6577 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
| 6578 | getDefaultPhone().getSubId(), callingPackage, "isMultisimSupported")) { |
| 6579 | return false; |
| 6580 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6581 | |
| 6582 | final long identity = Binder.clearCallingIdentity(); |
| 6583 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6584 | return isMultisimSupportedInternal(); |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6585 | } finally { |
| 6586 | Binder.restoreCallingIdentity(identity); |
| 6587 | } |
| 6588 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6589 | |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6590 | private boolean isMultisimSupportedInternal() { |
| 6591 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6592 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6593 | if (numPhysicalSlots < 2) { |
| 6594 | loge("isMultisimSupportedInternal: requires at least 2 cards"); |
| 6595 | return false; |
| 6596 | } |
| 6597 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 6598 | // supported by the modem, indicate that it is restricted. |
| 6599 | PhoneCapability staticCapability = |
| 6600 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 6601 | if (staticCapability == null) { |
| 6602 | loge("isMultisimSupportedInternal: no static configuration available"); |
| 6603 | return false; |
| 6604 | } |
| 6605 | if (staticCapability.logicalModemList.size() < 2) { |
| 6606 | loge("isMultisimSupportedInternal: maximum number of modem is < 2"); |
| 6607 | return false; |
| 6608 | } |
| 6609 | // Check if support of multiple SIMs is restricted by carrier |
| 6610 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
| 6611 | return false; |
| 6612 | } |
| 6613 | |
| 6614 | return true; |
| 6615 | } |
| 6616 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6617 | /** |
| 6618 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame^] | 6619 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 6620 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 6621 | * or carrier privileges |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6622 | * @param numOfSims number of active sims we want to switch to |
| 6623 | */ |
| 6624 | @Override |
| 6625 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame^] | 6626 | if (numOfSims == 1) { |
| 6627 | enforceModifyPermission(); |
| 6628 | } else { |
| 6629 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6630 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6631 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6632 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6633 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6634 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6635 | //only proceed if multi-sim is not restricted |
| 6636 | if (!isMultisimSupportedInternal()) { |
| 6637 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 6638 | return; |
| 6639 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6640 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 6641 | } finally { |
| 6642 | Binder.restoreCallingIdentity(identity); |
| 6643 | } |
| 6644 | } |
| 6645 | |
| 6646 | /** |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6647 | * Get whether reboot is required or not after making changes to modem configurations. |
Nazanin Bakhshi | 4a68f5f | 2019-02-08 14:31:19 -0800 | [diff] [blame] | 6648 | * Return value defaults to true |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6649 | */ |
| 6650 | @Override |
| 6651 | public boolean isRebootRequiredForModemConfigChange() { |
| 6652 | enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange"); |
| 6653 | final long identity = Binder.clearCallingIdentity(); |
| 6654 | try { |
| 6655 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 6656 | } finally { |
| 6657 | Binder.restoreCallingIdentity(identity); |
| 6658 | } |
| 6659 | } |
| 6660 | |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 6661 | private void updateModemStateMetrics() { |
| 6662 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 6663 | // TODO: check the state for each modem if the api is ready. |
| 6664 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 6665 | } |
| 6666 | |
Pengquan Meng | 3aceaec | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 6667 | @Override |
| 6668 | public int[] getSlotsMapping() { |
| 6669 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 6670 | |
| 6671 | final long identity = Binder.clearCallingIdentity(); |
| 6672 | try { |
| 6673 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 6674 | // All logical slots should have a mapping to a physical slot. |
| 6675 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 6676 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 6677 | for (int i = 0; i < slotInfos.length; i++) { |
| 6678 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 6679 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 6680 | } |
| 6681 | } |
| 6682 | return logicalSlotsMapping; |
| 6683 | } finally { |
| 6684 | Binder.restoreCallingIdentity(identity); |
| 6685 | } |
| 6686 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 6687 | |
| 6688 | /** |
| 6689 | * Get the IRadio HAL Version |
| 6690 | */ |
| 6691 | @Override |
| 6692 | public int getRadioHalVersion() { |
| 6693 | Phone phone = getDefaultPhone(); |
| 6694 | if (phone == null) return -1; |
| 6695 | HalVersion hv = phone.getHalVersion(); |
| 6696 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 6697 | return hv.major * 100 + hv.minor; |
| 6698 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6699 | } |