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