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