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 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 19 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 20 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 21 | import android.Manifest.permission; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 22 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 23 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 24 | import android.content.ComponentName; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 27 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 28 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 29 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 30 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 31 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 32 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 33 | import android.net.Uri; |
| 34 | import android.os.AsyncResult; |
| 35 | import android.os.Binder; |
| 36 | import android.os.Bundle; |
| 37 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 38 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.os.Looper; |
| 40 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 41 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 42 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 43 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 44 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 46 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 47 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 49 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 50 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 51 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 52 | import android.provider.Settings; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 53 | import android.service.carrier.CarrierIdentifier; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 54 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 55 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 56 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 57 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 59 | import android.telephony.CellInfoGsm; |
| 60 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 61 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 62 | import android.telephony.ClientRequestStats; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 63 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 64 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 65 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 66 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 67 | import android.telephony.NetworkScanRequest; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 68 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 69 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 71 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 72 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 73 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 74 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 75 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 76 | import android.telephony.TelephonyManager; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 77 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 78 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 79 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 80 | import android.telephony.cdma.CdmaCellLocation; |
| 81 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 82 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 83 | import android.telephony.ims.aidl.IImsConfig; |
| 84 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 85 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 86 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 87 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 88 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 89 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 90 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 91 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 92 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 93 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 94 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 95 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 96 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 97 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 98 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 99 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 100 | import com.android.internal.telephony.CarrierInfoManager; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 101 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 102 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 103 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 105 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 106 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 107 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 108 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 109 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 110 | import com.android.internal.telephony.Phone; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 111 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 112 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 113 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 114 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 115 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.ServiceStateTracker; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 119 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 120 | import com.android.internal.telephony.TelephonyPermissions; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.euicc.EuiccConnector; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.uicc.IccIoResult; |
| 123 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 126 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 128 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 129 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 131 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 132 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 133 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 134 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 135 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 136 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 137 | import java.io.FileDescriptor; |
| 138 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 139 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 141 | import java.util.Arrays; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 142 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 143 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 144 | import java.util.Map; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * Implementation of the ITelephony interface. |
| 148 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 149 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 150 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 151 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 152 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 153 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 154 | |
| 155 | // Message codes used with mMainThreadHandler |
| 156 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 157 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 158 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 159 | private static final int CMD_OPEN_CHANNEL = 9; |
| 160 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 161 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 162 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 163 | private static final int CMD_NV_READ_ITEM = 13; |
| 164 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 165 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 166 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 167 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 168 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 169 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 170 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 171 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 172 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 173 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 174 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 175 | private static final int CMD_SEND_ENVELOPE = 25; |
| 176 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 177 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 178 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 179 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 180 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 181 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 182 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 183 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 184 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 185 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 186 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 187 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 188 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 189 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 190 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 191 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 192 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 193 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 194 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 195 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 196 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 197 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 198 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 199 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 200 | private static final int CMD_SWITCH_SLOTS = 50; |
| 201 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 202 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 203 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 204 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 205 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 206 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 207 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 208 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 209 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 210 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 211 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 212 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 213 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 214 | private static final int CMD_MODEM_REBOOT = 64; |
| 215 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 216 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 217 | // Parameters of select command. |
| 218 | private static final int SELECT_COMMAND = 0xA4; |
| 219 | private static final int SELECT_P1 = 0x04; |
| 220 | private static final int SELECT_P2 = 0; |
| 221 | private static final int SELECT_P3 = 0x10; |
| 222 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 223 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 224 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 225 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 226 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 227 | /** The singleton instance. */ |
| 228 | private static PhoneInterfaceManager sInstance; |
| 229 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 230 | private PhoneGlobals mApp; |
| 231 | private Phone mPhone; |
| 232 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 233 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 234 | private AppOpsManager mAppOps; |
| 235 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 236 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 237 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 238 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 239 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 240 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 241 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 242 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 243 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 244 | // The AID of ISD-R. |
| 245 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 246 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 247 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 248 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 249 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 250 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 251 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 252 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 253 | * A request object to use for transmitting data to an ICC. |
| 254 | */ |
| 255 | private static final class IccAPDUArgument { |
| 256 | public int channel, cla, command, p1, p2, p3; |
| 257 | public String data; |
| 258 | |
| 259 | public IccAPDUArgument(int channel, int cla, int command, |
| 260 | int p1, int p2, int p3, String data) { |
| 261 | this.channel = channel; |
| 262 | this.cla = cla; |
| 263 | this.command = command; |
| 264 | this.p1 = p1; |
| 265 | this.p2 = p2; |
| 266 | this.p3 = p3; |
| 267 | this.data = data; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 272 | * A request object to use for transmitting data to an ICC. |
| 273 | */ |
| 274 | private static final class ManualNetworkSelectionArgument { |
| 275 | public OperatorInfo operatorInfo; |
| 276 | public boolean persistSelection; |
| 277 | |
| 278 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 279 | this.operatorInfo = operatorInfo; |
| 280 | this.persistSelection = persistSelection; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 285 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 286 | * request after sending. The main thread will notify the request when it is complete. |
| 287 | */ |
| 288 | private static final class MainThreadRequest { |
| 289 | /** The argument to use for the request */ |
| 290 | public Object argument; |
| 291 | /** The result of the request that is run on the main thread */ |
| 292 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 293 | // The subscriber id that this request applies to. Defaults to |
| 294 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 295 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 296 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 297 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 298 | public Phone phone; |
| 299 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 300 | public WorkSource workSource; |
| 301 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 302 | public MainThreadRequest(Object argument) { |
| 303 | this.argument = argument; |
| 304 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 305 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 306 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 307 | this.argument = argument; |
| 308 | if (phone != null) { |
| 309 | this.phone = phone; |
| 310 | } |
| 311 | this.workSource = workSource; |
| 312 | } |
| 313 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 314 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 315 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 316 | if (subId != null) { |
| 317 | this.subId = subId; |
| 318 | } |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 319 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 320 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 323 | private static final class IncomingThirdPartyCallArgs { |
| 324 | public final ComponentName component; |
| 325 | public final String callId; |
| 326 | public final String callerDisplayName; |
| 327 | |
| 328 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 329 | String callerDisplayName) { |
| 330 | this.component = component; |
| 331 | this.callId = callId; |
| 332 | this.callerDisplayName = callerDisplayName; |
| 333 | } |
| 334 | } |
| 335 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 336 | /** |
| 337 | * A handler that processes messages on the main thread in the phone process. Since many |
| 338 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 339 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 340 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 341 | * on, which will be notified when the operation completes and will contain the result of the |
| 342 | * request. |
| 343 | * |
| 344 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 345 | * note that request.result must be set to something non-null for the calling thread to |
| 346 | * unblock. |
| 347 | */ |
| 348 | private final class MainThreadHandler extends Handler { |
| 349 | @Override |
| 350 | public void handleMessage(Message msg) { |
| 351 | MainThreadRequest request; |
| 352 | Message onCompleted; |
| 353 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 354 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 355 | IccAPDUArgument iccArgument; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 356 | |
| 357 | switch (msg.what) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 358 | case CMD_HANDLE_USSD_REQUEST: { |
| 359 | request = (MainThreadRequest) msg.obj; |
| 360 | final Phone phone = getPhoneFromRequest(request); |
| 361 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 362 | String ussdRequest = ussdObject.first; |
| 363 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 364 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 365 | if (!isUssdApiAllowed(request.subId)) { |
| 366 | // Carrier does not support use of this API, return failure. |
| 367 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 368 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 369 | Bundle returnData = new Bundle(); |
| 370 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 371 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 372 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 373 | request.result = true; |
| 374 | notifyRequester(request); |
| 375 | return; |
| 376 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 377 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 378 | try { |
| 379 | request.result = phone != null |
| 380 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 381 | } catch (CallStateException cse) { |
| 382 | request.result = false; |
| 383 | } |
| 384 | // Wake up the requesting thread |
| 385 | notifyRequester(request); |
| 386 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 389 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 390 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 391 | final Phone phone = getPhoneFromRequest(request); |
| 392 | request.result = phone != null ? |
| 393 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 394 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 395 | // Wake up the requesting thread |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 396 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 397 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 398 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 399 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 400 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 401 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 402 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 403 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 404 | if (uiccCard == null) { |
| 405 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 406 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 407 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 408 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 409 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 410 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 411 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 412 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 413 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 414 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 415 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 416 | break; |
| 417 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 418 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 419 | ar = (AsyncResult) msg.obj; |
| 420 | request = (MainThreadRequest) ar.userObj; |
| 421 | if (ar.exception == null && ar.result != null) { |
| 422 | request.result = ar.result; |
| 423 | } else { |
| 424 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 425 | if (ar.result == null) { |
| 426 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 427 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 428 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 429 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 430 | } else { |
| 431 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 432 | } |
| 433 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 434 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 435 | break; |
| 436 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 437 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 438 | request = (MainThreadRequest) msg.obj; |
| 439 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 440 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 441 | if (uiccCard == null) { |
| 442 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 443 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 444 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 445 | } else { |
| 446 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 447 | request); |
| 448 | uiccCard.iccTransmitApduBasicChannel( |
| 449 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 450 | iccArgument.p3, iccArgument.data, onCompleted); |
| 451 | } |
| 452 | break; |
| 453 | |
| 454 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 455 | ar = (AsyncResult) msg.obj; |
| 456 | request = (MainThreadRequest) ar.userObj; |
| 457 | if (ar.exception == null && ar.result != null) { |
| 458 | request.result = ar.result; |
| 459 | } else { |
| 460 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 461 | if (ar.result == null) { |
| 462 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 463 | } else if (ar.exception instanceof CommandException) { |
| 464 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 465 | ar.exception); |
| 466 | } else { |
| 467 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 468 | } |
| 469 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 470 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 471 | break; |
| 472 | |
| 473 | case CMD_EXCHANGE_SIM_IO: |
| 474 | request = (MainThreadRequest) msg.obj; |
| 475 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 476 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 477 | if (uiccCard == null) { |
| 478 | loge("iccExchangeSimIO: No UICC"); |
| 479 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 480 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 481 | } else { |
| 482 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 483 | request); |
| 484 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 485 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 486 | iccArgument.data, onCompleted); |
| 487 | } |
| 488 | break; |
| 489 | |
| 490 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 491 | ar = (AsyncResult) msg.obj; |
| 492 | request = (MainThreadRequest) ar.userObj; |
| 493 | if (ar.exception == null && ar.result != null) { |
| 494 | request.result = ar.result; |
| 495 | } else { |
| 496 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 497 | } |
Pengquan Meng | 0c05b50 | 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 | break; |
| 500 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 501 | case CMD_SEND_ENVELOPE: |
| 502 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 503 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 504 | if (uiccCard == null) { |
| 505 | loge("sendEnvelopeWithStatus: No UICC"); |
| 506 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 507 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 508 | } else { |
| 509 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 510 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 511 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 512 | break; |
| 513 | |
| 514 | case EVENT_SEND_ENVELOPE_DONE: |
| 515 | ar = (AsyncResult) msg.obj; |
| 516 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 517 | if (ar.exception == null && ar.result != null) { |
| 518 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 519 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 520 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 521 | if (ar.result == null) { |
| 522 | loge("sendEnvelopeWithStatus: Empty response"); |
| 523 | } else if (ar.exception instanceof CommandException) { |
| 524 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 525 | ar.exception); |
| 526 | } else { |
| 527 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 528 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 529 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 530 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 531 | break; |
| 532 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 533 | case CMD_OPEN_CHANNEL: |
| 534 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 535 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 536 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 537 | if (uiccCard == null) { |
| 538 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 539 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 540 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 541 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 542 | } else { |
| 543 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 544 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 545 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 546 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 547 | break; |
| 548 | |
| 549 | case EVENT_OPEN_CHANNEL_DONE: |
| 550 | ar = (AsyncResult) msg.obj; |
| 551 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 552 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 553 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 554 | int[] result = (int[]) ar.result; |
| 555 | int channelId = result[0]; |
| 556 | byte[] selectResponse = null; |
| 557 | if (result.length > 1) { |
| 558 | selectResponse = new byte[result.length - 1]; |
| 559 | for (int i = 1; i < result.length; ++i) { |
| 560 | selectResponse[i - 1] = (byte) result[i]; |
| 561 | } |
| 562 | } |
| 563 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 564 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 565 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 566 | if (ar.result == null) { |
| 567 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 568 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 569 | if (ar.exception != null) { |
| 570 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 571 | } |
| 572 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 573 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 574 | if (ar.exception instanceof CommandException) { |
| 575 | CommandException.Error error = |
| 576 | ((CommandException) (ar.exception)).getCommandError(); |
| 577 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 578 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 579 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 580 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 584 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 585 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 586 | request.result = openChannelResp; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 587 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 588 | break; |
| 589 | |
| 590 | case CMD_CLOSE_CHANNEL: |
| 591 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 592 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 593 | if (uiccCard == null) { |
| 594 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 595 | request.result = false; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 596 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 597 | } else { |
| 598 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 599 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 600 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 601 | break; |
| 602 | |
| 603 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 604 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 605 | break; |
| 606 | |
| 607 | case CMD_NV_READ_ITEM: |
| 608 | request = (MainThreadRequest) msg.obj; |
| 609 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 610 | mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 611 | break; |
| 612 | |
| 613 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 614 | ar = (AsyncResult) msg.obj; |
| 615 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 616 | if (ar.exception == null && ar.result != null) { |
| 617 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 618 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 619 | request.result = ""; |
| 620 | if (ar.result == null) { |
| 621 | loge("nvReadItem: Empty response"); |
| 622 | } else if (ar.exception instanceof CommandException) { |
| 623 | loge("nvReadItem: CommandException: " + |
| 624 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 625 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 626 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 627 | } |
| 628 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 630 | break; |
| 631 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 632 | case CMD_NV_WRITE_ITEM: |
| 633 | request = (MainThreadRequest) msg.obj; |
| 634 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 635 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 636 | mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
| 637 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 638 | break; |
| 639 | |
| 640 | case EVENT_NV_WRITE_ITEM_DONE: |
| 641 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 642 | break; |
| 643 | |
| 644 | case CMD_NV_WRITE_CDMA_PRL: |
| 645 | request = (MainThreadRequest) msg.obj; |
| 646 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
| 647 | mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
| 648 | break; |
| 649 | |
| 650 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 651 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 652 | break; |
| 653 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 654 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 655 | request = (MainThreadRequest) msg.obj; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 656 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
| 657 | mPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 658 | break; |
| 659 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 660 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 661 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 662 | break; |
| 663 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 664 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 665 | request = (MainThreadRequest) msg.obj; |
| 666 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 667 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 668 | break; |
| 669 | |
| 670 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 671 | ar = (AsyncResult) msg.obj; |
| 672 | request = (MainThreadRequest) ar.userObj; |
| 673 | if (ar.exception == null && ar.result != null) { |
| 674 | request.result = ar.result; // Integer |
| 675 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 676 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 677 | if (ar.result == null) { |
| 678 | loge("getPreferredNetworkType: Empty response"); |
| 679 | } else if (ar.exception instanceof CommandException) { |
| 680 | loge("getPreferredNetworkType: CommandException: " + |
| 681 | ar.exception); |
| 682 | } else { |
| 683 | loge("getPreferredNetworkType: Unknown exception"); |
| 684 | } |
| 685 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 686 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 687 | break; |
| 688 | |
| 689 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 690 | request = (MainThreadRequest) msg.obj; |
| 691 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 692 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 693 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 694 | break; |
| 695 | |
| 696 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 697 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 698 | break; |
| 699 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 700 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 701 | request = (MainThreadRequest)msg.obj; |
| 702 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 703 | mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 704 | break; |
| 705 | |
| 706 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 707 | ar = (AsyncResult)msg.obj; |
| 708 | request = (MainThreadRequest)ar.userObj; |
| 709 | request.result = ar; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 710 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 711 | break; |
| 712 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 713 | case CMD_SET_VOICEMAIL_NUMBER: |
| 714 | request = (MainThreadRequest) msg.obj; |
| 715 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 716 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 717 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 718 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 719 | break; |
| 720 | |
| 721 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 722 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 723 | break; |
| 724 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 725 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 726 | request = (MainThreadRequest) msg.obj; |
| 727 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 728 | request); |
| 729 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 730 | break; |
| 731 | |
| 732 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 733 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 734 | break; |
| 735 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 736 | case CMD_PERFORM_NETWORK_SCAN: |
| 737 | request = (MainThreadRequest) msg.obj; |
| 738 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 739 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 740 | break; |
| 741 | |
| 742 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 743 | ar = (AsyncResult) msg.obj; |
| 744 | request = (MainThreadRequest) ar.userObj; |
| 745 | CellNetworkScanResult cellScanResult; |
| 746 | if (ar.exception == null && ar.result != null) { |
| 747 | cellScanResult = new CellNetworkScanResult( |
| 748 | CellNetworkScanResult.STATUS_SUCCESS, |
| 749 | (List<OperatorInfo>) ar.result); |
| 750 | } else { |
| 751 | if (ar.result == null) { |
| 752 | loge("getCellNetworkScanResults: Empty response"); |
| 753 | } |
| 754 | if (ar.exception != null) { |
| 755 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 756 | } |
| 757 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 758 | if (ar.exception instanceof CommandException) { |
| 759 | CommandException.Error error = |
| 760 | ((CommandException) (ar.exception)).getCommandError(); |
| 761 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 762 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 763 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 764 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 765 | } |
| 766 | } |
| 767 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 768 | } |
| 769 | request.result = cellScanResult; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 770 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 771 | break; |
| 772 | |
| 773 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 774 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 775 | ManualNetworkSelectionArgument selArg = |
| 776 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 777 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 778 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 779 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 780 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 781 | break; |
| 782 | |
| 783 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 784 | ar = (AsyncResult) msg.obj; |
| 785 | request = (MainThreadRequest) ar.userObj; |
| 786 | if (ar.exception == null) { |
| 787 | request.result = true; |
| 788 | } else { |
| 789 | request.result = false; |
| 790 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 791 | } |
| 792 | notifyRequester(request); |
| 793 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 794 | break; |
| 795 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 796 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 797 | request = (MainThreadRequest) msg.obj; |
| 798 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 799 | mPhone.getModemActivityInfo(onCompleted, request.workSource); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 800 | break; |
| 801 | |
| 802 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 803 | ar = (AsyncResult) msg.obj; |
| 804 | request = (MainThreadRequest) ar.userObj; |
| 805 | if (ar.exception == null && ar.result != null) { |
| 806 | request.result = ar.result; |
| 807 | } else { |
| 808 | if (ar.result == null) { |
| 809 | loge("queryModemActivityInfo: Empty response"); |
| 810 | } else if (ar.exception instanceof CommandException) { |
| 811 | loge("queryModemActivityInfo: CommandException: " + |
| 812 | ar.exception); |
| 813 | } else { |
| 814 | loge("queryModemActivityInfo: Unknown exception"); |
| 815 | } |
| 816 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 817 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 818 | if (request.result == null) { |
| 819 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 820 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 821 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 822 | break; |
| 823 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 824 | case CMD_SET_ALLOWED_CARRIERS: |
| 825 | request = (MainThreadRequest) msg.obj; |
| 826 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
| 827 | mPhone.setAllowedCarriers( |
| 828 | (List<CarrierIdentifier>) request.argument, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 829 | onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 830 | break; |
| 831 | |
| 832 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 833 | ar = (AsyncResult) msg.obj; |
| 834 | request = (MainThreadRequest) ar.userObj; |
| 835 | if (ar.exception == null && ar.result != null) { |
| 836 | request.result = ar.result; |
| 837 | } else { |
| 838 | if (ar.result == null) { |
| 839 | loge("setAllowedCarriers: Empty response"); |
| 840 | } else if (ar.exception instanceof CommandException) { |
| 841 | loge("setAllowedCarriers: CommandException: " + |
| 842 | ar.exception); |
| 843 | } else { |
| 844 | loge("setAllowedCarriers: Unknown exception"); |
| 845 | } |
| 846 | } |
| 847 | // Result cannot be null. Return -1 on error. |
| 848 | if (request.result == null) { |
| 849 | request.result = new int[]{-1}; |
| 850 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 851 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 852 | break; |
| 853 | |
| 854 | case CMD_GET_ALLOWED_CARRIERS: |
| 855 | request = (MainThreadRequest) msg.obj; |
| 856 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 857 | mPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 858 | break; |
| 859 | |
| 860 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 861 | ar = (AsyncResult) msg.obj; |
| 862 | request = (MainThreadRequest) ar.userObj; |
| 863 | if (ar.exception == null && ar.result != null) { |
| 864 | request.result = ar.result; |
| 865 | } else { |
| 866 | if (ar.result == null) { |
| 867 | loge("getAllowedCarriers: Empty response"); |
| 868 | } else if (ar.exception instanceof CommandException) { |
| 869 | loge("getAllowedCarriers: CommandException: " + |
| 870 | ar.exception); |
| 871 | } else { |
| 872 | loge("getAllowedCarriers: Unknown exception"); |
| 873 | } |
| 874 | } |
| 875 | // Result cannot be null. Return empty list of CarrierIdentifier. |
| 876 | if (request.result == null) { |
| 877 | request.result = new ArrayList<CarrierIdentifier>(0); |
| 878 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 879 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 880 | break; |
| 881 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 882 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 883 | ar = (AsyncResult) msg.obj; |
| 884 | request = (MainThreadRequest) ar.userObj; |
| 885 | if (ar.exception == null && ar.result != null) { |
| 886 | request.result = ar.result; |
| 887 | } else { |
| 888 | request.result = new IllegalArgumentException( |
| 889 | "Failed to retrieve Forbidden Plmns"); |
| 890 | if (ar.result == null) { |
| 891 | loge("getForbiddenPlmns: Empty response"); |
| 892 | } else { |
| 893 | loge("getForbiddenPlmns: Unknown exception"); |
| 894 | } |
| 895 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 896 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 897 | break; |
| 898 | |
| 899 | case CMD_GET_FORBIDDEN_PLMNS: |
| 900 | request = (MainThreadRequest) msg.obj; |
| 901 | uiccCard = getUiccCardFromRequest(request); |
| 902 | if (uiccCard == null) { |
| 903 | loge("getForbiddenPlmns() UiccCard is null"); |
| 904 | request.result = new IllegalArgumentException( |
| 905 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 906 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 907 | break; |
| 908 | } |
| 909 | Integer appType = (Integer) request.argument; |
| 910 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 911 | if (uiccApp == null) { |
| 912 | loge("getForbiddenPlmns() no app with specified type -- " |
| 913 | + appType); |
| 914 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 915 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 916 | break; |
| 917 | } else { |
| 918 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 919 | + " specified type -- " + appType); |
| 920 | } |
| 921 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 922 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 923 | onCompleted); |
| 924 | break; |
| 925 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 926 | case CMD_SWITCH_SLOTS: |
| 927 | request = (MainThreadRequest) msg.obj; |
| 928 | int[] physicalSlots = (int[]) request.argument; |
| 929 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 930 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 931 | break; |
| 932 | |
| 933 | case EVENT_SWITCH_SLOTS_DONE: |
| 934 | ar = (AsyncResult) msg.obj; |
| 935 | request = (MainThreadRequest) ar.userObj; |
| 936 | request.result = (ar.exception == null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 937 | notifyRequester(request); |
| 938 | break; |
| 939 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 940 | request = (MainThreadRequest) msg.obj; |
| 941 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 942 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 943 | break; |
| 944 | |
| 945 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 946 | ar = (AsyncResult) msg.obj; |
| 947 | request = (MainThreadRequest) ar.userObj; |
| 948 | if (ar.exception != null) { |
| 949 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 950 | } else { |
| 951 | int mode = ((int[]) ar.result)[0]; |
| 952 | if (mode == 0) { |
| 953 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 954 | } else { |
| 955 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 956 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 957 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 958 | notifyRequester(request); |
| 959 | break; |
| 960 | case CMD_GET_CDMA_ROAMING_MODE: |
| 961 | request = (MainThreadRequest) msg.obj; |
| 962 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 963 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 964 | break; |
| 965 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 966 | ar = (AsyncResult) msg.obj; |
| 967 | request = (MainThreadRequest) ar.userObj; |
| 968 | if (ar.exception != null) { |
| 969 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 970 | } else { |
| 971 | request.result = ((int[]) ar.result)[0]; |
| 972 | } |
| 973 | notifyRequester(request); |
| 974 | break; |
| 975 | case CMD_SET_CDMA_ROAMING_MODE: |
| 976 | request = (MainThreadRequest) msg.obj; |
| 977 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 978 | int mode = (int) request.argument; |
| 979 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 980 | break; |
| 981 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 982 | ar = (AsyncResult) msg.obj; |
| 983 | request = (MainThreadRequest) ar.userObj; |
| 984 | request.result = ar.exception == null; |
| 985 | notifyRequester(request); |
| 986 | break; |
| 987 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 988 | request = (MainThreadRequest) msg.obj; |
| 989 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 990 | int subscriptionMode = (int) request.argument; |
| 991 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 992 | break; |
| 993 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 994 | ar = (AsyncResult) msg.obj; |
| 995 | request = (MainThreadRequest) ar.userObj; |
| 996 | request.result = ar.exception == null; |
| 997 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 998 | break; |
| 999 | |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1000 | case CMD_GET_ALL_CELL_INFO: |
| 1001 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1002 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1003 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1004 | break; |
| 1005 | |
| 1006 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1007 | ar = (AsyncResult) msg.obj; |
| 1008 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1009 | // If a timeout occurs, the response will be null |
| 1010 | request.result = (ar.exception == null && ar.result != null) |
| 1011 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1012 | synchronized (request) { |
| 1013 | request.notifyAll(); |
| 1014 | } |
| 1015 | break; |
| 1016 | |
| 1017 | case CMD_GET_CELL_LOCATION: { |
| 1018 | request = (MainThreadRequest) msg.obj; |
| 1019 | WorkSource ws = (WorkSource) request.argument; |
| 1020 | Phone phone = getPhoneFromRequest(request); |
| 1021 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1022 | break; |
| 1023 | } |
| 1024 | |
| 1025 | case EVENT_GET_CELL_LOCATION_DONE: { |
| 1026 | ar = (AsyncResult) msg.obj; |
| 1027 | request = (MainThreadRequest) ar.userObj; |
| 1028 | if (ar.exception == null) { |
| 1029 | request.result = ar.result; |
| 1030 | } else { |
| 1031 | Phone phone = getPhoneFromRequest(request); |
| 1032 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1033 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1034 | } |
| 1035 | |
| 1036 | synchronized (request) { |
| 1037 | request.notifyAll(); |
| 1038 | } |
| 1039 | break; |
| 1040 | } |
| 1041 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1042 | case CMD_MODEM_REBOOT: |
| 1043 | request = (MainThreadRequest) msg.obj; |
| 1044 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
| 1045 | mPhone.rebootModem(onCompleted); |
| 1046 | break; |
| 1047 | |
| 1048 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1049 | handleNullReturnEvent(msg, "rebootModem"); |
| 1050 | break; |
| 1051 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1052 | default: |
| 1053 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1054 | break; |
| 1055 | } |
| 1056 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1057 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1058 | private void notifyRequester(MainThreadRequest request) { |
| 1059 | synchronized (request) { |
| 1060 | request.notifyAll(); |
| 1061 | } |
| 1062 | } |
| 1063 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1064 | private void handleNullReturnEvent(Message msg, String command) { |
| 1065 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1066 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1067 | if (ar.exception == null) { |
| 1068 | request.result = true; |
| 1069 | } else { |
| 1070 | request.result = false; |
| 1071 | if (ar.exception instanceof CommandException) { |
| 1072 | loge(command + ": CommandException: " + ar.exception); |
| 1073 | } else { |
| 1074 | loge(command + ": Unknown exception"); |
| 1075 | } |
| 1076 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1077 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1078 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | /** |
| 1082 | * Posts the specified command to be executed on the main thread, |
| 1083 | * waits for the request to complete, and returns the result. |
| 1084 | * @see #sendRequestAsync |
| 1085 | */ |
| 1086 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1087 | return sendRequest( |
| 1088 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | /** |
| 1092 | * Posts the specified command to be executed on the main thread, |
| 1093 | * waits for the request to complete, and returns the result. |
| 1094 | * @see #sendRequestAsync |
| 1095 | */ |
| 1096 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1097 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1098 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | /** |
| 1102 | * Posts the specified command to be executed on the main thread, |
| 1103 | * waits for the request to complete, and returns the result. |
| 1104 | * @see #sendRequestAsync |
| 1105 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1106 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1107 | return sendRequest(command, argument, subId, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | /** |
| 1111 | * Posts the specified command to be executed on the main thread, |
| 1112 | * waits for the request to complete, and returns the result. |
| 1113 | * @see #sendRequestAsync |
| 1114 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1115 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1116 | return sendRequest(command, argument, subId, null, workSource); |
| 1117 | } |
| 1118 | |
| 1119 | /** |
| 1120 | * Posts the specified command to be executed on the main thread, |
| 1121 | * waits for the request to complete, and returns the result. |
| 1122 | * @see #sendRequestAsync |
| 1123 | */ |
| 1124 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1125 | return sendRequest( |
| 1126 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1127 | } |
| 1128 | |
| 1129 | /** |
| 1130 | * Posts the specified command to be executed on the main thread, |
| 1131 | * waits for the request to complete, and returns the result. |
| 1132 | * @see #sendRequestAsync |
| 1133 | */ |
| 1134 | private Object sendRequest( |
| 1135 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1136 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1137 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1138 | } |
| 1139 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1140 | MainThreadRequest request = null; |
| 1141 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1142 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1143 | } else if (phone != null) { |
| 1144 | request = new MainThreadRequest(argument, phone, workSource); |
| 1145 | } else { |
| 1146 | request = new MainThreadRequest(argument, subId, workSource); |
| 1147 | } |
| 1148 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1149 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1150 | msg.sendToTarget(); |
| 1151 | |
| 1152 | // Wait for the request to complete |
| 1153 | synchronized (request) { |
| 1154 | while (request.result == null) { |
| 1155 | try { |
| 1156 | request.wait(); |
| 1157 | } catch (InterruptedException e) { |
| 1158 | // Do nothing, go back and wait until the request is complete |
| 1159 | } |
| 1160 | } |
| 1161 | } |
| 1162 | return request.result; |
| 1163 | } |
| 1164 | |
| 1165 | /** |
| 1166 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1167 | * Posts the specified command to be executed on the main thread, and |
| 1168 | * returns immediately. |
| 1169 | * @see #sendRequest |
| 1170 | */ |
| 1171 | private void sendRequestAsync(int command) { |
| 1172 | mMainThreadHandler.sendEmptyMessage(command); |
| 1173 | } |
| 1174 | |
| 1175 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1176 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
| 1177 | * @see {@link #sendRequest(int,Object)} |
| 1178 | */ |
| 1179 | private void sendRequestAsync(int command, Object argument) { |
| 1180 | MainThreadRequest request = new MainThreadRequest(argument); |
| 1181 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1182 | msg.sendToTarget(); |
| 1183 | } |
| 1184 | |
| 1185 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1186 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1187 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1188 | */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 1189 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1190 | synchronized (PhoneInterfaceManager.class) { |
| 1191 | if (sInstance == null) { |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 1192 | sInstance = new PhoneInterfaceManager(app, phone); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1193 | } else { |
| 1194 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1195 | } |
| 1196 | return sInstance; |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | /** Private constructor; @see init() */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 1201 | private PhoneInterfaceManager(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1202 | mApp = app; |
| 1203 | mPhone = phone; |
| 1204 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1205 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1206 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1207 | mMainThreadHandler = new MainThreadHandler(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 1208 | mTelephonySharedPreferences = |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 1209 | PreferenceManager.getDefaultSharedPreferences(mPhone.getContext()); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1210 | mSubscriptionController = SubscriptionController.getInstance(); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1211 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1212 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1213 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1214 | publish(); |
| 1215 | } |
| 1216 | |
| 1217 | private void publish() { |
| 1218 | if (DBG) log("publish: " + this); |
| 1219 | |
| 1220 | ServiceManager.addService("phone", this); |
| 1221 | } |
| 1222 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1223 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1224 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1225 | ? mPhone : getPhone(request.subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1226 | } |
| 1227 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1228 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1229 | Phone phone = getPhoneFromRequest(request); |
| 1230 | return phone == null ? null : |
| 1231 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1232 | } |
| 1233 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1234 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1235 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1236 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1237 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1238 | |
| 1239 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1240 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1241 | } |
| 1242 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1243 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1244 | if (DBG) log("dial: " + number); |
| 1245 | // No permission check needed here: This is just a wrapper around the |
| 1246 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1247 | // the UI before it does anything. |
| 1248 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1249 | final long identity = Binder.clearCallingIdentity(); |
| 1250 | try { |
| 1251 | String url = createTelUrl(number); |
| 1252 | if (url == null) { |
| 1253 | return; |
| 1254 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1255 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1256 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1257 | PhoneConstants.State state = mCM.getState(subId); |
| 1258 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1259 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1260 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1261 | mApp.startActivity(intent); |
| 1262 | } |
| 1263 | } finally { |
| 1264 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1269 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1270 | } |
| 1271 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1272 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1273 | if (DBG) log("call: " + number); |
| 1274 | |
| 1275 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1276 | // need to do a permission check since we're calling startActivity() |
| 1277 | // from the context of the phone app. |
| 1278 | enforceCallPermission(); |
| 1279 | |
| 1280 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1281 | != AppOpsManager.MODE_ALLOWED) { |
| 1282 | return; |
| 1283 | } |
| 1284 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1285 | final long identity = Binder.clearCallingIdentity(); |
| 1286 | try { |
| 1287 | String url = createTelUrl(number); |
| 1288 | if (url == null) { |
| 1289 | return; |
| 1290 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1291 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1292 | boolean isValid = false; |
| 1293 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1294 | if (slist != null) { |
| 1295 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1296 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1297 | isValid = true; |
| 1298 | break; |
| 1299 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1300 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1301 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1302 | if (!isValid) { |
| 1303 | return; |
| 1304 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1305 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1306 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1307 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1308 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1309 | mApp.startActivity(intent); |
| 1310 | } finally { |
| 1311 | Binder.restoreCallingIdentity(identity); |
| 1312 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1315 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1316 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1319 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1320 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1321 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1322 | } |
| 1323 | |
| 1324 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1325 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1328 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1329 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1330 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1331 | } |
| 1332 | |
| 1333 | /** {@hide} */ |
| 1334 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1335 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1338 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1339 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1340 | |
| 1341 | final long identity = Binder.clearCallingIdentity(); |
| 1342 | try { |
| 1343 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1344 | checkSimPin.start(); |
| 1345 | return checkSimPin.unlockSim(null, pin); |
| 1346 | } finally { |
| 1347 | Binder.restoreCallingIdentity(identity); |
| 1348 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1351 | /** {@hide} */ |
| 1352 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1353 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1356 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1357 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1358 | |
| 1359 | final long identity = Binder.clearCallingIdentity(); |
| 1360 | try { |
| 1361 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1362 | checkSimPuk.start(); |
| 1363 | return checkSimPuk.unlockSim(puk, pin); |
| 1364 | } finally { |
| 1365 | Binder.restoreCallingIdentity(identity); |
| 1366 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1370 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1371 | * a synchronous one. |
| 1372 | */ |
| 1373 | private static class UnlockSim extends Thread { |
| 1374 | |
| 1375 | private final IccCard mSimCard; |
| 1376 | |
| 1377 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1378 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1379 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1380 | |
| 1381 | // For replies from SimCard interface |
| 1382 | private Handler mHandler; |
| 1383 | |
| 1384 | // For async handler to identify request type |
| 1385 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1386 | |
| 1387 | public UnlockSim(IccCard simCard) { |
| 1388 | mSimCard = simCard; |
| 1389 | } |
| 1390 | |
| 1391 | @Override |
| 1392 | public void run() { |
| 1393 | Looper.prepare(); |
| 1394 | synchronized (UnlockSim.this) { |
| 1395 | mHandler = new Handler() { |
| 1396 | @Override |
| 1397 | public void handleMessage(Message msg) { |
| 1398 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1399 | switch (msg.what) { |
| 1400 | case SUPPLY_PIN_COMPLETE: |
| 1401 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1402 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1403 | mRetryCount = msg.arg1; |
| 1404 | if (ar.exception != null) { |
| 1405 | if (ar.exception instanceof CommandException && |
| 1406 | ((CommandException)(ar.exception)).getCommandError() |
| 1407 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1408 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1409 | } else { |
| 1410 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1411 | } |
| 1412 | } else { |
| 1413 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1414 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1415 | mDone = true; |
| 1416 | UnlockSim.this.notifyAll(); |
| 1417 | } |
| 1418 | break; |
| 1419 | } |
| 1420 | } |
| 1421 | }; |
| 1422 | UnlockSim.this.notifyAll(); |
| 1423 | } |
| 1424 | Looper.loop(); |
| 1425 | } |
| 1426 | |
| 1427 | /* |
| 1428 | * Use PIN or PUK to unlock SIM card |
| 1429 | * |
| 1430 | * If PUK is null, unlock SIM card with PIN |
| 1431 | * |
| 1432 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1433 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1434 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1435 | |
| 1436 | while (mHandler == null) { |
| 1437 | try { |
| 1438 | wait(); |
| 1439 | } catch (InterruptedException e) { |
| 1440 | Thread.currentThread().interrupt(); |
| 1441 | } |
| 1442 | } |
| 1443 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1444 | |
| 1445 | if (puk == null) { |
| 1446 | mSimCard.supplyPin(pin, callback); |
| 1447 | } else { |
| 1448 | mSimCard.supplyPuk(puk, pin, callback); |
| 1449 | } |
| 1450 | |
| 1451 | while (!mDone) { |
| 1452 | try { |
| 1453 | Log.d(LOG_TAG, "wait for done"); |
| 1454 | wait(); |
| 1455 | } catch (InterruptedException e) { |
| 1456 | // Restore the interrupted status |
| 1457 | Thread.currentThread().interrupt(); |
| 1458 | } |
| 1459 | } |
| 1460 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1461 | int[] resultArray = new int[2]; |
| 1462 | resultArray[0] = mResult; |
| 1463 | resultArray[1] = mRetryCount; |
| 1464 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1469 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1470 | |
| 1471 | } |
| 1472 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1473 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1474 | // No permission check needed here: this call is harmless, and it's |
| 1475 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1476 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1477 | final long identity = Binder.clearCallingIdentity(); |
| 1478 | try { |
| 1479 | final Phone phone = getPhone(subId); |
| 1480 | if (phone != null) { |
| 1481 | phone.updateServiceLocation(); |
| 1482 | } |
| 1483 | } finally { |
| 1484 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1485 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1488 | @Override |
| 1489 | public boolean isRadioOn(String callingPackage) { |
| 1490 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1493 | @Override |
| 1494 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1495 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1496 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1497 | return false; |
| 1498 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1499 | |
| 1500 | final long identity = Binder.clearCallingIdentity(); |
| 1501 | try { |
| 1502 | return isRadioOnForSubscriber(subId); |
| 1503 | } finally { |
| 1504 | Binder.restoreCallingIdentity(identity); |
| 1505 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1509 | final long identity = Binder.clearCallingIdentity(); |
| 1510 | try { |
| 1511 | final Phone phone = getPhone(subId); |
| 1512 | if (phone != null) { |
| 1513 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1514 | } else { |
| 1515 | return false; |
| 1516 | } |
| 1517 | } finally { |
| 1518 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1519 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1523 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1524 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1525 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1526 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1527 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1528 | |
| 1529 | final long identity = Binder.clearCallingIdentity(); |
| 1530 | try { |
| 1531 | final Phone phone = getPhone(subId); |
| 1532 | if (phone != null) { |
| 1533 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1534 | } |
| 1535 | } finally { |
| 1536 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1537 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1541 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1544 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1545 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1546 | |
| 1547 | final long identity = Binder.clearCallingIdentity(); |
| 1548 | try { |
| 1549 | final Phone phone = getPhone(subId); |
| 1550 | if (phone == null) { |
| 1551 | return false; |
| 1552 | } |
| 1553 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1554 | toggleRadioOnOffForSubscriber(subId); |
| 1555 | } |
| 1556 | return true; |
| 1557 | } finally { |
| 1558 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1559 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1560 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1561 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1562 | public boolean needMobileRadioShutdown() { |
| 1563 | /* |
| 1564 | * If any of the Radios are available, it will need to be |
| 1565 | * shutdown. So return true if any Radio is available. |
| 1566 | */ |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1567 | final long identity = Binder.clearCallingIdentity(); |
| 1568 | try { |
| 1569 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1570 | Phone phone = PhoneFactory.getPhone(i); |
| 1571 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1572 | } |
| 1573 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1574 | return false; |
| 1575 | } finally { |
| 1576 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1577 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1578 | } |
| 1579 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1580 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1581 | public void shutdownMobileRadios() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1582 | enforceModifyPermission(); |
| 1583 | |
| 1584 | final long identity = Binder.clearCallingIdentity(); |
| 1585 | try { |
| 1586 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1587 | logv("Shutting down Phone " + i); |
| 1588 | shutdownRadioUsingPhoneId(i); |
| 1589 | } |
| 1590 | } finally { |
| 1591 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1596 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1597 | if (phone != null && phone.isRadioAvailable()) { |
| 1598 | phone.shutdownRadio(); |
| 1599 | } |
| 1600 | } |
| 1601 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1602 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1603 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1604 | |
| 1605 | final long identity = Binder.clearCallingIdentity(); |
| 1606 | try { |
| 1607 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1608 | if (defaultPhone != null) { |
| 1609 | defaultPhone.setRadioPower(turnOn); |
| 1610 | return true; |
| 1611 | } else { |
| 1612 | loge("There's no default phone."); |
| 1613 | return false; |
| 1614 | } |
| 1615 | } finally { |
| 1616 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1617 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1620 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1621 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1622 | |
| 1623 | final long identity = Binder.clearCallingIdentity(); |
| 1624 | try { |
| 1625 | final Phone phone = getPhone(subId); |
| 1626 | if (phone != null) { |
| 1627 | phone.setRadioPower(turnOn); |
| 1628 | return true; |
| 1629 | } else { |
| 1630 | return false; |
| 1631 | } |
| 1632 | } finally { |
| 1633 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1634 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1635 | } |
| 1636 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1637 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1638 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1639 | public boolean enableDataConnectivity() { |
| 1640 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1641 | |
| 1642 | final long identity = Binder.clearCallingIdentity(); |
| 1643 | try { |
| 1644 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1645 | final Phone phone = getPhone(subId); |
| 1646 | if (phone != null) { |
| 1647 | phone.setUserDataEnabled(true); |
| 1648 | return true; |
| 1649 | } else { |
| 1650 | return false; |
| 1651 | } |
| 1652 | } finally { |
| 1653 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1654 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1655 | } |
| 1656 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1657 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1658 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1659 | public boolean disableDataConnectivity() { |
| 1660 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1661 | |
| 1662 | final long identity = Binder.clearCallingIdentity(); |
| 1663 | try { |
| 1664 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1665 | final Phone phone = getPhone(subId); |
| 1666 | if (phone != null) { |
| 1667 | phone.setUserDataEnabled(false); |
| 1668 | return true; |
| 1669 | } else { |
| 1670 | return false; |
| 1671 | } |
| 1672 | } finally { |
| 1673 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1674 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1677 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1678 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1679 | final long identity = Binder.clearCallingIdentity(); |
| 1680 | try { |
| 1681 | final Phone phone = getPhone(subId); |
| 1682 | if (phone != null) { |
| 1683 | return phone.isDataAllowed(); |
| 1684 | } else { |
| 1685 | return false; |
| 1686 | } |
| 1687 | } finally { |
| 1688 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1689 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1693 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1696 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1697 | enforceCallPermission(); |
| 1698 | |
| 1699 | final long identity = Binder.clearCallingIdentity(); |
| 1700 | try { |
| 1701 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1702 | return; |
| 1703 | } |
| 1704 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1705 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1706 | } finally { |
| 1707 | Binder.restoreCallingIdentity(identity); |
| 1708 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1709 | }; |
| 1710 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1711 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1712 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1713 | |
| 1714 | final long identity = Binder.clearCallingIdentity(); |
| 1715 | try { |
| 1716 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1717 | return false; |
| 1718 | } |
| 1719 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1720 | } finally { |
| 1721 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1722 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1725 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1726 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1729 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1730 | final long identity = Binder.clearCallingIdentity(); |
| 1731 | try { |
| 1732 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1733 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1734 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1735 | } finally { |
| 1736 | Binder.restoreCallingIdentity(identity); |
| 1737 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1740 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1741 | public int getDataState() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1742 | final long identity = Binder.clearCallingIdentity(); |
| 1743 | try { |
| 1744 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1745 | if (phone != null) { |
| 1746 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1747 | } else { |
| 1748 | return PhoneConstantConversions.convertDataState( |
| 1749 | PhoneConstants.DataState.DISCONNECTED); |
| 1750 | } |
| 1751 | } finally { |
| 1752 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1753 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1756 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1757 | public int getDataActivity() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1758 | final long identity = Binder.clearCallingIdentity(); |
| 1759 | try { |
| 1760 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1761 | if (phone != null) { |
| 1762 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1763 | } else { |
| 1764 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1765 | } |
| 1766 | } finally { |
| 1767 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1768 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1772 | public Bundle getCellLocation(String callingPackage) { |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1773 | mPhone.getContext().getSystemService(AppOpsManager.class) |
| 1774 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1775 | if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(), |
Svet Ganov | 4af6628 | 2018-03-07 19:57:05 -0800 | [diff] [blame] | 1776 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1777 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1780 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1781 | final long identity = Binder.clearCallingIdentity(); |
| 1782 | try { |
| 1783 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1784 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1785 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1786 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1787 | cl.fillInNotifierBundle(data); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1788 | return data; |
| 1789 | } finally { |
| 1790 | Binder.restoreCallingIdentity(identity); |
| 1791 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1794 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1795 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1796 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1797 | // registered cell info, so return a NULL country instead. |
| 1798 | final long identity = Binder.clearCallingIdentity(); |
| 1799 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1800 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1801 | // Get default phone in this case. |
| 1802 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1803 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1804 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1805 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1806 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1807 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1808 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1809 | return ""; |
| 1810 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1811 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1812 | if (phone != null) { |
| 1813 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1814 | if (sst != null) { |
| 1815 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1816 | if (lt != null) { |
| 1817 | return lt.getCurrentCountry(); |
| 1818 | } |
| 1819 | } |
| 1820 | } |
| 1821 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1822 | } finally { |
| 1823 | Binder.restoreCallingIdentity(identity); |
| 1824 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1828 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1829 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1832 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1833 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1834 | mApp.enforceCallingOrSelfPermission( |
| 1835 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1836 | |
| 1837 | final long identity = Binder.clearCallingIdentity(); |
| 1838 | try { |
| 1839 | final Phone phone = getPhone(subId); |
| 1840 | if (phone != null) { |
| 1841 | phone.enableLocationUpdates(); |
| 1842 | } |
| 1843 | } finally { |
| 1844 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1845 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | @Override |
| 1849 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1850 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1853 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1854 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1855 | mApp.enforceCallingOrSelfPermission( |
| 1856 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1857 | |
| 1858 | final long identity = Binder.clearCallingIdentity(); |
| 1859 | try { |
| 1860 | final Phone phone = getPhone(subId); |
| 1861 | if (phone != null) { |
| 1862 | phone.disableLocationUpdates(); |
| 1863 | } |
| 1864 | } finally { |
| 1865 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1866 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1869 | /** |
| 1870 | * Returns the target SDK version number for a given package name. |
| 1871 | * |
| 1872 | * @return target SDK if the package is found or INT_MAX. |
| 1873 | */ |
| 1874 | private int getTargetSdk(String packageName) { |
| 1875 | try { |
| 1876 | final ApplicationInfo ai = |
| 1877 | mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0); |
| 1878 | if (ai != null) return ai.targetSdkVersion; |
| 1879 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1880 | } |
| 1881 | return Integer.MAX_VALUE; |
| 1882 | } |
| 1883 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1884 | @Override |
| 1885 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1886 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1887 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1888 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1889 | throw new SecurityException( |
| 1890 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1891 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1892 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1893 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1894 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1895 | return null; |
| 1896 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1897 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1898 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1899 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1900 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 1901 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1902 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1903 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 1904 | for (CellInfo ci : info) { |
| 1905 | if (ci instanceof CellInfoGsm) { |
| 1906 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 1907 | } else if (ci instanceof CellInfoWcdma) { |
| 1908 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 1909 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1910 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1911 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | |
| 1915 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1916 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1917 | mPhone.getContext().getSystemService(AppOpsManager.class) |
| 1918 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1919 | if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(), |
Svet Ganov | 4af6628 | 2018-03-07 19:57:05 -0800 | [diff] [blame] | 1920 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1921 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1924 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1925 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1926 | final long identity = Binder.clearCallingIdentity(); |
| 1927 | try { |
| 1928 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 1929 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1930 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1931 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1932 | if (info != null) cellInfos.addAll(info); |
| 1933 | } |
| 1934 | return cellInfos; |
| 1935 | } finally { |
| 1936 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1937 | } |
| 1938 | } |
| 1939 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1940 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1941 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 1942 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1943 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1944 | |
| 1945 | final long identity = Binder.clearCallingIdentity(); |
| 1946 | try { |
| 1947 | mPhone.setCellInfoListRate(rateInMillis, workSource); |
| 1948 | } finally { |
| 1949 | Binder.restoreCallingIdentity(identity); |
| 1950 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1953 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1954 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1955 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1956 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1957 | return null; |
| 1958 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1959 | int subId = phone.getSubId(); |
| 1960 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 1961 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 1962 | return null; |
| 1963 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1964 | |
| 1965 | final long identity = Binder.clearCallingIdentity(); |
| 1966 | try { |
| 1967 | return phone.getImei(); |
| 1968 | } finally { |
| 1969 | Binder.restoreCallingIdentity(identity); |
| 1970 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 1974 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 1975 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1976 | String tac = null; |
| 1977 | if (phone != null) { |
| 1978 | String imei = phone.getImei(); |
| 1979 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 1980 | } |
| 1981 | return tac; |
| 1982 | } |
| 1983 | |
| 1984 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 1985 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1986 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1987 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 1988 | return null; |
| 1989 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1990 | int subId = phone.getSubId(); |
| 1991 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 1992 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 1993 | return null; |
| 1994 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1995 | |
| 1996 | final long identity = Binder.clearCallingIdentity(); |
| 1997 | try { |
| 1998 | return phone.getMeid(); |
| 1999 | } finally { |
| 2000 | Binder.restoreCallingIdentity(identity); |
| 2001 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2005 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2006 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2007 | String manufacturerCode = null; |
| 2008 | if (phone != null) { |
| 2009 | String meid = phone.getMeid(); |
| 2010 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2011 | } |
| 2012 | return manufacturerCode; |
| 2013 | } |
| 2014 | |
| 2015 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2016 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2017 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2018 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2019 | return null; |
| 2020 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2021 | int subId = phone.getSubId(); |
| 2022 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2023 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2024 | return null; |
| 2025 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2026 | |
| 2027 | final long identity = Binder.clearCallingIdentity(); |
| 2028 | try { |
| 2029 | return phone.getDeviceSvn(); |
| 2030 | } finally { |
| 2031 | Binder.restoreCallingIdentity(identity); |
| 2032 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2035 | @Override |
| 2036 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2037 | final long identity = Binder.clearCallingIdentity(); |
| 2038 | try { |
| 2039 | final Phone phone = getPhone(subId); |
| 2040 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2041 | } finally { |
| 2042 | Binder.restoreCallingIdentity(identity); |
| 2043 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | @Override |
| 2047 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2048 | final long identity = Binder.clearCallingIdentity(); |
| 2049 | try { |
| 2050 | final Phone phone = getPhone(subId); |
| 2051 | return phone == null ? null : phone.getCarrierName(); |
| 2052 | } finally { |
| 2053 | Binder.restoreCallingIdentity(identity); |
| 2054 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2055 | } |
| 2056 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2057 | // |
| 2058 | // Internal helper methods. |
| 2059 | // |
| 2060 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2061 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2062 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2063 | * |
| 2064 | * @throws SecurityException if the caller does not have the required permission |
| 2065 | */ |
| 2066 | private void enforceModifyPermission() { |
| 2067 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2068 | } |
| 2069 | |
| 2070 | /** |
| 2071 | * Make sure the caller has the CALL_PHONE permission. |
| 2072 | * |
| 2073 | * @throws SecurityException if the caller does not have the required permission |
| 2074 | */ |
| 2075 | private void enforceCallPermission() { |
| 2076 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2077 | } |
| 2078 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2079 | private void enforceConnectivityInternalPermission() { |
| 2080 | mApp.enforceCallingOrSelfPermission( |
| 2081 | android.Manifest.permission.CONNECTIVITY_INTERNAL, |
| 2082 | "ConnectivityService"); |
| 2083 | } |
| 2084 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2085 | private String createTelUrl(String number) { |
| 2086 | if (TextUtils.isEmpty(number)) { |
| 2087 | return null; |
| 2088 | } |
| 2089 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2090 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2091 | } |
| 2092 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2093 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2094 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2095 | } |
| 2096 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2097 | private static void logv(String msg) { |
| 2098 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2099 | } |
| 2100 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2101 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2102 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2103 | } |
| 2104 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2105 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2106 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2107 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2110 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2111 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2112 | final long identity = Binder.clearCallingIdentity(); |
| 2113 | try { |
| 2114 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2115 | if (phone == null) { |
| 2116 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2117 | } else { |
| 2118 | return phone.getPhoneType(); |
| 2119 | } |
| 2120 | } finally { |
| 2121 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2122 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | /** |
| 2126 | * Returns the CDMA ERI icon index to display |
| 2127 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2128 | @Override |
| 2129 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2130 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2131 | } |
| 2132 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2133 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2134 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2135 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2136 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2137 | return -1; |
| 2138 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2139 | |
| 2140 | final long identity = Binder.clearCallingIdentity(); |
| 2141 | try { |
| 2142 | final Phone phone = getPhone(subId); |
| 2143 | if (phone != null) { |
| 2144 | return phone.getCdmaEriIconIndex(); |
| 2145 | } else { |
| 2146 | return -1; |
| 2147 | } |
| 2148 | } finally { |
| 2149 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2150 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | /** |
| 2154 | * Returns the CDMA ERI icon mode, |
| 2155 | * 0 - ON |
| 2156 | * 1 - FLASHING |
| 2157 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2158 | @Override |
| 2159 | public int getCdmaEriIconMode(String callingPackage) { |
| 2160 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2161 | } |
| 2162 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2163 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2164 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2165 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2166 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2167 | return -1; |
| 2168 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2169 | |
| 2170 | final long identity = Binder.clearCallingIdentity(); |
| 2171 | try { |
| 2172 | final Phone phone = getPhone(subId); |
| 2173 | if (phone != null) { |
| 2174 | return phone.getCdmaEriIconMode(); |
| 2175 | } else { |
| 2176 | return -1; |
| 2177 | } |
| 2178 | } finally { |
| 2179 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2180 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2181 | } |
| 2182 | |
| 2183 | /** |
| 2184 | * Returns the CDMA ERI text, |
| 2185 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2186 | @Override |
| 2187 | public String getCdmaEriText(String callingPackage) { |
| 2188 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2191 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2192 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2193 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2194 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2195 | return null; |
| 2196 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2197 | |
| 2198 | final long identity = Binder.clearCallingIdentity(); |
| 2199 | try { |
| 2200 | final Phone phone = getPhone(subId); |
| 2201 | if (phone != null) { |
| 2202 | return phone.getCdmaEriText(); |
| 2203 | } else { |
| 2204 | return null; |
| 2205 | } |
| 2206 | } finally { |
| 2207 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2208 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2212 | * Returns the CDMA MDN. |
| 2213 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2214 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2215 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2216 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2217 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2218 | |
| 2219 | final long identity = Binder.clearCallingIdentity(); |
| 2220 | try { |
| 2221 | final Phone phone = getPhone(subId); |
| 2222 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) { |
| 2223 | return phone.getLine1Number(); |
| 2224 | } else { |
| 2225 | return null; |
| 2226 | } |
| 2227 | } finally { |
| 2228 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | /** |
| 2233 | * Returns the CDMA MIN. |
| 2234 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2235 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2236 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2237 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2238 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2239 | |
| 2240 | final long identity = Binder.clearCallingIdentity(); |
| 2241 | try { |
| 2242 | final Phone phone = getPhone(subId); |
| 2243 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2244 | return phone.getCdmaMin(); |
| 2245 | } else { |
| 2246 | return null; |
| 2247 | } |
| 2248 | } finally { |
| 2249 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2254 | * Returns true if CDMA provisioning needs to run. |
| 2255 | */ |
| 2256 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2257 | final long identity = Binder.clearCallingIdentity(); |
| 2258 | try { |
| 2259 | return mPhone.needsOtaServiceProvisioning(); |
| 2260 | } finally { |
| 2261 | Binder.restoreCallingIdentity(identity); |
| 2262 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2266 | * Sets the voice mail number of a given subId. |
| 2267 | */ |
| 2268 | @Override |
| 2269 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2270 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2271 | |
| 2272 | final long identity = Binder.clearCallingIdentity(); |
| 2273 | try { |
| 2274 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2275 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2276 | return success; |
| 2277 | } finally { |
| 2278 | Binder.restoreCallingIdentity(identity); |
| 2279 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2280 | } |
| 2281 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2282 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2283 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2284 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2285 | String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage(); |
| 2286 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2287 | throw new SecurityException("caller must be system dialer"); |
| 2288 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2289 | |
| 2290 | final long identity = Binder.clearCallingIdentity(); |
| 2291 | try { |
| 2292 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2293 | if (phoneAccountHandle == null) { |
| 2294 | return null; |
| 2295 | } |
| 2296 | return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle); |
| 2297 | } finally { |
| 2298 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2299 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2303 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2304 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2305 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2306 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2307 | return null; |
| 2308 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2309 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2310 | final long identity = Binder.clearCallingIdentity(); |
| 2311 | try { |
| 2312 | return RemoteVvmTaskManager |
| 2313 | .getRemotePackage(mPhone.getContext(), subId).getPackageName(); |
| 2314 | } finally { |
| 2315 | Binder.restoreCallingIdentity(identity); |
| 2316 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2320 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2321 | VisualVoicemailSmsFilterSettings settings) { |
| 2322 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2323 | |
| 2324 | final long identity = Binder.clearCallingIdentity(); |
| 2325 | try { |
| 2326 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
| 2327 | mPhone.getContext(), callingPackage, subId, settings); |
| 2328 | } finally { |
| 2329 | Binder.restoreCallingIdentity(identity); |
| 2330 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2334 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2335 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2336 | |
| 2337 | final long identity = Binder.clearCallingIdentity(); |
| 2338 | try { |
| 2339 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
| 2340 | mPhone.getContext(), callingPackage, subId); |
| 2341 | } finally { |
| 2342 | Binder.restoreCallingIdentity(identity); |
| 2343 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2347 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2348 | String callingPackage, int subId) { |
| 2349 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2350 | |
| 2351 | final long identity = Binder.clearCallingIdentity(); |
| 2352 | try { |
| 2353 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
| 2354 | mPhone.getContext(), callingPackage, subId); |
| 2355 | } finally { |
| 2356 | Binder.restoreCallingIdentity(identity); |
| 2357 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2361 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2362 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2363 | |
| 2364 | final long identity = Binder.clearCallingIdentity(); |
| 2365 | try { |
| 2366 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
| 2367 | mPhone.getContext(), subId); |
| 2368 | } finally { |
| 2369 | Binder.restoreCallingIdentity(identity); |
| 2370 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | @Override |
| 2374 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2375 | String number, int port, String text, PendingIntent sentIntent) { |
| 2376 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2377 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2378 | enforceSendSmsPermission(); |
| 2379 | // Make the calls as the phone process. |
| 2380 | final long identity = Binder.clearCallingIdentity(); |
| 2381 | try { |
| 2382 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2383 | if (port == 0) { |
| 2384 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2385 | sentIntent, null, false); |
| 2386 | } else { |
| 2387 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2388 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2389 | (short) port, data, sentIntent, null); |
| 2390 | } |
| 2391 | } finally { |
| 2392 | Binder.restoreCallingIdentity(identity); |
| 2393 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2394 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2395 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2396 | * Sets the voice activation state of a given subId. |
| 2397 | */ |
| 2398 | @Override |
| 2399 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2400 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2401 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2402 | |
| 2403 | final long identity = Binder.clearCallingIdentity(); |
| 2404 | try { |
| 2405 | final Phone phone = getPhone(subId); |
| 2406 | if (phone != null) { |
| 2407 | phone.setVoiceActivationState(activationState); |
| 2408 | } else { |
| 2409 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2410 | } |
| 2411 | } finally { |
| 2412 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2413 | } |
| 2414 | } |
| 2415 | |
| 2416 | /** |
| 2417 | * Sets the data activation state of a given subId. |
| 2418 | */ |
| 2419 | @Override |
| 2420 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2421 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2422 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2423 | |
| 2424 | final long identity = Binder.clearCallingIdentity(); |
| 2425 | try { |
| 2426 | final Phone phone = getPhone(subId); |
| 2427 | if (phone != null) { |
| 2428 | phone.setDataActivationState(activationState); |
| 2429 | } else { |
| 2430 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2431 | } |
| 2432 | } finally { |
| 2433 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2434 | } |
| 2435 | } |
| 2436 | |
| 2437 | /** |
| 2438 | * Returns the voice activation state of a given subId. |
| 2439 | */ |
| 2440 | @Override |
| 2441 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2442 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2443 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2444 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2445 | final long identity = Binder.clearCallingIdentity(); |
| 2446 | try { |
| 2447 | if (phone != null) { |
| 2448 | return phone.getVoiceActivationState(); |
| 2449 | } else { |
| 2450 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2451 | } |
| 2452 | } finally { |
| 2453 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | /** |
| 2458 | * Returns the data activation state of a given subId. |
| 2459 | */ |
| 2460 | @Override |
| 2461 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2462 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2463 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2464 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2465 | final long identity = Binder.clearCallingIdentity(); |
| 2466 | try { |
| 2467 | if (phone != null) { |
| 2468 | return phone.getDataActivationState(); |
| 2469 | } else { |
| 2470 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2471 | } |
| 2472 | } finally { |
| 2473 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2474 | } |
| 2475 | } |
| 2476 | |
| 2477 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | * Returns the unread count of voicemails |
| 2479 | */ |
| 2480 | public int getVoiceMessageCount() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2481 | return getVoiceMessageCountForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | /** |
| 2485 | * Returns the unread count of voicemails for a subId |
| 2486 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2487 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2488 | public int getVoiceMessageCountForSubscriber( int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2489 | final long identity = Binder.clearCallingIdentity(); |
| 2490 | try { |
| 2491 | final Phone phone = getPhone(subId); |
| 2492 | if (phone != null) { |
| 2493 | return phone.getVoiceMessageCount(); |
| 2494 | } else { |
| 2495 | return 0; |
| 2496 | } |
| 2497 | } finally { |
| 2498 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2499 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2503 | * returns true, if the device is in a state where both voice and data |
| 2504 | * are supported simultaneously. This can change based on location or network condition. |
| 2505 | */ |
| 2506 | @Override |
| 2507 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2508 | final long identity = Binder.clearCallingIdentity(); |
| 2509 | try { |
| 2510 | final Phone phone = getPhone(subId); |
| 2511 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2512 | } finally { |
| 2513 | Binder.restoreCallingIdentity(identity); |
| 2514 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2518 | * Send the dialer code if called from the current default dialer or the caller has |
| 2519 | * carrier privilege. |
| 2520 | * @param inputCode The dialer code to send |
| 2521 | */ |
| 2522 | @Override |
| 2523 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
| 2524 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2525 | String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage(); |
| 2526 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2527 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2528 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2529 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2530 | |
| 2531 | final long identity = Binder.clearCallingIdentity(); |
| 2532 | try { |
| 2533 | mPhone.sendDialerSpecialCode(inputCode); |
| 2534 | } finally { |
| 2535 | Binder.restoreCallingIdentity(identity); |
| 2536 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2540 | * Returns the data network type. |
| 2541 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2542 | * |
| 2543 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2544 | */ |
| 2545 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2546 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2547 | final long identity = Binder.clearCallingIdentity(); |
| 2548 | try { |
| 2549 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2550 | if (phone != null) { |
| 2551 | return phone.getServiceState().getDataNetworkType(); |
| 2552 | } else { |
| 2553 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2554 | } |
| 2555 | } finally { |
| 2556 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2557 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2560 | @Override |
| 2561 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2562 | if (!isActiveSubscription(subId)) { |
| 2563 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2564 | } |
| 2565 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2566 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2567 | } |
| 2568 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2569 | @Override |
| 2570 | public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c, |
| 2571 | String callingPackage) throws RemoteException { |
| 2572 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2573 | "addImsRegistrationCallback")) { |
| 2574 | return; |
| 2575 | } |
| 2576 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2577 | final long token = Binder.clearCallingIdentity(); |
| 2578 | try { |
| 2579 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2580 | .addRegistrationCallbackForSubscription(c, subId); |
| 2581 | } finally { |
| 2582 | Binder.restoreCallingIdentity(token); |
| 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | @Override |
| 2587 | public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c, |
| 2588 | String callingPackage) { |
| 2589 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2590 | "removeImsRegistrationCallback")) { |
| 2591 | return; |
| 2592 | } |
| 2593 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2594 | Binder.withCleanCallingIdentity(() -> |
| 2595 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2596 | .removeRegistrationCallbackForSubscription(c, subId)); |
| 2597 | } |
| 2598 | |
| 2599 | @Override |
| 2600 | public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c, |
| 2601 | String callingPackage) throws RemoteException { |
| 2602 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2603 | "addMmTelCapabilityCallback")) { |
| 2604 | return; |
| 2605 | } |
| 2606 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2607 | final long token = Binder.clearCallingIdentity(); |
| 2608 | try { |
| 2609 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2610 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2611 | } finally { |
| 2612 | Binder.restoreCallingIdentity(token); |
| 2613 | } |
| 2614 | } |
| 2615 | |
| 2616 | @Override |
| 2617 | public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c, |
| 2618 | String callingPackage) { |
| 2619 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2620 | "removeMmTelCapabilityCallback")) { |
| 2621 | return; |
| 2622 | } |
| 2623 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2624 | Binder.withCleanCallingIdentity(() -> |
| 2625 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2626 | .removeCapabilitiesCallbackForSubscription(c, subId)); |
| 2627 | } |
| 2628 | |
| 2629 | @Override |
| 2630 | public boolean isCapable(int subId, int capability, int regTech, String callingPackage) { |
| 2631 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2632 | "isCapable")) { |
| 2633 | return false; |
| 2634 | } |
| 2635 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2636 | final long token = Binder.clearCallingIdentity(); |
| 2637 | try { |
| 2638 | return ImsManager.getInstance(mPhone.getContext(), |
| 2639 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2640 | } catch (ImsException e) { |
| 2641 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2642 | return false; |
| 2643 | } finally { |
| 2644 | Binder.restoreCallingIdentity(token); |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | @Override |
| 2649 | public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) { |
| 2650 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2651 | "isAvailable")) { |
| 2652 | return false; |
| 2653 | } |
| 2654 | final long token = Binder.clearCallingIdentity(); |
| 2655 | try { |
| 2656 | Phone phone = getPhone(subId); |
| 2657 | if (phone == null) return false; |
| 2658 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2659 | } finally { |
| 2660 | Binder.restoreCallingIdentity(token); |
| 2661 | } |
| 2662 | } |
| 2663 | |
| 2664 | @Override |
| 2665 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2666 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2667 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2668 | final long token = Binder.clearCallingIdentity(); |
| 2669 | try { |
| 2670 | return ImsManager.getInstance(mPhone.getContext(), |
| 2671 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2672 | } finally { |
| 2673 | Binder.restoreCallingIdentity(token); |
| 2674 | } |
| 2675 | } |
| 2676 | |
| 2677 | @Override |
| 2678 | public void setAdvancedCallingSetting(int subId, boolean isEnabled) { |
| 2679 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2680 | "setAdvancedCallingSetting"); |
| 2681 | final long identity = Binder.clearCallingIdentity(); |
| 2682 | try { |
| 2683 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2684 | ImsManager.getInstance(mPhone.getContext(), |
| 2685 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2686 | } finally { |
| 2687 | Binder.restoreCallingIdentity(identity); |
| 2688 | } |
| 2689 | } |
| 2690 | |
| 2691 | @Override |
| 2692 | public boolean isVtSettingEnabled(int subId, String callingPackage) { |
| 2693 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2694 | "isVtSettingEnabled")) { |
| 2695 | return false; |
| 2696 | } |
| 2697 | final long identity = Binder.clearCallingIdentity(); |
| 2698 | try { |
| 2699 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2700 | return ImsManager.getInstance(mPhone.getContext(), |
| 2701 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2702 | } finally { |
| 2703 | Binder.restoreCallingIdentity(identity); |
| 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | @Override |
| 2708 | public void setVtSetting(int subId, boolean isEnabled) { |
| 2709 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2710 | "setVtSetting"); |
| 2711 | final long identity = Binder.clearCallingIdentity(); |
| 2712 | try { |
| 2713 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2714 | ImsManager.getInstance(mPhone.getContext(), |
| 2715 | getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
| 2716 | } finally { |
| 2717 | Binder.restoreCallingIdentity(identity); |
| 2718 | } |
| 2719 | } |
| 2720 | |
| 2721 | @Override |
| 2722 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2723 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2724 | final long identity = Binder.clearCallingIdentity(); |
| 2725 | try { |
| 2726 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2727 | return ImsManager.getInstance(mPhone.getContext(), |
| 2728 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2729 | } finally { |
| 2730 | Binder.restoreCallingIdentity(identity); |
| 2731 | } |
| 2732 | } |
| 2733 | |
| 2734 | @Override |
| 2735 | public void setVoWiFiSetting(int subId, boolean isEnabled) { |
| 2736 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2737 | "setVoWiFiSetting"); |
| 2738 | final long identity = Binder.clearCallingIdentity(); |
| 2739 | try { |
| 2740 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2741 | ImsManager.getInstance(mPhone.getContext(), |
| 2742 | getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
| 2743 | } finally { |
| 2744 | Binder.restoreCallingIdentity(identity); |
| 2745 | } |
| 2746 | } |
| 2747 | |
| 2748 | @Override |
| 2749 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2750 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2751 | final long identity = Binder.clearCallingIdentity(); |
| 2752 | try { |
| 2753 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2754 | return ImsManager.getInstance(mPhone.getContext(), |
| 2755 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 2756 | } finally { |
| 2757 | Binder.restoreCallingIdentity(identity); |
| 2758 | } |
| 2759 | } |
| 2760 | |
| 2761 | @Override |
| 2762 | public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) { |
| 2763 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2764 | "setVoWiFiRoamingSetting"); |
| 2765 | final long identity = Binder.clearCallingIdentity(); |
| 2766 | try { |
| 2767 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2768 | ImsManager.getInstance(mPhone.getContext(), |
| 2769 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 2770 | } finally { |
| 2771 | Binder.restoreCallingIdentity(identity); |
| 2772 | } |
| 2773 | } |
| 2774 | |
| 2775 | @Override |
| 2776 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 2777 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2778 | "setVoWiFiNonPersistent"); |
| 2779 | final long identity = Binder.clearCallingIdentity(); |
| 2780 | try { |
| 2781 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2782 | ImsManager.getInstance(mPhone.getContext(), |
| 2783 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
| 2784 | } finally { |
| 2785 | Binder.restoreCallingIdentity(identity); |
| 2786 | } |
| 2787 | } |
| 2788 | |
| 2789 | @Override |
| 2790 | public int getVoWiFiModeSetting(int subId) { |
| 2791 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 2792 | final long identity = Binder.clearCallingIdentity(); |
| 2793 | try { |
| 2794 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2795 | return ImsManager.getInstance(mPhone.getContext(), |
| 2796 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 2797 | } finally { |
| 2798 | Binder.restoreCallingIdentity(identity); |
| 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | @Override |
| 2803 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 2804 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2805 | "setVoWiFiModeSetting"); |
| 2806 | final long identity = Binder.clearCallingIdentity(); |
| 2807 | try { |
| 2808 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2809 | ImsManager.getInstance(mPhone.getContext(), |
| 2810 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 2811 | } finally { |
| 2812 | Binder.restoreCallingIdentity(identity); |
| 2813 | } |
| 2814 | } |
| 2815 | |
| 2816 | @Override |
| 2817 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 2818 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 2819 | final long identity = Binder.clearCallingIdentity(); |
| 2820 | try { |
| 2821 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2822 | return ImsManager.getInstance(mPhone.getContext(), |
| 2823 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 2824 | } finally { |
| 2825 | Binder.restoreCallingIdentity(identity); |
| 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | @Override |
| 2830 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 2831 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2832 | "setVoWiFiRoamingModeSetting"); |
| 2833 | final long identity = Binder.clearCallingIdentity(); |
| 2834 | try { |
| 2835 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2836 | ImsManager.getInstance(mPhone.getContext(), |
| 2837 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 2838 | } finally { |
| 2839 | Binder.restoreCallingIdentity(identity); |
| 2840 | } |
| 2841 | } |
| 2842 | |
| 2843 | @Override |
| 2844 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 2845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2846 | "setRttCapabilityEnabled"); |
| 2847 | final long identity = Binder.clearCallingIdentity(); |
| 2848 | try { |
| 2849 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2850 | ImsManager.getInstance(mPhone.getContext(), |
| 2851 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 2852 | } finally { |
| 2853 | Binder.restoreCallingIdentity(identity); |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | @Override |
| 2858 | public boolean isTtyOverVolteEnabled(int subId) { |
| 2859 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 2860 | final long identity = Binder.clearCallingIdentity(); |
| 2861 | try { |
| 2862 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2863 | return ImsManager.getInstance(mPhone.getContext(), |
| 2864 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 2865 | } finally { |
| 2866 | Binder.restoreCallingIdentity(identity); |
| 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 2871 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 2872 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 2873 | throw new IllegalArgumentException("Invalid Subscription Id."); |
| 2874 | } |
| 2875 | return slotId; |
| 2876 | } |
| 2877 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2878 | /** |
| 2879 | * Returns the network type for a subId |
| 2880 | */ |
| 2881 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2882 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2883 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2884 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2885 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2886 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2887 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2888 | final long identity = Binder.clearCallingIdentity(); |
| 2889 | try { |
| 2890 | final Phone phone = getPhone(subId); |
| 2891 | if (phone != null) { |
| 2892 | return phone.getServiceState().getDataNetworkType(); |
| 2893 | } else { |
| 2894 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2895 | } |
| 2896 | } finally { |
| 2897 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2898 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | /** |
| 2902 | * Returns the data network type |
| 2903 | */ |
| 2904 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2905 | public int getDataNetworkType(String callingPackage) { |
| 2906 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | /** |
| 2910 | * Returns the data network type for a subId |
| 2911 | */ |
| 2912 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2913 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2914 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2915 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2916 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2917 | } |
| 2918 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2919 | final long identity = Binder.clearCallingIdentity(); |
| 2920 | try { |
| 2921 | final Phone phone = getPhone(subId); |
| 2922 | if (phone != null) { |
| 2923 | return phone.getServiceState().getDataNetworkType(); |
| 2924 | } else { |
| 2925 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2926 | } |
| 2927 | } finally { |
| 2928 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2929 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2933 | * Returns the Voice network type for a subId |
| 2934 | */ |
| 2935 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2936 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2937 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2938 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2939 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2940 | } |
| 2941 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2942 | final long identity = Binder.clearCallingIdentity(); |
| 2943 | try { |
| 2944 | final Phone phone = getPhone(subId); |
| 2945 | if (phone != null) { |
| 2946 | return phone.getServiceState().getVoiceNetworkType(); |
| 2947 | } else { |
| 2948 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2949 | } |
| 2950 | } finally { |
| 2951 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2952 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | /** |
| 2956 | * @return true if a ICC card is present |
| 2957 | */ |
| 2958 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2959 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2960 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 2961 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2965 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2966 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2967 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2968 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2969 | final long identity = Binder.clearCallingIdentity(); |
| 2970 | try { |
| 2971 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2972 | if (phone != null) { |
| 2973 | return phone.getIccCard().hasIccCard(); |
| 2974 | } else { |
| 2975 | return false; |
| 2976 | } |
| 2977 | } finally { |
| 2978 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 2979 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | /** |
| 2983 | * Return if the current radio is LTE on CDMA. This |
| 2984 | * is a tri-state return value as for a period of time |
| 2985 | * the mode may be unknown. |
| 2986 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2987 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2988 | * @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] | 2989 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2990 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2991 | @Override |
| 2992 | public int getLteOnCdmaMode(String callingPackage) { |
| 2993 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2994 | } |
| 2995 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2996 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2997 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2998 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2999 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3000 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3001 | } |
| 3002 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3003 | final long identity = Binder.clearCallingIdentity(); |
| 3004 | try { |
| 3005 | final Phone phone = getPhone(subId); |
| 3006 | if (phone == null) { |
| 3007 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3008 | } else { |
| 3009 | return phone.getLteOnCdmaMode(); |
| 3010 | } |
| 3011 | } finally { |
| 3012 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3013 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3014 | } |
| 3015 | |
| 3016 | public void setPhone(Phone phone) { |
| 3017 | mPhone = phone; |
| 3018 | } |
| 3019 | |
| 3020 | /** |
| 3021 | * {@hide} |
| 3022 | * Returns Default subId, 0 in the case of single standby. |
| 3023 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3024 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3025 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3026 | } |
| 3027 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3028 | private int getSlotForDefaultSubscription() { |
| 3029 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3030 | } |
| 3031 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3032 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3033 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3034 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3035 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3036 | private boolean isActiveSubscription(int subId) { |
| 3037 | return mSubscriptionController.isActiveSubId(subId); |
| 3038 | } |
| 3039 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3040 | /** |
| 3041 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3042 | */ |
| 3043 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3044 | final long identity = Binder.clearCallingIdentity(); |
| 3045 | try { |
| 3046 | return Settings.System.getInt(mPhone.getContext().getContentResolver(), |
| 3047 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3048 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3049 | } finally { |
| 3050 | Binder.restoreCallingIdentity(identity); |
| 3051 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | /** |
| 3055 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3056 | */ |
| 3057 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3058 | final long identity = Binder.clearCallingIdentity(); |
| 3059 | try { |
| 3060 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
| 3061 | Settings.System.putInt(mPhone.getContext().getContentResolver(), |
| 3062 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3063 | } finally { |
| 3064 | Binder.restoreCallingIdentity(identity); |
| 3065 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3066 | } |
| 3067 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3068 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3069 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3070 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3071 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3072 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3073 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3074 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3075 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3076 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3077 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3078 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3079 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3080 | final long identity = Binder.clearCallingIdentity(); |
| 3081 | try { |
| 3082 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3083 | // Only allows LPA to open logical channel to ISD-R. |
| 3084 | ComponentInfo bestComponent = |
| 3085 | EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager()); |
| 3086 | if (bestComponent == null |
| 3087 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3088 | loge("The calling package is not allowed to access ISD-R."); |
| 3089 | throw new SecurityException( |
| 3090 | "The calling package is not allowed to access ISD-R."); |
| 3091 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3092 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3093 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3094 | if (DBG) { |
| 3095 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3096 | } |
| 3097 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| 3098 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
| 3099 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 3100 | return response; |
| 3101 | } finally { |
| 3102 | Binder.restoreCallingIdentity(identity); |
| 3103 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3107 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3108 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3109 | mApp, subId, "iccCloseLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3110 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3111 | final long identity = Binder.clearCallingIdentity(); |
| 3112 | try { |
| 3113 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3114 | if (channel < 0) { |
| 3115 | return false; |
| 3116 | } |
| 3117 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
| 3118 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 3119 | return success; |
| 3120 | } finally { |
| 3121 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3122 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3126 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3127 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3128 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3129 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3130 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3131 | final long identity = Binder.clearCallingIdentity(); |
| 3132 | try { |
| 3133 | if (DBG) { |
| 3134 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3135 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3136 | + p3 + " data=" + data); |
| 3137 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3138 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3139 | if (channel < 0) { |
| 3140 | return ""; |
| 3141 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3142 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3143 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| 3144 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
| 3145 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3146 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3147 | // Append the returned status code to the end of the response payload. |
| 3148 | String s = Integer.toHexString( |
| 3149 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3150 | if (response.payload != null) { |
| 3151 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3152 | } |
| 3153 | return s; |
| 3154 | } finally { |
| 3155 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3156 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3157 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3158 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3159 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3160 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3161 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3162 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3163 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3164 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3165 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3166 | final long identity = Binder.clearCallingIdentity(); |
| 3167 | try { |
| 3168 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3169 | && TextUtils.equals(ISDR_AID, data)) { |
| 3170 | // Only allows LPA to select ISD-R. |
| 3171 | ComponentInfo bestComponent = |
| 3172 | EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager()); |
| 3173 | if (bestComponent == null |
| 3174 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3175 | loge("The calling package is not allowed to select ISD-R."); |
| 3176 | throw new SecurityException( |
| 3177 | "The calling package is not allowed to select ISD-R."); |
| 3178 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3179 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3180 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3181 | if (DBG) { |
| 3182 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3183 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3184 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3185 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3186 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 3187 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
| 3188 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3189 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3190 | // Append the returned status code to the end of the response payload. |
| 3191 | String s = Integer.toHexString( |
| 3192 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3193 | if (response.payload != null) { |
| 3194 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3195 | } |
| 3196 | return s; |
| 3197 | } finally { |
| 3198 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3199 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3200 | } |
| 3201 | |
| 3202 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3203 | 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] | 3204 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3205 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3206 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3207 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3208 | final long identity = Binder.clearCallingIdentity(); |
| 3209 | try { |
| 3210 | if (DBG) { |
| 3211 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3212 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3213 | } |
| 3214 | |
| 3215 | IccIoResult response = |
| 3216 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3217 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3218 | subId); |
| 3219 | |
| 3220 | if (DBG) { |
| 3221 | log("Exchange SIM_IO [R]" + response); |
| 3222 | } |
| 3223 | |
| 3224 | byte[] result = null; |
| 3225 | int length = 2; |
| 3226 | if (response.payload != null) { |
| 3227 | length = 2 + response.payload.length; |
| 3228 | result = new byte[length]; |
| 3229 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3230 | } else { |
| 3231 | result = new byte[length]; |
| 3232 | } |
| 3233 | |
| 3234 | result[length - 1] = (byte) response.sw2; |
| 3235 | result[length - 2] = (byte) response.sw1; |
| 3236 | return result; |
| 3237 | } finally { |
| 3238 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3239 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3242 | /** |
| 3243 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3244 | * on a particular subscription |
| 3245 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3246 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3247 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3248 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3249 | return null; |
| 3250 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3251 | |
| 3252 | final long identity = Binder.clearCallingIdentity(); |
| 3253 | try { |
| 3254 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3255 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3256 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3257 | return null; |
| 3258 | } |
| 3259 | Object response = sendRequest( |
| 3260 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3261 | if (response instanceof String[]) { |
| 3262 | return (String[]) response; |
| 3263 | } |
| 3264 | // Response is an Exception of some kind, |
| 3265 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3266 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3267 | } finally { |
| 3268 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3269 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3270 | } |
| 3271 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3272 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3273 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3274 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3275 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3276 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3277 | final long identity = Binder.clearCallingIdentity(); |
| 3278 | try { |
| 3279 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3280 | if (response.payload == null) { |
| 3281 | return ""; |
| 3282 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3283 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3284 | // Append the returned status code to the end of the response payload. |
| 3285 | String s = Integer.toHexString( |
| 3286 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3287 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3288 | return s; |
| 3289 | } finally { |
| 3290 | Binder.restoreCallingIdentity(identity); |
| 3291 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3292 | } |
| 3293 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3294 | /** |
| 3295 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3296 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3297 | * |
| 3298 | * @param itemID the ID of the item to read |
| 3299 | * @return the NV item as a String, or null on error. |
| 3300 | */ |
| 3301 | @Override |
| 3302 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3303 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3304 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3305 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3306 | |
| 3307 | final long identity = Binder.clearCallingIdentity(); |
| 3308 | try { |
| 3309 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3310 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3311 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 3312 | return value; |
| 3313 | } finally { |
| 3314 | Binder.restoreCallingIdentity(identity); |
| 3315 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | /** |
| 3319 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3320 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3321 | * |
| 3322 | * @param itemID the ID of the item to read |
| 3323 | * @param itemValue the value to write, as a String |
| 3324 | * @return true on success; false on any failure |
| 3325 | */ |
| 3326 | @Override |
| 3327 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3328 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3329 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3330 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3331 | |
| 3332 | final long identity = Binder.clearCallingIdentity(); |
| 3333 | try { |
| 3334 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 3335 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3336 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3337 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 3338 | return success; |
| 3339 | } finally { |
| 3340 | Binder.restoreCallingIdentity(identity); |
| 3341 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3342 | } |
| 3343 | |
| 3344 | /** |
| 3345 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 3346 | * Used for device configuration by some CDMA operators. |
| 3347 | * |
| 3348 | * @param preferredRoamingList byte array containing the new PRL |
| 3349 | * @return true on success; false on any failure |
| 3350 | */ |
| 3351 | @Override |
| 3352 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3353 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3354 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3355 | |
| 3356 | final long identity = Binder.clearCallingIdentity(); |
| 3357 | try { |
| 3358 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 3359 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 3360 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 3361 | return success; |
| 3362 | } finally { |
| 3363 | Binder.restoreCallingIdentity(identity); |
| 3364 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3368 | * 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] | 3369 | * Used for device configuration by some CDMA operators. |
| 3370 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3371 | * @param slotIndex - device slot. |
| 3372 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3373 | * @return true on success; false on any failure |
| 3374 | */ |
| 3375 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3376 | public boolean resetModemConfig(int slotIndex) { |
| 3377 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3378 | if (phone != null) { |
| 3379 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3380 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3381 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3382 | final long identity = Binder.clearCallingIdentity(); |
| 3383 | try { |
| 3384 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 3385 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 3386 | return success; |
| 3387 | } finally { |
| 3388 | Binder.restoreCallingIdentity(identity); |
| 3389 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3390 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3391 | return false; |
| 3392 | } |
| 3393 | |
| 3394 | /** |
| 3395 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 3396 | * |
| 3397 | * @param slotIndex - device slot. |
| 3398 | * |
| 3399 | * @return true on success; false on any failure |
| 3400 | */ |
| 3401 | @Override |
| 3402 | public boolean rebootModem(int slotIndex) { |
| 3403 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3404 | if (phone != null) { |
| 3405 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3406 | mApp, phone.getSubId(), "rebootModem"); |
| 3407 | |
| 3408 | final long identity = Binder.clearCallingIdentity(); |
| 3409 | try { |
| 3410 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 3411 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 3412 | return success; |
| 3413 | } finally { |
| 3414 | Binder.restoreCallingIdentity(identity); |
| 3415 | } |
| 3416 | } |
| 3417 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3418 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3419 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3420 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3421 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3422 | mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3423 | return new String[0]; |
| 3424 | } |
| 3425 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3426 | final long identity = Binder.clearCallingIdentity(); |
| 3427 | try { |
| 3428 | return mPhone.getPcscfAddress(apnType); |
| 3429 | } finally { |
| 3430 | Binder.restoreCallingIdentity(identity); |
| 3431 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3432 | } |
| 3433 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3434 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3435 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 3436 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3437 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3438 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3439 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3440 | |
| 3441 | final long identity = Binder.clearCallingIdentity(); |
| 3442 | try { |
| 3443 | PhoneFactory.getImsResolver().enableIms(slotId); |
| 3444 | } finally { |
| 3445 | Binder.restoreCallingIdentity(identity); |
| 3446 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3450 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 3451 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3452 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3453 | public void disableIms(int slotId) { |
| 3454 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3455 | |
| 3456 | final long identity = Binder.clearCallingIdentity(); |
| 3457 | try { |
| 3458 | PhoneFactory.getImsResolver().disableIms(slotId); |
| 3459 | } finally { |
| 3460 | Binder.restoreCallingIdentity(identity); |
| 3461 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | /** |
| 3465 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 3466 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 3467 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 3468 | */ |
| 3469 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3470 | IImsServiceFeatureCallback callback) { |
| 3471 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3472 | |
| 3473 | final long identity = Binder.clearCallingIdentity(); |
| 3474 | try { |
| 3475 | return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback); |
| 3476 | } finally { |
| 3477 | Binder.restoreCallingIdentity(identity); |
| 3478 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | /** |
| 3482 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 3483 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 3484 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 3485 | * listener for feature updates. |
| 3486 | */ |
| 3487 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 3488 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3489 | |
| 3490 | final long identity = Binder.clearCallingIdentity(); |
| 3491 | try { |
| 3492 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); |
| 3493 | } finally { |
| 3494 | Binder.restoreCallingIdentity(identity); |
| 3495 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3496 | } |
| 3497 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3498 | /** |
| 3499 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| 3500 | * specified. |
| 3501 | */ |
| 3502 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 3503 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3504 | |
| 3505 | final long identity = Binder.clearCallingIdentity(); |
| 3506 | try { |
| 3507 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); |
| 3508 | } finally { |
| 3509 | Binder.restoreCallingIdentity(identity); |
| 3510 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3511 | } |
| 3512 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3513 | /** |
| 3514 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| 3515 | * specified. |
| 3516 | */ |
| 3517 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 3518 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3519 | |
| 3520 | final long identity = Binder.clearCallingIdentity(); |
| 3521 | try { |
| 3522 | return PhoneFactory.getImsResolver().getImsConfig(slotId, feature); |
| 3523 | } finally { |
| 3524 | Binder.restoreCallingIdentity(identity); |
| 3525 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3526 | } |
| 3527 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 3528 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3529 | * Sets the ImsService Package Name that Telephony will bind to. |
| 3530 | * |
| 3531 | * @param slotId the slot ID that the ImsService should bind for. |
| 3532 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 3533 | * ImsService is the device default ImsService. |
| 3534 | * @param packageName The package name of the application that contains the ImsService to bind |
| 3535 | * to. |
| 3536 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 3537 | * @hide |
| 3538 | */ |
| 3539 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3540 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3541 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3542 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3543 | "setImsService"); |
| 3544 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3545 | final long identity = Binder.clearCallingIdentity(); |
| 3546 | try { |
| 3547 | return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId, |
| 3548 | isCarrierImsService, packageName); |
| 3549 | } finally { |
| 3550 | Binder.restoreCallingIdentity(identity); |
| 3551 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | /** |
| 3555 | * Return the ImsService configuration. |
| 3556 | * |
| 3557 | * @param slotId The slot that the ImsService is associated with. |
| 3558 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 3559 | * the device default. |
| 3560 | * @return the package name of the ImsService configuration. |
| 3561 | */ |
| 3562 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3563 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3564 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3565 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3566 | "getImsService"); |
| 3567 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3568 | final long identity = Binder.clearCallingIdentity(); |
| 3569 | try { |
| 3570 | return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId, |
| 3571 | isCarrierImsService); |
| 3572 | } finally { |
| 3573 | Binder.restoreCallingIdentity(identity); |
| 3574 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3575 | } |
| 3576 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3577 | public void setImsRegistrationState(boolean registered) { |
| 3578 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3579 | |
| 3580 | final long identity = Binder.clearCallingIdentity(); |
| 3581 | try { |
| 3582 | mPhone.setImsRegistrationState(registered); |
| 3583 | } finally { |
| 3584 | Binder.restoreCallingIdentity(identity); |
| 3585 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3589 | * Set the network selection mode to automatic. |
| 3590 | * |
| 3591 | */ |
| 3592 | @Override |
| 3593 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3594 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3595 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3596 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3597 | if (!isActiveSubscription(subId)) { |
| 3598 | return; |
| 3599 | } |
| 3600 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3601 | final long identity = Binder.clearCallingIdentity(); |
| 3602 | try { |
| 3603 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 3604 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 3605 | } finally { |
| 3606 | Binder.restoreCallingIdentity(identity); |
| 3607 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3608 | } |
| 3609 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3610 | /** |
| 3611 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 3612 | * |
| 3613 | * @param subId the id of the subscription. |
| 3614 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 3615 | * the operator to attach to. |
| 3616 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 3617 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 3618 | * normal network selection next time. |
| 3619 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3620 | */ |
| 3621 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3622 | public boolean setNetworkSelectionModeManual( |
| 3623 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3625 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3626 | |
| 3627 | if (!isActiveSubscription(subId)) { |
| 3628 | return false; |
| 3629 | } |
| 3630 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3631 | final long identity = Binder.clearCallingIdentity(); |
| 3632 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3633 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3634 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3635 | if (DBG) { |
| 3636 | log("setNetworkSelectionModeManual: subId: " + subId |
| 3637 | + " operator: " + operatorInfo); |
| 3638 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3639 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 3640 | } finally { |
| 3641 | Binder.restoreCallingIdentity(identity); |
| 3642 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | /** |
| 3646 | * Scans for available networks. |
| 3647 | */ |
| 3648 | @Override |
| 3649 | public CellNetworkScanResult getCellNetworkScanResults(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3650 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3651 | mApp, subId, "getCellNetworkScanResults"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3652 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3653 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3654 | try { |
| 3655 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3656 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3657 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3658 | } finally { |
| 3659 | Binder.restoreCallingIdentity(identity); |
| 3660 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3664 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3665 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3666 | * @param subId id of the subscription |
| 3667 | * @param request contains the radio access networks with bands/channels to scan |
| 3668 | * @param messenger callback messenger for scan results or errors |
| 3669 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3670 | * @return the id of the requested scan which can be used to stop the scan. |
| 3671 | */ |
| 3672 | @Override |
| 3673 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
| 3674 | IBinder binder) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3675 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3676 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3677 | |
| 3678 | final long identity = Binder.clearCallingIdentity(); |
| 3679 | try { |
| 3680 | return mNetworkScanRequestTracker.startNetworkScan( |
| 3681 | request, messenger, binder, getPhone(subId)); |
| 3682 | } finally { |
| 3683 | Binder.restoreCallingIdentity(identity); |
| 3684 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3685 | } |
| 3686 | |
| 3687 | /** |
| 3688 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3689 | * |
| 3690 | * @param subId id of the subscription |
| 3691 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3692 | */ |
| 3693 | @Override |
| 3694 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3695 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3696 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3697 | |
| 3698 | final long identity = Binder.clearCallingIdentity(); |
| 3699 | try { |
| 3700 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 3701 | } finally { |
| 3702 | Binder.restoreCallingIdentity(identity); |
| 3703 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3707 | * Get the calculated preferred network type. |
| 3708 | * Used for debugging incorrect network type. |
| 3709 | * |
| 3710 | * @return the preferred network type, defined in RILConstants.java. |
| 3711 | */ |
| 3712 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3713 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3714 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3715 | mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3716 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 3717 | } |
| 3718 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3719 | final long identity = Binder.clearCallingIdentity(); |
| 3720 | try { |
| 3721 | // FIXME: need to get SubId from somewhere. |
| 3722 | return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); |
| 3723 | } finally { |
| 3724 | Binder.restoreCallingIdentity(identity); |
| 3725 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3729 | * Get the preferred network type. |
| 3730 | * Used for device configuration by some CDMA operators. |
| 3731 | * |
| 3732 | * @return the preferred network type, defined in RILConstants.java. |
| 3733 | */ |
| 3734 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3735 | public int getPreferredNetworkType(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3736 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3737 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3738 | |
| 3739 | final long identity = Binder.clearCallingIdentity(); |
| 3740 | try { |
| 3741 | if (DBG) log("getPreferredNetworkType"); |
| 3742 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 3743 | int networkType = (result != null ? result[0] : -1); |
| 3744 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 3745 | return networkType; |
| 3746 | } finally { |
| 3747 | Binder.restoreCallingIdentity(identity); |
| 3748 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | /** |
| 3752 | * Set the preferred network type. |
| 3753 | * Used for device configuration by some CDMA operators. |
| 3754 | * |
| 3755 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 3756 | * @return true on success; false on any failure. |
| 3757 | */ |
| 3758 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3759 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3760 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3761 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3762 | |
| 3763 | final long identity = Binder.clearCallingIdentity(); |
| 3764 | try { |
| 3765 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 3766 | Boolean success = (Boolean) sendRequest( |
| 3767 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 3768 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 3769 | if (success) { |
| 3770 | Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
| 3771 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 3772 | } |
| 3773 | return success; |
| 3774 | } finally { |
| 3775 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 3776 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3777 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 3778 | |
| 3779 | /** |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 3780 | * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 3781 | * SystemProperty to decide whether DUN APN is required for |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 3782 | * tethering. |
| 3783 | * |
| 3784 | * @return 0: Not required. 1: required. 2: Not set. |
| 3785 | * @hide |
| 3786 | */ |
| 3787 | @Override |
| 3788 | public int getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3789 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3790 | |
| 3791 | final long identity = Binder.clearCallingIdentity(); |
| 3792 | try { |
| 3793 | int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(), |
| 3794 | Settings.Global.TETHER_DUN_REQUIRED, 2); |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 3795 | // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3796 | if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) { |
| 3797 | dunRequired = 1; |
| 3798 | } |
| 3799 | return dunRequired; |
| 3800 | } finally { |
| 3801 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 3802 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 3806 | * Set mobile data enabled |
| 3807 | * Used by the user through settings etc to turn on/off mobile data |
| 3808 | * |
| 3809 | * @param enable {@code true} turn turn data on, else {@code false} |
| 3810 | */ |
| 3811 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 3812 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3813 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3814 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3815 | |
| 3816 | final long identity = Binder.clearCallingIdentity(); |
| 3817 | try { |
| 3818 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 3819 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 3820 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3821 | if (phone != null) { |
| 3822 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
| 3823 | phone.setUserDataEnabled(enable); |
| 3824 | } else { |
| 3825 | loge("setUserDataEnabled: no phone for subId=" + subId); |
| 3826 | } |
| 3827 | } finally { |
| 3828 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 3829 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 3830 | } |
| 3831 | |
| 3832 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 3833 | * Get the user enabled state of Mobile Data. |
| 3834 | * |
| 3835 | * TODO: remove and use isUserDataEnabled. |
| 3836 | * This can't be removed now because some vendor codes |
| 3837 | * calls through ITelephony directly while they should |
| 3838 | * use TelephonyManager. |
| 3839 | * |
| 3840 | * @return true on enabled |
| 3841 | */ |
| 3842 | @Override |
| 3843 | public boolean getDataEnabled(int subId) { |
| 3844 | return isUserDataEnabled(subId); |
| 3845 | } |
| 3846 | |
| 3847 | /** |
| 3848 | * Get whether mobile data is enabled per user setting. |
| 3849 | * |
| 3850 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 3851 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 3852 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 3853 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 3854 | * |
| 3855 | * @return {@code true} if data is enabled else {@code false} |
| 3856 | */ |
| 3857 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 3858 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 3859 | try { |
| 3860 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 3861 | null); |
| 3862 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3863 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3864 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 3865 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3866 | |
| 3867 | final long identity = Binder.clearCallingIdentity(); |
| 3868 | try { |
| 3869 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 3870 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 3871 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3872 | if (phone != null) { |
| 3873 | boolean retVal = phone.isUserDataEnabled(); |
| 3874 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 3875 | return retVal; |
| 3876 | } else { |
| 3877 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 3878 | return false; |
| 3879 | } |
| 3880 | } finally { |
| 3881 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 3882 | } |
| 3883 | } |
| 3884 | |
| 3885 | /** |
| 3886 | * Get whether mobile data is enabled. |
| 3887 | * |
| 3888 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 3889 | * whether mobile data is actually enabled. |
| 3890 | * |
| 3891 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 3892 | * |
| 3893 | * @return {@code true} if data is enabled else {@code false} |
| 3894 | */ |
| 3895 | @Override |
| 3896 | public boolean isDataEnabled(int subId) { |
| 3897 | try { |
| 3898 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 3899 | null); |
| 3900 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3901 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3902 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 3903 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3904 | |
| 3905 | final long identity = Binder.clearCallingIdentity(); |
| 3906 | try { |
| 3907 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 3908 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 3909 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3910 | if (phone != null) { |
| 3911 | boolean retVal = phone.isDataEnabled(); |
| 3912 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 3913 | return retVal; |
| 3914 | } else { |
| 3915 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 3916 | return false; |
| 3917 | } |
| 3918 | } finally { |
| 3919 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 3920 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 3921 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 3922 | |
| 3923 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3924 | public int getCarrierPrivilegeStatus(int subId) { |
| 3925 | final Phone phone = getPhone(subId); |
| 3926 | if (phone == null) { |
| 3927 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 3928 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 3929 | } |
| 3930 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 3931 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 3932 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 3933 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 3934 | } |
| 3935 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3936 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 3937 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 3938 | |
| 3939 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3940 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 3941 | final Phone phone = getPhone(subId); |
| 3942 | if (phone == null) { |
| 3943 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 3944 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 3945 | } |
| 3946 | UiccProfile profile = |
| 3947 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 3948 | if (profile == null) { |
| 3949 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 3950 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 3951 | } |
| 3952 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 3953 | } |
| 3954 | |
| 3955 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 3956 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 3957 | if (TextUtils.isEmpty(pkgName)) |
| 3958 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Shishir Agrawal | 2140925 | 2015-01-15 23:33:50 -0800 | [diff] [blame] | 3959 | UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 3960 | if (card == null) { |
| 3961 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 3962 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 3963 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 3964 | return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName); |
| 3965 | } |
| 3966 | |
| 3967 | @Override |
| 3968 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 3969 | if (TextUtils.isEmpty(pkgName)) |
| 3970 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 3971 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 3972 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3973 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 3974 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 3975 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 3976 | continue; |
| 3977 | } |
| 3978 | |
| 3979 | result = card.getCarrierPrivilegeStatus( |
| 3980 | mPhone.getContext().getPackageManager(), pkgName); |
| 3981 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 3982 | break; |
| 3983 | } |
| 3984 | } |
| 3985 | |
| 3986 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 3987 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 3988 | |
| 3989 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 3990 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 3991 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 3992 | loge("phoneId " + phoneId + " is not valid."); |
| 3993 | return null; |
| 3994 | } |
| 3995 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 3996 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 3997 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 3998 | return null ; |
| 3999 | } |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4000 | return card.getCarrierPackageNamesForIntent( |
Svetoslav | 483aff7 | 2015-04-21 14:16:07 -0700 | [diff] [blame] | 4001 | mPhone.getContext().getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4002 | } |
| 4003 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4004 | @Override |
| 4005 | public List<String> getPackagesWithCarrierPrivileges() { |
| 4006 | PackageManager pm = mPhone.getContext().getPackageManager(); |
| 4007 | List<String> privilegedPackages = new ArrayList<>(); |
| 4008 | List<PackageInfo> packages = null; |
| 4009 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4010 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4011 | if (card == null) { |
| 4012 | // No UICC in that slot. |
| 4013 | continue; |
| 4014 | } |
| 4015 | if (card.hasCarrierPrivilegeRules()) { |
| 4016 | if (packages == null) { |
| 4017 | // Only check packages in user 0 for now |
| 4018 | packages = pm.getInstalledPackagesAsUser( |
| 4019 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4020 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4021 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4022 | } |
| 4023 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4024 | PackageInfo pkgInfo = packages.get(p); |
| 4025 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4026 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4027 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4028 | privilegedPackages.add(pkgInfo.packageName); |
| 4029 | } |
| 4030 | } |
| 4031 | } |
| 4032 | } |
| 4033 | return privilegedPackages; |
| 4034 | } |
| 4035 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4036 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4037 | final Phone phone = getPhone(subId); |
| 4038 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4039 | if (card == null) { |
| 4040 | loge("getIccId: No UICC"); |
| 4041 | return null; |
| 4042 | } |
| 4043 | String iccId = card.getIccId(); |
| 4044 | if (TextUtils.isEmpty(iccId)) { |
| 4045 | loge("getIccId: ICC ID is null or empty."); |
| 4046 | return null; |
| 4047 | } |
| 4048 | return iccId; |
| 4049 | } |
| 4050 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4051 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4052 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4053 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4054 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4055 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4056 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4057 | final long identity = Binder.clearCallingIdentity(); |
| 4058 | try { |
| 4059 | final String iccId = getIccId(subId); |
| 4060 | final Phone phone = getPhone(subId); |
| 4061 | if (phone == null) { |
| 4062 | return false; |
| 4063 | } |
| 4064 | final String subscriberId = phone.getSubscriberId(); |
| 4065 | |
| 4066 | if (DBG_MERGE) { |
| 4067 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4068 | + subscriberId + " to " + number); |
| 4069 | } |
| 4070 | |
| 4071 | if (TextUtils.isEmpty(iccId)) { |
| 4072 | return false; |
| 4073 | } |
| 4074 | |
| 4075 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4076 | |
| 4077 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4078 | if (alphaTag == null) { |
| 4079 | editor.remove(alphaTagPrefKey); |
| 4080 | } else { |
| 4081 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4082 | } |
| 4083 | |
| 4084 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4085 | // track all merged IMSIs based on line number |
| 4086 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4087 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4088 | if (number == null) { |
| 4089 | editor.remove(numberPrefKey); |
| 4090 | editor.remove(subscriberPrefKey); |
| 4091 | } else { |
| 4092 | editor.putString(numberPrefKey, number); |
| 4093 | editor.putString(subscriberPrefKey, subscriberId); |
| 4094 | } |
| 4095 | |
| 4096 | editor.commit(); |
| 4097 | return true; |
| 4098 | } finally { |
| 4099 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4100 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4104 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4105 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4106 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4107 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4108 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4109 | return null; |
| 4110 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4111 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4112 | final long identity = Binder.clearCallingIdentity(); |
| 4113 | try { |
| 4114 | String iccId = getIccId(subId); |
| 4115 | if (iccId != null) { |
| 4116 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4117 | if (DBG_MERGE) { |
| 4118 | log("getLine1NumberForDisplay returning " |
| 4119 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4120 | } |
| 4121 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4122 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4123 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4124 | return null; |
| 4125 | } finally { |
| 4126 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4127 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4128 | } |
| 4129 | |
| 4130 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4131 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4132 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4133 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4134 | return null; |
| 4135 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4136 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4137 | final long identity = Binder.clearCallingIdentity(); |
| 4138 | try { |
| 4139 | String iccId = getIccId(subId); |
| 4140 | if (iccId != null) { |
| 4141 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4142 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4143 | } |
| 4144 | return null; |
| 4145 | } finally { |
| 4146 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4147 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4148 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4149 | |
| 4150 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4151 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4152 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4153 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4154 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4155 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4156 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4157 | return null; |
| 4158 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4159 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4160 | final long identity = Binder.clearCallingIdentity(); |
| 4161 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4162 | final Context context = mPhone.getContext(); |
| 4163 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4164 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4165 | |
| 4166 | // Figure out what subscribers are currently active |
| 4167 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4168 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4169 | // the process, where TelephonyManager was instantiated. |
| 4170 | // Otherwise AppOps check will fail. |
| 4171 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4172 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4173 | for (int subId : subIds) { |
| 4174 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4175 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4176 | |
| 4177 | // First pass, find a number override for an active subscriber |
| 4178 | String mergeNumber = null; |
| 4179 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4180 | for (String key : prefs.keySet()) { |
| 4181 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4182 | final String subscriberId = (String) prefs.get(key); |
| 4183 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4184 | final String iccId = key.substring( |
| 4185 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4186 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4187 | mergeNumber = (String) prefs.get(numberKey); |
| 4188 | if (DBG_MERGE) { |
| 4189 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4190 | + " for active subscriber " + subscriberId); |
| 4191 | } |
| 4192 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4193 | break; |
| 4194 | } |
| 4195 | } |
| 4196 | } |
| 4197 | } |
| 4198 | |
| 4199 | // Shortcut when no active merged subscribers |
| 4200 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4201 | return null; |
| 4202 | } |
| 4203 | |
| 4204 | // Second pass, find all subscribers under that line override |
| 4205 | final ArraySet<String> result = new ArraySet<>(); |
| 4206 | for (String key : prefs.keySet()) { |
| 4207 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4208 | final String number = (String) prefs.get(key); |
| 4209 | if (mergeNumber.equals(number)) { |
| 4210 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4211 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4212 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4213 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4214 | result.add(subscriberId); |
| 4215 | } |
| 4216 | } |
| 4217 | } |
| 4218 | } |
| 4219 | |
| 4220 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4221 | Arrays.sort(resultArray); |
| 4222 | if (DBG_MERGE) { |
| 4223 | Slog.d(LOG_TAG, |
| 4224 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4225 | } |
| 4226 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4227 | } finally { |
| 4228 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4229 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4233 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4234 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4235 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4236 | |
| 4237 | final long identity = Binder.clearCallingIdentity(); |
| 4238 | try { |
| 4239 | final Phone phone = getPhone(subId); |
| 4240 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4241 | } finally { |
| 4242 | Binder.restoreCallingIdentity(identity); |
| 4243 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4244 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4245 | |
| 4246 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4247 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4248 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 4249 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4250 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4251 | |
| 4252 | final long identity = Binder.clearCallingIdentity(); |
| 4253 | try { |
| 4254 | final Phone phone = getPhone(subId); |
| 4255 | if (phone == null) { |
| 4256 | return false; |
| 4257 | } |
| 4258 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 4259 | cdmaNonRoamingList); |
| 4260 | } finally { |
| 4261 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4262 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4266 | @Deprecated |
| 4267 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 4268 | enforceModifyPermission(); |
| 4269 | |
| 4270 | int returnValue = 0; |
| 4271 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4272 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4273 | if(result.exception == null) { |
| 4274 | if (result.result != null) { |
| 4275 | byte[] responseData = (byte[])(result.result); |
| 4276 | if(responseData.length > oemResp.length) { |
| 4277 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 4278 | responseData.length + "bytes. Buffer Size is " + |
| 4279 | oemResp.length + "bytes."); |
| 4280 | } |
| 4281 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 4282 | returnValue = responseData.length; |
| 4283 | } |
| 4284 | } else { |
| 4285 | CommandException ex = (CommandException) result.exception; |
| 4286 | returnValue = ex.getCommandError().ordinal(); |
| 4287 | if(returnValue > 0) returnValue *= -1; |
| 4288 | } |
| 4289 | } catch (RuntimeException e) { |
| 4290 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 4291 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 4292 | if(returnValue > 0) returnValue *= -1; |
| 4293 | } |
| 4294 | |
| 4295 | return returnValue; |
| 4296 | } |
| 4297 | |
| 4298 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4299 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 4300 | try { |
| 4301 | ProxyController.getInstance().setRadioCapability(rafs); |
| 4302 | } catch (RuntimeException e) { |
| 4303 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 4304 | } |
| 4305 | } |
| 4306 | |
| 4307 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4308 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4309 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4310 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4311 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4312 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4313 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4314 | final long identity = Binder.clearCallingIdentity(); |
| 4315 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4316 | TelephonyPermissions |
| 4317 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4318 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 4319 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4320 | } finally { |
| 4321 | Binder.restoreCallingIdentity(identity); |
| 4322 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4323 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4324 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4325 | |
| 4326 | @Override |
| 4327 | public void enableVideoCalling(boolean enable) { |
| 4328 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4329 | |
| 4330 | final long identity = Binder.clearCallingIdentity(); |
| 4331 | try { |
| 4332 | ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable); |
| 4333 | } finally { |
| 4334 | Binder.restoreCallingIdentity(identity); |
| 4335 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4339 | public boolean isVideoCallingEnabled(String callingPackage) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4340 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4341 | mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
| 4342 | return false; |
| 4343 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4344 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4345 | final long identity = Binder.clearCallingIdentity(); |
| 4346 | try { |
| 4347 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 4348 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 4349 | // In the long run, we may instead need to check if there exists a connection service |
| 4350 | // which can support video calling. |
| 4351 | ImsManager imsManager = |
| 4352 | ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()); |
| 4353 | return imsManager.isVtEnabledByPlatform() |
| 4354 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 4355 | && imsManager.isVtEnabledByUser(); |
| 4356 | } finally { |
| 4357 | Binder.restoreCallingIdentity(identity); |
| 4358 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4359 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 4360 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4361 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4362 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 4363 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4364 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4365 | return false; |
| 4366 | } |
| 4367 | |
| 4368 | final long identity = Binder.clearCallingIdentity(); |
| 4369 | try { |
| 4370 | CarrierConfigManager configManager = |
| 4371 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 4372 | return configManager.getConfigForSubId(mPhone.getSubId()) |
| 4373 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 4374 | } finally { |
| 4375 | Binder.restoreCallingIdentity(identity); |
| 4376 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4377 | } |
| 4378 | |
| 4379 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4380 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 4381 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4382 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4383 | return false; |
| 4384 | } |
| 4385 | |
| 4386 | final long identity = Binder.clearCallingIdentity(); |
| 4387 | try { |
| 4388 | CarrierConfigManager configManager = |
| 4389 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 4390 | return configManager.getConfigForSubId(mPhone.getSubId()) |
| 4391 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 4392 | } finally { |
| 4393 | Binder.restoreCallingIdentity(identity); |
| 4394 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4395 | } |
| 4396 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4397 | @Override |
| 4398 | public boolean isTtyModeSupported() { |
| 4399 | TelecomManager telecomManager = TelecomManager.from(mPhone.getContext()); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 4400 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4401 | } |
| 4402 | |
| 4403 | @Override |
| 4404 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4405 | final long identity = Binder.clearCallingIdentity(); |
| 4406 | try { |
| 4407 | return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled); |
| 4408 | } finally { |
| 4409 | Binder.restoreCallingIdentity(identity); |
| 4410 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4411 | } |
| 4412 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4413 | /** |
| 4414 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 4415 | * support for the feature and device firmware support. |
| 4416 | * |
| 4417 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 4418 | */ |
| 4419 | @Override |
| 4420 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4421 | final long identity = Binder.clearCallingIdentity(); |
| 4422 | try { |
| 4423 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId( |
| 4424 | mPhone.getSubId()).getBoolean( |
| 4425 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 4426 | boolean isDeviceSupported = |
| 4427 | mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
| 4428 | return isCarrierSupported && isDeviceSupported; |
| 4429 | } finally { |
| 4430 | Binder.restoreCallingIdentity(identity); |
| 4431 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 4432 | } |
| 4433 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4434 | /** |
| 4435 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 4436 | * both also support RTT. |
| 4437 | */ |
| 4438 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4439 | final long identity = Binder.clearCallingIdentity(); |
| 4440 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4441 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4442 | mPhone.getContext().getContentResolver(), |
| 4443 | Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 4444 | } finally { |
| 4445 | Binder.restoreCallingIdentity(identity); |
| 4446 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4449 | /** |
| 4450 | * Returns the unique device ID of phone, for example, the IMEI for |
| 4451 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 4452 | * |
| 4453 | * <p>Requires Permission: |
| 4454 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 4455 | */ |
| 4456 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4457 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4458 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4459 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4460 | return null; |
| 4461 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4462 | int subId = phone.getSubId(); |
| 4463 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4464 | mApp, subId, callingPackage, "getDeviceId")) { |
| 4465 | return null; |
| 4466 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4467 | |
| 4468 | final long identity = Binder.clearCallingIdentity(); |
| 4469 | try { |
| 4470 | return phone.getDeviceId(); |
| 4471 | } finally { |
| 4472 | Binder.restoreCallingIdentity(identity); |
| 4473 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4474 | } |
| 4475 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4476 | /** |
| 4477 | * {@hide} |
| 4478 | * Returns the IMS Registration Status on a particular subid |
| 4479 | * |
| 4480 | * @param subId |
| 4481 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4482 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4483 | Phone phone = getPhone(subId); |
| 4484 | if (phone != null) { |
| 4485 | return phone.isImsRegistered(); |
| 4486 | } else { |
| 4487 | return false; |
| 4488 | } |
| 4489 | } |
| 4490 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4491 | @Override |
| 4492 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4493 | final long identity = Binder.clearCallingIdentity(); |
| 4494 | try { |
| 4495 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 4496 | } finally { |
| 4497 | Binder.restoreCallingIdentity(identity); |
| 4498 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4499 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 4500 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4501 | /** |
| 4502 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4503 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4504 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4505 | final long identity = Binder.clearCallingIdentity(); |
| 4506 | try { |
| 4507 | Phone phone = getPhone(subId); |
| 4508 | if (phone != null) { |
| 4509 | return phone.isWifiCallingEnabled(); |
| 4510 | } else { |
| 4511 | return false; |
| 4512 | } |
| 4513 | } finally { |
| 4514 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4515 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4516 | } |
| 4517 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4518 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4519 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4520 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4521 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4522 | final long identity = Binder.clearCallingIdentity(); |
| 4523 | try { |
| 4524 | Phone phone = getPhone(subId); |
| 4525 | if (phone != null) { |
| 4526 | return phone.isVideoEnabled(); |
| 4527 | } else { |
| 4528 | return false; |
| 4529 | } |
| 4530 | } finally { |
| 4531 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4532 | } |
| 4533 | } |
| 4534 | |
| 4535 | /** |
| 4536 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 4537 | * defined in {@link ImsRegistrationImplBase}. |
| 4538 | */ |
| 4539 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4540 | final long identity = Binder.clearCallingIdentity(); |
| 4541 | try { |
| 4542 | Phone phone = getPhone(subId); |
| 4543 | if (phone != null) { |
| 4544 | return phone.getImsRegistrationTech(); |
| 4545 | } else { |
| 4546 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 4547 | } |
| 4548 | } finally { |
| 4549 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4550 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4551 | } |
| 4552 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4553 | @Override |
| 4554 | public void factoryReset(int subId) { |
| 4555 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4556 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 4557 | return; |
| 4558 | } |
| 4559 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4560 | final long identity = Binder.clearCallingIdentity(); |
| 4561 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4562 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 4563 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4564 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4565 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4566 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
| 4567 | mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId)); |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 4568 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4569 | } |
| 4570 | } finally { |
| 4571 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4572 | } |
| 4573 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4574 | |
| 4575 | @Override |
| 4576 | public String getLocaleFromDefaultSim() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4577 | final long identity = Binder.clearCallingIdentity(); |
| 4578 | try { |
| 4579 | // We query all subscriptions instead of just the active ones, because |
| 4580 | // this might be called early on in the provisioning flow when the |
| 4581 | // subscriptions potentially aren't active yet. |
| 4582 | final List<SubscriptionInfo> slist = getAllSubscriptionInfoList(); |
| 4583 | if (slist == null || slist.isEmpty()) { |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4584 | return null; |
| 4585 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4586 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4587 | // This function may be called very early, say, from the setup wizard, at |
| 4588 | // which point we won't have a default subscription set. If that's the case |
| 4589 | // we just choose the first, which will be valid in "most cases". |
| 4590 | final int defaultSubId = getDefaultSubscription(); |
| 4591 | SubscriptionInfo info = null; |
| 4592 | if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 4593 | info = slist.get(0); |
| 4594 | } else { |
| 4595 | for (SubscriptionInfo item : slist) { |
| 4596 | if (item.getSubscriptionId() == defaultSubId) { |
| 4597 | info = item; |
| 4598 | break; |
| 4599 | } |
| 4600 | } |
| 4601 | |
| 4602 | if (info == null) { |
| 4603 | return null; |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 4604 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4605 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4606 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4607 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 4608 | // preferences (EF-PL and EF-LI)... |
| 4609 | final int mcc = info.getMcc(); |
| 4610 | final Phone defaultPhone = getPhone(info.getSubscriptionId()); |
| 4611 | String simLanguage = null; |
| 4612 | if (defaultPhone != null) { |
| 4613 | final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs(); |
| 4614 | if (localeFromDefaultSim != null) { |
| 4615 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 4616 | if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim); |
| 4617 | return localeFromDefaultSim.toLanguageTag(); |
| 4618 | } else { |
| 4619 | simLanguage = localeFromDefaultSim.getLanguage(); |
| 4620 | } |
| 4621 | } |
| 4622 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4623 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4624 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 4625 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 4626 | // the SIM and carrier preferences does not include a country we add the country |
| 4627 | // determined from the SIM MCC to provide an exact locale. |
| 4628 | final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, |
| 4629 | simLanguage); |
| 4630 | if (mccLocale != null) { |
| 4631 | if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale); |
| 4632 | return mccLocale.toLanguageTag(); |
| 4633 | } |
| 4634 | |
| 4635 | if (DBG) log("No locale found - returning null"); |
| 4636 | return null; |
| 4637 | } finally { |
| 4638 | Binder.restoreCallingIdentity(identity); |
| 4639 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4640 | } |
| 4641 | |
| 4642 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4643 | return mSubscriptionController.getAllSubInfoList( |
| 4644 | mPhone.getContext().getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4645 | } |
| 4646 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4647 | /** |
| 4648 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 4649 | */ |
| 4650 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
| 4651 | return mSubscriptionController.getActiveSubscriptionInfoList( |
| 4652 | mPhone.getContext().getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4653 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4654 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4655 | private final ModemActivityInfo mLastModemActivityInfo = |
| 4656 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 4657 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4658 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4659 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 4660 | * representing the state of the modem. |
| 4661 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4662 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 4663 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4664 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4665 | */ |
| 4666 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4667 | public void requestModemActivityInfo(ResultReceiver result) { |
| 4668 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4669 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4670 | |
| 4671 | final long identity = Binder.clearCallingIdentity(); |
| 4672 | try { |
| 4673 | ModemActivityInfo ret = null; |
| 4674 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4675 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 4676 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 4677 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4678 | if (isModemActivityInfoValid(info)) { |
| 4679 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 4680 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 4681 | mergedTxTimeMs[i] = |
| 4682 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 4683 | } |
| 4684 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 4685 | mLastModemActivityInfo.setSleepTimeMillis( |
| 4686 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 4687 | mLastModemActivityInfo.setIdleTimeMillis( |
| 4688 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 4689 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 4690 | mLastModemActivityInfo.setRxTimeMillis( |
| 4691 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 4692 | mLastModemActivityInfo.setEnergyUsed( |
| 4693 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4694 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4695 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 4696 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 4697 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 4698 | mLastModemActivityInfo.getTxTimeMillis(), |
| 4699 | mLastModemActivityInfo.getRxTimeMillis(), |
| 4700 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4701 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4702 | Bundle bundle = new Bundle(); |
| 4703 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 4704 | result.send(0, bundle); |
| 4705 | } finally { |
| 4706 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4707 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4708 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4709 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 4710 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 4711 | // less than total activity duration. |
| 4712 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 4713 | if (info == null) { |
| 4714 | return false; |
| 4715 | } |
| 4716 | int activityDurationMs = |
| 4717 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 4718 | int totalTxTimeMs = 0; |
| 4719 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 4720 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 4721 | } |
| 4722 | return (info.isValid() |
| 4723 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 4724 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 4725 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 4726 | && (totalTxTimeMs <= activityDurationMs)); |
| 4727 | } |
| 4728 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4729 | /** |
| 4730 | * {@hide} |
| 4731 | * Returns the service state information on specified subscription. |
| 4732 | */ |
| 4733 | @Override |
| 4734 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4735 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4736 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4737 | return null; |
| 4738 | } |
| 4739 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4740 | final long identity = Binder.clearCallingIdentity(); |
| 4741 | try { |
| 4742 | final Phone phone = getPhone(subId); |
| 4743 | if (phone == null) { |
| 4744 | return null; |
| 4745 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4746 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4747 | return phone.getServiceState(); |
| 4748 | } finally { |
| 4749 | Binder.restoreCallingIdentity(identity); |
| 4750 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4751 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4752 | |
| 4753 | /** |
| 4754 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 4755 | * |
| 4756 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 4757 | * voicemail ringtone. |
| 4758 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 4759 | * PhoneAccount. |
| 4760 | */ |
| 4761 | @Override |
| 4762 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4763 | final long identity = Binder.clearCallingIdentity(); |
| 4764 | try { |
| 4765 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 4766 | if (phone == null) { |
| 4767 | phone = mPhone; |
| 4768 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4769 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4770 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 4771 | } finally { |
| 4772 | Binder.restoreCallingIdentity(identity); |
| 4773 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4774 | } |
| 4775 | |
| 4776 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4777 | * Sets the per-account voicemail ringtone. |
| 4778 | * |
| 4779 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 4780 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 4781 | * |
| 4782 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 4783 | * voicemail ringtone. |
| 4784 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 4785 | * PhoneAccount. |
| 4786 | */ |
| 4787 | @Override |
| 4788 | public void setVoicemailRingtoneUri(String callingPackage, |
| 4789 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
| 4790 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4791 | if (!TextUtils.equals(callingPackage, |
| 4792 | TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4793 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4794 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 4795 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4796 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4797 | |
| 4798 | final long identity = Binder.clearCallingIdentity(); |
| 4799 | try { |
| 4800 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 4801 | if (phone == null) { |
| 4802 | phone = mPhone; |
| 4803 | } |
| 4804 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 4805 | } finally { |
| 4806 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4807 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4811 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 4812 | * |
| 4813 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 4814 | * voicemail vibration setting. |
| 4815 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 4816 | */ |
| 4817 | @Override |
| 4818 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4819 | final long identity = Binder.clearCallingIdentity(); |
| 4820 | try { |
| 4821 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 4822 | if (phone == null) { |
| 4823 | phone = mPhone; |
| 4824 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4825 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4826 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 4827 | } finally { |
| 4828 | Binder.restoreCallingIdentity(identity); |
| 4829 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4830 | } |
| 4831 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 4832 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4833 | * Sets the per-account voicemail vibration. |
| 4834 | * |
| 4835 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 4836 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 4837 | * |
| 4838 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 4839 | * voicemail vibration setting. |
| 4840 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 4841 | * specific PhoneAccount. |
| 4842 | */ |
| 4843 | @Override |
| 4844 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 4845 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
| 4846 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4847 | if (!TextUtils.equals(callingPackage, |
| 4848 | TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4849 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4850 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 4851 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4852 | } |
| 4853 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4854 | final long identity = Binder.clearCallingIdentity(); |
| 4855 | try { |
| 4856 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 4857 | if (phone == null) { |
| 4858 | phone = mPhone; |
| 4859 | } |
| 4860 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 4861 | } finally { |
| 4862 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4863 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 4867 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 4868 | * |
| 4869 | * @throws SecurityException if the caller does not have the required permission |
| 4870 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4871 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 4872 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4873 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4877 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 4878 | * permission. |
| 4879 | * |
| 4880 | * @throws SecurityException if the caller does not have the required permission |
| 4881 | */ |
| 4882 | private void enforceSendSmsPermission() { |
| 4883 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 4884 | } |
| 4885 | |
| 4886 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4887 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4888 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4889 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4890 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4891 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4892 | final long identity = Binder.clearCallingIdentity(); |
| 4893 | try { |
| 4894 | ComponentName componentName = |
| 4895 | RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId); |
| 4896 | if (componentName == null) { |
| 4897 | throw new SecurityException( |
| 4898 | "Caller not current active visual voicemail package[null]"); |
| 4899 | } |
| 4900 | String vvmPackage = componentName.getPackageName(); |
| 4901 | if (!callingPackage.equals(vvmPackage)) { |
| 4902 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 4903 | + vvmPackage + "]"); |
| 4904 | } |
| 4905 | } finally { |
| 4906 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4907 | } |
| 4908 | } |
| 4909 | |
| 4910 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 4911 | * Return the application ID for the app type. |
| 4912 | * |
| 4913 | * @param subId the subscription ID that this request applies to. |
| 4914 | * @param appType the uicc app type. |
| 4915 | * @return Application ID for specificied app type, or null if no uicc. |
| 4916 | */ |
| 4917 | @Override |
| 4918 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4919 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 4920 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4921 | |
| 4922 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 4923 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4924 | if (phone == null) { |
| 4925 | return null; |
| 4926 | } |
| 4927 | String aid = null; |
| 4928 | try { |
| 4929 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 4930 | .getApplicationByType(appType).getAid(); |
| 4931 | } catch (Exception e) { |
| 4932 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 4933 | } |
| 4934 | return aid; |
| 4935 | } finally { |
| 4936 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 4937 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 4938 | } |
| 4939 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 4940 | /** |
| 4941 | * Return the Electronic Serial Number. |
| 4942 | * |
| 4943 | * @param subId the subscription ID that this request applies to. |
| 4944 | * @return ESN or null if error. |
| 4945 | */ |
| 4946 | @Override |
| 4947 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4948 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 4949 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4950 | |
| 4951 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 4952 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4953 | if (phone == null) { |
| 4954 | return null; |
| 4955 | } |
| 4956 | String esn = null; |
| 4957 | try { |
| 4958 | esn = phone.getEsn(); |
| 4959 | } catch (Exception e) { |
| 4960 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 4961 | } |
| 4962 | return esn; |
| 4963 | } finally { |
| 4964 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 4965 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 4966 | } |
| 4967 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 4968 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 4969 | * Return the Preferred Roaming List Version. |
| 4970 | * |
| 4971 | * @param subId the subscription ID that this request applies to. |
| 4972 | * @return PRLVersion or null if error. |
| 4973 | */ |
| 4974 | @Override |
| 4975 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4976 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 4977 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4978 | |
| 4979 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 4980 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4981 | if (phone == null) { |
| 4982 | return null; |
| 4983 | } |
| 4984 | String cdmaPrlVersion = null; |
| 4985 | try { |
| 4986 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 4987 | } catch (Exception e) { |
| 4988 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 4989 | } |
| 4990 | return cdmaPrlVersion; |
| 4991 | } finally { |
| 4992 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 4993 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 4997 | * Get snapshot of Telephony histograms |
| 4998 | * @return List of Telephony histograms |
| 4999 | * @hide |
| 5000 | */ |
| 5001 | @Override |
| 5002 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5004 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5005 | |
| 5006 | final long identity = Binder.clearCallingIdentity(); |
| 5007 | try { |
| 5008 | return RIL.getTelephonyRILTimingHistograms(); |
| 5009 | } finally { |
| 5010 | Binder.restoreCallingIdentity(identity); |
| 5011 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5012 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5013 | |
| 5014 | /** |
| 5015 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5016 | * Set the allowed carrier list for slotIndex |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5017 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5018 | * |
| 5019 | * @return The number of carriers set successfully, should match length of carriers |
| 5020 | */ |
| 5021 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5022 | public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5023 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5024 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5025 | |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5026 | if (carriers == null) { |
| 5027 | throw new NullPointerException("carriers cannot be null"); |
| 5028 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5029 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5030 | final long identity = Binder.clearCallingIdentity(); |
| 5031 | try { |
| 5032 | int subId = SubscriptionManager.getSubId(slotIndex)[0]; |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5033 | int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId, |
| 5034 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5035 | return retVal[0]; |
| 5036 | } finally { |
| 5037 | Binder.restoreCallingIdentity(identity); |
| 5038 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5039 | } |
| 5040 | |
| 5041 | /** |
| 5042 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5043 | * Get the allowed carrier list for slotIndex. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5044 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5045 | * |
| 5046 | * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list |
| 5047 | * means all carriers are allowed. |
| 5048 | */ |
| 5049 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5050 | public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5051 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5052 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5053 | |
| 5054 | final long identity = Binder.clearCallingIdentity(); |
| 5055 | try { |
| 5056 | int subId = SubscriptionManager.getSubId(slotIndex)[0]; |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5057 | return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId, |
| 5058 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5059 | } finally { |
| 5060 | Binder.restoreCallingIdentity(identity); |
| 5061 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5062 | } |
| 5063 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5064 | /** |
| 5065 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5066 | * @param subId the subscription ID that this action applies to. |
| 5067 | * @param enabled control enable or disable metered apns. |
| 5068 | * {@hide} |
| 5069 | */ |
| 5070 | @Override |
| 5071 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5072 | enforceModifyPermission(); |
| 5073 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5074 | |
| 5075 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5076 | if (phone == null) { |
| 5077 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5078 | return; |
| 5079 | } |
| 5080 | try { |
| 5081 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5082 | } catch (Exception e) { |
| 5083 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5084 | } finally { |
| 5085 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5086 | } |
| 5087 | } |
| 5088 | |
| 5089 | /** |
| 5090 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5091 | * @param subId the subscription ID that this action applies to. |
| 5092 | * @param enabled control enable or disable radio. |
| 5093 | * {@hide} |
| 5094 | */ |
| 5095 | @Override |
| 5096 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5097 | enforceModifyPermission(); |
| 5098 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5099 | |
| 5100 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5101 | if (phone == null) { |
| 5102 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5103 | return; |
| 5104 | } |
| 5105 | try { |
| 5106 | phone.carrierActionSetRadioEnabled(enabled); |
| 5107 | } catch (Exception e) { |
| 5108 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5109 | } finally { |
| 5110 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5111 | } |
| 5112 | } |
| 5113 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5114 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5115 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5116 | * network status based on which carrier apps could apply actions accordingly, |
| 5117 | * enable/disable default url handler for example. |
| 5118 | * |
| 5119 | * @param subId the subscription ID that this action applies to. |
| 5120 | * @param report control start/stop reporting the default network status. |
| 5121 | * {@hide} |
| 5122 | */ |
| 5123 | @Override |
| 5124 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5125 | enforceModifyPermission(); |
| 5126 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5127 | |
| 5128 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5129 | if (phone == null) { |
| 5130 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5131 | return; |
| 5132 | } |
| 5133 | try { |
| 5134 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5135 | } catch (Exception e) { |
| 5136 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5137 | } finally { |
| 5138 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5139 | } |
| 5140 | } |
| 5141 | |
| 5142 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5143 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5144 | * bug report is being generated. |
| 5145 | */ |
| 5146 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5147 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5148 | if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5149 | != PackageManager.PERMISSION_GRANTED) { |
| 5150 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5151 | + Binder.getCallingPid() |
| 5152 | + ", uid=" + Binder.getCallingUid() |
| 5153 | + "without permission " |
| 5154 | + android.Manifest.permission.DUMP); |
| 5155 | return; |
| 5156 | } |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5157 | DumpsysHandler.dump(mPhone.getContext(), fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5158 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5159 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5160 | @Override |
| 5161 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5162 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5163 | throws RemoteException { |
| 5164 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5165 | } |
| 5166 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5167 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5168 | * Get aggregated video call data usage since boot. |
| 5169 | * |
| 5170 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5171 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5172 | * {@hide} |
| 5173 | */ |
| 5174 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5175 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5176 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5177 | null); |
| 5178 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5179 | final long identity = Binder.clearCallingIdentity(); |
| 5180 | try { |
| 5181 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5182 | // records the delta with the corresponding network identity. |
| 5183 | // We just return the total video call data usage snapshot since boot. |
| 5184 | Phone phone = getPhone(subId); |
| 5185 | if (phone != null) { |
| 5186 | return phone.getVtDataUsage(perUidStats); |
| 5187 | } |
| 5188 | return null; |
| 5189 | } finally { |
| 5190 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5191 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5192 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5193 | |
| 5194 | /** |
| 5195 | * Policy control of data connection. Usually used when data limit is passed. |
| 5196 | * @param enabled True if enabling the data, otherwise disabling. |
| 5197 | * @param subId Subscription index |
| 5198 | * {@hide} |
| 5199 | */ |
| 5200 | @Override |
| 5201 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 5202 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5203 | |
| 5204 | final long identity = Binder.clearCallingIdentity(); |
| 5205 | try { |
| 5206 | Phone phone = getPhone(subId); |
| 5207 | if (phone != null) { |
| 5208 | phone.setPolicyDataEnabled(enabled); |
| 5209 | } |
| 5210 | } finally { |
| 5211 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5212 | } |
| 5213 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5214 | |
| 5215 | /** |
| 5216 | * Get Client request stats |
| 5217 | * @return List of Client Request Stats |
| 5218 | * @hide |
| 5219 | */ |
| 5220 | @Override |
| 5221 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5222 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5223 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5224 | return null; |
| 5225 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5226 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5227 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5228 | final long identity = Binder.clearCallingIdentity(); |
| 5229 | try { |
| 5230 | if (phone != null) { |
| 5231 | return phone.getClientRequestStats(); |
| 5232 | } |
| 5233 | |
| 5234 | return null; |
| 5235 | } finally { |
| 5236 | Binder.restoreCallingIdentity(identity); |
| 5237 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5238 | } |
| 5239 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5240 | private WorkSource getWorkSource(int uid) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5241 | String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5242 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5243 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5244 | |
| 5245 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5246 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5247 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5248 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5249 | * @param state State of SIM (power down, power up, pass through) |
| 5250 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 5251 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 5252 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5253 | * |
| 5254 | **/ |
| 5255 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5256 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5257 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5258 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5259 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5260 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5261 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5262 | final long identity = Binder.clearCallingIdentity(); |
| 5263 | try { |
| 5264 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5265 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5266 | } |
| 5267 | } finally { |
| 5268 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5269 | } |
| 5270 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5271 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5272 | private boolean isUssdApiAllowed(int subId) { |
| 5273 | CarrierConfigManager configManager = |
| 5274 | (CarrierConfigManager) mPhone.getContext().getSystemService( |
| 5275 | Context.CARRIER_CONFIG_SERVICE); |
| 5276 | if (configManager == null) { |
| 5277 | return false; |
| 5278 | } |
| 5279 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 5280 | if (pb == null) { |
| 5281 | return false; |
| 5282 | } |
| 5283 | return pb.getBoolean( |
| 5284 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 5285 | } |
| 5286 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5287 | /** |
| 5288 | * Check if phone is in emergency callback mode |
| 5289 | * @return true if phone is in emergency callback mode |
| 5290 | * @param subId sub id |
| 5291 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 5292 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5293 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5294 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5295 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5296 | |
| 5297 | final long identity = Binder.clearCallingIdentity(); |
| 5298 | try { |
| 5299 | if (phone != null) { |
| 5300 | return phone.isInEcm(); |
| 5301 | } else { |
| 5302 | return false; |
| 5303 | } |
| 5304 | } finally { |
| 5305 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5306 | } |
| 5307 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5308 | |
| 5309 | /** |
| 5310 | * Get the current signal strength information for the given subscription. |
| 5311 | * Because this information is not updated when the device is in a low power state |
| 5312 | * it should not be relied-upon to be current. |
| 5313 | * @param subId Subscription index |
| 5314 | * @return the most recent cached signal strength info from the modem |
| 5315 | */ |
| 5316 | @Override |
| 5317 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5318 | final long identity = Binder.clearCallingIdentity(); |
| 5319 | try { |
| 5320 | Phone p = getPhone(subId); |
| 5321 | if (p == null) { |
| 5322 | return null; |
| 5323 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5324 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5325 | return p.getSignalStrength(); |
| 5326 | } finally { |
| 5327 | Binder.restoreCallingIdentity(identity); |
| 5328 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5329 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5330 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5331 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 5332 | * Get the current modem radio state for the given slot. |
| 5333 | * @param slotIndex slot index. |
| 5334 | * @param callingPackage the name of the package making the call. |
| 5335 | * @return the current radio power state from the modem |
| 5336 | */ |
| 5337 | @Override |
| 5338 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 5339 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5340 | if (phone != null) { |
| 5341 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5342 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 5343 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5344 | } |
| 5345 | |
| 5346 | final long identity = Binder.clearCallingIdentity(); |
| 5347 | try { |
| 5348 | return phone.getRadioPowerState(); |
| 5349 | } finally { |
| 5350 | Binder.restoreCallingIdentity(identity); |
| 5351 | } |
| 5352 | } |
| 5353 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5354 | } |
| 5355 | |
| 5356 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5357 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 5358 | * |
| 5359 | * <p>Requires one of the following permissions: |
| 5360 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 5361 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 5362 | * privileges. |
| 5363 | * |
| 5364 | * @param subId subscription id |
| 5365 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 5366 | * {@code false}. |
| 5367 | */ |
| 5368 | @Override |
| 5369 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5370 | boolean isEnabled = false; |
| 5371 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5372 | try { |
| 5373 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5374 | null /* message */); |
| 5375 | Phone phone = getPhone(subId); |
| 5376 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5377 | } catch (Exception e) { |
| 5378 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5379 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5380 | } finally { |
| 5381 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5382 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5383 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5384 | } |
| 5385 | |
| 5386 | |
| 5387 | /** |
| 5388 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 5389 | * |
| 5390 | * <p> Requires permission: |
| 5391 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 5392 | * privileges. |
| 5393 | * |
| 5394 | * @param subId subscription id |
| 5395 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 5396 | */ |
| 5397 | @Override |
| 5398 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5399 | final long identity = Binder.clearCallingIdentity(); |
| 5400 | try { |
| 5401 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5402 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5403 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5404 | Phone phone = getPhone(subId); |
| 5405 | if (phone != null) { |
| 5406 | phone.setDataRoamingEnabled(isEnabled); |
| 5407 | } |
| 5408 | } finally { |
| 5409 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5410 | } |
| 5411 | } |
| 5412 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5413 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 5414 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 5415 | boolean isAllowed = true; |
| 5416 | final long identity = Binder.clearCallingIdentity(); |
| 5417 | try { |
| 5418 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5419 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 5420 | Phone phone = getPhone(subId); |
| 5421 | if (phone != null) { |
| 5422 | isAllowed = phone.isCspPlmnEnabled(); |
| 5423 | } |
| 5424 | } finally { |
| 5425 | Binder.restoreCallingIdentity(identity); |
| 5426 | } |
| 5427 | return isAllowed; |
| 5428 | } |
| 5429 | |
| 5430 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5431 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5432 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5433 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5434 | final long identity = Binder.clearCallingIdentity(); |
| 5435 | try { |
| 5436 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 5437 | if (slots == null) { |
| 5438 | Rlog.i(LOG_TAG, "slots is null."); |
| 5439 | return null; |
| 5440 | } |
| 5441 | |
| 5442 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 5443 | for (int i = 0; i < slots.length; i++) { |
| 5444 | UiccSlot slot = slots[i]; |
| 5445 | if (slot == null) { |
| 5446 | continue; |
| 5447 | } |
| 5448 | |
| 5449 | String cardId; |
| 5450 | UiccCard card = slot.getUiccCard(); |
| 5451 | if (card != null) { |
| 5452 | cardId = card.getCardId(); |
| 5453 | } else { |
| 5454 | cardId = slot.getIccId(); |
| 5455 | } |
| 5456 | |
| 5457 | int cardState = 0; |
| 5458 | switch (slot.getCardState()) { |
| 5459 | case CARDSTATE_ABSENT: |
| 5460 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 5461 | break; |
| 5462 | case CARDSTATE_PRESENT: |
| 5463 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 5464 | break; |
| 5465 | case CARDSTATE_ERROR: |
| 5466 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 5467 | break; |
| 5468 | case CARDSTATE_RESTRICTED: |
| 5469 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 5470 | break; |
| 5471 | default: |
| 5472 | break; |
| 5473 | |
| 5474 | } |
| 5475 | |
| 5476 | infos[i] = new UiccSlotInfo( |
| 5477 | slot.isActive(), |
| 5478 | slot.isEuicc(), |
| 5479 | cardId, |
| 5480 | cardState, |
| 5481 | slot.getPhoneId(), |
| 5482 | slot.isExtendedApduSupported()); |
| 5483 | } |
| 5484 | return infos; |
| 5485 | } finally { |
| 5486 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 5487 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5488 | } |
| 5489 | |
| 5490 | @Override |
| 5491 | public boolean switchSlots(int[] physicalSlots) { |
| 5492 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5493 | |
| 5494 | final long identity = Binder.clearCallingIdentity(); |
| 5495 | try { |
| 5496 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 5497 | } finally { |
| 5498 | Binder.restoreCallingIdentity(identity); |
| 5499 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5500 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5501 | |
| 5502 | @Override |
| 5503 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 5504 | enforceModifyPermission(); |
| 5505 | final Phone phone = getPhone(subId); |
| 5506 | if (phone == null) { |
| 5507 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 5508 | return; |
| 5509 | } |
| 5510 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5511 | final long identity = Binder.clearCallingIdentity(); |
| 5512 | try { |
| 5513 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 5514 | } finally { |
| 5515 | Binder.restoreCallingIdentity(identity); |
| 5516 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5517 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5518 | |
| 5519 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 5520 | * A test API to reload the UICC profile. |
| 5521 | * |
| 5522 | * <p>Requires that the calling app has permission |
| 5523 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5524 | * @hide |
| 5525 | */ |
| 5526 | @Override |
| 5527 | public void refreshUiccProfile(int subId) { |
| 5528 | enforceModifyPermission(); |
| 5529 | |
| 5530 | final long identity = Binder.clearCallingIdentity(); |
| 5531 | try { |
| 5532 | Phone phone = getPhone(subId); |
| 5533 | if (phone == null) { |
| 5534 | return; |
| 5535 | } |
| 5536 | UiccCard uiccCard = phone.getUiccCard(); |
| 5537 | if (uiccCard == null) { |
| 5538 | return; |
| 5539 | } |
| 5540 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 5541 | if (uiccProfile == null) { |
| 5542 | return; |
| 5543 | } |
| 5544 | uiccProfile.refresh(); |
| 5545 | } finally { |
| 5546 | Binder.restoreCallingIdentity(identity); |
| 5547 | } |
| 5548 | } |
| 5549 | |
| 5550 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5551 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 5552 | */ |
| 5553 | private boolean getDefaultDataEnabled() { |
| 5554 | return "true".equalsIgnoreCase( |
| 5555 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 5556 | } |
| 5557 | |
| 5558 | /** |
| 5559 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 5560 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 5561 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 5562 | */ |
| 5563 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 5564 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
| 5565 | mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 5566 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 5567 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 5568 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 5569 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 5570 | return isDataRoamingEnabled; |
| 5571 | } |
| 5572 | |
| 5573 | /** |
| 5574 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 5575 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 5576 | */ |
| 5577 | private int getDefaultNetworkType(int subId) { |
| 5578 | return Integer.parseInt( |
| 5579 | TelephonyManager.getTelephonyProperty( |
| 5580 | mSubscriptionController.getPhoneId(subId), |
| 5581 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 5582 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 5583 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5584 | |
| 5585 | @Override |
| 5586 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 5587 | gid1, String gid2, String plmn, String spn) { |
| 5588 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5589 | |
| 5590 | final long identity = Binder.clearCallingIdentity(); |
| 5591 | try { |
| 5592 | final Phone phone = getPhone(subId); |
| 5593 | if (phone == null) { |
| 5594 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 5595 | return; |
| 5596 | } |
| 5597 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 5598 | } finally { |
| 5599 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5600 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | @Override |
| 5604 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5605 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5606 | |
| 5607 | final long identity = Binder.clearCallingIdentity(); |
| 5608 | try { |
| 5609 | final Phone phone = getPhone(subId); |
| 5610 | if (phone == null) { |
| 5611 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 5612 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 5613 | } |
| 5614 | return phone.getCarrierIdListVersion(); |
| 5615 | } finally { |
| 5616 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5617 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5618 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 5619 | |
| 5620 | @Override |
| 5621 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 5622 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5623 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 5624 | return -1; |
| 5625 | } |
| 5626 | |
| 5627 | final long identity = Binder.clearCallingIdentity(); |
| 5628 | try { |
| 5629 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 5630 | } finally { |
| 5631 | Binder.restoreCallingIdentity(identity); |
| 5632 | } |
| 5633 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5634 | |
| 5635 | @Override |
| 5636 | public int getCdmaRoamingMode(int subId) { |
| 5637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5638 | mApp, subId, "getCdmaRoamingMode"); |
| 5639 | |
| 5640 | final long identity = Binder.clearCallingIdentity(); |
| 5641 | try { |
| 5642 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 5643 | } finally { |
| 5644 | Binder.restoreCallingIdentity(identity); |
| 5645 | } |
| 5646 | } |
| 5647 | |
| 5648 | @Override |
| 5649 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 5650 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5651 | mApp, subId, "setCdmaRoamingMode"); |
| 5652 | |
| 5653 | final long identity = Binder.clearCallingIdentity(); |
| 5654 | try { |
| 5655 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 5656 | } finally { |
| 5657 | Binder.restoreCallingIdentity(identity); |
| 5658 | } |
| 5659 | } |
| 5660 | |
| 5661 | @Override |
| 5662 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 5663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5664 | mApp, subId, "setCdmaSubscriptionMode"); |
| 5665 | |
| 5666 | final long identity = Binder.clearCallingIdentity(); |
| 5667 | try { |
| 5668 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 5669 | } finally { |
| 5670 | Binder.restoreCallingIdentity(identity); |
| 5671 | } |
| 5672 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 5673 | |
| 5674 | @Override |
| 5675 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 5676 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 5677 | Phone phone = getPhone(subId); |
| 5678 | if (phone == null) { |
| 5679 | return null; |
| 5680 | } |
| 5681 | final long identity = Binder.clearCallingIdentity(); |
| 5682 | try { |
| 5683 | UiccProfile profile = UiccController.getInstance() |
| 5684 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 5685 | if (profile != null) { |
| 5686 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 5687 | } |
| 5688 | } finally { |
| 5689 | Binder.restoreCallingIdentity(identity); |
| 5690 | } |
| 5691 | return null; |
| 5692 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5693 | } |