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