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 | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame^] | 82 | import android.telephony.data.ApnSetting; |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 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 | 4c46071 | 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 | 4c46071 | 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 | 4c46071 | 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 | 0258169 | 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 | f144d94 | 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; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [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; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [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 | 1cc0abe | 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 | 0c05b50 | 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 | 1cc0abe | 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 | f144d94 | 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 | e435a3e | 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 | e435a3e | 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 | e435a3e | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | e435a3e | 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 | 0c05b50 | 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 | e435a3e | 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 | 1cc0abe | 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 | 1cc0abe | 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 | 1cc0abe | 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 | 0c05b50 | 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 | e435a3e | 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 | 0c05b50 | 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 | 0c05b50 | 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 | dd9ac82 | 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 | e435a3e | 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 | 0c05b50 | 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 | e435a3e | 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 | 0c05b50 | 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 | e435a3e | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 1cc0abe | 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 | 1cc0abe | 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 | 0c05b50 | 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 | 0c05b50 | 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 | e435a3e | 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 | e435a3e | 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 | f144d94 | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame^] | 1719 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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(); |
| 2037 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2038 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 2039 | return null; |
| 2040 | } |
Malcolm Chen | d965c8b | 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(); |
| 2068 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2069 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 2070 | return null; |
| 2071 | } |
Malcolm Chen | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2134 | @Override |
| 2135 | public int getSubscriptionMNOCarrierId(int subId) { |
| 2136 | final long identity = Binder.clearCallingIdentity(); |
| 2137 | try { |
| 2138 | final Phone phone = getPhone(subId); |
| 2139 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId(); |
| 2140 | } finally { |
| 2141 | Binder.restoreCallingIdentity(identity); |
| 2142 | } |
| 2143 | } |
| 2144 | |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2145 | @Override |
| 2146 | public int getSubscriptionPreciseCarrierId(int subId) { |
| 2147 | final long identity = Binder.clearCallingIdentity(); |
| 2148 | try { |
| 2149 | final Phone phone = getPhone(subId); |
| 2150 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
| 2151 | : phone.getPreciseCarrierId(); |
| 2152 | } finally { |
| 2153 | Binder.restoreCallingIdentity(identity); |
| 2154 | } |
| 2155 | } |
| 2156 | |
| 2157 | @Override |
| 2158 | public String getSubscriptionPreciseCarrierName(int subId) { |
| 2159 | final long identity = Binder.clearCallingIdentity(); |
| 2160 | try { |
| 2161 | final Phone phone = getPhone(subId); |
| 2162 | return phone == null ? null : phone.getPreciseCarrierName(); |
| 2163 | } finally { |
| 2164 | Binder.restoreCallingIdentity(identity); |
| 2165 | } |
| 2166 | } |
| 2167 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2168 | @Override |
| 2169 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc) { |
| 2170 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2171 | if (phone == null) { |
| 2172 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2173 | } |
| 2174 | final long identity = Binder.clearCallingIdentity(); |
| 2175 | try { |
| 2176 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2177 | } finally { |
| 2178 | Binder.restoreCallingIdentity(identity); |
| 2179 | } |
| 2180 | } |
| 2181 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2182 | // |
| 2183 | // Internal helper methods. |
| 2184 | // |
| 2185 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2186 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2187 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2188 | * |
| 2189 | * @throws SecurityException if the caller does not have the required permission |
| 2190 | */ |
| 2191 | private void enforceModifyPermission() { |
| 2192 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2193 | } |
| 2194 | |
| 2195 | /** |
| 2196 | * Make sure the caller has the CALL_PHONE permission. |
| 2197 | * |
| 2198 | * @throws SecurityException if the caller does not have the required permission |
| 2199 | */ |
| 2200 | private void enforceCallPermission() { |
| 2201 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2202 | } |
| 2203 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2204 | private void enforceConnectivityInternalPermission() { |
| 2205 | mApp.enforceCallingOrSelfPermission( |
| 2206 | android.Manifest.permission.CONNECTIVITY_INTERNAL, |
| 2207 | "ConnectivityService"); |
| 2208 | } |
| 2209 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2210 | private String createTelUrl(String number) { |
| 2211 | if (TextUtils.isEmpty(number)) { |
| 2212 | return null; |
| 2213 | } |
| 2214 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2215 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2216 | } |
| 2217 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2218 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2219 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2220 | } |
| 2221 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2222 | private static void logv(String msg) { |
| 2223 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2224 | } |
| 2225 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2226 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2227 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2228 | } |
| 2229 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2230 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2231 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2232 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2235 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2236 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2237 | final long identity = Binder.clearCallingIdentity(); |
| 2238 | try { |
| 2239 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2240 | if (phone == null) { |
| 2241 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2242 | } else { |
| 2243 | return phone.getPhoneType(); |
| 2244 | } |
| 2245 | } finally { |
| 2246 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2247 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | /** |
| 2251 | * Returns the CDMA ERI icon index to display |
| 2252 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2253 | @Override |
| 2254 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2255 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2258 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2259 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2260 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2261 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2262 | return -1; |
| 2263 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2264 | |
| 2265 | final long identity = Binder.clearCallingIdentity(); |
| 2266 | try { |
| 2267 | final Phone phone = getPhone(subId); |
| 2268 | if (phone != null) { |
| 2269 | return phone.getCdmaEriIconIndex(); |
| 2270 | } else { |
| 2271 | return -1; |
| 2272 | } |
| 2273 | } finally { |
| 2274 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2275 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | /** |
| 2279 | * Returns the CDMA ERI icon mode, |
| 2280 | * 0 - ON |
| 2281 | * 1 - FLASHING |
| 2282 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2283 | @Override |
| 2284 | public int getCdmaEriIconMode(String callingPackage) { |
| 2285 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2288 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2289 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2290 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2291 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2292 | return -1; |
| 2293 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2294 | |
| 2295 | final long identity = Binder.clearCallingIdentity(); |
| 2296 | try { |
| 2297 | final Phone phone = getPhone(subId); |
| 2298 | if (phone != null) { |
| 2299 | return phone.getCdmaEriIconMode(); |
| 2300 | } else { |
| 2301 | return -1; |
| 2302 | } |
| 2303 | } finally { |
| 2304 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2305 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | /** |
| 2309 | * Returns the CDMA ERI text, |
| 2310 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2311 | @Override |
| 2312 | public String getCdmaEriText(String callingPackage) { |
| 2313 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2316 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2317 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2318 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2319 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2320 | return null; |
| 2321 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2322 | |
| 2323 | final long identity = Binder.clearCallingIdentity(); |
| 2324 | try { |
| 2325 | final Phone phone = getPhone(subId); |
| 2326 | if (phone != null) { |
| 2327 | return phone.getCdmaEriText(); |
| 2328 | } else { |
| 2329 | return null; |
| 2330 | } |
| 2331 | } finally { |
| 2332 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2333 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2337 | * Returns the CDMA MDN. |
| 2338 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2339 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2340 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2341 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2342 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2343 | |
| 2344 | final long identity = Binder.clearCallingIdentity(); |
| 2345 | try { |
| 2346 | final Phone phone = getPhone(subId); |
| 2347 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) { |
| 2348 | return phone.getLine1Number(); |
| 2349 | } else { |
| 2350 | return null; |
| 2351 | } |
| 2352 | } finally { |
| 2353 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | /** |
| 2358 | * Returns the CDMA MIN. |
| 2359 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2360 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2361 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2362 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2363 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2364 | |
| 2365 | final long identity = Binder.clearCallingIdentity(); |
| 2366 | try { |
| 2367 | final Phone phone = getPhone(subId); |
| 2368 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2369 | return phone.getCdmaMin(); |
| 2370 | } else { |
| 2371 | return null; |
| 2372 | } |
| 2373 | } finally { |
| 2374 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2379 | * Returns true if CDMA provisioning needs to run. |
| 2380 | */ |
| 2381 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2382 | final long identity = Binder.clearCallingIdentity(); |
| 2383 | try { |
| 2384 | return mPhone.needsOtaServiceProvisioning(); |
| 2385 | } finally { |
| 2386 | Binder.restoreCallingIdentity(identity); |
| 2387 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2391 | * Sets the voice mail number of a given subId. |
| 2392 | */ |
| 2393 | @Override |
| 2394 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2395 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2396 | |
| 2397 | final long identity = Binder.clearCallingIdentity(); |
| 2398 | try { |
| 2399 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2400 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2401 | return success; |
| 2402 | } finally { |
| 2403 | Binder.restoreCallingIdentity(identity); |
| 2404 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2405 | } |
| 2406 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2407 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2408 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2409 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2410 | String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage(); |
| 2411 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2412 | throw new SecurityException("caller must be system dialer"); |
| 2413 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2414 | |
| 2415 | final long identity = Binder.clearCallingIdentity(); |
| 2416 | try { |
| 2417 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2418 | if (phoneAccountHandle == null) { |
| 2419 | return null; |
| 2420 | } |
| 2421 | return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle); |
| 2422 | } finally { |
| 2423 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2424 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2428 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2429 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2430 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2431 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2432 | return null; |
| 2433 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2434 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2435 | final long identity = Binder.clearCallingIdentity(); |
| 2436 | try { |
| 2437 | return RemoteVvmTaskManager |
| 2438 | .getRemotePackage(mPhone.getContext(), subId).getPackageName(); |
| 2439 | } finally { |
| 2440 | Binder.restoreCallingIdentity(identity); |
| 2441 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2445 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2446 | VisualVoicemailSmsFilterSettings settings) { |
| 2447 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2448 | |
| 2449 | final long identity = Binder.clearCallingIdentity(); |
| 2450 | try { |
| 2451 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
| 2452 | mPhone.getContext(), callingPackage, subId, settings); |
| 2453 | } finally { |
| 2454 | Binder.restoreCallingIdentity(identity); |
| 2455 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2459 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2460 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2461 | |
| 2462 | final long identity = Binder.clearCallingIdentity(); |
| 2463 | try { |
| 2464 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
| 2465 | mPhone.getContext(), callingPackage, subId); |
| 2466 | } finally { |
| 2467 | Binder.restoreCallingIdentity(identity); |
| 2468 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2469 | } |
| 2470 | |
| 2471 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2472 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2473 | String callingPackage, int subId) { |
| 2474 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2475 | |
| 2476 | final long identity = Binder.clearCallingIdentity(); |
| 2477 | try { |
| 2478 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
| 2479 | mPhone.getContext(), callingPackage, subId); |
| 2480 | } finally { |
| 2481 | Binder.restoreCallingIdentity(identity); |
| 2482 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2486 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2487 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2488 | |
| 2489 | final long identity = Binder.clearCallingIdentity(); |
| 2490 | try { |
| 2491 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
| 2492 | mPhone.getContext(), subId); |
| 2493 | } finally { |
| 2494 | Binder.restoreCallingIdentity(identity); |
| 2495 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | @Override |
| 2499 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2500 | String number, int port, String text, PendingIntent sentIntent) { |
| 2501 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2502 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2503 | enforceSendSmsPermission(); |
| 2504 | // Make the calls as the phone process. |
| 2505 | final long identity = Binder.clearCallingIdentity(); |
| 2506 | try { |
| 2507 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2508 | if (port == 0) { |
| 2509 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2510 | sentIntent, null, false); |
| 2511 | } else { |
| 2512 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2513 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2514 | (short) port, data, sentIntent, null); |
| 2515 | } |
| 2516 | } finally { |
| 2517 | Binder.restoreCallingIdentity(identity); |
| 2518 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2519 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2520 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2521 | * Sets the voice activation state of a given subId. |
| 2522 | */ |
| 2523 | @Override |
| 2524 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2525 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2526 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2527 | |
| 2528 | final long identity = Binder.clearCallingIdentity(); |
| 2529 | try { |
| 2530 | final Phone phone = getPhone(subId); |
| 2531 | if (phone != null) { |
| 2532 | phone.setVoiceActivationState(activationState); |
| 2533 | } else { |
| 2534 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2535 | } |
| 2536 | } finally { |
| 2537 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2538 | } |
| 2539 | } |
| 2540 | |
| 2541 | /** |
| 2542 | * Sets the data activation state of a given subId. |
| 2543 | */ |
| 2544 | @Override |
| 2545 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2546 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2547 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2548 | |
| 2549 | final long identity = Binder.clearCallingIdentity(); |
| 2550 | try { |
| 2551 | final Phone phone = getPhone(subId); |
| 2552 | if (phone != null) { |
| 2553 | phone.setDataActivationState(activationState); |
| 2554 | } else { |
| 2555 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2556 | } |
| 2557 | } finally { |
| 2558 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2559 | } |
| 2560 | } |
| 2561 | |
| 2562 | /** |
| 2563 | * Returns the voice activation state of a given subId. |
| 2564 | */ |
| 2565 | @Override |
| 2566 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2567 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2568 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2569 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2570 | final long identity = Binder.clearCallingIdentity(); |
| 2571 | try { |
| 2572 | if (phone != null) { |
| 2573 | return phone.getVoiceActivationState(); |
| 2574 | } else { |
| 2575 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2576 | } |
| 2577 | } finally { |
| 2578 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2579 | } |
| 2580 | } |
| 2581 | |
| 2582 | /** |
| 2583 | * Returns the data activation state of a given subId. |
| 2584 | */ |
| 2585 | @Override |
| 2586 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2587 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2588 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2589 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2590 | final long identity = Binder.clearCallingIdentity(); |
| 2591 | try { |
| 2592 | if (phone != null) { |
| 2593 | return phone.getDataActivationState(); |
| 2594 | } else { |
| 2595 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2596 | } |
| 2597 | } finally { |
| 2598 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2599 | } |
| 2600 | } |
| 2601 | |
| 2602 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2603 | * Returns the unread count of voicemails for a subId |
| 2604 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2605 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2606 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2607 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2608 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2609 | return 0; |
| 2610 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2611 | final long identity = Binder.clearCallingIdentity(); |
| 2612 | try { |
| 2613 | final Phone phone = getPhone(subId); |
| 2614 | if (phone != null) { |
| 2615 | return phone.getVoiceMessageCount(); |
| 2616 | } else { |
| 2617 | return 0; |
| 2618 | } |
| 2619 | } finally { |
| 2620 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2621 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2625 | * returns true, if the device is in a state where both voice and data |
| 2626 | * are supported simultaneously. This can change based on location or network condition. |
| 2627 | */ |
| 2628 | @Override |
| 2629 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2630 | final long identity = Binder.clearCallingIdentity(); |
| 2631 | try { |
| 2632 | final Phone phone = getPhone(subId); |
| 2633 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2634 | } finally { |
| 2635 | Binder.restoreCallingIdentity(identity); |
| 2636 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2640 | * Send the dialer code if called from the current default dialer or the caller has |
| 2641 | * carrier privilege. |
| 2642 | * @param inputCode The dialer code to send |
| 2643 | */ |
| 2644 | @Override |
| 2645 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
| 2646 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2647 | String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage(); |
| 2648 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2649 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2650 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2651 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2652 | |
| 2653 | final long identity = Binder.clearCallingIdentity(); |
| 2654 | try { |
| 2655 | mPhone.sendDialerSpecialCode(inputCode); |
| 2656 | } finally { |
| 2657 | Binder.restoreCallingIdentity(identity); |
| 2658 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2662 | * Returns the data network type. |
| 2663 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2664 | * |
| 2665 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2666 | */ |
| 2667 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2668 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2669 | final long identity = Binder.clearCallingIdentity(); |
| 2670 | try { |
| 2671 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2672 | if (phone != null) { |
| 2673 | return phone.getServiceState().getDataNetworkType(); |
| 2674 | } else { |
| 2675 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2676 | } |
| 2677 | } finally { |
| 2678 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2679 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2682 | @Override |
| 2683 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2684 | if (!isActiveSubscription(subId)) { |
| 2685 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2686 | } |
| 2687 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2688 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2689 | } |
| 2690 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2691 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2692 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2693 | throws RemoteException { |
| 2694 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2695 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2696 | final long token = Binder.clearCallingIdentity(); |
| 2697 | try { |
| 2698 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2699 | .addRegistrationCallbackForSubscription(c, subId); |
| 2700 | } finally { |
| 2701 | Binder.restoreCallingIdentity(token); |
| 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2706 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2707 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2708 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2709 | Binder.withCleanCallingIdentity(() -> |
| 2710 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2711 | .removeRegistrationCallbackForSubscription(c, subId)); |
| 2712 | } |
| 2713 | |
| 2714 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2715 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2716 | throws RemoteException { |
| 2717 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2718 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2719 | final long token = Binder.clearCallingIdentity(); |
| 2720 | try { |
| 2721 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2722 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2723 | } finally { |
| 2724 | Binder.restoreCallingIdentity(token); |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2729 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2730 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2731 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2732 | Binder.withCleanCallingIdentity(() -> |
| 2733 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2734 | .removeCapabilitiesCallbackForSubscription(c, subId)); |
| 2735 | } |
| 2736 | |
| 2737 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2738 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2739 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2740 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2741 | final long token = Binder.clearCallingIdentity(); |
| 2742 | try { |
| 2743 | return ImsManager.getInstance(mPhone.getContext(), |
| 2744 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2745 | } catch (ImsException e) { |
| 2746 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2747 | return false; |
| 2748 | } finally { |
| 2749 | Binder.restoreCallingIdentity(token); |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2754 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2755 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2756 | final long token = Binder.clearCallingIdentity(); |
| 2757 | try { |
| 2758 | Phone phone = getPhone(subId); |
| 2759 | if (phone == null) return false; |
| 2760 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2761 | } finally { |
| 2762 | Binder.restoreCallingIdentity(token); |
| 2763 | } |
| 2764 | } |
| 2765 | |
| 2766 | @Override |
| 2767 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2768 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2769 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2770 | final long token = Binder.clearCallingIdentity(); |
| 2771 | try { |
| 2772 | return ImsManager.getInstance(mPhone.getContext(), |
| 2773 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2774 | } finally { |
| 2775 | Binder.restoreCallingIdentity(token); |
| 2776 | } |
| 2777 | } |
| 2778 | |
| 2779 | @Override |
| 2780 | public void setAdvancedCallingSetting(int subId, boolean isEnabled) { |
| 2781 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2782 | "setAdvancedCallingSetting"); |
| 2783 | final long identity = Binder.clearCallingIdentity(); |
| 2784 | try { |
| 2785 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2786 | ImsManager.getInstance(mPhone.getContext(), |
| 2787 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2788 | } finally { |
| 2789 | Binder.restoreCallingIdentity(identity); |
| 2790 | } |
| 2791 | } |
| 2792 | |
| 2793 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2794 | public boolean isVtSettingEnabled(int subId) { |
| 2795 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2796 | final long identity = Binder.clearCallingIdentity(); |
| 2797 | try { |
| 2798 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2799 | return ImsManager.getInstance(mPhone.getContext(), |
| 2800 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2801 | } finally { |
| 2802 | Binder.restoreCallingIdentity(identity); |
| 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | @Override |
| 2807 | public void setVtSetting(int subId, boolean isEnabled) { |
| 2808 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2809 | "setVtSetting"); |
| 2810 | final long identity = Binder.clearCallingIdentity(); |
| 2811 | try { |
| 2812 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2813 | ImsManager.getInstance(mPhone.getContext(), |
| 2814 | getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
| 2815 | } finally { |
| 2816 | Binder.restoreCallingIdentity(identity); |
| 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | @Override |
| 2821 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2822 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2823 | final long identity = Binder.clearCallingIdentity(); |
| 2824 | try { |
| 2825 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2826 | return ImsManager.getInstance(mPhone.getContext(), |
| 2827 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2828 | } finally { |
| 2829 | Binder.restoreCallingIdentity(identity); |
| 2830 | } |
| 2831 | } |
| 2832 | |
| 2833 | @Override |
| 2834 | public void setVoWiFiSetting(int subId, boolean isEnabled) { |
| 2835 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2836 | "setVoWiFiSetting"); |
| 2837 | final long identity = Binder.clearCallingIdentity(); |
| 2838 | try { |
| 2839 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2840 | ImsManager.getInstance(mPhone.getContext(), |
| 2841 | getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
| 2842 | } finally { |
| 2843 | Binder.restoreCallingIdentity(identity); |
| 2844 | } |
| 2845 | } |
| 2846 | |
| 2847 | @Override |
| 2848 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2849 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2850 | final long identity = Binder.clearCallingIdentity(); |
| 2851 | try { |
| 2852 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2853 | return ImsManager.getInstance(mPhone.getContext(), |
| 2854 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 2855 | } finally { |
| 2856 | Binder.restoreCallingIdentity(identity); |
| 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | @Override |
| 2861 | public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) { |
| 2862 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2863 | "setVoWiFiRoamingSetting"); |
| 2864 | final long identity = Binder.clearCallingIdentity(); |
| 2865 | try { |
| 2866 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2867 | ImsManager.getInstance(mPhone.getContext(), |
| 2868 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 2869 | } finally { |
| 2870 | Binder.restoreCallingIdentity(identity); |
| 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | @Override |
| 2875 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 2876 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2877 | "setVoWiFiNonPersistent"); |
| 2878 | final long identity = Binder.clearCallingIdentity(); |
| 2879 | try { |
| 2880 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2881 | ImsManager.getInstance(mPhone.getContext(), |
| 2882 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
| 2883 | } finally { |
| 2884 | Binder.restoreCallingIdentity(identity); |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | @Override |
| 2889 | public int getVoWiFiModeSetting(int subId) { |
| 2890 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 2891 | final long identity = Binder.clearCallingIdentity(); |
| 2892 | try { |
| 2893 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2894 | return ImsManager.getInstance(mPhone.getContext(), |
| 2895 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 2896 | } finally { |
| 2897 | Binder.restoreCallingIdentity(identity); |
| 2898 | } |
| 2899 | } |
| 2900 | |
| 2901 | @Override |
| 2902 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 2903 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2904 | "setVoWiFiModeSetting"); |
| 2905 | final long identity = Binder.clearCallingIdentity(); |
| 2906 | try { |
| 2907 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2908 | ImsManager.getInstance(mPhone.getContext(), |
| 2909 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 2910 | } finally { |
| 2911 | Binder.restoreCallingIdentity(identity); |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | @Override |
| 2916 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 2917 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 2918 | final long identity = Binder.clearCallingIdentity(); |
| 2919 | try { |
| 2920 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2921 | return ImsManager.getInstance(mPhone.getContext(), |
| 2922 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 2923 | } finally { |
| 2924 | Binder.restoreCallingIdentity(identity); |
| 2925 | } |
| 2926 | } |
| 2927 | |
| 2928 | @Override |
| 2929 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 2930 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2931 | "setVoWiFiRoamingModeSetting"); |
| 2932 | final long identity = Binder.clearCallingIdentity(); |
| 2933 | try { |
| 2934 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2935 | ImsManager.getInstance(mPhone.getContext(), |
| 2936 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 2937 | } finally { |
| 2938 | Binder.restoreCallingIdentity(identity); |
| 2939 | } |
| 2940 | } |
| 2941 | |
| 2942 | @Override |
| 2943 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 2944 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2945 | "setRttCapabilityEnabled"); |
| 2946 | final long identity = Binder.clearCallingIdentity(); |
| 2947 | try { |
| 2948 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2949 | ImsManager.getInstance(mPhone.getContext(), |
| 2950 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 2951 | } finally { |
| 2952 | Binder.restoreCallingIdentity(identity); |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | @Override |
| 2957 | public boolean isTtyOverVolteEnabled(int subId) { |
| 2958 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 2959 | final long identity = Binder.clearCallingIdentity(); |
| 2960 | try { |
| 2961 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2962 | return ImsManager.getInstance(mPhone.getContext(), |
| 2963 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 2964 | } finally { |
| 2965 | Binder.restoreCallingIdentity(identity); |
| 2966 | } |
| 2967 | } |
| 2968 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 2969 | @Override |
| 2970 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 2971 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 2972 | final long identity = Binder.clearCallingIdentity(); |
| 2973 | try { |
| 2974 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2975 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2976 | .getConfigInterface().addConfigCallback(callback); |
| 2977 | } catch (ImsException e) { |
| 2978 | throw new IllegalArgumentException(e.getMessage()); |
| 2979 | } finally { |
| 2980 | Binder.restoreCallingIdentity(identity); |
| 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | @Override |
| 2985 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 2986 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 2987 | final long identity = Binder.clearCallingIdentity(); |
| 2988 | try { |
| 2989 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2990 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2991 | .getConfigInterface().removeConfigCallback(callback); |
| 2992 | } catch (ImsException e) { |
| 2993 | throw new IllegalArgumentException(e.getMessage()); |
| 2994 | } finally { |
| 2995 | Binder.restoreCallingIdentity(identity); |
| 2996 | } |
| 2997 | } |
| 2998 | |
| 2999 | @Override |
| 3000 | public int getImsProvisioningInt(int subId, int key) { |
| 3001 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3002 | final long identity = Binder.clearCallingIdentity(); |
| 3003 | try { |
| 3004 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3005 | return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 3006 | .getConfigInterface().getConfigInt(key); |
| 3007 | } catch (ImsException e) { |
| 3008 | throw new IllegalArgumentException(e.getMessage()); |
| 3009 | } finally { |
| 3010 | Binder.restoreCallingIdentity(identity); |
| 3011 | } |
| 3012 | } |
| 3013 | |
| 3014 | @Override |
| 3015 | public String getImsProvisioningString(int subId, int key) { |
| 3016 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3017 | final long identity = Binder.clearCallingIdentity(); |
| 3018 | try { |
| 3019 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3020 | return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 3021 | .getConfigInterface().getConfigString(key); |
| 3022 | } catch (ImsException e) { |
| 3023 | throw new IllegalArgumentException(e.getMessage()); |
| 3024 | } finally { |
| 3025 | Binder.restoreCallingIdentity(identity); |
| 3026 | } |
| 3027 | } |
| 3028 | |
| 3029 | @Override |
| 3030 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3031 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3032 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3033 | final long identity = Binder.clearCallingIdentity(); |
| 3034 | try { |
| 3035 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3036 | return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 3037 | .getConfigInterface().setConfig(key, value); |
| 3038 | } catch (ImsException e) { |
| 3039 | throw new IllegalArgumentException(e.getMessage()); |
| 3040 | } finally { |
| 3041 | Binder.restoreCallingIdentity(identity); |
| 3042 | } |
| 3043 | } |
| 3044 | |
| 3045 | @Override |
| 3046 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3047 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3048 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3049 | final long identity = Binder.clearCallingIdentity(); |
| 3050 | try { |
| 3051 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3052 | return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 3053 | .getConfigInterface().setConfig(key, value); |
| 3054 | } catch (ImsException e) { |
| 3055 | throw new IllegalArgumentException(e.getMessage()); |
| 3056 | } finally { |
| 3057 | Binder.restoreCallingIdentity(identity); |
| 3058 | } |
| 3059 | } |
| 3060 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3061 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3062 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3063 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3064 | throw new IllegalArgumentException("Invalid Subscription Id."); |
| 3065 | } |
| 3066 | return slotId; |
| 3067 | } |
| 3068 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3069 | /** |
| 3070 | * Returns the network type for a subId |
| 3071 | */ |
| 3072 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3073 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3074 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3075 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3076 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3077 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3078 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3079 | final long identity = Binder.clearCallingIdentity(); |
| 3080 | try { |
| 3081 | final Phone phone = getPhone(subId); |
| 3082 | if (phone != null) { |
| 3083 | return phone.getServiceState().getDataNetworkType(); |
| 3084 | } else { |
| 3085 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3086 | } |
| 3087 | } finally { |
| 3088 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3089 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3090 | } |
| 3091 | |
| 3092 | /** |
| 3093 | * Returns the data network type |
| 3094 | */ |
| 3095 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3096 | public int getDataNetworkType(String callingPackage) { |
| 3097 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3098 | } |
| 3099 | |
| 3100 | /** |
| 3101 | * Returns the data network type for a subId |
| 3102 | */ |
| 3103 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3104 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3105 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3106 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3107 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3108 | } |
| 3109 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3110 | final long identity = Binder.clearCallingIdentity(); |
| 3111 | try { |
| 3112 | final Phone phone = getPhone(subId); |
| 3113 | if (phone != null) { |
| 3114 | return phone.getServiceState().getDataNetworkType(); |
| 3115 | } else { |
| 3116 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3117 | } |
| 3118 | } finally { |
| 3119 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3120 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3124 | * Returns the Voice network type for a subId |
| 3125 | */ |
| 3126 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3127 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3128 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3129 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3130 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3131 | } |
| 3132 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3133 | final long identity = Binder.clearCallingIdentity(); |
| 3134 | try { |
| 3135 | final Phone phone = getPhone(subId); |
| 3136 | if (phone != null) { |
| 3137 | return phone.getServiceState().getVoiceNetworkType(); |
| 3138 | } else { |
| 3139 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3140 | } |
| 3141 | } finally { |
| 3142 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3143 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3144 | } |
| 3145 | |
| 3146 | /** |
| 3147 | * @return true if a ICC card is present |
| 3148 | */ |
| 3149 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3150 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3151 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3152 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3156 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3157 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3158 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3159 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3160 | final long identity = Binder.clearCallingIdentity(); |
| 3161 | try { |
| 3162 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3163 | if (phone != null) { |
| 3164 | return phone.getIccCard().hasIccCard(); |
| 3165 | } else { |
| 3166 | return false; |
| 3167 | } |
| 3168 | } finally { |
| 3169 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3170 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3171 | } |
| 3172 | |
| 3173 | /** |
| 3174 | * Return if the current radio is LTE on CDMA. This |
| 3175 | * is a tri-state return value as for a period of time |
| 3176 | * the mode may be unknown. |
| 3177 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3178 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3179 | * @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] | 3180 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3181 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3182 | @Override |
| 3183 | public int getLteOnCdmaMode(String callingPackage) { |
| 3184 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3185 | } |
| 3186 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3187 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3188 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3189 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3190 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3191 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3192 | } |
| 3193 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3194 | final long identity = Binder.clearCallingIdentity(); |
| 3195 | try { |
| 3196 | final Phone phone = getPhone(subId); |
| 3197 | if (phone == null) { |
| 3198 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3199 | } else { |
| 3200 | return phone.getLteOnCdmaMode(); |
| 3201 | } |
| 3202 | } finally { |
| 3203 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3204 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3205 | } |
| 3206 | |
| 3207 | public void setPhone(Phone phone) { |
| 3208 | mPhone = phone; |
| 3209 | } |
| 3210 | |
| 3211 | /** |
| 3212 | * {@hide} |
| 3213 | * Returns Default subId, 0 in the case of single standby. |
| 3214 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3215 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3216 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3217 | } |
| 3218 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3219 | private int getSlotForDefaultSubscription() { |
| 3220 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3221 | } |
| 3222 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3223 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3224 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3225 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3226 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3227 | private boolean isActiveSubscription(int subId) { |
| 3228 | return mSubscriptionController.isActiveSubId(subId); |
| 3229 | } |
| 3230 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3231 | /** |
| 3232 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3233 | */ |
| 3234 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3235 | final long identity = Binder.clearCallingIdentity(); |
| 3236 | try { |
| 3237 | return Settings.System.getInt(mPhone.getContext().getContentResolver(), |
| 3238 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3239 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3240 | } finally { |
| 3241 | Binder.restoreCallingIdentity(identity); |
| 3242 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | /** |
| 3246 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3247 | */ |
| 3248 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3249 | final long identity = Binder.clearCallingIdentity(); |
| 3250 | try { |
| 3251 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
| 3252 | Settings.System.putInt(mPhone.getContext().getContentResolver(), |
| 3253 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3254 | } finally { |
| 3255 | Binder.restoreCallingIdentity(identity); |
| 3256 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3257 | } |
| 3258 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3259 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3260 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3261 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3262 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3263 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3264 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3265 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3266 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3267 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3268 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3269 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3270 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3271 | final long identity = Binder.clearCallingIdentity(); |
| 3272 | try { |
| 3273 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3274 | // Only allows LPA to open logical channel to ISD-R. |
| 3275 | ComponentInfo bestComponent = |
| 3276 | EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager()); |
| 3277 | if (bestComponent == null |
| 3278 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3279 | loge("The calling package is not allowed to access ISD-R."); |
| 3280 | throw new SecurityException( |
| 3281 | "The calling package is not allowed to access ISD-R."); |
| 3282 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3283 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3284 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3285 | if (DBG) { |
| 3286 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3287 | } |
| 3288 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| 3289 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
| 3290 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 3291 | return response; |
| 3292 | } finally { |
| 3293 | Binder.restoreCallingIdentity(identity); |
| 3294 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3295 | } |
| 3296 | |
| 3297 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3298 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3299 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3300 | mApp, subId, "iccCloseLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3301 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3302 | final long identity = Binder.clearCallingIdentity(); |
| 3303 | try { |
| 3304 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3305 | if (channel < 0) { |
| 3306 | return false; |
| 3307 | } |
| 3308 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
| 3309 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 3310 | return success; |
| 3311 | } finally { |
| 3312 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3313 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3317 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3318 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3319 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3320 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3321 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3322 | final long identity = Binder.clearCallingIdentity(); |
| 3323 | try { |
| 3324 | if (DBG) { |
| 3325 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3326 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3327 | + p3 + " data=" + data); |
| 3328 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3329 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3330 | if (channel < 0) { |
| 3331 | return ""; |
| 3332 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3333 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3334 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| 3335 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
| 3336 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3337 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3338 | // Append the returned status code to the end of the response payload. |
| 3339 | String s = Integer.toHexString( |
| 3340 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3341 | if (response.payload != null) { |
| 3342 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3343 | } |
| 3344 | return s; |
| 3345 | } finally { |
| 3346 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3347 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3348 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3349 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3350 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3351 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3352 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3353 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3354 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3355 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3356 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3357 | final long identity = Binder.clearCallingIdentity(); |
| 3358 | try { |
| 3359 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3360 | && TextUtils.equals(ISDR_AID, data)) { |
| 3361 | // Only allows LPA to select ISD-R. |
| 3362 | ComponentInfo bestComponent = |
| 3363 | EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager()); |
| 3364 | if (bestComponent == null |
| 3365 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3366 | loge("The calling package is not allowed to select ISD-R."); |
| 3367 | throw new SecurityException( |
| 3368 | "The calling package is not allowed to select ISD-R."); |
| 3369 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3370 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3371 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3372 | if (DBG) { |
| 3373 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3374 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3375 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3376 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3377 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 3378 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
| 3379 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3380 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3381 | // Append the returned status code to the end of the response payload. |
| 3382 | String s = Integer.toHexString( |
| 3383 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3384 | if (response.payload != null) { |
| 3385 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3386 | } |
| 3387 | return s; |
| 3388 | } finally { |
| 3389 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3390 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3394 | 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] | 3395 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3396 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3397 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3398 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3399 | final long identity = Binder.clearCallingIdentity(); |
| 3400 | try { |
| 3401 | if (DBG) { |
| 3402 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3403 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3404 | } |
| 3405 | |
| 3406 | IccIoResult response = |
| 3407 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3408 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3409 | subId); |
| 3410 | |
| 3411 | if (DBG) { |
| 3412 | log("Exchange SIM_IO [R]" + response); |
| 3413 | } |
| 3414 | |
| 3415 | byte[] result = null; |
| 3416 | int length = 2; |
| 3417 | if (response.payload != null) { |
| 3418 | length = 2 + response.payload.length; |
| 3419 | result = new byte[length]; |
| 3420 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3421 | } else { |
| 3422 | result = new byte[length]; |
| 3423 | } |
| 3424 | |
| 3425 | result[length - 1] = (byte) response.sw2; |
| 3426 | result[length - 2] = (byte) response.sw1; |
| 3427 | return result; |
| 3428 | } finally { |
| 3429 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3430 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3433 | /** |
| 3434 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3435 | * on a particular subscription |
| 3436 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3437 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3438 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3439 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3440 | return null; |
| 3441 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3442 | |
| 3443 | final long identity = Binder.clearCallingIdentity(); |
| 3444 | try { |
| 3445 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3446 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3447 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3448 | return null; |
| 3449 | } |
| 3450 | Object response = sendRequest( |
| 3451 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3452 | if (response instanceof String[]) { |
| 3453 | return (String[]) response; |
| 3454 | } |
| 3455 | // Response is an Exception of some kind, |
| 3456 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3457 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3458 | } finally { |
| 3459 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3460 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3461 | } |
| 3462 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3463 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3464 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3465 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3466 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3467 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3468 | final long identity = Binder.clearCallingIdentity(); |
| 3469 | try { |
| 3470 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3471 | if (response.payload == null) { |
| 3472 | return ""; |
| 3473 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3474 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3475 | // Append the returned status code to the end of the response payload. |
| 3476 | String s = Integer.toHexString( |
| 3477 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3478 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3479 | return s; |
| 3480 | } finally { |
| 3481 | Binder.restoreCallingIdentity(identity); |
| 3482 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3485 | /** |
| 3486 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3487 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3488 | * |
| 3489 | * @param itemID the ID of the item to read |
| 3490 | * @return the NV item as a String, or null on error. |
| 3491 | */ |
| 3492 | @Override |
| 3493 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3494 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3495 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3496 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3497 | |
| 3498 | final long identity = Binder.clearCallingIdentity(); |
| 3499 | try { |
| 3500 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3501 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3502 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 3503 | return value; |
| 3504 | } finally { |
| 3505 | Binder.restoreCallingIdentity(identity); |
| 3506 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | /** |
| 3510 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3511 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3512 | * |
| 3513 | * @param itemID the ID of the item to read |
| 3514 | * @param itemValue the value to write, as a String |
| 3515 | * @return true on success; false on any failure |
| 3516 | */ |
| 3517 | @Override |
| 3518 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3519 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3520 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3521 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3522 | |
| 3523 | final long identity = Binder.clearCallingIdentity(); |
| 3524 | try { |
| 3525 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 3526 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3527 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3528 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 3529 | return success; |
| 3530 | } finally { |
| 3531 | Binder.restoreCallingIdentity(identity); |
| 3532 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | /** |
| 3536 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 3537 | * Used for device configuration by some CDMA operators. |
| 3538 | * |
| 3539 | * @param preferredRoamingList byte array containing the new PRL |
| 3540 | * @return true on success; false on any failure |
| 3541 | */ |
| 3542 | @Override |
| 3543 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3544 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3545 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3546 | |
| 3547 | final long identity = Binder.clearCallingIdentity(); |
| 3548 | try { |
| 3549 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 3550 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 3551 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 3552 | return success; |
| 3553 | } finally { |
| 3554 | Binder.restoreCallingIdentity(identity); |
| 3555 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3556 | } |
| 3557 | |
| 3558 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3559 | * 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] | 3560 | * Used for device configuration by some CDMA operators. |
| 3561 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3562 | * @param slotIndex - device slot. |
| 3563 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3564 | * @return true on success; false on any failure |
| 3565 | */ |
| 3566 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3567 | public boolean resetModemConfig(int slotIndex) { |
| 3568 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3569 | if (phone != null) { |
| 3570 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3571 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3572 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3573 | final long identity = Binder.clearCallingIdentity(); |
| 3574 | try { |
| 3575 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 3576 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 3577 | return success; |
| 3578 | } finally { |
| 3579 | Binder.restoreCallingIdentity(identity); |
| 3580 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3581 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3582 | return false; |
| 3583 | } |
| 3584 | |
| 3585 | /** |
| 3586 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 3587 | * |
| 3588 | * @param slotIndex - device slot. |
| 3589 | * |
| 3590 | * @return true on success; false on any failure |
| 3591 | */ |
| 3592 | @Override |
| 3593 | public boolean rebootModem(int slotIndex) { |
| 3594 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3595 | if (phone != null) { |
| 3596 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3597 | mApp, phone.getSubId(), "rebootModem"); |
| 3598 | |
| 3599 | final long identity = Binder.clearCallingIdentity(); |
| 3600 | try { |
| 3601 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 3602 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 3603 | return success; |
| 3604 | } finally { |
| 3605 | Binder.restoreCallingIdentity(identity); |
| 3606 | } |
| 3607 | } |
| 3608 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3609 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3610 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3611 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3612 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3613 | mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3614 | return new String[0]; |
| 3615 | } |
| 3616 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3617 | final long identity = Binder.clearCallingIdentity(); |
| 3618 | try { |
| 3619 | return mPhone.getPcscfAddress(apnType); |
| 3620 | } finally { |
| 3621 | Binder.restoreCallingIdentity(identity); |
| 3622 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3623 | } |
| 3624 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3625 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3626 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 3627 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3628 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3629 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3630 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3631 | |
| 3632 | final long identity = Binder.clearCallingIdentity(); |
| 3633 | try { |
| 3634 | PhoneFactory.getImsResolver().enableIms(slotId); |
| 3635 | } finally { |
| 3636 | Binder.restoreCallingIdentity(identity); |
| 3637 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3638 | } |
| 3639 | |
| 3640 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3641 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 3642 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3643 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3644 | public void disableIms(int slotId) { |
| 3645 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3646 | |
| 3647 | final long identity = Binder.clearCallingIdentity(); |
| 3648 | try { |
| 3649 | PhoneFactory.getImsResolver().disableIms(slotId); |
| 3650 | } finally { |
| 3651 | Binder.restoreCallingIdentity(identity); |
| 3652 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | /** |
| 3656 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 3657 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 3658 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 3659 | */ |
| 3660 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3661 | IImsServiceFeatureCallback callback) { |
| 3662 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3663 | |
| 3664 | final long identity = Binder.clearCallingIdentity(); |
| 3665 | try { |
| 3666 | return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback); |
| 3667 | } finally { |
| 3668 | Binder.restoreCallingIdentity(identity); |
| 3669 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | /** |
| 3673 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 3674 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 3675 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 3676 | * listener for feature updates. |
| 3677 | */ |
| 3678 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 3679 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3680 | |
| 3681 | final long identity = Binder.clearCallingIdentity(); |
| 3682 | try { |
| 3683 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); |
| 3684 | } finally { |
| 3685 | Binder.restoreCallingIdentity(identity); |
| 3686 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3687 | } |
| 3688 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3689 | /** |
| 3690 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| 3691 | * specified. |
| 3692 | */ |
| 3693 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 3694 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3695 | |
| 3696 | final long identity = Binder.clearCallingIdentity(); |
| 3697 | try { |
| 3698 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); |
| 3699 | } finally { |
| 3700 | Binder.restoreCallingIdentity(identity); |
| 3701 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3702 | } |
| 3703 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3704 | /** |
| 3705 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| 3706 | * specified. |
| 3707 | */ |
| 3708 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 3709 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3710 | |
| 3711 | final long identity = Binder.clearCallingIdentity(); |
| 3712 | try { |
| 3713 | return PhoneFactory.getImsResolver().getImsConfig(slotId, feature); |
| 3714 | } finally { |
| 3715 | Binder.restoreCallingIdentity(identity); |
| 3716 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3717 | } |
| 3718 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 3719 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3720 | * Sets the ImsService Package Name that Telephony will bind to. |
| 3721 | * |
| 3722 | * @param slotId the slot ID that the ImsService should bind for. |
| 3723 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 3724 | * ImsService is the device default ImsService. |
| 3725 | * @param packageName The package name of the application that contains the ImsService to bind |
| 3726 | * to. |
| 3727 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 3728 | * @hide |
| 3729 | */ |
| 3730 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3731 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3732 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3733 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3734 | "setImsService"); |
| 3735 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3736 | final long identity = Binder.clearCallingIdentity(); |
| 3737 | try { |
| 3738 | return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId, |
| 3739 | isCarrierImsService, packageName); |
| 3740 | } finally { |
| 3741 | Binder.restoreCallingIdentity(identity); |
| 3742 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | /** |
| 3746 | * Return the ImsService configuration. |
| 3747 | * |
| 3748 | * @param slotId The slot that the ImsService is associated with. |
| 3749 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 3750 | * the device default. |
| 3751 | * @return the package name of the ImsService configuration. |
| 3752 | */ |
| 3753 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3754 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3755 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3756 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3757 | "getImsService"); |
| 3758 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3759 | final long identity = Binder.clearCallingIdentity(); |
| 3760 | try { |
| 3761 | return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId, |
| 3762 | isCarrierImsService); |
| 3763 | } finally { |
| 3764 | Binder.restoreCallingIdentity(identity); |
| 3765 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3766 | } |
| 3767 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3768 | public void setImsRegistrationState(boolean registered) { |
| 3769 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3770 | |
| 3771 | final long identity = Binder.clearCallingIdentity(); |
| 3772 | try { |
| 3773 | mPhone.setImsRegistrationState(registered); |
| 3774 | } finally { |
| 3775 | Binder.restoreCallingIdentity(identity); |
| 3776 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3780 | * Set the network selection mode to automatic. |
| 3781 | * |
| 3782 | */ |
| 3783 | @Override |
| 3784 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3785 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3786 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3787 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3788 | if (!isActiveSubscription(subId)) { |
| 3789 | return; |
| 3790 | } |
| 3791 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3792 | final long identity = Binder.clearCallingIdentity(); |
| 3793 | try { |
| 3794 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 3795 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 3796 | } finally { |
| 3797 | Binder.restoreCallingIdentity(identity); |
| 3798 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3799 | } |
| 3800 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3801 | /** |
| 3802 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 3803 | * |
| 3804 | * @param subId the id of the subscription. |
| 3805 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 3806 | * the operator to attach to. |
| 3807 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 3808 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 3809 | * normal network selection next time. |
| 3810 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3811 | */ |
| 3812 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3813 | public boolean setNetworkSelectionModeManual( |
| 3814 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3815 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3816 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3817 | |
| 3818 | if (!isActiveSubscription(subId)) { |
| 3819 | return false; |
| 3820 | } |
| 3821 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3822 | final long identity = Binder.clearCallingIdentity(); |
| 3823 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3824 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3825 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3826 | if (DBG) { |
| 3827 | log("setNetworkSelectionModeManual: subId: " + subId |
| 3828 | + " operator: " + operatorInfo); |
| 3829 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3830 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 3831 | } finally { |
| 3832 | Binder.restoreCallingIdentity(identity); |
| 3833 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3834 | } |
| 3835 | |
| 3836 | /** |
| 3837 | * Scans for available networks. |
| 3838 | */ |
| 3839 | @Override |
| 3840 | public CellNetworkScanResult getCellNetworkScanResults(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3841 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3842 | mApp, subId, "getCellNetworkScanResults"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3843 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3844 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3845 | try { |
| 3846 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3847 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3848 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3849 | } finally { |
| 3850 | Binder.restoreCallingIdentity(identity); |
| 3851 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3852 | } |
| 3853 | |
| 3854 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3855 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3856 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3857 | * @param subId id of the subscription |
| 3858 | * @param request contains the radio access networks with bands/channels to scan |
| 3859 | * @param messenger callback messenger for scan results or errors |
| 3860 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3861 | * @return the id of the requested scan which can be used to stop the scan. |
| 3862 | */ |
| 3863 | @Override |
| 3864 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
| 3865 | IBinder binder) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3866 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3867 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3868 | |
| 3869 | final long identity = Binder.clearCallingIdentity(); |
| 3870 | try { |
| 3871 | return mNetworkScanRequestTracker.startNetworkScan( |
| 3872 | request, messenger, binder, getPhone(subId)); |
| 3873 | } finally { |
| 3874 | Binder.restoreCallingIdentity(identity); |
| 3875 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3876 | } |
| 3877 | |
| 3878 | /** |
| 3879 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3880 | * |
| 3881 | * @param subId id of the subscription |
| 3882 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3883 | */ |
| 3884 | @Override |
| 3885 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3886 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3887 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3888 | |
| 3889 | final long identity = Binder.clearCallingIdentity(); |
| 3890 | try { |
| 3891 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 3892 | } finally { |
| 3893 | Binder.restoreCallingIdentity(identity); |
| 3894 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
| 3897 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3898 | * Get the calculated preferred network type. |
| 3899 | * Used for debugging incorrect network type. |
| 3900 | * |
| 3901 | * @return the preferred network type, defined in RILConstants.java. |
| 3902 | */ |
| 3903 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3904 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3905 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3906 | mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3907 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 3908 | } |
| 3909 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3910 | final long identity = Binder.clearCallingIdentity(); |
| 3911 | try { |
| 3912 | // FIXME: need to get SubId from somewhere. |
| 3913 | return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); |
| 3914 | } finally { |
| 3915 | Binder.restoreCallingIdentity(identity); |
| 3916 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3920 | * Get the preferred network type. |
| 3921 | * Used for device configuration by some CDMA operators. |
| 3922 | * |
| 3923 | * @return the preferred network type, defined in RILConstants.java. |
| 3924 | */ |
| 3925 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3926 | public int getPreferredNetworkType(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3927 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3928 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3929 | |
| 3930 | final long identity = Binder.clearCallingIdentity(); |
| 3931 | try { |
| 3932 | if (DBG) log("getPreferredNetworkType"); |
| 3933 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 3934 | int networkType = (result != null ? result[0] : -1); |
| 3935 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 3936 | return networkType; |
| 3937 | } finally { |
| 3938 | Binder.restoreCallingIdentity(identity); |
| 3939 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3940 | } |
| 3941 | |
| 3942 | /** |
| 3943 | * Set the preferred network type. |
| 3944 | * Used for device configuration by some CDMA operators. |
| 3945 | * |
| 3946 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 3947 | * @return true on success; false on any failure. |
| 3948 | */ |
| 3949 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3950 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3951 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3952 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3953 | |
| 3954 | final long identity = Binder.clearCallingIdentity(); |
| 3955 | try { |
| 3956 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 3957 | Boolean success = (Boolean) sendRequest( |
| 3958 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 3959 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 3960 | if (success) { |
| 3961 | Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
| 3962 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 3963 | } |
| 3964 | return success; |
| 3965 | } finally { |
| 3966 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 3967 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3968 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 3969 | |
| 3970 | /** |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 3971 | * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 3972 | * SystemProperty to decide whether DUN APN is required for |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 3973 | * tethering. |
| 3974 | * |
| 3975 | * @return 0: Not required. 1: required. 2: Not set. |
| 3976 | * @hide |
| 3977 | */ |
| 3978 | @Override |
| 3979 | public int getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3980 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3981 | |
| 3982 | final long identity = Binder.clearCallingIdentity(); |
| 3983 | try { |
| 3984 | int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(), |
| 3985 | Settings.Global.TETHER_DUN_REQUIRED, 2); |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 3986 | // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3987 | if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) { |
| 3988 | dunRequired = 1; |
| 3989 | } |
| 3990 | return dunRequired; |
| 3991 | } finally { |
| 3992 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 3993 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 3994 | } |
| 3995 | |
| 3996 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 3997 | * Set mobile data enabled |
| 3998 | * Used by the user through settings etc to turn on/off mobile data |
| 3999 | * |
| 4000 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4001 | */ |
| 4002 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4003 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4004 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4005 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4006 | |
| 4007 | final long identity = Binder.clearCallingIdentity(); |
| 4008 | try { |
| 4009 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4010 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4011 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4012 | if (phone != null) { |
| 4013 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
| 4014 | phone.setUserDataEnabled(enable); |
| 4015 | } else { |
| 4016 | loge("setUserDataEnabled: no phone for subId=" + subId); |
| 4017 | } |
| 4018 | } finally { |
| 4019 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4020 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4024 | * Get the user enabled state of Mobile Data. |
| 4025 | * |
| 4026 | * TODO: remove and use isUserDataEnabled. |
| 4027 | * This can't be removed now because some vendor codes |
| 4028 | * calls through ITelephony directly while they should |
| 4029 | * use TelephonyManager. |
| 4030 | * |
| 4031 | * @return true on enabled |
| 4032 | */ |
| 4033 | @Override |
| 4034 | public boolean getDataEnabled(int subId) { |
| 4035 | return isUserDataEnabled(subId); |
| 4036 | } |
| 4037 | |
| 4038 | /** |
| 4039 | * Get whether mobile data is enabled per user setting. |
| 4040 | * |
| 4041 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4042 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4043 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4044 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4045 | * |
| 4046 | * @return {@code true} if data is enabled else {@code false} |
| 4047 | */ |
| 4048 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4049 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4050 | try { |
| 4051 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4052 | null); |
| 4053 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4054 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4055 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4056 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4057 | |
| 4058 | final long identity = Binder.clearCallingIdentity(); |
| 4059 | try { |
| 4060 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4061 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4062 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4063 | if (phone != null) { |
| 4064 | boolean retVal = phone.isUserDataEnabled(); |
| 4065 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4066 | return retVal; |
| 4067 | } else { |
| 4068 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4069 | return false; |
| 4070 | } |
| 4071 | } finally { |
| 4072 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4073 | } |
| 4074 | } |
| 4075 | |
| 4076 | /** |
| 4077 | * Get whether mobile data is enabled. |
| 4078 | * |
| 4079 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4080 | * whether mobile data is actually enabled. |
| 4081 | * |
| 4082 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4083 | * |
| 4084 | * @return {@code true} if data is enabled else {@code false} |
| 4085 | */ |
| 4086 | @Override |
| 4087 | public boolean isDataEnabled(int subId) { |
| 4088 | try { |
| 4089 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4090 | null); |
| 4091 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4092 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4093 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4094 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4095 | |
| 4096 | final long identity = Binder.clearCallingIdentity(); |
| 4097 | try { |
| 4098 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4099 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4100 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4101 | if (phone != null) { |
| 4102 | boolean retVal = phone.isDataEnabled(); |
| 4103 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4104 | return retVal; |
| 4105 | } else { |
| 4106 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4107 | return false; |
| 4108 | } |
| 4109 | } finally { |
| 4110 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4111 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4112 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4113 | |
| 4114 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4115 | public int getCarrierPrivilegeStatus(int subId) { |
| 4116 | final Phone phone = getPhone(subId); |
| 4117 | if (phone == null) { |
| 4118 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4119 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4120 | } |
| 4121 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4122 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4123 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4124 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4125 | } |
| 4126 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4127 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4128 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4129 | |
| 4130 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4131 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4132 | final Phone phone = getPhone(subId); |
| 4133 | if (phone == null) { |
| 4134 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4135 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4136 | } |
| 4137 | UiccProfile profile = |
| 4138 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4139 | if (profile == null) { |
| 4140 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4141 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4142 | } |
| 4143 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4144 | } |
| 4145 | |
| 4146 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4147 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4148 | if (TextUtils.isEmpty(pkgName)) |
| 4149 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Shishir Agrawal | 2140925 | 2015-01-15 23:33:50 -0800 | [diff] [blame] | 4150 | UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4151 | if (card == null) { |
| 4152 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4153 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4154 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4155 | return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName); |
| 4156 | } |
| 4157 | |
| 4158 | @Override |
| 4159 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4160 | if (TextUtils.isEmpty(pkgName)) |
| 4161 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4162 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4163 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4164 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4165 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4166 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4167 | continue; |
| 4168 | } |
| 4169 | |
| 4170 | result = card.getCarrierPrivilegeStatus( |
| 4171 | mPhone.getContext().getPackageManager(), pkgName); |
| 4172 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4173 | break; |
| 4174 | } |
| 4175 | } |
| 4176 | |
| 4177 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4178 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4179 | |
| 4180 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4181 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4182 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4183 | loge("phoneId " + phoneId + " is not valid."); |
| 4184 | return null; |
| 4185 | } |
| 4186 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4187 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4188 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4189 | return null ; |
| 4190 | } |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4191 | return card.getCarrierPackageNamesForIntent( |
Svetoslav | 483aff7 | 2015-04-21 14:16:07 -0700 | [diff] [blame] | 4192 | mPhone.getContext().getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4193 | } |
| 4194 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4195 | @Override |
| 4196 | public List<String> getPackagesWithCarrierPrivileges() { |
| 4197 | PackageManager pm = mPhone.getContext().getPackageManager(); |
| 4198 | List<String> privilegedPackages = new ArrayList<>(); |
| 4199 | List<PackageInfo> packages = null; |
| 4200 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4201 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4202 | if (card == null) { |
| 4203 | // No UICC in that slot. |
| 4204 | continue; |
| 4205 | } |
| 4206 | if (card.hasCarrierPrivilegeRules()) { |
| 4207 | if (packages == null) { |
| 4208 | // Only check packages in user 0 for now |
| 4209 | packages = pm.getInstalledPackagesAsUser( |
| 4210 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4211 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4212 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4213 | } |
| 4214 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4215 | PackageInfo pkgInfo = packages.get(p); |
| 4216 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4217 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4218 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4219 | privilegedPackages.add(pkgInfo.packageName); |
| 4220 | } |
| 4221 | } |
| 4222 | } |
| 4223 | } |
| 4224 | return privilegedPackages; |
| 4225 | } |
| 4226 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4227 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4228 | final Phone phone = getPhone(subId); |
| 4229 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4230 | if (card == null) { |
| 4231 | loge("getIccId: No UICC"); |
| 4232 | return null; |
| 4233 | } |
| 4234 | String iccId = card.getIccId(); |
| 4235 | if (TextUtils.isEmpty(iccId)) { |
| 4236 | loge("getIccId: ICC ID is null or empty."); |
| 4237 | return null; |
| 4238 | } |
| 4239 | return iccId; |
| 4240 | } |
| 4241 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4242 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4243 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4244 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4245 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4246 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4247 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4248 | final long identity = Binder.clearCallingIdentity(); |
| 4249 | try { |
| 4250 | final String iccId = getIccId(subId); |
| 4251 | final Phone phone = getPhone(subId); |
| 4252 | if (phone == null) { |
| 4253 | return false; |
| 4254 | } |
| 4255 | final String subscriberId = phone.getSubscriberId(); |
| 4256 | |
| 4257 | if (DBG_MERGE) { |
| 4258 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4259 | + subscriberId + " to " + number); |
| 4260 | } |
| 4261 | |
| 4262 | if (TextUtils.isEmpty(iccId)) { |
| 4263 | return false; |
| 4264 | } |
| 4265 | |
| 4266 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4267 | |
| 4268 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4269 | if (alphaTag == null) { |
| 4270 | editor.remove(alphaTagPrefKey); |
| 4271 | } else { |
| 4272 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4273 | } |
| 4274 | |
| 4275 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4276 | // track all merged IMSIs based on line number |
| 4277 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4278 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4279 | if (number == null) { |
| 4280 | editor.remove(numberPrefKey); |
| 4281 | editor.remove(subscriberPrefKey); |
| 4282 | } else { |
| 4283 | editor.putString(numberPrefKey, number); |
| 4284 | editor.putString(subscriberPrefKey, subscriberId); |
| 4285 | } |
| 4286 | |
| 4287 | editor.commit(); |
| 4288 | return true; |
| 4289 | } finally { |
| 4290 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4291 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4292 | } |
| 4293 | |
| 4294 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4295 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4296 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4297 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4298 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4299 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4300 | return null; |
| 4301 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4302 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4303 | final long identity = Binder.clearCallingIdentity(); |
| 4304 | try { |
| 4305 | String iccId = getIccId(subId); |
| 4306 | if (iccId != null) { |
| 4307 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4308 | if (DBG_MERGE) { |
| 4309 | log("getLine1NumberForDisplay returning " |
| 4310 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4311 | } |
| 4312 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4313 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4314 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4315 | return null; |
| 4316 | } finally { |
| 4317 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4318 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4322 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4323 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4324 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4325 | return null; |
| 4326 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4327 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4328 | final long identity = Binder.clearCallingIdentity(); |
| 4329 | try { |
| 4330 | String iccId = getIccId(subId); |
| 4331 | if (iccId != null) { |
| 4332 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4333 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4334 | } |
| 4335 | return null; |
| 4336 | } finally { |
| 4337 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4338 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4339 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4340 | |
| 4341 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4342 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4343 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4344 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4345 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4346 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4347 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4348 | return null; |
| 4349 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4350 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4351 | final long identity = Binder.clearCallingIdentity(); |
| 4352 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4353 | final Context context = mPhone.getContext(); |
| 4354 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4355 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4356 | |
| 4357 | // Figure out what subscribers are currently active |
| 4358 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4359 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4360 | // the process, where TelephonyManager was instantiated. |
| 4361 | // Otherwise AppOps check will fail. |
| 4362 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4363 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4364 | for (int subId : subIds) { |
| 4365 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4366 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4367 | |
| 4368 | // First pass, find a number override for an active subscriber |
| 4369 | String mergeNumber = null; |
| 4370 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4371 | for (String key : prefs.keySet()) { |
| 4372 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4373 | final String subscriberId = (String) prefs.get(key); |
| 4374 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4375 | final String iccId = key.substring( |
| 4376 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4377 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4378 | mergeNumber = (String) prefs.get(numberKey); |
| 4379 | if (DBG_MERGE) { |
| 4380 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4381 | + " for active subscriber " + subscriberId); |
| 4382 | } |
| 4383 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4384 | break; |
| 4385 | } |
| 4386 | } |
| 4387 | } |
| 4388 | } |
| 4389 | |
| 4390 | // Shortcut when no active merged subscribers |
| 4391 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4392 | return null; |
| 4393 | } |
| 4394 | |
| 4395 | // Second pass, find all subscribers under that line override |
| 4396 | final ArraySet<String> result = new ArraySet<>(); |
| 4397 | for (String key : prefs.keySet()) { |
| 4398 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4399 | final String number = (String) prefs.get(key); |
| 4400 | if (mergeNumber.equals(number)) { |
| 4401 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4402 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4403 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4404 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4405 | result.add(subscriberId); |
| 4406 | } |
| 4407 | } |
| 4408 | } |
| 4409 | } |
| 4410 | |
| 4411 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4412 | Arrays.sort(resultArray); |
| 4413 | if (DBG_MERGE) { |
| 4414 | Slog.d(LOG_TAG, |
| 4415 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4416 | } |
| 4417 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4418 | } finally { |
| 4419 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4420 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4424 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4425 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4426 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4427 | |
| 4428 | final long identity = Binder.clearCallingIdentity(); |
| 4429 | try { |
| 4430 | final Phone phone = getPhone(subId); |
| 4431 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4432 | } finally { |
| 4433 | Binder.restoreCallingIdentity(identity); |
| 4434 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4435 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4436 | |
| 4437 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4438 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4439 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 4440 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4441 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4442 | |
| 4443 | final long identity = Binder.clearCallingIdentity(); |
| 4444 | try { |
| 4445 | final Phone phone = getPhone(subId); |
| 4446 | if (phone == null) { |
| 4447 | return false; |
| 4448 | } |
| 4449 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 4450 | cdmaNonRoamingList); |
| 4451 | } finally { |
| 4452 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4453 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4454 | } |
| 4455 | |
| 4456 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4457 | @Deprecated |
| 4458 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 4459 | enforceModifyPermission(); |
| 4460 | |
| 4461 | int returnValue = 0; |
| 4462 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4463 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4464 | if(result.exception == null) { |
| 4465 | if (result.result != null) { |
| 4466 | byte[] responseData = (byte[])(result.result); |
| 4467 | if(responseData.length > oemResp.length) { |
| 4468 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 4469 | responseData.length + "bytes. Buffer Size is " + |
| 4470 | oemResp.length + "bytes."); |
| 4471 | } |
| 4472 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 4473 | returnValue = responseData.length; |
| 4474 | } |
| 4475 | } else { |
| 4476 | CommandException ex = (CommandException) result.exception; |
| 4477 | returnValue = ex.getCommandError().ordinal(); |
| 4478 | if(returnValue > 0) returnValue *= -1; |
| 4479 | } |
| 4480 | } catch (RuntimeException e) { |
| 4481 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 4482 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 4483 | if(returnValue > 0) returnValue *= -1; |
| 4484 | } |
| 4485 | |
| 4486 | return returnValue; |
| 4487 | } |
| 4488 | |
| 4489 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4490 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 4491 | try { |
| 4492 | ProxyController.getInstance().setRadioCapability(rafs); |
| 4493 | } catch (RuntimeException e) { |
| 4494 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 4495 | } |
| 4496 | } |
| 4497 | |
| 4498 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4499 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4500 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4501 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4502 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4503 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4504 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4505 | final long identity = Binder.clearCallingIdentity(); |
| 4506 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4507 | TelephonyPermissions |
| 4508 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4509 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 4510 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4511 | } finally { |
| 4512 | Binder.restoreCallingIdentity(identity); |
| 4513 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4514 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4515 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4516 | |
| 4517 | @Override |
| 4518 | public void enableVideoCalling(boolean enable) { |
| 4519 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4520 | |
| 4521 | final long identity = Binder.clearCallingIdentity(); |
| 4522 | try { |
| 4523 | ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable); |
| 4524 | } finally { |
| 4525 | Binder.restoreCallingIdentity(identity); |
| 4526 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4530 | public boolean isVideoCallingEnabled(String callingPackage) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4531 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4532 | mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
| 4533 | return false; |
| 4534 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4535 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4536 | final long identity = Binder.clearCallingIdentity(); |
| 4537 | try { |
| 4538 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 4539 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 4540 | // In the long run, we may instead need to check if there exists a connection service |
| 4541 | // which can support video calling. |
| 4542 | ImsManager imsManager = |
| 4543 | ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()); |
| 4544 | return imsManager.isVtEnabledByPlatform() |
| 4545 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 4546 | && imsManager.isVtEnabledByUser(); |
| 4547 | } finally { |
| 4548 | Binder.restoreCallingIdentity(identity); |
| 4549 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4550 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 4551 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4552 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4553 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 4554 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4555 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4556 | return false; |
| 4557 | } |
| 4558 | |
| 4559 | final long identity = Binder.clearCallingIdentity(); |
| 4560 | try { |
| 4561 | CarrierConfigManager configManager = |
| 4562 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 4563 | return configManager.getConfigForSubId(mPhone.getSubId()) |
| 4564 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 4565 | } finally { |
| 4566 | Binder.restoreCallingIdentity(identity); |
| 4567 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4568 | } |
| 4569 | |
| 4570 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4571 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 4572 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4573 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4574 | return false; |
| 4575 | } |
| 4576 | |
| 4577 | final long identity = Binder.clearCallingIdentity(); |
| 4578 | try { |
| 4579 | CarrierConfigManager configManager = |
| 4580 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 4581 | return configManager.getConfigForSubId(mPhone.getSubId()) |
| 4582 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 4583 | } finally { |
| 4584 | Binder.restoreCallingIdentity(identity); |
| 4585 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4586 | } |
| 4587 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4588 | @Override |
| 4589 | public boolean isTtyModeSupported() { |
| 4590 | TelecomManager telecomManager = TelecomManager.from(mPhone.getContext()); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 4591 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4592 | } |
| 4593 | |
| 4594 | @Override |
| 4595 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4596 | final long identity = Binder.clearCallingIdentity(); |
| 4597 | try { |
| 4598 | return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled); |
| 4599 | } finally { |
| 4600 | Binder.restoreCallingIdentity(identity); |
| 4601 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4602 | } |
| 4603 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4604 | /** |
| 4605 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 4606 | * support for the feature and device firmware support. |
| 4607 | * |
| 4608 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 4609 | */ |
| 4610 | @Override |
| 4611 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4612 | final long identity = Binder.clearCallingIdentity(); |
| 4613 | try { |
| 4614 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId( |
| 4615 | mPhone.getSubId()).getBoolean( |
| 4616 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 4617 | boolean isDeviceSupported = |
| 4618 | mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
| 4619 | return isCarrierSupported && isDeviceSupported; |
| 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(identity); |
| 4622 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 4623 | } |
| 4624 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4625 | /** |
| 4626 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 4627 | * both also support RTT. |
| 4628 | */ |
| 4629 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4630 | final long identity = Binder.clearCallingIdentity(); |
| 4631 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4632 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4633 | mPhone.getContext().getContentResolver(), |
| 4634 | Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 4635 | } finally { |
| 4636 | Binder.restoreCallingIdentity(identity); |
| 4637 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 4638 | } |
| 4639 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4640 | /** |
| 4641 | * Returns the unique device ID of phone, for example, the IMEI for |
| 4642 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 4643 | * |
| 4644 | * <p>Requires Permission: |
| 4645 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 4646 | */ |
| 4647 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4648 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4649 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4650 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4651 | return null; |
| 4652 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4653 | int subId = phone.getSubId(); |
| 4654 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4655 | mApp, subId, callingPackage, "getDeviceId")) { |
| 4656 | return null; |
| 4657 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4658 | |
| 4659 | final long identity = Binder.clearCallingIdentity(); |
| 4660 | try { |
| 4661 | return phone.getDeviceId(); |
| 4662 | } finally { |
| 4663 | Binder.restoreCallingIdentity(identity); |
| 4664 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4665 | } |
| 4666 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4667 | /** |
| 4668 | * {@hide} |
| 4669 | * Returns the IMS Registration Status on a particular subid |
| 4670 | * |
| 4671 | * @param subId |
| 4672 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4673 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4674 | Phone phone = getPhone(subId); |
| 4675 | if (phone != null) { |
| 4676 | return phone.isImsRegistered(); |
| 4677 | } else { |
| 4678 | return false; |
| 4679 | } |
| 4680 | } |
| 4681 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4682 | @Override |
| 4683 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4684 | final long identity = Binder.clearCallingIdentity(); |
| 4685 | try { |
| 4686 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 4687 | } finally { |
| 4688 | Binder.restoreCallingIdentity(identity); |
| 4689 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4690 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 4691 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4692 | /** |
| 4693 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4694 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4695 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4696 | final long identity = Binder.clearCallingIdentity(); |
| 4697 | try { |
| 4698 | Phone phone = getPhone(subId); |
| 4699 | if (phone != null) { |
| 4700 | return phone.isWifiCallingEnabled(); |
| 4701 | } else { |
| 4702 | return false; |
| 4703 | } |
| 4704 | } finally { |
| 4705 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4706 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4707 | } |
| 4708 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4709 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4710 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4711 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4712 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4713 | final long identity = Binder.clearCallingIdentity(); |
| 4714 | try { |
| 4715 | Phone phone = getPhone(subId); |
| 4716 | if (phone != null) { |
| 4717 | return phone.isVideoEnabled(); |
| 4718 | } else { |
| 4719 | return false; |
| 4720 | } |
| 4721 | } finally { |
| 4722 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4723 | } |
| 4724 | } |
| 4725 | |
| 4726 | /** |
| 4727 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 4728 | * defined in {@link ImsRegistrationImplBase}. |
| 4729 | */ |
| 4730 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4731 | final long identity = Binder.clearCallingIdentity(); |
| 4732 | try { |
| 4733 | Phone phone = getPhone(subId); |
| 4734 | if (phone != null) { |
| 4735 | return phone.getImsRegistrationTech(); |
| 4736 | } else { |
| 4737 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 4738 | } |
| 4739 | } finally { |
| 4740 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4741 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4742 | } |
| 4743 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4744 | @Override |
| 4745 | public void factoryReset(int subId) { |
| 4746 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4747 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 4748 | return; |
| 4749 | } |
| 4750 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4751 | final long identity = Binder.clearCallingIdentity(); |
| 4752 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4753 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 4754 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4755 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4756 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4757 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
| 4758 | mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId)); |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 4759 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4760 | } |
| 4761 | } finally { |
| 4762 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4763 | } |
| 4764 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4765 | |
| 4766 | @Override |
| 4767 | public String getLocaleFromDefaultSim() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4768 | final long identity = Binder.clearCallingIdentity(); |
| 4769 | try { |
| 4770 | // We query all subscriptions instead of just the active ones, because |
| 4771 | // this might be called early on in the provisioning flow when the |
| 4772 | // subscriptions potentially aren't active yet. |
| 4773 | final List<SubscriptionInfo> slist = getAllSubscriptionInfoList(); |
| 4774 | if (slist == null || slist.isEmpty()) { |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4775 | return null; |
| 4776 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4777 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4778 | // This function may be called very early, say, from the setup wizard, at |
| 4779 | // which point we won't have a default subscription set. If that's the case |
| 4780 | // we just choose the first, which will be valid in "most cases". |
| 4781 | final int defaultSubId = getDefaultSubscription(); |
| 4782 | SubscriptionInfo info = null; |
| 4783 | if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 4784 | info = slist.get(0); |
| 4785 | } else { |
| 4786 | for (SubscriptionInfo item : slist) { |
| 4787 | if (item.getSubscriptionId() == defaultSubId) { |
| 4788 | info = item; |
| 4789 | break; |
| 4790 | } |
| 4791 | } |
| 4792 | |
| 4793 | if (info == null) { |
| 4794 | return null; |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 4795 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4796 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4797 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4798 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 4799 | // preferences (EF-PL and EF-LI)... |
| 4800 | final int mcc = info.getMcc(); |
| 4801 | final Phone defaultPhone = getPhone(info.getSubscriptionId()); |
| 4802 | String simLanguage = null; |
| 4803 | if (defaultPhone != null) { |
| 4804 | final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs(); |
| 4805 | if (localeFromDefaultSim != null) { |
| 4806 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 4807 | if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim); |
| 4808 | return localeFromDefaultSim.toLanguageTag(); |
| 4809 | } else { |
| 4810 | simLanguage = localeFromDefaultSim.getLanguage(); |
| 4811 | } |
| 4812 | } |
| 4813 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4814 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4815 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 4816 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 4817 | // the SIM and carrier preferences does not include a country we add the country |
| 4818 | // determined from the SIM MCC to provide an exact locale. |
| 4819 | final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, |
| 4820 | simLanguage); |
| 4821 | if (mccLocale != null) { |
| 4822 | if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale); |
| 4823 | return mccLocale.toLanguageTag(); |
| 4824 | } |
| 4825 | |
| 4826 | if (DBG) log("No locale found - returning null"); |
| 4827 | return null; |
| 4828 | } finally { |
| 4829 | Binder.restoreCallingIdentity(identity); |
| 4830 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4831 | } |
| 4832 | |
| 4833 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4834 | return mSubscriptionController.getAllSubInfoList( |
| 4835 | mPhone.getContext().getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4836 | } |
| 4837 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4838 | /** |
| 4839 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 4840 | */ |
| 4841 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
| 4842 | return mSubscriptionController.getActiveSubscriptionInfoList( |
| 4843 | mPhone.getContext().getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4844 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4845 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4846 | private final ModemActivityInfo mLastModemActivityInfo = |
| 4847 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 4848 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4849 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4850 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 4851 | * representing the state of the modem. |
| 4852 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4853 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 4854 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4855 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4856 | */ |
| 4857 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4858 | public void requestModemActivityInfo(ResultReceiver result) { |
| 4859 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4860 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4861 | |
| 4862 | final long identity = Binder.clearCallingIdentity(); |
| 4863 | try { |
| 4864 | ModemActivityInfo ret = null; |
| 4865 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4866 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 4867 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 4868 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4869 | if (isModemActivityInfoValid(info)) { |
| 4870 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 4871 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 4872 | mergedTxTimeMs[i] = |
| 4873 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 4874 | } |
| 4875 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 4876 | mLastModemActivityInfo.setSleepTimeMillis( |
| 4877 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 4878 | mLastModemActivityInfo.setIdleTimeMillis( |
| 4879 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 4880 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 4881 | mLastModemActivityInfo.setRxTimeMillis( |
| 4882 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 4883 | mLastModemActivityInfo.setEnergyUsed( |
| 4884 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4885 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4886 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 4887 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 4888 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 4889 | mLastModemActivityInfo.getTxTimeMillis(), |
| 4890 | mLastModemActivityInfo.getRxTimeMillis(), |
| 4891 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4892 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4893 | Bundle bundle = new Bundle(); |
| 4894 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 4895 | result.send(0, bundle); |
| 4896 | } finally { |
| 4897 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4898 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4899 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4900 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 4901 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 4902 | // less than total activity duration. |
| 4903 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 4904 | if (info == null) { |
| 4905 | return false; |
| 4906 | } |
| 4907 | int activityDurationMs = |
| 4908 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 4909 | int totalTxTimeMs = 0; |
| 4910 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 4911 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 4912 | } |
| 4913 | return (info.isValid() |
| 4914 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 4915 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 4916 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 4917 | && (totalTxTimeMs <= activityDurationMs)); |
| 4918 | } |
| 4919 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4920 | /** |
| 4921 | * {@hide} |
| 4922 | * Returns the service state information on specified subscription. |
| 4923 | */ |
| 4924 | @Override |
| 4925 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4926 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4927 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4928 | return null; |
| 4929 | } |
| 4930 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4931 | final long identity = Binder.clearCallingIdentity(); |
| 4932 | try { |
| 4933 | final Phone phone = getPhone(subId); |
| 4934 | if (phone == null) { |
| 4935 | return null; |
| 4936 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4937 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4938 | return phone.getServiceState(); |
| 4939 | } finally { |
| 4940 | Binder.restoreCallingIdentity(identity); |
| 4941 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4942 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4943 | |
| 4944 | /** |
| 4945 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 4946 | * |
| 4947 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 4948 | * voicemail ringtone. |
| 4949 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 4950 | * PhoneAccount. |
| 4951 | */ |
| 4952 | @Override |
| 4953 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4954 | final long identity = Binder.clearCallingIdentity(); |
| 4955 | try { |
| 4956 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 4957 | if (phone == null) { |
| 4958 | phone = mPhone; |
| 4959 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4960 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4961 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 4962 | } finally { |
| 4963 | Binder.restoreCallingIdentity(identity); |
| 4964 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4965 | } |
| 4966 | |
| 4967 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4968 | * Sets the per-account voicemail ringtone. |
| 4969 | * |
| 4970 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 4971 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 4972 | * |
| 4973 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 4974 | * voicemail ringtone. |
| 4975 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 4976 | * PhoneAccount. |
| 4977 | */ |
| 4978 | @Override |
| 4979 | public void setVoicemailRingtoneUri(String callingPackage, |
| 4980 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
| 4981 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4982 | if (!TextUtils.equals(callingPackage, |
| 4983 | TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4984 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4985 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 4986 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4987 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4988 | |
| 4989 | final long identity = Binder.clearCallingIdentity(); |
| 4990 | try { |
| 4991 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 4992 | if (phone == null) { |
| 4993 | phone = mPhone; |
| 4994 | } |
| 4995 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 4996 | } finally { |
| 4997 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4998 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5002 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5003 | * |
| 5004 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5005 | * voicemail vibration setting. |
| 5006 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5007 | */ |
| 5008 | @Override |
| 5009 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5010 | final long identity = Binder.clearCallingIdentity(); |
| 5011 | try { |
| 5012 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5013 | if (phone == null) { |
| 5014 | phone = mPhone; |
| 5015 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5016 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5017 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5018 | } finally { |
| 5019 | Binder.restoreCallingIdentity(identity); |
| 5020 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5021 | } |
| 5022 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5023 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5024 | * Sets the per-account voicemail vibration. |
| 5025 | * |
| 5026 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5027 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5028 | * |
| 5029 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5030 | * voicemail vibration setting. |
| 5031 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5032 | * specific PhoneAccount. |
| 5033 | */ |
| 5034 | @Override |
| 5035 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5036 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
| 5037 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5038 | if (!TextUtils.equals(callingPackage, |
| 5039 | TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5040 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5041 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5042 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5043 | } |
| 5044 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5045 | final long identity = Binder.clearCallingIdentity(); |
| 5046 | try { |
| 5047 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5048 | if (phone == null) { |
| 5049 | phone = mPhone; |
| 5050 | } |
| 5051 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5052 | } finally { |
| 5053 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5054 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5055 | } |
| 5056 | |
| 5057 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5058 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5059 | * |
| 5060 | * @throws SecurityException if the caller does not have the required permission |
| 5061 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5062 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5063 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5064 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5065 | } |
| 5066 | |
| 5067 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5068 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5069 | * permission. |
| 5070 | * |
| 5071 | * @throws SecurityException if the caller does not have the required permission |
| 5072 | */ |
| 5073 | private void enforceSendSmsPermission() { |
| 5074 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5075 | } |
| 5076 | |
| 5077 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5078 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5079 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5080 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5081 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5082 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5083 | final long identity = Binder.clearCallingIdentity(); |
| 5084 | try { |
| 5085 | ComponentName componentName = |
| 5086 | RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId); |
| 5087 | if (componentName == null) { |
| 5088 | throw new SecurityException( |
| 5089 | "Caller not current active visual voicemail package[null]"); |
| 5090 | } |
| 5091 | String vvmPackage = componentName.getPackageName(); |
| 5092 | if (!callingPackage.equals(vvmPackage)) { |
| 5093 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5094 | + vvmPackage + "]"); |
| 5095 | } |
| 5096 | } finally { |
| 5097 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5098 | } |
| 5099 | } |
| 5100 | |
| 5101 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5102 | * Return the application ID for the app type. |
| 5103 | * |
| 5104 | * @param subId the subscription ID that this request applies to. |
| 5105 | * @param appType the uicc app type. |
| 5106 | * @return Application ID for specificied app type, or null if no uicc. |
| 5107 | */ |
| 5108 | @Override |
| 5109 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5110 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5111 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5112 | |
| 5113 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5114 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5115 | if (phone == null) { |
| 5116 | return null; |
| 5117 | } |
| 5118 | String aid = null; |
| 5119 | try { |
| 5120 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5121 | .getApplicationByType(appType).getAid(); |
| 5122 | } catch (Exception e) { |
| 5123 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5124 | } |
| 5125 | return aid; |
| 5126 | } finally { |
| 5127 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5128 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5129 | } |
| 5130 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5131 | /** |
| 5132 | * Return the Electronic Serial Number. |
| 5133 | * |
| 5134 | * @param subId the subscription ID that this request applies to. |
| 5135 | * @return ESN or null if error. |
| 5136 | */ |
| 5137 | @Override |
| 5138 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5139 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5140 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5141 | |
| 5142 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5143 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5144 | if (phone == null) { |
| 5145 | return null; |
| 5146 | } |
| 5147 | String esn = null; |
| 5148 | try { |
| 5149 | esn = phone.getEsn(); |
| 5150 | } catch (Exception e) { |
| 5151 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5152 | } |
| 5153 | return esn; |
| 5154 | } finally { |
| 5155 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5156 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5157 | } |
| 5158 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5159 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5160 | * Return the Preferred Roaming List Version. |
| 5161 | * |
| 5162 | * @param subId the subscription ID that this request applies to. |
| 5163 | * @return PRLVersion or null if error. |
| 5164 | */ |
| 5165 | @Override |
| 5166 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5167 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5168 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5169 | |
| 5170 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5171 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5172 | if (phone == null) { |
| 5173 | return null; |
| 5174 | } |
| 5175 | String cdmaPrlVersion = null; |
| 5176 | try { |
| 5177 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5178 | } catch (Exception e) { |
| 5179 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5180 | } |
| 5181 | return cdmaPrlVersion; |
| 5182 | } finally { |
| 5183 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5184 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5185 | } |
| 5186 | |
| 5187 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5188 | * Get snapshot of Telephony histograms |
| 5189 | * @return List of Telephony histograms |
| 5190 | * @hide |
| 5191 | */ |
| 5192 | @Override |
| 5193 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5194 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5195 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5196 | |
| 5197 | final long identity = Binder.clearCallingIdentity(); |
| 5198 | try { |
| 5199 | return RIL.getTelephonyRILTimingHistograms(); |
| 5200 | } finally { |
| 5201 | Binder.restoreCallingIdentity(identity); |
| 5202 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5203 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5204 | |
| 5205 | /** |
| 5206 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5207 | * Set the allowed carrier list for slotIndex |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5208 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5209 | * |
| 5210 | * @return The number of carriers set successfully, should match length of carriers |
| 5211 | */ |
| 5212 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5213 | public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5214 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5215 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5216 | |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5217 | if (carriers == null) { |
| 5218 | throw new NullPointerException("carriers cannot be null"); |
| 5219 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5220 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5221 | final long identity = Binder.clearCallingIdentity(); |
| 5222 | try { |
| 5223 | int subId = SubscriptionManager.getSubId(slotIndex)[0]; |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5224 | int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId, |
| 5225 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5226 | return retVal[0]; |
| 5227 | } finally { |
| 5228 | Binder.restoreCallingIdentity(identity); |
| 5229 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | /** |
| 5233 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5234 | * Get the allowed carrier list for slotIndex. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5235 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5236 | * |
| 5237 | * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list |
| 5238 | * means all carriers are allowed. |
| 5239 | */ |
| 5240 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5241 | public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5242 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5243 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5244 | |
| 5245 | final long identity = Binder.clearCallingIdentity(); |
| 5246 | try { |
| 5247 | int subId = SubscriptionManager.getSubId(slotIndex)[0]; |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5248 | return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId, |
| 5249 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5250 | } finally { |
| 5251 | Binder.restoreCallingIdentity(identity); |
| 5252 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5253 | } |
| 5254 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5255 | /** |
| 5256 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5257 | * @param subId the subscription ID that this action applies to. |
| 5258 | * @param enabled control enable or disable metered apns. |
| 5259 | * {@hide} |
| 5260 | */ |
| 5261 | @Override |
| 5262 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5263 | enforceModifyPermission(); |
| 5264 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5265 | |
| 5266 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5267 | if (phone == null) { |
| 5268 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5269 | return; |
| 5270 | } |
| 5271 | try { |
| 5272 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5273 | } catch (Exception e) { |
| 5274 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5275 | } finally { |
| 5276 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5277 | } |
| 5278 | } |
| 5279 | |
| 5280 | /** |
| 5281 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5282 | * @param subId the subscription ID that this action applies to. |
| 5283 | * @param enabled control enable or disable radio. |
| 5284 | * {@hide} |
| 5285 | */ |
| 5286 | @Override |
| 5287 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5288 | enforceModifyPermission(); |
| 5289 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5290 | |
| 5291 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5292 | if (phone == null) { |
| 5293 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5294 | return; |
| 5295 | } |
| 5296 | try { |
| 5297 | phone.carrierActionSetRadioEnabled(enabled); |
| 5298 | } catch (Exception e) { |
| 5299 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5300 | } finally { |
| 5301 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5302 | } |
| 5303 | } |
| 5304 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5305 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5306 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5307 | * network status based on which carrier apps could apply actions accordingly, |
| 5308 | * enable/disable default url handler for example. |
| 5309 | * |
| 5310 | * @param subId the subscription ID that this action applies to. |
| 5311 | * @param report control start/stop reporting the default network status. |
| 5312 | * {@hide} |
| 5313 | */ |
| 5314 | @Override |
| 5315 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5316 | enforceModifyPermission(); |
| 5317 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5318 | |
| 5319 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5320 | if (phone == null) { |
| 5321 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5322 | return; |
| 5323 | } |
| 5324 | try { |
| 5325 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5326 | } catch (Exception e) { |
| 5327 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5328 | } finally { |
| 5329 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5330 | } |
| 5331 | } |
| 5332 | |
| 5333 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5334 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5335 | * bug report is being generated. |
| 5336 | */ |
| 5337 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5338 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5339 | if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5340 | != PackageManager.PERMISSION_GRANTED) { |
| 5341 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5342 | + Binder.getCallingPid() |
| 5343 | + ", uid=" + Binder.getCallingUid() |
| 5344 | + "without permission " |
| 5345 | + android.Manifest.permission.DUMP); |
| 5346 | return; |
| 5347 | } |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5348 | DumpsysHandler.dump(mPhone.getContext(), fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5349 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5350 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5351 | @Override |
| 5352 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5353 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5354 | throws RemoteException { |
| 5355 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5356 | } |
| 5357 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5358 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5359 | * Get aggregated video call data usage since boot. |
| 5360 | * |
| 5361 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5362 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5363 | * {@hide} |
| 5364 | */ |
| 5365 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5366 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5367 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5368 | null); |
| 5369 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5370 | final long identity = Binder.clearCallingIdentity(); |
| 5371 | try { |
| 5372 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5373 | // records the delta with the corresponding network identity. |
| 5374 | // We just return the total video call data usage snapshot since boot. |
| 5375 | Phone phone = getPhone(subId); |
| 5376 | if (phone != null) { |
| 5377 | return phone.getVtDataUsage(perUidStats); |
| 5378 | } |
| 5379 | return null; |
| 5380 | } finally { |
| 5381 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5382 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5383 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5384 | |
| 5385 | /** |
| 5386 | * Policy control of data connection. Usually used when data limit is passed. |
| 5387 | * @param enabled True if enabling the data, otherwise disabling. |
| 5388 | * @param subId Subscription index |
| 5389 | * {@hide} |
| 5390 | */ |
| 5391 | @Override |
| 5392 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 5393 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5394 | |
| 5395 | final long identity = Binder.clearCallingIdentity(); |
| 5396 | try { |
| 5397 | Phone phone = getPhone(subId); |
| 5398 | if (phone != null) { |
| 5399 | phone.setPolicyDataEnabled(enabled); |
| 5400 | } |
| 5401 | } finally { |
| 5402 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5403 | } |
| 5404 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5405 | |
| 5406 | /** |
| 5407 | * Get Client request stats |
| 5408 | * @return List of Client Request Stats |
| 5409 | * @hide |
| 5410 | */ |
| 5411 | @Override |
| 5412 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5413 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5414 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5415 | return null; |
| 5416 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5417 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5418 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5419 | final long identity = Binder.clearCallingIdentity(); |
| 5420 | try { |
| 5421 | if (phone != null) { |
| 5422 | return phone.getClientRequestStats(); |
| 5423 | } |
| 5424 | |
| 5425 | return null; |
| 5426 | } finally { |
| 5427 | Binder.restoreCallingIdentity(identity); |
| 5428 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5429 | } |
| 5430 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5431 | private WorkSource getWorkSource(int uid) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5432 | String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5433 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5434 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5435 | |
| 5436 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5437 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5438 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5439 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5440 | * @param state State of SIM (power down, power up, pass through) |
| 5441 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 5442 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 5443 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5444 | * |
| 5445 | **/ |
| 5446 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5447 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5448 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5449 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5450 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5451 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5452 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5453 | final long identity = Binder.clearCallingIdentity(); |
| 5454 | try { |
| 5455 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5456 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5457 | } |
| 5458 | } finally { |
| 5459 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5460 | } |
| 5461 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5462 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5463 | private boolean isUssdApiAllowed(int subId) { |
| 5464 | CarrierConfigManager configManager = |
| 5465 | (CarrierConfigManager) mPhone.getContext().getSystemService( |
| 5466 | Context.CARRIER_CONFIG_SERVICE); |
| 5467 | if (configManager == null) { |
| 5468 | return false; |
| 5469 | } |
| 5470 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 5471 | if (pb == null) { |
| 5472 | return false; |
| 5473 | } |
| 5474 | return pb.getBoolean( |
| 5475 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 5476 | } |
| 5477 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5478 | /** |
| 5479 | * Check if phone is in emergency callback mode |
| 5480 | * @return true if phone is in emergency callback mode |
| 5481 | * @param subId sub id |
| 5482 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 5483 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5484 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5485 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5486 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5487 | |
| 5488 | final long identity = Binder.clearCallingIdentity(); |
| 5489 | try { |
| 5490 | if (phone != null) { |
| 5491 | return phone.isInEcm(); |
| 5492 | } else { |
| 5493 | return false; |
| 5494 | } |
| 5495 | } finally { |
| 5496 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5497 | } |
| 5498 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5499 | |
| 5500 | /** |
| 5501 | * Get the current signal strength information for the given subscription. |
| 5502 | * Because this information is not updated when the device is in a low power state |
| 5503 | * it should not be relied-upon to be current. |
| 5504 | * @param subId Subscription index |
| 5505 | * @return the most recent cached signal strength info from the modem |
| 5506 | */ |
| 5507 | @Override |
| 5508 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5509 | final long identity = Binder.clearCallingIdentity(); |
| 5510 | try { |
| 5511 | Phone p = getPhone(subId); |
| 5512 | if (p == null) { |
| 5513 | return null; |
| 5514 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5515 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5516 | return p.getSignalStrength(); |
| 5517 | } finally { |
| 5518 | Binder.restoreCallingIdentity(identity); |
| 5519 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5520 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5521 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5522 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 5523 | * Get the current modem radio state for the given slot. |
| 5524 | * @param slotIndex slot index. |
| 5525 | * @param callingPackage the name of the package making the call. |
| 5526 | * @return the current radio power state from the modem |
| 5527 | */ |
| 5528 | @Override |
| 5529 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 5530 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5531 | if (phone != null) { |
| 5532 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5533 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 5534 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5535 | } |
| 5536 | |
| 5537 | final long identity = Binder.clearCallingIdentity(); |
| 5538 | try { |
| 5539 | return phone.getRadioPowerState(); |
| 5540 | } finally { |
| 5541 | Binder.restoreCallingIdentity(identity); |
| 5542 | } |
| 5543 | } |
| 5544 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5545 | } |
| 5546 | |
| 5547 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5548 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 5549 | * |
| 5550 | * <p>Requires one of the following permissions: |
| 5551 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 5552 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 5553 | * privileges. |
| 5554 | * |
| 5555 | * @param subId subscription id |
| 5556 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 5557 | * {@code false}. |
| 5558 | */ |
| 5559 | @Override |
| 5560 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5561 | boolean isEnabled = false; |
| 5562 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5563 | try { |
| 5564 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5565 | null /* message */); |
| 5566 | Phone phone = getPhone(subId); |
| 5567 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5568 | } catch (Exception e) { |
| 5569 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5570 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5571 | } finally { |
| 5572 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5573 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5574 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5575 | } |
| 5576 | |
| 5577 | |
| 5578 | /** |
| 5579 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 5580 | * |
| 5581 | * <p> Requires permission: |
| 5582 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 5583 | * privileges. |
| 5584 | * |
| 5585 | * @param subId subscription id |
| 5586 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 5587 | */ |
| 5588 | @Override |
| 5589 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5590 | final long identity = Binder.clearCallingIdentity(); |
| 5591 | try { |
| 5592 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5593 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5594 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5595 | Phone phone = getPhone(subId); |
| 5596 | if (phone != null) { |
| 5597 | phone.setDataRoamingEnabled(isEnabled); |
| 5598 | } |
| 5599 | } finally { |
| 5600 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5601 | } |
| 5602 | } |
| 5603 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5604 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 5605 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 5606 | boolean isAllowed = true; |
| 5607 | final long identity = Binder.clearCallingIdentity(); |
| 5608 | try { |
| 5609 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5610 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 5611 | Phone phone = getPhone(subId); |
| 5612 | if (phone != null) { |
| 5613 | isAllowed = phone.isCspPlmnEnabled(); |
| 5614 | } |
| 5615 | } finally { |
| 5616 | Binder.restoreCallingIdentity(identity); |
| 5617 | } |
| 5618 | return isAllowed; |
| 5619 | } |
| 5620 | |
| 5621 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5622 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5623 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5624 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5625 | final long identity = Binder.clearCallingIdentity(); |
| 5626 | try { |
| 5627 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 5628 | if (slots == null) { |
| 5629 | Rlog.i(LOG_TAG, "slots is null."); |
| 5630 | return null; |
| 5631 | } |
| 5632 | |
| 5633 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 5634 | for (int i = 0; i < slots.length; i++) { |
| 5635 | UiccSlot slot = slots[i]; |
| 5636 | if (slot == null) { |
| 5637 | continue; |
| 5638 | } |
| 5639 | |
| 5640 | String cardId; |
| 5641 | UiccCard card = slot.getUiccCard(); |
| 5642 | if (card != null) { |
| 5643 | cardId = card.getCardId(); |
| 5644 | } else { |
| 5645 | cardId = slot.getIccId(); |
| 5646 | } |
| 5647 | |
| 5648 | int cardState = 0; |
| 5649 | switch (slot.getCardState()) { |
| 5650 | case CARDSTATE_ABSENT: |
| 5651 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 5652 | break; |
| 5653 | case CARDSTATE_PRESENT: |
| 5654 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 5655 | break; |
| 5656 | case CARDSTATE_ERROR: |
| 5657 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 5658 | break; |
| 5659 | case CARDSTATE_RESTRICTED: |
| 5660 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 5661 | break; |
| 5662 | default: |
| 5663 | break; |
| 5664 | |
| 5665 | } |
| 5666 | |
| 5667 | infos[i] = new UiccSlotInfo( |
| 5668 | slot.isActive(), |
| 5669 | slot.isEuicc(), |
| 5670 | cardId, |
| 5671 | cardState, |
| 5672 | slot.getPhoneId(), |
| 5673 | slot.isExtendedApduSupported()); |
| 5674 | } |
| 5675 | return infos; |
| 5676 | } finally { |
| 5677 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 5678 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5679 | } |
| 5680 | |
| 5681 | @Override |
| 5682 | public boolean switchSlots(int[] physicalSlots) { |
| 5683 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5684 | |
| 5685 | final long identity = Binder.clearCallingIdentity(); |
| 5686 | try { |
| 5687 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 5688 | } finally { |
| 5689 | Binder.restoreCallingIdentity(identity); |
| 5690 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5691 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5692 | |
| 5693 | @Override |
| 5694 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 5695 | enforceModifyPermission(); |
| 5696 | final Phone phone = getPhone(subId); |
| 5697 | if (phone == null) { |
| 5698 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 5699 | return; |
| 5700 | } |
| 5701 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5702 | final long identity = Binder.clearCallingIdentity(); |
| 5703 | try { |
| 5704 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 5705 | } finally { |
| 5706 | Binder.restoreCallingIdentity(identity); |
| 5707 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5708 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5709 | |
| 5710 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 5711 | * A test API to reload the UICC profile. |
| 5712 | * |
| 5713 | * <p>Requires that the calling app has permission |
| 5714 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5715 | * @hide |
| 5716 | */ |
| 5717 | @Override |
| 5718 | public void refreshUiccProfile(int subId) { |
| 5719 | enforceModifyPermission(); |
| 5720 | |
| 5721 | final long identity = Binder.clearCallingIdentity(); |
| 5722 | try { |
| 5723 | Phone phone = getPhone(subId); |
| 5724 | if (phone == null) { |
| 5725 | return; |
| 5726 | } |
| 5727 | UiccCard uiccCard = phone.getUiccCard(); |
| 5728 | if (uiccCard == null) { |
| 5729 | return; |
| 5730 | } |
| 5731 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 5732 | if (uiccProfile == null) { |
| 5733 | return; |
| 5734 | } |
| 5735 | uiccProfile.refresh(); |
| 5736 | } finally { |
| 5737 | Binder.restoreCallingIdentity(identity); |
| 5738 | } |
| 5739 | } |
| 5740 | |
| 5741 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5742 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 5743 | */ |
| 5744 | private boolean getDefaultDataEnabled() { |
| 5745 | return "true".equalsIgnoreCase( |
| 5746 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 5747 | } |
| 5748 | |
| 5749 | /** |
| 5750 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 5751 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 5752 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 5753 | */ |
| 5754 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 5755 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
| 5756 | mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 5757 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 5758 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 5759 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 5760 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 5761 | return isDataRoamingEnabled; |
| 5762 | } |
| 5763 | |
| 5764 | /** |
| 5765 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 5766 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 5767 | */ |
| 5768 | private int getDefaultNetworkType(int subId) { |
| 5769 | return Integer.parseInt( |
| 5770 | TelephonyManager.getTelephonyProperty( |
| 5771 | mSubscriptionController.getPhoneId(subId), |
| 5772 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 5773 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 5774 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5775 | |
| 5776 | @Override |
| 5777 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 5778 | gid1, String gid2, String plmn, String spn) { |
| 5779 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | |
| 5781 | final long identity = Binder.clearCallingIdentity(); |
| 5782 | try { |
| 5783 | final Phone phone = getPhone(subId); |
| 5784 | if (phone == null) { |
| 5785 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 5786 | return; |
| 5787 | } |
| 5788 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 5789 | } finally { |
| 5790 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5791 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5792 | } |
| 5793 | |
| 5794 | @Override |
| 5795 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5796 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5797 | |
| 5798 | final long identity = Binder.clearCallingIdentity(); |
| 5799 | try { |
| 5800 | final Phone phone = getPhone(subId); |
| 5801 | if (phone == null) { |
| 5802 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 5803 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 5804 | } |
| 5805 | return phone.getCarrierIdListVersion(); |
| 5806 | } finally { |
| 5807 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5808 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5809 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 5810 | |
| 5811 | @Override |
| 5812 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 5813 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5814 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 5815 | return -1; |
| 5816 | } |
| 5817 | |
| 5818 | final long identity = Binder.clearCallingIdentity(); |
| 5819 | try { |
| 5820 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 5821 | } finally { |
| 5822 | Binder.restoreCallingIdentity(identity); |
| 5823 | } |
| 5824 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5825 | |
| 5826 | @Override |
| 5827 | public int getCdmaRoamingMode(int subId) { |
| 5828 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5829 | mApp, subId, "getCdmaRoamingMode"); |
| 5830 | |
| 5831 | final long identity = Binder.clearCallingIdentity(); |
| 5832 | try { |
| 5833 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 5834 | } finally { |
| 5835 | Binder.restoreCallingIdentity(identity); |
| 5836 | } |
| 5837 | } |
| 5838 | |
| 5839 | @Override |
| 5840 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 5841 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5842 | mApp, subId, "setCdmaRoamingMode"); |
| 5843 | |
| 5844 | final long identity = Binder.clearCallingIdentity(); |
| 5845 | try { |
| 5846 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 5847 | } finally { |
| 5848 | Binder.restoreCallingIdentity(identity); |
| 5849 | } |
| 5850 | } |
| 5851 | |
| 5852 | @Override |
| 5853 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 5854 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5855 | mApp, subId, "setCdmaSubscriptionMode"); |
| 5856 | |
| 5857 | final long identity = Binder.clearCallingIdentity(); |
| 5858 | try { |
| 5859 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 5860 | } finally { |
| 5861 | Binder.restoreCallingIdentity(identity); |
| 5862 | } |
| 5863 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 5864 | |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 5865 | private void ensureUserRunning(int userId) { |
| 5866 | if (!mUserManager.isUserRunning(userId)) { |
| 5867 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 5868 | } |
| 5869 | } |
| 5870 | |
| 5871 | /** |
| 5872 | * Returns a list of SMS apps on a given user. |
| 5873 | * |
| 5874 | * Only the shell user (UID 2000 or 0) can call it. |
| 5875 | * Target user must be running. |
| 5876 | */ |
| 5877 | @Override |
| 5878 | public String[] getSmsApps(int userId) { |
| 5879 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 5880 | ensureUserRunning(userId); |
| 5881 | |
| 5882 | final Collection<SmsApplicationData> apps = |
| 5883 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 5884 | |
| 5885 | String[] ret = new String[apps.size()]; |
| 5886 | int i = 0; |
| 5887 | for (SmsApplicationData app : apps) { |
| 5888 | ret[i++] = app.mPackageName; |
| 5889 | } |
| 5890 | return ret; |
| 5891 | } |
| 5892 | |
| 5893 | /** |
| 5894 | * Returns the default SMS app package name on a given user. |
| 5895 | * |
| 5896 | * Only the shell user (UID 2000 or 0) can call it. |
| 5897 | * Target user must be running. |
| 5898 | */ |
| 5899 | @Override |
| 5900 | public String getDefaultSmsApp(int userId) { |
| 5901 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 5902 | ensureUserRunning(userId); |
| 5903 | |
| 5904 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 5905 | /* updateIfNeeded= */ true, userId); |
| 5906 | return cn == null ? null : cn.getPackageName(); |
| 5907 | } |
| 5908 | |
| 5909 | /** |
| 5910 | * Set a package as the default SMS app on a given user. |
| 5911 | * |
| 5912 | * Only the shell user (UID 2000 or 0) can call it. |
| 5913 | * Target user must be running. |
| 5914 | */ |
| 5915 | @Override |
| 5916 | public void setDefaultSmsApp(int userId, String packageName) { |
| 5917 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 5918 | ensureUserRunning(userId); |
| 5919 | |
| 5920 | boolean found = false; |
| 5921 | for (String pkg : getSmsApps(userId)) { |
| 5922 | if (TextUtils.equals(packageName, pkg)) { |
| 5923 | found = true; |
| 5924 | break; |
| 5925 | } |
| 5926 | } |
| 5927 | if (!found) { |
| 5928 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 5929 | } |
| 5930 | |
| 5931 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 5932 | } |
| 5933 | |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 5934 | @Override |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 5935 | public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList( |
| 5936 | String callingPackage) { |
| 5937 | // TODO connect with internal content |
| 5938 | return null; |
| 5939 | } |
| 5940 | |
| 5941 | @Override |
| 5942 | public boolean isCurrentEmergencyNumber(String number) { |
| 5943 | // TODO connect with internal content |
| 5944 | return false; |
| 5945 | } |
| 5946 | |
| 5947 | @Override |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 5948 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 5949 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 5950 | Phone phone = getPhone(subId); |
| 5951 | if (phone == null) { |
| 5952 | return null; |
| 5953 | } |
| 5954 | final long identity = Binder.clearCallingIdentity(); |
| 5955 | try { |
| 5956 | UiccProfile profile = UiccController.getInstance() |
| 5957 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 5958 | if (profile != null) { |
| 5959 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 5960 | } |
| 5961 | } finally { |
| 5962 | Binder.restoreCallingIdentity(identity); |
| 5963 | } |
| 5964 | return null; |
| 5965 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5966 | } |