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