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; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 55 | import android.service.carrier.CarrierIdentifier; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 56 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 57 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 58 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 59 | import android.telephony.CarrierConfigManager; |
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; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 72 | import android.telephony.PhoneNumberUtils; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 73 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 74 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 76 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 77 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 78 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 79 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 80 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 81 | import android.telephony.TelephonyManager; |
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; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.euicc.EuiccConnector; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.uicc.IccIoResult; |
| 135 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 141 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 143 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 144 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 145 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 146 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 147 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 148 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 149 | import java.io.FileDescriptor; |
| 150 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 151 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 152 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 153 | import java.util.Arrays; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 154 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 155 | import java.util.HashMap; |
| 156 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 157 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 158 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 159 | import java.util.Map; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 160 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * Implementation of the ITelephony interface. |
| 164 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 165 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 166 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 167 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 168 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 169 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 170 | |
| 171 | // Message codes used with mMainThreadHandler |
| 172 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 173 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 174 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 175 | private static final int CMD_OPEN_CHANNEL = 9; |
| 176 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 177 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 178 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 179 | private static final int CMD_NV_READ_ITEM = 13; |
| 180 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 181 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 182 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 183 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 184 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 185 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 186 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 187 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 188 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 189 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 190 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 191 | private static final int CMD_SEND_ENVELOPE = 25; |
| 192 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 193 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 194 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 195 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 196 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 197 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 198 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 199 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 200 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 201 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 202 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 203 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 204 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 205 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 206 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 207 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 208 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 209 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 210 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 211 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 212 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 213 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 214 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 215 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 216 | private static final int CMD_SWITCH_SLOTS = 50; |
| 217 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 218 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 219 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 220 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 221 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 222 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 223 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 224 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 225 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 226 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 227 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 228 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 229 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 230 | private static final int CMD_MODEM_REBOOT = 64; |
| 231 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 232 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 233 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 234 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 235 | // Parameters of select command. |
| 236 | private static final int SELECT_COMMAND = 0xA4; |
| 237 | private static final int SELECT_P1 = 0x04; |
| 238 | private static final int SELECT_P2 = 0; |
| 239 | private static final int SELECT_P3 = 0x10; |
| 240 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 241 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 242 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 243 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 244 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 245 | /** The singleton instance. */ |
| 246 | private static PhoneInterfaceManager sInstance; |
| 247 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 248 | private PhoneGlobals mApp; |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 249 | private Phone mPhone; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 250 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 251 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 252 | private AppOpsManager mAppOps; |
| 253 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 254 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 255 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 256 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 257 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 258 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 259 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 260 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 261 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 262 | // The AID of ISD-R. |
| 263 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 264 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 265 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 266 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 267 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 268 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 269 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 270 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 271 | * A request object to use for transmitting data to an ICC. |
| 272 | */ |
| 273 | private static final class IccAPDUArgument { |
| 274 | public int channel, cla, command, p1, p2, p3; |
| 275 | public String data; |
| 276 | |
| 277 | public IccAPDUArgument(int channel, int cla, int command, |
| 278 | int p1, int p2, int p3, String data) { |
| 279 | this.channel = channel; |
| 280 | this.cla = cla; |
| 281 | this.command = command; |
| 282 | this.p1 = p1; |
| 283 | this.p2 = p2; |
| 284 | this.p3 = p3; |
| 285 | this.data = data; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 290 | * A request object to use for transmitting data to an ICC. |
| 291 | */ |
| 292 | private static final class ManualNetworkSelectionArgument { |
| 293 | public OperatorInfo operatorInfo; |
| 294 | public boolean persistSelection; |
| 295 | |
| 296 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 297 | this.operatorInfo = operatorInfo; |
| 298 | this.persistSelection = persistSelection; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 303 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 304 | * request after sending. The main thread will notify the request when it is complete. |
| 305 | */ |
| 306 | private static final class MainThreadRequest { |
| 307 | /** The argument to use for the request */ |
| 308 | public Object argument; |
| 309 | /** The result of the request that is run on the main thread */ |
| 310 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 311 | // The subscriber id that this request applies to. Defaults to |
| 312 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 313 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 314 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 315 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 316 | public Phone phone; |
| 317 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 318 | public WorkSource workSource; |
| 319 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 320 | public MainThreadRequest(Object argument) { |
| 321 | this.argument = argument; |
| 322 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 323 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 324 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 325 | this.argument = argument; |
| 326 | if (phone != null) { |
| 327 | this.phone = phone; |
| 328 | } |
| 329 | this.workSource = workSource; |
| 330 | } |
| 331 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 332 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 333 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 334 | if (subId != null) { |
| 335 | this.subId = subId; |
| 336 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 337 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 338 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 341 | private static final class IncomingThirdPartyCallArgs { |
| 342 | public final ComponentName component; |
| 343 | public final String callId; |
| 344 | public final String callerDisplayName; |
| 345 | |
| 346 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 347 | String callerDisplayName) { |
| 348 | this.component = component; |
| 349 | this.callId = callId; |
| 350 | this.callerDisplayName = callerDisplayName; |
| 351 | } |
| 352 | } |
| 353 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 354 | /** |
| 355 | * A handler that processes messages on the main thread in the phone process. Since many |
| 356 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 357 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 358 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 359 | * on, which will be notified when the operation completes and will contain the result of the |
| 360 | * request. |
| 361 | * |
| 362 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 363 | * note that request.result must be set to something non-null for the calling thread to |
| 364 | * unblock. |
| 365 | */ |
| 366 | private final class MainThreadHandler extends Handler { |
| 367 | @Override |
| 368 | public void handleMessage(Message msg) { |
| 369 | MainThreadRequest request; |
| 370 | Message onCompleted; |
| 371 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 372 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 373 | IccAPDUArgument iccArgument; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 374 | |
| 375 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 376 | case CMD_HANDLE_USSD_REQUEST: { |
| 377 | request = (MainThreadRequest) msg.obj; |
| 378 | final Phone phone = getPhoneFromRequest(request); |
| 379 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 380 | String ussdRequest = ussdObject.first; |
| 381 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 382 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 383 | if (!isUssdApiAllowed(request.subId)) { |
| 384 | // Carrier does not support use of this API, return failure. |
| 385 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 386 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 387 | Bundle returnData = new Bundle(); |
| 388 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 389 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 390 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 391 | request.result = true; |
| 392 | notifyRequester(request); |
| 393 | return; |
| 394 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 395 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 396 | try { |
| 397 | request.result = phone != null |
| 398 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 399 | } catch (CallStateException cse) { |
| 400 | request.result = false; |
| 401 | } |
| 402 | // Wake up the requesting thread |
| 403 | notifyRequester(request); |
| 404 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 407 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 408 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 409 | final Phone phone = getPhoneFromRequest(request); |
| 410 | request.result = phone != null ? |
| 411 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 412 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 413 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 414 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 415 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 416 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 417 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 418 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 419 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 420 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 421 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 422 | if (uiccCard == null) { |
| 423 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 424 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 425 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 426 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 427 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 428 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 429 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 430 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 431 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 432 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 433 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 434 | break; |
| 435 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 436 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 437 | ar = (AsyncResult) msg.obj; |
| 438 | request = (MainThreadRequest) ar.userObj; |
| 439 | if (ar.exception == null && ar.result != null) { |
| 440 | request.result = ar.result; |
| 441 | } else { |
| 442 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 443 | if (ar.result == null) { |
| 444 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 445 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 446 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 447 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 448 | } else { |
| 449 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 450 | } |
| 451 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 452 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 453 | break; |
| 454 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 455 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 456 | request = (MainThreadRequest) msg.obj; |
| 457 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 458 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 459 | if (uiccCard == null) { |
| 460 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 461 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 462 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 463 | } else { |
| 464 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 465 | request); |
| 466 | uiccCard.iccTransmitApduBasicChannel( |
| 467 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 468 | iccArgument.p3, iccArgument.data, onCompleted); |
| 469 | } |
| 470 | break; |
| 471 | |
| 472 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 473 | ar = (AsyncResult) msg.obj; |
| 474 | request = (MainThreadRequest) ar.userObj; |
| 475 | if (ar.exception == null && ar.result != null) { |
| 476 | request.result = ar.result; |
| 477 | } else { |
| 478 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 479 | if (ar.result == null) { |
| 480 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 481 | } else if (ar.exception instanceof CommandException) { |
| 482 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 483 | ar.exception); |
| 484 | } else { |
| 485 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 486 | } |
| 487 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 488 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 489 | break; |
| 490 | |
| 491 | case CMD_EXCHANGE_SIM_IO: |
| 492 | request = (MainThreadRequest) msg.obj; |
| 493 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 494 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 495 | if (uiccCard == null) { |
| 496 | loge("iccExchangeSimIO: No UICC"); |
| 497 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 498 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 499 | } else { |
| 500 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 501 | request); |
| 502 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 503 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 504 | iccArgument.data, onCompleted); |
| 505 | } |
| 506 | break; |
| 507 | |
| 508 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 509 | ar = (AsyncResult) msg.obj; |
| 510 | request = (MainThreadRequest) ar.userObj; |
| 511 | if (ar.exception == null && ar.result != null) { |
| 512 | request.result = ar.result; |
| 513 | } else { |
| 514 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 515 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 516 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 517 | break; |
| 518 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 519 | case CMD_SEND_ENVELOPE: |
| 520 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 521 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 522 | if (uiccCard == null) { |
| 523 | loge("sendEnvelopeWithStatus: No UICC"); |
| 524 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 525 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 526 | } else { |
| 527 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 528 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 529 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 530 | break; |
| 531 | |
| 532 | case EVENT_SEND_ENVELOPE_DONE: |
| 533 | ar = (AsyncResult) msg.obj; |
| 534 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 535 | if (ar.exception == null && ar.result != null) { |
| 536 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 537 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 538 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 539 | if (ar.result == null) { |
| 540 | loge("sendEnvelopeWithStatus: Empty response"); |
| 541 | } else if (ar.exception instanceof CommandException) { |
| 542 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 543 | ar.exception); |
| 544 | } else { |
| 545 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 546 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 547 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 548 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 549 | break; |
| 550 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 551 | case CMD_OPEN_CHANNEL: |
| 552 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 553 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 554 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 555 | if (uiccCard == null) { |
| 556 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 557 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 558 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 559 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 560 | } else { |
| 561 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 562 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 563 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 564 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 565 | break; |
| 566 | |
| 567 | case EVENT_OPEN_CHANNEL_DONE: |
| 568 | ar = (AsyncResult) msg.obj; |
| 569 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 570 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 571 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 572 | int[] result = (int[]) ar.result; |
| 573 | int channelId = result[0]; |
| 574 | byte[] selectResponse = null; |
| 575 | if (result.length > 1) { |
| 576 | selectResponse = new byte[result.length - 1]; |
| 577 | for (int i = 1; i < result.length; ++i) { |
| 578 | selectResponse[i - 1] = (byte) result[i]; |
| 579 | } |
| 580 | } |
| 581 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 582 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 583 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 584 | if (ar.result == null) { |
| 585 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 586 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 587 | if (ar.exception != null) { |
| 588 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 589 | } |
| 590 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 591 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 592 | if (ar.exception instanceof CommandException) { |
| 593 | CommandException.Error error = |
| 594 | ((CommandException) (ar.exception)).getCommandError(); |
| 595 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 596 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 597 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 598 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 602 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 603 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 604 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 605 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 606 | break; |
| 607 | |
| 608 | case CMD_CLOSE_CHANNEL: |
| 609 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 610 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 611 | if (uiccCard == null) { |
| 612 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 613 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 614 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 615 | } else { |
| 616 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 617 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 618 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 619 | break; |
| 620 | |
| 621 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 622 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 623 | break; |
| 624 | |
| 625 | case CMD_NV_READ_ITEM: |
| 626 | request = (MainThreadRequest) msg.obj; |
| 627 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 628 | mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 629 | break; |
| 630 | |
| 631 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 632 | ar = (AsyncResult) msg.obj; |
| 633 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 634 | if (ar.exception == null && ar.result != null) { |
| 635 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 637 | request.result = ""; |
| 638 | if (ar.result == null) { |
| 639 | loge("nvReadItem: Empty response"); |
| 640 | } else if (ar.exception instanceof CommandException) { |
| 641 | loge("nvReadItem: CommandException: " + |
| 642 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 643 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 644 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 645 | } |
| 646 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 647 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 648 | break; |
| 649 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 650 | case CMD_NV_WRITE_ITEM: |
| 651 | request = (MainThreadRequest) msg.obj; |
| 652 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 653 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 654 | mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 655 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 656 | break; |
| 657 | |
| 658 | case EVENT_NV_WRITE_ITEM_DONE: |
| 659 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 660 | break; |
| 661 | |
| 662 | case CMD_NV_WRITE_CDMA_PRL: |
| 663 | request = (MainThreadRequest) msg.obj; |
| 664 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 665 | mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 666 | break; |
| 667 | |
| 668 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 669 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 670 | break; |
| 671 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 672 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 673 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 674 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 675 | mPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 676 | break; |
| 677 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 678 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 679 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 680 | break; |
| 681 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 682 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 683 | request = (MainThreadRequest) msg.obj; |
| 684 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 685 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 686 | break; |
| 687 | |
| 688 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 689 | ar = (AsyncResult) msg.obj; |
| 690 | request = (MainThreadRequest) ar.userObj; |
| 691 | if (ar.exception == null && ar.result != null) { |
| 692 | request.result = ar.result; // Integer |
| 693 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 694 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 695 | if (ar.result == null) { |
| 696 | loge("getPreferredNetworkType: Empty response"); |
| 697 | } else if (ar.exception instanceof CommandException) { |
| 698 | loge("getPreferredNetworkType: CommandException: " + |
| 699 | ar.exception); |
| 700 | } else { |
| 701 | loge("getPreferredNetworkType: Unknown exception"); |
| 702 | } |
| 703 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 704 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 705 | break; |
| 706 | |
| 707 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 708 | request = (MainThreadRequest) msg.obj; |
| 709 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 710 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 711 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 712 | break; |
| 713 | |
| 714 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 715 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 716 | break; |
| 717 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 718 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 719 | request = (MainThreadRequest)msg.obj; |
| 720 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 721 | mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 722 | break; |
| 723 | |
| 724 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 725 | ar = (AsyncResult)msg.obj; |
| 726 | request = (MainThreadRequest)ar.userObj; |
| 727 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 728 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 729 | break; |
| 730 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 731 | case CMD_SET_VOICEMAIL_NUMBER: |
| 732 | request = (MainThreadRequest) msg.obj; |
| 733 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 734 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 735 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 736 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 737 | break; |
| 738 | |
| 739 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 740 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 741 | break; |
| 742 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 743 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 744 | request = (MainThreadRequest) msg.obj; |
| 745 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 746 | request); |
| 747 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 748 | break; |
| 749 | |
| 750 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 751 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 752 | break; |
| 753 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 754 | case CMD_PERFORM_NETWORK_SCAN: |
| 755 | request = (MainThreadRequest) msg.obj; |
| 756 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 757 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 758 | break; |
| 759 | |
| 760 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 761 | ar = (AsyncResult) msg.obj; |
| 762 | request = (MainThreadRequest) ar.userObj; |
| 763 | CellNetworkScanResult cellScanResult; |
| 764 | if (ar.exception == null && ar.result != null) { |
| 765 | cellScanResult = new CellNetworkScanResult( |
| 766 | CellNetworkScanResult.STATUS_SUCCESS, |
| 767 | (List<OperatorInfo>) ar.result); |
| 768 | } else { |
| 769 | if (ar.result == null) { |
| 770 | loge("getCellNetworkScanResults: Empty response"); |
| 771 | } |
| 772 | if (ar.exception != null) { |
| 773 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 774 | } |
| 775 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 776 | if (ar.exception instanceof CommandException) { |
| 777 | CommandException.Error error = |
| 778 | ((CommandException) (ar.exception)).getCommandError(); |
| 779 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 780 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 781 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 782 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 783 | } |
| 784 | } |
| 785 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 786 | } |
| 787 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 788 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 789 | break; |
| 790 | |
| 791 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 792 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 793 | ManualNetworkSelectionArgument selArg = |
| 794 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 795 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 796 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 797 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 798 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 799 | break; |
| 800 | |
| 801 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 802 | ar = (AsyncResult) msg.obj; |
| 803 | request = (MainThreadRequest) ar.userObj; |
| 804 | if (ar.exception == null) { |
| 805 | request.result = true; |
| 806 | } else { |
| 807 | request.result = false; |
| 808 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 809 | } |
| 810 | notifyRequester(request); |
| 811 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 812 | break; |
| 813 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 814 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 815 | request = (MainThreadRequest) msg.obj; |
| 816 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 817 | mPhone.getModemActivityInfo(onCompleted, request.workSource); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 818 | break; |
| 819 | |
| 820 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 821 | ar = (AsyncResult) msg.obj; |
| 822 | request = (MainThreadRequest) ar.userObj; |
| 823 | if (ar.exception == null && ar.result != null) { |
| 824 | request.result = ar.result; |
| 825 | } else { |
| 826 | if (ar.result == null) { |
| 827 | loge("queryModemActivityInfo: Empty response"); |
| 828 | } else if (ar.exception instanceof CommandException) { |
| 829 | loge("queryModemActivityInfo: CommandException: " + |
| 830 | ar.exception); |
| 831 | } else { |
| 832 | loge("queryModemActivityInfo: Unknown exception"); |
| 833 | } |
| 834 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 835 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 836 | if (request.result == null) { |
| 837 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 838 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 839 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 840 | break; |
| 841 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 842 | case CMD_SET_ALLOWED_CARRIERS: |
| 843 | request = (MainThreadRequest) msg.obj; |
| 844 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 845 | mPhone.setAllowedCarriers( |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 846 | (List<CarrierIdentifier>) request.argument, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 847 | onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 848 | break; |
| 849 | |
| 850 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 851 | ar = (AsyncResult) msg.obj; |
| 852 | request = (MainThreadRequest) ar.userObj; |
| 853 | if (ar.exception == null && ar.result != null) { |
| 854 | request.result = ar.result; |
| 855 | } else { |
| 856 | if (ar.result == null) { |
| 857 | loge("setAllowedCarriers: Empty response"); |
| 858 | } else if (ar.exception instanceof CommandException) { |
| 859 | loge("setAllowedCarriers: CommandException: " + |
| 860 | ar.exception); |
| 861 | } else { |
| 862 | loge("setAllowedCarriers: Unknown exception"); |
| 863 | } |
| 864 | } |
| 865 | // Result cannot be null. Return -1 on error. |
| 866 | if (request.result == null) { |
| 867 | request.result = new int[]{-1}; |
| 868 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 869 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 870 | break; |
| 871 | |
| 872 | case CMD_GET_ALLOWED_CARRIERS: |
| 873 | request = (MainThreadRequest) msg.obj; |
| 874 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 875 | mPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 876 | break; |
| 877 | |
| 878 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 879 | ar = (AsyncResult) msg.obj; |
| 880 | request = (MainThreadRequest) ar.userObj; |
| 881 | if (ar.exception == null && ar.result != null) { |
| 882 | request.result = ar.result; |
| 883 | } else { |
| 884 | if (ar.result == null) { |
| 885 | loge("getAllowedCarriers: Empty response"); |
| 886 | } else if (ar.exception instanceof CommandException) { |
| 887 | loge("getAllowedCarriers: CommandException: " + |
| 888 | ar.exception); |
| 889 | } else { |
| 890 | loge("getAllowedCarriers: Unknown exception"); |
| 891 | } |
| 892 | } |
| 893 | // Result cannot be null. Return empty list of CarrierIdentifier. |
| 894 | if (request.result == null) { |
| 895 | request.result = new ArrayList<CarrierIdentifier>(0); |
| 896 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 897 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 898 | break; |
| 899 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 900 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 901 | ar = (AsyncResult) msg.obj; |
| 902 | request = (MainThreadRequest) ar.userObj; |
| 903 | if (ar.exception == null && ar.result != null) { |
| 904 | request.result = ar.result; |
| 905 | } else { |
| 906 | request.result = new IllegalArgumentException( |
| 907 | "Failed to retrieve Forbidden Plmns"); |
| 908 | if (ar.result == null) { |
| 909 | loge("getForbiddenPlmns: Empty response"); |
| 910 | } else { |
| 911 | loge("getForbiddenPlmns: Unknown exception"); |
| 912 | } |
| 913 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 914 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 915 | break; |
| 916 | |
| 917 | case CMD_GET_FORBIDDEN_PLMNS: |
| 918 | request = (MainThreadRequest) msg.obj; |
| 919 | uiccCard = getUiccCardFromRequest(request); |
| 920 | if (uiccCard == null) { |
| 921 | loge("getForbiddenPlmns() UiccCard is null"); |
| 922 | request.result = new IllegalArgumentException( |
| 923 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 924 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 925 | break; |
| 926 | } |
| 927 | Integer appType = (Integer) request.argument; |
| 928 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 929 | if (uiccApp == null) { |
| 930 | loge("getForbiddenPlmns() no app with specified type -- " |
| 931 | + appType); |
| 932 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 933 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 934 | break; |
| 935 | } else { |
| 936 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 937 | + " specified type -- " + appType); |
| 938 | } |
| 939 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 940 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 941 | onCompleted); |
| 942 | break; |
| 943 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 944 | case CMD_SWITCH_SLOTS: |
| 945 | request = (MainThreadRequest) msg.obj; |
| 946 | int[] physicalSlots = (int[]) request.argument; |
| 947 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 948 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 949 | break; |
| 950 | |
| 951 | case EVENT_SWITCH_SLOTS_DONE: |
| 952 | ar = (AsyncResult) msg.obj; |
| 953 | request = (MainThreadRequest) ar.userObj; |
| 954 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 955 | notifyRequester(request); |
| 956 | break; |
| 957 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 958 | request = (MainThreadRequest) msg.obj; |
| 959 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 960 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 961 | break; |
| 962 | |
| 963 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 964 | ar = (AsyncResult) msg.obj; |
| 965 | request = (MainThreadRequest) ar.userObj; |
| 966 | if (ar.exception != null) { |
| 967 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 968 | } else { |
| 969 | int mode = ((int[]) ar.result)[0]; |
| 970 | if (mode == 0) { |
| 971 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 972 | } else { |
| 973 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 974 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 975 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 976 | notifyRequester(request); |
| 977 | break; |
| 978 | case CMD_GET_CDMA_ROAMING_MODE: |
| 979 | request = (MainThreadRequest) msg.obj; |
| 980 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 981 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 982 | break; |
| 983 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 984 | ar = (AsyncResult) msg.obj; |
| 985 | request = (MainThreadRequest) ar.userObj; |
| 986 | if (ar.exception != null) { |
| 987 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 988 | } else { |
| 989 | request.result = ((int[]) ar.result)[0]; |
| 990 | } |
| 991 | notifyRequester(request); |
| 992 | break; |
| 993 | case CMD_SET_CDMA_ROAMING_MODE: |
| 994 | request = (MainThreadRequest) msg.obj; |
| 995 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 996 | int mode = (int) request.argument; |
| 997 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 998 | break; |
| 999 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1000 | ar = (AsyncResult) msg.obj; |
| 1001 | request = (MainThreadRequest) ar.userObj; |
| 1002 | request.result = ar.exception == null; |
| 1003 | notifyRequester(request); |
| 1004 | break; |
| 1005 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1006 | request = (MainThreadRequest) msg.obj; |
| 1007 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1008 | int subscriptionMode = (int) request.argument; |
| 1009 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1010 | break; |
| 1011 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1012 | ar = (AsyncResult) msg.obj; |
| 1013 | request = (MainThreadRequest) ar.userObj; |
| 1014 | request.result = ar.exception == null; |
| 1015 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1016 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1017 | case CMD_GET_ALL_CELL_INFO: |
| 1018 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1019 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1020 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1021 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1022 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1023 | ar = (AsyncResult) msg.obj; |
| 1024 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1025 | // If a timeout occurs, the response will be null |
| 1026 | request.result = (ar.exception == null && ar.result != null) |
| 1027 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1028 | synchronized (request) { |
| 1029 | request.notifyAll(); |
| 1030 | } |
| 1031 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1032 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1033 | request = (MainThreadRequest) msg.obj; |
| 1034 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1035 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1036 | break; |
| 1037 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1038 | ar = (AsyncResult) msg.obj; |
| 1039 | request = (MainThreadRequest) ar.userObj; |
| 1040 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1041 | try { |
| 1042 | if (ar.exception != null) { |
| 1043 | // something went wrong... the response is null |
| 1044 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
| 1045 | cb.onCellInfo(null); |
| 1046 | } else if (ar.result == null) { |
| 1047 | // timeout occurred, so force the result to non-null "empty" |
| 1048 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
| 1049 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 1050 | } else { |
| 1051 | // use the result as returned |
| 1052 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1053 | } |
| 1054 | } catch (RemoteException re) { |
| 1055 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1056 | } |
| 1057 | break; |
| 1058 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1059 | request = (MainThreadRequest) msg.obj; |
| 1060 | WorkSource ws = (WorkSource) request.argument; |
| 1061 | Phone phone = getPhoneFromRequest(request); |
| 1062 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1063 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1064 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1065 | ar = (AsyncResult) msg.obj; |
| 1066 | request = (MainThreadRequest) ar.userObj; |
| 1067 | if (ar.exception == null) { |
| 1068 | request.result = ar.result; |
| 1069 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1070 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1071 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1072 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1073 | } |
| 1074 | |
| 1075 | synchronized (request) { |
| 1076 | request.notifyAll(); |
| 1077 | } |
| 1078 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1079 | case CMD_MODEM_REBOOT: |
| 1080 | request = (MainThreadRequest) msg.obj; |
| 1081 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1082 | mPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1083 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1084 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1085 | handleNullReturnEvent(msg, "rebootModem"); |
| 1086 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1087 | default: |
| 1088 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1089 | break; |
| 1090 | } |
| 1091 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1092 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1093 | private void notifyRequester(MainThreadRequest request) { |
| 1094 | synchronized (request) { |
| 1095 | request.notifyAll(); |
| 1096 | } |
| 1097 | } |
| 1098 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1099 | private void handleNullReturnEvent(Message msg, String command) { |
| 1100 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1101 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1102 | if (ar.exception == null) { |
| 1103 | request.result = true; |
| 1104 | } else { |
| 1105 | request.result = false; |
| 1106 | if (ar.exception instanceof CommandException) { |
| 1107 | loge(command + ": CommandException: " + ar.exception); |
| 1108 | } else { |
| 1109 | loge(command + ": Unknown exception"); |
| 1110 | } |
| 1111 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1112 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1113 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | /** |
| 1117 | * Posts the specified command to be executed on the main thread, |
| 1118 | * waits for the request to complete, and returns the result. |
| 1119 | * @see #sendRequestAsync |
| 1120 | */ |
| 1121 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1122 | return sendRequest( |
| 1123 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | /** |
| 1127 | * Posts the specified command to be executed on the main thread, |
| 1128 | * waits for the request to complete, and returns the result. |
| 1129 | * @see #sendRequestAsync |
| 1130 | */ |
| 1131 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1132 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1133 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | /** |
| 1137 | * Posts the specified command to be executed on the main thread, |
| 1138 | * waits for the request to complete, and returns the result. |
| 1139 | * @see #sendRequestAsync |
| 1140 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1141 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1142 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | /** |
| 1146 | * Posts the specified command to be executed on the main thread, |
| 1147 | * waits for the request to complete, and returns the result. |
| 1148 | * @see #sendRequestAsync |
| 1149 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1150 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1151 | return sendRequest(command, argument, subId, null, workSource); |
| 1152 | } |
| 1153 | |
| 1154 | /** |
| 1155 | * Posts the specified command to be executed on the main thread, |
| 1156 | * waits for the request to complete, and returns the result. |
| 1157 | * @see #sendRequestAsync |
| 1158 | */ |
| 1159 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1160 | return sendRequest( |
| 1161 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1162 | } |
| 1163 | |
| 1164 | /** |
| 1165 | * Posts the specified command to be executed on the main thread, |
| 1166 | * waits for the request to complete, and returns the result. |
| 1167 | * @see #sendRequestAsync |
| 1168 | */ |
| 1169 | private Object sendRequest( |
| 1170 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1171 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1172 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1173 | } |
| 1174 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1175 | MainThreadRequest request = null; |
| 1176 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1177 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1178 | } else if (phone != null) { |
| 1179 | request = new MainThreadRequest(argument, phone, workSource); |
| 1180 | } else { |
| 1181 | request = new MainThreadRequest(argument, subId, workSource); |
| 1182 | } |
| 1183 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1184 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1185 | msg.sendToTarget(); |
| 1186 | |
| 1187 | // Wait for the request to complete |
| 1188 | synchronized (request) { |
| 1189 | while (request.result == null) { |
| 1190 | try { |
| 1191 | request.wait(); |
| 1192 | } catch (InterruptedException e) { |
| 1193 | // Do nothing, go back and wait until the request is complete |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | return request.result; |
| 1198 | } |
| 1199 | |
| 1200 | /** |
| 1201 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1202 | * Posts the specified command to be executed on the main thread, and |
| 1203 | * returns immediately. |
| 1204 | * @see #sendRequest |
| 1205 | */ |
| 1206 | private void sendRequestAsync(int command) { |
| 1207 | mMainThreadHandler.sendEmptyMessage(command); |
| 1208 | } |
| 1209 | |
| 1210 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1211 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1212 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1213 | */ |
| 1214 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1215 | sendRequestAsync(command, argument, null, null); |
| 1216 | } |
| 1217 | |
| 1218 | /** |
| 1219 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1220 | * @see {@link #sendRequest(int,Object)} |
| 1221 | */ |
| 1222 | private void sendRequestAsync( |
| 1223 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1224 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1225 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1226 | msg.sendToTarget(); |
| 1227 | } |
| 1228 | |
| 1229 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1230 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1231 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1232 | */ |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1233 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1234 | synchronized (PhoneInterfaceManager.class) { |
| 1235 | if (sInstance == null) { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1236 | sInstance = new PhoneInterfaceManager(app, phone); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1237 | } else { |
| 1238 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1239 | } |
| 1240 | return sInstance; |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | /** Private constructor; @see init() */ |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1245 | private PhoneInterfaceManager(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1246 | mApp = app; |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1247 | mPhone = phone; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1248 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1249 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1250 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1251 | mMainThreadHandler = new MainThreadHandler(); |
Nazanin Bakhshi | a5509e9 | 2018-12-06 15:34:22 -0800 | [diff] [blame] | 1252 | mTelephonySharedPreferences = |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1253 | PreferenceManager.getDefaultSharedPreferences(mPhone.getContext()); |
| 1254 | mSubscriptionController = SubscriptionController.getInstance(); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1255 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1256 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1257 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1258 | publish(); |
| 1259 | } |
| 1260 | |
| 1261 | private void publish() { |
| 1262 | if (DBG) log("publish: " + this); |
| 1263 | |
| 1264 | ServiceManager.addService("phone", this); |
| 1265 | } |
| 1266 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1267 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1268 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1269 | ? mPhone : getPhone(request.subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1270 | } |
| 1271 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1272 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1273 | Phone phone = getPhoneFromRequest(request); |
| 1274 | return phone == null ? null : |
| 1275 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1276 | } |
| 1277 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1278 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1279 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1280 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1281 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1282 | |
| 1283 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1284 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1287 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1288 | if (DBG) log("dial: " + number); |
| 1289 | // No permission check needed here: This is just a wrapper around the |
| 1290 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1291 | // the UI before it does anything. |
| 1292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1293 | final long identity = Binder.clearCallingIdentity(); |
| 1294 | try { |
| 1295 | String url = createTelUrl(number); |
| 1296 | if (url == null) { |
| 1297 | return; |
| 1298 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1299 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1300 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1301 | PhoneConstants.State state = mCM.getState(subId); |
| 1302 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1303 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1304 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1305 | mApp.startActivity(intent); |
| 1306 | } |
| 1307 | } finally { |
| 1308 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1313 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1316 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1317 | if (DBG) log("call: " + number); |
| 1318 | |
| 1319 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1320 | // need to do a permission check since we're calling startActivity() |
| 1321 | // from the context of the phone app. |
| 1322 | enforceCallPermission(); |
| 1323 | |
| 1324 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1325 | != AppOpsManager.MODE_ALLOWED) { |
| 1326 | return; |
| 1327 | } |
| 1328 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1329 | final long identity = Binder.clearCallingIdentity(); |
| 1330 | try { |
| 1331 | String url = createTelUrl(number); |
| 1332 | if (url == null) { |
| 1333 | return; |
| 1334 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1335 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1336 | boolean isValid = false; |
| 1337 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1338 | if (slist != null) { |
| 1339 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1340 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1341 | isValid = true; |
| 1342 | break; |
| 1343 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1344 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1345 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1346 | if (!isValid) { |
| 1347 | return; |
| 1348 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1349 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1350 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1351 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1352 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1353 | mApp.startActivity(intent); |
| 1354 | } finally { |
| 1355 | Binder.restoreCallingIdentity(identity); |
| 1356 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1359 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1360 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1363 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1364 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1365 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1366 | } |
| 1367 | |
| 1368 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1369 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1372 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1373 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1374 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1375 | } |
| 1376 | |
| 1377 | /** {@hide} */ |
| 1378 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1379 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1382 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1383 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1384 | |
| 1385 | final long identity = Binder.clearCallingIdentity(); |
| 1386 | try { |
| 1387 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1388 | checkSimPin.start(); |
| 1389 | return checkSimPin.unlockSim(null, pin); |
| 1390 | } finally { |
| 1391 | Binder.restoreCallingIdentity(identity); |
| 1392 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1395 | /** {@hide} */ |
| 1396 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1397 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, 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[] supplyPukReportResultForSubscriber(int subId, String puk, 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 checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1406 | checkSimPuk.start(); |
| 1407 | return checkSimPuk.unlockSim(puk, pin); |
| 1408 | } finally { |
| 1409 | Binder.restoreCallingIdentity(identity); |
| 1410 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1414 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1415 | * a synchronous one. |
| 1416 | */ |
| 1417 | private static class UnlockSim extends Thread { |
| 1418 | |
| 1419 | private final IccCard mSimCard; |
| 1420 | |
| 1421 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1422 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1423 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1424 | |
| 1425 | // For replies from SimCard interface |
| 1426 | private Handler mHandler; |
| 1427 | |
| 1428 | // For async handler to identify request type |
| 1429 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1430 | |
| 1431 | public UnlockSim(IccCard simCard) { |
| 1432 | mSimCard = simCard; |
| 1433 | } |
| 1434 | |
| 1435 | @Override |
| 1436 | public void run() { |
| 1437 | Looper.prepare(); |
| 1438 | synchronized (UnlockSim.this) { |
| 1439 | mHandler = new Handler() { |
| 1440 | @Override |
| 1441 | public void handleMessage(Message msg) { |
| 1442 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1443 | switch (msg.what) { |
| 1444 | case SUPPLY_PIN_COMPLETE: |
| 1445 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1446 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1447 | mRetryCount = msg.arg1; |
| 1448 | if (ar.exception != null) { |
| 1449 | if (ar.exception instanceof CommandException && |
| 1450 | ((CommandException)(ar.exception)).getCommandError() |
| 1451 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1452 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1453 | } else { |
| 1454 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1455 | } |
| 1456 | } else { |
| 1457 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1458 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1459 | mDone = true; |
| 1460 | UnlockSim.this.notifyAll(); |
| 1461 | } |
| 1462 | break; |
| 1463 | } |
| 1464 | } |
| 1465 | }; |
| 1466 | UnlockSim.this.notifyAll(); |
| 1467 | } |
| 1468 | Looper.loop(); |
| 1469 | } |
| 1470 | |
| 1471 | /* |
| 1472 | * Use PIN or PUK to unlock SIM card |
| 1473 | * |
| 1474 | * If PUK is null, unlock SIM card with PIN |
| 1475 | * |
| 1476 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1477 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1478 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1479 | |
| 1480 | while (mHandler == null) { |
| 1481 | try { |
| 1482 | wait(); |
| 1483 | } catch (InterruptedException e) { |
| 1484 | Thread.currentThread().interrupt(); |
| 1485 | } |
| 1486 | } |
| 1487 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1488 | |
| 1489 | if (puk == null) { |
| 1490 | mSimCard.supplyPin(pin, callback); |
| 1491 | } else { |
| 1492 | mSimCard.supplyPuk(puk, pin, callback); |
| 1493 | } |
| 1494 | |
| 1495 | while (!mDone) { |
| 1496 | try { |
| 1497 | Log.d(LOG_TAG, "wait for done"); |
| 1498 | wait(); |
| 1499 | } catch (InterruptedException e) { |
| 1500 | // Restore the interrupted status |
| 1501 | Thread.currentThread().interrupt(); |
| 1502 | } |
| 1503 | } |
| 1504 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1505 | int[] resultArray = new int[2]; |
| 1506 | resultArray[0] = mResult; |
| 1507 | resultArray[1] = mRetryCount; |
| 1508 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1513 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1514 | |
| 1515 | } |
| 1516 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1517 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1518 | // No permission check needed here: this call is harmless, and it's |
| 1519 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1520 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1521 | final long identity = Binder.clearCallingIdentity(); |
| 1522 | try { |
| 1523 | final Phone phone = getPhone(subId); |
| 1524 | if (phone != null) { |
| 1525 | phone.updateServiceLocation(); |
| 1526 | } |
| 1527 | } finally { |
| 1528 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1529 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1532 | @Override |
| 1533 | public boolean isRadioOn(String callingPackage) { |
| 1534 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1535 | } |
| 1536 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1537 | @Override |
| 1538 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1539 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1540 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1541 | return false; |
| 1542 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1543 | |
| 1544 | final long identity = Binder.clearCallingIdentity(); |
| 1545 | try { |
| 1546 | return isRadioOnForSubscriber(subId); |
| 1547 | } finally { |
| 1548 | Binder.restoreCallingIdentity(identity); |
| 1549 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1553 | final long identity = Binder.clearCallingIdentity(); |
| 1554 | try { |
| 1555 | final Phone phone = getPhone(subId); |
| 1556 | if (phone != null) { |
| 1557 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1558 | } else { |
| 1559 | return false; |
| 1560 | } |
| 1561 | } finally { |
| 1562 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1563 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1567 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1568 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1569 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1570 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1571 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1572 | |
| 1573 | final long identity = Binder.clearCallingIdentity(); |
| 1574 | try { |
| 1575 | final Phone phone = getPhone(subId); |
| 1576 | if (phone != null) { |
| 1577 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1578 | } |
| 1579 | } finally { |
| 1580 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1581 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1585 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1588 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -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 | return false; |
| 1596 | } |
| 1597 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1598 | toggleRadioOnOffForSubscriber(subId); |
| 1599 | } |
| 1600 | return true; |
| 1601 | } finally { |
| 1602 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1603 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1604 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1605 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1606 | public boolean needMobileRadioShutdown() { |
| 1607 | /* |
| 1608 | * If any of the Radios are available, it will need to be |
| 1609 | * shutdown. So return true if any Radio is available. |
| 1610 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1611 | final long identity = Binder.clearCallingIdentity(); |
| 1612 | try { |
| 1613 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1614 | Phone phone = PhoneFactory.getPhone(i); |
| 1615 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1616 | } |
| 1617 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1618 | return false; |
| 1619 | } finally { |
| 1620 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1621 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1624 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1625 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1626 | enforceModifyPermission(); |
| 1627 | |
| 1628 | final long identity = Binder.clearCallingIdentity(); |
| 1629 | try { |
| 1630 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1631 | logv("Shutting down Phone " + i); |
| 1632 | shutdownRadioUsingPhoneId(i); |
| 1633 | } |
| 1634 | } finally { |
| 1635 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1640 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1641 | if (phone != null && phone.isRadioAvailable()) { |
| 1642 | phone.shutdownRadio(); |
| 1643 | } |
| 1644 | } |
| 1645 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1646 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1647 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1648 | |
| 1649 | final long identity = Binder.clearCallingIdentity(); |
| 1650 | try { |
| 1651 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1652 | if (defaultPhone != null) { |
| 1653 | defaultPhone.setRadioPower(turnOn); |
| 1654 | return true; |
| 1655 | } else { |
| 1656 | loge("There's no default phone."); |
| 1657 | return false; |
| 1658 | } |
| 1659 | } finally { |
| 1660 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1661 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1664 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -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 phone = getPhone(subId); |
| 1670 | if (phone != null) { |
| 1671 | phone.setRadioPower(turnOn); |
| 1672 | return true; |
| 1673 | } else { |
| 1674 | return false; |
| 1675 | } |
| 1676 | } finally { |
| 1677 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1678 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1681 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1682 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1683 | public boolean enableDataConnectivity() { |
| 1684 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1685 | |
| 1686 | final long identity = Binder.clearCallingIdentity(); |
| 1687 | try { |
| 1688 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1689 | final Phone phone = getPhone(subId); |
| 1690 | if (phone != null) { |
| 1691 | phone.setUserDataEnabled(true); |
| 1692 | return true; |
| 1693 | } else { |
| 1694 | return false; |
| 1695 | } |
| 1696 | } finally { |
| 1697 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1698 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1701 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1702 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1703 | public boolean disableDataConnectivity() { |
| 1704 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1705 | |
| 1706 | final long identity = Binder.clearCallingIdentity(); |
| 1707 | try { |
| 1708 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1709 | final Phone phone = getPhone(subId); |
| 1710 | if (phone != null) { |
| 1711 | phone.setUserDataEnabled(false); |
| 1712 | return true; |
| 1713 | } else { |
| 1714 | return false; |
| 1715 | } |
| 1716 | } finally { |
| 1717 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1718 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1721 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1722 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1723 | final long identity = Binder.clearCallingIdentity(); |
| 1724 | try { |
| 1725 | final Phone phone = getPhone(subId); |
| 1726 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1727 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1728 | } else { |
| 1729 | return false; |
| 1730 | } |
| 1731 | } finally { |
| 1732 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1733 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1737 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1740 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1741 | enforceCallPermission(); |
| 1742 | |
| 1743 | final long identity = Binder.clearCallingIdentity(); |
| 1744 | try { |
| 1745 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1746 | return; |
| 1747 | } |
| 1748 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1749 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1750 | } finally { |
| 1751 | Binder.restoreCallingIdentity(identity); |
| 1752 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1753 | }; |
| 1754 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1755 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1756 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1757 | |
| 1758 | final long identity = Binder.clearCallingIdentity(); |
| 1759 | try { |
| 1760 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1761 | return false; |
| 1762 | } |
| 1763 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1764 | } finally { |
| 1765 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1766 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1769 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1770 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1773 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1774 | final long identity = Binder.clearCallingIdentity(); |
| 1775 | try { |
| 1776 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1777 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1778 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1779 | } finally { |
| 1780 | Binder.restoreCallingIdentity(identity); |
| 1781 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1784 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1785 | public int getDataState() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1786 | final long identity = Binder.clearCallingIdentity(); |
| 1787 | try { |
| 1788 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1789 | if (phone != null) { |
| 1790 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1791 | } else { |
| 1792 | return PhoneConstantConversions.convertDataState( |
| 1793 | PhoneConstants.DataState.DISCONNECTED); |
| 1794 | } |
| 1795 | } finally { |
| 1796 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1797 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1800 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1801 | public int getDataActivity() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1802 | final long identity = Binder.clearCallingIdentity(); |
| 1803 | try { |
| 1804 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1805 | if (phone != null) { |
| 1806 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1807 | } else { |
| 1808 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1809 | } |
| 1810 | } finally { |
| 1811 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1812 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1816 | public Bundle getCellLocation(String callingPackage) { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1817 | mPhone.getContext().getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1818 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1819 | if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(), |
| 1820 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1821 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1824 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1825 | final long identity = Binder.clearCallingIdentity(); |
| 1826 | try { |
| 1827 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1828 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1829 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1830 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1831 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1832 | return data; |
| 1833 | } finally { |
| 1834 | Binder.restoreCallingIdentity(identity); |
| 1835 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1836 | } |
| 1837 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1838 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1839 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1840 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1841 | // registered cell info, so return a NULL country instead. |
| 1842 | final long identity = Binder.clearCallingIdentity(); |
| 1843 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1844 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1845 | // Get default phone in this case. |
| 1846 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1847 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1848 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1849 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1850 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1851 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1852 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1853 | return ""; |
| 1854 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1855 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1856 | if (phone != null) { |
| 1857 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1858 | if (sst != null) { |
| 1859 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1860 | if (lt != null) { |
| 1861 | return lt.getCurrentCountry(); |
| 1862 | } |
| 1863 | } |
| 1864 | } |
| 1865 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1866 | } finally { |
| 1867 | Binder.restoreCallingIdentity(identity); |
| 1868 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1869 | } |
| 1870 | |
| 1871 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1872 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1873 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1874 | } |
| 1875 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1876 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1877 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1878 | mApp.enforceCallingOrSelfPermission( |
| 1879 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1880 | |
| 1881 | final long identity = Binder.clearCallingIdentity(); |
| 1882 | try { |
| 1883 | final Phone phone = getPhone(subId); |
| 1884 | if (phone != null) { |
| 1885 | phone.enableLocationUpdates(); |
| 1886 | } |
| 1887 | } finally { |
| 1888 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1889 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | @Override |
| 1893 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1894 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1897 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1898 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1899 | mApp.enforceCallingOrSelfPermission( |
| 1900 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1901 | |
| 1902 | final long identity = Binder.clearCallingIdentity(); |
| 1903 | try { |
| 1904 | final Phone phone = getPhone(subId); |
| 1905 | if (phone != null) { |
| 1906 | phone.disableLocationUpdates(); |
| 1907 | } |
| 1908 | } finally { |
| 1909 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1910 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1913 | /** |
| 1914 | * Returns the target SDK version number for a given package name. |
| 1915 | * |
| 1916 | * @return target SDK if the package is found or INT_MAX. |
| 1917 | */ |
| 1918 | private int getTargetSdk(String packageName) { |
| 1919 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1920 | final ApplicationInfo ai = |
| 1921 | mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1922 | if (ai != null) return ai.targetSdkVersion; |
| 1923 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1924 | } |
| 1925 | return Integer.MAX_VALUE; |
| 1926 | } |
| 1927 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1928 | @Override |
| 1929 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1930 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1931 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1932 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1933 | throw new SecurityException( |
| 1934 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1935 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1936 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1937 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1938 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1939 | return null; |
| 1940 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1941 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1942 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1943 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1944 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 1945 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1946 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1947 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 1948 | for (CellInfo ci : info) { |
| 1949 | if (ci instanceof CellInfoGsm) { |
| 1950 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 1951 | } else if (ci instanceof CellInfoWcdma) { |
| 1952 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 1953 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1954 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1955 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1958 | private List<CellInfo> getCachedCellInfo() { |
| 1959 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 1960 | for (Phone phone : PhoneFactory.getPhones()) { |
| 1961 | List<CellInfo> info = phone.getAllCellInfo(); |
| 1962 | if (info != null) cellInfos.addAll(info); |
| 1963 | } |
| 1964 | return cellInfos; |
| 1965 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1966 | |
| 1967 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1968 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1969 | mPhone.getContext().getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1970 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1971 | if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(), |
Svet Ganov | 4af6628 | 2018-03-07 19:57:05 -0800 | [diff] [blame] | 1972 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1973 | return 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 | final int targetSdk = getTargetSdk(callingPackage); |
| 1977 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1978 | return getCachedCellInfo(); |
| 1979 | } |
| 1980 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1981 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1982 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1983 | final long identity = Binder.clearCallingIdentity(); |
| 1984 | try { |
| 1985 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 1986 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1987 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1988 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1989 | if (info != null) cellInfos.addAll(info); |
| 1990 | } |
| 1991 | return cellInfos; |
| 1992 | } finally { |
| 1993 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1994 | } |
| 1995 | } |
| 1996 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1997 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1998 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 1999 | requestCellInfoUpdateInternal( |
| 2000 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2001 | } |
| 2002 | |
| 2003 | @Override |
| 2004 | public void requestCellInfoUpdateWithWorkSource( |
| 2005 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2006 | enforceModifyPermission(); |
| 2007 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2008 | } |
| 2009 | |
| 2010 | private void requestCellInfoUpdateInternal( |
| 2011 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2012 | mPhone.getContext().getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2013 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2014 | if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(), |
| 2015 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2016 | return; |
| 2017 | } |
| 2018 | |
| 2019 | final Phone phone = getPhone(subId); |
| 2020 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2021 | |
| 2022 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2023 | } |
| 2024 | |
| 2025 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2026 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2027 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2028 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2029 | |
| 2030 | final long identity = Binder.clearCallingIdentity(); |
| 2031 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2032 | mPhone.setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2033 | } finally { |
| 2034 | Binder.restoreCallingIdentity(identity); |
| 2035 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2038 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2039 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2040 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2041 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2042 | return null; |
| 2043 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2044 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2045 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2046 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2047 | return null; |
| 2048 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2049 | |
| 2050 | final long identity = Binder.clearCallingIdentity(); |
| 2051 | try { |
| 2052 | return phone.getImei(); |
| 2053 | } finally { |
| 2054 | Binder.restoreCallingIdentity(identity); |
| 2055 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2059 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2060 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2061 | String tac = null; |
| 2062 | if (phone != null) { |
| 2063 | String imei = phone.getImei(); |
| 2064 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2065 | } |
| 2066 | return tac; |
| 2067 | } |
| 2068 | |
| 2069 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2070 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2071 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2072 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2073 | return null; |
| 2074 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2075 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2076 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2077 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2078 | return null; |
| 2079 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2080 | |
| 2081 | final long identity = Binder.clearCallingIdentity(); |
| 2082 | try { |
| 2083 | return phone.getMeid(); |
| 2084 | } finally { |
| 2085 | Binder.restoreCallingIdentity(identity); |
| 2086 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2090 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2091 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2092 | String manufacturerCode = null; |
| 2093 | if (phone != null) { |
| 2094 | String meid = phone.getMeid(); |
| 2095 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2096 | } |
| 2097 | return manufacturerCode; |
| 2098 | } |
| 2099 | |
| 2100 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2101 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2102 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2103 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2104 | return null; |
| 2105 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2106 | int subId = phone.getSubId(); |
| 2107 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2108 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2109 | return null; |
| 2110 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2111 | |
| 2112 | final long identity = Binder.clearCallingIdentity(); |
| 2113 | try { |
| 2114 | return phone.getDeviceSvn(); |
| 2115 | } finally { |
| 2116 | Binder.restoreCallingIdentity(identity); |
| 2117 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2118 | } |
| 2119 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2120 | @Override |
| 2121 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2122 | final long identity = Binder.clearCallingIdentity(); |
| 2123 | try { |
| 2124 | final Phone phone = getPhone(subId); |
| 2125 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2126 | } finally { |
| 2127 | Binder.restoreCallingIdentity(identity); |
| 2128 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | @Override |
| 2132 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2133 | final long identity = Binder.clearCallingIdentity(); |
| 2134 | try { |
| 2135 | final Phone phone = getPhone(subId); |
| 2136 | return phone == null ? null : phone.getCarrierName(); |
| 2137 | } finally { |
| 2138 | Binder.restoreCallingIdentity(identity); |
| 2139 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2140 | } |
| 2141 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2142 | @Override |
| 2143 | public int getSubscriptionMNOCarrierId(int subId) { |
| 2144 | final long identity = Binder.clearCallingIdentity(); |
| 2145 | try { |
| 2146 | final Phone phone = getPhone(subId); |
| 2147 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId(); |
| 2148 | } finally { |
| 2149 | Binder.restoreCallingIdentity(identity); |
| 2150 | } |
| 2151 | } |
| 2152 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2153 | @Override |
| 2154 | public int getSubscriptionPreciseCarrierId(int subId) { |
| 2155 | final long identity = Binder.clearCallingIdentity(); |
| 2156 | try { |
| 2157 | final Phone phone = getPhone(subId); |
| 2158 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
| 2159 | : phone.getPreciseCarrierId(); |
| 2160 | } finally { |
| 2161 | Binder.restoreCallingIdentity(identity); |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | @Override |
| 2166 | public String getSubscriptionPreciseCarrierName(int subId) { |
| 2167 | final long identity = Binder.clearCallingIdentity(); |
| 2168 | try { |
| 2169 | final Phone phone = getPhone(subId); |
| 2170 | return phone == null ? null : phone.getPreciseCarrierName(); |
| 2171 | } finally { |
| 2172 | Binder.restoreCallingIdentity(identity); |
| 2173 | } |
| 2174 | } |
| 2175 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2176 | @Override |
| 2177 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc) { |
| 2178 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2179 | if (phone == null) { |
| 2180 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2181 | } |
| 2182 | final long identity = Binder.clearCallingIdentity(); |
| 2183 | try { |
| 2184 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2185 | } finally { |
| 2186 | Binder.restoreCallingIdentity(identity); |
| 2187 | } |
| 2188 | } |
| 2189 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2190 | // |
| 2191 | // Internal helper methods. |
| 2192 | // |
| 2193 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2194 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2195 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2196 | * |
| 2197 | * @throws SecurityException if the caller does not have the required permission |
| 2198 | */ |
| 2199 | private void enforceModifyPermission() { |
| 2200 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2201 | } |
| 2202 | |
| 2203 | /** |
| 2204 | * Make sure the caller has the CALL_PHONE permission. |
| 2205 | * |
| 2206 | * @throws SecurityException if the caller does not have the required permission |
| 2207 | */ |
| 2208 | private void enforceCallPermission() { |
| 2209 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2210 | } |
| 2211 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2212 | private void enforceConnectivityInternalPermission() { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2213 | mApp.enforceCallingOrSelfPermission( |
| 2214 | android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2215 | "ConnectivityService"); |
| 2216 | } |
| 2217 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2218 | private String createTelUrl(String number) { |
| 2219 | if (TextUtils.isEmpty(number)) { |
| 2220 | return null; |
| 2221 | } |
| 2222 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2223 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2224 | } |
| 2225 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2226 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2227 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2228 | } |
| 2229 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2230 | private static void logv(String msg) { |
| 2231 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2232 | } |
| 2233 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2234 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2235 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2236 | } |
| 2237 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2238 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2239 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2240 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2243 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2244 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2245 | final long identity = Binder.clearCallingIdentity(); |
| 2246 | try { |
| 2247 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2248 | if (phone == null) { |
| 2249 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2250 | } else { |
| 2251 | return phone.getPhoneType(); |
| 2252 | } |
| 2253 | } finally { |
| 2254 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2255 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | /** |
| 2259 | * Returns the CDMA ERI icon index to display |
| 2260 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2261 | @Override |
| 2262 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2263 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2264 | } |
| 2265 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2266 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2267 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2268 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2269 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2270 | return -1; |
| 2271 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2272 | |
| 2273 | final long identity = Binder.clearCallingIdentity(); |
| 2274 | try { |
| 2275 | final Phone phone = getPhone(subId); |
| 2276 | if (phone != null) { |
| 2277 | return phone.getCdmaEriIconIndex(); |
| 2278 | } else { |
| 2279 | return -1; |
| 2280 | } |
| 2281 | } finally { |
| 2282 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2283 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | /** |
| 2287 | * Returns the CDMA ERI icon mode, |
| 2288 | * 0 - ON |
| 2289 | * 1 - FLASHING |
| 2290 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2291 | @Override |
| 2292 | public int getCdmaEriIconMode(String callingPackage) { |
| 2293 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2296 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2297 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2298 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2299 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2300 | return -1; |
| 2301 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2302 | |
| 2303 | final long identity = Binder.clearCallingIdentity(); |
| 2304 | try { |
| 2305 | final Phone phone = getPhone(subId); |
| 2306 | if (phone != null) { |
| 2307 | return phone.getCdmaEriIconMode(); |
| 2308 | } else { |
| 2309 | return -1; |
| 2310 | } |
| 2311 | } finally { |
| 2312 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2313 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | /** |
| 2317 | * Returns the CDMA ERI text, |
| 2318 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2319 | @Override |
| 2320 | public String getCdmaEriText(String callingPackage) { |
| 2321 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2322 | } |
| 2323 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2324 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2325 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2326 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2327 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2328 | return null; |
| 2329 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2330 | |
| 2331 | final long identity = Binder.clearCallingIdentity(); |
| 2332 | try { |
| 2333 | final Phone phone = getPhone(subId); |
| 2334 | if (phone != null) { |
| 2335 | return phone.getCdmaEriText(); |
| 2336 | } else { |
| 2337 | return null; |
| 2338 | } |
| 2339 | } finally { |
| 2340 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2341 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2345 | * Returns the CDMA MDN. |
| 2346 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2347 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2348 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2349 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2350 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2351 | |
| 2352 | final long identity = Binder.clearCallingIdentity(); |
| 2353 | try { |
| 2354 | final Phone phone = getPhone(subId); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2355 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2356 | return phone.getLine1Number(); |
| 2357 | } else { |
| 2358 | return null; |
| 2359 | } |
| 2360 | } finally { |
| 2361 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | /** |
| 2366 | * Returns the CDMA MIN. |
| 2367 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2368 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2369 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2370 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2371 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2372 | |
| 2373 | final long identity = Binder.clearCallingIdentity(); |
| 2374 | try { |
| 2375 | final Phone phone = getPhone(subId); |
| 2376 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2377 | return phone.getCdmaMin(); |
| 2378 | } else { |
| 2379 | return null; |
| 2380 | } |
| 2381 | } finally { |
| 2382 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2383 | } |
| 2384 | } |
| 2385 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2386 | @Override |
| 2387 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2388 | INumberVerificationCallback callback, String callingPackage) { |
| 2389 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2390 | != PERMISSION_GRANTED) { |
| 2391 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2392 | } |
| 2393 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2394 | |
| 2395 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2396 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2397 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2398 | } |
| 2399 | |
| 2400 | if (range == null) { |
| 2401 | throw new NullPointerException("Range must be non-null"); |
| 2402 | } |
| 2403 | |
| 2404 | timeoutMillis = Math.min(timeoutMillis, |
| 2405 | TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS); |
| 2406 | |
| 2407 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2408 | } |
| 2409 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2410 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2411 | * Returns true if CDMA provisioning needs to run. |
| 2412 | */ |
| 2413 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2414 | final long identity = Binder.clearCallingIdentity(); |
| 2415 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2416 | return mPhone.needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2417 | } finally { |
| 2418 | Binder.restoreCallingIdentity(identity); |
| 2419 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2423 | * Sets the voice mail number of a given subId. |
| 2424 | */ |
| 2425 | @Override |
| 2426 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2427 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2428 | |
| 2429 | final long identity = Binder.clearCallingIdentity(); |
| 2430 | try { |
| 2431 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2432 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2433 | return success; |
| 2434 | } finally { |
| 2435 | Binder.restoreCallingIdentity(identity); |
| 2436 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2437 | } |
| 2438 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2439 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2440 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2441 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2442 | String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2443 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2444 | throw new SecurityException("caller must be system dialer"); |
| 2445 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2446 | |
| 2447 | final long identity = Binder.clearCallingIdentity(); |
| 2448 | try { |
| 2449 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2450 | if (phoneAccountHandle == null) { |
| 2451 | return null; |
| 2452 | } |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2453 | return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2454 | } finally { |
| 2455 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2456 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2460 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2461 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2462 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2463 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2464 | return null; |
| 2465 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2466 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2467 | final long identity = Binder.clearCallingIdentity(); |
| 2468 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2469 | return RemoteVvmTaskManager |
| 2470 | .getRemotePackage(mPhone.getContext(), subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2471 | } finally { |
| 2472 | Binder.restoreCallingIdentity(identity); |
| 2473 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2474 | } |
| 2475 | |
| 2476 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2477 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2478 | VisualVoicemailSmsFilterSettings settings) { |
| 2479 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2480 | |
| 2481 | final long identity = Binder.clearCallingIdentity(); |
| 2482 | try { |
| 2483 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2484 | mPhone.getContext(), callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2485 | } finally { |
| 2486 | Binder.restoreCallingIdentity(identity); |
| 2487 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2491 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2492 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2493 | |
| 2494 | final long identity = Binder.clearCallingIdentity(); |
| 2495 | try { |
| 2496 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2497 | mPhone.getContext(), callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2498 | } finally { |
| 2499 | Binder.restoreCallingIdentity(identity); |
| 2500 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2504 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2505 | String callingPackage, int subId) { |
| 2506 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2507 | |
| 2508 | final long identity = Binder.clearCallingIdentity(); |
| 2509 | try { |
| 2510 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2511 | mPhone.getContext(), callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | } finally { |
| 2513 | Binder.restoreCallingIdentity(identity); |
| 2514 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2518 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2519 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2520 | |
| 2521 | final long identity = Binder.clearCallingIdentity(); |
| 2522 | try { |
| 2523 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2524 | mPhone.getContext(), subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2525 | } finally { |
| 2526 | Binder.restoreCallingIdentity(identity); |
| 2527 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | @Override |
| 2531 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2532 | String number, int port, String text, PendingIntent sentIntent) { |
| 2533 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2534 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2535 | enforceSendSmsPermission(); |
| 2536 | // Make the calls as the phone process. |
| 2537 | final long identity = Binder.clearCallingIdentity(); |
| 2538 | try { |
| 2539 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2540 | if (port == 0) { |
| 2541 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2542 | sentIntent, null, false); |
| 2543 | } else { |
| 2544 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2545 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2546 | (short) port, data, sentIntent, null); |
| 2547 | } |
| 2548 | } finally { |
| 2549 | Binder.restoreCallingIdentity(identity); |
| 2550 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2551 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2552 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2553 | * Sets the voice activation state of a given subId. |
| 2554 | */ |
| 2555 | @Override |
| 2556 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2557 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2558 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2559 | |
| 2560 | final long identity = Binder.clearCallingIdentity(); |
| 2561 | try { |
| 2562 | final Phone phone = getPhone(subId); |
| 2563 | if (phone != null) { |
| 2564 | phone.setVoiceActivationState(activationState); |
| 2565 | } else { |
| 2566 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2567 | } |
| 2568 | } finally { |
| 2569 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2570 | } |
| 2571 | } |
| 2572 | |
| 2573 | /** |
| 2574 | * Sets the data activation state of a given subId. |
| 2575 | */ |
| 2576 | @Override |
| 2577 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2578 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2579 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2580 | |
| 2581 | final long identity = Binder.clearCallingIdentity(); |
| 2582 | try { |
| 2583 | final Phone phone = getPhone(subId); |
| 2584 | if (phone != null) { |
| 2585 | phone.setDataActivationState(activationState); |
| 2586 | } else { |
| 2587 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2588 | } |
| 2589 | } finally { |
| 2590 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2591 | } |
| 2592 | } |
| 2593 | |
| 2594 | /** |
| 2595 | * Returns the voice activation state of a given subId. |
| 2596 | */ |
| 2597 | @Override |
| 2598 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2599 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2600 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2601 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 | final long identity = Binder.clearCallingIdentity(); |
| 2603 | try { |
| 2604 | if (phone != null) { |
| 2605 | return phone.getVoiceActivationState(); |
| 2606 | } else { |
| 2607 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2608 | } |
| 2609 | } finally { |
| 2610 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2611 | } |
| 2612 | } |
| 2613 | |
| 2614 | /** |
| 2615 | * Returns the data activation state of a given subId. |
| 2616 | */ |
| 2617 | @Override |
| 2618 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2619 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2620 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2621 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2622 | final long identity = Binder.clearCallingIdentity(); |
| 2623 | try { |
| 2624 | if (phone != null) { |
| 2625 | return phone.getDataActivationState(); |
| 2626 | } else { |
| 2627 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2628 | } |
| 2629 | } finally { |
| 2630 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2631 | } |
| 2632 | } |
| 2633 | |
| 2634 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2635 | * Returns the unread count of voicemails for a subId |
| 2636 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2637 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2638 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2639 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2640 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2641 | return 0; |
| 2642 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2643 | final long identity = Binder.clearCallingIdentity(); |
| 2644 | try { |
| 2645 | final Phone phone = getPhone(subId); |
| 2646 | if (phone != null) { |
| 2647 | return phone.getVoiceMessageCount(); |
| 2648 | } else { |
| 2649 | return 0; |
| 2650 | } |
| 2651 | } finally { |
| 2652 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2653 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2657 | * returns true, if the device is in a state where both voice and data |
| 2658 | * are supported simultaneously. This can change based on location or network condition. |
| 2659 | */ |
| 2660 | @Override |
| 2661 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2662 | final long identity = Binder.clearCallingIdentity(); |
| 2663 | try { |
| 2664 | final Phone phone = getPhone(subId); |
| 2665 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2666 | } finally { |
| 2667 | Binder.restoreCallingIdentity(identity); |
| 2668 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2672 | * Send the dialer code if called from the current default dialer or the caller has |
| 2673 | * carrier privilege. |
| 2674 | * @param inputCode The dialer code to send |
| 2675 | */ |
| 2676 | @Override |
| 2677 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
| 2678 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2679 | String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2680 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2681 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2682 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2683 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2684 | |
| 2685 | final long identity = Binder.clearCallingIdentity(); |
| 2686 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2687 | mPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2688 | } finally { |
| 2689 | Binder.restoreCallingIdentity(identity); |
| 2690 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2694 | * Returns the data network type. |
| 2695 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2696 | * |
| 2697 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2698 | */ |
| 2699 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2700 | public int getNetworkType() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2701 | final long identity = Binder.clearCallingIdentity(); |
| 2702 | try { |
| 2703 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2704 | if (phone != null) { |
| 2705 | return phone.getServiceState().getDataNetworkType(); |
| 2706 | } else { |
| 2707 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2708 | } |
| 2709 | } finally { |
| 2710 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2711 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2712 | } |
| 2713 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2714 | @Override |
| 2715 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2716 | if (!isActiveSubscription(subId)) { |
| 2717 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2718 | } |
| 2719 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2720 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2721 | } |
| 2722 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2723 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2724 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2725 | throws RemoteException { |
| 2726 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2727 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2728 | final long token = Binder.clearCallingIdentity(); |
| 2729 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2730 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2731 | .addRegistrationCallbackForSubscription(c, subId); |
| 2732 | } finally { |
| 2733 | Binder.restoreCallingIdentity(token); |
| 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2738 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2739 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2740 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2741 | Binder.withCleanCallingIdentity(() -> |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2742 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2743 | .removeRegistrationCallbackForSubscription(c, subId)); |
| 2744 | } |
| 2745 | |
| 2746 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2747 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2748 | throws RemoteException { |
| 2749 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2750 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2751 | final long token = Binder.clearCallingIdentity(); |
| 2752 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2753 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2754 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2755 | } finally { |
| 2756 | Binder.restoreCallingIdentity(token); |
| 2757 | } |
| 2758 | } |
| 2759 | |
| 2760 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2761 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2762 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2763 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2764 | Binder.withCleanCallingIdentity(() -> |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2765 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2766 | .removeCapabilitiesCallbackForSubscription(c, subId)); |
| 2767 | } |
| 2768 | |
| 2769 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2770 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2771 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2772 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2773 | final long token = Binder.clearCallingIdentity(); |
| 2774 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2775 | return ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2776 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2777 | } catch (ImsException e) { |
| 2778 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2779 | return false; |
| 2780 | } finally { |
| 2781 | Binder.restoreCallingIdentity(token); |
| 2782 | } |
| 2783 | } |
| 2784 | |
| 2785 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2786 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2787 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2788 | final long token = Binder.clearCallingIdentity(); |
| 2789 | try { |
| 2790 | Phone phone = getPhone(subId); |
| 2791 | if (phone == null) return false; |
| 2792 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2793 | } finally { |
| 2794 | Binder.restoreCallingIdentity(token); |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | @Override |
| 2799 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2800 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2801 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2802 | final long token = Binder.clearCallingIdentity(); |
| 2803 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2804 | return ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2805 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2806 | } finally { |
| 2807 | Binder.restoreCallingIdentity(token); |
| 2808 | } |
| 2809 | } |
| 2810 | |
| 2811 | @Override |
| 2812 | public void setAdvancedCallingSetting(int subId, boolean isEnabled) { |
| 2813 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2814 | "setAdvancedCallingSetting"); |
| 2815 | final long identity = Binder.clearCallingIdentity(); |
| 2816 | try { |
| 2817 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2818 | ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2819 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2820 | } finally { |
| 2821 | Binder.restoreCallingIdentity(identity); |
| 2822 | } |
| 2823 | } |
| 2824 | |
| 2825 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2826 | public boolean isVtSettingEnabled(int subId) { |
| 2827 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2828 | final long identity = Binder.clearCallingIdentity(); |
| 2829 | try { |
| 2830 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2831 | return ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2832 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2833 | } finally { |
| 2834 | Binder.restoreCallingIdentity(identity); |
| 2835 | } |
| 2836 | } |
| 2837 | |
| 2838 | @Override |
| 2839 | public void setVtSetting(int subId, boolean isEnabled) { |
| 2840 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2841 | "setVtSetting"); |
| 2842 | final long identity = Binder.clearCallingIdentity(); |
| 2843 | try { |
| 2844 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2845 | ImsManager.getInstance(mPhone.getContext(), |
| 2846 | getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2847 | } finally { |
| 2848 | Binder.restoreCallingIdentity(identity); |
| 2849 | } |
| 2850 | } |
| 2851 | |
| 2852 | @Override |
| 2853 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2854 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2855 | final long identity = Binder.clearCallingIdentity(); |
| 2856 | try { |
| 2857 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2858 | return ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2859 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2860 | } finally { |
| 2861 | Binder.restoreCallingIdentity(identity); |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | @Override |
| 2866 | public void setVoWiFiSetting(int subId, boolean isEnabled) { |
| 2867 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2868 | "setVoWiFiSetting"); |
| 2869 | final long identity = Binder.clearCallingIdentity(); |
| 2870 | try { |
| 2871 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2872 | ImsManager.getInstance(mPhone.getContext(), |
| 2873 | getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2874 | } finally { |
| 2875 | Binder.restoreCallingIdentity(identity); |
| 2876 | } |
| 2877 | } |
| 2878 | |
| 2879 | @Override |
| 2880 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2881 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2882 | final long identity = Binder.clearCallingIdentity(); |
| 2883 | try { |
| 2884 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2885 | return ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2886 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 2887 | } finally { |
| 2888 | Binder.restoreCallingIdentity(identity); |
| 2889 | } |
| 2890 | } |
| 2891 | |
| 2892 | @Override |
| 2893 | public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) { |
| 2894 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2895 | "setVoWiFiRoamingSetting"); |
| 2896 | final long identity = Binder.clearCallingIdentity(); |
| 2897 | try { |
| 2898 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2899 | ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2900 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 2901 | } finally { |
| 2902 | Binder.restoreCallingIdentity(identity); |
| 2903 | } |
| 2904 | } |
| 2905 | |
| 2906 | @Override |
| 2907 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 2908 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2909 | "setVoWiFiNonPersistent"); |
| 2910 | final long identity = Binder.clearCallingIdentity(); |
| 2911 | try { |
| 2912 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2913 | ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2914 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
| 2915 | } finally { |
| 2916 | Binder.restoreCallingIdentity(identity); |
| 2917 | } |
| 2918 | } |
| 2919 | |
| 2920 | @Override |
| 2921 | public int getVoWiFiModeSetting(int subId) { |
| 2922 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 2923 | final long identity = Binder.clearCallingIdentity(); |
| 2924 | try { |
| 2925 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2926 | return ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2927 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 2928 | } finally { |
| 2929 | Binder.restoreCallingIdentity(identity); |
| 2930 | } |
| 2931 | } |
| 2932 | |
| 2933 | @Override |
| 2934 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 2935 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2936 | "setVoWiFiModeSetting"); |
| 2937 | final long identity = Binder.clearCallingIdentity(); |
| 2938 | try { |
| 2939 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2940 | ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2941 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 2942 | } finally { |
| 2943 | Binder.restoreCallingIdentity(identity); |
| 2944 | } |
| 2945 | } |
| 2946 | |
| 2947 | @Override |
| 2948 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 2949 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 2950 | final long identity = Binder.clearCallingIdentity(); |
| 2951 | try { |
| 2952 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2953 | return ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2954 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 2955 | } finally { |
| 2956 | Binder.restoreCallingIdentity(identity); |
| 2957 | } |
| 2958 | } |
| 2959 | |
| 2960 | @Override |
| 2961 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 2962 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2963 | "setVoWiFiRoamingModeSetting"); |
| 2964 | final long identity = Binder.clearCallingIdentity(); |
| 2965 | try { |
| 2966 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2967 | ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2968 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 2969 | } finally { |
| 2970 | Binder.restoreCallingIdentity(identity); |
| 2971 | } |
| 2972 | } |
| 2973 | |
| 2974 | @Override |
| 2975 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 2976 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2977 | "setRttCapabilityEnabled"); |
| 2978 | final long identity = Binder.clearCallingIdentity(); |
| 2979 | try { |
| 2980 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2981 | ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2982 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 2983 | } finally { |
| 2984 | Binder.restoreCallingIdentity(identity); |
| 2985 | } |
| 2986 | } |
| 2987 | |
| 2988 | @Override |
| 2989 | public boolean isTtyOverVolteEnabled(int subId) { |
| 2990 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 2991 | final long identity = Binder.clearCallingIdentity(); |
| 2992 | try { |
| 2993 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2994 | return ImsManager.getInstance(mPhone.getContext(), |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2995 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 2996 | } finally { |
| 2997 | Binder.restoreCallingIdentity(identity); |
| 2998 | } |
| 2999 | } |
| 3000 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3001 | @Override |
| 3002 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3003 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3004 | final long identity = Binder.clearCallingIdentity(); |
| 3005 | try { |
| 3006 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3007 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3008 | .getConfigInterface().addConfigCallback(callback); |
| 3009 | } catch (ImsException e) { |
| 3010 | throw new IllegalArgumentException(e.getMessage()); |
| 3011 | } finally { |
| 3012 | Binder.restoreCallingIdentity(identity); |
| 3013 | } |
| 3014 | } |
| 3015 | |
| 3016 | @Override |
| 3017 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3018 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3019 | final long identity = Binder.clearCallingIdentity(); |
| 3020 | try { |
| 3021 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3022 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3023 | .getConfigInterface().removeConfigCallback(callback); |
| 3024 | } catch (ImsException e) { |
| 3025 | throw new IllegalArgumentException(e.getMessage()); |
| 3026 | } finally { |
| 3027 | Binder.restoreCallingIdentity(identity); |
| 3028 | } |
| 3029 | } |
| 3030 | |
| 3031 | @Override |
| 3032 | public int getImsProvisioningInt(int subId, int key) { |
| 3033 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3034 | final long identity = Binder.clearCallingIdentity(); |
| 3035 | try { |
| 3036 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3037 | return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 3038 | .getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3039 | } catch (ImsException e) { |
| 3040 | throw new IllegalArgumentException(e.getMessage()); |
| 3041 | } finally { |
| 3042 | Binder.restoreCallingIdentity(identity); |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | @Override |
| 3047 | public String getImsProvisioningString(int subId, int key) { |
| 3048 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3049 | final long identity = Binder.clearCallingIdentity(); |
| 3050 | try { |
| 3051 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3052 | return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 3053 | .getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3054 | } catch (ImsException e) { |
| 3055 | throw new IllegalArgumentException(e.getMessage()); |
| 3056 | } finally { |
| 3057 | Binder.restoreCallingIdentity(identity); |
| 3058 | } |
| 3059 | } |
| 3060 | |
| 3061 | @Override |
| 3062 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3063 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3064 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3065 | final long identity = Binder.clearCallingIdentity(); |
| 3066 | try { |
| 3067 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3068 | return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 3069 | .getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3070 | } catch (ImsException e) { |
| 3071 | throw new IllegalArgumentException(e.getMessage()); |
| 3072 | } finally { |
| 3073 | Binder.restoreCallingIdentity(identity); |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | @Override |
| 3078 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3079 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3080 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3081 | final long identity = Binder.clearCallingIdentity(); |
| 3082 | try { |
| 3083 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3084 | return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 3085 | .getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3086 | } catch (ImsException e) { |
| 3087 | throw new IllegalArgumentException(e.getMessage()); |
| 3088 | } finally { |
| 3089 | Binder.restoreCallingIdentity(identity); |
| 3090 | } |
| 3091 | } |
| 3092 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3093 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3094 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3095 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3096 | throw new IllegalArgumentException("Invalid Subscription Id."); |
| 3097 | } |
| 3098 | return slotId; |
| 3099 | } |
| 3100 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3101 | /** |
| 3102 | * Returns the network type for a subId |
| 3103 | */ |
| 3104 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3105 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3106 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3107 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3108 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3109 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3110 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3111 | final long identity = Binder.clearCallingIdentity(); |
| 3112 | try { |
| 3113 | final Phone phone = getPhone(subId); |
| 3114 | if (phone != null) { |
| 3115 | return phone.getServiceState().getDataNetworkType(); |
| 3116 | } else { |
| 3117 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3118 | } |
| 3119 | } finally { |
| 3120 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3121 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3122 | } |
| 3123 | |
| 3124 | /** |
| 3125 | * Returns the data network type |
| 3126 | */ |
| 3127 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3128 | public int getDataNetworkType(String callingPackage) { |
| 3129 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | /** |
| 3133 | * Returns the data network type for a subId |
| 3134 | */ |
| 3135 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3136 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3137 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3138 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3139 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3140 | } |
| 3141 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3142 | final long identity = Binder.clearCallingIdentity(); |
| 3143 | try { |
| 3144 | final Phone phone = getPhone(subId); |
| 3145 | if (phone != null) { |
| 3146 | return phone.getServiceState().getDataNetworkType(); |
| 3147 | } else { |
| 3148 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3149 | } |
| 3150 | } finally { |
| 3151 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3152 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3156 | * Returns the Voice network type for a subId |
| 3157 | */ |
| 3158 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3159 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3160 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3161 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3162 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3163 | } |
| 3164 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3165 | final long identity = Binder.clearCallingIdentity(); |
| 3166 | try { |
| 3167 | final Phone phone = getPhone(subId); |
| 3168 | if (phone != null) { |
| 3169 | return phone.getServiceState().getVoiceNetworkType(); |
| 3170 | } else { |
| 3171 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3172 | } |
| 3173 | } finally { |
| 3174 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3175 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | /** |
| 3179 | * @return true if a ICC card is present |
| 3180 | */ |
| 3181 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3182 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3183 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3184 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3188 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3189 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3190 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3191 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3192 | final long identity = Binder.clearCallingIdentity(); |
| 3193 | try { |
| 3194 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3195 | if (phone != null) { |
| 3196 | return phone.getIccCard().hasIccCard(); |
| 3197 | } else { |
| 3198 | return false; |
| 3199 | } |
| 3200 | } finally { |
| 3201 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3202 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3203 | } |
| 3204 | |
| 3205 | /** |
| 3206 | * Return if the current radio is LTE on CDMA. This |
| 3207 | * is a tri-state return value as for a period of time |
| 3208 | * the mode may be unknown. |
| 3209 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3210 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3211 | * @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] | 3212 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3213 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3214 | @Override |
| 3215 | public int getLteOnCdmaMode(String callingPackage) { |
| 3216 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3217 | } |
| 3218 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3219 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3220 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3221 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3222 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3223 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3224 | } |
| 3225 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3226 | final long identity = Binder.clearCallingIdentity(); |
| 3227 | try { |
| 3228 | final Phone phone = getPhone(subId); |
| 3229 | if (phone == null) { |
| 3230 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3231 | } else { |
| 3232 | return phone.getLteOnCdmaMode(); |
| 3233 | } |
| 3234 | } finally { |
| 3235 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3236 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3237 | } |
| 3238 | |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3239 | public void setPhone(Phone phone) { |
| 3240 | mPhone = phone; |
| 3241 | } |
| 3242 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3243 | /** |
| 3244 | * {@hide} |
| 3245 | * Returns Default subId, 0 in the case of single standby. |
| 3246 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3247 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3248 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3251 | private int getSlotForDefaultSubscription() { |
| 3252 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3253 | } |
| 3254 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3255 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3256 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3257 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3258 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3259 | private boolean isActiveSubscription(int subId) { |
| 3260 | return mSubscriptionController.isActiveSubId(subId); |
| 3261 | } |
| 3262 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3263 | /** |
| 3264 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3265 | */ |
| 3266 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3267 | final long identity = Binder.clearCallingIdentity(); |
| 3268 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3269 | return Settings.System.getInt(mPhone.getContext().getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3270 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3271 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3272 | } finally { |
| 3273 | Binder.restoreCallingIdentity(identity); |
| 3274 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | /** |
| 3278 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3279 | */ |
| 3280 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3281 | final long identity = Binder.clearCallingIdentity(); |
| 3282 | try { |
| 3283 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3284 | Settings.System.putInt(mPhone.getContext().getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3285 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3286 | } finally { |
| 3287 | Binder.restoreCallingIdentity(identity); |
| 3288 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3289 | } |
| 3290 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3291 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3292 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3293 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3294 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3295 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3296 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3297 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3298 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3299 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3300 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3301 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3302 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3303 | final long identity = Binder.clearCallingIdentity(); |
| 3304 | try { |
| 3305 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3306 | // Only allows LPA to open logical channel to ISD-R. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3307 | ComponentInfo bestComponent = |
| 3308 | EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3309 | if (bestComponent == null |
| 3310 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3311 | loge("The calling package is not allowed to access ISD-R."); |
| 3312 | throw new SecurityException( |
| 3313 | "The calling package is not allowed to access ISD-R."); |
| 3314 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3315 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3316 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3317 | if (DBG) { |
| 3318 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3319 | } |
| 3320 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| 3321 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
| 3322 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 3323 | return response; |
| 3324 | } finally { |
| 3325 | Binder.restoreCallingIdentity(identity); |
| 3326 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3330 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3331 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3332 | mApp, subId, "iccCloseLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3333 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3334 | final long identity = Binder.clearCallingIdentity(); |
| 3335 | try { |
| 3336 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3337 | if (channel < 0) { |
| 3338 | return false; |
| 3339 | } |
| 3340 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
| 3341 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 3342 | return success; |
| 3343 | } finally { |
| 3344 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3345 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
| 3348 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3349 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3350 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3351 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3352 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3353 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3354 | final long identity = Binder.clearCallingIdentity(); |
| 3355 | try { |
| 3356 | if (DBG) { |
| 3357 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3358 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3359 | + p3 + " data=" + data); |
| 3360 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3361 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3362 | if (channel < 0) { |
| 3363 | return ""; |
| 3364 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3365 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3366 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| 3367 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
| 3368 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3369 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3370 | // Append the returned status code to the end of the response payload. |
| 3371 | String s = Integer.toHexString( |
| 3372 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3373 | if (response.payload != null) { |
| 3374 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3375 | } |
| 3376 | return s; |
| 3377 | } finally { |
| 3378 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3379 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3380 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3381 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3382 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3383 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3384 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3385 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3386 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3387 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3388 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3389 | final long identity = Binder.clearCallingIdentity(); |
| 3390 | try { |
| 3391 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3392 | && TextUtils.equals(ISDR_AID, data)) { |
| 3393 | // Only allows LPA to select ISD-R. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3394 | ComponentInfo bestComponent = |
| 3395 | EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3396 | if (bestComponent == null |
| 3397 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3398 | loge("The calling package is not allowed to select ISD-R."); |
| 3399 | throw new SecurityException( |
| 3400 | "The calling package is not allowed to select ISD-R."); |
| 3401 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3402 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3403 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3404 | if (DBG) { |
| 3405 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3406 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3407 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3408 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3409 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 3410 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
| 3411 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3412 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3413 | // Append the returned status code to the end of the response payload. |
| 3414 | String s = Integer.toHexString( |
| 3415 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3416 | if (response.payload != null) { |
| 3417 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3418 | } |
| 3419 | return s; |
| 3420 | } finally { |
| 3421 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3422 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3423 | } |
| 3424 | |
| 3425 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3426 | 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] | 3427 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3428 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3429 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3430 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3431 | final long identity = Binder.clearCallingIdentity(); |
| 3432 | try { |
| 3433 | if (DBG) { |
| 3434 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3435 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3436 | } |
| 3437 | |
| 3438 | IccIoResult response = |
| 3439 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3440 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3441 | subId); |
| 3442 | |
| 3443 | if (DBG) { |
| 3444 | log("Exchange SIM_IO [R]" + response); |
| 3445 | } |
| 3446 | |
| 3447 | byte[] result = null; |
| 3448 | int length = 2; |
| 3449 | if (response.payload != null) { |
| 3450 | length = 2 + response.payload.length; |
| 3451 | result = new byte[length]; |
| 3452 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3453 | } else { |
| 3454 | result = new byte[length]; |
| 3455 | } |
| 3456 | |
| 3457 | result[length - 1] = (byte) response.sw2; |
| 3458 | result[length - 2] = (byte) response.sw1; |
| 3459 | return result; |
| 3460 | } finally { |
| 3461 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3462 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3463 | } |
| 3464 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3465 | /** |
| 3466 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3467 | * on a particular subscription |
| 3468 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3469 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3470 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3471 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3472 | return null; |
| 3473 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3474 | |
| 3475 | final long identity = Binder.clearCallingIdentity(); |
| 3476 | try { |
| 3477 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3478 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3479 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3480 | return null; |
| 3481 | } |
| 3482 | Object response = sendRequest( |
| 3483 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3484 | if (response instanceof String[]) { |
| 3485 | return (String[]) response; |
| 3486 | } |
| 3487 | // Response is an Exception of some kind, |
| 3488 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3489 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3490 | } finally { |
| 3491 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3492 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3493 | } |
| 3494 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3495 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3496 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3497 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3498 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3499 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3500 | final long identity = Binder.clearCallingIdentity(); |
| 3501 | try { |
| 3502 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3503 | if (response.payload == null) { |
| 3504 | return ""; |
| 3505 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3506 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3507 | // Append the returned status code to the end of the response payload. |
| 3508 | String s = Integer.toHexString( |
| 3509 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3510 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3511 | return s; |
| 3512 | } finally { |
| 3513 | Binder.restoreCallingIdentity(identity); |
| 3514 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3515 | } |
| 3516 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3517 | /** |
| 3518 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3519 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3520 | * |
| 3521 | * @param itemID the ID of the item to read |
| 3522 | * @return the NV item as a String, or null on error. |
| 3523 | */ |
| 3524 | @Override |
| 3525 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3526 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3527 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3528 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3529 | |
| 3530 | final long identity = Binder.clearCallingIdentity(); |
| 3531 | try { |
| 3532 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3533 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3534 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 3535 | return value; |
| 3536 | } finally { |
| 3537 | Binder.restoreCallingIdentity(identity); |
| 3538 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | /** |
| 3542 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3543 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3544 | * |
| 3545 | * @param itemID the ID of the item to read |
| 3546 | * @param itemValue the value to write, as a String |
| 3547 | * @return true on success; false on any failure |
| 3548 | */ |
| 3549 | @Override |
| 3550 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3551 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3552 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3553 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3554 | |
| 3555 | final long identity = Binder.clearCallingIdentity(); |
| 3556 | try { |
| 3557 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 3558 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3559 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3560 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 3561 | return success; |
| 3562 | } finally { |
| 3563 | Binder.restoreCallingIdentity(identity); |
| 3564 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | /** |
| 3568 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 3569 | * Used for device configuration by some CDMA operators. |
| 3570 | * |
| 3571 | * @param preferredRoamingList byte array containing the new PRL |
| 3572 | * @return true on success; false on any failure |
| 3573 | */ |
| 3574 | @Override |
| 3575 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3576 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3577 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3578 | |
| 3579 | final long identity = Binder.clearCallingIdentity(); |
| 3580 | try { |
| 3581 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 3582 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 3583 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 3584 | return success; |
| 3585 | } finally { |
| 3586 | Binder.restoreCallingIdentity(identity); |
| 3587 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3588 | } |
| 3589 | |
| 3590 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3591 | * 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] | 3592 | * Used for device configuration by some CDMA operators. |
| 3593 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3594 | * @param slotIndex - device slot. |
| 3595 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3596 | * @return true on success; false on any failure |
| 3597 | */ |
| 3598 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3599 | public boolean resetModemConfig(int slotIndex) { |
| 3600 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3601 | if (phone != null) { |
| 3602 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3603 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3604 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3605 | final long identity = Binder.clearCallingIdentity(); |
| 3606 | try { |
| 3607 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 3608 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 3609 | return success; |
| 3610 | } finally { |
| 3611 | Binder.restoreCallingIdentity(identity); |
| 3612 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3613 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3614 | return false; |
| 3615 | } |
| 3616 | |
| 3617 | /** |
| 3618 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 3619 | * |
| 3620 | * @param slotIndex - device slot. |
| 3621 | * |
| 3622 | * @return true on success; false on any failure |
| 3623 | */ |
| 3624 | @Override |
| 3625 | public boolean rebootModem(int slotIndex) { |
| 3626 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3627 | if (phone != null) { |
| 3628 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3629 | mApp, phone.getSubId(), "rebootModem"); |
| 3630 | |
| 3631 | final long identity = Binder.clearCallingIdentity(); |
| 3632 | try { |
| 3633 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 3634 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 3635 | return success; |
| 3636 | } finally { |
| 3637 | Binder.restoreCallingIdentity(identity); |
| 3638 | } |
| 3639 | } |
| 3640 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3641 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3642 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3643 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3644 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3645 | mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3646 | return new String[0]; |
| 3647 | } |
| 3648 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3649 | final long identity = Binder.clearCallingIdentity(); |
| 3650 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3651 | return mPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3652 | } finally { |
| 3653 | Binder.restoreCallingIdentity(identity); |
| 3654 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3655 | } |
| 3656 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3657 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3658 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 3659 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3660 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3661 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3662 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3663 | |
| 3664 | final long identity = Binder.clearCallingIdentity(); |
| 3665 | try { |
| 3666 | PhoneFactory.getImsResolver().enableIms(slotId); |
| 3667 | } finally { |
| 3668 | Binder.restoreCallingIdentity(identity); |
| 3669 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3673 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 3674 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3675 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3676 | public void disableIms(int slotId) { |
| 3677 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3678 | |
| 3679 | final long identity = Binder.clearCallingIdentity(); |
| 3680 | try { |
| 3681 | PhoneFactory.getImsResolver().disableIms(slotId); |
| 3682 | } finally { |
| 3683 | Binder.restoreCallingIdentity(identity); |
| 3684 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3685 | } |
| 3686 | |
| 3687 | /** |
| 3688 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 3689 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 3690 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 3691 | */ |
| 3692 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3693 | IImsServiceFeatureCallback callback) { |
| 3694 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3695 | |
| 3696 | final long identity = Binder.clearCallingIdentity(); |
| 3697 | try { |
| 3698 | return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback); |
| 3699 | } finally { |
| 3700 | Binder.restoreCallingIdentity(identity); |
| 3701 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | /** |
| 3705 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 3706 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 3707 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 3708 | * listener for feature updates. |
| 3709 | */ |
| 3710 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 3711 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3712 | |
| 3713 | final long identity = Binder.clearCallingIdentity(); |
| 3714 | try { |
| 3715 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); |
| 3716 | } finally { |
| 3717 | Binder.restoreCallingIdentity(identity); |
| 3718 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3719 | } |
| 3720 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3721 | /** |
| 3722 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| 3723 | * specified. |
| 3724 | */ |
| 3725 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 3726 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3727 | |
| 3728 | final long identity = Binder.clearCallingIdentity(); |
| 3729 | try { |
| 3730 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); |
| 3731 | } finally { |
| 3732 | Binder.restoreCallingIdentity(identity); |
| 3733 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3734 | } |
| 3735 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3736 | /** |
| 3737 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| 3738 | * specified. |
| 3739 | */ |
| 3740 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 3741 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3742 | |
| 3743 | final long identity = Binder.clearCallingIdentity(); |
| 3744 | try { |
| 3745 | return PhoneFactory.getImsResolver().getImsConfig(slotId, feature); |
| 3746 | } finally { |
| 3747 | Binder.restoreCallingIdentity(identity); |
| 3748 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3749 | } |
| 3750 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 3751 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3752 | * Sets the ImsService Package Name that Telephony will bind to. |
| 3753 | * |
| 3754 | * @param slotId the slot ID that the ImsService should bind for. |
| 3755 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 3756 | * ImsService is the device default ImsService. |
| 3757 | * @param packageName The package name of the application that contains the ImsService to bind |
| 3758 | * to. |
| 3759 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 3760 | * @hide |
| 3761 | */ |
| 3762 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3763 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3764 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3765 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3766 | "setImsService"); |
| 3767 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3768 | final long identity = Binder.clearCallingIdentity(); |
| 3769 | try { |
| 3770 | return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId, |
| 3771 | isCarrierImsService, packageName); |
| 3772 | } finally { |
| 3773 | Binder.restoreCallingIdentity(identity); |
| 3774 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3775 | } |
| 3776 | |
| 3777 | /** |
| 3778 | * Return the ImsService configuration. |
| 3779 | * |
| 3780 | * @param slotId The slot that the ImsService is associated with. |
| 3781 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 3782 | * the device default. |
| 3783 | * @return the package name of the ImsService configuration. |
| 3784 | */ |
| 3785 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3786 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3787 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3788 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3789 | "getImsService"); |
| 3790 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3791 | final long identity = Binder.clearCallingIdentity(); |
| 3792 | try { |
| 3793 | return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId, |
| 3794 | isCarrierImsService); |
| 3795 | } finally { |
| 3796 | Binder.restoreCallingIdentity(identity); |
| 3797 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3798 | } |
| 3799 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3800 | public void setImsRegistrationState(boolean registered) { |
| 3801 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3802 | |
| 3803 | final long identity = Binder.clearCallingIdentity(); |
| 3804 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3805 | mPhone.setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3806 | } finally { |
| 3807 | Binder.restoreCallingIdentity(identity); |
| 3808 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3812 | * Set the network selection mode to automatic. |
| 3813 | * |
| 3814 | */ |
| 3815 | @Override |
| 3816 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3817 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3818 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3819 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3820 | if (!isActiveSubscription(subId)) { |
| 3821 | return; |
| 3822 | } |
| 3823 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3824 | final long identity = Binder.clearCallingIdentity(); |
| 3825 | try { |
| 3826 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 3827 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 3828 | } finally { |
| 3829 | Binder.restoreCallingIdentity(identity); |
| 3830 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3833 | /** |
| 3834 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 3835 | * |
| 3836 | * @param subId the id of the subscription. |
| 3837 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 3838 | * the operator to attach to. |
| 3839 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 3840 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 3841 | * normal network selection next time. |
| 3842 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3843 | */ |
| 3844 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3845 | public boolean setNetworkSelectionModeManual( |
| 3846 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3847 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3848 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3849 | |
| 3850 | if (!isActiveSubscription(subId)) { |
| 3851 | return false; |
| 3852 | } |
| 3853 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3854 | final long identity = Binder.clearCallingIdentity(); |
| 3855 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3856 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3857 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3858 | if (DBG) { |
| 3859 | log("setNetworkSelectionModeManual: subId: " + subId |
| 3860 | + " operator: " + operatorInfo); |
| 3861 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3862 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 3863 | } finally { |
| 3864 | Binder.restoreCallingIdentity(identity); |
| 3865 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3866 | } |
| 3867 | |
| 3868 | /** |
| 3869 | * Scans for available networks. |
| 3870 | */ |
| 3871 | @Override |
| 3872 | public CellNetworkScanResult getCellNetworkScanResults(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3873 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3874 | mApp, subId, "getCellNetworkScanResults"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3875 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3876 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3877 | try { |
| 3878 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3879 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3880 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3881 | } finally { |
| 3882 | Binder.restoreCallingIdentity(identity); |
| 3883 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3884 | } |
| 3885 | |
| 3886 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3887 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3888 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3889 | * @param subId id of the subscription |
| 3890 | * @param request contains the radio access networks with bands/channels to scan |
| 3891 | * @param messenger callback messenger for scan results or errors |
| 3892 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3893 | * @return the id of the requested scan which can be used to stop the scan. |
| 3894 | */ |
| 3895 | @Override |
| 3896 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
| 3897 | IBinder binder) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3898 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3899 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3900 | |
| 3901 | final long identity = Binder.clearCallingIdentity(); |
| 3902 | try { |
| 3903 | return mNetworkScanRequestTracker.startNetworkScan( |
| 3904 | request, messenger, binder, getPhone(subId)); |
| 3905 | } finally { |
| 3906 | Binder.restoreCallingIdentity(identity); |
| 3907 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | /** |
| 3911 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3912 | * |
| 3913 | * @param subId id of the subscription |
| 3914 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3915 | */ |
| 3916 | @Override |
| 3917 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3918 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3919 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3920 | |
| 3921 | final long identity = Binder.clearCallingIdentity(); |
| 3922 | try { |
| 3923 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 3924 | } finally { |
| 3925 | Binder.restoreCallingIdentity(identity); |
| 3926 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3927 | } |
| 3928 | |
| 3929 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3930 | * Get the calculated preferred network type. |
| 3931 | * Used for debugging incorrect network type. |
| 3932 | * |
| 3933 | * @return the preferred network type, defined in RILConstants.java. |
| 3934 | */ |
| 3935 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3936 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3937 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3938 | mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3939 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 3940 | } |
| 3941 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3942 | final long identity = Binder.clearCallingIdentity(); |
| 3943 | try { |
| 3944 | // FIXME: need to get SubId from somewhere. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3945 | return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3946 | } finally { |
| 3947 | Binder.restoreCallingIdentity(identity); |
| 3948 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3949 | } |
| 3950 | |
| 3951 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3952 | * Get the preferred network type. |
| 3953 | * Used for device configuration by some CDMA operators. |
| 3954 | * |
| 3955 | * @return the preferred network type, defined in RILConstants.java. |
| 3956 | */ |
| 3957 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3958 | public int getPreferredNetworkType(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3959 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3960 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3961 | |
| 3962 | final long identity = Binder.clearCallingIdentity(); |
| 3963 | try { |
| 3964 | if (DBG) log("getPreferredNetworkType"); |
| 3965 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 3966 | int networkType = (result != null ? result[0] : -1); |
| 3967 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 3968 | return networkType; |
| 3969 | } finally { |
| 3970 | Binder.restoreCallingIdentity(identity); |
| 3971 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3972 | } |
| 3973 | |
| 3974 | /** |
| 3975 | * Set the preferred network type. |
| 3976 | * Used for device configuration by some CDMA operators. |
| 3977 | * |
| 3978 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 3979 | * @return true on success; false on any failure. |
| 3980 | */ |
| 3981 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3982 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3983 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3984 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3985 | |
| 3986 | final long identity = Binder.clearCallingIdentity(); |
| 3987 | try { |
| 3988 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 3989 | Boolean success = (Boolean) sendRequest( |
| 3990 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 3991 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 3992 | if (success) { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 3993 | Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3994 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 3995 | } |
| 3996 | return success; |
| 3997 | } finally { |
| 3998 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 3999 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4000 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4001 | |
| 4002 | /** |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4003 | * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning |
Jack Yu | 3cda1cd | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4004 | * SystemProperty to decide whether DUN APN is required for |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4005 | * tethering. |
| 4006 | * |
| 4007 | * @return 0: Not required. 1: required. 2: Not set. |
| 4008 | * @hide |
| 4009 | */ |
| 4010 | @Override |
| 4011 | public int getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4012 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4013 | |
| 4014 | final long identity = Binder.clearCallingIdentity(); |
| 4015 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4016 | int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4017 | Settings.Global.TETHER_DUN_REQUIRED, 2); |
Jack Yu | 3cda1cd | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4018 | // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4019 | if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4020 | dunRequired = 1; |
| 4021 | } |
| 4022 | return dunRequired; |
| 4023 | } finally { |
| 4024 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4025 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4026 | } |
| 4027 | |
| 4028 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4029 | * Set mobile data enabled |
| 4030 | * Used by the user through settings etc to turn on/off mobile data |
| 4031 | * |
| 4032 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4033 | */ |
| 4034 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4035 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4036 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4037 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4038 | |
| 4039 | final long identity = Binder.clearCallingIdentity(); |
| 4040 | try { |
| 4041 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4042 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4043 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4044 | if (phone != null) { |
| 4045 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
| 4046 | phone.setUserDataEnabled(enable); |
| 4047 | } else { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4048 | loge("setUserDataEnabled: no phone for subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4049 | } |
| 4050 | } finally { |
| 4051 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4052 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4053 | } |
| 4054 | |
| 4055 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4056 | * Get the user enabled state of Mobile Data. |
| 4057 | * |
| 4058 | * TODO: remove and use isUserDataEnabled. |
| 4059 | * This can't be removed now because some vendor codes |
| 4060 | * calls through ITelephony directly while they should |
| 4061 | * use TelephonyManager. |
| 4062 | * |
| 4063 | * @return true on enabled |
| 4064 | */ |
| 4065 | @Override |
| 4066 | public boolean getDataEnabled(int subId) { |
| 4067 | return isUserDataEnabled(subId); |
| 4068 | } |
| 4069 | |
| 4070 | /** |
| 4071 | * Get whether mobile data is enabled per user setting. |
| 4072 | * |
| 4073 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4074 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4075 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4076 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4077 | * |
| 4078 | * @return {@code true} if data is enabled else {@code false} |
| 4079 | */ |
| 4080 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4081 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4082 | try { |
| 4083 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4084 | null); |
| 4085 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4086 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4087 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4088 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4089 | |
| 4090 | final long identity = Binder.clearCallingIdentity(); |
| 4091 | try { |
| 4092 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4093 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4094 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4095 | if (phone != null) { |
| 4096 | boolean retVal = phone.isUserDataEnabled(); |
| 4097 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4098 | return retVal; |
| 4099 | } else { |
| 4100 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4101 | return false; |
| 4102 | } |
| 4103 | } finally { |
| 4104 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4105 | } |
| 4106 | } |
| 4107 | |
| 4108 | /** |
| 4109 | * Get whether mobile data is enabled. |
| 4110 | * |
| 4111 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4112 | * whether mobile data is actually enabled. |
| 4113 | * |
| 4114 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4115 | * |
| 4116 | * @return {@code true} if data is enabled else {@code false} |
| 4117 | */ |
| 4118 | @Override |
| 4119 | public boolean isDataEnabled(int subId) { |
| 4120 | try { |
| 4121 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4122 | null); |
| 4123 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4124 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4125 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4126 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4127 | |
| 4128 | final long identity = Binder.clearCallingIdentity(); |
| 4129 | try { |
| 4130 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4131 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4132 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4133 | if (phone != null) { |
| 4134 | boolean retVal = phone.isDataEnabled(); |
| 4135 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4136 | return retVal; |
| 4137 | } else { |
| 4138 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4139 | return false; |
| 4140 | } |
| 4141 | } finally { |
| 4142 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4143 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4144 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4145 | |
| 4146 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4147 | public int getCarrierPrivilegeStatus(int subId) { |
| 4148 | final Phone phone = getPhone(subId); |
| 4149 | if (phone == null) { |
| 4150 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4151 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4152 | } |
| 4153 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4154 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4155 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4156 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4157 | } |
| 4158 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4159 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4160 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4161 | |
| 4162 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4163 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4164 | final Phone phone = getPhone(subId); |
| 4165 | if (phone == null) { |
| 4166 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4167 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4168 | } |
| 4169 | UiccProfile profile = |
| 4170 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4171 | if (profile == null) { |
| 4172 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4173 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4174 | } |
| 4175 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4176 | } |
| 4177 | |
| 4178 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4179 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4180 | if (TextUtils.isEmpty(pkgName)) |
| 4181 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4182 | UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4183 | if (card == null) { |
| 4184 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4185 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4186 | } |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4187 | return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | @Override |
| 4191 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4192 | if (TextUtils.isEmpty(pkgName)) |
| 4193 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4194 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4195 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4196 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4197 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4198 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4199 | continue; |
| 4200 | } |
| 4201 | |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4202 | result = card.getCarrierPrivilegeStatus( |
| 4203 | mPhone.getContext().getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4204 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4205 | break; |
| 4206 | } |
| 4207 | } |
| 4208 | |
| 4209 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4210 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4211 | |
| 4212 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4213 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4214 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4215 | loge("phoneId " + phoneId + " is not valid."); |
| 4216 | return null; |
| 4217 | } |
| 4218 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4219 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4220 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4221 | return null ; |
| 4222 | } |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4223 | return card.getCarrierPackageNamesForIntent( |
| 4224 | mPhone.getContext().getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4225 | } |
| 4226 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4227 | @Override |
| 4228 | public List<String> getPackagesWithCarrierPrivileges() { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4229 | PackageManager pm = mPhone.getContext().getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4230 | List<String> privilegedPackages = new ArrayList<>(); |
| 4231 | List<PackageInfo> packages = null; |
| 4232 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4233 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4234 | if (card == null) { |
| 4235 | // No UICC in that slot. |
| 4236 | continue; |
| 4237 | } |
| 4238 | if (card.hasCarrierPrivilegeRules()) { |
| 4239 | if (packages == null) { |
| 4240 | // Only check packages in user 0 for now |
| 4241 | packages = pm.getInstalledPackagesAsUser( |
| 4242 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4243 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4244 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4245 | } |
| 4246 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4247 | PackageInfo pkgInfo = packages.get(p); |
| 4248 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4249 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4250 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4251 | privilegedPackages.add(pkgInfo.packageName); |
| 4252 | } |
| 4253 | } |
| 4254 | } |
| 4255 | } |
| 4256 | return privilegedPackages; |
| 4257 | } |
| 4258 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4259 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4260 | final Phone phone = getPhone(subId); |
| 4261 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4262 | if (card == null) { |
| 4263 | loge("getIccId: No UICC"); |
| 4264 | return null; |
| 4265 | } |
| 4266 | String iccId = card.getIccId(); |
| 4267 | if (TextUtils.isEmpty(iccId)) { |
| 4268 | loge("getIccId: ICC ID is null or empty."); |
| 4269 | return null; |
| 4270 | } |
| 4271 | return iccId; |
| 4272 | } |
| 4273 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4274 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4275 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4276 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4277 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4278 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4279 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4280 | final long identity = Binder.clearCallingIdentity(); |
| 4281 | try { |
| 4282 | final String iccId = getIccId(subId); |
| 4283 | final Phone phone = getPhone(subId); |
| 4284 | if (phone == null) { |
| 4285 | return false; |
| 4286 | } |
| 4287 | final String subscriberId = phone.getSubscriberId(); |
| 4288 | |
| 4289 | if (DBG_MERGE) { |
| 4290 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4291 | + subscriberId + " to " + number); |
| 4292 | } |
| 4293 | |
| 4294 | if (TextUtils.isEmpty(iccId)) { |
| 4295 | return false; |
| 4296 | } |
| 4297 | |
| 4298 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4299 | |
| 4300 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4301 | if (alphaTag == null) { |
| 4302 | editor.remove(alphaTagPrefKey); |
| 4303 | } else { |
| 4304 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4305 | } |
| 4306 | |
| 4307 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4308 | // track all merged IMSIs based on line number |
| 4309 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4310 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4311 | if (number == null) { |
| 4312 | editor.remove(numberPrefKey); |
| 4313 | editor.remove(subscriberPrefKey); |
| 4314 | } else { |
| 4315 | editor.putString(numberPrefKey, number); |
| 4316 | editor.putString(subscriberPrefKey, subscriberId); |
| 4317 | } |
| 4318 | |
| 4319 | editor.commit(); |
| 4320 | return true; |
| 4321 | } finally { |
| 4322 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4323 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4327 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4328 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4329 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4330 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4331 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4332 | return null; |
| 4333 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4334 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4335 | final long identity = Binder.clearCallingIdentity(); |
| 4336 | try { |
| 4337 | String iccId = getIccId(subId); |
| 4338 | if (iccId != null) { |
| 4339 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4340 | if (DBG_MERGE) { |
| 4341 | log("getLine1NumberForDisplay returning " |
| 4342 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4343 | } |
| 4344 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4345 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4346 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4347 | return null; |
| 4348 | } finally { |
| 4349 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4350 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4354 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4355 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4356 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4357 | return null; |
| 4358 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4359 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4360 | final long identity = Binder.clearCallingIdentity(); |
| 4361 | try { |
| 4362 | String iccId = getIccId(subId); |
| 4363 | if (iccId != null) { |
| 4364 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4365 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4366 | } |
| 4367 | return null; |
| 4368 | } finally { |
| 4369 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4370 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4371 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4372 | |
| 4373 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4374 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4375 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4376 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4377 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4378 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4379 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4380 | return null; |
| 4381 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4382 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4383 | final long identity = Binder.clearCallingIdentity(); |
| 4384 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4385 | final Context context = mPhone.getContext(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4386 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4387 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4388 | |
| 4389 | // Figure out what subscribers are currently active |
| 4390 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4391 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4392 | // the process, where TelephonyManager was instantiated. |
| 4393 | // Otherwise AppOps check will fail. |
| 4394 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4395 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4396 | for (int subId : subIds) { |
| 4397 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4398 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4399 | |
| 4400 | // First pass, find a number override for an active subscriber |
| 4401 | String mergeNumber = null; |
| 4402 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4403 | for (String key : prefs.keySet()) { |
| 4404 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4405 | final String subscriberId = (String) prefs.get(key); |
| 4406 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4407 | final String iccId = key.substring( |
| 4408 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4409 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4410 | mergeNumber = (String) prefs.get(numberKey); |
| 4411 | if (DBG_MERGE) { |
| 4412 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4413 | + " for active subscriber " + subscriberId); |
| 4414 | } |
| 4415 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4416 | break; |
| 4417 | } |
| 4418 | } |
| 4419 | } |
| 4420 | } |
| 4421 | |
| 4422 | // Shortcut when no active merged subscribers |
| 4423 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4424 | return null; |
| 4425 | } |
| 4426 | |
| 4427 | // Second pass, find all subscribers under that line override |
| 4428 | final ArraySet<String> result = new ArraySet<>(); |
| 4429 | for (String key : prefs.keySet()) { |
| 4430 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4431 | final String number = (String) prefs.get(key); |
| 4432 | if (mergeNumber.equals(number)) { |
| 4433 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4434 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4435 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4436 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4437 | result.add(subscriberId); |
| 4438 | } |
| 4439 | } |
| 4440 | } |
| 4441 | } |
| 4442 | |
| 4443 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4444 | Arrays.sort(resultArray); |
| 4445 | if (DBG_MERGE) { |
| 4446 | Slog.d(LOG_TAG, |
| 4447 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4448 | } |
| 4449 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4450 | } finally { |
| 4451 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4452 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4453 | } |
| 4454 | |
| 4455 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4456 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4457 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4458 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4459 | |
| 4460 | final long identity = Binder.clearCallingIdentity(); |
| 4461 | try { |
| 4462 | final Phone phone = getPhone(subId); |
| 4463 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4464 | } finally { |
| 4465 | Binder.restoreCallingIdentity(identity); |
| 4466 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4467 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4468 | |
| 4469 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4470 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4471 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 4472 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4473 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4474 | |
| 4475 | final long identity = Binder.clearCallingIdentity(); |
| 4476 | try { |
| 4477 | final Phone phone = getPhone(subId); |
| 4478 | if (phone == null) { |
| 4479 | return false; |
| 4480 | } |
| 4481 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 4482 | cdmaNonRoamingList); |
| 4483 | } finally { |
| 4484 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4485 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4486 | } |
| 4487 | |
| 4488 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4489 | @Deprecated |
| 4490 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 4491 | enforceModifyPermission(); |
| 4492 | |
| 4493 | int returnValue = 0; |
| 4494 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4495 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4496 | if(result.exception == null) { |
| 4497 | if (result.result != null) { |
| 4498 | byte[] responseData = (byte[])(result.result); |
| 4499 | if(responseData.length > oemResp.length) { |
| 4500 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 4501 | responseData.length + "bytes. Buffer Size is " + |
| 4502 | oemResp.length + "bytes."); |
| 4503 | } |
| 4504 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 4505 | returnValue = responseData.length; |
| 4506 | } |
| 4507 | } else { |
| 4508 | CommandException ex = (CommandException) result.exception; |
| 4509 | returnValue = ex.getCommandError().ordinal(); |
| 4510 | if(returnValue > 0) returnValue *= -1; |
| 4511 | } |
| 4512 | } catch (RuntimeException e) { |
| 4513 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 4514 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 4515 | if(returnValue > 0) returnValue *= -1; |
| 4516 | } |
| 4517 | |
| 4518 | return returnValue; |
| 4519 | } |
| 4520 | |
| 4521 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4522 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 4523 | try { |
| 4524 | ProxyController.getInstance().setRadioCapability(rafs); |
| 4525 | } catch (RuntimeException e) { |
| 4526 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 4527 | } |
| 4528 | } |
| 4529 | |
| 4530 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4531 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4532 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4533 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4534 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4535 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4536 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4537 | final long identity = Binder.clearCallingIdentity(); |
| 4538 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4539 | TelephonyPermissions |
| 4540 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4541 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 4542 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4543 | } finally { |
| 4544 | Binder.restoreCallingIdentity(identity); |
| 4545 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4546 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4547 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4548 | |
| 4549 | @Override |
| 4550 | public void enableVideoCalling(boolean enable) { |
| 4551 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4552 | |
| 4553 | final long identity = Binder.clearCallingIdentity(); |
| 4554 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4555 | ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4556 | } finally { |
| 4557 | Binder.restoreCallingIdentity(identity); |
| 4558 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4562 | public boolean isVideoCallingEnabled(String callingPackage) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4563 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4564 | mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4565 | return false; |
| 4566 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4567 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4568 | final long identity = Binder.clearCallingIdentity(); |
| 4569 | try { |
| 4570 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 4571 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 4572 | // In the long run, we may instead need to check if there exists a connection service |
| 4573 | // which can support video calling. |
| 4574 | ImsManager imsManager = |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4575 | ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4576 | return imsManager.isVtEnabledByPlatform() |
| 4577 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 4578 | && imsManager.isVtEnabledByUser(); |
| 4579 | } finally { |
| 4580 | Binder.restoreCallingIdentity(identity); |
| 4581 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4582 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 4583 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4584 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4585 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 4586 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4587 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4588 | return false; |
| 4589 | } |
| 4590 | |
| 4591 | final long identity = Binder.clearCallingIdentity(); |
| 4592 | try { |
| 4593 | CarrierConfigManager configManager = |
| 4594 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4595 | return configManager.getConfigForSubId(mPhone.getSubId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4596 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 4597 | } finally { |
| 4598 | Binder.restoreCallingIdentity(identity); |
| 4599 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4603 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 4604 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4605 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4606 | return false; |
| 4607 | } |
| 4608 | |
| 4609 | final long identity = Binder.clearCallingIdentity(); |
| 4610 | try { |
| 4611 | CarrierConfigManager configManager = |
| 4612 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4613 | return configManager.getConfigForSubId(mPhone.getSubId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4614 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 4615 | } finally { |
| 4616 | Binder.restoreCallingIdentity(identity); |
| 4617 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4618 | } |
| 4619 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4620 | @Override |
| 4621 | public boolean isTtyModeSupported() { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4622 | TelecomManager telecomManager = TelecomManager.from(mPhone.getContext()); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 4623 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | @Override |
| 4627 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4628 | final long identity = Binder.clearCallingIdentity(); |
| 4629 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4630 | return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4631 | } finally { |
| 4632 | Binder.restoreCallingIdentity(identity); |
| 4633 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4634 | } |
| 4635 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4636 | /** |
| 4637 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 4638 | * support for the feature and device firmware support. |
| 4639 | * |
| 4640 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 4641 | */ |
| 4642 | @Override |
| 4643 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4644 | final long identity = Binder.clearCallingIdentity(); |
| 4645 | try { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4646 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId( |
| 4647 | mPhone.getSubId()).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4648 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 4649 | boolean isDeviceSupported = |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4650 | mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4651 | return isCarrierSupported && isDeviceSupported; |
| 4652 | } finally { |
| 4653 | Binder.restoreCallingIdentity(identity); |
| 4654 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 4655 | } |
| 4656 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4657 | /** |
| 4658 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 4659 | * both also support RTT. |
| 4660 | */ |
| 4661 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4662 | final long identity = Binder.clearCallingIdentity(); |
| 4663 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4664 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4665 | mPhone.getContext().getContentResolver(), |
| 4666 | Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4667 | } finally { |
| 4668 | Binder.restoreCallingIdentity(identity); |
| 4669 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 4670 | } |
| 4671 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4672 | /** |
| 4673 | * Returns the unique device ID of phone, for example, the IMEI for |
| 4674 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 4675 | * |
| 4676 | * <p>Requires Permission: |
| 4677 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 4678 | */ |
| 4679 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4680 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4681 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4682 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4683 | return null; |
| 4684 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4685 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 4686 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 4687 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4688 | return null; |
| 4689 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4690 | |
| 4691 | final long identity = Binder.clearCallingIdentity(); |
| 4692 | try { |
| 4693 | return phone.getDeviceId(); |
| 4694 | } finally { |
| 4695 | Binder.restoreCallingIdentity(identity); |
| 4696 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4697 | } |
| 4698 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4699 | /** |
| 4700 | * {@hide} |
| 4701 | * Returns the IMS Registration Status on a particular subid |
| 4702 | * |
| 4703 | * @param subId |
| 4704 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4705 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4706 | Phone phone = getPhone(subId); |
| 4707 | if (phone != null) { |
| 4708 | return phone.isImsRegistered(); |
| 4709 | } else { |
| 4710 | return false; |
| 4711 | } |
| 4712 | } |
| 4713 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4714 | @Override |
| 4715 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4716 | final long identity = Binder.clearCallingIdentity(); |
| 4717 | try { |
| 4718 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 4719 | } finally { |
| 4720 | Binder.restoreCallingIdentity(identity); |
| 4721 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4722 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 4723 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4724 | /** |
| 4725 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4726 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4727 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4728 | final long identity = Binder.clearCallingIdentity(); |
| 4729 | try { |
| 4730 | Phone phone = getPhone(subId); |
| 4731 | if (phone != null) { |
| 4732 | return phone.isWifiCallingEnabled(); |
| 4733 | } else { |
| 4734 | return false; |
| 4735 | } |
| 4736 | } finally { |
| 4737 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4738 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4739 | } |
| 4740 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4741 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4742 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4743 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4744 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4745 | final long identity = Binder.clearCallingIdentity(); |
| 4746 | try { |
| 4747 | Phone phone = getPhone(subId); |
| 4748 | if (phone != null) { |
| 4749 | return phone.isVideoEnabled(); |
| 4750 | } else { |
| 4751 | return false; |
| 4752 | } |
| 4753 | } finally { |
| 4754 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4755 | } |
| 4756 | } |
| 4757 | |
| 4758 | /** |
| 4759 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 4760 | * defined in {@link ImsRegistrationImplBase}. |
| 4761 | */ |
| 4762 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4763 | final long identity = Binder.clearCallingIdentity(); |
| 4764 | try { |
| 4765 | Phone phone = getPhone(subId); |
| 4766 | if (phone != null) { |
| 4767 | return phone.getImsRegistrationTech(); |
| 4768 | } else { |
| 4769 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 4770 | } |
| 4771 | } finally { |
| 4772 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4773 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4774 | } |
| 4775 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4776 | @Override |
| 4777 | public void factoryReset(int subId) { |
| 4778 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4779 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 4780 | return; |
| 4781 | } |
| 4782 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4783 | final long identity = Binder.clearCallingIdentity(); |
| 4784 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4785 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 4786 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4787 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4788 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4789 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4790 | mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId)); |
| 4791 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4792 | } |
| 4793 | } finally { |
| 4794 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4795 | } |
| 4796 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4797 | |
| 4798 | @Override |
| 4799 | public String getLocaleFromDefaultSim() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4800 | final long identity = Binder.clearCallingIdentity(); |
| 4801 | try { |
| 4802 | // We query all subscriptions instead of just the active ones, because |
| 4803 | // this might be called early on in the provisioning flow when the |
| 4804 | // subscriptions potentially aren't active yet. |
| 4805 | final List<SubscriptionInfo> slist = getAllSubscriptionInfoList(); |
| 4806 | if (slist == null || slist.isEmpty()) { |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4807 | return null; |
| 4808 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4809 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4810 | // This function may be called very early, say, from the setup wizard, at |
| 4811 | // which point we won't have a default subscription set. If that's the case |
| 4812 | // we just choose the first, which will be valid in "most cases". |
| 4813 | final int defaultSubId = getDefaultSubscription(); |
| 4814 | SubscriptionInfo info = null; |
| 4815 | if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 4816 | info = slist.get(0); |
| 4817 | } else { |
| 4818 | for (SubscriptionInfo item : slist) { |
| 4819 | if (item.getSubscriptionId() == defaultSubId) { |
| 4820 | info = item; |
| 4821 | break; |
| 4822 | } |
| 4823 | } |
| 4824 | |
| 4825 | if (info == null) { |
| 4826 | return null; |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 4827 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4828 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4829 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4830 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 4831 | // preferences (EF-PL and EF-LI)... |
| 4832 | final int mcc = info.getMcc(); |
| 4833 | final Phone defaultPhone = getPhone(info.getSubscriptionId()); |
| 4834 | String simLanguage = null; |
| 4835 | if (defaultPhone != null) { |
| 4836 | final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs(); |
| 4837 | if (localeFromDefaultSim != null) { |
| 4838 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 4839 | if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim); |
| 4840 | return localeFromDefaultSim.toLanguageTag(); |
| 4841 | } else { |
| 4842 | simLanguage = localeFromDefaultSim.getLanguage(); |
| 4843 | } |
| 4844 | } |
| 4845 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4846 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4847 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 4848 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 4849 | // the SIM and carrier preferences does not include a country we add the country |
| 4850 | // determined from the SIM MCC to provide an exact locale. |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4851 | final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, |
| 4852 | simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4853 | if (mccLocale != null) { |
| 4854 | if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale); |
| 4855 | return mccLocale.toLanguageTag(); |
| 4856 | } |
| 4857 | |
| 4858 | if (DBG) log("No locale found - returning null"); |
| 4859 | return null; |
| 4860 | } finally { |
| 4861 | Binder.restoreCallingIdentity(identity); |
| 4862 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4866 | return mSubscriptionController.getAllSubInfoList( |
| 4867 | mPhone.getContext().getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4868 | } |
| 4869 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4870 | /** |
| 4871 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 4872 | */ |
| 4873 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4874 | return mSubscriptionController.getActiveSubscriptionInfoList( |
| 4875 | mPhone.getContext().getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4876 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4877 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4878 | private final ModemActivityInfo mLastModemActivityInfo = |
| 4879 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 4880 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4881 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4882 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 4883 | * representing the state of the modem. |
| 4884 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4885 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 4886 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4887 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4888 | */ |
| 4889 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4890 | public void requestModemActivityInfo(ResultReceiver result) { |
| 4891 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4892 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4893 | |
| 4894 | final long identity = Binder.clearCallingIdentity(); |
| 4895 | try { |
| 4896 | ModemActivityInfo ret = null; |
| 4897 | synchronized (mLastModemActivityInfo) { |
| 4898 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 4899 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4900 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 4901 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4902 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 4903 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4904 | mergedTxTimeMs[i] = |
| 4905 | info.getTxTimeMillis()[i] |
| 4906 | + mLastModemActivityInfo.getTxTimeMillis()[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4907 | } |
| 4908 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4909 | mLastModemActivityInfo.setSleepTimeMillis( |
| 4910 | info.getSleepTimeMillis() |
| 4911 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4912 | mLastModemActivityInfo.setIdleTimeMillis( |
| 4913 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 4914 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 4915 | mLastModemActivityInfo.setRxTimeMillis( |
| 4916 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 4917 | mLastModemActivityInfo.setEnergyUsed( |
| 4918 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4919 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4920 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 4921 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 4922 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 4923 | mLastModemActivityInfo.getTxTimeMillis(), |
| 4924 | mLastModemActivityInfo.getRxTimeMillis(), |
| 4925 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4926 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4927 | Bundle bundle = new Bundle(); |
| 4928 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 4929 | result.send(0, bundle); |
| 4930 | } finally { |
| 4931 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4932 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4933 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4934 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 4935 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 4936 | // less than total activity duration. |
| 4937 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 4938 | if (info == null) { |
| 4939 | return false; |
| 4940 | } |
| 4941 | int activityDurationMs = |
| 4942 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 4943 | int totalTxTimeMs = 0; |
| 4944 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 4945 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 4946 | } |
| 4947 | return (info.isValid() |
| 4948 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 4949 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 4950 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 4951 | && (totalTxTimeMs <= activityDurationMs)); |
| 4952 | } |
| 4953 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4954 | /** |
| 4955 | * {@hide} |
| 4956 | * Returns the service state information on specified subscription. |
| 4957 | */ |
| 4958 | @Override |
| 4959 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4960 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4961 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4962 | return null; |
| 4963 | } |
| 4964 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4965 | final long identity = Binder.clearCallingIdentity(); |
| 4966 | try { |
| 4967 | final Phone phone = getPhone(subId); |
| 4968 | if (phone == null) { |
| 4969 | return null; |
| 4970 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4971 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4972 | return phone.getServiceState(); |
| 4973 | } finally { |
| 4974 | Binder.restoreCallingIdentity(identity); |
| 4975 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4976 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4977 | |
| 4978 | /** |
| 4979 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 4980 | * |
| 4981 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 4982 | * voicemail ringtone. |
| 4983 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 4984 | * PhoneAccount. |
| 4985 | */ |
| 4986 | @Override |
| 4987 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4988 | final long identity = Binder.clearCallingIdentity(); |
| 4989 | try { |
| 4990 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 4991 | if (phone == null) { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 4992 | phone = mPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4993 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4994 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4995 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 4996 | } finally { |
| 4997 | Binder.restoreCallingIdentity(identity); |
| 4998 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5002 | * Sets the per-account voicemail ringtone. |
| 5003 | * |
| 5004 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5005 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5006 | * |
| 5007 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5008 | * voicemail ringtone. |
| 5009 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5010 | * PhoneAccount. |
| 5011 | */ |
| 5012 | @Override |
| 5013 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5014 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
| 5015 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5016 | if (!TextUtils.equals(callingPackage, |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 5017 | TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5018 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5019 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5020 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5021 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5022 | |
| 5023 | final long identity = Binder.clearCallingIdentity(); |
| 5024 | try { |
| 5025 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5026 | if (phone == null) { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 5027 | phone = mPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5028 | } |
| 5029 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5030 | } finally { |
| 5031 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5032 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5033 | } |
| 5034 | |
| 5035 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5036 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5037 | * |
| 5038 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5039 | * voicemail vibration setting. |
| 5040 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5041 | */ |
| 5042 | @Override |
| 5043 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5044 | final long identity = Binder.clearCallingIdentity(); |
| 5045 | try { |
| 5046 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5047 | if (phone == null) { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 5048 | phone = mPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5049 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5050 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5051 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5052 | } finally { |
| 5053 | Binder.restoreCallingIdentity(identity); |
| 5054 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5055 | } |
| 5056 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5057 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5058 | * Sets the per-account voicemail vibration. |
| 5059 | * |
| 5060 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5061 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5062 | * |
| 5063 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5064 | * voicemail vibration setting. |
| 5065 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5066 | * specific PhoneAccount. |
| 5067 | */ |
| 5068 | @Override |
| 5069 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5070 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
| 5071 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5072 | if (!TextUtils.equals(callingPackage, |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 5073 | TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5074 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5075 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5076 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5077 | } |
| 5078 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5079 | final long identity = Binder.clearCallingIdentity(); |
| 5080 | try { |
| 5081 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5082 | if (phone == null) { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 5083 | phone = mPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5084 | } |
| 5085 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5086 | } finally { |
| 5087 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5088 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5089 | } |
| 5090 | |
| 5091 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5092 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5093 | * |
| 5094 | * @throws SecurityException if the caller does not have the required permission |
| 5095 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5096 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5097 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5098 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5099 | } |
| 5100 | |
| 5101 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5102 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5103 | * permission. |
| 5104 | * |
| 5105 | * @throws SecurityException if the caller does not have the required permission |
| 5106 | */ |
| 5107 | private void enforceSendSmsPermission() { |
| 5108 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5109 | } |
| 5110 | |
| 5111 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5112 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5113 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5114 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5115 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5116 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5117 | final long identity = Binder.clearCallingIdentity(); |
| 5118 | try { |
| 5119 | ComponentName componentName = |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 5120 | RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5121 | if (componentName == null) { |
| 5122 | throw new SecurityException( |
| 5123 | "Caller not current active visual voicemail package[null]"); |
| 5124 | } |
| 5125 | String vvmPackage = componentName.getPackageName(); |
| 5126 | if (!callingPackage.equals(vvmPackage)) { |
| 5127 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5128 | + vvmPackage + "]"); |
| 5129 | } |
| 5130 | } finally { |
| 5131 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5132 | } |
| 5133 | } |
| 5134 | |
| 5135 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5136 | * Return the application ID for the app type. |
| 5137 | * |
| 5138 | * @param subId the subscription ID that this request applies to. |
| 5139 | * @param appType the uicc app type. |
| 5140 | * @return Application ID for specificied app type, or null if no uicc. |
| 5141 | */ |
| 5142 | @Override |
| 5143 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5144 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5145 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5146 | |
| 5147 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5148 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5149 | if (phone == null) { |
| 5150 | return null; |
| 5151 | } |
| 5152 | String aid = null; |
| 5153 | try { |
| 5154 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5155 | .getApplicationByType(appType).getAid(); |
| 5156 | } catch (Exception e) { |
| 5157 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5158 | } |
| 5159 | return aid; |
| 5160 | } finally { |
| 5161 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5162 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5163 | } |
| 5164 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5165 | /** |
| 5166 | * Return the Electronic Serial Number. |
| 5167 | * |
| 5168 | * @param subId the subscription ID that this request applies to. |
| 5169 | * @return ESN or null if error. |
| 5170 | */ |
| 5171 | @Override |
| 5172 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5173 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5174 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5175 | |
| 5176 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5177 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5178 | if (phone == null) { |
| 5179 | return null; |
| 5180 | } |
| 5181 | String esn = null; |
| 5182 | try { |
| 5183 | esn = phone.getEsn(); |
| 5184 | } catch (Exception e) { |
| 5185 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5186 | } |
| 5187 | return esn; |
| 5188 | } finally { |
| 5189 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5190 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5191 | } |
| 5192 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5193 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5194 | * Return the Preferred Roaming List Version. |
| 5195 | * |
| 5196 | * @param subId the subscription ID that this request applies to. |
| 5197 | * @return PRLVersion or null if error. |
| 5198 | */ |
| 5199 | @Override |
| 5200 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5201 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5202 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5203 | |
| 5204 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5205 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5206 | if (phone == null) { |
| 5207 | return null; |
| 5208 | } |
| 5209 | String cdmaPrlVersion = null; |
| 5210 | try { |
| 5211 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5212 | } catch (Exception e) { |
| 5213 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5214 | } |
| 5215 | return cdmaPrlVersion; |
| 5216 | } finally { |
| 5217 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5218 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5219 | } |
| 5220 | |
| 5221 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5222 | * Get snapshot of Telephony histograms |
| 5223 | * @return List of Telephony histograms |
| 5224 | * @hide |
| 5225 | */ |
| 5226 | @Override |
| 5227 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5228 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5229 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5230 | |
| 5231 | final long identity = Binder.clearCallingIdentity(); |
| 5232 | try { |
| 5233 | return RIL.getTelephonyRILTimingHistograms(); |
| 5234 | } finally { |
| 5235 | Binder.restoreCallingIdentity(identity); |
| 5236 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5237 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5238 | |
| 5239 | /** |
| 5240 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5241 | * Set the allowed carrier list for slotIndex |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5242 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5243 | * |
| 5244 | * @return The number of carriers set successfully, should match length of carriers |
| 5245 | */ |
| 5246 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5247 | public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5248 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5249 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5250 | |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5251 | if (carriers == null) { |
| 5252 | throw new NullPointerException("carriers cannot be null"); |
| 5253 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5254 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5255 | final long identity = Binder.clearCallingIdentity(); |
| 5256 | try { |
| 5257 | int subId = SubscriptionManager.getSubId(slotIndex)[0]; |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5258 | int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId, |
| 5259 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5260 | return retVal[0]; |
| 5261 | } finally { |
| 5262 | Binder.restoreCallingIdentity(identity); |
| 5263 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5264 | } |
| 5265 | |
| 5266 | /** |
| 5267 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5268 | * Get the allowed carrier list for slotIndex. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5269 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5270 | * |
| 5271 | * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list |
| 5272 | * means all carriers are allowed. |
| 5273 | */ |
| 5274 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5275 | public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5276 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5277 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5278 | |
| 5279 | final long identity = Binder.clearCallingIdentity(); |
| 5280 | try { |
| 5281 | int subId = SubscriptionManager.getSubId(slotIndex)[0]; |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5282 | return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId, |
| 5283 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5284 | } finally { |
| 5285 | Binder.restoreCallingIdentity(identity); |
| 5286 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5287 | } |
| 5288 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5289 | /** |
| 5290 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5291 | * @param subId the subscription ID that this action applies to. |
| 5292 | * @param enabled control enable or disable metered apns. |
| 5293 | * {@hide} |
| 5294 | */ |
| 5295 | @Override |
| 5296 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5297 | enforceModifyPermission(); |
| 5298 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5299 | |
| 5300 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5301 | if (phone == null) { |
| 5302 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5303 | return; |
| 5304 | } |
| 5305 | try { |
| 5306 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5307 | } catch (Exception e) { |
| 5308 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5309 | } finally { |
| 5310 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5311 | } |
| 5312 | } |
| 5313 | |
| 5314 | /** |
| 5315 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5316 | * @param subId the subscription ID that this action applies to. |
| 5317 | * @param enabled control enable or disable radio. |
| 5318 | * {@hide} |
| 5319 | */ |
| 5320 | @Override |
| 5321 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5322 | enforceModifyPermission(); |
| 5323 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5324 | |
| 5325 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5326 | if (phone == null) { |
| 5327 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5328 | return; |
| 5329 | } |
| 5330 | try { |
| 5331 | phone.carrierActionSetRadioEnabled(enabled); |
| 5332 | } catch (Exception e) { |
| 5333 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5334 | } finally { |
| 5335 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5336 | } |
| 5337 | } |
| 5338 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5339 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5340 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5341 | * network status based on which carrier apps could apply actions accordingly, |
| 5342 | * enable/disable default url handler for example. |
| 5343 | * |
| 5344 | * @param subId the subscription ID that this action applies to. |
| 5345 | * @param report control start/stop reporting the default network status. |
| 5346 | * {@hide} |
| 5347 | */ |
| 5348 | @Override |
| 5349 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5350 | enforceModifyPermission(); |
| 5351 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5352 | |
| 5353 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5354 | if (phone == null) { |
| 5355 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5356 | return; |
| 5357 | } |
| 5358 | try { |
| 5359 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5360 | } catch (Exception e) { |
| 5361 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5362 | } finally { |
| 5363 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5364 | } |
| 5365 | } |
| 5366 | |
| 5367 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5368 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5369 | * bug report is being generated. |
| 5370 | */ |
| 5371 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5372 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 5373 | if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5374 | != PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5375 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5376 | + Binder.getCallingPid() |
| 5377 | + ", uid=" + Binder.getCallingUid() |
| 5378 | + "without permission " |
| 5379 | + android.Manifest.permission.DUMP); |
| 5380 | return; |
| 5381 | } |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 5382 | DumpsysHandler.dump(mPhone.getContext(), fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5383 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5384 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5385 | @Override |
| 5386 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5387 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5388 | throws RemoteException { |
| 5389 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5390 | } |
| 5391 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5392 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5393 | * Get aggregated video call data usage since boot. |
| 5394 | * |
| 5395 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5396 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5397 | * {@hide} |
| 5398 | */ |
| 5399 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5400 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5401 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5402 | null); |
| 5403 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5404 | final long identity = Binder.clearCallingIdentity(); |
| 5405 | try { |
| 5406 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5407 | // records the delta with the corresponding network identity. |
| 5408 | // We just return the total video call data usage snapshot since boot. |
| 5409 | Phone phone = getPhone(subId); |
| 5410 | if (phone != null) { |
| 5411 | return phone.getVtDataUsage(perUidStats); |
| 5412 | } |
| 5413 | return null; |
| 5414 | } finally { |
| 5415 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5416 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5417 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5418 | |
| 5419 | /** |
| 5420 | * Policy control of data connection. Usually used when data limit is passed. |
| 5421 | * @param enabled True if enabling the data, otherwise disabling. |
| 5422 | * @param subId Subscription index |
| 5423 | * {@hide} |
| 5424 | */ |
| 5425 | @Override |
| 5426 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 5427 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5428 | |
| 5429 | final long identity = Binder.clearCallingIdentity(); |
| 5430 | try { |
| 5431 | Phone phone = getPhone(subId); |
| 5432 | if (phone != null) { |
| 5433 | phone.setPolicyDataEnabled(enabled); |
| 5434 | } |
| 5435 | } finally { |
| 5436 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5437 | } |
| 5438 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5439 | |
| 5440 | /** |
| 5441 | * Get Client request stats |
| 5442 | * @return List of Client Request Stats |
| 5443 | * @hide |
| 5444 | */ |
| 5445 | @Override |
| 5446 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5447 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5448 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5449 | return null; |
| 5450 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5451 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5452 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5453 | final long identity = Binder.clearCallingIdentity(); |
| 5454 | try { |
| 5455 | if (phone != null) { |
| 5456 | return phone.getClientRequestStats(); |
| 5457 | } |
| 5458 | |
| 5459 | return null; |
| 5460 | } finally { |
| 5461 | Binder.restoreCallingIdentity(identity); |
| 5462 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5463 | } |
| 5464 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5465 | private WorkSource getWorkSource(int uid) { |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 5466 | String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5467 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5468 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5469 | |
| 5470 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5471 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5472 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5473 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5474 | * @param state State of SIM (power down, power up, pass through) |
| 5475 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 5476 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 5477 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5478 | * |
| 5479 | **/ |
| 5480 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5481 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5482 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5483 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5484 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5485 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5486 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5487 | final long identity = Binder.clearCallingIdentity(); |
| 5488 | try { |
| 5489 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5490 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5491 | } |
| 5492 | } finally { |
| 5493 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5494 | } |
| 5495 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5496 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5497 | private boolean isUssdApiAllowed(int subId) { |
| 5498 | CarrierConfigManager configManager = |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 5499 | (CarrierConfigManager) mPhone.getContext().getSystemService( |
| 5500 | Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5501 | if (configManager == null) { |
| 5502 | return false; |
| 5503 | } |
| 5504 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 5505 | if (pb == null) { |
| 5506 | return false; |
| 5507 | } |
| 5508 | return pb.getBoolean( |
| 5509 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 5510 | } |
| 5511 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5512 | /** |
| 5513 | * Check if phone is in emergency callback mode |
| 5514 | * @return true if phone is in emergency callback mode |
| 5515 | * @param subId sub id |
| 5516 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 5517 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5518 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5519 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5520 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5521 | |
| 5522 | final long identity = Binder.clearCallingIdentity(); |
| 5523 | try { |
| 5524 | if (phone != null) { |
| 5525 | return phone.isInEcm(); |
| 5526 | } else { |
| 5527 | return false; |
| 5528 | } |
| 5529 | } finally { |
| 5530 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5531 | } |
| 5532 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5533 | |
| 5534 | /** |
| 5535 | * Get the current signal strength information for the given subscription. |
| 5536 | * Because this information is not updated when the device is in a low power state |
| 5537 | * it should not be relied-upon to be current. |
| 5538 | * @param subId Subscription index |
| 5539 | * @return the most recent cached signal strength info from the modem |
| 5540 | */ |
| 5541 | @Override |
| 5542 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5543 | final long identity = Binder.clearCallingIdentity(); |
| 5544 | try { |
| 5545 | Phone p = getPhone(subId); |
| 5546 | if (p == null) { |
| 5547 | return null; |
| 5548 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5549 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5550 | return p.getSignalStrength(); |
| 5551 | } finally { |
| 5552 | Binder.restoreCallingIdentity(identity); |
| 5553 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5554 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5555 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5556 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 5557 | * Get the current modem radio state for the given slot. |
| 5558 | * @param slotIndex slot index. |
| 5559 | * @param callingPackage the name of the package making the call. |
| 5560 | * @return the current radio power state from the modem |
| 5561 | */ |
| 5562 | @Override |
| 5563 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 5564 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5565 | if (phone != null) { |
| 5566 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5567 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 5568 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5569 | } |
| 5570 | |
| 5571 | final long identity = Binder.clearCallingIdentity(); |
| 5572 | try { |
| 5573 | return phone.getRadioPowerState(); |
| 5574 | } finally { |
| 5575 | Binder.restoreCallingIdentity(identity); |
| 5576 | } |
| 5577 | } |
| 5578 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5579 | } |
| 5580 | |
| 5581 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5582 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 5583 | * |
| 5584 | * <p>Requires one of the following permissions: |
| 5585 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 5586 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 5587 | * privileges. |
| 5588 | * |
| 5589 | * @param subId subscription id |
| 5590 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 5591 | * {@code false}. |
| 5592 | */ |
| 5593 | @Override |
| 5594 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5595 | boolean isEnabled = false; |
| 5596 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5597 | try { |
| 5598 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5599 | null /* message */); |
| 5600 | Phone phone = getPhone(subId); |
| 5601 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5602 | } catch (Exception e) { |
| 5603 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5604 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5605 | } finally { |
| 5606 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5607 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5608 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5609 | } |
| 5610 | |
| 5611 | |
| 5612 | /** |
| 5613 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 5614 | * |
| 5615 | * <p> Requires permission: |
| 5616 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 5617 | * privileges. |
| 5618 | * |
| 5619 | * @param subId subscription id |
| 5620 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 5621 | */ |
| 5622 | @Override |
| 5623 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5624 | final long identity = Binder.clearCallingIdentity(); |
| 5625 | try { |
| 5626 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5627 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5628 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5629 | Phone phone = getPhone(subId); |
| 5630 | if (phone != null) { |
| 5631 | phone.setDataRoamingEnabled(isEnabled); |
| 5632 | } |
| 5633 | } finally { |
| 5634 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5635 | } |
| 5636 | } |
| 5637 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5638 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 5639 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 5640 | boolean isAllowed = true; |
| 5641 | final long identity = Binder.clearCallingIdentity(); |
| 5642 | try { |
| 5643 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5644 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 5645 | Phone phone = getPhone(subId); |
| 5646 | if (phone != null) { |
| 5647 | isAllowed = phone.isCspPlmnEnabled(); |
| 5648 | } |
| 5649 | } finally { |
| 5650 | Binder.restoreCallingIdentity(identity); |
| 5651 | } |
| 5652 | return isAllowed; |
| 5653 | } |
| 5654 | |
| 5655 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5656 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5657 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5658 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5659 | final long identity = Binder.clearCallingIdentity(); |
| 5660 | try { |
| 5661 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 5662 | if (slots == null) { |
| 5663 | Rlog.i(LOG_TAG, "slots is null."); |
| 5664 | return null; |
| 5665 | } |
| 5666 | |
| 5667 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 5668 | for (int i = 0; i < slots.length; i++) { |
| 5669 | UiccSlot slot = slots[i]; |
| 5670 | if (slot == null) { |
| 5671 | continue; |
| 5672 | } |
| 5673 | |
| 5674 | String cardId; |
| 5675 | UiccCard card = slot.getUiccCard(); |
| 5676 | if (card != null) { |
| 5677 | cardId = card.getCardId(); |
| 5678 | } else { |
| 5679 | cardId = slot.getIccId(); |
| 5680 | } |
| 5681 | |
| 5682 | int cardState = 0; |
| 5683 | switch (slot.getCardState()) { |
| 5684 | case CARDSTATE_ABSENT: |
| 5685 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 5686 | break; |
| 5687 | case CARDSTATE_PRESENT: |
| 5688 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 5689 | break; |
| 5690 | case CARDSTATE_ERROR: |
| 5691 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 5692 | break; |
| 5693 | case CARDSTATE_RESTRICTED: |
| 5694 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 5695 | break; |
| 5696 | default: |
| 5697 | break; |
| 5698 | |
| 5699 | } |
| 5700 | |
| 5701 | infos[i] = new UiccSlotInfo( |
| 5702 | slot.isActive(), |
| 5703 | slot.isEuicc(), |
| 5704 | cardId, |
| 5705 | cardState, |
| 5706 | slot.getPhoneId(), |
| 5707 | slot.isExtendedApduSupported()); |
| 5708 | } |
| 5709 | return infos; |
| 5710 | } finally { |
| 5711 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 5712 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5713 | } |
| 5714 | |
| 5715 | @Override |
| 5716 | public boolean switchSlots(int[] physicalSlots) { |
| 5717 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5718 | |
| 5719 | final long identity = Binder.clearCallingIdentity(); |
| 5720 | try { |
| 5721 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 5722 | } finally { |
| 5723 | Binder.restoreCallingIdentity(identity); |
| 5724 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5725 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5726 | |
| 5727 | @Override |
| 5728 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 5729 | enforceModifyPermission(); |
| 5730 | final Phone phone = getPhone(subId); |
| 5731 | if (phone == null) { |
| 5732 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 5733 | return; |
| 5734 | } |
| 5735 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5736 | final long identity = Binder.clearCallingIdentity(); |
| 5737 | try { |
| 5738 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 5739 | } finally { |
| 5740 | Binder.restoreCallingIdentity(identity); |
| 5741 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5742 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5743 | |
| 5744 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 5745 | * A test API to reload the UICC profile. |
| 5746 | * |
| 5747 | * <p>Requires that the calling app has permission |
| 5748 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5749 | * @hide |
| 5750 | */ |
| 5751 | @Override |
| 5752 | public void refreshUiccProfile(int subId) { |
| 5753 | enforceModifyPermission(); |
| 5754 | |
| 5755 | final long identity = Binder.clearCallingIdentity(); |
| 5756 | try { |
| 5757 | Phone phone = getPhone(subId); |
| 5758 | if (phone == null) { |
| 5759 | return; |
| 5760 | } |
| 5761 | UiccCard uiccCard = phone.getUiccCard(); |
| 5762 | if (uiccCard == null) { |
| 5763 | return; |
| 5764 | } |
| 5765 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 5766 | if (uiccProfile == null) { |
| 5767 | return; |
| 5768 | } |
| 5769 | uiccProfile.refresh(); |
| 5770 | } finally { |
| 5771 | Binder.restoreCallingIdentity(identity); |
| 5772 | } |
| 5773 | } |
| 5774 | |
| 5775 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5776 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 5777 | */ |
| 5778 | private boolean getDefaultDataEnabled() { |
| 5779 | return "true".equalsIgnoreCase( |
| 5780 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 5781 | } |
| 5782 | |
| 5783 | /** |
| 5784 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 5785 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 5786 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 5787 | */ |
| 5788 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 5789 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 5790 | mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5791 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 5792 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 5793 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 5794 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 5795 | return isDataRoamingEnabled; |
| 5796 | } |
| 5797 | |
| 5798 | /** |
| 5799 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 5800 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 5801 | */ |
| 5802 | private int getDefaultNetworkType(int subId) { |
| 5803 | return Integer.parseInt( |
| 5804 | TelephonyManager.getTelephonyProperty( |
| 5805 | mSubscriptionController.getPhoneId(subId), |
| 5806 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 5807 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 5808 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5809 | |
| 5810 | @Override |
| 5811 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 5812 | gid1, String gid2, String plmn, String spn) { |
| 5813 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5814 | |
| 5815 | final long identity = Binder.clearCallingIdentity(); |
| 5816 | try { |
| 5817 | final Phone phone = getPhone(subId); |
| 5818 | if (phone == null) { |
| 5819 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 5820 | return; |
| 5821 | } |
| 5822 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 5823 | } finally { |
| 5824 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5825 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | @Override |
| 5829 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5830 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5831 | |
| 5832 | final long identity = Binder.clearCallingIdentity(); |
| 5833 | try { |
| 5834 | final Phone phone = getPhone(subId); |
| 5835 | if (phone == null) { |
| 5836 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 5837 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 5838 | } |
| 5839 | return phone.getCarrierIdListVersion(); |
| 5840 | } finally { |
| 5841 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5842 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5843 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 5844 | |
| 5845 | @Override |
| 5846 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 5847 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5848 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 5849 | return -1; |
| 5850 | } |
| 5851 | |
| 5852 | final long identity = Binder.clearCallingIdentity(); |
| 5853 | try { |
| 5854 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 5855 | } finally { |
| 5856 | Binder.restoreCallingIdentity(identity); |
| 5857 | } |
| 5858 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5859 | |
| 5860 | @Override |
| 5861 | public int getCdmaRoamingMode(int subId) { |
| 5862 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5863 | mApp, subId, "getCdmaRoamingMode"); |
| 5864 | |
| 5865 | final long identity = Binder.clearCallingIdentity(); |
| 5866 | try { |
| 5867 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 5868 | } finally { |
| 5869 | Binder.restoreCallingIdentity(identity); |
| 5870 | } |
| 5871 | } |
| 5872 | |
| 5873 | @Override |
| 5874 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 5875 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5876 | mApp, subId, "setCdmaRoamingMode"); |
| 5877 | |
| 5878 | final long identity = Binder.clearCallingIdentity(); |
| 5879 | try { |
| 5880 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 5881 | } finally { |
| 5882 | Binder.restoreCallingIdentity(identity); |
| 5883 | } |
| 5884 | } |
| 5885 | |
| 5886 | @Override |
| 5887 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 5888 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5889 | mApp, subId, "setCdmaSubscriptionMode"); |
| 5890 | |
| 5891 | final long identity = Binder.clearCallingIdentity(); |
| 5892 | try { |
| 5893 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 5894 | } finally { |
| 5895 | Binder.restoreCallingIdentity(identity); |
| 5896 | } |
| 5897 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 5898 | |
| 5899 | private void ensureUserRunning(int userId) { |
| 5900 | if (!mUserManager.isUserRunning(userId)) { |
| 5901 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 5902 | } |
| 5903 | } |
| 5904 | |
| 5905 | /** |
| 5906 | * Returns a list of SMS apps on a given user. |
| 5907 | * |
| 5908 | * Only the shell user (UID 2000 or 0) can call it. |
| 5909 | * Target user must be running. |
| 5910 | */ |
| 5911 | @Override |
| 5912 | public String[] getSmsApps(int userId) { |
| 5913 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 5914 | ensureUserRunning(userId); |
| 5915 | |
| 5916 | final Collection<SmsApplicationData> apps = |
| 5917 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 5918 | |
| 5919 | String[] ret = new String[apps.size()]; |
| 5920 | int i = 0; |
| 5921 | for (SmsApplicationData app : apps) { |
| 5922 | ret[i++] = app.mPackageName; |
| 5923 | } |
| 5924 | return ret; |
| 5925 | } |
| 5926 | |
| 5927 | /** |
| 5928 | * Returns the default SMS app package name on a given user. |
| 5929 | * |
| 5930 | * Only the shell user (UID 2000 or 0) can call it. |
| 5931 | * Target user must be running. |
| 5932 | */ |
| 5933 | @Override |
| 5934 | public String getDefaultSmsApp(int userId) { |
| 5935 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 5936 | ensureUserRunning(userId); |
| 5937 | |
| 5938 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 5939 | /* updateIfNeeded= */ true, userId); |
| 5940 | return cn == null ? null : cn.getPackageName(); |
| 5941 | } |
| 5942 | |
| 5943 | /** |
| 5944 | * Set a package as the default SMS app on a given user. |
| 5945 | * |
| 5946 | * Only the shell user (UID 2000 or 0) can call it. |
| 5947 | * Target user must be running. |
| 5948 | */ |
| 5949 | @Override |
| 5950 | public void setDefaultSmsApp(int userId, String packageName) { |
| 5951 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 5952 | ensureUserRunning(userId); |
| 5953 | |
| 5954 | boolean found = false; |
| 5955 | for (String pkg : getSmsApps(userId)) { |
| 5956 | if (TextUtils.equals(packageName, pkg)) { |
| 5957 | found = true; |
| 5958 | break; |
| 5959 | } |
| 5960 | } |
| 5961 | if (!found) { |
| 5962 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 5963 | } |
| 5964 | |
| 5965 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 5966 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 5967 | |
| 5968 | @Override |
| 5969 | public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList( |
| 5970 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 5971 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5972 | mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) { |
| 5973 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 5974 | } |
| 5975 | final long identity = Binder.clearCallingIdentity(); |
| 5976 | try { |
| 5977 | Map<Integer, List<EmergencyNumber>> results = getEmergencyNumberListInternal(); |
| 5978 | // Use ecclist to construct Emergency number list for backward compatibality |
| 5979 | if (results.isEmpty()) { |
| 5980 | results = getEmergencyNumberListFromEccList(); |
| 5981 | } |
| 5982 | return results; |
| 5983 | } finally { |
| 5984 | Binder.restoreCallingIdentity(identity); |
| 5985 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | @Override |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 5989 | public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) { |
| 5990 | if (!exactMatch) { |
| 5991 | TelephonyPermissions |
| 5992 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5993 | mApp, mPhone.getSubId(), "isCurrentEmergencyNumber(Potential)"); |
| 5994 | } |
| 5995 | final long identity = Binder.clearCallingIdentity(); |
| 5996 | try { |
| 5997 | Map<Integer, List<EmergencyNumber>> emergencyNumberLists = |
| 5998 | getEmergencyNumberListInternal(); |
| 5999 | |
| 6000 | String defaultCountryIso = getNetworkCountryIsoForPhone(mPhone.getPhoneId()); |
| 6001 | |
| 6002 | if (!emergencyNumberLists.isEmpty()) { |
| 6003 | for (List<EmergencyNumber> emergencyNumberList : emergencyNumberLists.values()) { |
| 6004 | if (emergencyNumberList != null) { |
| 6005 | for (EmergencyNumber num : emergencyNumberList) { |
| 6006 | // According to com.android.i18n.phonenumbers.ShortNumberInfo, in |
| 6007 | // these countries, if extra digits are added to an emergency number, |
| 6008 | // it no longer connects to the emergency service. |
| 6009 | Set<String> countriesRequiredForExactMatch = new HashSet<>(); |
| 6010 | countriesRequiredForExactMatch.add("br"); |
| 6011 | countriesRequiredForExactMatch.add("cl"); |
| 6012 | countriesRequiredForExactMatch.add("ni"); |
| 6013 | if (exactMatch || countriesRequiredForExactMatch.contains( |
| 6014 | defaultCountryIso)) { |
| 6015 | if (num.getNumber().equals(number)) { |
| 6016 | return true; |
| 6017 | } |
| 6018 | } else { |
| 6019 | if (number.startsWith(num.getNumber())) { |
| 6020 | return true; |
| 6021 | } |
| 6022 | } |
| 6023 | |
| 6024 | } |
| 6025 | } |
| 6026 | } |
| 6027 | } else { |
| 6028 | // For backward compatibility for devices launched before Q |
| 6029 | return PhoneNumberUtils.isEmergencyNumberInternal(number, exactMatch, |
| 6030 | defaultCountryIso); |
| 6031 | } |
| 6032 | return false; |
| 6033 | } finally { |
| 6034 | Binder.restoreCallingIdentity(identity); |
| 6035 | } |
| 6036 | } |
| 6037 | |
| 6038 | private Map<Integer, List<EmergencyNumber>> getEmergencyNumberListInternal() { |
| 6039 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6040 | |
| 6041 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6042 | if (phone.getEmergencyNumberTracker() != null |
| 6043 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6044 | emergencyNumberListInternal.put( |
| 6045 | phone.getSubId(), |
| 6046 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6047 | } |
| 6048 | } |
| 6049 | return emergencyNumberListInternal; |
| 6050 | } |
| 6051 | |
| 6052 | private List<EmergencyNumber> getEmergencyNumberListFromEccList(int subscriptionId) { |
| 6053 | SubscriptionManager sm = (SubscriptionManager) mPhone.getContext().getSystemService( |
| 6054 | Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6055 | List<EmergencyNumber> emergencyNumberList = new ArrayList<>(); |
| 6056 | int slotId = sm.getSlotIndex(subscriptionId); |
| 6057 | |
| 6058 | String ecclist = (slotId <= 0) ? "ril.ecclist" : ("ril.ecclist" + slotId); |
| 6059 | String emergencyNumbers = SystemProperties.get(ecclist, ""); |
| 6060 | if (TextUtils.isEmpty(emergencyNumbers)) { |
| 6061 | // then read-only ecclist property since old RIL only uses this |
| 6062 | emergencyNumbers = SystemProperties.get("ro.ril.ecclist"); |
| 6063 | } |
| 6064 | if (!TextUtils.isEmpty(emergencyNumbers)) { |
| 6065 | // searches through the comma-separated list for a match, |
| 6066 | // return true if one is found. |
| 6067 | for (String emergencyNum : emergencyNumbers.split(",")) { |
| 6068 | emergencyNumberList.add(new EmergencyNumber(emergencyNum, "", "", |
| 6069 | EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, 0)); |
| 6070 | } |
| 6071 | } |
| 6072 | emergencyNumbers = ((slotId < 0) ? "112,911,000,08,110,118,119,999" : "112,911"); |
| 6073 | for (String emergencyNum : emergencyNumbers.split(",")) { |
| 6074 | emergencyNumberList.add(new EmergencyNumber(emergencyNum, "", "", |
| 6075 | EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, 0)); |
| 6076 | } |
| 6077 | EmergencyNumber.mergeSameNumbersInEmergencyNumberList(emergencyNumberList); |
| 6078 | return emergencyNumberList; |
| 6079 | } |
| 6080 | |
| 6081 | /** |
| 6082 | * Get Emergency number list based on EccList. This util is used for solving backward |
| 6083 | * compatibility if device does not support the 1.4 IRadioIndication HAL that reports |
| 6084 | * emergency number list. |
| 6085 | * |
| 6086 | * @return Map including the key as the active subscription ID (Note: if there is no active |
| 6087 | * subscription, the key is {@link SubscriptionManager#getDefaultSubscriptionId}) |
| 6088 | * and the value as the list of {@link EmergencyNumber}. |
| 6089 | */ |
| 6090 | private Map<Integer, List<EmergencyNumber>> getEmergencyNumberListFromEccList() { |
| 6091 | Map<Integer, List<EmergencyNumber>> results = new HashMap<>(); |
| 6092 | SubscriptionManager sm = (SubscriptionManager) mPhone.getContext().getSystemService( |
| 6093 | Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6094 | int[] activeSubscriptionIds = sm.getActiveSubscriptionIdList(); |
| 6095 | |
| 6096 | if (activeSubscriptionIds.length == 0) { |
| 6097 | int defaultSubscriptionId = getDefaultSubscription(); |
| 6098 | results.put(defaultSubscriptionId, |
| 6099 | getEmergencyNumberListFromEccList(defaultSubscriptionId)); |
| 6100 | } else { |
| 6101 | for (int activeSubscriptionId : activeSubscriptionIds) { |
| 6102 | results.put(activeSubscriptionId, |
| 6103 | getEmergencyNumberListFromEccList(activeSubscriptionId)); |
| 6104 | } |
| 6105 | } |
| 6106 | return results; |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6107 | } |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6108 | |
| 6109 | @Override |
| 6110 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6111 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6112 | Phone phone = getPhone(subId); |
| 6113 | if (phone == null) { |
| 6114 | return null; |
| 6115 | } |
| 6116 | final long identity = Binder.clearCallingIdentity(); |
| 6117 | try { |
| 6118 | UiccProfile profile = UiccController.getInstance() |
| 6119 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6120 | if (profile != null) { |
| 6121 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6122 | } |
| 6123 | } finally { |
| 6124 | Binder.restoreCallingIdentity(identity); |
| 6125 | } |
| 6126 | return null; |
| 6127 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6128 | } |