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