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