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