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