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