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; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 28 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 29 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 30 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 31 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.net.Uri; |
| 33 | import android.os.AsyncResult; |
| 34 | import android.os.Binder; |
| 35 | import android.os.Bundle; |
| 36 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 37 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.os.Looper; |
| 39 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 40 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 41 | import android.os.PersistableBundle; |
Brad Ebinger | 7e934f5 | 2017-12-14 14:26:15 -0800 | [diff] [blame^] | 42 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 43 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.ServiceManager; |
| 45 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 46 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 47 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 48 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 49 | import android.provider.Settings; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 50 | import android.service.carrier.CarrierIdentifier; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 51 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 52 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 53 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 54 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.telephony.CellInfo; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 56 | import android.telephony.ClientRequestStats; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 57 | import android.telephony.IccOpenLogicalChannelResponse; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 58 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 59 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 60 | import android.telephony.NetworkScanRequest; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 61 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 62 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 63 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 64 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 65 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 66 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 67 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 68 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 69 | import android.telephony.TelephonyManager; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 70 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 71 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 72 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 73 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 75 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 76 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 77 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 78 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 79 | import com.android.ims.internal.IImsMMTelFeature; |
| 80 | import com.android.ims.internal.IImsRcsFeature; |
Brad Ebinger | 7e934f5 | 2017-12-14 14:26:15 -0800 | [diff] [blame^] | 81 | import com.android.ims.internal.IImsRegistration; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 82 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 83 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 84 | import com.android.internal.telephony.CallStateException; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 85 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 86 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 87 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 88 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 89 | import com.android.internal.telephony.IccCard; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 90 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 91 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 92 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 93 | import com.android.internal.telephony.Phone; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 94 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 95 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 96 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 97 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 98 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 99 | import com.android.internal.telephony.RILConstants; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 100 | import com.android.internal.telephony.SubscriptionController; |
Jonathan Basseri | 0392395 | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 101 | import com.android.internal.telephony.TelephonyProperties; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 102 | import com.android.internal.telephony.euicc.EuiccConnector; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 103 | import com.android.internal.telephony.uicc.IccIoResult; |
| 104 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 105 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 106 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 107 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 108 | import com.android.internal.telephony.uicc.UiccController; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 109 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 110 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 111 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 112 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 113 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 114 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 115 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 116 | import java.io.FileDescriptor; |
| 117 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 118 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 119 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 120 | import java.util.Arrays; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 121 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 122 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 123 | import java.util.Map; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 124 | |
| 125 | /** |
| 126 | * Implementation of the ITelephony interface. |
| 127 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 128 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 130 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 131 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 132 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 133 | |
| 134 | // Message codes used with mMainThreadHandler |
| 135 | private static final int CMD_HANDLE_PIN_MMI = 1; |
| 136 | private static final int CMD_HANDLE_NEIGHBORING_CELL = 2; |
| 137 | private static final int EVENT_NEIGHBORING_CELL_DONE = 3; |
| 138 | private static final int CMD_ANSWER_RINGING_CALL = 4; |
| 139 | private static final int CMD_END_CALL = 5; // not used yet |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 140 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 141 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 142 | private static final int CMD_OPEN_CHANNEL = 9; |
| 143 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 144 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 145 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 146 | private static final int CMD_NV_READ_ITEM = 13; |
| 147 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 148 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 149 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 150 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 151 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
| 152 | private static final int CMD_NV_RESET_CONFIG = 19; |
| 153 | private static final int EVENT_NV_RESET_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 154 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 155 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 156 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 157 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 158 | private static final int CMD_SEND_ENVELOPE = 25; |
| 159 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 160 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 161 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 162 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 163 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 164 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 165 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 166 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 167 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 168 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 169 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 170 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 171 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 172 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 173 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 174 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 175 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 176 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 177 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 178 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 179 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 180 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 181 | |
| 182 | /** The singleton instance. */ |
| 183 | private static PhoneInterfaceManager sInstance; |
| 184 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 185 | private PhoneGlobals mApp; |
| 186 | private Phone mPhone; |
| 187 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 188 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 189 | private AppOpsManager mAppOps; |
| 190 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 191 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 192 | private SharedPreferences mTelephonySharedPreferences; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 193 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 194 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 195 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 196 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 197 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 198 | // The AID of ISD-R. |
| 199 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 200 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 201 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 202 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 203 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 204 | * A request object to use for transmitting data to an ICC. |
| 205 | */ |
| 206 | private static final class IccAPDUArgument { |
| 207 | public int channel, cla, command, p1, p2, p3; |
| 208 | public String data; |
| 209 | |
| 210 | public IccAPDUArgument(int channel, int cla, int command, |
| 211 | int p1, int p2, int p3, String data) { |
| 212 | this.channel = channel; |
| 213 | this.cla = cla; |
| 214 | this.command = command; |
| 215 | this.p1 = p1; |
| 216 | this.p2 = p2; |
| 217 | this.p3 = p3; |
| 218 | this.data = data; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 223 | * A request object to use for transmitting data to an ICC. |
| 224 | */ |
| 225 | private static final class ManualNetworkSelectionArgument { |
| 226 | public OperatorInfo operatorInfo; |
| 227 | public boolean persistSelection; |
| 228 | |
| 229 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 230 | this.operatorInfo = operatorInfo; |
| 231 | this.persistSelection = persistSelection; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 236 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 237 | * request after sending. The main thread will notify the request when it is complete. |
| 238 | */ |
| 239 | private static final class MainThreadRequest { |
| 240 | /** The argument to use for the request */ |
| 241 | public Object argument; |
| 242 | /** The result of the request that is run on the main thread */ |
| 243 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 244 | // The subscriber id that this request applies to. Defaults to |
| 245 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 246 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 247 | |
| 248 | public MainThreadRequest(Object argument) { |
| 249 | this.argument = argument; |
| 250 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 251 | |
| 252 | public MainThreadRequest(Object argument, Integer subId) { |
| 253 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 254 | if (subId != null) { |
| 255 | this.subId = subId; |
| 256 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 257 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 260 | private static final class IncomingThirdPartyCallArgs { |
| 261 | public final ComponentName component; |
| 262 | public final String callId; |
| 263 | public final String callerDisplayName; |
| 264 | |
| 265 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 266 | String callerDisplayName) { |
| 267 | this.component = component; |
| 268 | this.callId = callId; |
| 269 | this.callerDisplayName = callerDisplayName; |
| 270 | } |
| 271 | } |
| 272 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 273 | /** |
| 274 | * A handler that processes messages on the main thread in the phone process. Since many |
| 275 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 276 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 277 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 278 | * on, which will be notified when the operation completes and will contain the result of the |
| 279 | * request. |
| 280 | * |
| 281 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 282 | * note that request.result must be set to something non-null for the calling thread to |
| 283 | * unblock. |
| 284 | */ |
| 285 | private final class MainThreadHandler extends Handler { |
| 286 | @Override |
| 287 | public void handleMessage(Message msg) { |
| 288 | MainThreadRequest request; |
| 289 | Message onCompleted; |
| 290 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 291 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 292 | IccAPDUArgument iccArgument; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 293 | |
| 294 | switch (msg.what) { |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 295 | case CMD_HANDLE_USSD_REQUEST: { |
| 296 | request = (MainThreadRequest) msg.obj; |
| 297 | final Phone phone = getPhoneFromRequest(request); |
| 298 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 299 | String ussdRequest = ussdObject.first; |
| 300 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 301 | |
| 302 | if (!isUssdApiAllowed(request.subId)) { |
| 303 | // Carrier does not support use of this API, return failure. |
| 304 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 305 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 306 | Bundle returnData = new Bundle(); |
| 307 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 308 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
| 309 | |
| 310 | request.result = true; |
| 311 | synchronized (request) { |
| 312 | request.notifyAll(); |
| 313 | } |
| 314 | return; |
| 315 | } |
| 316 | |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 317 | try { |
| 318 | request.result = phone != null ? |
| 319 | phone.handleUssdRequest(ussdRequest, wrappedCallback) |
| 320 | : false; |
| 321 | } catch (CallStateException cse) { |
| 322 | request.result = false; |
| 323 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 324 | // Wake up the requesting thread |
| 325 | synchronized (request) { |
| 326 | request.notifyAll(); |
| 327 | } |
| 328 | break; |
| 329 | } |
| 330 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 331 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 332 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 333 | final Phone phone = getPhoneFromRequest(request); |
| 334 | request.result = phone != null ? |
| 335 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 336 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 337 | // Wake up the requesting thread |
| 338 | synchronized (request) { |
| 339 | request.notifyAll(); |
| 340 | } |
| 341 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 342 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 343 | |
| 344 | case CMD_HANDLE_NEIGHBORING_CELL: |
| 345 | request = (MainThreadRequest) msg.obj; |
| 346 | onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE, |
| 347 | request); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 348 | mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 349 | break; |
| 350 | |
| 351 | case EVENT_NEIGHBORING_CELL_DONE: |
| 352 | ar = (AsyncResult) msg.obj; |
| 353 | request = (MainThreadRequest) ar.userObj; |
| 354 | if (ar.exception == null && ar.result != null) { |
| 355 | request.result = ar.result; |
| 356 | } else { |
| 357 | // create an empty list to notify the waiting thread |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 358 | request.result = new ArrayList<NeighboringCellInfo>(0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 359 | } |
| 360 | // Wake up the requesting thread |
| 361 | synchronized (request) { |
| 362 | request.notifyAll(); |
| 363 | } |
| 364 | break; |
| 365 | |
| 366 | case CMD_ANSWER_RINGING_CALL: |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 367 | request = (MainThreadRequest) msg.obj; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 368 | int answer_subId = request.subId; |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 369 | answerRingingCallInternal(answer_subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 370 | break; |
| 371 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 372 | case CMD_END_CALL: |
| 373 | request = (MainThreadRequest) msg.obj; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 374 | int end_subId = request.subId; |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 375 | final boolean hungUp; |
Anthony Lee | ae4e36d | 2015-05-21 07:17:46 -0700 | [diff] [blame] | 376 | Phone phone = getPhone(end_subId); |
| 377 | if (phone == null) { |
| 378 | if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId); |
| 379 | break; |
| 380 | } |
| 381 | int phoneType = phone.getPhoneType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 382 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
| 383 | // CDMA: If the user presses the Power button we treat it as |
| 384 | // ending the complete call session |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 385 | hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 386 | } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { |
| 387 | // GSM: End the call as per the Phone state |
| 388 | hungUp = PhoneUtils.hangup(mCM); |
| 389 | } else { |
| 390 | throw new IllegalStateException("Unexpected phone type: " + phoneType); |
| 391 | } |
| 392 | if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up")); |
| 393 | request.result = hungUp; |
| 394 | // Wake up the requesting thread |
| 395 | synchronized (request) { |
| 396 | request.notifyAll(); |
| 397 | } |
| 398 | break; |
| 399 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 400 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 401 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 402 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 403 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 404 | if (uiccCard == null) { |
| 405 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 406 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 407 | synchronized (request) { |
| 408 | request.notifyAll(); |
| 409 | } |
| 410 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 411 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 412 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 413 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 414 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 415 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 416 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 417 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 418 | break; |
| 419 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 420 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 421 | ar = (AsyncResult) msg.obj; |
| 422 | request = (MainThreadRequest) ar.userObj; |
| 423 | if (ar.exception == null && ar.result != null) { |
| 424 | request.result = ar.result; |
| 425 | } else { |
| 426 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 427 | if (ar.result == null) { |
| 428 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 429 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 430 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 431 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 432 | } else { |
| 433 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 434 | } |
| 435 | } |
| 436 | synchronized (request) { |
| 437 | request.notifyAll(); |
| 438 | } |
| 439 | break; |
| 440 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 441 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 442 | request = (MainThreadRequest) msg.obj; |
| 443 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 444 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 445 | if (uiccCard == null) { |
| 446 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 447 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 448 | synchronized (request) { |
| 449 | request.notifyAll(); |
| 450 | } |
| 451 | } else { |
| 452 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 453 | request); |
| 454 | uiccCard.iccTransmitApduBasicChannel( |
| 455 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 456 | iccArgument.p3, iccArgument.data, onCompleted); |
| 457 | } |
| 458 | break; |
| 459 | |
| 460 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 461 | ar = (AsyncResult) msg.obj; |
| 462 | request = (MainThreadRequest) ar.userObj; |
| 463 | if (ar.exception == null && ar.result != null) { |
| 464 | request.result = ar.result; |
| 465 | } else { |
| 466 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 467 | if (ar.result == null) { |
| 468 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 469 | } else if (ar.exception instanceof CommandException) { |
| 470 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 471 | ar.exception); |
| 472 | } else { |
| 473 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 474 | } |
| 475 | } |
| 476 | synchronized (request) { |
| 477 | request.notifyAll(); |
| 478 | } |
| 479 | break; |
| 480 | |
| 481 | case CMD_EXCHANGE_SIM_IO: |
| 482 | request = (MainThreadRequest) msg.obj; |
| 483 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 484 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 485 | if (uiccCard == null) { |
| 486 | loge("iccExchangeSimIO: No UICC"); |
| 487 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 488 | synchronized (request) { |
| 489 | request.notifyAll(); |
| 490 | } |
| 491 | } else { |
| 492 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 493 | request); |
| 494 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 495 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 496 | iccArgument.data, onCompleted); |
| 497 | } |
| 498 | break; |
| 499 | |
| 500 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 501 | ar = (AsyncResult) msg.obj; |
| 502 | request = (MainThreadRequest) ar.userObj; |
| 503 | if (ar.exception == null && ar.result != null) { |
| 504 | request.result = ar.result; |
| 505 | } else { |
| 506 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 507 | } |
| 508 | synchronized (request) { |
| 509 | request.notifyAll(); |
| 510 | } |
| 511 | break; |
| 512 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 513 | case CMD_SEND_ENVELOPE: |
| 514 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 515 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 516 | if (uiccCard == null) { |
| 517 | loge("sendEnvelopeWithStatus: No UICC"); |
| 518 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 519 | synchronized (request) { |
| 520 | request.notifyAll(); |
| 521 | } |
| 522 | } else { |
| 523 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 524 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 525 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 526 | break; |
| 527 | |
| 528 | case EVENT_SEND_ENVELOPE_DONE: |
| 529 | ar = (AsyncResult) msg.obj; |
| 530 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 531 | if (ar.exception == null && ar.result != null) { |
| 532 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 533 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 534 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 535 | if (ar.result == null) { |
| 536 | loge("sendEnvelopeWithStatus: Empty response"); |
| 537 | } else if (ar.exception instanceof CommandException) { |
| 538 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 539 | ar.exception); |
| 540 | } else { |
| 541 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 542 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 543 | } |
| 544 | synchronized (request) { |
| 545 | request.notifyAll(); |
| 546 | } |
| 547 | break; |
| 548 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 549 | case CMD_OPEN_CHANNEL: |
| 550 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 551 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 552 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 553 | if (uiccCard == null) { |
| 554 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 555 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 556 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 557 | synchronized (request) { |
| 558 | request.notifyAll(); |
| 559 | } |
| 560 | } else { |
| 561 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 562 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 563 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 564 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 565 | break; |
| 566 | |
| 567 | case EVENT_OPEN_CHANNEL_DONE: |
| 568 | ar = (AsyncResult) msg.obj; |
| 569 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 570 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 571 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 572 | int[] result = (int[]) ar.result; |
| 573 | int channelId = result[0]; |
| 574 | byte[] selectResponse = null; |
| 575 | if (result.length > 1) { |
| 576 | selectResponse = new byte[result.length - 1]; |
| 577 | for (int i = 1; i < result.length; ++i) { |
| 578 | selectResponse[i - 1] = (byte) result[i]; |
| 579 | } |
| 580 | } |
| 581 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 582 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 583 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 584 | if (ar.result == null) { |
| 585 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 586 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 587 | if (ar.exception != null) { |
| 588 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 589 | } |
| 590 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 591 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 592 | if (ar.exception instanceof CommandException) { |
| 593 | CommandException.Error error = |
| 594 | ((CommandException) (ar.exception)).getCommandError(); |
| 595 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 596 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 597 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 598 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 602 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 603 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 604 | request.result = openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 605 | synchronized (request) { |
| 606 | request.notifyAll(); |
| 607 | } |
| 608 | break; |
| 609 | |
| 610 | case CMD_CLOSE_CHANNEL: |
| 611 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 612 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 613 | if (uiccCard == null) { |
| 614 | loge("iccCloseLogicalChannel: No UICC"); |
| 615 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 616 | synchronized (request) { |
| 617 | request.notifyAll(); |
| 618 | } |
| 619 | } else { |
| 620 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 621 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 622 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 623 | break; |
| 624 | |
| 625 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 626 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 627 | break; |
| 628 | |
| 629 | case CMD_NV_READ_ITEM: |
| 630 | request = (MainThreadRequest) msg.obj; |
| 631 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
| 632 | mPhone.nvReadItem((Integer) request.argument, onCompleted); |
| 633 | break; |
| 634 | |
| 635 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | ar = (AsyncResult) msg.obj; |
| 637 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 638 | if (ar.exception == null && ar.result != null) { |
| 639 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 640 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 641 | request.result = ""; |
| 642 | if (ar.result == null) { |
| 643 | loge("nvReadItem: Empty response"); |
| 644 | } else if (ar.exception instanceof CommandException) { |
| 645 | loge("nvReadItem: CommandException: " + |
| 646 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 648 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | synchronized (request) { |
| 652 | request.notifyAll(); |
| 653 | } |
| 654 | break; |
| 655 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 656 | case CMD_NV_WRITE_ITEM: |
| 657 | request = (MainThreadRequest) msg.obj; |
| 658 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 659 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
| 660 | mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted); |
| 661 | break; |
| 662 | |
| 663 | case EVENT_NV_WRITE_ITEM_DONE: |
| 664 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 665 | break; |
| 666 | |
| 667 | case CMD_NV_WRITE_CDMA_PRL: |
| 668 | request = (MainThreadRequest) msg.obj; |
| 669 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
| 670 | mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
| 671 | break; |
| 672 | |
| 673 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 674 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 675 | break; |
| 676 | |
| 677 | case CMD_NV_RESET_CONFIG: |
| 678 | request = (MainThreadRequest) msg.obj; |
| 679 | onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request); |
| 680 | mPhone.nvResetConfig((Integer) request.argument, onCompleted); |
| 681 | break; |
| 682 | |
| 683 | case EVENT_NV_RESET_CONFIG_DONE: |
| 684 | handleNullReturnEvent(msg, "nvResetConfig"); |
| 685 | break; |
| 686 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 687 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 688 | request = (MainThreadRequest) msg.obj; |
| 689 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 690 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 691 | break; |
| 692 | |
| 693 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 694 | ar = (AsyncResult) msg.obj; |
| 695 | request = (MainThreadRequest) ar.userObj; |
| 696 | if (ar.exception == null && ar.result != null) { |
| 697 | request.result = ar.result; // Integer |
| 698 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 699 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 700 | if (ar.result == null) { |
| 701 | loge("getPreferredNetworkType: Empty response"); |
| 702 | } else if (ar.exception instanceof CommandException) { |
| 703 | loge("getPreferredNetworkType: CommandException: " + |
| 704 | ar.exception); |
| 705 | } else { |
| 706 | loge("getPreferredNetworkType: Unknown exception"); |
| 707 | } |
| 708 | } |
| 709 | synchronized (request) { |
| 710 | request.notifyAll(); |
| 711 | } |
| 712 | break; |
| 713 | |
| 714 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 715 | request = (MainThreadRequest) msg.obj; |
| 716 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 717 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 718 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 719 | break; |
| 720 | |
| 721 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 722 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 723 | break; |
| 724 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 725 | case CMD_SET_VOICEMAIL_NUMBER: |
| 726 | request = (MainThreadRequest) msg.obj; |
| 727 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 728 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 729 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 730 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 731 | break; |
| 732 | |
| 733 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 734 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 735 | break; |
| 736 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 737 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 738 | request = (MainThreadRequest) msg.obj; |
| 739 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 740 | request); |
| 741 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 742 | break; |
| 743 | |
| 744 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 745 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 746 | break; |
| 747 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 748 | case CMD_PERFORM_NETWORK_SCAN: |
| 749 | request = (MainThreadRequest) msg.obj; |
| 750 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 751 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 752 | break; |
| 753 | |
| 754 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 755 | ar = (AsyncResult) msg.obj; |
| 756 | request = (MainThreadRequest) ar.userObj; |
| 757 | CellNetworkScanResult cellScanResult; |
| 758 | if (ar.exception == null && ar.result != null) { |
| 759 | cellScanResult = new CellNetworkScanResult( |
| 760 | CellNetworkScanResult.STATUS_SUCCESS, |
| 761 | (List<OperatorInfo>) ar.result); |
| 762 | } else { |
| 763 | if (ar.result == null) { |
| 764 | loge("getCellNetworkScanResults: Empty response"); |
| 765 | } |
| 766 | if (ar.exception != null) { |
| 767 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 768 | } |
| 769 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 770 | if (ar.exception instanceof CommandException) { |
| 771 | CommandException.Error error = |
| 772 | ((CommandException) (ar.exception)).getCommandError(); |
| 773 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 774 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 775 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 776 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 777 | } |
| 778 | } |
| 779 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 780 | } |
| 781 | request.result = cellScanResult; |
| 782 | synchronized (request) { |
| 783 | request.notifyAll(); |
| 784 | } |
| 785 | break; |
| 786 | |
| 787 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 788 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 789 | ManualNetworkSelectionArgument selArg = |
| 790 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 791 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 792 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 793 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 794 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 795 | break; |
| 796 | |
| 797 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
| 798 | handleNullReturnEvent(msg, "setNetworkSelectionModeManual"); |
| 799 | break; |
| 800 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 801 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 802 | request = (MainThreadRequest) msg.obj; |
| 803 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
Prerepa Viswanadham | 61a60ad | 2015-06-08 18:07:51 -0700 | [diff] [blame] | 804 | mPhone.getModemActivityInfo(onCompleted); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 805 | break; |
| 806 | |
| 807 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 808 | ar = (AsyncResult) msg.obj; |
| 809 | request = (MainThreadRequest) ar.userObj; |
| 810 | if (ar.exception == null && ar.result != null) { |
| 811 | request.result = ar.result; |
| 812 | } else { |
| 813 | if (ar.result == null) { |
| 814 | loge("queryModemActivityInfo: Empty response"); |
| 815 | } else if (ar.exception instanceof CommandException) { |
| 816 | loge("queryModemActivityInfo: CommandException: " + |
| 817 | ar.exception); |
| 818 | } else { |
| 819 | loge("queryModemActivityInfo: Unknown exception"); |
| 820 | } |
| 821 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 822 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 823 | if (request.result == null) { |
| 824 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 825 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 826 | synchronized (request) { |
| 827 | request.notifyAll(); |
| 828 | } |
| 829 | break; |
| 830 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 831 | case CMD_SET_ALLOWED_CARRIERS: |
| 832 | request = (MainThreadRequest) msg.obj; |
| 833 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
| 834 | mPhone.setAllowedCarriers( |
| 835 | (List<CarrierIdentifier>) request.argument, |
| 836 | onCompleted); |
| 837 | break; |
| 838 | |
| 839 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 840 | ar = (AsyncResult) msg.obj; |
| 841 | request = (MainThreadRequest) ar.userObj; |
| 842 | if (ar.exception == null && ar.result != null) { |
| 843 | request.result = ar.result; |
| 844 | } else { |
| 845 | if (ar.result == null) { |
| 846 | loge("setAllowedCarriers: Empty response"); |
| 847 | } else if (ar.exception instanceof CommandException) { |
| 848 | loge("setAllowedCarriers: CommandException: " + |
| 849 | ar.exception); |
| 850 | } else { |
| 851 | loge("setAllowedCarriers: Unknown exception"); |
| 852 | } |
| 853 | } |
| 854 | // Result cannot be null. Return -1 on error. |
| 855 | if (request.result == null) { |
| 856 | request.result = new int[]{-1}; |
| 857 | } |
| 858 | synchronized (request) { |
| 859 | request.notifyAll(); |
| 860 | } |
| 861 | break; |
| 862 | |
| 863 | case CMD_GET_ALLOWED_CARRIERS: |
| 864 | request = (MainThreadRequest) msg.obj; |
| 865 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
| 866 | mPhone.getAllowedCarriers(onCompleted); |
| 867 | break; |
| 868 | |
| 869 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 870 | ar = (AsyncResult) msg.obj; |
| 871 | request = (MainThreadRequest) ar.userObj; |
| 872 | if (ar.exception == null && ar.result != null) { |
| 873 | request.result = ar.result; |
| 874 | } else { |
| 875 | if (ar.result == null) { |
| 876 | loge("getAllowedCarriers: Empty response"); |
| 877 | } else if (ar.exception instanceof CommandException) { |
| 878 | loge("getAllowedCarriers: CommandException: " + |
| 879 | ar.exception); |
| 880 | } else { |
| 881 | loge("getAllowedCarriers: Unknown exception"); |
| 882 | } |
| 883 | } |
| 884 | // Result cannot be null. Return empty list of CarrierIdentifier. |
| 885 | if (request.result == null) { |
| 886 | request.result = new ArrayList<CarrierIdentifier>(0); |
| 887 | } |
| 888 | synchronized (request) { |
| 889 | request.notifyAll(); |
| 890 | } |
| 891 | break; |
| 892 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 893 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 894 | ar = (AsyncResult) msg.obj; |
| 895 | request = (MainThreadRequest) ar.userObj; |
| 896 | if (ar.exception == null && ar.result != null) { |
| 897 | request.result = ar.result; |
| 898 | } else { |
| 899 | request.result = new IllegalArgumentException( |
| 900 | "Failed to retrieve Forbidden Plmns"); |
| 901 | if (ar.result == null) { |
| 902 | loge("getForbiddenPlmns: Empty response"); |
| 903 | } else { |
| 904 | loge("getForbiddenPlmns: Unknown exception"); |
| 905 | } |
| 906 | } |
| 907 | synchronized (request) { |
| 908 | request.notifyAll(); |
| 909 | } |
| 910 | break; |
| 911 | |
| 912 | case CMD_GET_FORBIDDEN_PLMNS: |
| 913 | request = (MainThreadRequest) msg.obj; |
| 914 | uiccCard = getUiccCardFromRequest(request); |
| 915 | if (uiccCard == null) { |
| 916 | loge("getForbiddenPlmns() UiccCard is null"); |
| 917 | request.result = new IllegalArgumentException( |
| 918 | "getForbiddenPlmns() UiccCard is null"); |
| 919 | synchronized (request) { |
| 920 | request.notifyAll(); |
| 921 | } |
| 922 | break; |
| 923 | } |
| 924 | Integer appType = (Integer) request.argument; |
| 925 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 926 | if (uiccApp == null) { |
| 927 | loge("getForbiddenPlmns() no app with specified type -- " |
| 928 | + appType); |
| 929 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
| 930 | synchronized (request) { |
| 931 | request.notifyAll(); |
| 932 | } |
| 933 | break; |
| 934 | } else { |
| 935 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 936 | + " specified type -- " + appType); |
| 937 | } |
| 938 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 939 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 940 | onCompleted); |
| 941 | break; |
| 942 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 943 | default: |
| 944 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 945 | break; |
| 946 | } |
| 947 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 948 | |
| 949 | private void handleNullReturnEvent(Message msg, String command) { |
| 950 | AsyncResult ar = (AsyncResult) msg.obj; |
| 951 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 952 | if (ar.exception == null) { |
| 953 | request.result = true; |
| 954 | } else { |
| 955 | request.result = false; |
| 956 | if (ar.exception instanceof CommandException) { |
| 957 | loge(command + ": CommandException: " + ar.exception); |
| 958 | } else { |
| 959 | loge(command + ": Unknown exception"); |
| 960 | } |
| 961 | } |
| 962 | synchronized (request) { |
| 963 | request.notifyAll(); |
| 964 | } |
| 965 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | /** |
| 969 | * Posts the specified command to be executed on the main thread, |
| 970 | * waits for the request to complete, and returns the result. |
| 971 | * @see #sendRequestAsync |
| 972 | */ |
| 973 | private Object sendRequest(int command, Object argument) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 974 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | /** |
| 978 | * Posts the specified command to be executed on the main thread, |
| 979 | * waits for the request to complete, and returns the result. |
| 980 | * @see #sendRequestAsync |
| 981 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 982 | private Object sendRequest(int command, Object argument, Integer subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 983 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 984 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 985 | } |
| 986 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 987 | MainThreadRequest request = new MainThreadRequest(argument, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 988 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 989 | msg.sendToTarget(); |
| 990 | |
| 991 | // Wait for the request to complete |
| 992 | synchronized (request) { |
| 993 | while (request.result == null) { |
| 994 | try { |
| 995 | request.wait(); |
| 996 | } catch (InterruptedException e) { |
| 997 | // Do nothing, go back and wait until the request is complete |
| 998 | } |
| 999 | } |
| 1000 | } |
| 1001 | return request.result; |
| 1002 | } |
| 1003 | |
| 1004 | /** |
| 1005 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1006 | * Posts the specified command to be executed on the main thread, and |
| 1007 | * returns immediately. |
| 1008 | * @see #sendRequest |
| 1009 | */ |
| 1010 | private void sendRequestAsync(int command) { |
| 1011 | mMainThreadHandler.sendEmptyMessage(command); |
| 1012 | } |
| 1013 | |
| 1014 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1015 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
| 1016 | * @see {@link #sendRequest(int,Object)} |
| 1017 | */ |
| 1018 | private void sendRequestAsync(int command, Object argument) { |
| 1019 | MainThreadRequest request = new MainThreadRequest(argument); |
| 1020 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1021 | msg.sendToTarget(); |
| 1022 | } |
| 1023 | |
| 1024 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1025 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1026 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1027 | */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 1028 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1029 | synchronized (PhoneInterfaceManager.class) { |
| 1030 | if (sInstance == null) { |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 1031 | sInstance = new PhoneInterfaceManager(app, phone); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1032 | } else { |
| 1033 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1034 | } |
| 1035 | return sInstance; |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | /** Private constructor; @see init() */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 1040 | private PhoneInterfaceManager(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1041 | mApp = app; |
| 1042 | mPhone = phone; |
| 1043 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1044 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1045 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1046 | mMainThreadHandler = new MainThreadHandler(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 1047 | mTelephonySharedPreferences = |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 1048 | PreferenceManager.getDefaultSharedPreferences(mPhone.getContext()); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1049 | mSubscriptionController = SubscriptionController.getInstance(); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1050 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1051 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1052 | publish(); |
| 1053 | } |
| 1054 | |
| 1055 | private void publish() { |
| 1056 | if (DBG) log("publish: " + this); |
| 1057 | |
| 1058 | ServiceManager.addService("phone", this); |
| 1059 | } |
| 1060 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1061 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1062 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1063 | ? mPhone : getPhone(request.subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1064 | } |
| 1065 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1066 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1067 | Phone phone = getPhoneFromRequest(request); |
| 1068 | return phone == null ? null : |
| 1069 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1070 | } |
| 1071 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1072 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1073 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1074 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1075 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1076 | // |
| 1077 | // Implementation of the ITelephony interface. |
| 1078 | // |
| 1079 | |
| 1080 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1081 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1084 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1085 | if (DBG) log("dial: " + number); |
| 1086 | // No permission check needed here: This is just a wrapper around the |
| 1087 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1088 | // the UI before it does anything. |
| 1089 | |
| 1090 | String url = createTelUrl(number); |
| 1091 | if (url == null) { |
| 1092 | return; |
| 1093 | } |
| 1094 | |
| 1095 | // PENDING: should we just silently fail if phone is offhook or ringing? |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1096 | PhoneConstants.State state = mCM.getState(subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1097 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1098 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1099 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1100 | mApp.startActivity(intent); |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1105 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1108 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1109 | if (DBG) log("call: " + number); |
| 1110 | |
| 1111 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1112 | // need to do a permission check since we're calling startActivity() |
| 1113 | // from the context of the phone app. |
| 1114 | enforceCallPermission(); |
| 1115 | |
| 1116 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1117 | != AppOpsManager.MODE_ALLOWED) { |
| 1118 | return; |
| 1119 | } |
| 1120 | |
| 1121 | String url = createTelUrl(number); |
| 1122 | if (url == null) { |
| 1123 | return; |
| 1124 | } |
| 1125 | |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1126 | boolean isValid = false; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 1127 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1128 | if (slist != null) { |
| 1129 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1130 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1131 | isValid = true; |
| 1132 | break; |
| 1133 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | if (isValid == false) { |
| 1137 | return; |
| 1138 | } |
| 1139 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1140 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1141 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1142 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1143 | mApp.startActivity(intent); |
| 1144 | } |
| 1145 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1146 | /** |
| 1147 | * End a call based on call state |
| 1148 | * @return true is a call was ended |
| 1149 | */ |
| 1150 | public boolean endCall() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1151 | return endCallForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | /** |
| 1155 | * End a call based on the call state of the subId |
| 1156 | * @return true is a call was ended |
| 1157 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1158 | public boolean endCallForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1159 | enforceCallPermission(); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1160 | return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | public void answerRingingCall() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1164 | answerRingingCallForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1167 | public void answerRingingCallForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1168 | if (DBG) log("answerRingingCall..."); |
| 1169 | // TODO: there should eventually be a separate "ANSWER_PHONE" permission, |
| 1170 | // but that can probably wait till the big TelephonyManager API overhaul. |
| 1171 | // For now, protect this call with the MODIFY_PHONE_STATE permission. |
| 1172 | enforceModifyPermission(); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1173 | sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | /** |
| 1177 | * Make the actual telephony calls to implement answerRingingCall(). |
| 1178 | * This should only be called from the main thread of the Phone app. |
| 1179 | * @see #answerRingingCall |
| 1180 | * |
| 1181 | * TODO: it would be nice to return true if we answered the call, or |
| 1182 | * false if there wasn't actually a ringing incoming call, or some |
| 1183 | * other error occurred. (In other words, pass back the return value |
| 1184 | * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().) |
| 1185 | * But that would require calling this method via sendRequest() rather |
| 1186 | * than sendRequestAsync(), and right now we don't actually *need* that |
| 1187 | * return value, so let's just return void for now. |
| 1188 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1189 | private void answerRingingCallInternal(int subId) { |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1190 | final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1191 | if (hasRingingCall) { |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1192 | final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle(); |
| 1193 | final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1194 | if (hasActiveCall && hasHoldingCall) { |
| 1195 | // Both lines are in use! |
| 1196 | // TODO: provide a flag to let the caller specify what |
| 1197 | // policy to use if both lines are in use. (The current |
| 1198 | // behavior is hardwired to "answer incoming, end ongoing", |
| 1199 | // which is how the CALL button is specced to behave.) |
| 1200 | PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall()); |
| 1201 | return; |
| 1202 | } else { |
| 1203 | // answerCall() will automatically hold the current active |
| 1204 | // call, if there is one. |
| 1205 | PhoneUtils.answerCall(mCM.getFirstActiveRingingCall()); |
| 1206 | return; |
| 1207 | } |
| 1208 | } else { |
| 1209 | // No call was ringing. |
| 1210 | return; |
| 1211 | } |
| 1212 | } |
| 1213 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1214 | /** |
Santos Cordon | 5422a8d | 2014-09-12 04:20:56 -0700 | [diff] [blame] | 1215 | * This method is no longer used and can be removed once TelephonyManager stops referring to it. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1216 | */ |
Santos Cordon | 5422a8d | 2014-09-12 04:20:56 -0700 | [diff] [blame] | 1217 | public void silenceRinger() { |
| 1218 | Log.e(LOG_TAG, "silenseRinger not supported"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1221 | @Override |
| 1222 | public boolean isOffhook(String callingPackage) { |
| 1223 | return isOffhookForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1226 | @Override |
| 1227 | public boolean isOffhookForSubscriber(int subId, String callingPackage) { |
| 1228 | if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) { |
| 1229 | return false; |
| 1230 | } |
| 1231 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1232 | final Phone phone = getPhone(subId); |
| 1233 | if (phone != null) { |
| 1234 | return (phone.getState() == PhoneConstants.State.OFFHOOK); |
| 1235 | } else { |
| 1236 | return false; |
| 1237 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1240 | @Override |
| 1241 | public boolean isRinging(String callingPackage) { |
| 1242 | return (isRingingForSubscriber(getDefaultSubscription(), callingPackage)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1245 | @Override |
| 1246 | public boolean isRingingForSubscriber(int subId, String callingPackage) { |
| 1247 | if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) { |
| 1248 | return false; |
| 1249 | } |
| 1250 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1251 | final Phone phone = getPhone(subId); |
| 1252 | if (phone != null) { |
| 1253 | return (phone.getState() == PhoneConstants.State.RINGING); |
| 1254 | } else { |
| 1255 | return false; |
| 1256 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1259 | @Override |
| 1260 | public boolean isIdle(String callingPackage) { |
| 1261 | return isIdleForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1264 | @Override |
| 1265 | public boolean isIdleForSubscriber(int subId, String callingPackage) { |
| 1266 | if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) { |
| 1267 | return false; |
| 1268 | } |
| 1269 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1270 | final Phone phone = getPhone(subId); |
| 1271 | if (phone != null) { |
| 1272 | return (phone.getState() == PhoneConstants.State.IDLE); |
| 1273 | } else { |
| 1274 | return false; |
| 1275 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1278 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1279 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1282 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1283 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1284 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1285 | } |
| 1286 | |
| 1287 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1288 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1291 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1292 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1293 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1294 | } |
| 1295 | |
| 1296 | /** {@hide} */ |
| 1297 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1298 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1301 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1302 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1303 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1304 | checkSimPin.start(); |
| 1305 | return checkSimPin.unlockSim(null, pin); |
| 1306 | } |
| 1307 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1308 | /** {@hide} */ |
| 1309 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1310 | return supplyPukReportResultForSubscriber(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 int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1314 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1315 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1316 | checkSimPuk.start(); |
| 1317 | return checkSimPuk.unlockSim(puk, pin); |
| 1318 | } |
| 1319 | |
| 1320 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1321 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1322 | * a synchronous one. |
| 1323 | */ |
| 1324 | private static class UnlockSim extends Thread { |
| 1325 | |
| 1326 | private final IccCard mSimCard; |
| 1327 | |
| 1328 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1329 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1330 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1331 | |
| 1332 | // For replies from SimCard interface |
| 1333 | private Handler mHandler; |
| 1334 | |
| 1335 | // For async handler to identify request type |
| 1336 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1337 | |
| 1338 | public UnlockSim(IccCard simCard) { |
| 1339 | mSimCard = simCard; |
| 1340 | } |
| 1341 | |
| 1342 | @Override |
| 1343 | public void run() { |
| 1344 | Looper.prepare(); |
| 1345 | synchronized (UnlockSim.this) { |
| 1346 | mHandler = new Handler() { |
| 1347 | @Override |
| 1348 | public void handleMessage(Message msg) { |
| 1349 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1350 | switch (msg.what) { |
| 1351 | case SUPPLY_PIN_COMPLETE: |
| 1352 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1353 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1354 | mRetryCount = msg.arg1; |
| 1355 | if (ar.exception != null) { |
| 1356 | if (ar.exception instanceof CommandException && |
| 1357 | ((CommandException)(ar.exception)).getCommandError() |
| 1358 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1359 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1360 | } else { |
| 1361 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1362 | } |
| 1363 | } else { |
| 1364 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1365 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1366 | mDone = true; |
| 1367 | UnlockSim.this.notifyAll(); |
| 1368 | } |
| 1369 | break; |
| 1370 | } |
| 1371 | } |
| 1372 | }; |
| 1373 | UnlockSim.this.notifyAll(); |
| 1374 | } |
| 1375 | Looper.loop(); |
| 1376 | } |
| 1377 | |
| 1378 | /* |
| 1379 | * Use PIN or PUK to unlock SIM card |
| 1380 | * |
| 1381 | * If PUK is null, unlock SIM card with PIN |
| 1382 | * |
| 1383 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1384 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1385 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1386 | |
| 1387 | while (mHandler == null) { |
| 1388 | try { |
| 1389 | wait(); |
| 1390 | } catch (InterruptedException e) { |
| 1391 | Thread.currentThread().interrupt(); |
| 1392 | } |
| 1393 | } |
| 1394 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1395 | |
| 1396 | if (puk == null) { |
| 1397 | mSimCard.supplyPin(pin, callback); |
| 1398 | } else { |
| 1399 | mSimCard.supplyPuk(puk, pin, callback); |
| 1400 | } |
| 1401 | |
| 1402 | while (!mDone) { |
| 1403 | try { |
| 1404 | Log.d(LOG_TAG, "wait for done"); |
| 1405 | wait(); |
| 1406 | } catch (InterruptedException e) { |
| 1407 | // Restore the interrupted status |
| 1408 | Thread.currentThread().interrupt(); |
| 1409 | } |
| 1410 | } |
| 1411 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1412 | int[] resultArray = new int[2]; |
| 1413 | resultArray[0] = mResult; |
| 1414 | resultArray[1] = mRetryCount; |
| 1415 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1420 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1421 | |
| 1422 | } |
| 1423 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1424 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1425 | // No permission check needed here: this call is harmless, and it's |
| 1426 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1427 | // already intentionally exposed to 3rd parties.) |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1428 | final Phone phone = getPhone(subId); |
| 1429 | if (phone != null) { |
| 1430 | phone.updateServiceLocation(); |
| 1431 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1434 | @Override |
| 1435 | public boolean isRadioOn(String callingPackage) { |
| 1436 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1437 | } |
| 1438 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1439 | @Override |
| 1440 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 1441 | if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) { |
| 1442 | return false; |
| 1443 | } |
| 1444 | return isRadioOnForSubscriber(subId); |
| 1445 | } |
| 1446 | |
| 1447 | private boolean isRadioOnForSubscriber(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1448 | final Phone phone = getPhone(subId); |
| 1449 | if (phone != null) { |
| 1450 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1451 | } else { |
| 1452 | return false; |
| 1453 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1457 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1458 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1459 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1460 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1461 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1462 | enforceModifyPermission(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1463 | final Phone phone = getPhone(subId); |
| 1464 | if (phone != null) { |
| 1465 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1466 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1470 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1471 | } |
| 1472 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1473 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1474 | enforceModifyPermission(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1475 | final Phone phone = getPhone(subId); |
| 1476 | if (phone == null) { |
| 1477 | return false; |
| 1478 | } |
| 1479 | if ((phone.getServiceState().getState() != |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1480 | ServiceState.STATE_POWER_OFF) != turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1481 | toggleRadioOnOffForSubscriber(subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1482 | } |
| 1483 | return true; |
| 1484 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1485 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1486 | public boolean needMobileRadioShutdown() { |
| 1487 | /* |
| 1488 | * If any of the Radios are available, it will need to be |
| 1489 | * shutdown. So return true if any Radio is available. |
| 1490 | */ |
| 1491 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1492 | Phone phone = PhoneFactory.getPhone(i); |
| 1493 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1494 | } |
| 1495 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1496 | return false; |
| 1497 | } |
| 1498 | |
| 1499 | public void shutdownMobileRadios() { |
| 1500 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1501 | logv("Shutting down Phone " + i); |
| 1502 | shutdownRadioUsingPhoneId(i); |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | private void shutdownRadioUsingPhoneId(int phoneId) { |
| 1507 | enforceModifyPermission(); |
| 1508 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1509 | if (phone != null && phone.isRadioAvailable()) { |
| 1510 | phone.shutdownRadio(); |
| 1511 | } |
| 1512 | } |
| 1513 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1514 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1515 | enforceModifyPermission(); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1516 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1517 | if (defaultPhone != null) { |
| 1518 | defaultPhone.setRadioPower(turnOn); |
| 1519 | return true; |
| 1520 | } else { |
| 1521 | loge("There's no default phone."); |
| 1522 | return false; |
| 1523 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1524 | } |
| 1525 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1526 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1527 | enforceModifyPermission(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1528 | final Phone phone = getPhone(subId); |
| 1529 | if (phone != null) { |
| 1530 | phone.setRadioPower(turnOn); |
| 1531 | return true; |
| 1532 | } else { |
| 1533 | return false; |
| 1534 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1535 | } |
| 1536 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1537 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1538 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1539 | public boolean enableDataConnectivity() { |
| 1540 | enforceModifyPermission(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1541 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1542 | final Phone phone = getPhone(subId); |
| 1543 | if (phone != null) { |
| 1544 | phone.setDataEnabled(true); |
| 1545 | return true; |
| 1546 | } else { |
| 1547 | return false; |
| 1548 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1551 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1552 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1553 | public boolean disableDataConnectivity() { |
| 1554 | enforceModifyPermission(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1555 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1556 | final Phone phone = getPhone(subId); |
| 1557 | if (phone != null) { |
| 1558 | phone.setDataEnabled(false); |
| 1559 | return true; |
| 1560 | } else { |
| 1561 | return false; |
| 1562 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1563 | } |
| 1564 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1565 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1566 | public boolean isDataConnectivityPossible(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1567 | final Phone phone = getPhone(subId); |
| 1568 | if (phone != null) { |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1569 | return phone.isDataAllowed(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1570 | } else { |
| 1571 | return false; |
| 1572 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1576 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1579 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1580 | enforceCallPermission(); |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1581 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1582 | return; |
| 1583 | } |
| 1584 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1585 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1586 | }; |
| 1587 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1588 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1589 | enforceModifyPermission(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1590 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1591 | return false; |
| 1592 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1593 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1596 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1597 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1600 | public int getCallStateForSlot(int slotIndex) { |
| 1601 | Phone phone = PhoneFactory.getPhone(slotIndex); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1602 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 1603 | PhoneConstantConversions.convertCallState(phone.getState()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1606 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1607 | public int getDataState() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1608 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1609 | if (phone != null) { |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 1610 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1611 | } else { |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 1612 | return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1613 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1616 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1617 | public int getDataActivity() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1618 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1619 | if (phone != null) { |
| 1620 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1621 | } else { |
| 1622 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1623 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1627 | public Bundle getCellLocation(String callingPackage) { |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1628 | if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(), |
Svet Ganov | e4ae941 | 2017-09-28 12:45:30 -0700 | [diff] [blame] | 1629 | callingPackage, Binder.getCallingUid(), "getCellLocation")) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1630 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1633 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1634 | Bundle data = new Bundle(); |
| 1635 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1636 | if (phone == null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1637 | return null; |
| 1638 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1639 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1640 | WorkSource workSource = getWorkSource(null, Binder.getCallingUid()); |
| 1641 | phone.getCellLocation(workSource).fillInNotifierBundle(data); |
| 1642 | return data; |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1645 | @Override |
Jonathan Basseri | 0392395 | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1646 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1647 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1648 | // registered cell info, so return a NULL country instead. |
| 1649 | final long identity = Binder.clearCallingIdentity(); |
| 1650 | try { |
| 1651 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
| 1652 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1653 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1654 | return ""; |
| 1655 | } |
| 1656 | } finally { |
| 1657 | Binder.restoreCallingIdentity(identity); |
| 1658 | } |
| 1659 | return TelephonyManager.getTelephonyProperty( |
| 1660 | phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, ""); |
| 1661 | } |
| 1662 | |
| 1663 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1664 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1665 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1666 | } |
| 1667 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1668 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1669 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1670 | mApp.enforceCallingOrSelfPermission( |
| 1671 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1672 | final Phone phone = getPhone(subId); |
| 1673 | if (phone != null) { |
| 1674 | phone.enableLocationUpdates(); |
| 1675 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | @Override |
| 1679 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1680 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1683 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1684 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1685 | mApp.enforceCallingOrSelfPermission( |
| 1686 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1687 | final Phone phone = getPhone(subId); |
| 1688 | if (phone != null) { |
| 1689 | phone.disableLocationUpdates(); |
| 1690 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | @Override |
| 1694 | @SuppressWarnings("unchecked") |
| 1695 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1696 | if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(), |
Svet Ganov | e4ae941 | 2017-09-28 12:45:30 -0700 | [diff] [blame] | 1697 | callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1698 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1702 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1703 | return null; |
| 1704 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1705 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1706 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1707 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1708 | ArrayList<NeighboringCellInfo> cells = null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1709 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1710 | WorkSource workSource = getWorkSource(null, Binder.getCallingUid()); |
| 1711 | try { |
| 1712 | cells = (ArrayList<NeighboringCellInfo>) sendRequest( |
| 1713 | CMD_HANDLE_NEIGHBORING_CELL, workSource, |
| 1714 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 1715 | } catch (RuntimeException e) { |
| 1716 | Log.e(LOG_TAG, "getNeighboringCellInfo " + e); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1717 | } |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1718 | return cells; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | |
| 1722 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1723 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1724 | if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(), |
Svet Ganov | e4ae941 | 2017-09-28 12:45:30 -0700 | [diff] [blame] | 1725 | callingPackage, Binder.getCallingUid(), "getAllCellInfo")) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1726 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1729 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
| 1730 | WorkSource workSource = getWorkSource(null, Binder.getCallingUid()); |
| 1731 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 1732 | for (Phone phone : PhoneFactory.getPhones()) { |
| 1733 | final List<CellInfo> info = phone.getAllCellInfo(workSource); |
| 1734 | if (info != null) cellInfos.addAll(info); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1735 | } |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1736 | return cellInfos; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1739 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1740 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 1741 | enforceModifyPermission(); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 1742 | WorkSource workSource = getWorkSource(null, Binder.getCallingUid()); |
| 1743 | mPhone.setCellInfoListRate(rateInMillis, workSource); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1744 | } |
| 1745 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1746 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1747 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1748 | if (!canReadPhoneState(callingPackage, "getImeiForSlot")) { |
| 1749 | return null; |
| 1750 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1751 | Phone phone = PhoneFactory.getPhone(slotIndex); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1752 | return phone == null ? null : phone.getImei(); |
| 1753 | } |
| 1754 | |
| 1755 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 1756 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
| 1757 | if (!canReadPhoneState(callingPackage, "getMeidForSlot")) { |
| 1758 | return null; |
| 1759 | } |
| 1760 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1761 | return phone == null ? null : phone.getMeid(); |
| 1762 | } |
| 1763 | |
| 1764 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1765 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1766 | if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 1767 | return null; |
| 1768 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1769 | Phone phone = PhoneFactory.getPhone(slotIndex); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1770 | return phone == null ? null : phone.getDeviceSvn(); |
| 1771 | } |
| 1772 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1773 | // |
| 1774 | // Internal helper methods. |
| 1775 | // |
| 1776 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 1777 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1778 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 1779 | * |
| 1780 | * @throws SecurityException if the caller does not have the required permission |
| 1781 | */ |
| 1782 | private void enforceModifyPermission() { |
| 1783 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 1784 | } |
| 1785 | |
| 1786 | /** |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1787 | * Make sure either system app or the caller has carrier privilege. |
| 1788 | * |
| 1789 | * @throws SecurityException if the caller does not have the required permission/privilege |
| 1790 | */ |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1791 | private void enforceModifyPermissionOrCarrierPrivilege(int subId) { |
Shishir Agrawal | f1ac4c9 | 2014-07-14 13:54:28 -0700 | [diff] [blame] | 1792 | int permission = mApp.checkCallingOrSelfPermission( |
| 1793 | android.Manifest.permission.MODIFY_PHONE_STATE); |
| 1794 | if (permission == PackageManager.PERMISSION_GRANTED) { |
| 1795 | return; |
| 1796 | } |
| 1797 | |
| 1798 | log("No modify permission, check carrier privilege next."); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1799 | enforceCarrierPrivilege(subId); |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | /** |
| 1803 | * Make sure the caller has carrier privilege. |
| 1804 | * |
| 1805 | * @throws SecurityException if the caller does not have the required permission |
| 1806 | */ |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1807 | private void enforceCarrierPrivilege(int subId) { |
| 1808 | if (getCarrierPrivilegeStatus(subId) != |
| 1809 | TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Shishir Agrawal | f1ac4c9 | 2014-07-14 13:54:28 -0700 | [diff] [blame] | 1810 | loge("No Carrier Privilege."); |
| 1811 | throw new SecurityException("No Carrier Privilege."); |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1816 | * Make sure the caller has the CALL_PHONE permission. |
| 1817 | * |
| 1818 | * @throws SecurityException if the caller does not have the required permission |
| 1819 | */ |
| 1820 | private void enforceCallPermission() { |
| 1821 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 1822 | } |
| 1823 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 1824 | private void enforceConnectivityInternalPermission() { |
| 1825 | mApp.enforceCallingOrSelfPermission( |
| 1826 | android.Manifest.permission.CONNECTIVITY_INTERNAL, |
| 1827 | "ConnectivityService"); |
| 1828 | } |
| 1829 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1830 | private String createTelUrl(String number) { |
| 1831 | if (TextUtils.isEmpty(number)) { |
| 1832 | return null; |
| 1833 | } |
| 1834 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1835 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1836 | } |
| 1837 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1838 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1839 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1840 | } |
| 1841 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1842 | private static void logv(String msg) { |
| 1843 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1844 | } |
| 1845 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1846 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1847 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1848 | } |
| 1849 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1850 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1851 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1852 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1855 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1856 | public int getActivePhoneTypeForSlot(int slotIndex) { |
| 1857 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1858 | if (phone == null) { |
| 1859 | return PhoneConstants.PHONE_TYPE_NONE; |
| 1860 | } else { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1861 | return phone.getPhoneType(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1862 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | /** |
| 1866 | * Returns the CDMA ERI icon index to display |
| 1867 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1868 | @Override |
| 1869 | public int getCdmaEriIconIndex(String callingPackage) { |
| 1870 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1873 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1874 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
| 1875 | if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
| 1876 | return -1; |
| 1877 | } |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1878 | final Phone phone = getPhone(subId); |
| 1879 | if (phone != null) { |
| 1880 | return phone.getCdmaEriIconIndex(); |
| 1881 | } else { |
| 1882 | return -1; |
| 1883 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | /** |
| 1887 | * Returns the CDMA ERI icon mode, |
| 1888 | * 0 - ON |
| 1889 | * 1 - FLASHING |
| 1890 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1891 | @Override |
| 1892 | public int getCdmaEriIconMode(String callingPackage) { |
| 1893 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1896 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1897 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
| 1898 | if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) { |
| 1899 | return -1; |
| 1900 | } |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1901 | final Phone phone = getPhone(subId); |
| 1902 | if (phone != null) { |
| 1903 | return phone.getCdmaEriIconMode(); |
| 1904 | } else { |
| 1905 | return -1; |
| 1906 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | /** |
| 1910 | * Returns the CDMA ERI text, |
| 1911 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1912 | @Override |
| 1913 | public String getCdmaEriText(String callingPackage) { |
| 1914 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1917 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1918 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
| 1919 | if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) { |
| 1920 | return null; |
| 1921 | } |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1922 | final Phone phone = getPhone(subId); |
| 1923 | if (phone != null) { |
| 1924 | return phone.getCdmaEriText(); |
| 1925 | } else { |
| 1926 | return null; |
| 1927 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 1931 | * Returns the CDMA MDN. |
| 1932 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1933 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1934 | public String getCdmaMdn(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1935 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1936 | final Phone phone = getPhone(subId); |
| 1937 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) { |
| 1938 | return phone.getLine1Number(); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 1939 | } else { |
| 1940 | return null; |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | /** |
| 1945 | * Returns the CDMA MIN. |
| 1946 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1947 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1948 | public String getCdmaMin(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1949 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1950 | final Phone phone = getPhone(subId); |
| 1951 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 1952 | return phone.getCdmaMin(); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 1953 | } else { |
| 1954 | return null; |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1959 | * Returns true if CDMA provisioning needs to run. |
| 1960 | */ |
| 1961 | public boolean needsOtaServiceProvisioning() { |
| 1962 | return mPhone.needsOtaServiceProvisioning(); |
| 1963 | } |
| 1964 | |
| 1965 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1966 | * Sets the voice mail number of a given subId. |
| 1967 | */ |
| 1968 | @Override |
| 1969 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1970 | enforceCarrierPrivilege(subId); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1971 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 1972 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 1973 | return success; |
| 1974 | } |
| 1975 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 1976 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 1977 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 1978 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 1979 | String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage(); |
| 1980 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 1981 | throw new SecurityException("caller must be system dialer"); |
| 1982 | } |
| 1983 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 1984 | if (phoneAccountHandle == null){ |
| 1985 | return null; |
| 1986 | } |
| 1987 | return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle); |
| 1988 | } |
| 1989 | |
| 1990 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 1991 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 1992 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 1993 | if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) { |
| 1994 | return null; |
| 1995 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 1996 | return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName(); |
| 1997 | } |
| 1998 | |
| 1999 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2000 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2001 | VisualVoicemailSmsFilterSettings settings) { |
| 2002 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2003 | VisualVoicemailSmsFilterConfig |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2004 | .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId, |
| 2005 | settings); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2009 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2010 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2011 | VisualVoicemailSmsFilterConfig |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2012 | .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2016 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2017 | String callingPackage, int subId) { |
| 2018 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2019 | return VisualVoicemailSmsFilterConfig |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2020 | .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2024 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2025 | enforceReadPrivilegedPermission(); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2026 | return VisualVoicemailSmsFilterConfig |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2027 | .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId); |
| 2028 | } |
| 2029 | |
| 2030 | @Override |
| 2031 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2032 | String number, int port, String text, PendingIntent sentIntent) { |
| 2033 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2034 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2035 | enforceSendSmsPermission(); |
| 2036 | // Make the calls as the phone process. |
| 2037 | final long identity = Binder.clearCallingIdentity(); |
| 2038 | try { |
| 2039 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2040 | if (port == 0) { |
| 2041 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2042 | sentIntent, null, false); |
| 2043 | } else { |
| 2044 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2045 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2046 | (short) port, data, sentIntent, null); |
| 2047 | } |
| 2048 | } finally { |
| 2049 | Binder.restoreCallingIdentity(identity); |
| 2050 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2051 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2052 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2053 | * Sets the voice activation state of a given subId. |
| 2054 | */ |
| 2055 | @Override |
| 2056 | public void setVoiceActivationState(int subId, int activationState) { |
| 2057 | enforceModifyPermissionOrCarrierPrivilege(subId); |
| 2058 | final Phone phone = getPhone(subId); |
| 2059 | if (phone != null) { |
| 2060 | phone.setVoiceActivationState(activationState); |
| 2061 | } else { |
| 2062 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | /** |
| 2067 | * Sets the data activation state of a given subId. |
| 2068 | */ |
| 2069 | @Override |
| 2070 | public void setDataActivationState(int subId, int activationState) { |
| 2071 | enforceModifyPermissionOrCarrierPrivilege(subId); |
| 2072 | final Phone phone = getPhone(subId); |
| 2073 | if (phone != null) { |
| 2074 | phone.setDataActivationState(activationState); |
| 2075 | } else { |
| 2076 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2077 | } |
| 2078 | } |
| 2079 | |
| 2080 | /** |
| 2081 | * Returns the voice activation state of a given subId. |
| 2082 | */ |
| 2083 | @Override |
| 2084 | public int getVoiceActivationState(int subId, String callingPackage) { |
| 2085 | if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) { |
| 2086 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2087 | } |
| 2088 | final Phone phone = getPhone(subId); |
| 2089 | if (phone != null) { |
| 2090 | return phone.getVoiceActivationState(); |
| 2091 | } else { |
| 2092 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | /** |
| 2097 | * Returns the data activation state of a given subId. |
| 2098 | */ |
| 2099 | @Override |
| 2100 | public int getDataActivationState(int subId, String callingPackage) { |
| 2101 | if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) { |
| 2102 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2103 | } |
| 2104 | final Phone phone = getPhone(subId); |
| 2105 | if (phone != null) { |
| 2106 | return phone.getDataActivationState(); |
| 2107 | } else { |
| 2108 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2113 | * Returns the unread count of voicemails |
| 2114 | */ |
| 2115 | public int getVoiceMessageCount() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2116 | return getVoiceMessageCountForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | /** |
| 2120 | * Returns the unread count of voicemails for a subId |
| 2121 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2122 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2123 | public int getVoiceMessageCountForSubscriber( int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2124 | final Phone phone = getPhone(subId); |
| 2125 | if (phone != null) { |
| 2126 | return phone.getVoiceMessageCount(); |
| 2127 | } else { |
| 2128 | return 0; |
| 2129 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2133 | * returns true, if the device is in a state where both voice and data |
| 2134 | * are supported simultaneously. This can change based on location or network condition. |
| 2135 | */ |
| 2136 | @Override |
| 2137 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
| 2138 | final Phone phone = getPhone(subId); |
| 2139 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2140 | } |
| 2141 | |
| 2142 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2143 | * Send the dialer code if called from the current default dialer or the caller has |
| 2144 | * carrier privilege. |
| 2145 | * @param inputCode The dialer code to send |
| 2146 | */ |
| 2147 | @Override |
| 2148 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
| 2149 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2150 | String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage(); |
| 2151 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
| 2152 | enforceCarrierPrivilege(getDefaultSubscription()); |
| 2153 | } |
| 2154 | mPhone.sendDialerSpecialCode(inputCode); |
| 2155 | } |
| 2156 | |
| 2157 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2158 | * Returns the data network type. |
| 2159 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2160 | * |
| 2161 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2162 | */ |
| 2163 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2164 | public int getNetworkType() { |
| 2165 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2166 | if (phone != null) { |
| 2167 | return phone.getServiceState().getDataNetworkType(); |
| 2168 | } else { |
| 2169 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2170 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | /** |
| 2174 | * Returns the network type for a subId |
| 2175 | */ |
| 2176 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2177 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
| 2178 | if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) { |
| 2179 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2180 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2181 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2182 | final Phone phone = getPhone(subId); |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2183 | if (phone != null) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2184 | return phone.getServiceState().getDataNetworkType(); |
| 2185 | } else { |
| 2186 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2187 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | /** |
| 2191 | * Returns the data network type |
| 2192 | */ |
| 2193 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2194 | public int getDataNetworkType(String callingPackage) { |
| 2195 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | /** |
| 2199 | * Returns the data network type for a subId |
| 2200 | */ |
| 2201 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2202 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
| 2203 | if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) { |
| 2204 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2205 | } |
| 2206 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2207 | final Phone phone = getPhone(subId); |
| 2208 | if (phone != null) { |
| 2209 | return phone.getServiceState().getDataNetworkType(); |
| 2210 | } else { |
| 2211 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2212 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2216 | * Returns the Voice network type for a subId |
| 2217 | */ |
| 2218 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2219 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
| 2220 | if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) { |
| 2221 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2222 | } |
| 2223 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2224 | final Phone phone = getPhone(subId); |
| 2225 | if (phone != null) { |
| 2226 | return phone.getServiceState().getVoiceNetworkType(); |
| 2227 | } else { |
| 2228 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2229 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | /** |
| 2233 | * @return true if a ICC card is present |
| 2234 | */ |
| 2235 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2236 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2237 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 2238 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2242 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2243 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2244 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2245 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
| 2246 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
fionaxu | 6e6c68b | 2016-06-23 13:31:32 -0700 | [diff] [blame] | 2247 | if (phone != null) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2248 | return phone.getIccCard().hasIccCard(); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 2249 | } else { |
| 2250 | return false; |
| 2251 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | /** |
| 2255 | * Return if the current radio is LTE on CDMA. This |
| 2256 | * is a tri-state return value as for a period of time |
| 2257 | * the mode may be unknown. |
| 2258 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2259 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2260 | * @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] | 2261 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2262 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2263 | @Override |
| 2264 | public int getLteOnCdmaMode(String callingPackage) { |
| 2265 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2266 | } |
| 2267 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2268 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2269 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
| 2270 | if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) { |
| 2271 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 2272 | } |
| 2273 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2274 | final Phone phone = getPhone(subId); |
| 2275 | if (phone == null) { |
| 2276 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 2277 | } else { |
| 2278 | return phone.getLteOnCdmaMode(); |
| 2279 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | public void setPhone(Phone phone) { |
| 2283 | mPhone = phone; |
| 2284 | } |
| 2285 | |
| 2286 | /** |
| 2287 | * {@hide} |
| 2288 | * Returns Default subId, 0 in the case of single standby. |
| 2289 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2290 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2291 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2294 | private int getSlotForDefaultSubscription() { |
| 2295 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 2296 | } |
| 2297 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2298 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2299 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2300 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 2301 | |
| 2302 | /** |
| 2303 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 2304 | */ |
| 2305 | public int getWhenToMakeWifiCalls() { |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 2306 | return Settings.System.getInt(mPhone.getContext().getContentResolver(), |
| 2307 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference()); |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | /** |
| 2311 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 2312 | */ |
| 2313 | public void setWhenToMakeWifiCalls(int preference) { |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 2314 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
| 2315 | Settings.System.putInt(mPhone.getContext().getContentResolver(), |
| 2316 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2317 | } |
| 2318 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 2319 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 2320 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 2321 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 2322 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 2323 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2324 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 2325 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 2326 | int subId, String callingPackage, String aid, int p2) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2327 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2328 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 2329 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 2330 | // Only allows LPA to open logical channel to ISD-R. |
| 2331 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2332 | ComponentInfo bestComponent = |
| 2333 | EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager()); |
| 2334 | if (bestComponent == null |
| 2335 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 2336 | loge("The calling package is not allowed to access ISD-R."); |
| 2337 | throw new SecurityException("The calling package is not allowed to access ISD-R."); |
| 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2342 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest( |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 2343 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2344 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 2345 | return response; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2349 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
| 2350 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2351 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2352 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2353 | if (channel < 0) { |
| 2354 | return false; |
| 2355 | } |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2356 | Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2357 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 2358 | return success; |
| 2359 | } |
| 2360 | |
| 2361 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2362 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2363 | int command, int p1, int p2, int p3, String data) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2364 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2365 | |
| 2366 | if (DBG) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2367 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel + |
| 2368 | " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2369 | " data=" + data); |
| 2370 | } |
| 2371 | |
| 2372 | if (channel < 0) { |
| 2373 | return ""; |
| 2374 | } |
| 2375 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2376 | IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2377 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2378 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
| 2379 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2380 | // Append the returned status code to the end of the response payload. |
| 2381 | String s = Integer.toHexString( |
| 2382 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 2383 | if (response.payload != null) { |
| 2384 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 2385 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2386 | return s; |
| 2387 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2388 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 2389 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2390 | public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2, |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2391 | int p3, String data) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2392 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2393 | |
| 2394 | if (DBG) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2395 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command |
| 2396 | + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2400 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2401 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
| 2402 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2403 | // Append the returned status code to the end of the response payload. |
| 2404 | String s = Integer.toHexString( |
| 2405 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 2406 | if (response.payload != null) { |
| 2407 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 2408 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2409 | return s; |
| 2410 | } |
| 2411 | |
| 2412 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2413 | 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] | 2414 | String filePath) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2415 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2416 | |
| 2417 | if (DBG) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2418 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " + |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2419 | p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 2420 | } |
| 2421 | |
| 2422 | IccIoResult response = |
| 2423 | (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO, |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2424 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 2425 | subId); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2426 | |
| 2427 | if (DBG) { |
| 2428 | log("Exchange SIM_IO [R]" + response); |
| 2429 | } |
| 2430 | |
| 2431 | byte[] result = null; |
| 2432 | int length = 2; |
| 2433 | if (response.payload != null) { |
| 2434 | length = 2 + response.payload.length; |
| 2435 | result = new byte[length]; |
| 2436 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 2437 | } else { |
| 2438 | result = new byte[length]; |
| 2439 | } |
| 2440 | |
| 2441 | result[length - 1] = (byte) response.sw2; |
| 2442 | result[length - 2] = (byte) response.sw1; |
| 2443 | return result; |
| 2444 | } |
| 2445 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 2446 | /** |
| 2447 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 2448 | * on a particular subscription |
| 2449 | */ |
| 2450 | public String[] getForbiddenPlmns(int subId, int appType) { |
Nathan Harold | 892104e | 2017-04-13 18:19:05 -0700 | [diff] [blame] | 2451 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 2452 | "Requires READ_PHONE_STATE"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 2453 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 2454 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 2455 | return null; |
| 2456 | } |
| 2457 | Object response = sendRequest( |
| 2458 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 2459 | if (response instanceof String[]) { |
| 2460 | return (String[]) response; |
| 2461 | } |
| 2462 | // Response is an Exception of some kind, which is signalled to the user as a NULL retval |
| 2463 | return null; |
| 2464 | } |
| 2465 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2466 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2467 | public String sendEnvelopeWithStatus(int subId, String content) { |
| 2468 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 2469 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2470 | IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 2471 | if (response.payload == null) { |
| 2472 | return ""; |
| 2473 | } |
| 2474 | |
| 2475 | // Append the returned status code to the end of the response payload. |
| 2476 | String s = Integer.toHexString( |
| 2477 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 2478 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 2479 | return s; |
| 2480 | } |
| 2481 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2482 | /** |
| 2483 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 2484 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 2485 | * |
| 2486 | * @param itemID the ID of the item to read |
| 2487 | * @return the NV item as a String, or null on error. |
| 2488 | */ |
| 2489 | @Override |
| 2490 | public String nvReadItem(int itemID) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2491 | enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription()); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2492 | if (DBG) log("nvReadItem: item " + itemID); |
| 2493 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID); |
| 2494 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 2495 | return value; |
| 2496 | } |
| 2497 | |
| 2498 | /** |
| 2499 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 2500 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 2501 | * |
| 2502 | * @param itemID the ID of the item to read |
| 2503 | * @param itemValue the value to write, as a String |
| 2504 | * @return true on success; false on any failure |
| 2505 | */ |
| 2506 | @Override |
| 2507 | public boolean nvWriteItem(int itemID, String itemValue) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2508 | enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription()); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2509 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 2510 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
| 2511 | new Pair<Integer, String>(itemID, itemValue)); |
| 2512 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 2513 | return success; |
| 2514 | } |
| 2515 | |
| 2516 | /** |
| 2517 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 2518 | * Used for device configuration by some CDMA operators. |
| 2519 | * |
| 2520 | * @param preferredRoamingList byte array containing the new PRL |
| 2521 | * @return true on success; false on any failure |
| 2522 | */ |
| 2523 | @Override |
| 2524 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2525 | enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription()); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2526 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 2527 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 2528 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 2529 | return success; |
| 2530 | } |
| 2531 | |
| 2532 | /** |
| 2533 | * Perform the specified type of NV config reset. |
| 2534 | * Used for device configuration by some CDMA operators. |
| 2535 | * |
| 2536 | * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset) |
| 2537 | * @return true on success; false on any failure |
| 2538 | */ |
| 2539 | @Override |
| 2540 | public boolean nvResetConfig(int resetType) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2541 | enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription()); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2542 | if (DBG) log("nvResetConfig: type " + resetType); |
| 2543 | Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType); |
| 2544 | if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail")); |
| 2545 | return success; |
| 2546 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2547 | |
| 2548 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2549 | * {@hide} |
| 2550 | * Returns Default sim, 0 in the case of single standby. |
| 2551 | */ |
| 2552 | public int getDefaultSim() { |
| 2553 | //TODO Need to get it from Telephony Devcontroller |
| 2554 | return 0; |
| 2555 | } |
| 2556 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2557 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
| 2558 | if (!canReadPhoneState(callingPackage, "getPcscfAddress")) { |
| 2559 | return new String[0]; |
| 2560 | } |
| 2561 | |
| 2562 | |
ram | 87fca6f | 2014-07-18 18:58:44 +0530 | [diff] [blame] | 2563 | return mPhone.getPcscfAddress(apnType); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 2566 | /** |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 2567 | * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel |
| 2568 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 2569 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 2570 | */ |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 2571 | public IImsMMTelFeature getMMTelFeatureAndListen(int slotId, |
| 2572 | IImsServiceFeatureCallback callback) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 2573 | enforceModifyPermission(); |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 2574 | return PhoneFactory.getImsResolver().getMMTelFeatureAndListen(slotId, callback); |
| 2575 | } |
| 2576 | |
| 2577 | /** |
| 2578 | * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel |
| 2579 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 2580 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 2581 | * listener for feature updates. |
| 2582 | */ |
| 2583 | public IImsMMTelFeature getEmergencyMMTelFeatureAndListen(int slotId, |
| 2584 | IImsServiceFeatureCallback callback) { |
| 2585 | enforceModifyPermission(); |
| 2586 | return PhoneFactory.getImsResolver().getEmergencyMMTelFeatureAndListen(slotId, callback); |
| 2587 | } |
| 2588 | |
| 2589 | /** |
| 2590 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 2591 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 2592 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 2593 | * listener for feature updates. |
| 2594 | */ |
| 2595 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 2596 | enforceModifyPermission(); |
| 2597 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 2598 | } |
| 2599 | |
Brad Ebinger | 7e934f5 | 2017-12-14 14:26:15 -0800 | [diff] [blame^] | 2600 | /** |
| 2601 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| 2602 | * specified. |
| 2603 | */ |
| 2604 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 2605 | enforceModifyPermission(); |
| 2606 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); |
| 2607 | } |
| 2608 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2609 | public void setImsRegistrationState(boolean registered) { |
| 2610 | enforceModifyPermission(); |
| 2611 | mPhone.setImsRegistrationState(registered); |
| 2612 | } |
| 2613 | |
| 2614 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2615 | * Set the network selection mode to automatic. |
| 2616 | * |
| 2617 | */ |
| 2618 | @Override |
| 2619 | public void setNetworkSelectionModeAutomatic(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2620 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2621 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 2622 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 2623 | } |
| 2624 | |
| 2625 | /** |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 2626 | * Set the network selection mode to manual with the selected carrier. |
| 2627 | */ |
| 2628 | @Override |
yinxu | 6e5abd7 | 2017-12-01 11:35:19 -0800 | [diff] [blame] | 2629 | public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric, |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 2630 | boolean persistSelection) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2631 | enforceModifyPermissionOrCarrierPrivilege(subId); |
yinxu | 6e5abd7 | 2017-12-01 11:35:19 -0800 | [diff] [blame] | 2632 | OperatorInfo operator = new OperatorInfo( |
| 2633 | /* operatorAlphaLong */ "", |
| 2634 | /* operatorAlphaShort */ "", |
| 2635 | operatorNumeric); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 2636 | if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 2637 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator, |
| 2638 | persistSelection); |
| 2639 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | /** |
| 2643 | * Scans for available networks. |
| 2644 | */ |
| 2645 | @Override |
| 2646 | public CellNetworkScanResult getCellNetworkScanResults(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2647 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 2648 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
| 2649 | CellNetworkScanResult result = (CellNetworkScanResult) sendRequest( |
| 2650 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
| 2651 | return result; |
| 2652 | } |
| 2653 | |
| 2654 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2655 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 2656 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2657 | * @param subId id of the subscription |
| 2658 | * @param request contains the radio access networks with bands/channels to scan |
| 2659 | * @param messenger callback messenger for scan results or errors |
| 2660 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 2661 | * @return the id of the requested scan which can be used to stop the scan. |
| 2662 | */ |
| 2663 | @Override |
| 2664 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
| 2665 | IBinder binder) { |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2666 | enforceModifyPermissionOrCarrierPrivilege(subId); |
| 2667 | return mNetworkScanRequestTracker.startNetworkScan( |
| 2668 | request, messenger, binder, getPhone(subId)); |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | /** |
| 2672 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2673 | * |
| 2674 | * @param subId id of the subscription |
| 2675 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 2676 | */ |
| 2677 | @Override |
| 2678 | public void stopNetworkScan(int subId, int scanId) { |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2679 | enforceModifyPermissionOrCarrierPrivilege(subId); |
| 2680 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 2684 | * Get the calculated preferred network type. |
| 2685 | * Used for debugging incorrect network type. |
| 2686 | * |
| 2687 | * @return the preferred network type, defined in RILConstants.java. |
| 2688 | */ |
| 2689 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2690 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
| 2691 | if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) { |
| 2692 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 2693 | } |
| 2694 | |
Amit Mahajan | 43330e0 | 2014-11-18 11:54:45 -0800 | [diff] [blame] | 2695 | return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2699 | * Get the preferred network type. |
| 2700 | * Used for device configuration by some CDMA operators. |
| 2701 | * |
| 2702 | * @return the preferred network type, defined in RILConstants.java. |
| 2703 | */ |
| 2704 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2705 | public int getPreferredNetworkType(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2706 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2707 | if (DBG) log("getPreferredNetworkType"); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2708 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2709 | int networkType = (result != null ? result[0] : -1); |
| 2710 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 2711 | return networkType; |
| 2712 | } |
| 2713 | |
| 2714 | /** |
| 2715 | * Set the preferred network type. |
| 2716 | * Used for device configuration by some CDMA operators. |
| 2717 | * |
| 2718 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 2719 | * @return true on success; false on any failure. |
| 2720 | */ |
| 2721 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2722 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2723 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2724 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 2725 | Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2726 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 2727 | if (success) { |
| 2728 | Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2729 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 2730 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2731 | return success; |
| 2732 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2733 | |
| 2734 | /** |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 2735 | * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning |
| 2736 | * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for |
| 2737 | * tethering. |
| 2738 | * |
| 2739 | * @return 0: Not required. 1: required. 2: Not set. |
| 2740 | * @hide |
| 2741 | */ |
| 2742 | @Override |
| 2743 | public int getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2744 | enforceModifyPermission(); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 2745 | int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(), |
| 2746 | Settings.Global.TETHER_DUN_REQUIRED, 2); |
| 2747 | // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and |
| 2748 | // config_tether_apndata. |
| 2749 | if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) { |
| 2750 | dunRequired = 1; |
| 2751 | } |
| 2752 | return dunRequired; |
| 2753 | } |
| 2754 | |
| 2755 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2756 | * Set mobile data enabled |
| 2757 | * Used by the user through settings etc to turn on/off mobile data |
| 2758 | * |
| 2759 | * @param enable {@code true} turn turn data on, else {@code false} |
| 2760 | */ |
| 2761 | @Override |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2762 | public void setDataEnabled(int subId, boolean enable) { |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 2763 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2764 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Joe Onorato | a601dd2 | 2016-02-23 13:03:53 -0800 | [diff] [blame] | 2765 | if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2766 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2767 | if (phone != null) { |
Joe Onorato | a601dd2 | 2016-02-23 13:03:53 -0800 | [diff] [blame] | 2768 | if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2769 | phone.setDataEnabled(enable); |
| 2770 | } else { |
| 2771 | loge("setDataEnabled: no phone for subId=" + subId); |
| 2772 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | /** |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 2776 | * Get whether mobile data is enabled. |
| 2777 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 2778 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2779 | * |
| 2780 | * @return {@code true} if data is enabled else {@code false} |
| 2781 | */ |
| 2782 | @Override |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2783 | public boolean getDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 2784 | try { |
| 2785 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 2786 | null); |
| 2787 | } catch (Exception e) { |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 2788 | enforceModifyPermissionOrCarrierPrivilege(subId); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 2789 | } |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2790 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Joe Onorato | a601dd2 | 2016-02-23 13:03:53 -0800 | [diff] [blame] | 2791 | if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2792 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2793 | if (phone != null) { |
| 2794 | boolean retVal = phone.getDataEnabled(); |
Joe Onorato | a601dd2 | 2016-02-23 13:03:53 -0800 | [diff] [blame] | 2795 | if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2796 | return retVal; |
| 2797 | } else { |
Joe Onorato | a601dd2 | 2016-02-23 13:03:53 -0800 | [diff] [blame] | 2798 | if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false"); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2799 | return false; |
| 2800 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2801 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 2802 | |
| 2803 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2804 | public int getCarrierPrivilegeStatus(int subId) { |
| 2805 | final Phone phone = getPhone(subId); |
| 2806 | if (phone == null) { |
| 2807 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 2808 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 2809 | } |
| 2810 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 2811 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 2812 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 2813 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 2814 | } |
| 2815 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2816 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 2817 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 2818 | |
| 2819 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 2820 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 2821 | if (TextUtils.isEmpty(pkgName)) |
| 2822 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Shishir Agrawal | 2140925 | 2015-01-15 23:33:50 -0800 | [diff] [blame] | 2823 | UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 2824 | if (card == null) { |
| 2825 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 2826 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 2827 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 2828 | return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName); |
| 2829 | } |
| 2830 | |
| 2831 | @Override |
| 2832 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 2833 | if (TextUtils.isEmpty(pkgName)) |
| 2834 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 2835 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 2836 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2837 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 2838 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 2839 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 2840 | continue; |
| 2841 | } |
| 2842 | |
| 2843 | result = card.getCarrierPrivilegeStatus( |
| 2844 | mPhone.getContext().getPackageManager(), pkgName); |
| 2845 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 2846 | break; |
| 2847 | } |
| 2848 | } |
| 2849 | |
| 2850 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 2851 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 2852 | |
| 2853 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 2854 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 2855 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 2856 | loge("phoneId " + phoneId + " is not valid."); |
| 2857 | return null; |
| 2858 | } |
| 2859 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 2860 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 2861 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 2862 | return null ; |
| 2863 | } |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 2864 | return card.getCarrierPackageNamesForIntent( |
Svetoslav | 483aff7 | 2015-04-21 14:16:07 -0700 | [diff] [blame] | 2865 | mPhone.getContext().getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 2866 | } |
| 2867 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 2868 | @Override |
| 2869 | public List<String> getPackagesWithCarrierPrivileges() { |
| 2870 | PackageManager pm = mPhone.getContext().getPackageManager(); |
| 2871 | List<String> privilegedPackages = new ArrayList<>(); |
| 2872 | List<PackageInfo> packages = null; |
| 2873 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2874 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 2875 | if (card == null) { |
| 2876 | // No UICC in that slot. |
| 2877 | continue; |
| 2878 | } |
| 2879 | if (card.hasCarrierPrivilegeRules()) { |
| 2880 | if (packages == null) { |
| 2881 | // Only check packages in user 0 for now |
| 2882 | packages = pm.getInstalledPackagesAsUser( |
| 2883 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 2884 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 2885 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 2886 | } |
| 2887 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 2888 | PackageInfo pkgInfo = packages.get(p); |
| 2889 | if (pkgInfo != null && pkgInfo.packageName != null |
| 2890 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 2891 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 2892 | privilegedPackages.add(pkgInfo.packageName); |
| 2893 | } |
| 2894 | } |
| 2895 | } |
| 2896 | } |
| 2897 | return privilegedPackages; |
| 2898 | } |
| 2899 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2900 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2901 | final Phone phone = getPhone(subId); |
| 2902 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2903 | if (card == null) { |
| 2904 | loge("getIccId: No UICC"); |
| 2905 | return null; |
| 2906 | } |
| 2907 | String iccId = card.getIccId(); |
| 2908 | if (TextUtils.isEmpty(iccId)) { |
| 2909 | loge("getIccId: ICC ID is null or empty."); |
| 2910 | return null; |
| 2911 | } |
| 2912 | return iccId; |
| 2913 | } |
| 2914 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 2915 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2916 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 2917 | String number) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2918 | enforceCarrierPrivilege(subId); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2919 | |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2920 | final String iccId = getIccId(subId); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2921 | final Phone phone = getPhone(subId); |
| 2922 | if (phone == null) { |
| 2923 | return false; |
| 2924 | } |
| 2925 | final String subscriberId = phone.getSubscriberId(); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2926 | |
| 2927 | if (DBG_MERGE) { |
| 2928 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 2929 | + subscriberId + " to " + number); |
| 2930 | } |
| 2931 | |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2932 | if (TextUtils.isEmpty(iccId)) { |
| 2933 | return false; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2934 | } |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2935 | |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2936 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 2937 | |
| 2938 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2939 | if (alphaTag == null) { |
| 2940 | editor.remove(alphaTagPrefKey); |
| 2941 | } else { |
| 2942 | editor.putString(alphaTagPrefKey, alphaTag); |
| 2943 | } |
| 2944 | |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2945 | // Record both the line number and IMSI for this ICCID, since we need to |
| 2946 | // track all merged IMSIs based on line number |
| 2947 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 2948 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2949 | if (number == null) { |
| 2950 | editor.remove(numberPrefKey); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2951 | editor.remove(subscriberPrefKey); |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2952 | } else { |
| 2953 | editor.putString(numberPrefKey, number); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2954 | editor.putString(subscriberPrefKey, subscriberId); |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2955 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2956 | |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2957 | editor.commit(); |
| 2958 | return true; |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2962 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 2963 | // This is open to apps with WRITE_SMS. |
| 2964 | if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 2965 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2966 | return null; |
| 2967 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2968 | |
| 2969 | String iccId = getIccId(subId); |
| 2970 | if (iccId != null) { |
| 2971 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 2972 | if (DBG_MERGE) { |
| 2973 | log("getLine1NumberForDisplay returning " + |
| 2974 | mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 2975 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 2976 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2977 | } |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 2978 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2979 | return null; |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2983 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
| 2984 | if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) { |
| 2985 | return null; |
| 2986 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2987 | |
| 2988 | String iccId = getIccId(subId); |
| 2989 | if (iccId != null) { |
| 2990 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 2991 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2992 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2993 | return null; |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2994 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 2995 | |
| 2996 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 2997 | public String[] getMergedSubscriberIds(String callingPackage) { |
| 2998 | if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) { |
| 2999 | return null; |
| 3000 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 3001 | final Context context = mPhone.getContext(); |
| 3002 | final TelephonyManager tele = TelephonyManager.from(context); |
| 3003 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 3004 | |
| 3005 | // Figure out what subscribers are currently active |
| 3006 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 3007 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 3008 | // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail. |
| 3009 | final long identity = Binder.clearCallingIdentity(); |
| 3010 | try { |
| 3011 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 3012 | for (int subId : subIds) { |
| 3013 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 3014 | } |
| 3015 | } finally { |
| 3016 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 3017 | } |
| 3018 | |
| 3019 | // First pass, find a number override for an active subscriber |
| 3020 | String mergeNumber = null; |
| 3021 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 3022 | for (String key : prefs.keySet()) { |
| 3023 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 3024 | final String subscriberId = (String) prefs.get(key); |
| 3025 | if (activeSubscriberIds.contains(subscriberId)) { |
| 3026 | final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 3027 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 3028 | mergeNumber = (String) prefs.get(numberKey); |
| 3029 | if (DBG_MERGE) { |
| 3030 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 3031 | + " for active subscriber " + subscriberId); |
| 3032 | } |
| 3033 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 3034 | break; |
| 3035 | } |
| 3036 | } |
| 3037 | } |
| 3038 | } |
| 3039 | |
| 3040 | // Shortcut when no active merged subscribers |
| 3041 | if (TextUtils.isEmpty(mergeNumber)) { |
| 3042 | return null; |
| 3043 | } |
| 3044 | |
| 3045 | // Second pass, find all subscribers under that line override |
| 3046 | final ArraySet<String> result = new ArraySet<>(); |
| 3047 | for (String key : prefs.keySet()) { |
| 3048 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 3049 | final String number = (String) prefs.get(key); |
| 3050 | if (mergeNumber.equals(number)) { |
| 3051 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 3052 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 3053 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 3054 | if (!TextUtils.isEmpty(subscriberId)) { |
| 3055 | result.add(subscriberId); |
| 3056 | } |
| 3057 | } |
| 3058 | } |
| 3059 | } |
| 3060 | |
| 3061 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 3062 | Arrays.sort(resultArray); |
| 3063 | if (DBG_MERGE) { |
| 3064 | Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 3065 | } |
| 3066 | return resultArray; |
| 3067 | } |
| 3068 | |
| 3069 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3070 | public boolean setOperatorBrandOverride(int subId, String brand) { |
| 3071 | enforceCarrierPrivilege(subId); |
| 3072 | final Phone phone = getPhone(subId); |
| 3073 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 3074 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 3075 | |
| 3076 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3077 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 3078 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 3079 | List<String> cdmaNonRoamingList) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3080 | enforceCarrierPrivilege(subId); |
| 3081 | final Phone phone = getPhone(subId); |
| 3082 | if (phone == null) { |
| 3083 | return false; |
| 3084 | } |
| 3085 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 3086 | cdmaNonRoamingList); |
| 3087 | } |
| 3088 | |
| 3089 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 3090 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 3091 | try { |
| 3092 | ProxyController.getInstance().setRadioCapability(rafs); |
| 3093 | } catch (RuntimeException e) { |
| 3094 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3099 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
| 3100 | if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) { |
| 3101 | return RadioAccessFamily.RAF_UNKNOWN; |
| 3102 | } |
| 3103 | |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 3104 | return ProxyController.getInstance().getRadioAccessFamily(phoneId); |
| 3105 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 3106 | |
| 3107 | @Override |
| 3108 | public void enableVideoCalling(boolean enable) { |
| 3109 | enforceModifyPermission(); |
Tyler Gunn | fdd69de | 2015-12-04 21:24:38 -0800 | [diff] [blame] | 3110 | ImsManager.setVtSetting(mPhone.getContext(), enable); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 3111 | } |
| 3112 | |
| 3113 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3114 | public boolean isVideoCallingEnabled(String callingPackage) { |
| 3115 | if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) { |
| 3116 | return false; |
| 3117 | } |
| 3118 | |
Andrew Lee | 77527ac | 2014-10-21 16:57:39 -0700 | [diff] [blame] | 3119 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 3120 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 3121 | // In the long run, we may instead need to check if there exists a connection service |
| 3122 | // which can support video calling. |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 3123 | return ImsManager.isVtEnabledByPlatform(mPhone.getContext()) |
| 3124 | && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext()) |
Tyler Gunn | fdd69de | 2015-12-04 21:24:38 -0800 | [diff] [blame] | 3125 | && ImsManager.isVtEnabledByUser(mPhone.getContext()); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 3126 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 3127 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 3128 | @Override |
| 3129 | public boolean canChangeDtmfToneLength() { |
Jonathan Basseri | 9504c6b | 2015-06-04 14:23:32 -0700 | [diff] [blame] | 3130 | return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | @Override |
| 3134 | public boolean isWorldPhone() { |
Jonathan Basseri | 9504c6b | 2015-06-04 14:23:32 -0700 | [diff] [blame] | 3135 | return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 3136 | } |
| 3137 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 3138 | @Override |
| 3139 | public boolean isTtyModeSupported() { |
| 3140 | TelecomManager telecomManager = TelecomManager.from(mPhone.getContext()); |
| 3141 | TelephonyManager telephonyManager = |
| 3142 | (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 3143 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 3144 | } |
| 3145 | |
| 3146 | @Override |
| 3147 | public boolean isHearingAidCompatibilitySupported() { |
| 3148 | return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled); |
| 3149 | } |
| 3150 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 3151 | /** |
| 3152 | * Returns the unique device ID of phone, for example, the IMEI for |
| 3153 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 3154 | * |
| 3155 | * <p>Requires Permission: |
| 3156 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 3157 | */ |
| 3158 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3159 | public String getDeviceId(String callingPackage) { |
| 3160 | if (!canReadPhoneState(callingPackage, "getDeviceId")) { |
| 3161 | return null; |
| 3162 | } |
| 3163 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 3164 | final Phone phone = PhoneFactory.getPhone(0); |
| 3165 | if (phone != null) { |
| 3166 | return phone.getDeviceId(); |
| 3167 | } else { |
| 3168 | return null; |
| 3169 | } |
| 3170 | } |
| 3171 | |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 3172 | /* |
| 3173 | * {@hide} |
| 3174 | * Returns the IMS Registration Status |
| 3175 | */ |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 3176 | @Override |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 3177 | public boolean isImsRegistered() { |
| 3178 | return mPhone.isImsRegistered(); |
| 3179 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 3180 | |
Ping Sun | 014fe8e | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 3181 | /** |
| 3182 | * {@hide} |
| 3183 | * Returns the IMS Registration Status on a particular subid |
| 3184 | * |
| 3185 | * @param subId |
| 3186 | */ |
| 3187 | public boolean isImsRegisteredForSubscriber(int subId) { |
| 3188 | Phone phone = getPhone(subId); |
| 3189 | if (phone != null) { |
| 3190 | return phone.isImsRegistered(); |
| 3191 | } else { |
| 3192 | return false; |
| 3193 | } |
| 3194 | } |
| 3195 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 3196 | @Override |
| 3197 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
| 3198 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 3199 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 3200 | |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 3201 | /* |
| 3202 | * {@hide} |
| 3203 | * Returns the IMS Registration Status |
| 3204 | */ |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 3205 | public boolean isWifiCallingAvailable() { |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 3206 | return mPhone.isWifiCallingEnabled(); |
| 3207 | } |
| 3208 | |
| 3209 | /* |
| 3210 | * {@hide} |
| 3211 | * Returns the IMS Registration Status |
| 3212 | */ |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 3213 | public boolean isVolteAvailable() { |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 3214 | return mPhone.isVolteEnabled(); |
| 3215 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3216 | |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 3217 | /* |
| 3218 | * {@hide} Returns the IMS Registration Status |
| 3219 | */ |
| 3220 | public boolean isVideoTelephonyAvailable() { |
| 3221 | return mPhone.isVideoEnabled(); |
| 3222 | } |
| 3223 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3224 | private boolean canReadPhoneState(String callingPackage, String message) { |
Etan Cohen | 921655c | 2015-06-24 13:54:50 -0700 | [diff] [blame] | 3225 | try { |
Amit Mahajan | 83ea23b | 2015-07-30 16:05:11 -0700 | [diff] [blame] | 3226 | mApp.enforceCallingOrSelfPermission( |
Etan Cohen | 921655c | 2015-06-24 13:54:50 -0700 | [diff] [blame] | 3227 | android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message); |
| 3228 | |
Amit Mahajan | 83ea23b | 2015-07-30 16:05:11 -0700 | [diff] [blame] | 3229 | // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission |
Etan Cohen | 921655c | 2015-06-24 13:54:50 -0700 | [diff] [blame] | 3230 | return true; |
Amit Mahajan | 785783f | 2015-06-29 10:36:50 -0700 | [diff] [blame] | 3231 | } catch (SecurityException e) { |
| 3232 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 3233 | message); |
Etan Cohen | 921655c | 2015-06-24 13:54:50 -0700 | [diff] [blame] | 3234 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3235 | |
| 3236 | if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(), |
| 3237 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3238 | return false; |
| 3239 | } |
| 3240 | |
| 3241 | return true; |
| 3242 | } |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3243 | |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 3244 | /** |
Amit Mahajan | b9b4978 | 2015-09-15 18:16:32 -0700 | [diff] [blame] | 3245 | * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers. |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 3246 | */ |
| 3247 | private boolean canReadPhoneNumber(String callingPackage, String message) { |
Makoto Onuki | e4072d1 | 2015-08-03 15:12:23 -0700 | [diff] [blame] | 3248 | // Default SMS app can always read it. |
| 3249 | if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS, |
| 3250 | Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) { |
| 3251 | return true; |
| 3252 | } |
Chad Brubaker | 7a8fba2 | 2016-11-10 11:23:18 -0800 | [diff] [blame] | 3253 | |
Makoto Onuki | e4072d1 | 2015-08-03 15:12:23 -0700 | [diff] [blame] | 3254 | try { |
| 3255 | return canReadPhoneState(callingPackage, message); |
Amit Mahajan | b9b4978 | 2015-09-15 18:16:32 -0700 | [diff] [blame] | 3256 | } catch (SecurityException readPhoneStateSecurityException) { |
Makoto Onuki | e4072d1 | 2015-08-03 15:12:23 -0700 | [diff] [blame] | 3257 | } |
Chad Brubaker | 7a8fba2 | 2016-11-10 11:23:18 -0800 | [diff] [blame] | 3258 | // Can be read with READ_SMS too. |
| 3259 | try { |
| 3260 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message); |
| 3261 | int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS); |
| 3262 | if (opCode != AppOpsManager.OP_NONE) { |
| 3263 | return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage) |
| 3264 | == AppOpsManager.MODE_ALLOWED; |
| 3265 | } else { |
| 3266 | return true; |
| 3267 | } |
| 3268 | } catch (SecurityException readSmsSecurityException) { |
| 3269 | } |
Chad Brubaker | f342a98 | 2017-03-30 16:27:34 -0700 | [diff] [blame] | 3270 | // Can be read with READ_PHONE_NUMBERS too. |
Chad Brubaker | 7a8fba2 | 2016-11-10 11:23:18 -0800 | [diff] [blame] | 3271 | try { |
Chad Brubaker | f342a98 | 2017-03-30 16:27:34 -0700 | [diff] [blame] | 3272 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS, |
Chad Brubaker | 7a8fba2 | 2016-11-10 11:23:18 -0800 | [diff] [blame] | 3273 | message); |
Chad Brubaker | f342a98 | 2017-03-30 16:27:34 -0700 | [diff] [blame] | 3274 | int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS); |
Chad Brubaker | 7a8fba2 | 2016-11-10 11:23:18 -0800 | [diff] [blame] | 3275 | if (opCode != AppOpsManager.OP_NONE) { |
| 3276 | return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage) |
| 3277 | == AppOpsManager.MODE_ALLOWED; |
| 3278 | } else { |
| 3279 | return true; |
| 3280 | } |
| 3281 | } catch (SecurityException readPhoneNumberSecurityException) { |
| 3282 | } |
| 3283 | |
| 3284 | throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() + |
| 3285 | " nor current process has" + android.Manifest.permission.READ_PHONE_STATE + |
| 3286 | ", " + android.Manifest.permission.READ_SMS + ", or " + |
Chad Brubaker | f342a98 | 2017-03-30 16:27:34 -0700 | [diff] [blame] | 3287 | android.Manifest.permission.READ_PHONE_NUMBERS); |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 3288 | } |
| 3289 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3290 | @Override |
| 3291 | public void factoryReset(int subId) { |
| 3292 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 3293 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 3294 | return; |
| 3295 | } |
| 3296 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 3297 | final long identity = Binder.clearCallingIdentity(); |
| 3298 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 3299 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 3300 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 3301 | // Enable data |
| 3302 | setDataEnabled(subId, true); |
| 3303 | // Set network selection mode to automatic |
| 3304 | setNetworkSelectionModeAutomatic(subId); |
| 3305 | // Set preferred mobile network type to the best available |
| 3306 | setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE); |
| 3307 | // Turn off roaming |
Malcolm Chen | f6b97f4 | 2017-04-19 16:03:24 -0700 | [diff] [blame] | 3308 | mPhone.setDataRoamingEnabled(false); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 3309 | } |
| 3310 | } finally { |
| 3311 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3312 | } |
| 3313 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3314 | |
| 3315 | @Override |
| 3316 | public String getLocaleFromDefaultSim() { |
| 3317 | // We query all subscriptions instead of just the active ones, because |
| 3318 | // this might be called early on in the provisioning flow when the |
| 3319 | // subscriptions potentially aren't active yet. |
| 3320 | final List<SubscriptionInfo> slist = getAllSubscriptionInfoList(); |
| 3321 | if (slist == null || slist.isEmpty()) { |
| 3322 | return null; |
| 3323 | } |
| 3324 | |
| 3325 | // This function may be called very early, say, from the setup wizard, at |
| 3326 | // which point we won't have a default subscription set. If that's the case |
| 3327 | // we just choose the first, which will be valid in "most cases". |
| 3328 | final int defaultSubId = getDefaultSubscription(); |
| 3329 | SubscriptionInfo info = null; |
| 3330 | if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 3331 | info = slist.get(0); |
| 3332 | } else { |
| 3333 | for (SubscriptionInfo item : slist) { |
| 3334 | if (item.getSubscriptionId() == defaultSubId) { |
| 3335 | info = item; |
| 3336 | break; |
| 3337 | } |
| 3338 | } |
| 3339 | |
| 3340 | if (info == null) { |
| 3341 | return null; |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 3346 | // preferences (EF-PL and EF-LI)... |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3347 | final int mcc = info.getMcc(); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3348 | final Phone defaultPhone = getPhone(info.getSubscriptionId()); |
Narayan Kamath | 011676f | 2015-07-29 12:04:08 +0100 | [diff] [blame] | 3349 | String simLanguage = null; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3350 | if (defaultPhone != null) { |
| 3351 | final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs(); |
| 3352 | if (localeFromDefaultSim != null) { |
Narayan Kamath | 011676f | 2015-07-29 12:04:08 +0100 | [diff] [blame] | 3353 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3354 | if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim); |
| 3355 | return localeFromDefaultSim.toLanguageTag(); |
Narayan Kamath | 011676f | 2015-07-29 12:04:08 +0100 | [diff] [blame] | 3356 | } else { |
| 3357 | simLanguage = localeFromDefaultSim.getLanguage(); |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3358 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3359 | } |
| 3360 | } |
| 3361 | |
Narayan Kamath | 011676f | 2015-07-29 12:04:08 +0100 | [diff] [blame] | 3362 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 3363 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 3364 | // the SIM and carrier preferences does not include a country we add the country |
| 3365 | // determined from the SIM MCC to provide an exact locale. |
| 3366 | final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage); |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3367 | if (mccLocale != null) { |
| 3368 | if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale); |
| 3369 | return mccLocale.toLanguageTag(); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3370 | } |
| 3371 | |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3372 | if (DBG) log("No locale found - returning null"); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3373 | return null; |
| 3374 | } |
| 3375 | |
| 3376 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
| 3377 | final long identity = Binder.clearCallingIdentity(); |
| 3378 | try { |
| 3379 | return mSubscriptionController.getAllSubInfoList( |
| 3380 | mPhone.getContext().getOpPackageName()); |
| 3381 | } finally { |
| 3382 | Binder.restoreCallingIdentity(identity); |
| 3383 | } |
| 3384 | } |
| 3385 | |
| 3386 | private List<SubscriptionInfo> getActiveSubscriptionInfoList() { |
| 3387 | final long identity = Binder.clearCallingIdentity(); |
| 3388 | try { |
| 3389 | return mSubscriptionController.getActiveSubscriptionInfoList( |
| 3390 | mPhone.getContext().getOpPackageName()); |
| 3391 | } finally { |
| 3392 | Binder.restoreCallingIdentity(identity); |
| 3393 | } |
| 3394 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 3395 | |
| 3396 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 3397 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 3398 | * representing the state of the modem. |
| 3399 | * |
| 3400 | * NOTE: This clears the modem state, so there should only every be one caller. |
| 3401 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 3402 | */ |
| 3403 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 3404 | public void requestModemActivityInfo(ResultReceiver result) { |
| 3405 | enforceModifyPermission(); |
| 3406 | |
| 3407 | ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null); |
| 3408 | Bundle bundle = new Bundle(); |
| 3409 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info); |
| 3410 | result.send(0, bundle); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 3411 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 3412 | |
| 3413 | /** |
| 3414 | * {@hide} |
| 3415 | * Returns the service state information on specified subscription. |
| 3416 | */ |
| 3417 | @Override |
| 3418 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
| 3419 | |
| 3420 | if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) { |
| 3421 | return null; |
| 3422 | } |
| 3423 | |
| 3424 | final Phone phone = getPhone(subId); |
| 3425 | if (phone == null) { |
| 3426 | return null; |
| 3427 | } |
| 3428 | |
| 3429 | return phone.getServiceState(); |
| 3430 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3431 | |
| 3432 | /** |
| 3433 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 3434 | * |
| 3435 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 3436 | * voicemail ringtone. |
| 3437 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 3438 | * PhoneAccount. |
| 3439 | */ |
| 3440 | @Override |
| 3441 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Ta-wei Yen | 00b4ab5 | 2017-04-11 13:24:26 -0700 | [diff] [blame] | 3442 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3443 | if (phone == null) { |
Ta-wei Yen | 00b4ab5 | 2017-04-11 13:24:26 -0700 | [diff] [blame] | 3444 | phone = mPhone; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3445 | } |
| 3446 | |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 3447 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3451 | * Sets the per-account voicemail ringtone. |
| 3452 | * |
| 3453 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 3454 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 3455 | * |
| 3456 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 3457 | * voicemail ringtone. |
| 3458 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 3459 | * PhoneAccount. |
| 3460 | */ |
| 3461 | @Override |
| 3462 | public void setVoicemailRingtoneUri(String callingPackage, |
| 3463 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
| 3464 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3465 | if (!TextUtils.equals(callingPackage, |
| 3466 | TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) { |
| 3467 | enforceModifyPermissionOrCarrierPrivilege( |
| 3468 | PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle)); |
| 3469 | } |
| 3470 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 3471 | if (phone == null){ |
Ta-wei Yen | 00b4ab5 | 2017-04-11 13:24:26 -0700 | [diff] [blame] | 3472 | phone = mPhone; |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3473 | } |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 3474 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3478 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 3479 | * |
| 3480 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 3481 | * voicemail vibration setting. |
| 3482 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 3483 | */ |
| 3484 | @Override |
| 3485 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Ta-wei Yen | 00b4ab5 | 2017-04-11 13:24:26 -0700 | [diff] [blame] | 3486 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3487 | if (phone == null) { |
Ta-wei Yen | 00b4ab5 | 2017-04-11 13:24:26 -0700 | [diff] [blame] | 3488 | phone = mPhone; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3489 | } |
| 3490 | |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 3491 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3492 | } |
| 3493 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 3494 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3495 | * Sets the per-account voicemail vibration. |
| 3496 | * |
| 3497 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 3498 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 3499 | * |
| 3500 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 3501 | * voicemail vibration setting. |
| 3502 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 3503 | * specific PhoneAccount. |
| 3504 | */ |
| 3505 | @Override |
| 3506 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 3507 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
| 3508 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3509 | if (!TextUtils.equals(callingPackage, |
| 3510 | TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) { |
| 3511 | enforceModifyPermissionOrCarrierPrivilege( |
| 3512 | PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle)); |
| 3513 | } |
| 3514 | |
| 3515 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 3516 | if (phone == null){ |
Ta-wei Yen | 00b4ab5 | 2017-04-11 13:24:26 -0700 | [diff] [blame] | 3517 | phone = mPhone; |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3518 | } |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 3519 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 3523 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 3524 | * |
| 3525 | * @throws SecurityException if the caller does not have the required permission |
| 3526 | */ |
| 3527 | private void enforceReadPrivilegedPermission() { |
| 3528 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 3529 | null); |
| 3530 | } |
| 3531 | |
| 3532 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3533 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 3534 | * permission. |
| 3535 | * |
| 3536 | * @throws SecurityException if the caller does not have the required permission |
| 3537 | */ |
| 3538 | private void enforceSendSmsPermission() { |
| 3539 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 3540 | } |
| 3541 | |
| 3542 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3543 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3544 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3545 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3546 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3547 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Ta-wei Yen | 5d81b0c | 2017-03-03 16:32:26 -0800 | [diff] [blame] | 3548 | ComponentName componentName = |
| 3549 | RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId); |
| 3550 | if(componentName == null) { |
| 3551 | throw new SecurityException("Caller not current active visual voicemail package[null]"); |
| 3552 | } |
| 3553 | String vvmPackage = componentName.getPackageName(); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3554 | if (!callingPackage.equals(vvmPackage)) { |
| 3555 | throw new SecurityException("Caller not current active visual voicemail package[" + |
| 3556 | vvmPackage + "]"); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3557 | } |
| 3558 | } |
| 3559 | |
| 3560 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 3561 | * Return the application ID for the app type. |
| 3562 | * |
| 3563 | * @param subId the subscription ID that this request applies to. |
| 3564 | * @param appType the uicc app type. |
| 3565 | * @return Application ID for specificied app type, or null if no uicc. |
| 3566 | */ |
| 3567 | @Override |
| 3568 | public String getAidForAppType(int subId, int appType) { |
| 3569 | enforceReadPrivilegedPermission(); |
| 3570 | Phone phone = getPhone(subId); |
| 3571 | if (phone == null) { |
| 3572 | return null; |
| 3573 | } |
| 3574 | String aid = null; |
| 3575 | try { |
| 3576 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 3577 | .getApplicationByType(appType).getAid(); |
| 3578 | } catch (Exception e) { |
| 3579 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 3580 | } |
| 3581 | return aid; |
| 3582 | } |
| 3583 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 3584 | /** |
| 3585 | * Return the Electronic Serial Number. |
| 3586 | * |
| 3587 | * @param subId the subscription ID that this request applies to. |
| 3588 | * @return ESN or null if error. |
| 3589 | */ |
| 3590 | @Override |
| 3591 | public String getEsn(int subId) { |
| 3592 | enforceReadPrivilegedPermission(); |
| 3593 | Phone phone = getPhone(subId); |
| 3594 | if (phone == null) { |
| 3595 | return null; |
| 3596 | } |
| 3597 | String esn = null; |
| 3598 | try { |
| 3599 | esn = phone.getEsn(); |
| 3600 | } catch (Exception e) { |
| 3601 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 3602 | } |
| 3603 | return esn; |
| 3604 | } |
| 3605 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 3606 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 3607 | * Return the Preferred Roaming List Version. |
| 3608 | * |
| 3609 | * @param subId the subscription ID that this request applies to. |
| 3610 | * @return PRLVersion or null if error. |
| 3611 | */ |
| 3612 | @Override |
| 3613 | public String getCdmaPrlVersion(int subId) { |
| 3614 | enforceReadPrivilegedPermission(); |
| 3615 | Phone phone = getPhone(subId); |
| 3616 | if (phone == null) { |
| 3617 | return null; |
| 3618 | } |
| 3619 | String cdmaPrlVersion = null; |
| 3620 | try { |
| 3621 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 3622 | } catch (Exception e) { |
| 3623 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 3624 | } |
| 3625 | return cdmaPrlVersion; |
| 3626 | } |
| 3627 | |
| 3628 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 3629 | * Get snapshot of Telephony histograms |
| 3630 | * @return List of Telephony histograms |
| 3631 | * @hide |
| 3632 | */ |
| 3633 | @Override |
| 3634 | public List<TelephonyHistogram> getTelephonyHistograms() { |
| 3635 | enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription()); |
| 3636 | return RIL.getTelephonyRILTimingHistograms(); |
| 3637 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3638 | |
| 3639 | /** |
| 3640 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3641 | * Set the allowed carrier list for slotIndex |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3642 | * Require system privileges. In the future we may add this to carrier APIs. |
| 3643 | * |
| 3644 | * @return The number of carriers set successfully, should match length of carriers |
| 3645 | */ |
| 3646 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3647 | public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3648 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3649 | |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 3650 | if (carriers == null) { |
| 3651 | throw new NullPointerException("carriers cannot be null"); |
| 3652 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3653 | |
| 3654 | int subId = SubscriptionManager.getSubId(slotIndex)[0]; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3655 | int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId); |
| 3656 | return retVal[0]; |
| 3657 | } |
| 3658 | |
| 3659 | /** |
| 3660 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3661 | * Get the allowed carrier list for slotIndex. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3662 | * Require system privileges. In the future we may add this to carrier APIs. |
| 3663 | * |
| 3664 | * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list |
| 3665 | * means all carriers are allowed. |
| 3666 | */ |
| 3667 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3668 | public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3669 | enforceReadPrivilegedPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3670 | int subId = SubscriptionManager.getSubId(slotIndex)[0]; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3671 | return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId); |
| 3672 | } |
| 3673 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 3674 | /** |
| 3675 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 3676 | * @param subId the subscription ID that this action applies to. |
| 3677 | * @param enabled control enable or disable metered apns. |
| 3678 | * {@hide} |
| 3679 | */ |
| 3680 | @Override |
| 3681 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 3682 | enforceModifyPermission(); |
| 3683 | final Phone phone = getPhone(subId); |
| 3684 | if (phone == null) { |
| 3685 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 3686 | return; |
| 3687 | } |
| 3688 | try { |
| 3689 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 3690 | } catch (Exception e) { |
| 3691 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
| 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | /** |
| 3696 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 3697 | * @param subId the subscription ID that this action applies to. |
| 3698 | * @param enabled control enable or disable radio. |
| 3699 | * {@hide} |
| 3700 | */ |
| 3701 | @Override |
| 3702 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 3703 | enforceModifyPermission(); |
| 3704 | final Phone phone = getPhone(subId); |
| 3705 | if (phone == null) { |
| 3706 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 3707 | return; |
| 3708 | } |
| 3709 | try { |
| 3710 | phone.carrierActionSetRadioEnabled(enabled); |
| 3711 | } catch (Exception e) { |
| 3712 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
| 3713 | } |
| 3714 | } |
| 3715 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 3716 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 3717 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 3718 | * network status based on which carrier apps could apply actions accordingly, |
| 3719 | * enable/disable default url handler for example. |
| 3720 | * |
| 3721 | * @param subId the subscription ID that this action applies to. |
| 3722 | * @param report control start/stop reporting the default network status. |
| 3723 | * {@hide} |
| 3724 | */ |
| 3725 | @Override |
| 3726 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 3727 | enforceModifyPermission(); |
| 3728 | final Phone phone = getPhone(subId); |
| 3729 | if (phone == null) { |
| 3730 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 3731 | return; |
| 3732 | } |
| 3733 | try { |
| 3734 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 3735 | } catch (Exception e) { |
| 3736 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
| 3737 | } |
| 3738 | } |
| 3739 | |
| 3740 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 3741 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 3742 | * bug report is being generated. |
| 3743 | */ |
| 3744 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 3745 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 3746 | if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 3747 | != PackageManager.PERMISSION_GRANTED) { |
| 3748 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 3749 | + Binder.getCallingPid() |
| 3750 | + ", uid=" + Binder.getCallingUid() |
| 3751 | + "without permission " |
| 3752 | + android.Manifest.permission.DUMP); |
| 3753 | return; |
| 3754 | } |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 3755 | DumpsysHandler.dump(mPhone.getContext(), fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 3756 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 3757 | |
| 3758 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 3759 | * Get aggregated video call data usage since boot. |
| 3760 | * |
| 3761 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 3762 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 3763 | * {@hide} |
| 3764 | */ |
| 3765 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 3766 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 3767 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 3768 | null); |
| 3769 | |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 3770 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 3771 | // records the delta with the corresponding network identity. We just return the total video |
| 3772 | // call data usage snapshot since boot. |
| 3773 | Phone phone = getPhone(subId); |
| 3774 | if (phone != null) { |
| 3775 | return phone.getVtDataUsage(perUidStats); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 3776 | } |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 3777 | return null; |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 3778 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 3779 | |
| 3780 | /** |
| 3781 | * Policy control of data connection. Usually used when data limit is passed. |
| 3782 | * @param enabled True if enabling the data, otherwise disabling. |
| 3783 | * @param subId Subscription index |
| 3784 | * {@hide} |
| 3785 | */ |
| 3786 | @Override |
| 3787 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 3788 | enforceModifyPermission(); |
| 3789 | Phone phone = getPhone(subId); |
| 3790 | if (phone != null) { |
| 3791 | phone.setPolicyDataEnabled(enabled); |
| 3792 | } |
| 3793 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 3794 | |
| 3795 | /** |
| 3796 | * Get Client request stats |
| 3797 | * @return List of Client Request Stats |
| 3798 | * @hide |
| 3799 | */ |
| 3800 | @Override |
| 3801 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
| 3802 | if (!canReadPhoneState(callingPackage, "getClientRequestStats")) { |
| 3803 | return null; |
| 3804 | } |
| 3805 | |
| 3806 | Phone phone = getPhone(subId); |
| 3807 | if (phone != null) { |
| 3808 | return phone.getClientRequestStats(); |
| 3809 | } |
| 3810 | |
| 3811 | return null; |
| 3812 | } |
| 3813 | |
| 3814 | private WorkSource getWorkSource(WorkSource workSource, int uid) { |
| 3815 | if (workSource != null) { |
| 3816 | return workSource; |
| 3817 | } |
| 3818 | |
| 3819 | String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid); |
| 3820 | workSource = new WorkSource(uid, packageName); |
| 3821 | return workSource; |
| 3822 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 3823 | |
| 3824 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 3825 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 3826 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3827 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 3828 | * @param state State of SIM (power down, power up, pass through) |
| 3829 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 3830 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 3831 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 3832 | * |
| 3833 | **/ |
| 3834 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 3835 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 3836 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3837 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3838 | |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 3839 | if (phone != null) { |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 3840 | phone.setSimPowerState(state); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 3841 | } |
| 3842 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 3843 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 3844 | private boolean isUssdApiAllowed(int subId) { |
| 3845 | CarrierConfigManager configManager = |
| 3846 | (CarrierConfigManager) mPhone.getContext().getSystemService( |
| 3847 | Context.CARRIER_CONFIG_SERVICE); |
| 3848 | if (configManager == null) { |
| 3849 | return false; |
| 3850 | } |
| 3851 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 3852 | if (pb == null) { |
| 3853 | return false; |
| 3854 | } |
| 3855 | return pb.getBoolean( |
| 3856 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 3857 | } |
| 3858 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 3859 | /** |
| 3860 | * Check if phone is in emergency callback mode |
| 3861 | * @return true if phone is in emergency callback mode |
| 3862 | * @param subId sub id |
| 3863 | */ |
| 3864 | public boolean getEmergencyCallbackMode(int subId) { |
| 3865 | final Phone phone = getPhone(subId); |
| 3866 | if (phone != null) { |
| 3867 | return phone.isInEcm(); |
| 3868 | } else { |
| 3869 | return false; |
| 3870 | } |
| 3871 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 3872 | |
| 3873 | /** |
| 3874 | * Get the current signal strength information for the given subscription. |
| 3875 | * Because this information is not updated when the device is in a low power state |
| 3876 | * it should not be relied-upon to be current. |
| 3877 | * @param subId Subscription index |
| 3878 | * @return the most recent cached signal strength info from the modem |
| 3879 | */ |
| 3880 | @Override |
| 3881 | public SignalStrength getSignalStrength(int subId) { |
| 3882 | Phone p = getPhone(subId); |
| 3883 | if (p == null) { |
| 3884 | return null; |
| 3885 | } |
| 3886 | |
| 3887 | return p.getSignalStrength(); |
| 3888 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3889 | } |