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; |
| 38 | import android.os.Bundle; |
| 39 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 40 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Looper; |
| 42 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 44 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 45 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 46 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 47 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 48 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 49 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 51 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 52 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 53 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 54 | import android.provider.Settings; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 55 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 56 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 57 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 58 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 59 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 61 | import android.telephony.CellInfoGsm; |
| 62 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 63 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 64 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 65 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 66 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 67 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 68 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 69 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 70 | import android.telephony.NetworkScanRequest; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 71 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 72 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 73 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 75 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 76 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 77 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 78 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 79 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 80 | import android.telephony.TelephonyManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 81 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 82 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 83 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 84 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 85 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 86 | import android.telephony.data.ApnSetting; |
| 87 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 88 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 89 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 90 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 91 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 92 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 93 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 94 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 95 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 96 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 97 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 98 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 99 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 100 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 101 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 102 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 103 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 104 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 105 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 106 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 107 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 108 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 109 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 110 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 111 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 112 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 113 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 114 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 115 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 117 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 122 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.ServiceStateTracker; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.SmsApplication; |
| 130 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.TelephonyPermissions; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.euicc.EuiccConnector; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.uicc.IccIoResult; |
| 136 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 142 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 144 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 145 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 146 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 147 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 148 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 149 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 150 | import java.io.FileDescriptor; |
| 151 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 152 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 153 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 154 | import java.util.Arrays; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 155 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 156 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 157 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 158 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 159 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 160 | import java.util.Map; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 161 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 162 | |
| 163 | /** |
| 164 | * Implementation of the ITelephony interface. |
| 165 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 166 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 167 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 168 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 169 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 170 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 171 | |
| 172 | // Message codes used with mMainThreadHandler |
| 173 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 174 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 175 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 176 | private static final int CMD_OPEN_CHANNEL = 9; |
| 177 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 178 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 179 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 180 | private static final int CMD_NV_READ_ITEM = 13; |
| 181 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 182 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 183 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 184 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 185 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 186 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 187 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 188 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 189 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 190 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 191 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 192 | private static final int CMD_SEND_ENVELOPE = 25; |
| 193 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 194 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 195 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 196 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 197 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 198 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 199 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 200 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 201 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 202 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 203 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 204 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 205 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 206 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 207 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 208 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 209 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 210 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 211 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 212 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 213 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 214 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 215 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 216 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 217 | private static final int CMD_SWITCH_SLOTS = 50; |
| 218 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 219 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 220 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 221 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 222 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 223 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 224 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 225 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 226 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 227 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 228 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 229 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 230 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 231 | private static final int CMD_MODEM_REBOOT = 64; |
| 232 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 233 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 234 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 235 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 236 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 237 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 238 | // Parameters of select command. |
| 239 | private static final int SELECT_COMMAND = 0xA4; |
| 240 | private static final int SELECT_P1 = 0x04; |
| 241 | private static final int SELECT_P2 = 0; |
| 242 | private static final int SELECT_P3 = 0x10; |
| 243 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 244 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 245 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 246 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 247 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 248 | /** The singleton instance. */ |
| 249 | private static PhoneInterfaceManager sInstance; |
| 250 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 251 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 252 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 253 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 254 | private AppOpsManager mAppOps; |
| 255 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 256 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 257 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 258 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 259 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 260 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 261 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 262 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 263 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 264 | // The AID of ISD-R. |
| 265 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 266 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 267 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 268 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 269 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 270 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 271 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 272 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 273 | * A request object to use for transmitting data to an ICC. |
| 274 | */ |
| 275 | private static final class IccAPDUArgument { |
| 276 | public int channel, cla, command, p1, p2, p3; |
| 277 | public String data; |
| 278 | |
| 279 | public IccAPDUArgument(int channel, int cla, int command, |
| 280 | int p1, int p2, int p3, String data) { |
| 281 | this.channel = channel; |
| 282 | this.cla = cla; |
| 283 | this.command = command; |
| 284 | this.p1 = p1; |
| 285 | this.p2 = p2; |
| 286 | this.p3 = p3; |
| 287 | this.data = data; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 292 | * A request object to use for transmitting data to an ICC. |
| 293 | */ |
| 294 | private static final class ManualNetworkSelectionArgument { |
| 295 | public OperatorInfo operatorInfo; |
| 296 | public boolean persistSelection; |
| 297 | |
| 298 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 299 | this.operatorInfo = operatorInfo; |
| 300 | this.persistSelection = persistSelection; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 305 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 306 | * request after sending. The main thread will notify the request when it is complete. |
| 307 | */ |
| 308 | private static final class MainThreadRequest { |
| 309 | /** The argument to use for the request */ |
| 310 | public Object argument; |
| 311 | /** The result of the request that is run on the main thread */ |
| 312 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 313 | // The subscriber id that this request applies to. Defaults to |
| 314 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 315 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 316 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 317 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 318 | public Phone phone; |
| 319 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 320 | public WorkSource workSource; |
| 321 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 322 | public MainThreadRequest(Object argument) { |
| 323 | this.argument = argument; |
| 324 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 325 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 326 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 327 | this.argument = argument; |
| 328 | if (phone != null) { |
| 329 | this.phone = phone; |
| 330 | } |
| 331 | this.workSource = workSource; |
| 332 | } |
| 333 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 334 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 335 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 336 | if (subId != null) { |
| 337 | this.subId = subId; |
| 338 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 339 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 340 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 343 | private static final class IncomingThirdPartyCallArgs { |
| 344 | public final ComponentName component; |
| 345 | public final String callId; |
| 346 | public final String callerDisplayName; |
| 347 | |
| 348 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 349 | String callerDisplayName) { |
| 350 | this.component = component; |
| 351 | this.callId = callId; |
| 352 | this.callerDisplayName = callerDisplayName; |
| 353 | } |
| 354 | } |
| 355 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 356 | /** |
| 357 | * A handler that processes messages on the main thread in the phone process. Since many |
| 358 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 359 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 360 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 361 | * on, which will be notified when the operation completes and will contain the result of the |
| 362 | * request. |
| 363 | * |
| 364 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 365 | * note that request.result must be set to something non-null for the calling thread to |
| 366 | * unblock. |
| 367 | */ |
| 368 | private final class MainThreadHandler extends Handler { |
| 369 | @Override |
| 370 | public void handleMessage(Message msg) { |
| 371 | MainThreadRequest request; |
| 372 | Message onCompleted; |
| 373 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 374 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 375 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 376 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 377 | |
| 378 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 379 | case CMD_HANDLE_USSD_REQUEST: { |
| 380 | request = (MainThreadRequest) msg.obj; |
| 381 | final Phone phone = getPhoneFromRequest(request); |
| 382 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 383 | String ussdRequest = ussdObject.first; |
| 384 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 385 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 386 | if (!isUssdApiAllowed(request.subId)) { |
| 387 | // Carrier does not support use of this API, return failure. |
| 388 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 389 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 390 | Bundle returnData = new Bundle(); |
| 391 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 392 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 393 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 394 | request.result = true; |
| 395 | notifyRequester(request); |
| 396 | return; |
| 397 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 398 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 399 | try { |
| 400 | request.result = phone != null |
| 401 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 402 | } catch (CallStateException cse) { |
| 403 | request.result = false; |
| 404 | } |
| 405 | // Wake up the requesting thread |
| 406 | notifyRequester(request); |
| 407 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 410 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 411 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 412 | final Phone phone = getPhoneFromRequest(request); |
| 413 | request.result = phone != null ? |
| 414 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 415 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 416 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 417 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 418 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 419 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 420 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 421 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 422 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 423 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 424 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 425 | if (uiccCard == null) { |
| 426 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 427 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 428 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 429 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 430 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 431 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 432 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 433 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 434 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 435 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 436 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 437 | break; |
| 438 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 439 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 440 | ar = (AsyncResult) msg.obj; |
| 441 | request = (MainThreadRequest) ar.userObj; |
| 442 | if (ar.exception == null && ar.result != null) { |
| 443 | request.result = ar.result; |
| 444 | } else { |
| 445 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 446 | if (ar.result == null) { |
| 447 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 448 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 449 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 450 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 451 | } else { |
| 452 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 453 | } |
| 454 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 455 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 456 | break; |
| 457 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 458 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 459 | request = (MainThreadRequest) msg.obj; |
| 460 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 461 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 462 | if (uiccCard == null) { |
| 463 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 464 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 465 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 466 | } else { |
| 467 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 468 | request); |
| 469 | uiccCard.iccTransmitApduBasicChannel( |
| 470 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 471 | iccArgument.p3, iccArgument.data, onCompleted); |
| 472 | } |
| 473 | break; |
| 474 | |
| 475 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 476 | ar = (AsyncResult) msg.obj; |
| 477 | request = (MainThreadRequest) ar.userObj; |
| 478 | if (ar.exception == null && ar.result != null) { |
| 479 | request.result = ar.result; |
| 480 | } else { |
| 481 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 482 | if (ar.result == null) { |
| 483 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 484 | } else if (ar.exception instanceof CommandException) { |
| 485 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 486 | ar.exception); |
| 487 | } else { |
| 488 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 489 | } |
| 490 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 491 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 492 | break; |
| 493 | |
| 494 | case CMD_EXCHANGE_SIM_IO: |
| 495 | request = (MainThreadRequest) msg.obj; |
| 496 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 497 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 498 | if (uiccCard == null) { |
| 499 | loge("iccExchangeSimIO: No UICC"); |
| 500 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 501 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 502 | } else { |
| 503 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 504 | request); |
| 505 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 506 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 507 | iccArgument.data, onCompleted); |
| 508 | } |
| 509 | break; |
| 510 | |
| 511 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 512 | ar = (AsyncResult) msg.obj; |
| 513 | request = (MainThreadRequest) ar.userObj; |
| 514 | if (ar.exception == null && ar.result != null) { |
| 515 | request.result = ar.result; |
| 516 | } else { |
| 517 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 518 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 519 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 520 | break; |
| 521 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 522 | case CMD_SEND_ENVELOPE: |
| 523 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 524 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 525 | if (uiccCard == null) { |
| 526 | loge("sendEnvelopeWithStatus: No UICC"); |
| 527 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 528 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 529 | } else { |
| 530 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 531 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 532 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 533 | break; |
| 534 | |
| 535 | case EVENT_SEND_ENVELOPE_DONE: |
| 536 | ar = (AsyncResult) msg.obj; |
| 537 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 538 | if (ar.exception == null && ar.result != null) { |
| 539 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 540 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 541 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 542 | if (ar.result == null) { |
| 543 | loge("sendEnvelopeWithStatus: Empty response"); |
| 544 | } else if (ar.exception instanceof CommandException) { |
| 545 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 546 | ar.exception); |
| 547 | } else { |
| 548 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 549 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 550 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 551 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 552 | break; |
| 553 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 554 | case CMD_OPEN_CHANNEL: |
| 555 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 556 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 557 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 558 | if (uiccCard == null) { |
| 559 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 560 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 561 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 562 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 563 | } else { |
| 564 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 565 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 566 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 567 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 568 | break; |
| 569 | |
| 570 | case EVENT_OPEN_CHANNEL_DONE: |
| 571 | ar = (AsyncResult) msg.obj; |
| 572 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 573 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 574 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 575 | int[] result = (int[]) ar.result; |
| 576 | int channelId = result[0]; |
| 577 | byte[] selectResponse = null; |
| 578 | if (result.length > 1) { |
| 579 | selectResponse = new byte[result.length - 1]; |
| 580 | for (int i = 1; i < result.length; ++i) { |
| 581 | selectResponse[i - 1] = (byte) result[i]; |
| 582 | } |
| 583 | } |
| 584 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 585 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 586 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 587 | if (ar.result == null) { |
| 588 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 589 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 590 | if (ar.exception != null) { |
| 591 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 592 | } |
| 593 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 594 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 595 | if (ar.exception instanceof CommandException) { |
| 596 | CommandException.Error error = |
| 597 | ((CommandException) (ar.exception)).getCommandError(); |
| 598 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 599 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 600 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 601 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 605 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 606 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 607 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 608 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 609 | break; |
| 610 | |
| 611 | case CMD_CLOSE_CHANNEL: |
| 612 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 613 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 614 | if (uiccCard == null) { |
| 615 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 616 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 617 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 618 | } else { |
| 619 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 620 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 621 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 622 | break; |
| 623 | |
| 624 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 625 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 626 | break; |
| 627 | |
| 628 | case CMD_NV_READ_ITEM: |
| 629 | request = (MainThreadRequest) msg.obj; |
| 630 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 631 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 632 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 633 | break; |
| 634 | |
| 635 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | ar = (AsyncResult) msg.obj; |
| 637 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 638 | if (ar.exception == null && ar.result != null) { |
| 639 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 640 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 641 | request.result = ""; |
| 642 | if (ar.result == null) { |
| 643 | loge("nvReadItem: Empty response"); |
| 644 | } else if (ar.exception instanceof CommandException) { |
| 645 | loge("nvReadItem: CommandException: " + |
| 646 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 648 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | } |
| 650 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 651 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 652 | break; |
| 653 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 654 | case CMD_NV_WRITE_ITEM: |
| 655 | request = (MainThreadRequest) msg.obj; |
| 656 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 657 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 658 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 659 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 660 | break; |
| 661 | |
| 662 | case EVENT_NV_WRITE_ITEM_DONE: |
| 663 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 664 | break; |
| 665 | |
| 666 | case CMD_NV_WRITE_CDMA_PRL: |
| 667 | request = (MainThreadRequest) msg.obj; |
| 668 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 669 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 670 | break; |
| 671 | |
| 672 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 673 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 674 | break; |
| 675 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 676 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 677 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 678 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 679 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 680 | break; |
| 681 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 682 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 683 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 684 | break; |
| 685 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 686 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 687 | request = (MainThreadRequest) msg.obj; |
| 688 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 689 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 690 | break; |
| 691 | |
| 692 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 693 | ar = (AsyncResult) msg.obj; |
| 694 | request = (MainThreadRequest) ar.userObj; |
| 695 | if (ar.exception == null && ar.result != null) { |
| 696 | request.result = ar.result; // Integer |
| 697 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 698 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 699 | if (ar.result == null) { |
| 700 | loge("getPreferredNetworkType: Empty response"); |
| 701 | } else if (ar.exception instanceof CommandException) { |
| 702 | loge("getPreferredNetworkType: CommandException: " + |
| 703 | ar.exception); |
| 704 | } else { |
| 705 | loge("getPreferredNetworkType: Unknown exception"); |
| 706 | } |
| 707 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 708 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 709 | break; |
| 710 | |
| 711 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 712 | request = (MainThreadRequest) msg.obj; |
| 713 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 714 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 715 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 716 | break; |
| 717 | |
| 718 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 719 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 720 | break; |
| 721 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 722 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 723 | request = (MainThreadRequest)msg.obj; |
| 724 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 725 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 726 | break; |
| 727 | |
| 728 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 729 | ar = (AsyncResult)msg.obj; |
| 730 | request = (MainThreadRequest)ar.userObj; |
| 731 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 732 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 733 | break; |
| 734 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 735 | case CMD_SET_VOICEMAIL_NUMBER: |
| 736 | request = (MainThreadRequest) msg.obj; |
| 737 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 738 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 739 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 740 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 741 | break; |
| 742 | |
| 743 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 744 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 745 | break; |
| 746 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 747 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 748 | request = (MainThreadRequest) msg.obj; |
| 749 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 750 | request); |
| 751 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 752 | break; |
| 753 | |
| 754 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 755 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 756 | break; |
| 757 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 758 | case CMD_PERFORM_NETWORK_SCAN: |
| 759 | request = (MainThreadRequest) msg.obj; |
| 760 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 761 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 762 | break; |
| 763 | |
| 764 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 765 | ar = (AsyncResult) msg.obj; |
| 766 | request = (MainThreadRequest) ar.userObj; |
| 767 | CellNetworkScanResult cellScanResult; |
| 768 | if (ar.exception == null && ar.result != null) { |
| 769 | cellScanResult = new CellNetworkScanResult( |
| 770 | CellNetworkScanResult.STATUS_SUCCESS, |
| 771 | (List<OperatorInfo>) ar.result); |
| 772 | } else { |
| 773 | if (ar.result == null) { |
| 774 | loge("getCellNetworkScanResults: Empty response"); |
| 775 | } |
| 776 | if (ar.exception != null) { |
| 777 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 778 | } |
| 779 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 780 | if (ar.exception instanceof CommandException) { |
| 781 | CommandException.Error error = |
| 782 | ((CommandException) (ar.exception)).getCommandError(); |
| 783 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 784 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 785 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 786 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 787 | } |
| 788 | } |
| 789 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 790 | } |
| 791 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 792 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 793 | break; |
| 794 | |
| 795 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 796 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 797 | ManualNetworkSelectionArgument selArg = |
| 798 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 799 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 800 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 801 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 802 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 803 | break; |
| 804 | |
| 805 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 806 | ar = (AsyncResult) msg.obj; |
| 807 | request = (MainThreadRequest) ar.userObj; |
| 808 | if (ar.exception == null) { |
| 809 | request.result = true; |
| 810 | } else { |
| 811 | request.result = false; |
| 812 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 813 | } |
| 814 | notifyRequester(request); |
| 815 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 816 | break; |
| 817 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 818 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 819 | request = (MainThreadRequest) msg.obj; |
| 820 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 821 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 822 | break; |
| 823 | |
| 824 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 825 | ar = (AsyncResult) msg.obj; |
| 826 | request = (MainThreadRequest) ar.userObj; |
| 827 | if (ar.exception == null && ar.result != null) { |
| 828 | request.result = ar.result; |
| 829 | } else { |
| 830 | if (ar.result == null) { |
| 831 | loge("queryModemActivityInfo: Empty response"); |
| 832 | } else if (ar.exception instanceof CommandException) { |
| 833 | loge("queryModemActivityInfo: CommandException: " + |
| 834 | ar.exception); |
| 835 | } else { |
| 836 | loge("queryModemActivityInfo: Unknown exception"); |
| 837 | } |
| 838 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 839 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 840 | if (request.result == null) { |
| 841 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 842 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 843 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 844 | break; |
| 845 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 846 | case CMD_SET_ALLOWED_CARRIERS: |
| 847 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 848 | CarrierRestrictionRules argument = |
| 849 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 850 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 851 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 852 | break; |
| 853 | |
| 854 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 855 | ar = (AsyncResult) msg.obj; |
| 856 | request = (MainThreadRequest) ar.userObj; |
| 857 | if (ar.exception == null && ar.result != null) { |
| 858 | request.result = ar.result; |
| 859 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 860 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 861 | if (ar.exception instanceof CommandException) { |
| 862 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 863 | CommandException.Error error = |
| 864 | ((CommandException) (ar.exception)).getCommandError(); |
| 865 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 866 | request.result = |
| 867 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 868 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 869 | } else { |
| 870 | loge("setAllowedCarriers: Unknown exception"); |
| 871 | } |
| 872 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 873 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 874 | break; |
| 875 | |
| 876 | case CMD_GET_ALLOWED_CARRIERS: |
| 877 | request = (MainThreadRequest) msg.obj; |
| 878 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 879 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 880 | break; |
| 881 | |
| 882 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 883 | ar = (AsyncResult) msg.obj; |
| 884 | request = (MainThreadRequest) ar.userObj; |
| 885 | if (ar.exception == null && ar.result != null) { |
| 886 | request.result = ar.result; |
| 887 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 888 | request.result = new IllegalStateException( |
| 889 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 890 | if (ar.result == null) { |
| 891 | loge("getAllowedCarriers: Empty response"); |
| 892 | } else if (ar.exception instanceof CommandException) { |
| 893 | loge("getAllowedCarriers: CommandException: " + |
| 894 | ar.exception); |
| 895 | } else { |
| 896 | loge("getAllowedCarriers: Unknown exception"); |
| 897 | } |
| 898 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 899 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 900 | break; |
| 901 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 902 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 903 | ar = (AsyncResult) msg.obj; |
| 904 | request = (MainThreadRequest) ar.userObj; |
| 905 | if (ar.exception == null && ar.result != null) { |
| 906 | request.result = ar.result; |
| 907 | } else { |
| 908 | request.result = new IllegalArgumentException( |
| 909 | "Failed to retrieve Forbidden Plmns"); |
| 910 | if (ar.result == null) { |
| 911 | loge("getForbiddenPlmns: Empty response"); |
| 912 | } else { |
| 913 | loge("getForbiddenPlmns: Unknown exception"); |
| 914 | } |
| 915 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 916 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 917 | break; |
| 918 | |
| 919 | case CMD_GET_FORBIDDEN_PLMNS: |
| 920 | request = (MainThreadRequest) msg.obj; |
| 921 | uiccCard = getUiccCardFromRequest(request); |
| 922 | if (uiccCard == null) { |
| 923 | loge("getForbiddenPlmns() UiccCard is null"); |
| 924 | request.result = new IllegalArgumentException( |
| 925 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 926 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 927 | break; |
| 928 | } |
| 929 | Integer appType = (Integer) request.argument; |
| 930 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 931 | if (uiccApp == null) { |
| 932 | loge("getForbiddenPlmns() no app with specified type -- " |
| 933 | + appType); |
| 934 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 935 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 936 | break; |
| 937 | } else { |
| 938 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 939 | + " specified type -- " + appType); |
| 940 | } |
| 941 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 942 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 943 | onCompleted); |
| 944 | break; |
| 945 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 946 | case CMD_SWITCH_SLOTS: |
| 947 | request = (MainThreadRequest) msg.obj; |
| 948 | int[] physicalSlots = (int[]) request.argument; |
| 949 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 950 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 951 | break; |
| 952 | |
| 953 | case EVENT_SWITCH_SLOTS_DONE: |
| 954 | ar = (AsyncResult) msg.obj; |
| 955 | request = (MainThreadRequest) ar.userObj; |
| 956 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 957 | notifyRequester(request); |
| 958 | break; |
| 959 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 960 | request = (MainThreadRequest) msg.obj; |
| 961 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 962 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 963 | break; |
| 964 | |
| 965 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 966 | ar = (AsyncResult) msg.obj; |
| 967 | request = (MainThreadRequest) ar.userObj; |
| 968 | if (ar.exception != null) { |
| 969 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 970 | } else { |
| 971 | int mode = ((int[]) ar.result)[0]; |
| 972 | if (mode == 0) { |
| 973 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 974 | } else { |
| 975 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 976 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 977 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 978 | notifyRequester(request); |
| 979 | break; |
| 980 | case CMD_GET_CDMA_ROAMING_MODE: |
| 981 | request = (MainThreadRequest) msg.obj; |
| 982 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 983 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 984 | break; |
| 985 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 986 | ar = (AsyncResult) msg.obj; |
| 987 | request = (MainThreadRequest) ar.userObj; |
| 988 | if (ar.exception != null) { |
| 989 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 990 | } else { |
| 991 | request.result = ((int[]) ar.result)[0]; |
| 992 | } |
| 993 | notifyRequester(request); |
| 994 | break; |
| 995 | case CMD_SET_CDMA_ROAMING_MODE: |
| 996 | request = (MainThreadRequest) msg.obj; |
| 997 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 998 | int mode = (int) request.argument; |
| 999 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1000 | break; |
| 1001 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1002 | ar = (AsyncResult) msg.obj; |
| 1003 | request = (MainThreadRequest) ar.userObj; |
| 1004 | request.result = ar.exception == null; |
| 1005 | notifyRequester(request); |
| 1006 | break; |
| 1007 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1008 | request = (MainThreadRequest) msg.obj; |
| 1009 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1010 | int subscriptionMode = (int) request.argument; |
| 1011 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1012 | break; |
| 1013 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1014 | ar = (AsyncResult) msg.obj; |
| 1015 | request = (MainThreadRequest) ar.userObj; |
| 1016 | request.result = ar.exception == null; |
| 1017 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1018 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1019 | case CMD_GET_ALL_CELL_INFO: |
| 1020 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1021 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1022 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1023 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1024 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1025 | ar = (AsyncResult) msg.obj; |
| 1026 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1027 | // If a timeout occurs, the response will be null |
| 1028 | request.result = (ar.exception == null && ar.result != null) |
| 1029 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1030 | synchronized (request) { |
| 1031 | request.notifyAll(); |
| 1032 | } |
| 1033 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1034 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1035 | request = (MainThreadRequest) msg.obj; |
| 1036 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1037 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1038 | break; |
| 1039 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1040 | ar = (AsyncResult) msg.obj; |
| 1041 | request = (MainThreadRequest) ar.userObj; |
| 1042 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1043 | try { |
| 1044 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1045 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1046 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1047 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1048 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1049 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1050 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1051 | } else { |
| 1052 | // use the result as returned |
| 1053 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1054 | } |
| 1055 | } catch (RemoteException re) { |
| 1056 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1057 | } |
| 1058 | break; |
| 1059 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1060 | request = (MainThreadRequest) msg.obj; |
| 1061 | WorkSource ws = (WorkSource) request.argument; |
| 1062 | Phone phone = getPhoneFromRequest(request); |
| 1063 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1064 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1065 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1066 | ar = (AsyncResult) msg.obj; |
| 1067 | request = (MainThreadRequest) ar.userObj; |
| 1068 | if (ar.exception == null) { |
| 1069 | request.result = ar.result; |
| 1070 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1071 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1072 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1073 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1074 | } |
| 1075 | |
| 1076 | synchronized (request) { |
| 1077 | request.notifyAll(); |
| 1078 | } |
| 1079 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1080 | case CMD_MODEM_REBOOT: |
| 1081 | request = (MainThreadRequest) msg.obj; |
| 1082 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1083 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1084 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1085 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1086 | handleNullReturnEvent(msg, "rebootModem"); |
| 1087 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1088 | case CMD_REQUEST_ENABLE_MODEM: |
| 1089 | request = (MainThreadRequest) msg.obj; |
| 1090 | boolean enable = (boolean) request.argument; |
| 1091 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
| 1092 | PhoneConfigurationManager.getInstance() |
| 1093 | .enablePhone(request.phone, enable, onCompleted); |
| 1094 | break; |
| 1095 | case EVENT_ENABLE_MODEM_DONE: |
| 1096 | ar = (AsyncResult) msg.obj; |
| 1097 | request = (MainThreadRequest) ar.userObj; |
| 1098 | request.result = (ar.exception == null); |
| 1099 | notifyRequester(request); |
| 1100 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1101 | default: |
| 1102 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1103 | break; |
| 1104 | } |
| 1105 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1106 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1107 | private void notifyRequester(MainThreadRequest request) { |
| 1108 | synchronized (request) { |
| 1109 | request.notifyAll(); |
| 1110 | } |
| 1111 | } |
| 1112 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1113 | private void handleNullReturnEvent(Message msg, String command) { |
| 1114 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1115 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1116 | if (ar.exception == null) { |
| 1117 | request.result = true; |
| 1118 | } else { |
| 1119 | request.result = false; |
| 1120 | if (ar.exception instanceof CommandException) { |
| 1121 | loge(command + ": CommandException: " + ar.exception); |
| 1122 | } else { |
| 1123 | loge(command + ": Unknown exception"); |
| 1124 | } |
| 1125 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1126 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1127 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | /** |
| 1131 | * Posts the specified command to be executed on the main thread, |
| 1132 | * waits for the request to complete, and returns the result. |
| 1133 | * @see #sendRequestAsync |
| 1134 | */ |
| 1135 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1136 | return sendRequest( |
| 1137 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | /** |
| 1141 | * Posts the specified command to be executed on the main thread, |
| 1142 | * waits for the request to complete, and returns the result. |
| 1143 | * @see #sendRequestAsync |
| 1144 | */ |
| 1145 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1146 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1147 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | /** |
| 1151 | * Posts the specified command to be executed on the main thread, |
| 1152 | * waits for the request to complete, and returns the result. |
| 1153 | * @see #sendRequestAsync |
| 1154 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1155 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1156 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | /** |
| 1160 | * Posts the specified command to be executed on the main thread, |
| 1161 | * waits for the request to complete, and returns the result. |
| 1162 | * @see #sendRequestAsync |
| 1163 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1164 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1165 | return sendRequest(command, argument, subId, null, workSource); |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * Posts the specified command to be executed on the main thread, |
| 1170 | * waits for the request to complete, and returns the result. |
| 1171 | * @see #sendRequestAsync |
| 1172 | */ |
| 1173 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1174 | return sendRequest( |
| 1175 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1176 | } |
| 1177 | |
| 1178 | /** |
| 1179 | * Posts the specified command to be executed on the main thread, |
| 1180 | * waits for the request to complete, and returns the result. |
| 1181 | * @see #sendRequestAsync |
| 1182 | */ |
| 1183 | private Object sendRequest( |
| 1184 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1185 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1186 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1187 | } |
| 1188 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1189 | MainThreadRequest request = null; |
| 1190 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1191 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1192 | } else if (phone != null) { |
| 1193 | request = new MainThreadRequest(argument, phone, workSource); |
| 1194 | } else { |
| 1195 | request = new MainThreadRequest(argument, subId, workSource); |
| 1196 | } |
| 1197 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1198 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1199 | msg.sendToTarget(); |
| 1200 | |
| 1201 | // Wait for the request to complete |
| 1202 | synchronized (request) { |
| 1203 | while (request.result == null) { |
| 1204 | try { |
| 1205 | request.wait(); |
| 1206 | } catch (InterruptedException e) { |
| 1207 | // Do nothing, go back and wait until the request is complete |
| 1208 | } |
| 1209 | } |
| 1210 | } |
| 1211 | return request.result; |
| 1212 | } |
| 1213 | |
| 1214 | /** |
| 1215 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1216 | * Posts the specified command to be executed on the main thread, and |
| 1217 | * returns immediately. |
| 1218 | * @see #sendRequest |
| 1219 | */ |
| 1220 | private void sendRequestAsync(int command) { |
| 1221 | mMainThreadHandler.sendEmptyMessage(command); |
| 1222 | } |
| 1223 | |
| 1224 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1225 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1226 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1227 | */ |
| 1228 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1229 | sendRequestAsync(command, argument, null, null); |
| 1230 | } |
| 1231 | |
| 1232 | /** |
| 1233 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1234 | * @see {@link #sendRequest(int,Object)} |
| 1235 | */ |
| 1236 | private void sendRequestAsync( |
| 1237 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1238 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1239 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1240 | msg.sendToTarget(); |
| 1241 | } |
| 1242 | |
| 1243 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1244 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1245 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1246 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1247 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1248 | synchronized (PhoneInterfaceManager.class) { |
| 1249 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1250 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1251 | } else { |
| 1252 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1253 | } |
| 1254 | return sInstance; |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1259 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1260 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1261 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1262 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1263 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1264 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1265 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1266 | mTelephonySharedPreferences = |
| 1267 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1268 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1269 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1270 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1271 | publish(); |
| 1272 | } |
| 1273 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1274 | private Phone getDefaultPhone() { |
| 1275 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1276 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1277 | } |
| 1278 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1279 | private void publish() { |
| 1280 | if (DBG) log("publish: " + this); |
| 1281 | |
| 1282 | ServiceManager.addService("phone", this); |
| 1283 | } |
| 1284 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1285 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1286 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1287 | ? getDefaultPhone() : getPhone(request.subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1288 | } |
| 1289 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1290 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1291 | Phone phone = getPhoneFromRequest(request); |
| 1292 | return phone == null ? null : |
| 1293 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1294 | } |
| 1295 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1296 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1297 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1298 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1299 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1300 | |
| 1301 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1302 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1305 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1306 | if (DBG) log("dial: " + number); |
| 1307 | // No permission check needed here: This is just a wrapper around the |
| 1308 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1309 | // the UI before it does anything. |
| 1310 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1311 | final long identity = Binder.clearCallingIdentity(); |
| 1312 | try { |
| 1313 | String url = createTelUrl(number); |
| 1314 | if (url == null) { |
| 1315 | return; |
| 1316 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1317 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1318 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1319 | PhoneConstants.State state = mCM.getState(subId); |
| 1320 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1321 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1322 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1323 | mApp.startActivity(intent); |
| 1324 | } |
| 1325 | } finally { |
| 1326 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1331 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1334 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1335 | if (DBG) log("call: " + number); |
| 1336 | |
| 1337 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1338 | // need to do a permission check since we're calling startActivity() |
| 1339 | // from the context of the phone app. |
| 1340 | enforceCallPermission(); |
| 1341 | |
| 1342 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1343 | != AppOpsManager.MODE_ALLOWED) { |
| 1344 | return; |
| 1345 | } |
| 1346 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1347 | final long identity = Binder.clearCallingIdentity(); |
| 1348 | try { |
| 1349 | String url = createTelUrl(number); |
| 1350 | if (url == null) { |
| 1351 | return; |
| 1352 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1353 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1354 | boolean isValid = false; |
| 1355 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1356 | if (slist != null) { |
| 1357 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1358 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1359 | isValid = true; |
| 1360 | break; |
| 1361 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1362 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1363 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1364 | if (!isValid) { |
| 1365 | return; |
| 1366 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1367 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1368 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1369 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1370 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1371 | mApp.startActivity(intent); |
| 1372 | } finally { |
| 1373 | Binder.restoreCallingIdentity(identity); |
| 1374 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1377 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1378 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1381 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1382 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1383 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1384 | } |
| 1385 | |
| 1386 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1387 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1390 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1391 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1392 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1393 | } |
| 1394 | |
| 1395 | /** {@hide} */ |
| 1396 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1397 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1400 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1401 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1402 | |
| 1403 | final long identity = Binder.clearCallingIdentity(); |
| 1404 | try { |
| 1405 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1406 | checkSimPin.start(); |
| 1407 | return checkSimPin.unlockSim(null, pin); |
| 1408 | } finally { |
| 1409 | Binder.restoreCallingIdentity(identity); |
| 1410 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1413 | /** {@hide} */ |
| 1414 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1415 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1418 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1419 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1420 | |
| 1421 | final long identity = Binder.clearCallingIdentity(); |
| 1422 | try { |
| 1423 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1424 | checkSimPuk.start(); |
| 1425 | return checkSimPuk.unlockSim(puk, pin); |
| 1426 | } finally { |
| 1427 | Binder.restoreCallingIdentity(identity); |
| 1428 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1432 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1433 | * a synchronous one. |
| 1434 | */ |
| 1435 | private static class UnlockSim extends Thread { |
| 1436 | |
| 1437 | private final IccCard mSimCard; |
| 1438 | |
| 1439 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1440 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1441 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1442 | |
| 1443 | // For replies from SimCard interface |
| 1444 | private Handler mHandler; |
| 1445 | |
| 1446 | // For async handler to identify request type |
| 1447 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1448 | |
| 1449 | public UnlockSim(IccCard simCard) { |
| 1450 | mSimCard = simCard; |
| 1451 | } |
| 1452 | |
| 1453 | @Override |
| 1454 | public void run() { |
| 1455 | Looper.prepare(); |
| 1456 | synchronized (UnlockSim.this) { |
| 1457 | mHandler = new Handler() { |
| 1458 | @Override |
| 1459 | public void handleMessage(Message msg) { |
| 1460 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1461 | switch (msg.what) { |
| 1462 | case SUPPLY_PIN_COMPLETE: |
| 1463 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1464 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1465 | mRetryCount = msg.arg1; |
| 1466 | if (ar.exception != null) { |
| 1467 | if (ar.exception instanceof CommandException && |
| 1468 | ((CommandException)(ar.exception)).getCommandError() |
| 1469 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1470 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1471 | } else { |
| 1472 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1473 | } |
| 1474 | } else { |
| 1475 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1476 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1477 | mDone = true; |
| 1478 | UnlockSim.this.notifyAll(); |
| 1479 | } |
| 1480 | break; |
| 1481 | } |
| 1482 | } |
| 1483 | }; |
| 1484 | UnlockSim.this.notifyAll(); |
| 1485 | } |
| 1486 | Looper.loop(); |
| 1487 | } |
| 1488 | |
| 1489 | /* |
| 1490 | * Use PIN or PUK to unlock SIM card |
| 1491 | * |
| 1492 | * If PUK is null, unlock SIM card with PIN |
| 1493 | * |
| 1494 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1495 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1496 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1497 | |
| 1498 | while (mHandler == null) { |
| 1499 | try { |
| 1500 | wait(); |
| 1501 | } catch (InterruptedException e) { |
| 1502 | Thread.currentThread().interrupt(); |
| 1503 | } |
| 1504 | } |
| 1505 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1506 | |
| 1507 | if (puk == null) { |
| 1508 | mSimCard.supplyPin(pin, callback); |
| 1509 | } else { |
| 1510 | mSimCard.supplyPuk(puk, pin, callback); |
| 1511 | } |
| 1512 | |
| 1513 | while (!mDone) { |
| 1514 | try { |
| 1515 | Log.d(LOG_TAG, "wait for done"); |
| 1516 | wait(); |
| 1517 | } catch (InterruptedException e) { |
| 1518 | // Restore the interrupted status |
| 1519 | Thread.currentThread().interrupt(); |
| 1520 | } |
| 1521 | } |
| 1522 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1523 | int[] resultArray = new int[2]; |
| 1524 | resultArray[0] = mResult; |
| 1525 | resultArray[1] = mRetryCount; |
| 1526 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1527 | } |
| 1528 | } |
| 1529 | |
| 1530 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1531 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1532 | |
| 1533 | } |
| 1534 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1535 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1536 | // No permission check needed here: this call is harmless, and it's |
| 1537 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1538 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1539 | final long identity = Binder.clearCallingIdentity(); |
| 1540 | try { |
| 1541 | final Phone phone = getPhone(subId); |
| 1542 | if (phone != null) { |
| 1543 | phone.updateServiceLocation(); |
| 1544 | } |
| 1545 | } finally { |
| 1546 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1547 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1550 | @Override |
| 1551 | public boolean isRadioOn(String callingPackage) { |
| 1552 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1555 | @Override |
| 1556 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1557 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1558 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1559 | return false; |
| 1560 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1561 | |
| 1562 | final long identity = Binder.clearCallingIdentity(); |
| 1563 | try { |
| 1564 | return isRadioOnForSubscriber(subId); |
| 1565 | } finally { |
| 1566 | Binder.restoreCallingIdentity(identity); |
| 1567 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1571 | final long identity = Binder.clearCallingIdentity(); |
| 1572 | try { |
| 1573 | final Phone phone = getPhone(subId); |
| 1574 | if (phone != null) { |
| 1575 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1576 | } else { |
| 1577 | return false; |
| 1578 | } |
| 1579 | } finally { |
| 1580 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1581 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1585 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1586 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1587 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1588 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1589 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1590 | |
| 1591 | final long identity = Binder.clearCallingIdentity(); |
| 1592 | try { |
| 1593 | final Phone phone = getPhone(subId); |
| 1594 | if (phone != null) { |
| 1595 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1596 | } |
| 1597 | } finally { |
| 1598 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1599 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1603 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1606 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1607 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1608 | |
| 1609 | final long identity = Binder.clearCallingIdentity(); |
| 1610 | try { |
| 1611 | final Phone phone = getPhone(subId); |
| 1612 | if (phone == null) { |
| 1613 | return false; |
| 1614 | } |
| 1615 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1616 | toggleRadioOnOffForSubscriber(subId); |
| 1617 | } |
| 1618 | return true; |
| 1619 | } finally { |
| 1620 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1621 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1622 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1623 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1624 | public boolean needMobileRadioShutdown() { |
| 1625 | /* |
| 1626 | * If any of the Radios are available, it will need to be |
| 1627 | * shutdown. So return true if any Radio is available. |
| 1628 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1629 | final long identity = Binder.clearCallingIdentity(); |
| 1630 | try { |
| 1631 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1632 | Phone phone = PhoneFactory.getPhone(i); |
| 1633 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1634 | } |
| 1635 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1636 | return false; |
| 1637 | } finally { |
| 1638 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1639 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1642 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1643 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1644 | enforceModifyPermission(); |
| 1645 | |
| 1646 | final long identity = Binder.clearCallingIdentity(); |
| 1647 | try { |
| 1648 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1649 | logv("Shutting down Phone " + i); |
| 1650 | shutdownRadioUsingPhoneId(i); |
| 1651 | } |
| 1652 | } finally { |
| 1653 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1658 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1659 | if (phone != null && phone.isRadioAvailable()) { |
| 1660 | phone.shutdownRadio(); |
| 1661 | } |
| 1662 | } |
| 1663 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1664 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1665 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1666 | |
| 1667 | final long identity = Binder.clearCallingIdentity(); |
| 1668 | try { |
| 1669 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1670 | if (defaultPhone != null) { |
| 1671 | defaultPhone.setRadioPower(turnOn); |
| 1672 | return true; |
| 1673 | } else { |
| 1674 | loge("There's no default phone."); |
| 1675 | return false; |
| 1676 | } |
| 1677 | } finally { |
| 1678 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1679 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1680 | } |
| 1681 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1682 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1683 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1684 | |
| 1685 | final long identity = Binder.clearCallingIdentity(); |
| 1686 | try { |
| 1687 | final Phone phone = getPhone(subId); |
| 1688 | if (phone != null) { |
| 1689 | phone.setRadioPower(turnOn); |
| 1690 | return true; |
| 1691 | } else { |
| 1692 | return false; |
| 1693 | } |
| 1694 | } finally { |
| 1695 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1696 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1699 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1700 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1701 | public boolean enableDataConnectivity() { |
| 1702 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1703 | |
| 1704 | final long identity = Binder.clearCallingIdentity(); |
| 1705 | try { |
| 1706 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1707 | final Phone phone = getPhone(subId); |
| 1708 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1709 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1710 | return true; |
| 1711 | } else { |
| 1712 | return false; |
| 1713 | } |
| 1714 | } finally { |
| 1715 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1716 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1719 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1720 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1721 | public boolean disableDataConnectivity() { |
| 1722 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1723 | |
| 1724 | final long identity = Binder.clearCallingIdentity(); |
| 1725 | try { |
| 1726 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1727 | final Phone phone = getPhone(subId); |
| 1728 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1729 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1730 | return true; |
| 1731 | } else { |
| 1732 | return false; |
| 1733 | } |
| 1734 | } finally { |
| 1735 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1736 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1739 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1740 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1741 | final long identity = Binder.clearCallingIdentity(); |
| 1742 | try { |
| 1743 | final Phone phone = getPhone(subId); |
| 1744 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1745 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1746 | } else { |
| 1747 | return false; |
| 1748 | } |
| 1749 | } finally { |
| 1750 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1751 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1755 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1758 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1759 | enforceCallPermission(); |
| 1760 | |
| 1761 | final long identity = Binder.clearCallingIdentity(); |
| 1762 | try { |
| 1763 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1764 | return; |
| 1765 | } |
| 1766 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1767 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1768 | } finally { |
| 1769 | Binder.restoreCallingIdentity(identity); |
| 1770 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1771 | }; |
| 1772 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1773 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1774 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1775 | |
| 1776 | final long identity = Binder.clearCallingIdentity(); |
| 1777 | try { |
| 1778 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1779 | return false; |
| 1780 | } |
| 1781 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1782 | } finally { |
| 1783 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1784 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1787 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1788 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1791 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1792 | final long identity = Binder.clearCallingIdentity(); |
| 1793 | try { |
| 1794 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1795 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1796 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1797 | } finally { |
| 1798 | Binder.restoreCallingIdentity(identity); |
| 1799 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1802 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1803 | public int getDataState() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1804 | final long identity = Binder.clearCallingIdentity(); |
| 1805 | try { |
| 1806 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1807 | if (phone != null) { |
| 1808 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1809 | } else { |
| 1810 | return PhoneConstantConversions.convertDataState( |
| 1811 | PhoneConstants.DataState.DISCONNECTED); |
| 1812 | } |
| 1813 | } finally { |
| 1814 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 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 getDataActivity() { |
Malcolm Chen | aa4a853 | 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 DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1825 | } else { |
| 1826 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1827 | } |
| 1828 | } finally { |
| 1829 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1830 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1834 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1835 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1836 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1837 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage, |
| 1838 | Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1839 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1842 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1843 | final long identity = Binder.clearCallingIdentity(); |
| 1844 | try { |
| 1845 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1846 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1847 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1848 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1849 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1850 | return data; |
| 1851 | } finally { |
| 1852 | Binder.restoreCallingIdentity(identity); |
| 1853 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1856 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1857 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1858 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1859 | // registered cell info, so return a NULL country instead. |
| 1860 | final long identity = Binder.clearCallingIdentity(); |
| 1861 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1862 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1863 | // Get default phone in this case. |
| 1864 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1865 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1866 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1867 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1868 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1869 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1870 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1871 | return ""; |
| 1872 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1873 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1874 | if (phone != null) { |
| 1875 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1876 | if (sst != null) { |
| 1877 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1878 | if (lt != null) { |
| 1879 | return lt.getCurrentCountry(); |
| 1880 | } |
| 1881 | } |
| 1882 | } |
| 1883 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1884 | } finally { |
| 1885 | Binder.restoreCallingIdentity(identity); |
| 1886 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1890 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1891 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1894 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1895 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1896 | mApp.enforceCallingOrSelfPermission( |
| 1897 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1898 | |
| 1899 | final long identity = Binder.clearCallingIdentity(); |
| 1900 | try { |
| 1901 | final Phone phone = getPhone(subId); |
| 1902 | if (phone != null) { |
| 1903 | phone.enableLocationUpdates(); |
| 1904 | } |
| 1905 | } finally { |
| 1906 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1907 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | @Override |
| 1911 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1912 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1915 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1916 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1917 | mApp.enforceCallingOrSelfPermission( |
| 1918 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1919 | |
| 1920 | final long identity = Binder.clearCallingIdentity(); |
| 1921 | try { |
| 1922 | final Phone phone = getPhone(subId); |
| 1923 | if (phone != null) { |
| 1924 | phone.disableLocationUpdates(); |
| 1925 | } |
| 1926 | } finally { |
| 1927 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1928 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1931 | /** |
| 1932 | * Returns the target SDK version number for a given package name. |
| 1933 | * |
| 1934 | * @return target SDK if the package is found or INT_MAX. |
| 1935 | */ |
| 1936 | private int getTargetSdk(String packageName) { |
| 1937 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1938 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 1939 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1940 | if (ai != null) return ai.targetSdkVersion; |
| 1941 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1942 | } |
| 1943 | return Integer.MAX_VALUE; |
| 1944 | } |
| 1945 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1946 | @Override |
| 1947 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1948 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1949 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1950 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1951 | throw new SecurityException( |
| 1952 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1953 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1954 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1955 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1956 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1957 | return null; |
| 1958 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1959 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1960 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1961 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1962 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 1963 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1964 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1965 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 1966 | for (CellInfo ci : info) { |
| 1967 | if (ci instanceof CellInfoGsm) { |
| 1968 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 1969 | } else if (ci instanceof CellInfoWcdma) { |
| 1970 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 1971 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1972 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1973 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1976 | private List<CellInfo> getCachedCellInfo() { |
| 1977 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 1978 | for (Phone phone : PhoneFactory.getPhones()) { |
| 1979 | List<CellInfo> info = phone.getAllCellInfo(); |
| 1980 | if (info != null) cellInfos.addAll(info); |
| 1981 | } |
| 1982 | return cellInfos; |
| 1983 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1984 | |
| 1985 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1986 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1987 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1988 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1989 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, |
Svet Ganov | 4af6628 | 2018-03-07 19:57:05 -0800 | [diff] [blame] | 1990 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1991 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1994 | final int targetSdk = getTargetSdk(callingPackage); |
| 1995 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1996 | return getCachedCellInfo(); |
| 1997 | } |
| 1998 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1999 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2000 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2001 | final long identity = Binder.clearCallingIdentity(); |
| 2002 | try { |
| 2003 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2004 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2005 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2006 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2007 | if (info != null) cellInfos.addAll(info); |
| 2008 | } |
| 2009 | return cellInfos; |
| 2010 | } finally { |
| 2011 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2012 | } |
| 2013 | } |
| 2014 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2015 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2016 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2017 | requestCellInfoUpdateInternal( |
| 2018 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2019 | } |
| 2020 | |
| 2021 | @Override |
| 2022 | public void requestCellInfoUpdateWithWorkSource( |
| 2023 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2024 | enforceModifyPermission(); |
| 2025 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2026 | } |
| 2027 | |
| 2028 | private void requestCellInfoUpdateInternal( |
| 2029 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2030 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2031 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2032 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage, |
| 2033 | Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2034 | return; |
| 2035 | } |
| 2036 | |
| 2037 | final Phone phone = getPhone(subId); |
| 2038 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2039 | |
| 2040 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2041 | } |
| 2042 | |
| 2043 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2044 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2045 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2046 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2047 | |
| 2048 | final long identity = Binder.clearCallingIdentity(); |
| 2049 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2050 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2051 | } finally { |
| 2052 | Binder.restoreCallingIdentity(identity); |
| 2053 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2054 | } |
| 2055 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2056 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2057 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2058 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2059 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2060 | return null; |
| 2061 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2062 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2063 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2064 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2065 | return null; |
| 2066 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2067 | |
| 2068 | final long identity = Binder.clearCallingIdentity(); |
| 2069 | try { |
| 2070 | return phone.getImei(); |
| 2071 | } finally { |
| 2072 | Binder.restoreCallingIdentity(identity); |
| 2073 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2077 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2078 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2079 | String tac = null; |
| 2080 | if (phone != null) { |
| 2081 | String imei = phone.getImei(); |
| 2082 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2083 | } |
| 2084 | return tac; |
| 2085 | } |
| 2086 | |
| 2087 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2088 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2089 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2090 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2091 | return null; |
| 2092 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2093 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2094 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2095 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2096 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2097 | return null; |
| 2098 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2099 | |
| 2100 | final long identity = Binder.clearCallingIdentity(); |
| 2101 | try { |
| 2102 | return phone.getMeid(); |
| 2103 | } finally { |
| 2104 | Binder.restoreCallingIdentity(identity); |
| 2105 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2109 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2110 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2111 | String manufacturerCode = null; |
| 2112 | if (phone != null) { |
| 2113 | String meid = phone.getMeid(); |
| 2114 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2115 | } |
| 2116 | return manufacturerCode; |
| 2117 | } |
| 2118 | |
| 2119 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2120 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2121 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2122 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2123 | return null; |
| 2124 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2125 | int subId = phone.getSubId(); |
| 2126 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2127 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2128 | return null; |
| 2129 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2130 | |
| 2131 | final long identity = Binder.clearCallingIdentity(); |
| 2132 | try { |
| 2133 | return phone.getDeviceSvn(); |
| 2134 | } finally { |
| 2135 | Binder.restoreCallingIdentity(identity); |
| 2136 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2137 | } |
| 2138 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2139 | @Override |
| 2140 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2141 | final long identity = Binder.clearCallingIdentity(); |
| 2142 | try { |
| 2143 | final Phone phone = getPhone(subId); |
| 2144 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2145 | } finally { |
| 2146 | Binder.restoreCallingIdentity(identity); |
| 2147 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | @Override |
| 2151 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2152 | final long identity = Binder.clearCallingIdentity(); |
| 2153 | try { |
| 2154 | final Phone phone = getPhone(subId); |
| 2155 | return phone == null ? null : phone.getCarrierName(); |
| 2156 | } finally { |
| 2157 | Binder.restoreCallingIdentity(identity); |
| 2158 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2159 | } |
| 2160 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2161 | @Override |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2162 | public int getSubscriptionPreciseCarrierId(int subId) { |
| 2163 | final long identity = Binder.clearCallingIdentity(); |
| 2164 | try { |
| 2165 | final Phone phone = getPhone(subId); |
| 2166 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
| 2167 | : phone.getPreciseCarrierId(); |
| 2168 | } finally { |
| 2169 | Binder.restoreCallingIdentity(identity); |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | @Override |
| 2174 | public String getSubscriptionPreciseCarrierName(int subId) { |
| 2175 | final long identity = Binder.clearCallingIdentity(); |
| 2176 | try { |
| 2177 | final Phone phone = getPhone(subId); |
| 2178 | return phone == null ? null : phone.getPreciseCarrierName(); |
| 2179 | } finally { |
| 2180 | Binder.restoreCallingIdentity(identity); |
| 2181 | } |
| 2182 | } |
| 2183 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2184 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2185 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2186 | if (!isSubscriptionMccMnc) { |
| 2187 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2188 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2189 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2190 | if (phone == null) { |
| 2191 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2192 | } |
| 2193 | final long identity = Binder.clearCallingIdentity(); |
| 2194 | try { |
| 2195 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2196 | } finally { |
| 2197 | Binder.restoreCallingIdentity(identity); |
| 2198 | } |
| 2199 | } |
| 2200 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2201 | // |
| 2202 | // Internal helper methods. |
| 2203 | // |
| 2204 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2205 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2206 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2207 | * |
| 2208 | * @throws SecurityException if the caller does not have the required permission |
| 2209 | */ |
| 2210 | private void enforceModifyPermission() { |
| 2211 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2212 | } |
| 2213 | |
| 2214 | /** |
| 2215 | * Make sure the caller has the CALL_PHONE permission. |
| 2216 | * |
| 2217 | * @throws SecurityException if the caller does not have the required permission |
| 2218 | */ |
| 2219 | private void enforceCallPermission() { |
| 2220 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2221 | } |
| 2222 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2223 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2224 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2225 | "ConnectivityService"); |
| 2226 | } |
| 2227 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2228 | private String createTelUrl(String number) { |
| 2229 | if (TextUtils.isEmpty(number)) { |
| 2230 | return null; |
| 2231 | } |
| 2232 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2233 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2236 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2237 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2238 | } |
| 2239 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2240 | private static void logv(String msg) { |
| 2241 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2242 | } |
| 2243 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2244 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2245 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2246 | } |
| 2247 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2248 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2249 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2250 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2251 | } |
| 2252 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2253 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2254 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2255 | final long identity = Binder.clearCallingIdentity(); |
| 2256 | try { |
| 2257 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2258 | if (phone == null) { |
| 2259 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2260 | } else { |
| 2261 | return phone.getPhoneType(); |
| 2262 | } |
| 2263 | } finally { |
| 2264 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2265 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | /** |
| 2269 | * Returns the CDMA ERI icon index to display |
| 2270 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2271 | @Override |
| 2272 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2273 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2276 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2277 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2278 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2279 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2280 | return -1; |
| 2281 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2282 | |
| 2283 | final long identity = Binder.clearCallingIdentity(); |
| 2284 | try { |
| 2285 | final Phone phone = getPhone(subId); |
| 2286 | if (phone != null) { |
| 2287 | return phone.getCdmaEriIconIndex(); |
| 2288 | } else { |
| 2289 | return -1; |
| 2290 | } |
| 2291 | } finally { |
| 2292 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2293 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | /** |
| 2297 | * Returns the CDMA ERI icon mode, |
| 2298 | * 0 - ON |
| 2299 | * 1 - FLASHING |
| 2300 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2301 | @Override |
| 2302 | public int getCdmaEriIconMode(String callingPackage) { |
| 2303 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
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 |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2307 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2308 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2309 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2310 | return -1; |
| 2311 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2312 | |
| 2313 | final long identity = Binder.clearCallingIdentity(); |
| 2314 | try { |
| 2315 | final Phone phone = getPhone(subId); |
| 2316 | if (phone != null) { |
| 2317 | return phone.getCdmaEriIconMode(); |
| 2318 | } else { |
| 2319 | return -1; |
| 2320 | } |
| 2321 | } finally { |
| 2322 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2323 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | /** |
| 2327 | * Returns the CDMA ERI text, |
| 2328 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2329 | @Override |
| 2330 | public String getCdmaEriText(String callingPackage) { |
| 2331 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2334 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2335 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2336 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2337 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2338 | return null; |
| 2339 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2340 | |
| 2341 | final long identity = Binder.clearCallingIdentity(); |
| 2342 | try { |
| 2343 | final Phone phone = getPhone(subId); |
| 2344 | if (phone != null) { |
| 2345 | return phone.getCdmaEriText(); |
| 2346 | } else { |
| 2347 | return null; |
| 2348 | } |
| 2349 | } finally { |
| 2350 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2351 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2355 | * Returns the CDMA MDN. |
| 2356 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2357 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2358 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2359 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2360 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2361 | |
| 2362 | final long identity = Binder.clearCallingIdentity(); |
| 2363 | try { |
| 2364 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2365 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2366 | return phone.getLine1Number(); |
| 2367 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2368 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2369 | return null; |
| 2370 | } |
| 2371 | } finally { |
| 2372 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2373 | } |
| 2374 | } |
| 2375 | |
| 2376 | /** |
| 2377 | * Returns the CDMA MIN. |
| 2378 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2379 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2380 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2381 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2382 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2383 | |
| 2384 | final long identity = Binder.clearCallingIdentity(); |
| 2385 | try { |
| 2386 | final Phone phone = getPhone(subId); |
| 2387 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2388 | return phone.getCdmaMin(); |
| 2389 | } else { |
| 2390 | return null; |
| 2391 | } |
| 2392 | } finally { |
| 2393 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2394 | } |
| 2395 | } |
| 2396 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2397 | @Override |
| 2398 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2399 | INumberVerificationCallback callback, String callingPackage) { |
| 2400 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2401 | != PERMISSION_GRANTED) { |
| 2402 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2403 | } |
| 2404 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2405 | |
| 2406 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2407 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2408 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2409 | } |
| 2410 | |
| 2411 | if (range == null) { |
| 2412 | throw new NullPointerException("Range must be non-null"); |
| 2413 | } |
| 2414 | |
| 2415 | timeoutMillis = Math.min(timeoutMillis, |
| 2416 | TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS); |
| 2417 | |
| 2418 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2419 | } |
| 2420 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2421 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2422 | * Returns true if CDMA provisioning needs to run. |
| 2423 | */ |
| 2424 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2425 | final long identity = Binder.clearCallingIdentity(); |
| 2426 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2427 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2428 | } finally { |
| 2429 | Binder.restoreCallingIdentity(identity); |
| 2430 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2434 | * Sets the voice mail number of a given subId. |
| 2435 | */ |
| 2436 | @Override |
| 2437 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2438 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2439 | |
| 2440 | final long identity = Binder.clearCallingIdentity(); |
| 2441 | try { |
| 2442 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2443 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2444 | return success; |
| 2445 | } finally { |
| 2446 | Binder.restoreCallingIdentity(identity); |
| 2447 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2448 | } |
| 2449 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2450 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2451 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2452 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2453 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2454 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2455 | throw new SecurityException("caller must be system dialer"); |
| 2456 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2457 | |
| 2458 | final long identity = Binder.clearCallingIdentity(); |
| 2459 | try { |
| 2460 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2461 | if (phoneAccountHandle == null) { |
| 2462 | return null; |
| 2463 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2464 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2465 | } finally { |
| 2466 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2467 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2471 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2472 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2473 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2474 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2475 | return null; |
| 2476 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2477 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2478 | final long identity = Binder.clearCallingIdentity(); |
| 2479 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2480 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2481 | } finally { |
| 2482 | Binder.restoreCallingIdentity(identity); |
| 2483 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2487 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2488 | VisualVoicemailSmsFilterSettings settings) { |
| 2489 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2490 | |
| 2491 | final long identity = Binder.clearCallingIdentity(); |
| 2492 | try { |
| 2493 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2494 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2495 | } finally { |
| 2496 | Binder.restoreCallingIdentity(identity); |
| 2497 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2501 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2502 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2503 | |
| 2504 | final long identity = Binder.clearCallingIdentity(); |
| 2505 | try { |
| 2506 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2507 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2508 | } finally { |
| 2509 | Binder.restoreCallingIdentity(identity); |
| 2510 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2514 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2515 | String callingPackage, int subId) { |
| 2516 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2517 | |
| 2518 | final long identity = Binder.clearCallingIdentity(); |
| 2519 | try { |
| 2520 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2521 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2522 | } finally { |
| 2523 | Binder.restoreCallingIdentity(identity); |
| 2524 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2528 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2529 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2530 | |
| 2531 | final long identity = Binder.clearCallingIdentity(); |
| 2532 | try { |
| 2533 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2534 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2535 | } finally { |
| 2536 | Binder.restoreCallingIdentity(identity); |
| 2537 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | @Override |
| 2541 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2542 | String number, int port, String text, PendingIntent sentIntent) { |
| 2543 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2544 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2545 | enforceSendSmsPermission(); |
| 2546 | // Make the calls as the phone process. |
| 2547 | final long identity = Binder.clearCallingIdentity(); |
| 2548 | try { |
| 2549 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2550 | if (port == 0) { |
| 2551 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2552 | sentIntent, null, false); |
| 2553 | } else { |
| 2554 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2555 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2556 | (short) port, data, sentIntent, null); |
| 2557 | } |
| 2558 | } finally { |
| 2559 | Binder.restoreCallingIdentity(identity); |
| 2560 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2561 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2562 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2563 | * Sets the voice activation state of a given subId. |
| 2564 | */ |
| 2565 | @Override |
| 2566 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2567 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2568 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2569 | |
| 2570 | final long identity = Binder.clearCallingIdentity(); |
| 2571 | try { |
| 2572 | final Phone phone = getPhone(subId); |
| 2573 | if (phone != null) { |
| 2574 | phone.setVoiceActivationState(activationState); |
| 2575 | } else { |
| 2576 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2577 | } |
| 2578 | } finally { |
| 2579 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2580 | } |
| 2581 | } |
| 2582 | |
| 2583 | /** |
| 2584 | * Sets the data activation state of a given subId. |
| 2585 | */ |
| 2586 | @Override |
| 2587 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2588 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2589 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2590 | |
| 2591 | final long identity = Binder.clearCallingIdentity(); |
| 2592 | try { |
| 2593 | final Phone phone = getPhone(subId); |
| 2594 | if (phone != null) { |
| 2595 | phone.setDataActivationState(activationState); |
| 2596 | } else { |
| 2597 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2598 | } |
| 2599 | } finally { |
| 2600 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | /** |
| 2605 | * Returns the voice activation state of a given subId. |
| 2606 | */ |
| 2607 | @Override |
| 2608 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2609 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2610 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2611 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2612 | final long identity = Binder.clearCallingIdentity(); |
| 2613 | try { |
| 2614 | if (phone != null) { |
| 2615 | return phone.getVoiceActivationState(); |
| 2616 | } else { |
| 2617 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2618 | } |
| 2619 | } finally { |
| 2620 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2621 | } |
| 2622 | } |
| 2623 | |
| 2624 | /** |
| 2625 | * Returns the data activation state of a given subId. |
| 2626 | */ |
| 2627 | @Override |
| 2628 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2629 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2630 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2631 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2632 | final long identity = Binder.clearCallingIdentity(); |
| 2633 | try { |
| 2634 | if (phone != null) { |
| 2635 | return phone.getDataActivationState(); |
| 2636 | } else { |
| 2637 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2638 | } |
| 2639 | } finally { |
| 2640 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2641 | } |
| 2642 | } |
| 2643 | |
| 2644 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2645 | * Returns the unread count of voicemails for a subId |
| 2646 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2647 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2648 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2649 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2650 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2651 | return 0; |
| 2652 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2653 | final long identity = Binder.clearCallingIdentity(); |
| 2654 | try { |
| 2655 | final Phone phone = getPhone(subId); |
| 2656 | if (phone != null) { |
| 2657 | return phone.getVoiceMessageCount(); |
| 2658 | } else { |
| 2659 | return 0; |
| 2660 | } |
| 2661 | } finally { |
| 2662 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2663 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2667 | * returns true, if the device is in a state where both voice and data |
| 2668 | * are supported simultaneously. This can change based on location or network condition. |
| 2669 | */ |
| 2670 | @Override |
| 2671 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2672 | final long identity = Binder.clearCallingIdentity(); |
| 2673 | try { |
| 2674 | final Phone phone = getPhone(subId); |
| 2675 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2676 | } finally { |
| 2677 | Binder.restoreCallingIdentity(identity); |
| 2678 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2682 | * Send the dialer code if called from the current default dialer or the caller has |
| 2683 | * carrier privilege. |
| 2684 | * @param inputCode The dialer code to send |
| 2685 | */ |
| 2686 | @Override |
| 2687 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2688 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2689 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2690 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2691 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2692 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2693 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2694 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2695 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2696 | |
| 2697 | final long identity = Binder.clearCallingIdentity(); |
| 2698 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2699 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2700 | } finally { |
| 2701 | Binder.restoreCallingIdentity(identity); |
| 2702 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2703 | } |
| 2704 | |
| 2705 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2706 | * Returns the data network type. |
| 2707 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2708 | * |
| 2709 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2710 | */ |
| 2711 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2712 | public int getNetworkType() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2713 | final long identity = Binder.clearCallingIdentity(); |
| 2714 | try { |
| 2715 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2716 | if (phone != null) { |
| 2717 | return phone.getServiceState().getDataNetworkType(); |
| 2718 | } else { |
| 2719 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2720 | } |
| 2721 | } finally { |
| 2722 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2723 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2726 | @Override |
| 2727 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2728 | if (!isActiveSubscription(subId)) { |
| 2729 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2730 | } |
| 2731 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2732 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2733 | } |
| 2734 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2735 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2736 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2737 | throws RemoteException { |
| 2738 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2739 | final long token = Binder.clearCallingIdentity(); |
| 2740 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2741 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2742 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2743 | .addRegistrationCallbackForSubscription(c, subId); |
| 2744 | } finally { |
| 2745 | Binder.restoreCallingIdentity(token); |
| 2746 | } |
| 2747 | } |
| 2748 | |
| 2749 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2750 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2751 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2752 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2753 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2754 | } |
| 2755 | Binder.withCleanCallingIdentity(() -> { |
| 2756 | try { |
| 2757 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2758 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2759 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2760 | } catch (IllegalArgumentException e) { |
| 2761 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2762 | + "is inactive, ignoring unregister."); |
| 2763 | // If the subscription is no longer active, just return, since the callback |
| 2764 | // will already have been removed internally. |
| 2765 | } |
| 2766 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2770 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2771 | throws RemoteException { |
| 2772 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2773 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2774 | final long token = Binder.clearCallingIdentity(); |
| 2775 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2776 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2777 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2778 | } finally { |
| 2779 | Binder.restoreCallingIdentity(token); |
| 2780 | } |
| 2781 | } |
| 2782 | |
| 2783 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2784 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2785 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2786 | |
| 2787 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2788 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2789 | } |
| 2790 | Binder.withCleanCallingIdentity(() -> { |
| 2791 | try { |
| 2792 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2793 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2794 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2795 | } catch (IllegalArgumentException e) { |
| 2796 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2797 | + "is inactive, ignoring unregister."); |
| 2798 | // If the subscription is no longer active, just return, since the callback |
| 2799 | // will already have been removed internally. |
| 2800 | } |
| 2801 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2805 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2806 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2807 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2808 | final long token = Binder.clearCallingIdentity(); |
| 2809 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2810 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2811 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2812 | } catch (ImsException e) { |
| 2813 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2814 | return false; |
| 2815 | } finally { |
| 2816 | Binder.restoreCallingIdentity(token); |
| 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2821 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2822 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2823 | final long token = Binder.clearCallingIdentity(); |
| 2824 | try { |
| 2825 | Phone phone = getPhone(subId); |
| 2826 | if (phone == null) return false; |
| 2827 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2828 | } finally { |
| 2829 | Binder.restoreCallingIdentity(token); |
| 2830 | } |
| 2831 | } |
| 2832 | |
| 2833 | @Override |
| 2834 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2835 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2836 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2837 | final long token = Binder.clearCallingIdentity(); |
| 2838 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2839 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2840 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2841 | } finally { |
| 2842 | Binder.restoreCallingIdentity(token); |
| 2843 | } |
| 2844 | } |
| 2845 | |
| 2846 | @Override |
| 2847 | public void setAdvancedCallingSetting(int subId, boolean isEnabled) { |
| 2848 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2849 | "setAdvancedCallingSetting"); |
| 2850 | final long identity = Binder.clearCallingIdentity(); |
| 2851 | try { |
| 2852 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2853 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2854 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2855 | } finally { |
| 2856 | Binder.restoreCallingIdentity(identity); |
| 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2861 | public boolean isVtSettingEnabled(int subId) { |
| 2862 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2863 | final long identity = Binder.clearCallingIdentity(); |
| 2864 | try { |
| 2865 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2866 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2867 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2868 | } finally { |
| 2869 | Binder.restoreCallingIdentity(identity); |
| 2870 | } |
| 2871 | } |
| 2872 | |
| 2873 | @Override |
| 2874 | public void setVtSetting(int subId, boolean isEnabled) { |
| 2875 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2876 | "setVtSetting"); |
| 2877 | final long identity = Binder.clearCallingIdentity(); |
| 2878 | try { |
| 2879 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2880 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2881 | } finally { |
| 2882 | Binder.restoreCallingIdentity(identity); |
| 2883 | } |
| 2884 | } |
| 2885 | |
| 2886 | @Override |
| 2887 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2888 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2889 | final long identity = Binder.clearCallingIdentity(); |
| 2890 | try { |
| 2891 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2892 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2893 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2894 | } finally { |
| 2895 | Binder.restoreCallingIdentity(identity); |
| 2896 | } |
| 2897 | } |
| 2898 | |
| 2899 | @Override |
| 2900 | public void setVoWiFiSetting(int subId, boolean isEnabled) { |
| 2901 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2902 | "setVoWiFiSetting"); |
| 2903 | final long identity = Binder.clearCallingIdentity(); |
| 2904 | try { |
| 2905 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2906 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2907 | } finally { |
| 2908 | Binder.restoreCallingIdentity(identity); |
| 2909 | } |
| 2910 | } |
| 2911 | |
| 2912 | @Override |
| 2913 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2914 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2915 | final long identity = Binder.clearCallingIdentity(); |
| 2916 | try { |
| 2917 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2918 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2919 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 2920 | } finally { |
| 2921 | Binder.restoreCallingIdentity(identity); |
| 2922 | } |
| 2923 | } |
| 2924 | |
| 2925 | @Override |
| 2926 | public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) { |
| 2927 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2928 | "setVoWiFiRoamingSetting"); |
| 2929 | final long identity = Binder.clearCallingIdentity(); |
| 2930 | try { |
| 2931 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2932 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2933 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 2934 | } finally { |
| 2935 | Binder.restoreCallingIdentity(identity); |
| 2936 | } |
| 2937 | } |
| 2938 | |
| 2939 | @Override |
| 2940 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 2941 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2942 | "setVoWiFiNonPersistent"); |
| 2943 | final long identity = Binder.clearCallingIdentity(); |
| 2944 | try { |
| 2945 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2946 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2947 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
| 2948 | } finally { |
| 2949 | Binder.restoreCallingIdentity(identity); |
| 2950 | } |
| 2951 | } |
| 2952 | |
| 2953 | @Override |
| 2954 | public int getVoWiFiModeSetting(int subId) { |
| 2955 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 2956 | final long identity = Binder.clearCallingIdentity(); |
| 2957 | try { |
| 2958 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2959 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2960 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 2961 | } finally { |
| 2962 | Binder.restoreCallingIdentity(identity); |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | @Override |
| 2967 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 2968 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2969 | "setVoWiFiModeSetting"); |
| 2970 | final long identity = Binder.clearCallingIdentity(); |
| 2971 | try { |
| 2972 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2973 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2974 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 2975 | } finally { |
| 2976 | Binder.restoreCallingIdentity(identity); |
| 2977 | } |
| 2978 | } |
| 2979 | |
| 2980 | @Override |
| 2981 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 2982 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 2983 | final long identity = Binder.clearCallingIdentity(); |
| 2984 | try { |
| 2985 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2986 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2987 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 2988 | } finally { |
| 2989 | Binder.restoreCallingIdentity(identity); |
| 2990 | } |
| 2991 | } |
| 2992 | |
| 2993 | @Override |
| 2994 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 2995 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2996 | "setVoWiFiRoamingModeSetting"); |
| 2997 | final long identity = Binder.clearCallingIdentity(); |
| 2998 | try { |
| 2999 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3000 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3001 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3002 | } finally { |
| 3003 | Binder.restoreCallingIdentity(identity); |
| 3004 | } |
| 3005 | } |
| 3006 | |
| 3007 | @Override |
| 3008 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3009 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3010 | "setRttCapabilityEnabled"); |
| 3011 | final long identity = Binder.clearCallingIdentity(); |
| 3012 | try { |
| 3013 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3014 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3015 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3016 | } finally { |
| 3017 | Binder.restoreCallingIdentity(identity); |
| 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | @Override |
| 3022 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3023 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3024 | final long identity = Binder.clearCallingIdentity(); |
| 3025 | try { |
| 3026 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3027 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3028 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3029 | } finally { |
| 3030 | Binder.restoreCallingIdentity(identity); |
| 3031 | } |
| 3032 | } |
| 3033 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3034 | @Override |
| 3035 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3036 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3037 | final long identity = Binder.clearCallingIdentity(); |
| 3038 | try { |
| 3039 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3040 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3041 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3042 | } finally { |
| 3043 | Binder.restoreCallingIdentity(identity); |
| 3044 | } |
| 3045 | } |
| 3046 | |
| 3047 | @Override |
| 3048 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3049 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3050 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3051 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3052 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3053 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3054 | try { |
| 3055 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3056 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3057 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3058 | } catch (IllegalArgumentException e) { |
| 3059 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3060 | + "is inactive, ignoring unregister."); |
| 3061 | // If the subscription is no longer active, just return, since the callback will already |
| 3062 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3063 | } finally { |
| 3064 | Binder.restoreCallingIdentity(identity); |
| 3065 | } |
| 3066 | } |
| 3067 | |
| 3068 | @Override |
| 3069 | public int getImsProvisioningInt(int subId, int key) { |
| 3070 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3071 | final long identity = Binder.clearCallingIdentity(); |
| 3072 | try { |
| 3073 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3074 | return ImsManager.getInstance(mApp, |
| 3075 | getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3076 | } catch (ImsException e) { |
| 3077 | throw new IllegalArgumentException(e.getMessage()); |
| 3078 | } finally { |
| 3079 | Binder.restoreCallingIdentity(identity); |
| 3080 | } |
| 3081 | } |
| 3082 | |
| 3083 | @Override |
| 3084 | public String getImsProvisioningString(int subId, int key) { |
| 3085 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3086 | final long identity = Binder.clearCallingIdentity(); |
| 3087 | try { |
| 3088 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3089 | return ImsManager.getInstance(mApp, |
| 3090 | getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3091 | } catch (ImsException e) { |
| 3092 | throw new IllegalArgumentException(e.getMessage()); |
| 3093 | } finally { |
| 3094 | Binder.restoreCallingIdentity(identity); |
| 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | @Override |
| 3099 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3100 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3101 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3102 | final long identity = Binder.clearCallingIdentity(); |
| 3103 | try { |
| 3104 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3105 | return ImsManager.getInstance(mApp, |
| 3106 | getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3107 | } catch (ImsException e) { |
| 3108 | throw new IllegalArgumentException(e.getMessage()); |
| 3109 | } finally { |
| 3110 | Binder.restoreCallingIdentity(identity); |
| 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | @Override |
| 3115 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3116 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3117 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3118 | final long identity = Binder.clearCallingIdentity(); |
| 3119 | try { |
| 3120 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3121 | return ImsManager.getInstance(mApp, |
| 3122 | getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3123 | } catch (ImsException e) { |
| 3124 | throw new IllegalArgumentException(e.getMessage()); |
| 3125 | } finally { |
| 3126 | Binder.restoreCallingIdentity(identity); |
| 3127 | } |
| 3128 | } |
| 3129 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3130 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3131 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3132 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3133 | throw new IllegalArgumentException("Invalid Subscription Id."); |
| 3134 | } |
| 3135 | return slotId; |
| 3136 | } |
| 3137 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3138 | /** |
| 3139 | * Returns the network type for a subId |
| 3140 | */ |
| 3141 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3142 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3143 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3144 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3145 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3146 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3147 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3148 | final long identity = Binder.clearCallingIdentity(); |
| 3149 | try { |
| 3150 | final Phone phone = getPhone(subId); |
| 3151 | if (phone != null) { |
| 3152 | return phone.getServiceState().getDataNetworkType(); |
| 3153 | } else { |
| 3154 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3155 | } |
| 3156 | } finally { |
| 3157 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3158 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | /** |
| 3162 | * Returns the data network type |
| 3163 | */ |
| 3164 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3165 | public int getDataNetworkType(String callingPackage) { |
| 3166 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | /** |
| 3170 | * Returns the data network type for a subId |
| 3171 | */ |
| 3172 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3173 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3174 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3175 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3176 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3177 | } |
| 3178 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3179 | final long identity = Binder.clearCallingIdentity(); |
| 3180 | try { |
| 3181 | final Phone phone = getPhone(subId); |
| 3182 | if (phone != null) { |
| 3183 | return phone.getServiceState().getDataNetworkType(); |
| 3184 | } else { |
| 3185 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3186 | } |
| 3187 | } finally { |
| 3188 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3189 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3193 | * Returns the Voice network type for a subId |
| 3194 | */ |
| 3195 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3196 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3197 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3198 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3199 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3200 | } |
| 3201 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3202 | final long identity = Binder.clearCallingIdentity(); |
| 3203 | try { |
| 3204 | final Phone phone = getPhone(subId); |
| 3205 | if (phone != null) { |
| 3206 | return phone.getServiceState().getVoiceNetworkType(); |
| 3207 | } else { |
| 3208 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3209 | } |
| 3210 | } finally { |
| 3211 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3212 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | /** |
| 3216 | * @return true if a ICC card is present |
| 3217 | */ |
| 3218 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3219 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3220 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3221 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3225 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3226 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3227 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3228 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3229 | final long identity = Binder.clearCallingIdentity(); |
| 3230 | try { |
| 3231 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3232 | if (phone != null) { |
| 3233 | return phone.getIccCard().hasIccCard(); |
| 3234 | } else { |
| 3235 | return false; |
| 3236 | } |
| 3237 | } finally { |
| 3238 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3239 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | /** |
| 3243 | * Return if the current radio is LTE on CDMA. This |
| 3244 | * is a tri-state return value as for a period of time |
| 3245 | * the mode may be unknown. |
| 3246 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3247 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3248 | * @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] | 3249 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3250 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3251 | @Override |
| 3252 | public int getLteOnCdmaMode(String callingPackage) { |
| 3253 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3254 | } |
| 3255 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3256 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3257 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3258 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3259 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3260 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3261 | } |
| 3262 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3263 | final long identity = Binder.clearCallingIdentity(); |
| 3264 | try { |
| 3265 | final Phone phone = getPhone(subId); |
| 3266 | if (phone == null) { |
| 3267 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3268 | } else { |
| 3269 | return phone.getLteOnCdmaMode(); |
| 3270 | } |
| 3271 | } finally { |
| 3272 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3273 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3274 | } |
| 3275 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3276 | /** |
| 3277 | * {@hide} |
| 3278 | * Returns Default subId, 0 in the case of single standby. |
| 3279 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3280 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3281 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3282 | } |
| 3283 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3284 | private int getSlotForDefaultSubscription() { |
| 3285 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3286 | } |
| 3287 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3288 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3289 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3290 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3291 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3292 | private boolean isActiveSubscription(int subId) { |
| 3293 | return mSubscriptionController.isActiveSubId(subId); |
| 3294 | } |
| 3295 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3296 | /** |
| 3297 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3298 | */ |
| 3299 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3300 | final long identity = Binder.clearCallingIdentity(); |
| 3301 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3302 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3303 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3304 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3305 | } finally { |
| 3306 | Binder.restoreCallingIdentity(identity); |
| 3307 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3308 | } |
| 3309 | |
| 3310 | /** |
| 3311 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3312 | */ |
| 3313 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3314 | final long identity = Binder.clearCallingIdentity(); |
| 3315 | try { |
| 3316 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3317 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3318 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3319 | } finally { |
| 3320 | Binder.restoreCallingIdentity(identity); |
| 3321 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3322 | } |
| 3323 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3324 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3325 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3326 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3327 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3328 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3329 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3330 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3331 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3332 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3333 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3334 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3335 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3336 | final long identity = Binder.clearCallingIdentity(); |
| 3337 | try { |
| 3338 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3339 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3340 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3341 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3342 | if (bestComponent == null |
| 3343 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3344 | loge("The calling package is not allowed to access ISD-R."); |
| 3345 | throw new SecurityException( |
| 3346 | "The calling package is not allowed to access ISD-R."); |
| 3347 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3348 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3349 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3350 | if (DBG) { |
| 3351 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3352 | } |
| 3353 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| 3354 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
| 3355 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 3356 | return response; |
| 3357 | } finally { |
| 3358 | Binder.restoreCallingIdentity(identity); |
| 3359 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3363 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3364 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3365 | mApp, subId, "iccCloseLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3366 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3367 | final long identity = Binder.clearCallingIdentity(); |
| 3368 | try { |
| 3369 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3370 | if (channel < 0) { |
| 3371 | return false; |
| 3372 | } |
| 3373 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
| 3374 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 3375 | return success; |
| 3376 | } finally { |
| 3377 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3378 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3382 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3383 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3384 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3385 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3386 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3387 | final long identity = Binder.clearCallingIdentity(); |
| 3388 | try { |
| 3389 | if (DBG) { |
| 3390 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3391 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3392 | + p3 + " data=" + data); |
| 3393 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3394 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3395 | if (channel < 0) { |
| 3396 | return ""; |
| 3397 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3398 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3399 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| 3400 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
| 3401 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3402 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3403 | // Append the returned status code to the end of the response payload. |
| 3404 | String s = Integer.toHexString( |
| 3405 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3406 | if (response.payload != null) { |
| 3407 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3408 | } |
| 3409 | return s; |
| 3410 | } finally { |
| 3411 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3412 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3413 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3414 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3415 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3416 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3417 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3418 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3419 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3420 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3421 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3422 | final long identity = Binder.clearCallingIdentity(); |
| 3423 | try { |
| 3424 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3425 | && TextUtils.equals(ISDR_AID, data)) { |
| 3426 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3427 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3428 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3429 | if (bestComponent == null |
| 3430 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3431 | loge("The calling package is not allowed to select ISD-R."); |
| 3432 | throw new SecurityException( |
| 3433 | "The calling package is not allowed to select ISD-R."); |
| 3434 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3435 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3436 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3437 | if (DBG) { |
| 3438 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3439 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3440 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3441 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3442 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 3443 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
| 3444 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3445 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3446 | // Append the returned status code to the end of the response payload. |
| 3447 | String s = Integer.toHexString( |
| 3448 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3449 | if (response.payload != null) { |
| 3450 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3451 | } |
| 3452 | return s; |
| 3453 | } finally { |
| 3454 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3455 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3459 | 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] | 3460 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3461 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3462 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3463 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3464 | final long identity = Binder.clearCallingIdentity(); |
| 3465 | try { |
| 3466 | if (DBG) { |
| 3467 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3468 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3469 | } |
| 3470 | |
| 3471 | IccIoResult response = |
| 3472 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3473 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3474 | subId); |
| 3475 | |
| 3476 | if (DBG) { |
| 3477 | log("Exchange SIM_IO [R]" + response); |
| 3478 | } |
| 3479 | |
| 3480 | byte[] result = null; |
| 3481 | int length = 2; |
| 3482 | if (response.payload != null) { |
| 3483 | length = 2 + response.payload.length; |
| 3484 | result = new byte[length]; |
| 3485 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3486 | } else { |
| 3487 | result = new byte[length]; |
| 3488 | } |
| 3489 | |
| 3490 | result[length - 1] = (byte) response.sw2; |
| 3491 | result[length - 2] = (byte) response.sw1; |
| 3492 | return result; |
| 3493 | } finally { |
| 3494 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3495 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3496 | } |
| 3497 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3498 | /** |
| 3499 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3500 | * on a particular subscription |
| 3501 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3502 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3503 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3504 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3505 | return null; |
| 3506 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3507 | |
| 3508 | final long identity = Binder.clearCallingIdentity(); |
| 3509 | try { |
| 3510 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3511 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3512 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3513 | return null; |
| 3514 | } |
| 3515 | Object response = sendRequest( |
| 3516 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3517 | if (response instanceof String[]) { |
| 3518 | return (String[]) response; |
| 3519 | } |
| 3520 | // Response is an Exception of some kind, |
| 3521 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3522 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3523 | } finally { |
| 3524 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3525 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3526 | } |
| 3527 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3528 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3529 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3530 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3531 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3532 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3533 | final long identity = Binder.clearCallingIdentity(); |
| 3534 | try { |
| 3535 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3536 | if (response.payload == null) { |
| 3537 | return ""; |
| 3538 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3539 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3540 | // Append the returned status code to the end of the response payload. |
| 3541 | String s = Integer.toHexString( |
| 3542 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3543 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3544 | return s; |
| 3545 | } finally { |
| 3546 | Binder.restoreCallingIdentity(identity); |
| 3547 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3548 | } |
| 3549 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3550 | /** |
| 3551 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3552 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3553 | * |
| 3554 | * @param itemID the ID of the item to read |
| 3555 | * @return the NV item as a String, or null on error. |
| 3556 | */ |
| 3557 | @Override |
| 3558 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3559 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3560 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3561 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3562 | |
| 3563 | final long identity = Binder.clearCallingIdentity(); |
| 3564 | try { |
| 3565 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3566 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3567 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 3568 | return value; |
| 3569 | } finally { |
| 3570 | Binder.restoreCallingIdentity(identity); |
| 3571 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3572 | } |
| 3573 | |
| 3574 | /** |
| 3575 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3576 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3577 | * |
| 3578 | * @param itemID the ID of the item to read |
| 3579 | * @param itemValue the value to write, as a String |
| 3580 | * @return true on success; false on any failure |
| 3581 | */ |
| 3582 | @Override |
| 3583 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3584 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3585 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3586 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3587 | |
| 3588 | final long identity = Binder.clearCallingIdentity(); |
| 3589 | try { |
| 3590 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 3591 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3592 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3593 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 3594 | return success; |
| 3595 | } finally { |
| 3596 | Binder.restoreCallingIdentity(identity); |
| 3597 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | /** |
| 3601 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 3602 | * Used for device configuration by some CDMA operators. |
| 3603 | * |
| 3604 | * @param preferredRoamingList byte array containing the new PRL |
| 3605 | * @return true on success; false on any failure |
| 3606 | */ |
| 3607 | @Override |
| 3608 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3609 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3610 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3611 | |
| 3612 | final long identity = Binder.clearCallingIdentity(); |
| 3613 | try { |
| 3614 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 3615 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 3616 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 3617 | return success; |
| 3618 | } finally { |
| 3619 | Binder.restoreCallingIdentity(identity); |
| 3620 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3624 | * 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] | 3625 | * Used for device configuration by some CDMA operators. |
| 3626 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3627 | * @param slotIndex - device slot. |
| 3628 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3629 | * @return true on success; false on any failure |
| 3630 | */ |
| 3631 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3632 | public boolean resetModemConfig(int slotIndex) { |
| 3633 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3634 | if (phone != null) { |
| 3635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3636 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3637 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3638 | final long identity = Binder.clearCallingIdentity(); |
| 3639 | try { |
| 3640 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 3641 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 3642 | return success; |
| 3643 | } finally { |
| 3644 | Binder.restoreCallingIdentity(identity); |
| 3645 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3646 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3647 | return false; |
| 3648 | } |
| 3649 | |
| 3650 | /** |
| 3651 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 3652 | * |
| 3653 | * @param slotIndex - device slot. |
| 3654 | * |
| 3655 | * @return true on success; false on any failure |
| 3656 | */ |
| 3657 | @Override |
| 3658 | public boolean rebootModem(int slotIndex) { |
| 3659 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3660 | if (phone != null) { |
| 3661 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3662 | mApp, phone.getSubId(), "rebootModem"); |
| 3663 | |
| 3664 | final long identity = Binder.clearCallingIdentity(); |
| 3665 | try { |
| 3666 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 3667 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 3668 | return success; |
| 3669 | } finally { |
| 3670 | Binder.restoreCallingIdentity(identity); |
| 3671 | } |
| 3672 | } |
| 3673 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3674 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3675 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3676 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3677 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3678 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3679 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3680 | return new String[0]; |
| 3681 | } |
| 3682 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3683 | final long identity = Binder.clearCallingIdentity(); |
| 3684 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3685 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3686 | } finally { |
| 3687 | Binder.restoreCallingIdentity(identity); |
| 3688 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3689 | } |
| 3690 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3691 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3692 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 3693 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3694 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3695 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3696 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3697 | |
| 3698 | final long identity = Binder.clearCallingIdentity(); |
| 3699 | try { |
| 3700 | PhoneFactory.getImsResolver().enableIms(slotId); |
| 3701 | } finally { |
| 3702 | Binder.restoreCallingIdentity(identity); |
| 3703 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3707 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 3708 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3709 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3710 | public void disableIms(int slotId) { |
| 3711 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3712 | |
| 3713 | final long identity = Binder.clearCallingIdentity(); |
| 3714 | try { |
| 3715 | PhoneFactory.getImsResolver().disableIms(slotId); |
| 3716 | } finally { |
| 3717 | Binder.restoreCallingIdentity(identity); |
| 3718 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | /** |
| 3722 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 3723 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 3724 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 3725 | */ |
| 3726 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3727 | IImsServiceFeatureCallback callback) { |
| 3728 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3729 | |
| 3730 | final long identity = Binder.clearCallingIdentity(); |
| 3731 | try { |
| 3732 | return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback); |
| 3733 | } finally { |
| 3734 | Binder.restoreCallingIdentity(identity); |
| 3735 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | /** |
| 3739 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 3740 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 3741 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 3742 | * listener for feature updates. |
| 3743 | */ |
| 3744 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 3745 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3746 | |
| 3747 | final long identity = Binder.clearCallingIdentity(); |
| 3748 | try { |
| 3749 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); |
| 3750 | } finally { |
| 3751 | Binder.restoreCallingIdentity(identity); |
| 3752 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3753 | } |
| 3754 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3755 | /** |
| 3756 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| 3757 | * specified. |
| 3758 | */ |
| 3759 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 3760 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3761 | |
| 3762 | final long identity = Binder.clearCallingIdentity(); |
| 3763 | try { |
| 3764 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); |
| 3765 | } finally { |
| 3766 | Binder.restoreCallingIdentity(identity); |
| 3767 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3768 | } |
| 3769 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3770 | /** |
| 3771 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| 3772 | * specified. |
| 3773 | */ |
| 3774 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 3775 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3776 | |
| 3777 | final long identity = Binder.clearCallingIdentity(); |
| 3778 | try { |
| 3779 | return PhoneFactory.getImsResolver().getImsConfig(slotId, feature); |
| 3780 | } finally { |
| 3781 | Binder.restoreCallingIdentity(identity); |
| 3782 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3783 | } |
| 3784 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 3785 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3786 | * Sets the ImsService Package Name that Telephony will bind to. |
| 3787 | * |
| 3788 | * @param slotId the slot ID that the ImsService should bind for. |
| 3789 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 3790 | * ImsService is the device default ImsService. |
| 3791 | * @param packageName The package name of the application that contains the ImsService to bind |
| 3792 | * to. |
| 3793 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 3794 | * @hide |
| 3795 | */ |
| 3796 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3797 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3798 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3799 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3800 | "setImsService"); |
| 3801 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3802 | final long identity = Binder.clearCallingIdentity(); |
| 3803 | try { |
| 3804 | return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId, |
| 3805 | isCarrierImsService, packageName); |
| 3806 | } finally { |
| 3807 | Binder.restoreCallingIdentity(identity); |
| 3808 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | /** |
| 3812 | * Return the ImsService configuration. |
| 3813 | * |
| 3814 | * @param slotId The slot that the ImsService is associated with. |
| 3815 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 3816 | * the device default. |
| 3817 | * @return the package name of the ImsService configuration. |
| 3818 | */ |
| 3819 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3820 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3821 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3822 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3823 | "getImsService"); |
| 3824 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3825 | final long identity = Binder.clearCallingIdentity(); |
| 3826 | try { |
| 3827 | return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId, |
| 3828 | isCarrierImsService); |
| 3829 | } finally { |
| 3830 | Binder.restoreCallingIdentity(identity); |
| 3831 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3832 | } |
| 3833 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3834 | public void setImsRegistrationState(boolean registered) { |
| 3835 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3836 | |
| 3837 | final long identity = Binder.clearCallingIdentity(); |
| 3838 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3839 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3840 | } finally { |
| 3841 | Binder.restoreCallingIdentity(identity); |
| 3842 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3843 | } |
| 3844 | |
| 3845 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3846 | * Set the network selection mode to automatic. |
| 3847 | * |
| 3848 | */ |
| 3849 | @Override |
| 3850 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3851 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3852 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3853 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3854 | if (!isActiveSubscription(subId)) { |
| 3855 | return; |
| 3856 | } |
| 3857 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3858 | final long identity = Binder.clearCallingIdentity(); |
| 3859 | try { |
| 3860 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 3861 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 3862 | } finally { |
| 3863 | Binder.restoreCallingIdentity(identity); |
| 3864 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3865 | } |
| 3866 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3867 | /** |
| 3868 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 3869 | * |
| 3870 | * @param subId the id of the subscription. |
| 3871 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 3872 | * the operator to attach to. |
| 3873 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 3874 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 3875 | * normal network selection next time. |
| 3876 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3877 | */ |
| 3878 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3879 | public boolean setNetworkSelectionModeManual( |
| 3880 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3881 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3882 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3883 | |
| 3884 | if (!isActiveSubscription(subId)) { |
| 3885 | return false; |
| 3886 | } |
| 3887 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3888 | final long identity = Binder.clearCallingIdentity(); |
| 3889 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3890 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3891 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3892 | if (DBG) { |
| 3893 | log("setNetworkSelectionModeManual: subId: " + subId |
| 3894 | + " operator: " + operatorInfo); |
| 3895 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3896 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 3897 | } finally { |
| 3898 | Binder.restoreCallingIdentity(identity); |
| 3899 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | /** |
| 3903 | * Scans for available networks. |
| 3904 | */ |
| 3905 | @Override |
| 3906 | public CellNetworkScanResult getCellNetworkScanResults(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3907 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3908 | mApp, subId, "getCellNetworkScanResults"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3909 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3910 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3911 | try { |
| 3912 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3913 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3914 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3915 | } finally { |
| 3916 | Binder.restoreCallingIdentity(identity); |
| 3917 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3918 | } |
| 3919 | |
| 3920 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3921 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3922 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3923 | * @param subId id of the subscription |
| 3924 | * @param request contains the radio access networks with bands/channels to scan |
| 3925 | * @param messenger callback messenger for scan results or errors |
| 3926 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3927 | * @return the id of the requested scan which can be used to stop the scan. |
| 3928 | */ |
| 3929 | @Override |
| 3930 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
| 3931 | IBinder binder) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3932 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3933 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3934 | |
| 3935 | final long identity = Binder.clearCallingIdentity(); |
| 3936 | try { |
| 3937 | return mNetworkScanRequestTracker.startNetworkScan( |
| 3938 | request, messenger, binder, getPhone(subId)); |
| 3939 | } finally { |
| 3940 | Binder.restoreCallingIdentity(identity); |
| 3941 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3942 | } |
| 3943 | |
| 3944 | /** |
| 3945 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3946 | * |
| 3947 | * @param subId id of the subscription |
| 3948 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3949 | */ |
| 3950 | @Override |
| 3951 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3952 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3953 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3954 | |
| 3955 | final long identity = Binder.clearCallingIdentity(); |
| 3956 | try { |
| 3957 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 3958 | } finally { |
| 3959 | Binder.restoreCallingIdentity(identity); |
| 3960 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3961 | } |
| 3962 | |
| 3963 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3964 | * Get the calculated preferred network type. |
| 3965 | * Used for debugging incorrect network type. |
| 3966 | * |
| 3967 | * @return the preferred network type, defined in RILConstants.java. |
| 3968 | */ |
| 3969 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3970 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3971 | final Phone defaultPhone = getDefaultPhone(); |
| 3972 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 3973 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3974 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 3975 | } |
| 3976 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3977 | final long identity = Binder.clearCallingIdentity(); |
| 3978 | try { |
| 3979 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3980 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3981 | } finally { |
| 3982 | Binder.restoreCallingIdentity(identity); |
| 3983 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3984 | } |
| 3985 | |
| 3986 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3987 | * Get the preferred network type. |
| 3988 | * Used for device configuration by some CDMA operators. |
| 3989 | * |
| 3990 | * @return the preferred network type, defined in RILConstants.java. |
| 3991 | */ |
| 3992 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3993 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 3994 | TelephonyPermissions |
| 3995 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 3996 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3997 | |
| 3998 | final long identity = Binder.clearCallingIdentity(); |
| 3999 | try { |
| 4000 | if (DBG) log("getPreferredNetworkType"); |
| 4001 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4002 | int networkType = (result != null ? result[0] : -1); |
| 4003 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4004 | return networkType; |
| 4005 | } finally { |
| 4006 | Binder.restoreCallingIdentity(identity); |
| 4007 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | /** |
| 4011 | * Set the preferred network type. |
| 4012 | * Used for device configuration by some CDMA operators. |
| 4013 | * |
| 4014 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4015 | * @return true on success; false on any failure. |
| 4016 | */ |
| 4017 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4018 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4019 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4020 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4021 | |
| 4022 | final long identity = Binder.clearCallingIdentity(); |
| 4023 | try { |
| 4024 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4025 | Boolean success = (Boolean) sendRequest( |
| 4026 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4027 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4028 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4029 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4030 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4031 | } |
| 4032 | return success; |
| 4033 | } finally { |
| 4034 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4035 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4036 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4037 | |
| 4038 | /** |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4039 | * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning |
Jack Yu | 3cda1cd | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4040 | * SystemProperty to decide whether DUN APN is required for |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4041 | * tethering. |
| 4042 | * |
| 4043 | * @return 0: Not required. 1: required. 2: Not set. |
| 4044 | * @hide |
| 4045 | */ |
| 4046 | @Override |
| 4047 | public int getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4048 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4049 | |
| 4050 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4051 | final Phone defaultPhone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4052 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4053 | int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4054 | Settings.Global.TETHER_DUN_REQUIRED, 2); |
Jack Yu | 3cda1cd | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4055 | // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4056 | if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4057 | dunRequired = 1; |
| 4058 | } |
| 4059 | return dunRequired; |
| 4060 | } finally { |
| 4061 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4062 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4066 | * Set mobile data enabled |
| 4067 | * Used by the user through settings etc to turn on/off mobile data |
| 4068 | * |
| 4069 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4070 | */ |
| 4071 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4072 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4073 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4074 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4075 | |
| 4076 | final long identity = Binder.clearCallingIdentity(); |
| 4077 | try { |
| 4078 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4079 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4080 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4081 | if (phone != null) { |
| 4082 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4083 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4084 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4085 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4086 | } |
| 4087 | } finally { |
| 4088 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4089 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4093 | * Get the user enabled state of Mobile Data. |
| 4094 | * |
| 4095 | * TODO: remove and use isUserDataEnabled. |
| 4096 | * This can't be removed now because some vendor codes |
| 4097 | * calls through ITelephony directly while they should |
| 4098 | * use TelephonyManager. |
| 4099 | * |
| 4100 | * @return true on enabled |
| 4101 | */ |
| 4102 | @Override |
| 4103 | public boolean getDataEnabled(int subId) { |
| 4104 | return isUserDataEnabled(subId); |
| 4105 | } |
| 4106 | |
| 4107 | /** |
| 4108 | * Get whether mobile data is enabled per user setting. |
| 4109 | * |
| 4110 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4111 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4112 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4113 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4114 | * |
| 4115 | * @return {@code true} if data is enabled else {@code false} |
| 4116 | */ |
| 4117 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4118 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4119 | try { |
| 4120 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4121 | null); |
| 4122 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4123 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4124 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4125 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4126 | |
| 4127 | final long identity = Binder.clearCallingIdentity(); |
| 4128 | try { |
| 4129 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4130 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4131 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4132 | if (phone != null) { |
| 4133 | boolean retVal = phone.isUserDataEnabled(); |
| 4134 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4135 | return retVal; |
| 4136 | } else { |
| 4137 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4138 | return false; |
| 4139 | } |
| 4140 | } finally { |
| 4141 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4142 | } |
| 4143 | } |
| 4144 | |
| 4145 | /** |
| 4146 | * Get whether mobile data is enabled. |
| 4147 | * |
| 4148 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4149 | * whether mobile data is actually enabled. |
| 4150 | * |
| 4151 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4152 | * |
| 4153 | * @return {@code true} if data is enabled else {@code false} |
| 4154 | */ |
| 4155 | @Override |
| 4156 | public boolean isDataEnabled(int subId) { |
| 4157 | try { |
| 4158 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4159 | null); |
| 4160 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4161 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4162 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4163 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4164 | |
| 4165 | final long identity = Binder.clearCallingIdentity(); |
| 4166 | try { |
| 4167 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4168 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4169 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4170 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4171 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4172 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4173 | return retVal; |
| 4174 | } else { |
| 4175 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4176 | return false; |
| 4177 | } |
| 4178 | } finally { |
| 4179 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4180 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4181 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4182 | |
| 4183 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4184 | public int getCarrierPrivilegeStatus(int subId) { |
| 4185 | final Phone phone = getPhone(subId); |
| 4186 | if (phone == null) { |
| 4187 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4188 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4189 | } |
| 4190 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4191 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4192 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4193 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4194 | } |
| 4195 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4196 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4197 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4198 | |
| 4199 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4200 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4201 | final Phone phone = getPhone(subId); |
| 4202 | if (phone == null) { |
| 4203 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4204 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4205 | } |
| 4206 | UiccProfile profile = |
| 4207 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4208 | if (profile == null) { |
| 4209 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4210 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4211 | } |
| 4212 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4213 | } |
| 4214 | |
| 4215 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4216 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4217 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4218 | if (TextUtils.isEmpty(pkgName)) |
| 4219 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4220 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4221 | if (card == null) { |
| 4222 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4223 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4224 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4225 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4226 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4227 | } |
| 4228 | |
| 4229 | @Override |
| 4230 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4231 | if (TextUtils.isEmpty(pkgName)) |
| 4232 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4233 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4234 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4235 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4236 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4237 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4238 | continue; |
| 4239 | } |
| 4240 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4241 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4242 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4243 | break; |
| 4244 | } |
| 4245 | } |
| 4246 | |
| 4247 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4248 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4249 | |
| 4250 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4251 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4252 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4253 | loge("phoneId " + phoneId + " is not valid."); |
| 4254 | return null; |
| 4255 | } |
| 4256 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4257 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4258 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4259 | return null ; |
| 4260 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4261 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4262 | } |
| 4263 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4264 | @Override |
| 4265 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4266 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4267 | List<String> privilegedPackages = new ArrayList<>(); |
| 4268 | List<PackageInfo> packages = null; |
| 4269 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4270 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4271 | if (card == null) { |
| 4272 | // No UICC in that slot. |
| 4273 | continue; |
| 4274 | } |
| 4275 | if (card.hasCarrierPrivilegeRules()) { |
| 4276 | if (packages == null) { |
| 4277 | // Only check packages in user 0 for now |
| 4278 | packages = pm.getInstalledPackagesAsUser( |
| 4279 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4280 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4281 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4282 | } |
| 4283 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4284 | PackageInfo pkgInfo = packages.get(p); |
| 4285 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4286 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4287 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4288 | privilegedPackages.add(pkgInfo.packageName); |
| 4289 | } |
| 4290 | } |
| 4291 | } |
| 4292 | } |
| 4293 | return privilegedPackages; |
| 4294 | } |
| 4295 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4296 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4297 | final Phone phone = getPhone(subId); |
| 4298 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4299 | if (card == null) { |
| 4300 | loge("getIccId: No UICC"); |
| 4301 | return null; |
| 4302 | } |
| 4303 | String iccId = card.getIccId(); |
| 4304 | if (TextUtils.isEmpty(iccId)) { |
| 4305 | loge("getIccId: ICC ID is null or empty."); |
| 4306 | return null; |
| 4307 | } |
| 4308 | return iccId; |
| 4309 | } |
| 4310 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4311 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4312 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4313 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4314 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4315 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4316 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4317 | final long identity = Binder.clearCallingIdentity(); |
| 4318 | try { |
| 4319 | final String iccId = getIccId(subId); |
| 4320 | final Phone phone = getPhone(subId); |
| 4321 | if (phone == null) { |
| 4322 | return false; |
| 4323 | } |
| 4324 | final String subscriberId = phone.getSubscriberId(); |
| 4325 | |
| 4326 | if (DBG_MERGE) { |
| 4327 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4328 | + subscriberId + " to " + number); |
| 4329 | } |
| 4330 | |
| 4331 | if (TextUtils.isEmpty(iccId)) { |
| 4332 | return false; |
| 4333 | } |
| 4334 | |
| 4335 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4336 | |
| 4337 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4338 | if (alphaTag == null) { |
| 4339 | editor.remove(alphaTagPrefKey); |
| 4340 | } else { |
| 4341 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4342 | } |
| 4343 | |
| 4344 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4345 | // track all merged IMSIs based on line number |
| 4346 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4347 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4348 | if (number == null) { |
| 4349 | editor.remove(numberPrefKey); |
| 4350 | editor.remove(subscriberPrefKey); |
| 4351 | } else { |
| 4352 | editor.putString(numberPrefKey, number); |
| 4353 | editor.putString(subscriberPrefKey, subscriberId); |
| 4354 | } |
| 4355 | |
| 4356 | editor.commit(); |
| 4357 | return true; |
| 4358 | } finally { |
| 4359 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4360 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4364 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4365 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4366 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4367 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4368 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4369 | return null; |
| 4370 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4371 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4372 | final long identity = Binder.clearCallingIdentity(); |
| 4373 | try { |
| 4374 | String iccId = getIccId(subId); |
| 4375 | if (iccId != null) { |
| 4376 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4377 | if (DBG_MERGE) { |
| 4378 | log("getLine1NumberForDisplay returning " |
| 4379 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4380 | } |
| 4381 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4382 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4383 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4384 | return null; |
| 4385 | } finally { |
| 4386 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4387 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4391 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4392 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4393 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4394 | return null; |
| 4395 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4396 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4397 | final long identity = Binder.clearCallingIdentity(); |
| 4398 | try { |
| 4399 | String iccId = getIccId(subId); |
| 4400 | if (iccId != null) { |
| 4401 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4402 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4403 | } |
| 4404 | return null; |
| 4405 | } finally { |
| 4406 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4407 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4408 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4409 | |
| 4410 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4411 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4412 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4413 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4414 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4415 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4416 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4417 | return null; |
| 4418 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4419 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4420 | final long identity = Binder.clearCallingIdentity(); |
| 4421 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4422 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4423 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4424 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4425 | |
| 4426 | // Figure out what subscribers are currently active |
| 4427 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4428 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4429 | // the process, where TelephonyManager was instantiated. |
| 4430 | // Otherwise AppOps check will fail. |
| 4431 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4432 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4433 | for (int subId : subIds) { |
| 4434 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4435 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4436 | |
| 4437 | // First pass, find a number override for an active subscriber |
| 4438 | String mergeNumber = null; |
| 4439 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4440 | for (String key : prefs.keySet()) { |
| 4441 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4442 | final String subscriberId = (String) prefs.get(key); |
| 4443 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4444 | final String iccId = key.substring( |
| 4445 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4446 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4447 | mergeNumber = (String) prefs.get(numberKey); |
| 4448 | if (DBG_MERGE) { |
| 4449 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4450 | + " for active subscriber " + subscriberId); |
| 4451 | } |
| 4452 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4453 | break; |
| 4454 | } |
| 4455 | } |
| 4456 | } |
| 4457 | } |
| 4458 | |
| 4459 | // Shortcut when no active merged subscribers |
| 4460 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4461 | return null; |
| 4462 | } |
| 4463 | |
| 4464 | // Second pass, find all subscribers under that line override |
| 4465 | final ArraySet<String> result = new ArraySet<>(); |
| 4466 | for (String key : prefs.keySet()) { |
| 4467 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4468 | final String number = (String) prefs.get(key); |
| 4469 | if (mergeNumber.equals(number)) { |
| 4470 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4471 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4472 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4473 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4474 | result.add(subscriberId); |
| 4475 | } |
| 4476 | } |
| 4477 | } |
| 4478 | } |
| 4479 | |
| 4480 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4481 | Arrays.sort(resultArray); |
| 4482 | if (DBG_MERGE) { |
| 4483 | Slog.d(LOG_TAG, |
| 4484 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4485 | } |
| 4486 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4487 | } finally { |
| 4488 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4489 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4493 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4494 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4495 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4496 | |
| 4497 | final long identity = Binder.clearCallingIdentity(); |
| 4498 | try { |
| 4499 | final Phone phone = getPhone(subId); |
| 4500 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4501 | } finally { |
| 4502 | Binder.restoreCallingIdentity(identity); |
| 4503 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4504 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4505 | |
| 4506 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4507 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4508 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 4509 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4510 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4511 | |
| 4512 | final long identity = Binder.clearCallingIdentity(); |
| 4513 | try { |
| 4514 | final Phone phone = getPhone(subId); |
| 4515 | if (phone == null) { |
| 4516 | return false; |
| 4517 | } |
| 4518 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 4519 | cdmaNonRoamingList); |
| 4520 | } finally { |
| 4521 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4522 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4523 | } |
| 4524 | |
| 4525 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4526 | @Deprecated |
| 4527 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 4528 | enforceModifyPermission(); |
| 4529 | |
| 4530 | int returnValue = 0; |
| 4531 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4532 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4533 | if(result.exception == null) { |
| 4534 | if (result.result != null) { |
| 4535 | byte[] responseData = (byte[])(result.result); |
| 4536 | if(responseData.length > oemResp.length) { |
| 4537 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 4538 | responseData.length + "bytes. Buffer Size is " + |
| 4539 | oemResp.length + "bytes."); |
| 4540 | } |
| 4541 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 4542 | returnValue = responseData.length; |
| 4543 | } |
| 4544 | } else { |
| 4545 | CommandException ex = (CommandException) result.exception; |
| 4546 | returnValue = ex.getCommandError().ordinal(); |
| 4547 | if(returnValue > 0) returnValue *= -1; |
| 4548 | } |
| 4549 | } catch (RuntimeException e) { |
| 4550 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 4551 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 4552 | if(returnValue > 0) returnValue *= -1; |
| 4553 | } |
| 4554 | |
| 4555 | return returnValue; |
| 4556 | } |
| 4557 | |
| 4558 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4559 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 4560 | try { |
| 4561 | ProxyController.getInstance().setRadioCapability(rafs); |
| 4562 | } catch (RuntimeException e) { |
| 4563 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 4564 | } |
| 4565 | } |
| 4566 | |
| 4567 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4568 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4569 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4570 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4571 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4572 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4573 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4574 | final long identity = Binder.clearCallingIdentity(); |
| 4575 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4576 | TelephonyPermissions |
| 4577 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4578 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 4579 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4580 | } finally { |
| 4581 | Binder.restoreCallingIdentity(identity); |
| 4582 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4583 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4584 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4585 | |
| 4586 | @Override |
| 4587 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4588 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4589 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4590 | |
| 4591 | final long identity = Binder.clearCallingIdentity(); |
| 4592 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4593 | ImsManager.getInstance(defaultPhone.getContext(), |
| 4594 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4595 | } finally { |
| 4596 | Binder.restoreCallingIdentity(identity); |
| 4597 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4598 | } |
| 4599 | |
| 4600 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4601 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4602 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4603 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4604 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4605 | return false; |
| 4606 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4607 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4608 | final long identity = Binder.clearCallingIdentity(); |
| 4609 | try { |
| 4610 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 4611 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 4612 | // In the long run, we may instead need to check if there exists a connection service |
| 4613 | // which can support video calling. |
| 4614 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4615 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4616 | return imsManager.isVtEnabledByPlatform() |
| 4617 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 4618 | && imsManager.isVtEnabledByUser(); |
| 4619 | } finally { |
| 4620 | Binder.restoreCallingIdentity(identity); |
| 4621 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4622 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 4623 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4624 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4625 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 4626 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4627 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4628 | return false; |
| 4629 | } |
| 4630 | |
| 4631 | final long identity = Binder.clearCallingIdentity(); |
| 4632 | try { |
| 4633 | CarrierConfigManager configManager = |
| 4634 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4635 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4636 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 4637 | } finally { |
| 4638 | Binder.restoreCallingIdentity(identity); |
| 4639 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4640 | } |
| 4641 | |
| 4642 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4643 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 4644 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4645 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4646 | return false; |
| 4647 | } |
| 4648 | |
| 4649 | final long identity = Binder.clearCallingIdentity(); |
| 4650 | try { |
| 4651 | CarrierConfigManager configManager = |
| 4652 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4653 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4654 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 4655 | } finally { |
| 4656 | Binder.restoreCallingIdentity(identity); |
| 4657 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4658 | } |
| 4659 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4660 | @Override |
| 4661 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4662 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 4663 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4664 | } |
| 4665 | |
| 4666 | @Override |
| 4667 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4668 | final long identity = Binder.clearCallingIdentity(); |
| 4669 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4670 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4671 | } finally { |
| 4672 | Binder.restoreCallingIdentity(identity); |
| 4673 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4674 | } |
| 4675 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4676 | /** |
| 4677 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 4678 | * support for the feature and device firmware support. |
| 4679 | * |
| 4680 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 4681 | */ |
| 4682 | @Override |
| 4683 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4684 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4685 | final Phone phone = getPhone(subscriptionId); |
| 4686 | if (phone == null) { |
| 4687 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 4688 | return false; |
| 4689 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4690 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4691 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4692 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 4693 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4694 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4695 | return isCarrierSupported && isDeviceSupported; |
| 4696 | } finally { |
| 4697 | Binder.restoreCallingIdentity(identity); |
| 4698 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 4699 | } |
| 4700 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4701 | /** |
| 4702 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 4703 | * both also support RTT. |
| 4704 | */ |
| 4705 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4706 | final long identity = Binder.clearCallingIdentity(); |
| 4707 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4708 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4709 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4710 | } finally { |
| 4711 | Binder.restoreCallingIdentity(identity); |
| 4712 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 4713 | } |
| 4714 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4715 | /** |
| 4716 | * Returns the unique device ID of phone, for example, the IMEI for |
| 4717 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 4718 | * |
| 4719 | * <p>Requires Permission: |
| 4720 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 4721 | */ |
| 4722 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4723 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4724 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4725 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4726 | return null; |
| 4727 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4728 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 4729 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 4730 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4731 | return null; |
| 4732 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4733 | |
| 4734 | final long identity = Binder.clearCallingIdentity(); |
| 4735 | try { |
| 4736 | return phone.getDeviceId(); |
| 4737 | } finally { |
| 4738 | Binder.restoreCallingIdentity(identity); |
| 4739 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4740 | } |
| 4741 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4742 | /** |
| 4743 | * {@hide} |
| 4744 | * Returns the IMS Registration Status on a particular subid |
| 4745 | * |
| 4746 | * @param subId |
| 4747 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4748 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4749 | Phone phone = getPhone(subId); |
| 4750 | if (phone != null) { |
| 4751 | return phone.isImsRegistered(); |
| 4752 | } else { |
| 4753 | return false; |
| 4754 | } |
| 4755 | } |
| 4756 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4757 | @Override |
| 4758 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4759 | final long identity = Binder.clearCallingIdentity(); |
| 4760 | try { |
| 4761 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 4762 | } finally { |
| 4763 | Binder.restoreCallingIdentity(identity); |
| 4764 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4765 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 4766 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4767 | /** |
| 4768 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4769 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4770 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4771 | final long identity = Binder.clearCallingIdentity(); |
| 4772 | try { |
| 4773 | Phone phone = getPhone(subId); |
| 4774 | if (phone != null) { |
| 4775 | return phone.isWifiCallingEnabled(); |
| 4776 | } else { |
| 4777 | return false; |
| 4778 | } |
| 4779 | } finally { |
| 4780 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4781 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4782 | } |
| 4783 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4784 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4785 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4786 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4787 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4788 | final long identity = Binder.clearCallingIdentity(); |
| 4789 | try { |
| 4790 | Phone phone = getPhone(subId); |
| 4791 | if (phone != null) { |
| 4792 | return phone.isVideoEnabled(); |
| 4793 | } else { |
| 4794 | return false; |
| 4795 | } |
| 4796 | } finally { |
| 4797 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4798 | } |
| 4799 | } |
| 4800 | |
| 4801 | /** |
| 4802 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 4803 | * defined in {@link ImsRegistrationImplBase}. |
| 4804 | */ |
| 4805 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4806 | final long identity = Binder.clearCallingIdentity(); |
| 4807 | try { |
| 4808 | Phone phone = getPhone(subId); |
| 4809 | if (phone != null) { |
| 4810 | return phone.getImsRegistrationTech(); |
| 4811 | } else { |
| 4812 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 4813 | } |
| 4814 | } finally { |
| 4815 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4816 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4817 | } |
| 4818 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4819 | @Override |
| 4820 | public void factoryReset(int subId) { |
| 4821 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4822 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 4823 | return; |
| 4824 | } |
| 4825 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4826 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4827 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4828 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4829 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 4830 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4831 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4832 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4833 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4834 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 4835 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4836 | } |
| 4837 | } finally { |
| 4838 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4839 | } |
| 4840 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4841 | |
| 4842 | @Override |
| 4843 | public String getLocaleFromDefaultSim() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4844 | final long identity = Binder.clearCallingIdentity(); |
| 4845 | try { |
| 4846 | // We query all subscriptions instead of just the active ones, because |
| 4847 | // this might be called early on in the provisioning flow when the |
| 4848 | // subscriptions potentially aren't active yet. |
| 4849 | final List<SubscriptionInfo> slist = getAllSubscriptionInfoList(); |
| 4850 | if (slist == null || slist.isEmpty()) { |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4851 | return null; |
| 4852 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4853 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4854 | // This function may be called very early, say, from the setup wizard, at |
| 4855 | // which point we won't have a default subscription set. If that's the case |
| 4856 | // we just choose the first, which will be valid in "most cases". |
| 4857 | final int defaultSubId = getDefaultSubscription(); |
| 4858 | SubscriptionInfo info = null; |
| 4859 | if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 4860 | info = slist.get(0); |
| 4861 | } else { |
| 4862 | for (SubscriptionInfo item : slist) { |
| 4863 | if (item.getSubscriptionId() == defaultSubId) { |
| 4864 | info = item; |
| 4865 | break; |
| 4866 | } |
| 4867 | } |
| 4868 | |
| 4869 | if (info == null) { |
| 4870 | return null; |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 4871 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4872 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4873 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4874 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 4875 | // preferences (EF-PL and EF-LI)... |
| 4876 | final int mcc = info.getMcc(); |
| 4877 | final Phone defaultPhone = getPhone(info.getSubscriptionId()); |
| 4878 | String simLanguage = null; |
| 4879 | if (defaultPhone != null) { |
| 4880 | final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs(); |
| 4881 | if (localeFromDefaultSim != null) { |
| 4882 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 4883 | if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim); |
| 4884 | return localeFromDefaultSim.toLanguageTag(); |
| 4885 | } else { |
| 4886 | simLanguage = localeFromDefaultSim.getLanguage(); |
| 4887 | } |
| 4888 | } |
| 4889 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4890 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4891 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 4892 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 4893 | // the SIM and carrier preferences does not include a country we add the country |
| 4894 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4895 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4896 | if (mccLocale != null) { |
| 4897 | if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale); |
| 4898 | return mccLocale.toLanguageTag(); |
| 4899 | } |
| 4900 | |
| 4901 | if (DBG) log("No locale found - returning null"); |
| 4902 | return null; |
| 4903 | } finally { |
| 4904 | Binder.restoreCallingIdentity(identity); |
| 4905 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4909 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4910 | } |
| 4911 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4912 | /** |
| 4913 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 4914 | */ |
| 4915 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4916 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4917 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4918 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4919 | private final ModemActivityInfo mLastModemActivityInfo = |
| 4920 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 4921 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4922 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4923 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 4924 | * representing the state of the modem. |
| 4925 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4926 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 4927 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4928 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4929 | */ |
| 4930 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4931 | public void requestModemActivityInfo(ResultReceiver result) { |
| 4932 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4933 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4934 | |
| 4935 | final long identity = Binder.clearCallingIdentity(); |
| 4936 | try { |
| 4937 | ModemActivityInfo ret = null; |
| 4938 | synchronized (mLastModemActivityInfo) { |
| 4939 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 4940 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4941 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 4942 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4943 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 4944 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4945 | mergedTxTimeMs[i] = info.getTxTimeMillis()[i] |
| 4946 | + mLastModemActivityInfo.getTxTimeMillis()[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4947 | } |
| 4948 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4949 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 4950 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4951 | mLastModemActivityInfo.setIdleTimeMillis( |
| 4952 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 4953 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 4954 | mLastModemActivityInfo.setRxTimeMillis( |
| 4955 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 4956 | mLastModemActivityInfo.setEnergyUsed( |
| 4957 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4958 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4959 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 4960 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 4961 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 4962 | mLastModemActivityInfo.getTxTimeMillis(), |
| 4963 | mLastModemActivityInfo.getRxTimeMillis(), |
| 4964 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4965 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4966 | Bundle bundle = new Bundle(); |
| 4967 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 4968 | result.send(0, bundle); |
| 4969 | } finally { |
| 4970 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4971 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4972 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4973 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 4974 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 4975 | // less than total activity duration. |
| 4976 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 4977 | if (info == null) { |
| 4978 | return false; |
| 4979 | } |
| 4980 | int activityDurationMs = |
| 4981 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 4982 | int totalTxTimeMs = 0; |
| 4983 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 4984 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 4985 | } |
| 4986 | return (info.isValid() |
| 4987 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 4988 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 4989 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 4990 | && (totalTxTimeMs <= activityDurationMs)); |
| 4991 | } |
| 4992 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4993 | /** |
| 4994 | * {@hide} |
| 4995 | * Returns the service state information on specified subscription. |
| 4996 | */ |
| 4997 | @Override |
| 4998 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4999 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5000 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5001 | return null; |
| 5002 | } |
| 5003 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5004 | final long identity = Binder.clearCallingIdentity(); |
| 5005 | try { |
| 5006 | final Phone phone = getPhone(subId); |
| 5007 | if (phone == null) { |
| 5008 | return null; |
| 5009 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5010 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5011 | return phone.getServiceState(); |
| 5012 | } finally { |
| 5013 | Binder.restoreCallingIdentity(identity); |
| 5014 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5015 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5016 | |
| 5017 | /** |
| 5018 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5019 | * |
| 5020 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5021 | * voicemail ringtone. |
| 5022 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5023 | * PhoneAccount. |
| 5024 | */ |
| 5025 | @Override |
| 5026 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5027 | final long identity = Binder.clearCallingIdentity(); |
| 5028 | try { |
| 5029 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5030 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5031 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5032 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5033 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5034 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5035 | } finally { |
| 5036 | Binder.restoreCallingIdentity(identity); |
| 5037 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5041 | * Sets the per-account voicemail ringtone. |
| 5042 | * |
| 5043 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5044 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5045 | * |
| 5046 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5047 | * voicemail ringtone. |
| 5048 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5049 | * PhoneAccount. |
| 5050 | */ |
| 5051 | @Override |
| 5052 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5053 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5054 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5055 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5056 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5057 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5058 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5059 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5060 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5061 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5062 | |
| 5063 | final long identity = Binder.clearCallingIdentity(); |
| 5064 | try { |
| 5065 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5066 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5067 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5068 | } |
| 5069 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5070 | } finally { |
| 5071 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5072 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5073 | } |
| 5074 | |
| 5075 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5076 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5077 | * |
| 5078 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5079 | * voicemail vibration setting. |
| 5080 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5081 | */ |
| 5082 | @Override |
| 5083 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5084 | final long identity = Binder.clearCallingIdentity(); |
| 5085 | try { |
| 5086 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5087 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5088 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5089 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5090 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5091 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5092 | } finally { |
| 5093 | Binder.restoreCallingIdentity(identity); |
| 5094 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5095 | } |
| 5096 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5097 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5098 | * Sets the per-account voicemail vibration. |
| 5099 | * |
| 5100 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5101 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5102 | * |
| 5103 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5104 | * voicemail vibration setting. |
| 5105 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5106 | * specific PhoneAccount. |
| 5107 | */ |
| 5108 | @Override |
| 5109 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5110 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5111 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5112 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5113 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5114 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5115 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5116 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5117 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5118 | } |
| 5119 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5120 | final long identity = Binder.clearCallingIdentity(); |
| 5121 | try { |
| 5122 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5123 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5124 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5125 | } |
| 5126 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5127 | } finally { |
| 5128 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5129 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5130 | } |
| 5131 | |
| 5132 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5133 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5134 | * |
| 5135 | * @throws SecurityException if the caller does not have the required permission |
| 5136 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5137 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5138 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5139 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5140 | } |
| 5141 | |
| 5142 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5143 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5144 | * permission. |
| 5145 | * |
| 5146 | * @throws SecurityException if the caller does not have the required permission |
| 5147 | */ |
| 5148 | private void enforceSendSmsPermission() { |
| 5149 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5150 | } |
| 5151 | |
| 5152 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5153 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5154 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5155 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5156 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5157 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5158 | final long identity = Binder.clearCallingIdentity(); |
| 5159 | try { |
| 5160 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5161 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5162 | if (componentName == null) { |
| 5163 | throw new SecurityException( |
| 5164 | "Caller not current active visual voicemail package[null]"); |
| 5165 | } |
| 5166 | String vvmPackage = componentName.getPackageName(); |
| 5167 | if (!callingPackage.equals(vvmPackage)) { |
| 5168 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5169 | + vvmPackage + "]"); |
| 5170 | } |
| 5171 | } finally { |
| 5172 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5173 | } |
| 5174 | } |
| 5175 | |
| 5176 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5177 | * Return the application ID for the app type. |
| 5178 | * |
| 5179 | * @param subId the subscription ID that this request applies to. |
| 5180 | * @param appType the uicc app type. |
| 5181 | * @return Application ID for specificied app type, or null if no uicc. |
| 5182 | */ |
| 5183 | @Override |
| 5184 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5185 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5186 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5187 | |
| 5188 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5189 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5190 | if (phone == null) { |
| 5191 | return null; |
| 5192 | } |
| 5193 | String aid = null; |
| 5194 | try { |
| 5195 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5196 | .getApplicationByType(appType).getAid(); |
| 5197 | } catch (Exception e) { |
| 5198 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5199 | } |
| 5200 | return aid; |
| 5201 | } finally { |
| 5202 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5203 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5204 | } |
| 5205 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5206 | /** |
| 5207 | * Return the Electronic Serial Number. |
| 5208 | * |
| 5209 | * @param subId the subscription ID that this request applies to. |
| 5210 | * @return ESN or null if error. |
| 5211 | */ |
| 5212 | @Override |
| 5213 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5214 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5215 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5216 | |
| 5217 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5218 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5219 | if (phone == null) { |
| 5220 | return null; |
| 5221 | } |
| 5222 | String esn = null; |
| 5223 | try { |
| 5224 | esn = phone.getEsn(); |
| 5225 | } catch (Exception e) { |
| 5226 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5227 | } |
| 5228 | return esn; |
| 5229 | } finally { |
| 5230 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5231 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5232 | } |
| 5233 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5234 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5235 | * Return the Preferred Roaming List Version. |
| 5236 | * |
| 5237 | * @param subId the subscription ID that this request applies to. |
| 5238 | * @return PRLVersion or null if error. |
| 5239 | */ |
| 5240 | @Override |
| 5241 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5242 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5243 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5244 | |
| 5245 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5246 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | if (phone == null) { |
| 5248 | return null; |
| 5249 | } |
| 5250 | String cdmaPrlVersion = null; |
| 5251 | try { |
| 5252 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5253 | } catch (Exception e) { |
| 5254 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5255 | } |
| 5256 | return cdmaPrlVersion; |
| 5257 | } finally { |
| 5258 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5259 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5260 | } |
| 5261 | |
| 5262 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5263 | * Get snapshot of Telephony histograms |
| 5264 | * @return List of Telephony histograms |
| 5265 | * @hide |
| 5266 | */ |
| 5267 | @Override |
| 5268 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5269 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5270 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5271 | |
| 5272 | final long identity = Binder.clearCallingIdentity(); |
| 5273 | try { |
| 5274 | return RIL.getTelephonyRILTimingHistograms(); |
| 5275 | } finally { |
| 5276 | Binder.restoreCallingIdentity(identity); |
| 5277 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5278 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5279 | |
| 5280 | /** |
| 5281 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5282 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5283 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5284 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5285 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5286 | * @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] | 5287 | */ |
| 5288 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5289 | @TelephonyManager.SetCarrierRestrictionResult |
| 5290 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5291 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5292 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5293 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5294 | if (carrierRestrictionRules == null) { |
| 5295 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5296 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5297 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5298 | final long identity = Binder.clearCallingIdentity(); |
| 5299 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5300 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5301 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5302 | } finally { |
| 5303 | Binder.restoreCallingIdentity(identity); |
| 5304 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | /** |
| 5308 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5309 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5310 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5311 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5312 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5313 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5314 | */ |
| 5315 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5316 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5317 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5318 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5319 | |
| 5320 | final long identity = Binder.clearCallingIdentity(); |
| 5321 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5322 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5323 | if (response instanceof CarrierRestrictionRules) { |
| 5324 | return (CarrierRestrictionRules) response; |
| 5325 | } |
| 5326 | // Response is an Exception of some kind, |
| 5327 | // which is signalled to the user as a NULL retval |
| 5328 | return null; |
| 5329 | } catch (Exception e) { |
| 5330 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5331 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5332 | } finally { |
| 5333 | Binder.restoreCallingIdentity(identity); |
| 5334 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5335 | } |
| 5336 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5337 | /** |
| 5338 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5339 | * @param subId the subscription ID that this action applies to. |
| 5340 | * @param enabled control enable or disable metered apns. |
| 5341 | * {@hide} |
| 5342 | */ |
| 5343 | @Override |
| 5344 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5345 | enforceModifyPermission(); |
| 5346 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5347 | |
| 5348 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5349 | if (phone == null) { |
| 5350 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5351 | return; |
| 5352 | } |
| 5353 | try { |
| 5354 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5355 | } catch (Exception e) { |
| 5356 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5357 | } finally { |
| 5358 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5359 | } |
| 5360 | } |
| 5361 | |
| 5362 | /** |
| 5363 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5364 | * @param subId the subscription ID that this action applies to. |
| 5365 | * @param enabled control enable or disable radio. |
| 5366 | * {@hide} |
| 5367 | */ |
| 5368 | @Override |
| 5369 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5370 | enforceModifyPermission(); |
| 5371 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5372 | |
| 5373 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5374 | if (phone == null) { |
| 5375 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5376 | return; |
| 5377 | } |
| 5378 | try { |
| 5379 | phone.carrierActionSetRadioEnabled(enabled); |
| 5380 | } catch (Exception e) { |
| 5381 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5382 | } finally { |
| 5383 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5384 | } |
| 5385 | } |
| 5386 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5387 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5388 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5389 | * network status based on which carrier apps could apply actions accordingly, |
| 5390 | * enable/disable default url handler for example. |
| 5391 | * |
| 5392 | * @param subId the subscription ID that this action applies to. |
| 5393 | * @param report control start/stop reporting the default network status. |
| 5394 | * {@hide} |
| 5395 | */ |
| 5396 | @Override |
| 5397 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5398 | enforceModifyPermission(); |
| 5399 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5400 | |
| 5401 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5402 | if (phone == null) { |
| 5403 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5404 | return; |
| 5405 | } |
| 5406 | try { |
| 5407 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5408 | } catch (Exception e) { |
| 5409 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5410 | } finally { |
| 5411 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5412 | } |
| 5413 | } |
| 5414 | |
| 5415 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 5416 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 5417 | * @param subId the subscription ID that this action applies to. |
| 5418 | * {@hide} |
| 5419 | */ |
| 5420 | @Override |
| 5421 | public void carrierActionResetAll(int subId) { |
| 5422 | enforceModifyPermission(); |
| 5423 | final Phone phone = getPhone(subId); |
| 5424 | if (phone == null) { |
| 5425 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 5426 | return; |
| 5427 | } |
| 5428 | try { |
| 5429 | phone.carrierActionResetAll(); |
| 5430 | } catch (Exception e) { |
| 5431 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 5432 | } |
| 5433 | } |
| 5434 | |
| 5435 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5436 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5437 | * bug report is being generated. |
| 5438 | */ |
| 5439 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5440 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5441 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5442 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5443 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5444 | + Binder.getCallingPid() |
| 5445 | + ", uid=" + Binder.getCallingUid() |
| 5446 | + "without permission " |
| 5447 | + android.Manifest.permission.DUMP); |
| 5448 | return; |
| 5449 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5450 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5451 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5452 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5453 | @Override |
| 5454 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5455 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5456 | throws RemoteException { |
| 5457 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5458 | } |
| 5459 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5460 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5461 | * Get aggregated video call data usage since boot. |
| 5462 | * |
| 5463 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5464 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5465 | * {@hide} |
| 5466 | */ |
| 5467 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5468 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5469 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5470 | null); |
| 5471 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5472 | final long identity = Binder.clearCallingIdentity(); |
| 5473 | try { |
| 5474 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5475 | // records the delta with the corresponding network identity. |
| 5476 | // We just return the total video call data usage snapshot since boot. |
| 5477 | Phone phone = getPhone(subId); |
| 5478 | if (phone != null) { |
| 5479 | return phone.getVtDataUsage(perUidStats); |
| 5480 | } |
| 5481 | return null; |
| 5482 | } finally { |
| 5483 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5484 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5485 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5486 | |
| 5487 | /** |
| 5488 | * Policy control of data connection. Usually used when data limit is passed. |
| 5489 | * @param enabled True if enabling the data, otherwise disabling. |
| 5490 | * @param subId Subscription index |
| 5491 | * {@hide} |
| 5492 | */ |
| 5493 | @Override |
| 5494 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 5495 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5496 | |
| 5497 | final long identity = Binder.clearCallingIdentity(); |
| 5498 | try { |
| 5499 | Phone phone = getPhone(subId); |
| 5500 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5501 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5502 | } |
| 5503 | } finally { |
| 5504 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5505 | } |
| 5506 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5507 | |
| 5508 | /** |
| 5509 | * Get Client request stats |
| 5510 | * @return List of Client Request Stats |
| 5511 | * @hide |
| 5512 | */ |
| 5513 | @Override |
| 5514 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5515 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5516 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5517 | return null; |
| 5518 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5519 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5520 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5521 | final long identity = Binder.clearCallingIdentity(); |
| 5522 | try { |
| 5523 | if (phone != null) { |
| 5524 | return phone.getClientRequestStats(); |
| 5525 | } |
| 5526 | |
| 5527 | return null; |
| 5528 | } finally { |
| 5529 | Binder.restoreCallingIdentity(identity); |
| 5530 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5531 | } |
| 5532 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5533 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5534 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5535 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5536 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5537 | |
| 5538 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5539 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5540 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5541 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5542 | * @param state State of SIM (power down, power up, pass through) |
| 5543 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 5544 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 5545 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5546 | * |
| 5547 | **/ |
| 5548 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5549 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5550 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5551 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5552 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5553 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5554 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5555 | final long identity = Binder.clearCallingIdentity(); |
| 5556 | try { |
| 5557 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5558 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5559 | } |
| 5560 | } finally { |
| 5561 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5562 | } |
| 5563 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5564 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5565 | private boolean isUssdApiAllowed(int subId) { |
| 5566 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5567 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5568 | if (configManager == null) { |
| 5569 | return false; |
| 5570 | } |
| 5571 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 5572 | if (pb == null) { |
| 5573 | return false; |
| 5574 | } |
| 5575 | return pb.getBoolean( |
| 5576 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 5577 | } |
| 5578 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5579 | /** |
| 5580 | * Check if phone is in emergency callback mode |
| 5581 | * @return true if phone is in emergency callback mode |
| 5582 | * @param subId sub id |
| 5583 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 5584 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5585 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5586 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5587 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5588 | |
| 5589 | final long identity = Binder.clearCallingIdentity(); |
| 5590 | try { |
| 5591 | if (phone != null) { |
| 5592 | return phone.isInEcm(); |
| 5593 | } else { |
| 5594 | return false; |
| 5595 | } |
| 5596 | } finally { |
| 5597 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5598 | } |
| 5599 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5600 | |
| 5601 | /** |
| 5602 | * Get the current signal strength information for the given subscription. |
| 5603 | * Because this information is not updated when the device is in a low power state |
| 5604 | * it should not be relied-upon to be current. |
| 5605 | * @param subId Subscription index |
| 5606 | * @return the most recent cached signal strength info from the modem |
| 5607 | */ |
| 5608 | @Override |
| 5609 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5610 | final long identity = Binder.clearCallingIdentity(); |
| 5611 | try { |
| 5612 | Phone p = getPhone(subId); |
| 5613 | if (p == null) { |
| 5614 | return null; |
| 5615 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5616 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5617 | return p.getSignalStrength(); |
| 5618 | } finally { |
| 5619 | Binder.restoreCallingIdentity(identity); |
| 5620 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5621 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5622 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5623 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 5624 | * Get the current modem radio state for the given slot. |
| 5625 | * @param slotIndex slot index. |
| 5626 | * @param callingPackage the name of the package making the call. |
| 5627 | * @return the current radio power state from the modem |
| 5628 | */ |
| 5629 | @Override |
| 5630 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 5631 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5632 | if (phone != null) { |
| 5633 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5634 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 5635 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5636 | } |
| 5637 | |
| 5638 | final long identity = Binder.clearCallingIdentity(); |
| 5639 | try { |
| 5640 | return phone.getRadioPowerState(); |
| 5641 | } finally { |
| 5642 | Binder.restoreCallingIdentity(identity); |
| 5643 | } |
| 5644 | } |
| 5645 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5646 | } |
| 5647 | |
| 5648 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5649 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 5650 | * |
| 5651 | * <p>Requires one of the following permissions: |
| 5652 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 5653 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 5654 | * privileges. |
| 5655 | * |
| 5656 | * @param subId subscription id |
| 5657 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 5658 | * {@code false}. |
| 5659 | */ |
| 5660 | @Override |
| 5661 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5662 | boolean isEnabled = false; |
| 5663 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5664 | try { |
| 5665 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5666 | null /* message */); |
| 5667 | Phone phone = getPhone(subId); |
| 5668 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5669 | } catch (Exception e) { |
| 5670 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5671 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5672 | } finally { |
| 5673 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5674 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5675 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5676 | } |
| 5677 | |
| 5678 | |
| 5679 | /** |
| 5680 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 5681 | * |
| 5682 | * <p> Requires permission: |
| 5683 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 5684 | * privileges. |
| 5685 | * |
| 5686 | * @param subId subscription id |
| 5687 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 5688 | */ |
| 5689 | @Override |
| 5690 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5691 | final long identity = Binder.clearCallingIdentity(); |
| 5692 | try { |
| 5693 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5694 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5695 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5696 | Phone phone = getPhone(subId); |
| 5697 | if (phone != null) { |
| 5698 | phone.setDataRoamingEnabled(isEnabled); |
| 5699 | } |
| 5700 | } finally { |
| 5701 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5702 | } |
| 5703 | } |
| 5704 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5705 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 5706 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 5707 | boolean isAllowed = true; |
| 5708 | final long identity = Binder.clearCallingIdentity(); |
| 5709 | try { |
| 5710 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5711 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 5712 | Phone phone = getPhone(subId); |
| 5713 | if (phone != null) { |
| 5714 | isAllowed = phone.isCspPlmnEnabled(); |
| 5715 | } |
| 5716 | } finally { |
| 5717 | Binder.restoreCallingIdentity(identity); |
| 5718 | } |
| 5719 | return isAllowed; |
| 5720 | } |
| 5721 | |
| 5722 | @Override |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 5723 | public UiccCardInfo[] getUiccCardsInfo() { |
| 5724 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
| 5725 | |
| 5726 | final long identity = Binder.clearCallingIdentity(); |
| 5727 | try { |
| 5728 | ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos(); |
| 5729 | return cards.toArray(new UiccCardInfo[cards.size()]); |
| 5730 | } finally { |
| 5731 | Binder.restoreCallingIdentity(identity); |
| 5732 | } |
| 5733 | } |
| 5734 | |
| 5735 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5736 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5737 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5738 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5739 | final long identity = Binder.clearCallingIdentity(); |
| 5740 | try { |
| 5741 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 5742 | if (slots == null) { |
| 5743 | Rlog.i(LOG_TAG, "slots is null."); |
| 5744 | return null; |
| 5745 | } |
| 5746 | |
| 5747 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 5748 | for (int i = 0; i < slots.length; i++) { |
| 5749 | UiccSlot slot = slots[i]; |
| 5750 | if (slot == null) { |
| 5751 | continue; |
| 5752 | } |
| 5753 | |
| 5754 | String cardId; |
| 5755 | UiccCard card = slot.getUiccCard(); |
| 5756 | if (card != null) { |
| 5757 | cardId = card.getCardId(); |
| 5758 | } else { |
| 5759 | cardId = slot.getIccId(); |
| 5760 | } |
| 5761 | |
| 5762 | int cardState = 0; |
| 5763 | switch (slot.getCardState()) { |
| 5764 | case CARDSTATE_ABSENT: |
| 5765 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 5766 | break; |
| 5767 | case CARDSTATE_PRESENT: |
| 5768 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 5769 | break; |
| 5770 | case CARDSTATE_ERROR: |
| 5771 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 5772 | break; |
| 5773 | case CARDSTATE_RESTRICTED: |
| 5774 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 5775 | break; |
| 5776 | default: |
| 5777 | break; |
| 5778 | |
| 5779 | } |
| 5780 | |
| 5781 | infos[i] = new UiccSlotInfo( |
| 5782 | slot.isActive(), |
| 5783 | slot.isEuicc(), |
| 5784 | cardId, |
| 5785 | cardState, |
| 5786 | slot.getPhoneId(), |
| 5787 | slot.isExtendedApduSupported()); |
| 5788 | } |
| 5789 | return infos; |
| 5790 | } finally { |
| 5791 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 5792 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | @Override |
| 5796 | public boolean switchSlots(int[] physicalSlots) { |
| 5797 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5798 | |
| 5799 | final long identity = Binder.clearCallingIdentity(); |
| 5800 | try { |
| 5801 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 5802 | } finally { |
| 5803 | Binder.restoreCallingIdentity(identity); |
| 5804 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5805 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5806 | |
| 5807 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 5808 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
| 5809 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5810 | mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) { |
| 5811 | return TelephonyManager.INVALID_CARD_ID; |
| 5812 | } |
| 5813 | |
| 5814 | final long identity = Binder.clearCallingIdentity(); |
| 5815 | try { |
| 5816 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 5817 | } finally { |
| 5818 | Binder.restoreCallingIdentity(identity); |
| 5819 | } |
| 5820 | } |
| 5821 | |
| 5822 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5823 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 5824 | enforceModifyPermission(); |
| 5825 | final Phone phone = getPhone(subId); |
| 5826 | if (phone == null) { |
| 5827 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 5828 | return; |
| 5829 | } |
| 5830 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5831 | final long identity = Binder.clearCallingIdentity(); |
| 5832 | try { |
| 5833 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 5834 | } finally { |
| 5835 | Binder.restoreCallingIdentity(identity); |
| 5836 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5837 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5838 | |
| 5839 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 5840 | * A test API to reload the UICC profile. |
| 5841 | * |
| 5842 | * <p>Requires that the calling app has permission |
| 5843 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5844 | * @hide |
| 5845 | */ |
| 5846 | @Override |
| 5847 | public void refreshUiccProfile(int subId) { |
| 5848 | enforceModifyPermission(); |
| 5849 | |
| 5850 | final long identity = Binder.clearCallingIdentity(); |
| 5851 | try { |
| 5852 | Phone phone = getPhone(subId); |
| 5853 | if (phone == null) { |
| 5854 | return; |
| 5855 | } |
| 5856 | UiccCard uiccCard = phone.getUiccCard(); |
| 5857 | if (uiccCard == null) { |
| 5858 | return; |
| 5859 | } |
| 5860 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 5861 | if (uiccProfile == null) { |
| 5862 | return; |
| 5863 | } |
| 5864 | uiccProfile.refresh(); |
| 5865 | } finally { |
| 5866 | Binder.restoreCallingIdentity(identity); |
| 5867 | } |
| 5868 | } |
| 5869 | |
| 5870 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5871 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 5872 | */ |
| 5873 | private boolean getDefaultDataEnabled() { |
| 5874 | return "true".equalsIgnoreCase( |
| 5875 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 5876 | } |
| 5877 | |
| 5878 | /** |
| 5879 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 5880 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 5881 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 5882 | */ |
| 5883 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 5884 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5885 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5886 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 5887 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 5888 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 5889 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 5890 | return isDataRoamingEnabled; |
| 5891 | } |
| 5892 | |
| 5893 | /** |
| 5894 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 5895 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 5896 | */ |
| 5897 | private int getDefaultNetworkType(int subId) { |
| 5898 | return Integer.parseInt( |
| 5899 | TelephonyManager.getTelephonyProperty( |
| 5900 | mSubscriptionController.getPhoneId(subId), |
| 5901 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 5902 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 5903 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5904 | |
| 5905 | @Override |
| 5906 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 5907 | gid1, String gid2, String plmn, String spn) { |
| 5908 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5909 | |
| 5910 | final long identity = Binder.clearCallingIdentity(); |
| 5911 | try { |
| 5912 | final Phone phone = getPhone(subId); |
| 5913 | if (phone == null) { |
| 5914 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 5915 | return; |
| 5916 | } |
| 5917 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 5918 | } finally { |
| 5919 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5920 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5921 | } |
| 5922 | |
| 5923 | @Override |
| 5924 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5925 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5926 | |
| 5927 | final long identity = Binder.clearCallingIdentity(); |
| 5928 | try { |
| 5929 | final Phone phone = getPhone(subId); |
| 5930 | if (phone == null) { |
| 5931 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 5932 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 5933 | } |
| 5934 | return phone.getCarrierIdListVersion(); |
| 5935 | } finally { |
| 5936 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5937 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5938 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 5939 | |
| 5940 | @Override |
| 5941 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 5942 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5943 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 5944 | return -1; |
| 5945 | } |
| 5946 | |
| 5947 | final long identity = Binder.clearCallingIdentity(); |
| 5948 | try { |
| 5949 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 5950 | } finally { |
| 5951 | Binder.restoreCallingIdentity(identity); |
| 5952 | } |
| 5953 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5954 | |
| 5955 | @Override |
| 5956 | public int getCdmaRoamingMode(int subId) { |
| 5957 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5958 | mApp, subId, "getCdmaRoamingMode"); |
| 5959 | |
| 5960 | final long identity = Binder.clearCallingIdentity(); |
| 5961 | try { |
| 5962 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 5963 | } finally { |
| 5964 | Binder.restoreCallingIdentity(identity); |
| 5965 | } |
| 5966 | } |
| 5967 | |
| 5968 | @Override |
| 5969 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 5970 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5971 | mApp, subId, "setCdmaRoamingMode"); |
| 5972 | |
| 5973 | final long identity = Binder.clearCallingIdentity(); |
| 5974 | try { |
| 5975 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 5976 | } finally { |
| 5977 | Binder.restoreCallingIdentity(identity); |
| 5978 | } |
| 5979 | } |
| 5980 | |
| 5981 | @Override |
| 5982 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 5983 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5984 | mApp, subId, "setCdmaSubscriptionMode"); |
| 5985 | |
| 5986 | final long identity = Binder.clearCallingIdentity(); |
| 5987 | try { |
| 5988 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 5989 | } finally { |
| 5990 | Binder.restoreCallingIdentity(identity); |
| 5991 | } |
| 5992 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 5993 | |
| 5994 | private void ensureUserRunning(int userId) { |
| 5995 | if (!mUserManager.isUserRunning(userId)) { |
| 5996 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 5997 | } |
| 5998 | } |
| 5999 | |
| 6000 | /** |
| 6001 | * Returns a list of SMS apps on a given user. |
| 6002 | * |
| 6003 | * Only the shell user (UID 2000 or 0) can call it. |
| 6004 | * Target user must be running. |
| 6005 | */ |
| 6006 | @Override |
| 6007 | public String[] getSmsApps(int userId) { |
| 6008 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6009 | ensureUserRunning(userId); |
| 6010 | |
| 6011 | final Collection<SmsApplicationData> apps = |
| 6012 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6013 | |
| 6014 | String[] ret = new String[apps.size()]; |
| 6015 | int i = 0; |
| 6016 | for (SmsApplicationData app : apps) { |
| 6017 | ret[i++] = app.mPackageName; |
| 6018 | } |
| 6019 | return ret; |
| 6020 | } |
| 6021 | |
| 6022 | /** |
| 6023 | * Returns the default SMS app package name on a given user. |
| 6024 | * |
| 6025 | * Only the shell user (UID 2000 or 0) can call it. |
| 6026 | * Target user must be running. |
| 6027 | */ |
| 6028 | @Override |
| 6029 | public String getDefaultSmsApp(int userId) { |
| 6030 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6031 | ensureUserRunning(userId); |
| 6032 | |
| 6033 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6034 | /* updateIfNeeded= */ true, userId); |
| 6035 | return cn == null ? null : cn.getPackageName(); |
| 6036 | } |
| 6037 | |
| 6038 | /** |
| 6039 | * Set a package as the default SMS app on a given user. |
| 6040 | * |
| 6041 | * Only the shell user (UID 2000 or 0) can call it. |
| 6042 | * Target user must be running. |
| 6043 | */ |
| 6044 | @Override |
| 6045 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6046 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6047 | ensureUserRunning(userId); |
| 6048 | |
| 6049 | boolean found = false; |
| 6050 | for (String pkg : getSmsApps(userId)) { |
| 6051 | if (TextUtils.equals(packageName, pkg)) { |
| 6052 | found = true; |
| 6053 | break; |
| 6054 | } |
| 6055 | } |
| 6056 | if (!found) { |
| 6057 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6058 | } |
| 6059 | |
| 6060 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6061 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6062 | |
| 6063 | @Override |
| 6064 | public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList( |
| 6065 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6066 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6067 | mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) { |
| 6068 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6069 | } |
| 6070 | final long identity = Binder.clearCallingIdentity(); |
| 6071 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6072 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6073 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6074 | if (phone.getEmergencyNumberTracker() != null |
| 6075 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6076 | emergencyNumberListInternal.put( |
| 6077 | phone.getSubId(), |
| 6078 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6079 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6080 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6081 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6082 | } finally { |
| 6083 | Binder.restoreCallingIdentity(identity); |
| 6084 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6085 | } |
| 6086 | |
| 6087 | @Override |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6088 | public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6089 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6090 | if (!exactMatch) { |
| 6091 | TelephonyPermissions |
| 6092 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6093 | mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6094 | } |
| 6095 | final long identity = Binder.clearCallingIdentity(); |
| 6096 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6097 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6098 | if (phone.getEmergencyNumberTracker() != null |
| 6099 | && phone.getEmergencyNumberTracker() != null) { |
| 6100 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6101 | number, exactMatch)) { |
| 6102 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6103 | } |
| 6104 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6105 | } |
| 6106 | return false; |
| 6107 | } finally { |
| 6108 | Binder.restoreCallingIdentity(identity); |
| 6109 | } |
| 6110 | } |
| 6111 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6112 | /** |
| 6113 | * Update emergency number list for test mode. |
| 6114 | */ |
| 6115 | @Override |
| 6116 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6117 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6118 | "updateEmergencyNumberListTestMode"); |
| 6119 | |
| 6120 | final long identity = Binder.clearCallingIdentity(); |
| 6121 | try { |
| 6122 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6123 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6124 | if (tracker != null) { |
| 6125 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6126 | } |
| 6127 | } |
| 6128 | } finally { |
| 6129 | Binder.restoreCallingIdentity(identity); |
| 6130 | } |
| 6131 | } |
| 6132 | |
| 6133 | /** |
| 6134 | * Get the full emergency number list for test mode. |
| 6135 | */ |
| 6136 | @Override |
| 6137 | public List<String> getEmergencyNumberListTestMode() { |
| 6138 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6139 | "getEmergencyNumberListTestMode"); |
| 6140 | |
| 6141 | final long identity = Binder.clearCallingIdentity(); |
| 6142 | try { |
| 6143 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6144 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6145 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6146 | if (tracker != null) { |
| 6147 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6148 | emergencyNumbers.add(num.getNumber()); |
| 6149 | } |
| 6150 | } |
| 6151 | } |
| 6152 | return new ArrayList<>(emergencyNumbers); |
| 6153 | } finally { |
| 6154 | Binder.restoreCallingIdentity(identity); |
| 6155 | } |
| 6156 | } |
| 6157 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6158 | @Override |
| 6159 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6160 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6161 | Phone phone = getPhone(subId); |
| 6162 | if (phone == null) { |
| 6163 | return null; |
| 6164 | } |
| 6165 | final long identity = Binder.clearCallingIdentity(); |
| 6166 | try { |
| 6167 | UiccProfile profile = UiccController.getInstance() |
| 6168 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6169 | if (profile != null) { |
| 6170 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6171 | } |
| 6172 | } finally { |
| 6173 | Binder.restoreCallingIdentity(identity); |
| 6174 | } |
| 6175 | return null; |
| 6176 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6177 | |
| 6178 | /** |
| 6179 | * Enable or disable a modem stack. |
| 6180 | */ |
| 6181 | @Override |
| 6182 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6183 | enforceModifyPermission(); |
| 6184 | |
| 6185 | final long identity = Binder.clearCallingIdentity(); |
| 6186 | try { |
| 6187 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6188 | if (phone == null) { |
| 6189 | return false; |
| 6190 | } else { |
| 6191 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6192 | } |
| 6193 | } finally { |
| 6194 | Binder.restoreCallingIdentity(identity); |
| 6195 | } |
| 6196 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6197 | } |