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