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