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 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 22 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 23 | import android.Manifest.permission; |
Tyler Gunn | 327a972 | 2019-04-03 15:28:53 -0700 | [diff] [blame^] | 24 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 26 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 27 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 28 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 31 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 32 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 33 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 34 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 36 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.Uri; |
| 38 | import android.os.AsyncResult; |
| 39 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 40 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
| 42 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.Looper; |
| 45 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 46 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 47 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 48 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 49 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 51 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 52 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 54 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 55 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 56 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 57 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 58 | import android.provider.Telephony; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 59 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 60 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 61 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 62 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 63 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 65 | import android.telephony.CellInfoGsm; |
| 66 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 67 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 68 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 69 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 70 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 71 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 72 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 73 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 74 | import android.telephony.NetworkScanRequest; |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 75 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 76 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 77 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 78 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 79 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 80 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 81 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 82 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 83 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 84 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 85 | import android.telephony.TelephonyManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 86 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 87 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 88 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 89 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 90 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 91 | import android.telephony.data.ApnSetting; |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 92 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 93 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 94 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 95 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 96 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 97 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 98 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 99 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 100 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 101 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 102 | import android.telephony.ims.feature.MmTelFeature; |
| 103 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 104 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 105 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 106 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 107 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 108 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 109 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 110 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 111 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 112 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 113 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 114 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 115 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 117 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 121 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 122 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 126 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.Phone; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.ServiceStateTracker; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.SmsApplication; |
| 139 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.TelephonyPermissions; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.ims.ImsResolver; |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.uicc.IccIoResult; |
| 147 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 153 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 155 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 156 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 157 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 158 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 159 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 160 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 161 | import java.io.FileDescriptor; |
| 162 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 163 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 164 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 165 | import java.util.Arrays; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 166 | import java.util.Collection; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 167 | import java.util.HashMap; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 168 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 169 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 170 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 171 | import java.util.Map; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 172 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * Implementation of the ITelephony interface. |
| 176 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 177 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 178 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 179 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 180 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 181 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 182 | |
| 183 | // Message codes used with mMainThreadHandler |
| 184 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 185 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 186 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 187 | private static final int CMD_OPEN_CHANNEL = 9; |
| 188 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 189 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 190 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 191 | private static final int CMD_NV_READ_ITEM = 13; |
| 192 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 193 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 194 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 195 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 196 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 197 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 198 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 199 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 200 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 201 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 202 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 203 | private static final int CMD_SEND_ENVELOPE = 25; |
| 204 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 205 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 206 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 207 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 208 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 209 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 210 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 211 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 212 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 213 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 214 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 215 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 216 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 217 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 218 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 219 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 220 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 221 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 222 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 223 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 224 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 225 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 226 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 227 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 228 | private static final int CMD_SWITCH_SLOTS = 50; |
| 229 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 230 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 231 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 232 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 233 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 234 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 235 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 236 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 237 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 238 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 239 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 240 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 241 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 242 | private static final int CMD_MODEM_REBOOT = 64; |
| 243 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 244 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 245 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 246 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 247 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 248 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 249 | // Parameters of select command. |
| 250 | private static final int SELECT_COMMAND = 0xA4; |
| 251 | private static final int SELECT_P1 = 0x04; |
| 252 | private static final int SELECT_P2 = 0; |
| 253 | private static final int SELECT_P3 = 0x10; |
| 254 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 255 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 256 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 257 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 258 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 259 | /** The singleton instance. */ |
| 260 | private static PhoneInterfaceManager sInstance; |
| 261 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 262 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 263 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 264 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 265 | private AppOpsManager mAppOps; |
| 266 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 267 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 268 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 269 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 270 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 271 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 272 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 273 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 274 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 275 | |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 276 | // String to store multi SIM allowed |
| 277 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 278 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 279 | // The AID of ISD-R. |
| 280 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 281 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 282 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 283 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 284 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 285 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 286 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 287 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 288 | * A request object to use for transmitting data to an ICC. |
| 289 | */ |
| 290 | private static final class IccAPDUArgument { |
| 291 | public int channel, cla, command, p1, p2, p3; |
| 292 | public String data; |
| 293 | |
| 294 | public IccAPDUArgument(int channel, int cla, int command, |
| 295 | int p1, int p2, int p3, String data) { |
| 296 | this.channel = channel; |
| 297 | this.cla = cla; |
| 298 | this.command = command; |
| 299 | this.p1 = p1; |
| 300 | this.p2 = p2; |
| 301 | this.p3 = p3; |
| 302 | this.data = data; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 307 | * A request object to use for transmitting data to an ICC. |
| 308 | */ |
| 309 | private static final class ManualNetworkSelectionArgument { |
| 310 | public OperatorInfo operatorInfo; |
| 311 | public boolean persistSelection; |
| 312 | |
| 313 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 314 | this.operatorInfo = operatorInfo; |
| 315 | this.persistSelection = persistSelection; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 320 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 321 | * request after sending. The main thread will notify the request when it is complete. |
| 322 | */ |
| 323 | private static final class MainThreadRequest { |
| 324 | /** The argument to use for the request */ |
| 325 | public Object argument; |
| 326 | /** The result of the request that is run on the main thread */ |
| 327 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 328 | // The subscriber id that this request applies to. Defaults to |
| 329 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 330 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 331 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 332 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 333 | public Phone phone; |
| 334 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 335 | public WorkSource workSource; |
| 336 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 337 | public MainThreadRequest(Object argument) { |
| 338 | this.argument = argument; |
| 339 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 340 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 341 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 342 | this.argument = argument; |
| 343 | if (phone != null) { |
| 344 | this.phone = phone; |
| 345 | } |
| 346 | this.workSource = workSource; |
| 347 | } |
| 348 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 349 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 350 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 351 | if (subId != null) { |
| 352 | this.subId = subId; |
| 353 | } |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 354 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 355 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 358 | private static final class IncomingThirdPartyCallArgs { |
| 359 | public final ComponentName component; |
| 360 | public final String callId; |
| 361 | public final String callerDisplayName; |
| 362 | |
| 363 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 364 | String callerDisplayName) { |
| 365 | this.component = component; |
| 366 | this.callId = callId; |
| 367 | this.callerDisplayName = callerDisplayName; |
| 368 | } |
| 369 | } |
| 370 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 371 | /** |
| 372 | * A handler that processes messages on the main thread in the phone process. Since many |
| 373 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 374 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 375 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 376 | * on, which will be notified when the operation completes and will contain the result of the |
| 377 | * request. |
| 378 | * |
| 379 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 380 | * note that request.result must be set to something non-null for the calling thread to |
| 381 | * unblock. |
| 382 | */ |
| 383 | private final class MainThreadHandler extends Handler { |
| 384 | @Override |
| 385 | public void handleMessage(Message msg) { |
| 386 | MainThreadRequest request; |
| 387 | Message onCompleted; |
| 388 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 389 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 390 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 391 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 392 | |
| 393 | switch (msg.what) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 394 | case CMD_HANDLE_USSD_REQUEST: { |
| 395 | request = (MainThreadRequest) msg.obj; |
| 396 | final Phone phone = getPhoneFromRequest(request); |
| 397 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 398 | String ussdRequest = ussdObject.first; |
| 399 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 400 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 401 | if (!isUssdApiAllowed(request.subId)) { |
| 402 | // Carrier does not support use of this API, return failure. |
| 403 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 404 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 405 | Bundle returnData = new Bundle(); |
| 406 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 407 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 408 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 409 | request.result = true; |
| 410 | notifyRequester(request); |
| 411 | return; |
| 412 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 413 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 414 | try { |
| 415 | request.result = phone != null |
| 416 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 417 | } catch (CallStateException cse) { |
| 418 | request.result = false; |
| 419 | } |
| 420 | // Wake up the requesting thread |
| 421 | notifyRequester(request); |
| 422 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 425 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 426 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 427 | final Phone phone = getPhoneFromRequest(request); |
| 428 | request.result = phone != null ? |
| 429 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 430 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 431 | // Wake up the requesting thread |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 432 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 433 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 434 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 435 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 436 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 437 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 438 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 439 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 440 | if (uiccCard == null) { |
| 441 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 442 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 443 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 444 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 445 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 446 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 447 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 448 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 449 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 450 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 451 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 452 | break; |
| 453 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 454 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 455 | ar = (AsyncResult) msg.obj; |
| 456 | request = (MainThreadRequest) ar.userObj; |
| 457 | if (ar.exception == null && ar.result != null) { |
| 458 | request.result = ar.result; |
| 459 | } else { |
| 460 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 461 | if (ar.result == null) { |
| 462 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 463 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 464 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 465 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 466 | } else { |
| 467 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 468 | } |
| 469 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 470 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 471 | break; |
| 472 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 473 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 474 | request = (MainThreadRequest) msg.obj; |
| 475 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 476 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 477 | if (uiccCard == null) { |
| 478 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 479 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
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 | } else { |
| 482 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 483 | request); |
| 484 | uiccCard.iccTransmitApduBasicChannel( |
| 485 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 486 | iccArgument.p3, iccArgument.data, onCompleted); |
| 487 | } |
| 488 | break; |
| 489 | |
| 490 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 491 | ar = (AsyncResult) msg.obj; |
| 492 | request = (MainThreadRequest) ar.userObj; |
| 493 | if (ar.exception == null && ar.result != null) { |
| 494 | request.result = ar.result; |
| 495 | } else { |
| 496 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 497 | if (ar.result == null) { |
| 498 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 499 | } else if (ar.exception instanceof CommandException) { |
| 500 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 501 | ar.exception); |
| 502 | } else { |
| 503 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 504 | } |
| 505 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 506 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 507 | break; |
| 508 | |
| 509 | case CMD_EXCHANGE_SIM_IO: |
| 510 | request = (MainThreadRequest) msg.obj; |
| 511 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 512 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 513 | if (uiccCard == null) { |
| 514 | loge("iccExchangeSimIO: No UICC"); |
| 515 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 516 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 517 | } else { |
| 518 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 519 | request); |
| 520 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 521 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 522 | iccArgument.data, onCompleted); |
| 523 | } |
| 524 | break; |
| 525 | |
| 526 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 527 | ar = (AsyncResult) msg.obj; |
| 528 | request = (MainThreadRequest) ar.userObj; |
| 529 | if (ar.exception == null && ar.result != null) { |
| 530 | request.result = ar.result; |
| 531 | } else { |
| 532 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 533 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 534 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 535 | break; |
| 536 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 537 | case CMD_SEND_ENVELOPE: |
| 538 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 539 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 540 | if (uiccCard == null) { |
| 541 | loge("sendEnvelopeWithStatus: No UICC"); |
| 542 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 543 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 544 | } else { |
| 545 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 546 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 547 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 548 | break; |
| 549 | |
| 550 | case EVENT_SEND_ENVELOPE_DONE: |
| 551 | ar = (AsyncResult) msg.obj; |
| 552 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 553 | if (ar.exception == null && ar.result != null) { |
| 554 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 555 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 556 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 557 | if (ar.result == null) { |
| 558 | loge("sendEnvelopeWithStatus: Empty response"); |
| 559 | } else if (ar.exception instanceof CommandException) { |
| 560 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 561 | ar.exception); |
| 562 | } else { |
| 563 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 564 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 565 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 566 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 567 | break; |
| 568 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 569 | case CMD_OPEN_CHANNEL: |
| 570 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 571 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 572 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 573 | if (uiccCard == null) { |
| 574 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 575 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 576 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 577 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 578 | } else { |
| 579 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 580 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 581 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 582 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 583 | break; |
| 584 | |
| 585 | case EVENT_OPEN_CHANNEL_DONE: |
| 586 | ar = (AsyncResult) msg.obj; |
| 587 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 588 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 589 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 590 | int[] result = (int[]) ar.result; |
| 591 | int channelId = result[0]; |
| 592 | byte[] selectResponse = null; |
| 593 | if (result.length > 1) { |
| 594 | selectResponse = new byte[result.length - 1]; |
| 595 | for (int i = 1; i < result.length; ++i) { |
| 596 | selectResponse[i - 1] = (byte) result[i]; |
| 597 | } |
| 598 | } |
| 599 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 600 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 601 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 602 | if (ar.result == null) { |
| 603 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 604 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 605 | if (ar.exception != null) { |
| 606 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 607 | } |
| 608 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 609 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 610 | if (ar.exception instanceof CommandException) { |
| 611 | CommandException.Error error = |
| 612 | ((CommandException) (ar.exception)).getCommandError(); |
| 613 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 614 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 615 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 616 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 620 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 621 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 622 | request.result = openChannelResp; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 623 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 624 | break; |
| 625 | |
| 626 | case CMD_CLOSE_CHANNEL: |
| 627 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 628 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 629 | if (uiccCard == null) { |
| 630 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 631 | request.result = false; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 632 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 633 | } else { |
| 634 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 635 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 636 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 637 | break; |
| 638 | |
| 639 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 640 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 641 | break; |
| 642 | |
| 643 | case CMD_NV_READ_ITEM: |
| 644 | request = (MainThreadRequest) msg.obj; |
| 645 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 646 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 647 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 648 | break; |
| 649 | |
| 650 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 651 | ar = (AsyncResult) msg.obj; |
| 652 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 653 | if (ar.exception == null && ar.result != null) { |
| 654 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 655 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 656 | request.result = ""; |
| 657 | if (ar.result == null) { |
| 658 | loge("nvReadItem: Empty response"); |
| 659 | } else if (ar.exception instanceof CommandException) { |
| 660 | loge("nvReadItem: CommandException: " + |
| 661 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 663 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 664 | } |
| 665 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 666 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 667 | break; |
| 668 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 669 | case CMD_NV_WRITE_ITEM: |
| 670 | request = (MainThreadRequest) msg.obj; |
| 671 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 672 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 673 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 674 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 675 | break; |
| 676 | |
| 677 | case EVENT_NV_WRITE_ITEM_DONE: |
| 678 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 679 | break; |
| 680 | |
| 681 | case CMD_NV_WRITE_CDMA_PRL: |
| 682 | request = (MainThreadRequest) msg.obj; |
| 683 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 684 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 685 | break; |
| 686 | |
| 687 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 688 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 689 | break; |
| 690 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 691 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 692 | request = (MainThreadRequest) msg.obj; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 693 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 694 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 695 | break; |
| 696 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 697 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 698 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 699 | break; |
| 700 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 701 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 702 | request = (MainThreadRequest) msg.obj; |
| 703 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 704 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 705 | break; |
| 706 | |
| 707 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 708 | ar = (AsyncResult) msg.obj; |
| 709 | request = (MainThreadRequest) ar.userObj; |
| 710 | if (ar.exception == null && ar.result != null) { |
| 711 | request.result = ar.result; // Integer |
| 712 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 713 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 714 | if (ar.result == null) { |
| 715 | loge("getPreferredNetworkType: Empty response"); |
| 716 | } else if (ar.exception instanceof CommandException) { |
| 717 | loge("getPreferredNetworkType: CommandException: " + |
| 718 | ar.exception); |
| 719 | } else { |
| 720 | loge("getPreferredNetworkType: Unknown exception"); |
| 721 | } |
| 722 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 723 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 724 | break; |
| 725 | |
| 726 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 727 | request = (MainThreadRequest) msg.obj; |
| 728 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 729 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 730 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 731 | break; |
| 732 | |
| 733 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 734 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 735 | break; |
| 736 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 737 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 738 | request = (MainThreadRequest)msg.obj; |
| 739 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 740 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 741 | break; |
| 742 | |
| 743 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 744 | ar = (AsyncResult)msg.obj; |
| 745 | request = (MainThreadRequest)ar.userObj; |
| 746 | request.result = ar; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 747 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 748 | break; |
| 749 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 750 | case CMD_SET_VOICEMAIL_NUMBER: |
| 751 | request = (MainThreadRequest) msg.obj; |
| 752 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 753 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 754 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 755 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 756 | break; |
| 757 | |
| 758 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 759 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 760 | break; |
| 761 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 762 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 763 | request = (MainThreadRequest) msg.obj; |
| 764 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 765 | request); |
| 766 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 767 | break; |
| 768 | |
| 769 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 770 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 771 | break; |
| 772 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 773 | case CMD_PERFORM_NETWORK_SCAN: |
| 774 | request = (MainThreadRequest) msg.obj; |
| 775 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 776 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 777 | break; |
| 778 | |
| 779 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 780 | ar = (AsyncResult) msg.obj; |
| 781 | request = (MainThreadRequest) ar.userObj; |
| 782 | CellNetworkScanResult cellScanResult; |
| 783 | if (ar.exception == null && ar.result != null) { |
| 784 | cellScanResult = new CellNetworkScanResult( |
| 785 | CellNetworkScanResult.STATUS_SUCCESS, |
| 786 | (List<OperatorInfo>) ar.result); |
| 787 | } else { |
| 788 | if (ar.result == null) { |
| 789 | loge("getCellNetworkScanResults: Empty response"); |
| 790 | } |
| 791 | if (ar.exception != null) { |
| 792 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 793 | } |
| 794 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 795 | if (ar.exception instanceof CommandException) { |
| 796 | CommandException.Error error = |
| 797 | ((CommandException) (ar.exception)).getCommandError(); |
| 798 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 799 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 800 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 801 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 802 | } |
| 803 | } |
| 804 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 805 | } |
| 806 | request.result = cellScanResult; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 807 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 808 | break; |
| 809 | |
| 810 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 811 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 812 | ManualNetworkSelectionArgument selArg = |
| 813 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 814 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 815 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 816 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 817 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 818 | break; |
| 819 | |
| 820 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 821 | ar = (AsyncResult) msg.obj; |
| 822 | request = (MainThreadRequest) ar.userObj; |
| 823 | if (ar.exception == null) { |
| 824 | request.result = true; |
| 825 | } else { |
| 826 | request.result = false; |
| 827 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 828 | } |
| 829 | notifyRequester(request); |
| 830 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 831 | break; |
| 832 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 833 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 834 | request = (MainThreadRequest) msg.obj; |
| 835 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 836 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 837 | break; |
| 838 | |
| 839 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 840 | ar = (AsyncResult) msg.obj; |
| 841 | request = (MainThreadRequest) ar.userObj; |
| 842 | if (ar.exception == null && ar.result != null) { |
| 843 | request.result = ar.result; |
| 844 | } else { |
| 845 | if (ar.result == null) { |
| 846 | loge("queryModemActivityInfo: Empty response"); |
| 847 | } else if (ar.exception instanceof CommandException) { |
| 848 | loge("queryModemActivityInfo: CommandException: " + |
| 849 | ar.exception); |
| 850 | } else { |
| 851 | loge("queryModemActivityInfo: Unknown exception"); |
| 852 | } |
| 853 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 854 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 855 | if (request.result == null) { |
| 856 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 857 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 858 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 859 | break; |
| 860 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 861 | case CMD_SET_ALLOWED_CARRIERS: |
| 862 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 863 | CarrierRestrictionRules argument = |
| 864 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 865 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 866 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 867 | break; |
| 868 | |
| 869 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 870 | ar = (AsyncResult) msg.obj; |
| 871 | request = (MainThreadRequest) ar.userObj; |
| 872 | if (ar.exception == null && ar.result != null) { |
| 873 | request.result = ar.result; |
| 874 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 875 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 876 | if (ar.exception instanceof CommandException) { |
| 877 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 878 | CommandException.Error error = |
| 879 | ((CommandException) (ar.exception)).getCommandError(); |
| 880 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 881 | request.result = |
| 882 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 883 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 884 | } else { |
| 885 | loge("setAllowedCarriers: Unknown exception"); |
| 886 | } |
| 887 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 888 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 889 | break; |
| 890 | |
| 891 | case CMD_GET_ALLOWED_CARRIERS: |
| 892 | request = (MainThreadRequest) msg.obj; |
| 893 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 894 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 895 | break; |
| 896 | |
| 897 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 898 | ar = (AsyncResult) msg.obj; |
| 899 | request = (MainThreadRequest) ar.userObj; |
| 900 | if (ar.exception == null && ar.result != null) { |
| 901 | request.result = ar.result; |
| 902 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 903 | request.result = new IllegalStateException( |
| 904 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 905 | if (ar.result == null) { |
| 906 | loge("getAllowedCarriers: Empty response"); |
| 907 | } else if (ar.exception instanceof CommandException) { |
| 908 | loge("getAllowedCarriers: CommandException: " + |
| 909 | ar.exception); |
| 910 | } else { |
| 911 | loge("getAllowedCarriers: Unknown exception"); |
| 912 | } |
| 913 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 914 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 915 | break; |
| 916 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 917 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 918 | ar = (AsyncResult) msg.obj; |
| 919 | request = (MainThreadRequest) ar.userObj; |
| 920 | if (ar.exception == null && ar.result != null) { |
| 921 | request.result = ar.result; |
| 922 | } else { |
| 923 | request.result = new IllegalArgumentException( |
| 924 | "Failed to retrieve Forbidden Plmns"); |
| 925 | if (ar.result == null) { |
| 926 | loge("getForbiddenPlmns: Empty response"); |
| 927 | } else { |
| 928 | loge("getForbiddenPlmns: Unknown exception"); |
| 929 | } |
| 930 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 931 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 932 | break; |
| 933 | |
| 934 | case CMD_GET_FORBIDDEN_PLMNS: |
| 935 | request = (MainThreadRequest) msg.obj; |
| 936 | uiccCard = getUiccCardFromRequest(request); |
| 937 | if (uiccCard == null) { |
| 938 | loge("getForbiddenPlmns() UiccCard is null"); |
| 939 | request.result = new IllegalArgumentException( |
| 940 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 941 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 942 | break; |
| 943 | } |
| 944 | Integer appType = (Integer) request.argument; |
| 945 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 946 | if (uiccApp == null) { |
| 947 | loge("getForbiddenPlmns() no app with specified type -- " |
| 948 | + appType); |
| 949 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 950 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 951 | break; |
| 952 | } else { |
| 953 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 954 | + " specified type -- " + appType); |
| 955 | } |
| 956 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 957 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 958 | onCompleted); |
| 959 | break; |
| 960 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 961 | case CMD_SWITCH_SLOTS: |
| 962 | request = (MainThreadRequest) msg.obj; |
| 963 | int[] physicalSlots = (int[]) request.argument; |
| 964 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 965 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 966 | break; |
| 967 | |
| 968 | case EVENT_SWITCH_SLOTS_DONE: |
| 969 | ar = (AsyncResult) msg.obj; |
| 970 | request = (MainThreadRequest) ar.userObj; |
| 971 | request.result = (ar.exception == null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 972 | notifyRequester(request); |
| 973 | break; |
| 974 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 975 | request = (MainThreadRequest) msg.obj; |
| 976 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 977 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 978 | break; |
| 979 | |
| 980 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 981 | ar = (AsyncResult) msg.obj; |
| 982 | request = (MainThreadRequest) ar.userObj; |
| 983 | if (ar.exception != null) { |
| 984 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 985 | } else { |
| 986 | int mode = ((int[]) ar.result)[0]; |
| 987 | if (mode == 0) { |
| 988 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 989 | } else { |
| 990 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 991 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 992 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 993 | notifyRequester(request); |
| 994 | break; |
| 995 | case CMD_GET_CDMA_ROAMING_MODE: |
| 996 | request = (MainThreadRequest) msg.obj; |
| 997 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 998 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 999 | break; |
| 1000 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1001 | ar = (AsyncResult) msg.obj; |
| 1002 | request = (MainThreadRequest) ar.userObj; |
| 1003 | if (ar.exception != null) { |
| 1004 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1005 | } else { |
| 1006 | request.result = ((int[]) ar.result)[0]; |
| 1007 | } |
| 1008 | notifyRequester(request); |
| 1009 | break; |
| 1010 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1011 | request = (MainThreadRequest) msg.obj; |
| 1012 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1013 | int mode = (int) request.argument; |
| 1014 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1015 | break; |
| 1016 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1017 | ar = (AsyncResult) msg.obj; |
| 1018 | request = (MainThreadRequest) ar.userObj; |
| 1019 | request.result = ar.exception == null; |
| 1020 | notifyRequester(request); |
| 1021 | break; |
| 1022 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1023 | request = (MainThreadRequest) msg.obj; |
| 1024 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1025 | int subscriptionMode = (int) request.argument; |
| 1026 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1027 | break; |
| 1028 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1029 | ar = (AsyncResult) msg.obj; |
| 1030 | request = (MainThreadRequest) ar.userObj; |
| 1031 | request.result = ar.exception == null; |
| 1032 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1033 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1034 | case CMD_GET_ALL_CELL_INFO: |
| 1035 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1036 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1037 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1038 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1039 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1040 | ar = (AsyncResult) msg.obj; |
| 1041 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1042 | // If a timeout occurs, the response will be null |
| 1043 | request.result = (ar.exception == null && ar.result != null) |
| 1044 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1045 | synchronized (request) { |
| 1046 | request.notifyAll(); |
| 1047 | } |
| 1048 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1049 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1050 | request = (MainThreadRequest) msg.obj; |
| 1051 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1052 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1053 | break; |
| 1054 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1055 | ar = (AsyncResult) msg.obj; |
| 1056 | request = (MainThreadRequest) ar.userObj; |
| 1057 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1058 | try { |
| 1059 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1060 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1061 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1062 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1063 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1064 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1065 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1066 | } else { |
| 1067 | // use the result as returned |
| 1068 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1069 | } |
| 1070 | } catch (RemoteException re) { |
| 1071 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1072 | } |
| 1073 | break; |
| 1074 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1075 | request = (MainThreadRequest) msg.obj; |
| 1076 | WorkSource ws = (WorkSource) request.argument; |
| 1077 | Phone phone = getPhoneFromRequest(request); |
| 1078 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1079 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1080 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1081 | ar = (AsyncResult) msg.obj; |
| 1082 | request = (MainThreadRequest) ar.userObj; |
| 1083 | if (ar.exception == null) { |
| 1084 | request.result = ar.result; |
| 1085 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1086 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1087 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1088 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1089 | } |
| 1090 | |
| 1091 | synchronized (request) { |
| 1092 | request.notifyAll(); |
| 1093 | } |
| 1094 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1095 | case CMD_MODEM_REBOOT: |
| 1096 | request = (MainThreadRequest) msg.obj; |
| 1097 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1098 | defaultPhone.rebootModem(onCompleted); |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1099 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1100 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1101 | handleNullReturnEvent(msg, "rebootModem"); |
| 1102 | break; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1103 | case CMD_REQUEST_ENABLE_MODEM: |
| 1104 | request = (MainThreadRequest) msg.obj; |
| 1105 | boolean enable = (boolean) request.argument; |
| 1106 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1107 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1108 | PhoneConfigurationManager.getInstance() |
| 1109 | .enablePhone(request.phone, enable, onCompleted); |
| 1110 | break; |
| 1111 | case EVENT_ENABLE_MODEM_DONE: |
| 1112 | ar = (AsyncResult) msg.obj; |
| 1113 | request = (MainThreadRequest) ar.userObj; |
| 1114 | request.result = (ar.exception == null); |
Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1115 | //update the cache as modem status has changed |
| 1116 | mPhoneConfigurationManager.addToPhoneStatusCache( |
| 1117 | request.phone.getPhoneId(), msg.arg1 == 1); |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 1118 | updateModemStateMetrics(); |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1119 | notifyRequester(request); |
| 1120 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1121 | default: |
| 1122 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1123 | break; |
| 1124 | } |
| 1125 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1126 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1127 | private void notifyRequester(MainThreadRequest request) { |
| 1128 | synchronized (request) { |
| 1129 | request.notifyAll(); |
| 1130 | } |
| 1131 | } |
| 1132 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1133 | private void handleNullReturnEvent(Message msg, String command) { |
| 1134 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1135 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1136 | if (ar.exception == null) { |
| 1137 | request.result = true; |
| 1138 | } else { |
| 1139 | request.result = false; |
| 1140 | if (ar.exception instanceof CommandException) { |
| 1141 | loge(command + ": CommandException: " + ar.exception); |
| 1142 | } else { |
| 1143 | loge(command + ": Unknown exception"); |
| 1144 | } |
| 1145 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1146 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1147 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | /** |
| 1151 | * Posts the specified command to be executed on the main thread, |
| 1152 | * waits for the request to complete, and returns the result. |
| 1153 | * @see #sendRequestAsync |
| 1154 | */ |
| 1155 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1156 | return sendRequest( |
| 1157 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | /** |
| 1161 | * Posts the specified command to be executed on the main thread, |
| 1162 | * waits for the request to complete, and returns the result. |
| 1163 | * @see #sendRequestAsync |
| 1164 | */ |
| 1165 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1166 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1167 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | /** |
| 1171 | * Posts the specified command to be executed on the main thread, |
| 1172 | * waits for the request to complete, and returns the result. |
| 1173 | * @see #sendRequestAsync |
| 1174 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1175 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1176 | return sendRequest(command, argument, subId, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | /** |
| 1180 | * Posts the specified command to be executed on the main thread, |
| 1181 | * waits for the request to complete, and returns the result. |
| 1182 | * @see #sendRequestAsync |
| 1183 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1184 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1185 | return sendRequest(command, argument, subId, null, workSource); |
| 1186 | } |
| 1187 | |
| 1188 | /** |
| 1189 | * Posts the specified command to be executed on the main thread, |
| 1190 | * waits for the request to complete, and returns the result. |
| 1191 | * @see #sendRequestAsync |
| 1192 | */ |
| 1193 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1194 | return sendRequest( |
| 1195 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1196 | } |
| 1197 | |
| 1198 | /** |
| 1199 | * Posts the specified command to be executed on the main thread, |
| 1200 | * waits for the request to complete, and returns the result. |
| 1201 | * @see #sendRequestAsync |
| 1202 | */ |
| 1203 | private Object sendRequest( |
| 1204 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1205 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1206 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1207 | } |
| 1208 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1209 | MainThreadRequest request = null; |
| 1210 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1211 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1212 | } else if (phone != null) { |
| 1213 | request = new MainThreadRequest(argument, phone, workSource); |
| 1214 | } else { |
| 1215 | request = new MainThreadRequest(argument, subId, workSource); |
| 1216 | } |
| 1217 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1218 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1219 | msg.sendToTarget(); |
| 1220 | |
| 1221 | // Wait for the request to complete |
| 1222 | synchronized (request) { |
| 1223 | while (request.result == null) { |
| 1224 | try { |
| 1225 | request.wait(); |
| 1226 | } catch (InterruptedException e) { |
| 1227 | // Do nothing, go back and wait until the request is complete |
| 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | return request.result; |
| 1232 | } |
| 1233 | |
| 1234 | /** |
| 1235 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1236 | * Posts the specified command to be executed on the main thread, and |
| 1237 | * returns immediately. |
| 1238 | * @see #sendRequest |
| 1239 | */ |
| 1240 | private void sendRequestAsync(int command) { |
| 1241 | mMainThreadHandler.sendEmptyMessage(command); |
| 1242 | } |
| 1243 | |
| 1244 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1245 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1246 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1247 | */ |
| 1248 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1249 | sendRequestAsync(command, argument, null, null); |
| 1250 | } |
| 1251 | |
| 1252 | /** |
| 1253 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1254 | * @see {@link #sendRequest(int,Object)} |
| 1255 | */ |
| 1256 | private void sendRequestAsync( |
| 1257 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1258 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1259 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1260 | msg.sendToTarget(); |
| 1261 | } |
| 1262 | |
| 1263 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1264 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1265 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1266 | */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1267 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1268 | synchronized (PhoneInterfaceManager.class) { |
| 1269 | if (sInstance == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1270 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1271 | } else { |
| 1272 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1273 | } |
| 1274 | return sInstance; |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1279 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1280 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1281 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1282 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1283 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1284 | mMainThreadHandler = new MainThreadHandler(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1285 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1286 | mTelephonySharedPreferences = |
| 1287 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1288 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1289 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1290 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1291 | publish(); |
| 1292 | } |
| 1293 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1294 | private Phone getDefaultPhone() { |
| 1295 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1296 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1297 | } |
| 1298 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1299 | private void publish() { |
| 1300 | if (DBG) log("publish: " + this); |
| 1301 | |
| 1302 | ServiceManager.addService("phone", this); |
| 1303 | } |
| 1304 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1305 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1306 | if (request.phone != null) { |
| 1307 | return request.phone; |
| 1308 | } else { |
| 1309 | return getPhoneFromSubId(request.subId); |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | private Phone getPhoneFromSubId(int subId) { |
| 1314 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1315 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1316 | } |
| 1317 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1318 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1319 | Phone phone = getPhoneFromRequest(request); |
| 1320 | return phone == null ? null : |
| 1321 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1322 | } |
| 1323 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1324 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1325 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1326 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1327 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1328 | |
| 1329 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1330 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1331 | } |
| 1332 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1333 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1334 | if (DBG) log("dial: " + number); |
| 1335 | // No permission check needed here: This is just a wrapper around the |
| 1336 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1337 | // the UI before it does anything. |
| 1338 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1339 | final long identity = Binder.clearCallingIdentity(); |
| 1340 | try { |
| 1341 | String url = createTelUrl(number); |
| 1342 | if (url == null) { |
| 1343 | return; |
| 1344 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1345 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1346 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1347 | PhoneConstants.State state = mCM.getState(subId); |
| 1348 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1349 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1350 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1351 | mApp.startActivity(intent); |
| 1352 | } |
| 1353 | } finally { |
| 1354 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1359 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1362 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1363 | if (DBG) log("call: " + number); |
| 1364 | |
| 1365 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1366 | // need to do a permission check since we're calling startActivity() |
| 1367 | // from the context of the phone app. |
| 1368 | enforceCallPermission(); |
| 1369 | |
| 1370 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1371 | != AppOpsManager.MODE_ALLOWED) { |
| 1372 | return; |
| 1373 | } |
| 1374 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1375 | final long identity = Binder.clearCallingIdentity(); |
| 1376 | try { |
| 1377 | String url = createTelUrl(number); |
| 1378 | if (url == null) { |
| 1379 | return; |
| 1380 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1381 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1382 | boolean isValid = false; |
| 1383 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1384 | if (slist != null) { |
| 1385 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1386 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1387 | isValid = true; |
| 1388 | break; |
| 1389 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1390 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1391 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1392 | if (!isValid) { |
| 1393 | return; |
| 1394 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1395 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1396 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1397 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1398 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1399 | mApp.startActivity(intent); |
| 1400 | } finally { |
| 1401 | Binder.restoreCallingIdentity(identity); |
| 1402 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1405 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1406 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1409 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1410 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1411 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1412 | } |
| 1413 | |
| 1414 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1415 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1418 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1419 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1420 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1421 | } |
| 1422 | |
| 1423 | /** {@hide} */ |
| 1424 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1425 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1428 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1429 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1430 | |
| 1431 | final long identity = Binder.clearCallingIdentity(); |
| 1432 | try { |
| 1433 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1434 | checkSimPin.start(); |
| 1435 | return checkSimPin.unlockSim(null, pin); |
| 1436 | } finally { |
| 1437 | Binder.restoreCallingIdentity(identity); |
| 1438 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1441 | /** {@hide} */ |
| 1442 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1443 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1446 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1447 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1448 | |
| 1449 | final long identity = Binder.clearCallingIdentity(); |
| 1450 | try { |
| 1451 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1452 | checkSimPuk.start(); |
| 1453 | return checkSimPuk.unlockSim(puk, pin); |
| 1454 | } finally { |
| 1455 | Binder.restoreCallingIdentity(identity); |
| 1456 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1460 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1461 | * a synchronous one. |
| 1462 | */ |
| 1463 | private static class UnlockSim extends Thread { |
| 1464 | |
| 1465 | private final IccCard mSimCard; |
| 1466 | |
| 1467 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1468 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1469 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1470 | |
| 1471 | // For replies from SimCard interface |
| 1472 | private Handler mHandler; |
| 1473 | |
| 1474 | // For async handler to identify request type |
| 1475 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1476 | |
| 1477 | public UnlockSim(IccCard simCard) { |
| 1478 | mSimCard = simCard; |
| 1479 | } |
| 1480 | |
| 1481 | @Override |
| 1482 | public void run() { |
| 1483 | Looper.prepare(); |
| 1484 | synchronized (UnlockSim.this) { |
| 1485 | mHandler = new Handler() { |
| 1486 | @Override |
| 1487 | public void handleMessage(Message msg) { |
| 1488 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1489 | switch (msg.what) { |
| 1490 | case SUPPLY_PIN_COMPLETE: |
| 1491 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1492 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1493 | mRetryCount = msg.arg1; |
| 1494 | if (ar.exception != null) { |
| 1495 | if (ar.exception instanceof CommandException && |
| 1496 | ((CommandException)(ar.exception)).getCommandError() |
| 1497 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1498 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1499 | } else { |
| 1500 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1501 | } |
| 1502 | } else { |
| 1503 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1504 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1505 | mDone = true; |
| 1506 | UnlockSim.this.notifyAll(); |
| 1507 | } |
| 1508 | break; |
| 1509 | } |
| 1510 | } |
| 1511 | }; |
| 1512 | UnlockSim.this.notifyAll(); |
| 1513 | } |
| 1514 | Looper.loop(); |
| 1515 | } |
| 1516 | |
| 1517 | /* |
| 1518 | * Use PIN or PUK to unlock SIM card |
| 1519 | * |
| 1520 | * If PUK is null, unlock SIM card with PIN |
| 1521 | * |
| 1522 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1523 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1524 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1525 | |
| 1526 | while (mHandler == null) { |
| 1527 | try { |
| 1528 | wait(); |
| 1529 | } catch (InterruptedException e) { |
| 1530 | Thread.currentThread().interrupt(); |
| 1531 | } |
| 1532 | } |
| 1533 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1534 | |
| 1535 | if (puk == null) { |
| 1536 | mSimCard.supplyPin(pin, callback); |
| 1537 | } else { |
| 1538 | mSimCard.supplyPuk(puk, pin, callback); |
| 1539 | } |
| 1540 | |
| 1541 | while (!mDone) { |
| 1542 | try { |
| 1543 | Log.d(LOG_TAG, "wait for done"); |
| 1544 | wait(); |
| 1545 | } catch (InterruptedException e) { |
| 1546 | // Restore the interrupted status |
| 1547 | Thread.currentThread().interrupt(); |
| 1548 | } |
| 1549 | } |
| 1550 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1551 | int[] resultArray = new int[2]; |
| 1552 | resultArray[0] = mResult; |
| 1553 | resultArray[1] = mRetryCount; |
| 1554 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1559 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1560 | |
| 1561 | } |
| 1562 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1563 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1564 | // No permission check needed here: this call is harmless, and it's |
| 1565 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1566 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1567 | final long identity = Binder.clearCallingIdentity(); |
| 1568 | try { |
| 1569 | final Phone phone = getPhone(subId); |
| 1570 | if (phone != null) { |
| 1571 | phone.updateServiceLocation(); |
| 1572 | } |
| 1573 | } finally { |
| 1574 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1575 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1578 | @Override |
| 1579 | public boolean isRadioOn(String callingPackage) { |
| 1580 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1583 | @Override |
| 1584 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1585 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1586 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1587 | return false; |
| 1588 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1589 | |
| 1590 | final long identity = Binder.clearCallingIdentity(); |
| 1591 | try { |
| 1592 | return isRadioOnForSubscriber(subId); |
| 1593 | } finally { |
| 1594 | Binder.restoreCallingIdentity(identity); |
| 1595 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1599 | final long identity = Binder.clearCallingIdentity(); |
| 1600 | try { |
| 1601 | final Phone phone = getPhone(subId); |
| 1602 | if (phone != null) { |
| 1603 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1604 | } else { |
| 1605 | return false; |
| 1606 | } |
| 1607 | } finally { |
| 1608 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1609 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1613 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1614 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1615 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1616 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1617 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1618 | |
| 1619 | final long identity = Binder.clearCallingIdentity(); |
| 1620 | try { |
| 1621 | final Phone phone = getPhone(subId); |
| 1622 | if (phone != null) { |
| 1623 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1624 | } |
| 1625 | } finally { |
| 1626 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1627 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1631 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1634 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1635 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1636 | |
| 1637 | final long identity = Binder.clearCallingIdentity(); |
| 1638 | try { |
| 1639 | final Phone phone = getPhone(subId); |
| 1640 | if (phone == null) { |
| 1641 | return false; |
| 1642 | } |
| 1643 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1644 | toggleRadioOnOffForSubscriber(subId); |
| 1645 | } |
| 1646 | return true; |
| 1647 | } finally { |
| 1648 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1649 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1650 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1651 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1652 | public boolean needMobileRadioShutdown() { |
| 1653 | /* |
| 1654 | * If any of the Radios are available, it will need to be |
| 1655 | * shutdown. So return true if any Radio is available. |
| 1656 | */ |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1657 | final long identity = Binder.clearCallingIdentity(); |
| 1658 | try { |
| 1659 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1660 | Phone phone = PhoneFactory.getPhone(i); |
| 1661 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1662 | } |
| 1663 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1664 | return false; |
| 1665 | } finally { |
| 1666 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1667 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1670 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1671 | public void shutdownMobileRadios() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1672 | enforceModifyPermission(); |
| 1673 | |
| 1674 | final long identity = Binder.clearCallingIdentity(); |
| 1675 | try { |
| 1676 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1677 | logv("Shutting down Phone " + i); |
| 1678 | shutdownRadioUsingPhoneId(i); |
| 1679 | } |
| 1680 | } finally { |
| 1681 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1686 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1687 | if (phone != null && phone.isRadioAvailable()) { |
| 1688 | phone.shutdownRadio(); |
| 1689 | } |
| 1690 | } |
| 1691 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1692 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1693 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1694 | |
| 1695 | final long identity = Binder.clearCallingIdentity(); |
| 1696 | try { |
| 1697 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1698 | if (defaultPhone != null) { |
| 1699 | defaultPhone.setRadioPower(turnOn); |
| 1700 | return true; |
| 1701 | } else { |
| 1702 | loge("There's no default phone."); |
| 1703 | return false; |
| 1704 | } |
| 1705 | } finally { |
| 1706 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1707 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1710 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1711 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1712 | |
| 1713 | final long identity = Binder.clearCallingIdentity(); |
| 1714 | try { |
| 1715 | final Phone phone = getPhone(subId); |
| 1716 | if (phone != null) { |
| 1717 | phone.setRadioPower(turnOn); |
| 1718 | return true; |
| 1719 | } else { |
| 1720 | return false; |
| 1721 | } |
| 1722 | } finally { |
| 1723 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1724 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1727 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1728 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1729 | public boolean enableDataConnectivity() { |
| 1730 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1731 | |
| 1732 | final long identity = Binder.clearCallingIdentity(); |
| 1733 | try { |
| 1734 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1735 | final Phone phone = getPhone(subId); |
| 1736 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1737 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1738 | return true; |
| 1739 | } else { |
| 1740 | return false; |
| 1741 | } |
| 1742 | } finally { |
| 1743 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1744 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1747 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1748 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1749 | public boolean disableDataConnectivity() { |
| 1750 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1751 | |
| 1752 | final long identity = Binder.clearCallingIdentity(); |
| 1753 | try { |
| 1754 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1755 | final Phone phone = getPhone(subId); |
| 1756 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1757 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1758 | return true; |
| 1759 | } else { |
| 1760 | return false; |
| 1761 | } |
| 1762 | } finally { |
| 1763 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1764 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1767 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1768 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1769 | final long identity = Binder.clearCallingIdentity(); |
| 1770 | try { |
| 1771 | final Phone phone = getPhone(subId); |
| 1772 | if (phone != null) { |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1773 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1774 | } else { |
| 1775 | return false; |
| 1776 | } |
| 1777 | } finally { |
| 1778 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1779 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1783 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1786 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1787 | enforceCallPermission(); |
| 1788 | |
| 1789 | final long identity = Binder.clearCallingIdentity(); |
| 1790 | try { |
| 1791 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1792 | return; |
| 1793 | } |
| 1794 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1795 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1796 | } finally { |
| 1797 | Binder.restoreCallingIdentity(identity); |
| 1798 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1799 | }; |
| 1800 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1801 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1802 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1803 | |
| 1804 | final long identity = Binder.clearCallingIdentity(); |
| 1805 | try { |
| 1806 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1807 | return false; |
| 1808 | } |
| 1809 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1810 | } finally { |
| 1811 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1812 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1815 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1816 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1819 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1820 | final long identity = Binder.clearCallingIdentity(); |
| 1821 | try { |
| 1822 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1823 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1824 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1825 | } finally { |
| 1826 | Binder.restoreCallingIdentity(identity); |
| 1827 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1828 | } |
| 1829 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1830 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1831 | public int getDataState() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1832 | final long identity = Binder.clearCallingIdentity(); |
| 1833 | try { |
| 1834 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1835 | if (phone != null) { |
| 1836 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1837 | } else { |
| 1838 | return PhoneConstantConversions.convertDataState( |
| 1839 | PhoneConstants.DataState.DISCONNECTED); |
| 1840 | } |
| 1841 | } finally { |
| 1842 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1843 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1846 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1847 | public int getDataActivity() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1848 | final long identity = Binder.clearCallingIdentity(); |
| 1849 | try { |
| 1850 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1851 | if (phone != null) { |
| 1852 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1853 | } else { |
| 1854 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1855 | } |
| 1856 | } finally { |
| 1857 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1858 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1862 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1863 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1864 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1865 | |
| 1866 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1867 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1868 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1869 | .setCallingPackage(callingPackage) |
| 1870 | .setCallingPid(Binder.getCallingPid()) |
| 1871 | .setCallingUid(Binder.getCallingUid()) |
| 1872 | .setMethod("getCellLocation") |
| 1873 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1874 | .build()); |
| 1875 | switch (locationResult) { |
| 1876 | case DENIED_HARD: |
| 1877 | throw new SecurityException("Not allowed to access cell location"); |
| 1878 | case DENIED_SOFT: |
| 1879 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1882 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1883 | final long identity = Binder.clearCallingIdentity(); |
| 1884 | try { |
| 1885 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1886 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1887 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1888 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1889 | cl.fillInNotifierBundle(data); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1890 | return data; |
| 1891 | } finally { |
| 1892 | Binder.restoreCallingIdentity(identity); |
| 1893 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1896 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1897 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1898 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1899 | // registered cell info, so return a NULL country instead. |
| 1900 | final long identity = Binder.clearCallingIdentity(); |
| 1901 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1902 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1903 | // Get default phone in this case. |
| 1904 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1905 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1906 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1907 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1908 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1909 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1910 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1911 | return ""; |
| 1912 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1913 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1914 | if (phone != null) { |
| 1915 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1916 | if (sst != null) { |
| 1917 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1918 | if (lt != null) { |
| 1919 | return lt.getCurrentCountry(); |
| 1920 | } |
| 1921 | } |
| 1922 | } |
| 1923 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1924 | } finally { |
| 1925 | Binder.restoreCallingIdentity(identity); |
| 1926 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1930 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1931 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1934 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1935 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1936 | mApp.enforceCallingOrSelfPermission( |
| 1937 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1938 | |
| 1939 | final long identity = Binder.clearCallingIdentity(); |
| 1940 | try { |
| 1941 | final Phone phone = getPhone(subId); |
| 1942 | if (phone != null) { |
| 1943 | phone.enableLocationUpdates(); |
| 1944 | } |
| 1945 | } finally { |
| 1946 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1947 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | @Override |
| 1951 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1952 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1955 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1956 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1957 | mApp.enforceCallingOrSelfPermission( |
| 1958 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1959 | |
| 1960 | final long identity = Binder.clearCallingIdentity(); |
| 1961 | try { |
| 1962 | final Phone phone = getPhone(subId); |
| 1963 | if (phone != null) { |
| 1964 | phone.disableLocationUpdates(); |
| 1965 | } |
| 1966 | } finally { |
| 1967 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1968 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1971 | /** |
| 1972 | * Returns the target SDK version number for a given package name. |
| 1973 | * |
| 1974 | * @return target SDK if the package is found or INT_MAX. |
| 1975 | */ |
| 1976 | private int getTargetSdk(String packageName) { |
| 1977 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1978 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 1979 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1980 | if (ai != null) return ai.targetSdkVersion; |
| 1981 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1982 | } |
| 1983 | return Integer.MAX_VALUE; |
| 1984 | } |
| 1985 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1986 | @Override |
| 1987 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1988 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1989 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1990 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1991 | throw new SecurityException( |
| 1992 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1993 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1994 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1995 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1996 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1997 | return null; |
| 1998 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1999 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2000 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2001 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2002 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2003 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2004 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2005 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2006 | for (CellInfo ci : info) { |
| 2007 | if (ci instanceof CellInfoGsm) { |
| 2008 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2009 | } else if (ci instanceof CellInfoWcdma) { |
| 2010 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2011 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2012 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2013 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2016 | private List<CellInfo> getCachedCellInfo() { |
| 2017 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2018 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2019 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2020 | if (info != null) cellInfos.addAll(info); |
| 2021 | } |
| 2022 | return cellInfos; |
| 2023 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2024 | |
| 2025 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2026 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2027 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2028 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2029 | |
| 2030 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2031 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2032 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2033 | .setCallingPackage(callingPackage) |
| 2034 | .setCallingPid(Binder.getCallingPid()) |
| 2035 | .setCallingUid(Binder.getCallingUid()) |
| 2036 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2037 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2038 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2039 | .build()); |
| 2040 | switch (locationResult) { |
| 2041 | case DENIED_HARD: |
| 2042 | throw new SecurityException("Not allowed to access cell info"); |
| 2043 | case DENIED_SOFT: |
| 2044 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2047 | final int targetSdk = getTargetSdk(callingPackage); |
| 2048 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2049 | return getCachedCellInfo(); |
| 2050 | } |
| 2051 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2052 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2053 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2054 | final long identity = Binder.clearCallingIdentity(); |
| 2055 | try { |
| 2056 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2057 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2058 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2059 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2060 | if (info != null) cellInfos.addAll(info); |
| 2061 | } |
| 2062 | return cellInfos; |
| 2063 | } finally { |
| 2064 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2065 | } |
| 2066 | } |
| 2067 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2068 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2069 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2070 | requestCellInfoUpdateInternal( |
| 2071 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2072 | } |
| 2073 | |
| 2074 | @Override |
| 2075 | public void requestCellInfoUpdateWithWorkSource( |
| 2076 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2077 | enforceModifyPermission(); |
| 2078 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2079 | } |
| 2080 | |
| 2081 | private void requestCellInfoUpdateInternal( |
| 2082 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2083 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2084 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2085 | |
| 2086 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2087 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2088 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2089 | .setCallingPackage(callingPackage) |
| 2090 | .setCallingPid(Binder.getCallingPid()) |
| 2091 | .setCallingUid(Binder.getCallingUid()) |
| 2092 | .setMethod("requestCellInfoUpdate") |
| 2093 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2094 | .build()); |
| 2095 | switch (locationResult) { |
| 2096 | case DENIED_HARD: |
| 2097 | throw new SecurityException("Not allowed to access cell info"); |
| 2098 | case DENIED_SOFT: |
| 2099 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | final Phone phone = getPhone(subId); |
| 2103 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2104 | |
| 2105 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2106 | } |
| 2107 | |
| 2108 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2109 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2110 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2111 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2112 | |
| 2113 | final long identity = Binder.clearCallingIdentity(); |
| 2114 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2115 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2116 | } finally { |
| 2117 | Binder.restoreCallingIdentity(identity); |
| 2118 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2119 | } |
| 2120 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2121 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2122 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2123 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2124 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2125 | return null; |
| 2126 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2127 | int subId = phone.getSubId(); |
| 2128 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2129 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 2130 | return null; |
| 2131 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2132 | |
| 2133 | final long identity = Binder.clearCallingIdentity(); |
| 2134 | try { |
| 2135 | return phone.getImei(); |
| 2136 | } finally { |
| 2137 | Binder.restoreCallingIdentity(identity); |
| 2138 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2142 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2143 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2144 | String tac = null; |
| 2145 | if (phone != null) { |
| 2146 | String imei = phone.getImei(); |
| 2147 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2148 | } |
| 2149 | return tac; |
| 2150 | } |
| 2151 | |
| 2152 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2153 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2154 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2155 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2156 | return null; |
| 2157 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2158 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2159 | int subId = phone.getSubId(); |
| 2160 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2161 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 2162 | return null; |
| 2163 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2164 | |
| 2165 | final long identity = Binder.clearCallingIdentity(); |
| 2166 | try { |
| 2167 | return phone.getMeid(); |
| 2168 | } finally { |
| 2169 | Binder.restoreCallingIdentity(identity); |
| 2170 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2174 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2175 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2176 | String manufacturerCode = null; |
| 2177 | if (phone != null) { |
| 2178 | String meid = phone.getMeid(); |
| 2179 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2180 | } |
| 2181 | return manufacturerCode; |
| 2182 | } |
| 2183 | |
| 2184 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2185 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2186 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2187 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2188 | return null; |
| 2189 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2190 | int subId = phone.getSubId(); |
| 2191 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2192 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2193 | return null; |
| 2194 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2195 | |
| 2196 | final long identity = Binder.clearCallingIdentity(); |
| 2197 | try { |
| 2198 | return phone.getDeviceSvn(); |
| 2199 | } finally { |
| 2200 | Binder.restoreCallingIdentity(identity); |
| 2201 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2204 | @Override |
| 2205 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2206 | final long identity = Binder.clearCallingIdentity(); |
| 2207 | try { |
| 2208 | final Phone phone = getPhone(subId); |
| 2209 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2210 | } finally { |
| 2211 | Binder.restoreCallingIdentity(identity); |
| 2212 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | @Override |
| 2216 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2217 | final long identity = Binder.clearCallingIdentity(); |
| 2218 | try { |
| 2219 | final Phone phone = getPhone(subId); |
| 2220 | return phone == null ? null : phone.getCarrierName(); |
| 2221 | } finally { |
| 2222 | Binder.restoreCallingIdentity(identity); |
| 2223 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2224 | } |
| 2225 | |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2226 | @Override |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2227 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2228 | final long identity = Binder.clearCallingIdentity(); |
| 2229 | try { |
| 2230 | final Phone phone = getPhone(subId); |
| 2231 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2232 | : phone.getSpecificCarrierId(); |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2233 | } finally { |
| 2234 | Binder.restoreCallingIdentity(identity); |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | @Override |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2239 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2240 | final long identity = Binder.clearCallingIdentity(); |
| 2241 | try { |
| 2242 | final Phone phone = getPhone(subId); |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2243 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2244 | } finally { |
| 2245 | Binder.restoreCallingIdentity(identity); |
| 2246 | } |
| 2247 | } |
| 2248 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2249 | @Override |
chen xu | 4ca4e69 | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2250 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2251 | if (!isSubscriptionMccMnc) { |
| 2252 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2253 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2254 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2255 | if (phone == null) { |
| 2256 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2257 | } |
| 2258 | final long identity = Binder.clearCallingIdentity(); |
| 2259 | try { |
| 2260 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2261 | } finally { |
| 2262 | Binder.restoreCallingIdentity(identity); |
| 2263 | } |
| 2264 | } |
| 2265 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2266 | // |
| 2267 | // Internal helper methods. |
| 2268 | // |
| 2269 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2270 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2271 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2272 | * |
| 2273 | * @throws SecurityException if the caller does not have the required permission |
| 2274 | */ |
| 2275 | private void enforceModifyPermission() { |
| 2276 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2277 | } |
| 2278 | |
| 2279 | /** |
| 2280 | * Make sure the caller has the CALL_PHONE permission. |
| 2281 | * |
| 2282 | * @throws SecurityException if the caller does not have the required permission |
| 2283 | */ |
| 2284 | private void enforceCallPermission() { |
| 2285 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2286 | } |
| 2287 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2288 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2289 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2290 | "ConnectivityService"); |
| 2291 | } |
| 2292 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2293 | private String createTelUrl(String number) { |
| 2294 | if (TextUtils.isEmpty(number)) { |
| 2295 | return null; |
| 2296 | } |
| 2297 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2298 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2299 | } |
| 2300 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2301 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2302 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2303 | } |
| 2304 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2305 | private static void logv(String msg) { |
| 2306 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2307 | } |
| 2308 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2309 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2310 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2311 | } |
| 2312 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2313 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2315 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2316 | } |
| 2317 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2318 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2319 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2320 | final long identity = Binder.clearCallingIdentity(); |
| 2321 | try { |
| 2322 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2323 | if (phone == null) { |
| 2324 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2325 | } else { |
| 2326 | return phone.getPhoneType(); |
| 2327 | } |
| 2328 | } finally { |
| 2329 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2330 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | /** |
| 2334 | * Returns the CDMA ERI icon index to display |
| 2335 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2336 | @Override |
| 2337 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2338 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2341 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2342 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2343 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2344 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2345 | return -1; |
| 2346 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2347 | |
| 2348 | final long identity = Binder.clearCallingIdentity(); |
| 2349 | try { |
| 2350 | final Phone phone = getPhone(subId); |
| 2351 | if (phone != null) { |
| 2352 | return phone.getCdmaEriIconIndex(); |
| 2353 | } else { |
| 2354 | return -1; |
| 2355 | } |
| 2356 | } finally { |
| 2357 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2358 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | /** |
| 2362 | * Returns the CDMA ERI icon mode, |
| 2363 | * 0 - ON |
| 2364 | * 1 - FLASHING |
| 2365 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2366 | @Override |
| 2367 | public int getCdmaEriIconMode(String callingPackage) { |
| 2368 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2371 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2372 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2373 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2374 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2375 | return -1; |
| 2376 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2377 | |
| 2378 | final long identity = Binder.clearCallingIdentity(); |
| 2379 | try { |
| 2380 | final Phone phone = getPhone(subId); |
| 2381 | if (phone != null) { |
| 2382 | return phone.getCdmaEriIconMode(); |
| 2383 | } else { |
| 2384 | return -1; |
| 2385 | } |
| 2386 | } finally { |
| 2387 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2388 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | /** |
| 2392 | * Returns the CDMA ERI text, |
| 2393 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2394 | @Override |
| 2395 | public String getCdmaEriText(String callingPackage) { |
| 2396 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2397 | } |
| 2398 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2399 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2400 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2401 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2402 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2403 | return null; |
| 2404 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2405 | |
| 2406 | final long identity = Binder.clearCallingIdentity(); |
| 2407 | try { |
| 2408 | final Phone phone = getPhone(subId); |
| 2409 | if (phone != null) { |
| 2410 | return phone.getCdmaEriText(); |
| 2411 | } else { |
| 2412 | return null; |
| 2413 | } |
| 2414 | } finally { |
| 2415 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2416 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2420 | * Returns the CDMA MDN. |
| 2421 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2422 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2423 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2424 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2425 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2426 | |
| 2427 | final long identity = Binder.clearCallingIdentity(); |
| 2428 | try { |
| 2429 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2430 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2431 | return phone.getLine1Number(); |
| 2432 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2433 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2434 | return null; |
| 2435 | } |
| 2436 | } finally { |
| 2437 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | /** |
| 2442 | * Returns the CDMA MIN. |
| 2443 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2444 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2445 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2446 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2447 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2448 | |
| 2449 | final long identity = Binder.clearCallingIdentity(); |
| 2450 | try { |
| 2451 | final Phone phone = getPhone(subId); |
| 2452 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2453 | return phone.getCdmaMin(); |
| 2454 | } else { |
| 2455 | return null; |
| 2456 | } |
| 2457 | } finally { |
| 2458 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2459 | } |
| 2460 | } |
| 2461 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2462 | @Override |
| 2463 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2464 | INumberVerificationCallback callback, String callingPackage) { |
| 2465 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2466 | != PERMISSION_GRANTED) { |
| 2467 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2468 | } |
| 2469 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2470 | |
| 2471 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2472 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2473 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2474 | } |
| 2475 | |
| 2476 | if (range == null) { |
| 2477 | throw new NullPointerException("Range must be non-null"); |
| 2478 | } |
| 2479 | |
| 2480 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2481 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2482 | |
| 2483 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2484 | } |
| 2485 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2486 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2487 | * Returns true if CDMA provisioning needs to run. |
| 2488 | */ |
| 2489 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2490 | final long identity = Binder.clearCallingIdentity(); |
| 2491 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2492 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2493 | } finally { |
| 2494 | Binder.restoreCallingIdentity(identity); |
| 2495 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2499 | * Sets the voice mail number of a given subId. |
| 2500 | */ |
| 2501 | @Override |
| 2502 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2503 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2504 | |
| 2505 | final long identity = Binder.clearCallingIdentity(); |
| 2506 | try { |
| 2507 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2508 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2509 | return success; |
| 2510 | } finally { |
| 2511 | Binder.restoreCallingIdentity(identity); |
| 2512 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2513 | } |
| 2514 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2515 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2516 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2517 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2518 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2519 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2520 | throw new SecurityException("caller must be system dialer"); |
| 2521 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2522 | |
| 2523 | final long identity = Binder.clearCallingIdentity(); |
| 2524 | try { |
| 2525 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2526 | if (phoneAccountHandle == null) { |
| 2527 | return null; |
| 2528 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2529 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2530 | } finally { |
| 2531 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2532 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2533 | } |
| 2534 | |
| 2535 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2536 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2537 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2538 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2539 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2540 | return null; |
| 2541 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2542 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2543 | final long identity = Binder.clearCallingIdentity(); |
| 2544 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2545 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2546 | } finally { |
| 2547 | Binder.restoreCallingIdentity(identity); |
| 2548 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2552 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2553 | VisualVoicemailSmsFilterSettings settings) { |
| 2554 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2555 | |
| 2556 | final long identity = Binder.clearCallingIdentity(); |
| 2557 | try { |
| 2558 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2559 | mApp, callingPackage, subId, settings); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2560 | } finally { |
| 2561 | Binder.restoreCallingIdentity(identity); |
| 2562 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2566 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2567 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2568 | |
| 2569 | final long identity = Binder.clearCallingIdentity(); |
| 2570 | try { |
| 2571 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2572 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2573 | } finally { |
| 2574 | Binder.restoreCallingIdentity(identity); |
| 2575 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2579 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2580 | String callingPackage, int subId) { |
| 2581 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2582 | |
| 2583 | final long identity = Binder.clearCallingIdentity(); |
| 2584 | try { |
| 2585 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2586 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2587 | } finally { |
| 2588 | Binder.restoreCallingIdentity(identity); |
| 2589 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2593 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2594 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2595 | |
| 2596 | final long identity = Binder.clearCallingIdentity(); |
| 2597 | try { |
| 2598 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2599 | mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2600 | } finally { |
| 2601 | Binder.restoreCallingIdentity(identity); |
| 2602 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | @Override |
| 2606 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2607 | String number, int port, String text, PendingIntent sentIntent) { |
| 2608 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2609 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2610 | enforceSendSmsPermission(); |
| 2611 | // Make the calls as the phone process. |
| 2612 | final long identity = Binder.clearCallingIdentity(); |
| 2613 | try { |
| 2614 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2615 | if (port == 0) { |
| 2616 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2617 | sentIntent, null, false); |
| 2618 | } else { |
| 2619 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2620 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2621 | (short) port, data, sentIntent, null); |
| 2622 | } |
| 2623 | } finally { |
| 2624 | Binder.restoreCallingIdentity(identity); |
| 2625 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2626 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2627 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2628 | * Sets the voice activation state of a given subId. |
| 2629 | */ |
| 2630 | @Override |
| 2631 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2632 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2633 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2634 | |
| 2635 | final long identity = Binder.clearCallingIdentity(); |
| 2636 | try { |
| 2637 | final Phone phone = getPhone(subId); |
| 2638 | if (phone != null) { |
| 2639 | phone.setVoiceActivationState(activationState); |
| 2640 | } else { |
| 2641 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2642 | } |
| 2643 | } finally { |
| 2644 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | /** |
| 2649 | * Sets the data activation state of a given subId. |
| 2650 | */ |
| 2651 | @Override |
| 2652 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2653 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2654 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2655 | |
| 2656 | final long identity = Binder.clearCallingIdentity(); |
| 2657 | try { |
| 2658 | final Phone phone = getPhone(subId); |
| 2659 | if (phone != null) { |
| 2660 | phone.setDataActivationState(activationState); |
| 2661 | } else { |
| 2662 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2663 | } |
| 2664 | } finally { |
| 2665 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2666 | } |
| 2667 | } |
| 2668 | |
| 2669 | /** |
| 2670 | * Returns the voice activation state of a given subId. |
| 2671 | */ |
| 2672 | @Override |
| 2673 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2674 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2675 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2676 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2677 | final long identity = Binder.clearCallingIdentity(); |
| 2678 | try { |
| 2679 | if (phone != null) { |
| 2680 | return phone.getVoiceActivationState(); |
| 2681 | } else { |
| 2682 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2683 | } |
| 2684 | } finally { |
| 2685 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2686 | } |
| 2687 | } |
| 2688 | |
| 2689 | /** |
| 2690 | * Returns the data activation state of a given subId. |
| 2691 | */ |
| 2692 | @Override |
| 2693 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2694 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2695 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2696 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2697 | final long identity = Binder.clearCallingIdentity(); |
| 2698 | try { |
| 2699 | if (phone != null) { |
| 2700 | return phone.getDataActivationState(); |
| 2701 | } else { |
| 2702 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2703 | } |
| 2704 | } finally { |
| 2705 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2710 | * Returns the unread count of voicemails for a subId |
| 2711 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2712 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2713 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2714 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2715 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2716 | return 0; |
| 2717 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2718 | final long identity = Binder.clearCallingIdentity(); |
| 2719 | try { |
| 2720 | final Phone phone = getPhone(subId); |
| 2721 | if (phone != null) { |
| 2722 | return phone.getVoiceMessageCount(); |
| 2723 | } else { |
| 2724 | return 0; |
| 2725 | } |
| 2726 | } finally { |
| 2727 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2728 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2732 | * returns true, if the device is in a state where both voice and data |
| 2733 | * are supported simultaneously. This can change based on location or network condition. |
| 2734 | */ |
| 2735 | @Override |
| 2736 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2737 | final long identity = Binder.clearCallingIdentity(); |
| 2738 | try { |
| 2739 | final Phone phone = getPhone(subId); |
| 2740 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2741 | } finally { |
| 2742 | Binder.restoreCallingIdentity(identity); |
| 2743 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2747 | * Send the dialer code if called from the current default dialer or the caller has |
| 2748 | * carrier privilege. |
| 2749 | * @param inputCode The dialer code to send |
| 2750 | */ |
| 2751 | @Override |
| 2752 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2753 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2754 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2755 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2756 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2757 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2758 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2759 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2760 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2761 | |
| 2762 | final long identity = Binder.clearCallingIdentity(); |
| 2763 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2764 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2765 | } finally { |
| 2766 | Binder.restoreCallingIdentity(identity); |
| 2767 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2771 | * Returns the data network type. |
| 2772 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2773 | * |
| 2774 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2775 | */ |
| 2776 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2777 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2778 | final long identity = Binder.clearCallingIdentity(); |
| 2779 | try { |
| 2780 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2781 | if (phone != null) { |
| 2782 | return phone.getServiceState().getDataNetworkType(); |
| 2783 | } else { |
| 2784 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2785 | } |
| 2786 | } finally { |
| 2787 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2788 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2791 | @Override |
| 2792 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2793 | if (!isActiveSubscription(subId)) { |
| 2794 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2795 | } |
| 2796 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2797 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2798 | } |
| 2799 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2800 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2801 | public boolean isInEmergencySmsMode() { |
| 2802 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2803 | final long identity = Binder.clearCallingIdentity(); |
| 2804 | try { |
| 2805 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2806 | if (phone.isInEmergencySmsMode()) { |
| 2807 | return true; |
| 2808 | } |
| 2809 | } |
| 2810 | } finally { |
| 2811 | Binder.restoreCallingIdentity(identity); |
| 2812 | } |
| 2813 | return false; |
| 2814 | } |
| 2815 | |
| 2816 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2817 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2818 | throws RemoteException { |
| 2819 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2820 | final long token = Binder.clearCallingIdentity(); |
| 2821 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2822 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2823 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2824 | .addRegistrationCallbackForSubscription(c, subId); |
| 2825 | } finally { |
| 2826 | Binder.restoreCallingIdentity(token); |
| 2827 | } |
| 2828 | } |
| 2829 | |
| 2830 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2831 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2832 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2833 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2834 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2835 | } |
| 2836 | Binder.withCleanCallingIdentity(() -> { |
| 2837 | try { |
| 2838 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2839 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2840 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2841 | } catch (IllegalArgumentException e) { |
| 2842 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2843 | + "is inactive, ignoring unregister."); |
| 2844 | // If the subscription is no longer active, just return, since the callback |
| 2845 | // will already have been removed internally. |
| 2846 | } |
| 2847 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2851 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2852 | throws RemoteException { |
| 2853 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2854 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2855 | final long token = Binder.clearCallingIdentity(); |
| 2856 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2857 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2858 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2859 | } finally { |
| 2860 | Binder.restoreCallingIdentity(token); |
| 2861 | } |
| 2862 | } |
| 2863 | |
| 2864 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2865 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2866 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2867 | |
| 2868 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2869 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2870 | } |
| 2871 | Binder.withCleanCallingIdentity(() -> { |
| 2872 | try { |
| 2873 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2874 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2875 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2876 | } catch (IllegalArgumentException e) { |
| 2877 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2878 | + "is inactive, ignoring unregister."); |
| 2879 | // If the subscription is no longer active, just return, since the callback |
| 2880 | // will already have been removed internally. |
| 2881 | } |
| 2882 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2886 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2887 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2888 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2889 | final long token = Binder.clearCallingIdentity(); |
| 2890 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2891 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2892 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2893 | } catch (ImsException e) { |
| 2894 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2895 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2896 | } catch (IllegalArgumentException e) { |
| 2897 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2898 | return false; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2899 | } finally { |
| 2900 | Binder.restoreCallingIdentity(token); |
| 2901 | } |
| 2902 | } |
| 2903 | |
| 2904 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2905 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2906 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2907 | final long token = Binder.clearCallingIdentity(); |
| 2908 | try { |
| 2909 | Phone phone = getPhone(subId); |
| 2910 | if (phone == null) return false; |
| 2911 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2912 | } finally { |
| 2913 | Binder.restoreCallingIdentity(token); |
| 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | @Override |
| 2918 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2919 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2920 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2921 | final long token = Binder.clearCallingIdentity(); |
| 2922 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2923 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2924 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2925 | } finally { |
| 2926 | Binder.restoreCallingIdentity(token); |
| 2927 | } |
| 2928 | } |
| 2929 | |
| 2930 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2931 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2932 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2933 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2934 | final long identity = Binder.clearCallingIdentity(); |
| 2935 | try { |
| 2936 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2937 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2938 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2939 | } finally { |
| 2940 | Binder.restoreCallingIdentity(identity); |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2945 | public boolean isVtSettingEnabled(int subId) { |
| 2946 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2947 | final long identity = Binder.clearCallingIdentity(); |
| 2948 | try { |
| 2949 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2950 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2951 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2952 | } finally { |
| 2953 | Binder.restoreCallingIdentity(identity); |
| 2954 | } |
| 2955 | } |
| 2956 | |
| 2957 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2958 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2959 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2960 | "setVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2961 | final long identity = Binder.clearCallingIdentity(); |
| 2962 | try { |
| 2963 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2964 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2965 | } finally { |
| 2966 | Binder.restoreCallingIdentity(identity); |
| 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | @Override |
| 2971 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2972 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2973 | final long identity = Binder.clearCallingIdentity(); |
| 2974 | try { |
| 2975 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2976 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2977 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2978 | } finally { |
| 2979 | Binder.restoreCallingIdentity(identity); |
| 2980 | } |
| 2981 | } |
| 2982 | |
| 2983 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2984 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2985 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2986 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2987 | final long identity = Binder.clearCallingIdentity(); |
| 2988 | try { |
| 2989 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2990 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2991 | } finally { |
| 2992 | Binder.restoreCallingIdentity(identity); |
| 2993 | } |
| 2994 | } |
| 2995 | |
| 2996 | @Override |
| 2997 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2998 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2999 | final long identity = Binder.clearCallingIdentity(); |
| 3000 | try { |
| 3001 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3002 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3003 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 3004 | } finally { |
| 3005 | Binder.restoreCallingIdentity(identity); |
| 3006 | } |
| 3007 | } |
| 3008 | |
| 3009 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3010 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3011 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3012 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3013 | final long identity = Binder.clearCallingIdentity(); |
| 3014 | try { |
| 3015 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3016 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3017 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 3018 | } finally { |
| 3019 | Binder.restoreCallingIdentity(identity); |
| 3020 | } |
| 3021 | } |
| 3022 | |
| 3023 | @Override |
| 3024 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3025 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3026 | "setVoWiFiNonPersistent"); |
| 3027 | final long identity = Binder.clearCallingIdentity(); |
| 3028 | try { |
| 3029 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3030 | boolean isRoaming = TelephonyManager.from( |
| 3031 | getPhone(subId).getContext()).isNetworkRoaming(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3032 | ImsManager.getInstance(mApp, |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3033 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3034 | } finally { |
| 3035 | Binder.restoreCallingIdentity(identity); |
| 3036 | } |
| 3037 | } |
| 3038 | |
| 3039 | @Override |
| 3040 | public int getVoWiFiModeSetting(int subId) { |
| 3041 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3042 | final long identity = Binder.clearCallingIdentity(); |
| 3043 | try { |
| 3044 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3045 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3046 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3047 | } finally { |
| 3048 | Binder.restoreCallingIdentity(identity); |
| 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | @Override |
| 3053 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3054 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3055 | "setVoWiFiModeSetting"); |
| 3056 | final long identity = Binder.clearCallingIdentity(); |
| 3057 | try { |
| 3058 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3059 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3060 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3061 | } finally { |
| 3062 | Binder.restoreCallingIdentity(identity); |
| 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | @Override |
| 3067 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3068 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3069 | final long identity = Binder.clearCallingIdentity(); |
| 3070 | try { |
| 3071 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3072 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3073 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3074 | } finally { |
| 3075 | Binder.restoreCallingIdentity(identity); |
| 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | @Override |
| 3080 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3081 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3082 | "setVoWiFiRoamingModeSetting"); |
| 3083 | final long identity = Binder.clearCallingIdentity(); |
| 3084 | try { |
| 3085 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3086 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3087 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3088 | } finally { |
| 3089 | Binder.restoreCallingIdentity(identity); |
| 3090 | } |
| 3091 | } |
| 3092 | |
| 3093 | @Override |
| 3094 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3095 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3096 | "setRttCapabilityEnabled"); |
| 3097 | final long identity = Binder.clearCallingIdentity(); |
| 3098 | try { |
| 3099 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3100 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3101 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3102 | } finally { |
| 3103 | Binder.restoreCallingIdentity(identity); |
| 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | @Override |
| 3108 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3109 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3110 | final long identity = Binder.clearCallingIdentity(); |
| 3111 | try { |
| 3112 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3113 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3114 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3115 | } finally { |
| 3116 | Binder.restoreCallingIdentity(identity); |
| 3117 | } |
| 3118 | } |
| 3119 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3120 | @Override |
| 3121 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3122 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3123 | final long identity = Binder.clearCallingIdentity(); |
| 3124 | try { |
| 3125 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3126 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3127 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3128 | } finally { |
| 3129 | Binder.restoreCallingIdentity(identity); |
| 3130 | } |
| 3131 | } |
| 3132 | |
| 3133 | @Override |
| 3134 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3135 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3136 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3137 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3138 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3139 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3140 | try { |
| 3141 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3142 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3143 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3144 | } catch (IllegalArgumentException e) { |
| 3145 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3146 | + "is inactive, ignoring unregister."); |
| 3147 | // If the subscription is no longer active, just return, since the callback will already |
| 3148 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3149 | } finally { |
| 3150 | Binder.restoreCallingIdentity(identity); |
| 3151 | } |
| 3152 | } |
| 3153 | |
| 3154 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3155 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3156 | boolean isProvisioned) { |
| 3157 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3158 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3159 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3160 | } |
| 3161 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3162 | "setProvisioningStatusForCapability"); |
| 3163 | final long identity = Binder.clearCallingIdentity(); |
| 3164 | try { |
| 3165 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3166 | Phone phone = getPhone(subId); |
| 3167 | if (phone == null) { |
| 3168 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3169 | + subId); |
| 3170 | return; |
| 3171 | } |
| 3172 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3173 | return; |
| 3174 | } |
| 3175 | |
| 3176 | // this capability requires provisioning, route to the correct API. |
| 3177 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3178 | switch (capability) { |
| 3179 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3180 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3181 | ims.setVolteProvisioned(isProvisioned); |
| 3182 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3183 | ims.setWfcProvisioned(isProvisioned); |
| 3184 | } |
| 3185 | break; |
| 3186 | } |
| 3187 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3188 | // There is currently no difference in VT provisioning type. |
| 3189 | ims.setVtProvisioned(isProvisioned); |
| 3190 | break; |
| 3191 | } |
| 3192 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3193 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3194 | // change the capability of the feature instead if needed. |
| 3195 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3196 | == isProvisioned) { |
| 3197 | // No change in provisioning. |
| 3198 | return; |
| 3199 | } |
| 3200 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3201 | try { |
| 3202 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3203 | } catch (ImsException e) { |
| 3204 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3205 | + ", Exception" + e.getMessage()); |
| 3206 | } |
| 3207 | break; |
| 3208 | } |
| 3209 | default: { |
| 3210 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3211 | + capability + "', which does not require provisioning."); |
| 3212 | } |
| 3213 | } |
| 3214 | |
| 3215 | } finally { |
| 3216 | Binder.restoreCallingIdentity(identity); |
| 3217 | } |
| 3218 | } |
| 3219 | |
| 3220 | @Override |
| 3221 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3222 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3223 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3224 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3225 | } |
| 3226 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3227 | final long identity = Binder.clearCallingIdentity(); |
| 3228 | try { |
| 3229 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3230 | Phone phone = getPhone(subId); |
| 3231 | if (phone == null) { |
| 3232 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3233 | + subId); |
| 3234 | // We will fail with "true" as the provisioning status because this is the default |
| 3235 | // if we do not require provisioning. |
| 3236 | return true; |
| 3237 | } |
| 3238 | |
| 3239 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3240 | return true; |
| 3241 | } |
| 3242 | |
| 3243 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3244 | switch (capability) { |
| 3245 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3246 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3247 | return ims.isVolteProvisionedOnDevice(); |
| 3248 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3249 | return ims.isWfcProvisionedOnDevice(); |
| 3250 | } |
| 3251 | // This should never happen, since we are checking tech above to make sure it |
| 3252 | // is either LTE or IWLAN. |
| 3253 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3254 | + "capability."); |
| 3255 | } |
| 3256 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3257 | // There is currently no difference in VT provisioning type. |
| 3258 | return ims.isVtProvisionedOnDevice(); |
| 3259 | } |
| 3260 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3261 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3262 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3263 | } |
| 3264 | default: { |
| 3265 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3266 | + capability + "', which does not require provisioning."); |
| 3267 | } |
| 3268 | } |
| 3269 | |
| 3270 | } finally { |
| 3271 | Binder.restoreCallingIdentity(identity); |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | @Override |
| 3276 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3277 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3278 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3279 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3280 | } |
| 3281 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3282 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3283 | return (provisionedBits & capability) > 0; |
| 3284 | } |
| 3285 | |
| 3286 | @Override |
| 3287 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3288 | boolean isProvisioned) { |
| 3289 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3290 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3291 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3292 | } |
| 3293 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3294 | "setProvisioningStatusForCapability"); |
| 3295 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3296 | // If the current provisioning status for capability already matches isProvisioned, |
| 3297 | // do nothing. |
| 3298 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3299 | return; |
| 3300 | } |
| 3301 | if (isProvisioned) { |
| 3302 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3303 | } else { |
| 3304 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3305 | } |
| 3306 | } |
| 3307 | |
| 3308 | /** |
| 3309 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3310 | * technology. The bitfield should mirror the bitfield defined by |
| 3311 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3312 | */ |
| 3313 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3314 | String key = getMmTelProvisioningKey(subId, tech); |
| 3315 | // Default is no capabilities are provisioned. |
| 3316 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3317 | } |
| 3318 | |
| 3319 | /** |
| 3320 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3321 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3322 | * technology specified. |
| 3323 | * |
| 3324 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3325 | */ |
| 3326 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3327 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3328 | String key = getMmTelProvisioningKey(subId, tech); |
| 3329 | editor.putInt(key, newField); |
| 3330 | editor.commit(); |
| 3331 | } |
| 3332 | |
| 3333 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3334 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3335 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3336 | } |
| 3337 | |
| 3338 | /** |
| 3339 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3340 | * carrier associated with the subscription id. |
| 3341 | */ |
| 3342 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3343 | int capability) { |
| 3344 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3345 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3346 | boolean requireUtProvisioning = c.getBoolean( |
| 3347 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3348 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3349 | // the no-SIM case, where we would normally shortcut this to false. |
| 3350 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3351 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3352 | false); |
| 3353 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3354 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3355 | |
| 3356 | // First check to make sure that the capability requires provisioning. |
| 3357 | switch (capability) { |
| 3358 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3359 | // intentional fallthrough |
| 3360 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3361 | if (requireVoiceVtProvisioning) { |
| 3362 | // Voice and Video requires provisioning |
| 3363 | return true; |
| 3364 | } |
| 3365 | break; |
| 3366 | } |
| 3367 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3368 | if (requireUtProvisioning) { |
| 3369 | // UT requires provisioning |
| 3370 | return true; |
| 3371 | } |
| 3372 | break; |
| 3373 | } |
| 3374 | } |
| 3375 | return false; |
| 3376 | } |
| 3377 | |
| 3378 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3379 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3380 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3381 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3382 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3383 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3384 | final long identity = Binder.clearCallingIdentity(); |
| 3385 | try { |
| 3386 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3387 | int slotId = getSlotIndex(subId); |
| 3388 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3389 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3390 | + subId + "' for key:" + key); |
| 3391 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3392 | } |
| 3393 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3394 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3395 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3396 | + subId + "' for key:" + key); |
| 3397 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3398 | } finally { |
| 3399 | Binder.restoreCallingIdentity(identity); |
| 3400 | } |
| 3401 | } |
| 3402 | |
| 3403 | @Override |
| 3404 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3405 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3406 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3407 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3408 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3409 | final long identity = Binder.clearCallingIdentity(); |
| 3410 | try { |
| 3411 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3412 | int slotId = getSlotIndex(subId); |
| 3413 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3414 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3415 | + subId + "' for key:" + key); |
| 3416 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3417 | } |
| 3418 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3419 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3420 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3421 | + subId + "' for key:" + key); |
| 3422 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3423 | } finally { |
| 3424 | Binder.restoreCallingIdentity(identity); |
| 3425 | } |
| 3426 | } |
| 3427 | |
| 3428 | @Override |
| 3429 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3430 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3431 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3432 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3433 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3434 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3435 | final long identity = Binder.clearCallingIdentity(); |
| 3436 | try { |
| 3437 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3438 | int slotId = getSlotIndex(subId); |
| 3439 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3440 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3441 | + subId + "' for key:" + key); |
| 3442 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3443 | } |
| 3444 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3445 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3446 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3447 | + "' for key:" + key); |
| 3448 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3449 | } finally { |
| 3450 | Binder.restoreCallingIdentity(identity); |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | @Override |
| 3455 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3456 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3457 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3458 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3459 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3460 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3461 | final long identity = Binder.clearCallingIdentity(); |
| 3462 | try { |
| 3463 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3464 | int slotId = getSlotIndex(subId); |
| 3465 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3466 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3467 | + subId + "' for key:" + key); |
| 3468 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3469 | } |
| 3470 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3471 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3472 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3473 | + "' for key:" + key); |
| 3474 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3475 | } finally { |
| 3476 | Binder.restoreCallingIdentity(identity); |
| 3477 | } |
| 3478 | } |
| 3479 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3480 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3481 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3482 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3483 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3484 | } |
| 3485 | return slotId; |
| 3486 | } |
| 3487 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3488 | private int getSlotIndex(int subId) { |
| 3489 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3490 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3491 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3492 | } |
| 3493 | return slotId; |
| 3494 | } |
| 3495 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3496 | /** |
| 3497 | * Returns the network type for a subId |
| 3498 | */ |
| 3499 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3500 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3501 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3502 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3503 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3504 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3505 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3506 | final long identity = Binder.clearCallingIdentity(); |
| 3507 | try { |
| 3508 | final Phone phone = getPhone(subId); |
| 3509 | if (phone != null) { |
| 3510 | return phone.getServiceState().getDataNetworkType(); |
| 3511 | } else { |
| 3512 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3513 | } |
| 3514 | } finally { |
| 3515 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3516 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3517 | } |
| 3518 | |
| 3519 | /** |
| 3520 | * Returns the data network type |
| 3521 | */ |
| 3522 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3523 | public int getDataNetworkType(String callingPackage) { |
| 3524 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3525 | } |
| 3526 | |
| 3527 | /** |
| 3528 | * Returns the data network type for a subId |
| 3529 | */ |
| 3530 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3531 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3532 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3533 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3534 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3535 | } |
| 3536 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3537 | final long identity = Binder.clearCallingIdentity(); |
| 3538 | try { |
| 3539 | final Phone phone = getPhone(subId); |
| 3540 | if (phone != null) { |
| 3541 | return phone.getServiceState().getDataNetworkType(); |
| 3542 | } else { |
| 3543 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3544 | } |
| 3545 | } finally { |
| 3546 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3547 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3548 | } |
| 3549 | |
| 3550 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3551 | * Returns the Voice network type for a subId |
| 3552 | */ |
| 3553 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3554 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3555 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3556 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3557 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3558 | } |
| 3559 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3560 | final long identity = Binder.clearCallingIdentity(); |
| 3561 | try { |
| 3562 | final Phone phone = getPhone(subId); |
| 3563 | if (phone != null) { |
| 3564 | return phone.getServiceState().getVoiceNetworkType(); |
| 3565 | } else { |
| 3566 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3567 | } |
| 3568 | } finally { |
| 3569 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3570 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | /** |
| 3574 | * @return true if a ICC card is present |
| 3575 | */ |
| 3576 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3577 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3578 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3579 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3583 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3584 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3585 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3586 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3587 | final long identity = Binder.clearCallingIdentity(); |
| 3588 | try { |
| 3589 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3590 | if (phone != null) { |
| 3591 | return phone.getIccCard().hasIccCard(); |
| 3592 | } else { |
| 3593 | return false; |
| 3594 | } |
| 3595 | } finally { |
| 3596 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3597 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | /** |
| 3601 | * Return if the current radio is LTE on CDMA. This |
| 3602 | * is a tri-state return value as for a period of time |
| 3603 | * the mode may be unknown. |
| 3604 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3605 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3606 | * @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] | 3607 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3608 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3609 | @Override |
| 3610 | public int getLteOnCdmaMode(String callingPackage) { |
| 3611 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3614 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3615 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3616 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3617 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3618 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3619 | } |
| 3620 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3621 | final long identity = Binder.clearCallingIdentity(); |
| 3622 | try { |
| 3623 | final Phone phone = getPhone(subId); |
| 3624 | if (phone == null) { |
| 3625 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3626 | } else { |
| 3627 | return phone.getLteOnCdmaMode(); |
| 3628 | } |
| 3629 | } finally { |
| 3630 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3631 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3632 | } |
| 3633 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3634 | /** |
| 3635 | * {@hide} |
| 3636 | * Returns Default subId, 0 in the case of single standby. |
| 3637 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3638 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3639 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3640 | } |
| 3641 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3642 | private int getSlotForDefaultSubscription() { |
| 3643 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3644 | } |
| 3645 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3646 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3647 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3648 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3649 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3650 | private boolean isActiveSubscription(int subId) { |
| 3651 | return mSubscriptionController.isActiveSubId(subId); |
| 3652 | } |
| 3653 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3654 | /** |
| 3655 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3656 | */ |
| 3657 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3658 | final long identity = Binder.clearCallingIdentity(); |
| 3659 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3660 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3661 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3662 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3663 | } finally { |
| 3664 | Binder.restoreCallingIdentity(identity); |
| 3665 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | /** |
| 3669 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3670 | */ |
| 3671 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3672 | final long identity = Binder.clearCallingIdentity(); |
| 3673 | try { |
| 3674 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3675 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3676 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3677 | } finally { |
| 3678 | Binder.restoreCallingIdentity(identity); |
| 3679 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3680 | } |
| 3681 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3682 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3683 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3684 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3685 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3686 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3687 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3688 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3689 | if (phoneId == -1) { |
| 3690 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3691 | + " does not correspond to an active phone"); |
| 3692 | } |
| 3693 | return PhoneFactory.getPhone(phoneId); |
| 3694 | } |
| 3695 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3696 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3697 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3698 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3699 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3700 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3701 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3702 | if (DBG) { |
| 3703 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3704 | } |
| 3705 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3706 | p2); |
| 3707 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3708 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3709 | |
| 3710 | @Override |
| 3711 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3712 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3713 | enforceModifyPermission(); |
| 3714 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3715 | if (DBG) { |
| 3716 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3717 | } |
| 3718 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3719 | callingPackage, aid, p2); |
| 3720 | } |
| 3721 | |
| 3722 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3723 | String callingPackage, String aid, int p2) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3724 | final long identity = Binder.clearCallingIdentity(); |
| 3725 | try { |
| 3726 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3727 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3728 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3729 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3730 | if (bestComponent == null |
| 3731 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3732 | loge("The calling package is not allowed to access ISD-R."); |
| 3733 | throw new SecurityException( |
| 3734 | "The calling package is not allowed to access ISD-R."); |
| 3735 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3736 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3737 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3738 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3739 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3740 | null /* workSource */); |
| 3741 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3742 | return response; |
| 3743 | } finally { |
| 3744 | Binder.restoreCallingIdentity(identity); |
| 3745 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3749 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3750 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3751 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3752 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3753 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3754 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3755 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3756 | @Override |
| 3757 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3758 | enforceModifyPermission(); |
| 3759 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3760 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3761 | channel); |
| 3762 | } |
| 3763 | |
| 3764 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3765 | final long identity = Binder.clearCallingIdentity(); |
| 3766 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3767 | if (channel < 0) { |
| 3768 | return false; |
| 3769 | } |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3770 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3771 | null /* workSource */); |
| 3772 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3773 | return success; |
| 3774 | } finally { |
| 3775 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3776 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3780 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3781 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3782 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3783 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3784 | if (DBG) { |
| 3785 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3786 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3787 | + p3 + " data=" + data); |
| 3788 | } |
| 3789 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3790 | command, p1, p2, p3, data); |
| 3791 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3792 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3793 | @Override |
| 3794 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3795 | int command, int p1, int p2, int p3, String data) { |
| 3796 | enforceModifyPermission(); |
| 3797 | if (DBG) { |
| 3798 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3799 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3800 | + p3 + " data=" + data); |
| 3801 | } |
| 3802 | return iccTransmitApduLogicalChannelWithPermission( |
| 3803 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3804 | data); |
| 3805 | } |
| 3806 | |
| 3807 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3808 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3809 | final long identity = Binder.clearCallingIdentity(); |
| 3810 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3811 | if (channel < 0) { |
| 3812 | return ""; |
| 3813 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3814 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3815 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3816 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3817 | null /* workSource */); |
| 3818 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3819 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3820 | // Append the returned status code to the end of the response payload. |
| 3821 | String s = Integer.toHexString( |
| 3822 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3823 | if (response.payload != null) { |
| 3824 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3825 | } |
| 3826 | return s; |
| 3827 | } finally { |
| 3828 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3829 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3830 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3831 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3832 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3833 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3834 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3835 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3836 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3837 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3838 | if (DBG) { |
| 3839 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3840 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3841 | } |
| 3842 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3843 | cla, command, p1, p2, p3, data); |
| 3844 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3845 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3846 | @Override |
| 3847 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3848 | int command, int p1, int p2, int p3, String data) { |
| 3849 | enforceModifyPermission(); |
| 3850 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3851 | if (DBG) { |
| 3852 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3853 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3854 | + " data=" + data); |
| 3855 | } |
| 3856 | |
| 3857 | return iccTransmitApduBasicChannelWithPermission( |
| 3858 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3859 | p2, p3, data); |
| 3860 | } |
| 3861 | |
| 3862 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3863 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3864 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3865 | final long identity = Binder.clearCallingIdentity(); |
| 3866 | try { |
| 3867 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3868 | && TextUtils.equals(ISDR_AID, data)) { |
| 3869 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3870 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3871 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3872 | if (bestComponent == null |
| 3873 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3874 | loge("The calling package is not allowed to select ISD-R."); |
| 3875 | throw new SecurityException( |
| 3876 | "The calling package is not allowed to select ISD-R."); |
| 3877 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3878 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3879 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3880 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3881 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 3882 | null /* workSource */); |
| 3883 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3884 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3885 | // Append the returned status code to the end of the response payload. |
| 3886 | String s = Integer.toHexString( |
| 3887 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3888 | if (response.payload != null) { |
| 3889 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3890 | } |
| 3891 | return s; |
| 3892 | } finally { |
| 3893 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3894 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
| 3897 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3898 | 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] | 3899 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3900 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3901 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3902 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3903 | final long identity = Binder.clearCallingIdentity(); |
| 3904 | try { |
| 3905 | if (DBG) { |
| 3906 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3907 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3908 | } |
| 3909 | |
| 3910 | IccIoResult response = |
| 3911 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3912 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3913 | subId); |
| 3914 | |
| 3915 | if (DBG) { |
| 3916 | log("Exchange SIM_IO [R]" + response); |
| 3917 | } |
| 3918 | |
| 3919 | byte[] result = null; |
| 3920 | int length = 2; |
| 3921 | if (response.payload != null) { |
| 3922 | length = 2 + response.payload.length; |
| 3923 | result = new byte[length]; |
| 3924 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3925 | } else { |
| 3926 | result = new byte[length]; |
| 3927 | } |
| 3928 | |
| 3929 | result[length - 1] = (byte) response.sw2; |
| 3930 | result[length - 2] = (byte) response.sw1; |
| 3931 | return result; |
| 3932 | } finally { |
| 3933 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3934 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3935 | } |
| 3936 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3937 | /** |
| 3938 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3939 | * on a particular subscription |
| 3940 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3941 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3942 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3943 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3944 | return null; |
| 3945 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3946 | |
| 3947 | final long identity = Binder.clearCallingIdentity(); |
| 3948 | try { |
| 3949 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3950 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3951 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3952 | return null; |
| 3953 | } |
| 3954 | Object response = sendRequest( |
| 3955 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3956 | if (response instanceof String[]) { |
| 3957 | return (String[]) response; |
| 3958 | } |
| 3959 | // Response is an Exception of some kind, |
| 3960 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3961 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3962 | } finally { |
| 3963 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3964 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3965 | } |
| 3966 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3967 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3968 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3969 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3970 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3971 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3972 | final long identity = Binder.clearCallingIdentity(); |
| 3973 | try { |
| 3974 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3975 | if (response.payload == null) { |
| 3976 | return ""; |
| 3977 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3978 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3979 | // Append the returned status code to the end of the response payload. |
| 3980 | String s = Integer.toHexString( |
| 3981 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3982 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3983 | return s; |
| 3984 | } finally { |
| 3985 | Binder.restoreCallingIdentity(identity); |
| 3986 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3987 | } |
| 3988 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3989 | /** |
| 3990 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3991 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3992 | * |
| 3993 | * @param itemID the ID of the item to read |
| 3994 | * @return the NV item as a String, or null on error. |
| 3995 | */ |
| 3996 | @Override |
| 3997 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3998 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4000 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4001 | |
| 4002 | final long identity = Binder.clearCallingIdentity(); |
| 4003 | try { |
| 4004 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4005 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4006 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4007 | return value; |
| 4008 | } finally { |
| 4009 | Binder.restoreCallingIdentity(identity); |
| 4010 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4011 | } |
| 4012 | |
| 4013 | /** |
| 4014 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4015 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4016 | * |
| 4017 | * @param itemID the ID of the item to read |
| 4018 | * @param itemValue the value to write, as a String |
| 4019 | * @return true on success; false on any failure |
| 4020 | */ |
| 4021 | @Override |
| 4022 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4023 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4024 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4025 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4026 | |
| 4027 | final long identity = Binder.clearCallingIdentity(); |
| 4028 | try { |
| 4029 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4030 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4031 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4032 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4033 | return success; |
| 4034 | } finally { |
| 4035 | Binder.restoreCallingIdentity(identity); |
| 4036 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4037 | } |
| 4038 | |
| 4039 | /** |
| 4040 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4041 | * Used for device configuration by some CDMA operators. |
| 4042 | * |
| 4043 | * @param preferredRoamingList byte array containing the new PRL |
| 4044 | * @return true on success; false on any failure |
| 4045 | */ |
| 4046 | @Override |
| 4047 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4048 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4049 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4050 | |
| 4051 | final long identity = Binder.clearCallingIdentity(); |
| 4052 | try { |
| 4053 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4054 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4055 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4056 | return success; |
| 4057 | } finally { |
| 4058 | Binder.restoreCallingIdentity(identity); |
| 4059 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4063 | * 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] | 4064 | * Used for device configuration by some CDMA operators. |
| 4065 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4066 | * @param slotIndex - device slot. |
| 4067 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4068 | * @return true on success; false on any failure |
| 4069 | */ |
| 4070 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4071 | public boolean resetModemConfig(int slotIndex) { |
| 4072 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4073 | if (phone != null) { |
| 4074 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4075 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4076 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4077 | final long identity = Binder.clearCallingIdentity(); |
| 4078 | try { |
| 4079 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4080 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4081 | return success; |
| 4082 | } finally { |
| 4083 | Binder.restoreCallingIdentity(identity); |
| 4084 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4085 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4086 | return false; |
| 4087 | } |
| 4088 | |
| 4089 | /** |
| 4090 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4091 | * |
| 4092 | * @param slotIndex - device slot. |
| 4093 | * |
| 4094 | * @return true on success; false on any failure |
| 4095 | */ |
| 4096 | @Override |
| 4097 | public boolean rebootModem(int slotIndex) { |
| 4098 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4099 | if (phone != null) { |
| 4100 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4101 | mApp, phone.getSubId(), "rebootModem"); |
| 4102 | |
| 4103 | final long identity = Binder.clearCallingIdentity(); |
| 4104 | try { |
| 4105 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4106 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4107 | return success; |
| 4108 | } finally { |
| 4109 | Binder.restoreCallingIdentity(identity); |
| 4110 | } |
| 4111 | } |
| 4112 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4113 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4114 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4115 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4116 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4117 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4118 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4119 | return new String[0]; |
| 4120 | } |
| 4121 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4122 | final long identity = Binder.clearCallingIdentity(); |
| 4123 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4124 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4125 | } finally { |
| 4126 | Binder.restoreCallingIdentity(identity); |
| 4127 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4128 | } |
| 4129 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4130 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4131 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4132 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4133 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4134 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4135 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4136 | |
| 4137 | final long identity = Binder.clearCallingIdentity(); |
| 4138 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4139 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4140 | if (resolver == null) { |
| 4141 | // may happen if the device does not support IMS. |
| 4142 | return; |
| 4143 | } |
| 4144 | resolver.enableIms(slotId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4145 | } finally { |
| 4146 | Binder.restoreCallingIdentity(identity); |
| 4147 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4151 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4152 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4153 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4154 | public void disableIms(int slotId) { |
| 4155 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4156 | |
| 4157 | final long identity = Binder.clearCallingIdentity(); |
| 4158 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4159 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4160 | if (resolver == null) { |
| 4161 | // may happen if the device does not support IMS. |
| 4162 | return; |
| 4163 | } |
| 4164 | resolver.disableIms(slotId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4165 | } finally { |
| 4166 | Binder.restoreCallingIdentity(identity); |
| 4167 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | /** |
| 4171 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4172 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4173 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4174 | */ |
| 4175 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4176 | IImsServiceFeatureCallback callback) { |
| 4177 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4178 | |
| 4179 | final long identity = Binder.clearCallingIdentity(); |
| 4180 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4181 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4182 | if (resolver == null) { |
| 4183 | // may happen if the device does not support IMS. |
| 4184 | return null; |
| 4185 | } |
| 4186 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4187 | } finally { |
| 4188 | Binder.restoreCallingIdentity(identity); |
| 4189 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4190 | } |
| 4191 | |
| 4192 | /** |
| 4193 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4194 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4195 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4196 | * listener for feature updates. |
| 4197 | */ |
| 4198 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4199 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4200 | |
| 4201 | final long identity = Binder.clearCallingIdentity(); |
| 4202 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4203 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4204 | if (resolver == null) { |
| 4205 | // may happen if the device does not support IMS. |
| 4206 | return null; |
| 4207 | } |
| 4208 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4209 | } finally { |
| 4210 | Binder.restoreCallingIdentity(identity); |
| 4211 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4212 | } |
| 4213 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4214 | /** |
| 4215 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4216 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4217 | */ |
| 4218 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4219 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4220 | |
| 4221 | final long identity = Binder.clearCallingIdentity(); |
| 4222 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4223 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4224 | if (resolver == null) { |
| 4225 | // may happen if the device does not support IMS. |
| 4226 | return null; |
| 4227 | } |
| 4228 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4229 | } finally { |
| 4230 | Binder.restoreCallingIdentity(identity); |
| 4231 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4232 | } |
| 4233 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4234 | /** |
| 4235 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4236 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4237 | */ |
| 4238 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4239 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4240 | |
| 4241 | final long identity = Binder.clearCallingIdentity(); |
| 4242 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4243 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4244 | if (resolver == null) { |
| 4245 | // may happen if the device does not support IMS. |
| 4246 | return null; |
| 4247 | } |
| 4248 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4249 | } finally { |
| 4250 | Binder.restoreCallingIdentity(identity); |
| 4251 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4252 | } |
| 4253 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4254 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4255 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4256 | * |
| 4257 | * @param slotId the slot ID that the ImsService should bind for. |
| 4258 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4259 | * ImsService is the device default ImsService. |
| 4260 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4261 | * to. |
| 4262 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4263 | * @hide |
| 4264 | */ |
| 4265 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4266 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4267 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4268 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4269 | "setImsService"); |
| 4270 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4271 | final long identity = Binder.clearCallingIdentity(); |
| 4272 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4273 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4274 | if (resolver == null) { |
| 4275 | // may happen if the device does not support IMS. |
| 4276 | return false; |
| 4277 | } |
| 4278 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4279 | packageName); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4280 | } finally { |
| 4281 | Binder.restoreCallingIdentity(identity); |
| 4282 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | /** |
| 4286 | * Return the ImsService configuration. |
| 4287 | * |
| 4288 | * @param slotId The slot that the ImsService is associated with. |
| 4289 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4290 | * the device default. |
| 4291 | * @return the package name of the ImsService configuration. |
| 4292 | */ |
| 4293 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4294 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4295 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4296 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4297 | "getImsService"); |
| 4298 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4299 | final long identity = Binder.clearCallingIdentity(); |
| 4300 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4301 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4302 | if (resolver == null) { |
| 4303 | // may happen if the device does not support IMS. |
| 4304 | return ""; |
| 4305 | } |
| 4306 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4307 | } finally { |
| 4308 | Binder.restoreCallingIdentity(identity); |
| 4309 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4310 | } |
| 4311 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4312 | public void setImsRegistrationState(boolean registered) { |
| 4313 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4314 | |
| 4315 | final long identity = Binder.clearCallingIdentity(); |
| 4316 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4317 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4318 | } finally { |
| 4319 | Binder.restoreCallingIdentity(identity); |
| 4320 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4324 | * Set the network selection mode to automatic. |
| 4325 | * |
| 4326 | */ |
| 4327 | @Override |
| 4328 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4329 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4330 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4331 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4332 | if (!isActiveSubscription(subId)) { |
| 4333 | return; |
| 4334 | } |
| 4335 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4336 | final long identity = Binder.clearCallingIdentity(); |
| 4337 | try { |
| 4338 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4339 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4340 | } finally { |
| 4341 | Binder.restoreCallingIdentity(identity); |
| 4342 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4343 | } |
| 4344 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4345 | /** |
| 4346 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4347 | * |
| 4348 | * @param subId the id of the subscription. |
| 4349 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4350 | * the operator to attach to. |
| 4351 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4352 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4353 | * normal network selection next time. |
| 4354 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4355 | */ |
| 4356 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4357 | public boolean setNetworkSelectionModeManual( |
| 4358 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4359 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4360 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4361 | |
| 4362 | if (!isActiveSubscription(subId)) { |
| 4363 | return false; |
| 4364 | } |
| 4365 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4366 | final long identity = Binder.clearCallingIdentity(); |
| 4367 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4368 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4369 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4370 | if (DBG) { |
| 4371 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4372 | + " operator: " + operatorInfo); |
| 4373 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4374 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4375 | } finally { |
| 4376 | Binder.restoreCallingIdentity(identity); |
| 4377 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | /** |
| 4381 | * Scans for available networks. |
| 4382 | */ |
| 4383 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4384 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4385 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4386 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4387 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4388 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4389 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4390 | .setCallingPackage(callingPackage) |
| 4391 | .setCallingPid(Binder.getCallingPid()) |
| 4392 | .setCallingUid(Binder.getCallingUid()) |
| 4393 | .setMethod("getCellNetworkScanResults") |
| 4394 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4395 | .build()); |
| 4396 | switch (locationResult) { |
| 4397 | case DENIED_HARD: |
| 4398 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4399 | case DENIED_SOFT: |
| 4400 | return null; |
| 4401 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4402 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4403 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4404 | try { |
| 4405 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4406 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4407 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4408 | } finally { |
| 4409 | Binder.restoreCallingIdentity(identity); |
| 4410 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4411 | } |
| 4412 | |
| 4413 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4414 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4415 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4416 | * @param subId id of the subscription |
| 4417 | * @param request contains the radio access networks with bands/channels to scan |
| 4418 | * @param messenger callback messenger for scan results or errors |
| 4419 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4420 | * @return the id of the requested scan which can be used to stop the scan. |
| 4421 | */ |
| 4422 | @Override |
| 4423 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4424 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4425 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4426 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4427 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4428 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4429 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4430 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4431 | .setCallingPackage(callingPackage) |
| 4432 | .setCallingPid(Binder.getCallingPid()) |
| 4433 | .setCallingUid(Binder.getCallingUid()) |
| 4434 | .setMethod("requestNetworkScan") |
| 4435 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4436 | .build()); |
| 4437 | switch (locationResult) { |
| 4438 | case DENIED_HARD: |
| 4439 | throw new SecurityException("Not allowed to request network scan -- location"); |
| 4440 | case DENIED_SOFT: |
| 4441 | return -1; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4442 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4443 | |
| 4444 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4445 | request, messenger, binder, getPhone(subId), |
| 4446 | callingPackage); |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | /** |
| 4450 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4451 | * |
| 4452 | * @param subId id of the subscription |
| 4453 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4454 | */ |
| 4455 | @Override |
| 4456 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4457 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4458 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4459 | |
| 4460 | final long identity = Binder.clearCallingIdentity(); |
| 4461 | try { |
| 4462 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 4463 | } finally { |
| 4464 | Binder.restoreCallingIdentity(identity); |
| 4465 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4469 | * Get the calculated preferred network type. |
| 4470 | * Used for debugging incorrect network type. |
| 4471 | * |
| 4472 | * @return the preferred network type, defined in RILConstants.java. |
| 4473 | */ |
| 4474 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4475 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4476 | final Phone defaultPhone = getDefaultPhone(); |
| 4477 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4478 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4479 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4480 | } |
| 4481 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4482 | final long identity = Binder.clearCallingIdentity(); |
| 4483 | try { |
| 4484 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4485 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4486 | } finally { |
| 4487 | Binder.restoreCallingIdentity(identity); |
| 4488 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4492 | * Get the preferred network type. |
| 4493 | * Used for device configuration by some CDMA operators. |
| 4494 | * |
| 4495 | * @return the preferred network type, defined in RILConstants.java. |
| 4496 | */ |
| 4497 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4498 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | 4848cd0 | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4499 | TelephonyPermissions |
| 4500 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4501 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4502 | |
| 4503 | final long identity = Binder.clearCallingIdentity(); |
| 4504 | try { |
| 4505 | if (DBG) log("getPreferredNetworkType"); |
| 4506 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4507 | int networkType = (result != null ? result[0] : -1); |
| 4508 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4509 | return networkType; |
| 4510 | } finally { |
| 4511 | Binder.restoreCallingIdentity(identity); |
| 4512 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4513 | } |
| 4514 | |
| 4515 | /** |
| 4516 | * Set the preferred network type. |
| 4517 | * Used for device configuration by some CDMA operators. |
| 4518 | * |
| 4519 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4520 | * @return true on success; false on any failure. |
| 4521 | */ |
| 4522 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4523 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4524 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4525 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4526 | |
| 4527 | final long identity = Binder.clearCallingIdentity(); |
| 4528 | try { |
| 4529 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4530 | Boolean success = (Boolean) sendRequest( |
| 4531 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4532 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4533 | if (success) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4534 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4535 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4536 | } |
| 4537 | return success; |
| 4538 | } finally { |
| 4539 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4540 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4541 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4542 | |
| 4543 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4544 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4545 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4546 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4547 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4548 | * @hide |
| 4549 | */ |
| 4550 | @Override |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4551 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4552 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4553 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4554 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4555 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4556 | if (phone != null) { |
| 4557 | return phone.hasMatchedTetherApnSetting(); |
| 4558 | } else { |
| 4559 | return false; |
| 4560 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4561 | } finally { |
| 4562 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4563 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4564 | } |
| 4565 | |
| 4566 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4567 | * Set mobile data enabled |
| 4568 | * Used by the user through settings etc to turn on/off mobile data |
| 4569 | * |
| 4570 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4571 | */ |
| 4572 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4573 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4574 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4575 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4576 | |
| 4577 | final long identity = Binder.clearCallingIdentity(); |
| 4578 | try { |
| 4579 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4580 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4581 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4582 | if (phone != null) { |
| 4583 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4584 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4585 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4586 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4587 | } |
| 4588 | } finally { |
| 4589 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4590 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4591 | } |
| 4592 | |
| 4593 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4594 | * Get the user enabled state of Mobile Data. |
| 4595 | * |
| 4596 | * TODO: remove and use isUserDataEnabled. |
| 4597 | * This can't be removed now because some vendor codes |
| 4598 | * calls through ITelephony directly while they should |
| 4599 | * use TelephonyManager. |
| 4600 | * |
| 4601 | * @return true on enabled |
| 4602 | */ |
| 4603 | @Override |
| 4604 | public boolean getDataEnabled(int subId) { |
| 4605 | return isUserDataEnabled(subId); |
| 4606 | } |
| 4607 | |
| 4608 | /** |
| 4609 | * Get whether mobile data is enabled per user setting. |
| 4610 | * |
| 4611 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4612 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4613 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4614 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4615 | * |
| 4616 | * @return {@code true} if data is enabled else {@code false} |
| 4617 | */ |
| 4618 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4619 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4620 | try { |
| 4621 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4622 | null); |
| 4623 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4625 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4626 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4627 | |
| 4628 | final long identity = Binder.clearCallingIdentity(); |
| 4629 | try { |
| 4630 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4631 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4632 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4633 | if (phone != null) { |
| 4634 | boolean retVal = phone.isUserDataEnabled(); |
| 4635 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4636 | return retVal; |
| 4637 | } else { |
| 4638 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4639 | return false; |
| 4640 | } |
| 4641 | } finally { |
| 4642 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4643 | } |
| 4644 | } |
| 4645 | |
| 4646 | /** |
| 4647 | * Get whether mobile data is enabled. |
| 4648 | * |
| 4649 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4650 | * whether mobile data is actually enabled. |
| 4651 | * |
| 4652 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4653 | * |
| 4654 | * @return {@code true} if data is enabled else {@code false} |
| 4655 | */ |
| 4656 | @Override |
| 4657 | public boolean isDataEnabled(int subId) { |
| 4658 | try { |
| 4659 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4660 | null); |
| 4661 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4662 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4663 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4664 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4665 | |
| 4666 | final long identity = Binder.clearCallingIdentity(); |
| 4667 | try { |
| 4668 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4669 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4670 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4671 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4672 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4673 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4674 | return retVal; |
| 4675 | } else { |
| 4676 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4677 | return false; |
| 4678 | } |
| 4679 | } finally { |
| 4680 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4681 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4682 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4683 | |
| 4684 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4685 | public int getCarrierPrivilegeStatus(int subId) { |
| 4686 | final Phone phone = getPhone(subId); |
| 4687 | if (phone == null) { |
| 4688 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4689 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4690 | } |
| 4691 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4692 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4693 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4694 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4695 | } |
| 4696 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4697 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4698 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4699 | |
| 4700 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4701 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4702 | final Phone phone = getPhone(subId); |
| 4703 | if (phone == null) { |
| 4704 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4705 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4706 | } |
| 4707 | UiccProfile profile = |
| 4708 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4709 | if (profile == null) { |
| 4710 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4711 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4712 | } |
| 4713 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4714 | } |
| 4715 | |
| 4716 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4717 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4718 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4719 | if (TextUtils.isEmpty(pkgName)) |
| 4720 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4721 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4722 | if (card == null) { |
| 4723 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4724 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4725 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4726 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4727 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | @Override |
| 4731 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4732 | if (TextUtils.isEmpty(pkgName)) |
| 4733 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4734 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4735 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4736 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4737 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4738 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4739 | continue; |
| 4740 | } |
| 4741 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4742 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4743 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4744 | break; |
| 4745 | } |
| 4746 | } |
| 4747 | |
| 4748 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4749 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4750 | |
| 4751 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4752 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4753 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4754 | loge("phoneId " + phoneId + " is not valid."); |
| 4755 | return null; |
| 4756 | } |
| 4757 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4758 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4759 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4760 | return null ; |
| 4761 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4762 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4763 | } |
| 4764 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4765 | @Override |
| 4766 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4767 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4768 | List<String> privilegedPackages = new ArrayList<>(); |
| 4769 | List<PackageInfo> packages = null; |
| 4770 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4771 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4772 | if (card == null) { |
| 4773 | // No UICC in that slot. |
| 4774 | continue; |
| 4775 | } |
| 4776 | if (card.hasCarrierPrivilegeRules()) { |
| 4777 | if (packages == null) { |
| 4778 | // Only check packages in user 0 for now |
| 4779 | packages = pm.getInstalledPackagesAsUser( |
| 4780 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4781 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4782 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4783 | } |
| 4784 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4785 | PackageInfo pkgInfo = packages.get(p); |
| 4786 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4787 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4788 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4789 | privilegedPackages.add(pkgInfo.packageName); |
| 4790 | } |
| 4791 | } |
| 4792 | } |
| 4793 | } |
| 4794 | return privilegedPackages; |
| 4795 | } |
| 4796 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4797 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4798 | final Phone phone = getPhone(subId); |
| 4799 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4800 | if (card == null) { |
| 4801 | loge("getIccId: No UICC"); |
| 4802 | return null; |
| 4803 | } |
| 4804 | String iccId = card.getIccId(); |
| 4805 | if (TextUtils.isEmpty(iccId)) { |
| 4806 | loge("getIccId: ICC ID is null or empty."); |
| 4807 | return null; |
| 4808 | } |
| 4809 | return iccId; |
| 4810 | } |
| 4811 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4812 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4813 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4814 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4815 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4816 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4817 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4818 | final long identity = Binder.clearCallingIdentity(); |
| 4819 | try { |
| 4820 | final String iccId = getIccId(subId); |
| 4821 | final Phone phone = getPhone(subId); |
| 4822 | if (phone == null) { |
| 4823 | return false; |
| 4824 | } |
| 4825 | final String subscriberId = phone.getSubscriberId(); |
| 4826 | |
| 4827 | if (DBG_MERGE) { |
| 4828 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4829 | + subscriberId + " to " + number); |
| 4830 | } |
| 4831 | |
| 4832 | if (TextUtils.isEmpty(iccId)) { |
| 4833 | return false; |
| 4834 | } |
| 4835 | |
| 4836 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4837 | |
| 4838 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4839 | if (alphaTag == null) { |
| 4840 | editor.remove(alphaTagPrefKey); |
| 4841 | } else { |
| 4842 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4843 | } |
| 4844 | |
| 4845 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4846 | // track all merged IMSIs based on line number |
| 4847 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4848 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4849 | if (number == null) { |
| 4850 | editor.remove(numberPrefKey); |
| 4851 | editor.remove(subscriberPrefKey); |
| 4852 | } else { |
| 4853 | editor.putString(numberPrefKey, number); |
| 4854 | editor.putString(subscriberPrefKey, subscriberId); |
| 4855 | } |
| 4856 | |
| 4857 | editor.commit(); |
| 4858 | return true; |
| 4859 | } finally { |
| 4860 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4861 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4862 | } |
| 4863 | |
| 4864 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4865 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4866 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4867 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4868 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4869 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4870 | return null; |
| 4871 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4872 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4873 | final long identity = Binder.clearCallingIdentity(); |
| 4874 | try { |
| 4875 | String iccId = getIccId(subId); |
| 4876 | if (iccId != null) { |
| 4877 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4878 | if (DBG_MERGE) { |
| 4879 | log("getLine1NumberForDisplay returning " |
| 4880 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4881 | } |
| 4882 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4883 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4884 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4885 | return null; |
| 4886 | } finally { |
| 4887 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4888 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4889 | } |
| 4890 | |
| 4891 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4892 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4893 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4894 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4895 | return null; |
| 4896 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4897 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4898 | final long identity = Binder.clearCallingIdentity(); |
| 4899 | try { |
| 4900 | String iccId = getIccId(subId); |
| 4901 | if (iccId != null) { |
| 4902 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4903 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4904 | } |
| 4905 | return null; |
| 4906 | } finally { |
| 4907 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4908 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4909 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4910 | |
| 4911 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4912 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4913 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4914 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4915 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4916 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4917 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4918 | return null; |
| 4919 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4920 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4921 | final long identity = Binder.clearCallingIdentity(); |
| 4922 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4923 | final Context context = mApp; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4924 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4925 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4926 | |
| 4927 | // Figure out what subscribers are currently active |
| 4928 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4929 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4930 | // the process, where TelephonyManager was instantiated. |
| 4931 | // Otherwise AppOps check will fail. |
| 4932 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4933 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4934 | for (int subId : subIds) { |
| 4935 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4936 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4937 | |
| 4938 | // First pass, find a number override for an active subscriber |
| 4939 | String mergeNumber = null; |
| 4940 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4941 | for (String key : prefs.keySet()) { |
| 4942 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4943 | final String subscriberId = (String) prefs.get(key); |
| 4944 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4945 | final String iccId = key.substring( |
| 4946 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4947 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4948 | mergeNumber = (String) prefs.get(numberKey); |
| 4949 | if (DBG_MERGE) { |
| 4950 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4951 | + " for active subscriber " + subscriberId); |
| 4952 | } |
| 4953 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4954 | break; |
| 4955 | } |
| 4956 | } |
| 4957 | } |
| 4958 | } |
| 4959 | |
| 4960 | // Shortcut when no active merged subscribers |
| 4961 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4962 | return null; |
| 4963 | } |
| 4964 | |
| 4965 | // Second pass, find all subscribers under that line override |
| 4966 | final ArraySet<String> result = new ArraySet<>(); |
| 4967 | for (String key : prefs.keySet()) { |
| 4968 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4969 | final String number = (String) prefs.get(key); |
| 4970 | if (mergeNumber.equals(number)) { |
| 4971 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4972 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4973 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4974 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4975 | result.add(subscriberId); |
| 4976 | } |
| 4977 | } |
| 4978 | } |
| 4979 | } |
| 4980 | |
| 4981 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4982 | Arrays.sort(resultArray); |
| 4983 | if (DBG_MERGE) { |
| 4984 | Slog.d(LOG_TAG, |
| 4985 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4986 | } |
| 4987 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4988 | } finally { |
| 4989 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4990 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4991 | } |
| 4992 | |
| 4993 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4994 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4995 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4996 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4997 | |
| 4998 | final long identity = Binder.clearCallingIdentity(); |
| 4999 | try { |
| 5000 | final Phone phone = getPhone(subId); |
| 5001 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5002 | } finally { |
| 5003 | Binder.restoreCallingIdentity(identity); |
| 5004 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5005 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5006 | |
| 5007 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5008 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5009 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5010 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5011 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5012 | |
| 5013 | final long identity = Binder.clearCallingIdentity(); |
| 5014 | try { |
| 5015 | final Phone phone = getPhone(subId); |
| 5016 | if (phone == null) { |
| 5017 | return false; |
| 5018 | } |
| 5019 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5020 | cdmaNonRoamingList); |
| 5021 | } finally { |
| 5022 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5023 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5027 | @Deprecated |
| 5028 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5029 | enforceModifyPermission(); |
| 5030 | |
| 5031 | int returnValue = 0; |
| 5032 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5033 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5034 | if(result.exception == null) { |
| 5035 | if (result.result != null) { |
| 5036 | byte[] responseData = (byte[])(result.result); |
| 5037 | if(responseData.length > oemResp.length) { |
| 5038 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5039 | responseData.length + "bytes. Buffer Size is " + |
| 5040 | oemResp.length + "bytes."); |
| 5041 | } |
| 5042 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5043 | returnValue = responseData.length; |
| 5044 | } |
| 5045 | } else { |
| 5046 | CommandException ex = (CommandException) result.exception; |
| 5047 | returnValue = ex.getCommandError().ordinal(); |
| 5048 | if(returnValue > 0) returnValue *= -1; |
| 5049 | } |
| 5050 | } catch (RuntimeException e) { |
| 5051 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5052 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5053 | if(returnValue > 0) returnValue *= -1; |
| 5054 | } |
| 5055 | |
| 5056 | return returnValue; |
| 5057 | } |
| 5058 | |
| 5059 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5060 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5061 | try { |
| 5062 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5063 | } catch (RuntimeException e) { |
| 5064 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5065 | } |
| 5066 | } |
| 5067 | |
| 5068 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5069 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5070 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5071 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5072 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5073 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5074 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5075 | final long identity = Binder.clearCallingIdentity(); |
| 5076 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5077 | TelephonyPermissions |
| 5078 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5079 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5080 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5081 | } finally { |
| 5082 | Binder.restoreCallingIdentity(identity); |
| 5083 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5084 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5085 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5086 | |
| 5087 | @Override |
| 5088 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5089 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5090 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5091 | |
| 5092 | final long identity = Binder.clearCallingIdentity(); |
| 5093 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5094 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5095 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5096 | } finally { |
| 5097 | Binder.restoreCallingIdentity(identity); |
| 5098 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5099 | } |
| 5100 | |
| 5101 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5102 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5103 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5104 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5105 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5106 | return false; |
| 5107 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5108 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5109 | final long identity = Binder.clearCallingIdentity(); |
| 5110 | try { |
| 5111 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5112 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5113 | // In the long run, we may instead need to check if there exists a connection service |
| 5114 | // which can support video calling. |
| 5115 | ImsManager imsManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5116 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5117 | return imsManager.isVtEnabledByPlatform() |
| 5118 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5119 | && imsManager.isVtEnabledByUser(); |
| 5120 | } finally { |
| 5121 | Binder.restoreCallingIdentity(identity); |
| 5122 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5123 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5124 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5125 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5126 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5127 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5128 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5129 | return false; |
| 5130 | } |
| 5131 | |
| 5132 | final long identity = Binder.clearCallingIdentity(); |
| 5133 | try { |
| 5134 | CarrierConfigManager configManager = |
| 5135 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5136 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5137 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5138 | } finally { |
| 5139 | Binder.restoreCallingIdentity(identity); |
| 5140 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5141 | } |
| 5142 | |
| 5143 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5144 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5145 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5146 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5147 | return false; |
| 5148 | } |
| 5149 | |
| 5150 | final long identity = Binder.clearCallingIdentity(); |
| 5151 | try { |
| 5152 | CarrierConfigManager configManager = |
| 5153 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5154 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5155 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5156 | } finally { |
| 5157 | Binder.restoreCallingIdentity(identity); |
| 5158 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5159 | } |
| 5160 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5161 | @Override |
| 5162 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5163 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5164 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | @Override |
| 5168 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5169 | final long identity = Binder.clearCallingIdentity(); |
| 5170 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5171 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5172 | } finally { |
| 5173 | Binder.restoreCallingIdentity(identity); |
| 5174 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5175 | } |
| 5176 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5177 | /** |
| 5178 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5179 | * support for the feature and device firmware support. |
| 5180 | * |
| 5181 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5182 | */ |
| 5183 | @Override |
| 5184 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5185 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5186 | final Phone phone = getPhone(subscriptionId); |
| 5187 | if (phone == null) { |
| 5188 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5189 | return false; |
| 5190 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5191 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5192 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5193 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5194 | boolean isDeviceSupported = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5195 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5196 | return isCarrierSupported && isDeviceSupported; |
| 5197 | } finally { |
| 5198 | Binder.restoreCallingIdentity(identity); |
| 5199 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5200 | } |
| 5201 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5202 | /** |
| 5203 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 5204 | * both also support RTT. |
| 5205 | */ |
| 5206 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5207 | final long identity = Binder.clearCallingIdentity(); |
| 5208 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5209 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5210 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5211 | } finally { |
| 5212 | Binder.restoreCallingIdentity(identity); |
| 5213 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5214 | } |
| 5215 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5216 | /** |
| 5217 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5218 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5219 | * |
| 5220 | * <p>Requires Permission: |
| 5221 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5222 | */ |
| 5223 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5224 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5225 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5226 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5227 | return null; |
| 5228 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5229 | int subId = phone.getSubId(); |
| 5230 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5231 | mApp, subId, callingPackage, "getDeviceId")) { |
| 5232 | return null; |
| 5233 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5234 | |
| 5235 | final long identity = Binder.clearCallingIdentity(); |
| 5236 | try { |
| 5237 | return phone.getDeviceId(); |
| 5238 | } finally { |
| 5239 | Binder.restoreCallingIdentity(identity); |
| 5240 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5241 | } |
| 5242 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5243 | /** |
| 5244 | * {@hide} |
| 5245 | * Returns the IMS Registration Status on a particular subid |
| 5246 | * |
| 5247 | * @param subId |
| 5248 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5249 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5250 | Phone phone = getPhone(subId); |
| 5251 | if (phone != null) { |
| 5252 | return phone.isImsRegistered(); |
| 5253 | } else { |
| 5254 | return false; |
| 5255 | } |
| 5256 | } |
| 5257 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5258 | @Override |
| 5259 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5260 | final long identity = Binder.clearCallingIdentity(); |
| 5261 | try { |
| 5262 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5263 | } finally { |
| 5264 | Binder.restoreCallingIdentity(identity); |
| 5265 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5266 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5267 | |
Tyler Gunn | 327a972 | 2019-04-03 15:28:53 -0700 | [diff] [blame^] | 5268 | @Override |
| 5269 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5270 | final long identity = Binder.clearCallingIdentity(); |
| 5271 | try { |
| 5272 | Phone phone = getPhone(subscriptionId); |
| 5273 | if (phone == null) { |
| 5274 | return null; |
| 5275 | } |
| 5276 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5277 | } finally { |
| 5278 | Binder.restoreCallingIdentity(identity); |
| 5279 | } |
| 5280 | } |
| 5281 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5282 | /** |
| 5283 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5284 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5285 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5286 | final long identity = Binder.clearCallingIdentity(); |
| 5287 | try { |
| 5288 | Phone phone = getPhone(subId); |
| 5289 | if (phone != null) { |
| 5290 | return phone.isWifiCallingEnabled(); |
| 5291 | } else { |
| 5292 | return false; |
| 5293 | } |
| 5294 | } finally { |
| 5295 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5296 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5297 | } |
| 5298 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5299 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5300 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5301 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5302 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5303 | final long identity = Binder.clearCallingIdentity(); |
| 5304 | try { |
| 5305 | Phone phone = getPhone(subId); |
| 5306 | if (phone != null) { |
| 5307 | return phone.isVideoEnabled(); |
| 5308 | } else { |
| 5309 | return false; |
| 5310 | } |
| 5311 | } finally { |
| 5312 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5313 | } |
| 5314 | } |
| 5315 | |
| 5316 | /** |
| 5317 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5318 | * defined in {@link ImsRegistrationImplBase}. |
| 5319 | */ |
| 5320 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5321 | final long identity = Binder.clearCallingIdentity(); |
| 5322 | try { |
| 5323 | Phone phone = getPhone(subId); |
| 5324 | if (phone != null) { |
| 5325 | return phone.getImsRegistrationTech(); |
| 5326 | } else { |
| 5327 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5328 | } |
| 5329 | } finally { |
| 5330 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5331 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5332 | } |
| 5333 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5334 | @Override |
| 5335 | public void factoryReset(int subId) { |
| 5336 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5337 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5338 | return; |
| 5339 | } |
| 5340 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5341 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5342 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5343 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5344 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5345 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5346 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5347 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5348 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5349 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5350 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5351 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5352 | // There has been issues when Sms raw table somehow stores orphan |
| 5353 | // fragments. They lead to garbled message when new fragments come |
| 5354 | // in and combined with those stale ones. In case this happens again, |
| 5355 | // user can reset all network settings which will clean up this table. |
| 5356 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5357 | } finally { |
| 5358 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5359 | } |
| 5360 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5361 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5362 | private void cleanUpSmsRawTable(Context context) { |
| 5363 | ContentResolver resolver = context.getContentResolver(); |
| 5364 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5365 | resolver.delete(uri, null, null); |
| 5366 | } |
| 5367 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5368 | @Override |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5369 | public String getSimLocaleForSubscriber(int subId) { |
| 5370 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5371 | final Phone phone = getPhone(subId); |
| 5372 | if (phone == null) { |
| 5373 | log("getSimLocaleForSubscriber, invalid subId"); |
Pengquan Meng | 9c29148 | 2019-01-28 16:26:29 -0800 | [diff] [blame] | 5374 | return null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5375 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5376 | final long identity = Binder.clearCallingIdentity(); |
| 5377 | try { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5378 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5379 | phone.getContext().getOpPackageName()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5380 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5381 | // preferences (EF-PL and EF-LI)... |
| 5382 | final int mcc = info.getMcc(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5383 | String simLanguage = null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5384 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5385 | if (localeFromDefaultSim != null) { |
| 5386 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5387 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5388 | + localeFromDefaultSim); |
| 5389 | return localeFromDefaultSim.toLanguageTag(); |
| 5390 | } else { |
| 5391 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5392 | } |
| 5393 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5394 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5395 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5396 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5397 | // the SIM and carrier preferences does not include a country we add the country |
| 5398 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5399 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5400 | if (mccLocale != null) { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5401 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5402 | return mccLocale.toLanguageTag(); |
| 5403 | } |
| 5404 | |
| 5405 | if (DBG) log("No locale found - returning null"); |
| 5406 | return null; |
| 5407 | } finally { |
| 5408 | Binder.restoreCallingIdentity(identity); |
| 5409 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5413 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5414 | } |
| 5415 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5416 | /** |
| 5417 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5418 | */ |
| 5419 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5420 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5421 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5422 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5423 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5424 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5425 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5426 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5427 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5428 | * representing the state of the modem. |
| 5429 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5430 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5431 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5432 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5433 | */ |
| 5434 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5435 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5436 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5437 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5438 | |
| 5439 | final long identity = Binder.clearCallingIdentity(); |
| 5440 | try { |
| 5441 | ModemActivityInfo ret = null; |
| 5442 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5443 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5444 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 5445 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5446 | if (isModemActivityInfoValid(info)) { |
| 5447 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5448 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 5449 | mergedTxTimeMs[i] = |
| 5450 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 5451 | } |
| 5452 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 5453 | mLastModemActivityInfo.setSleepTimeMillis( |
| 5454 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 5455 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5456 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5457 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5458 | mLastModemActivityInfo.setRxTimeMillis( |
| 5459 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5460 | mLastModemActivityInfo.setEnergyUsed( |
| 5461 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5462 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5463 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5464 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5465 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5466 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5467 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5468 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5469 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5470 | Bundle bundle = new Bundle(); |
| 5471 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5472 | result.send(0, bundle); |
| 5473 | } finally { |
| 5474 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5475 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5476 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5477 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5478 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5479 | // less than total activity duration. |
| 5480 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5481 | if (info == null) { |
| 5482 | return false; |
| 5483 | } |
| 5484 | int activityDurationMs = |
| 5485 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5486 | int totalTxTimeMs = 0; |
| 5487 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5488 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5489 | } |
| 5490 | return (info.isValid() |
| 5491 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5492 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5493 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5494 | && (totalTxTimeMs <= activityDurationMs)); |
| 5495 | } |
| 5496 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5497 | /** |
| 5498 | * {@hide} |
| 5499 | * Returns the service state information on specified subscription. |
| 5500 | */ |
| 5501 | @Override |
| 5502 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5503 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5504 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5505 | return null; |
| 5506 | } |
| 5507 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5508 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5509 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5510 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5511 | .setCallingPackage(callingPackage) |
| 5512 | .setCallingPid(Binder.getCallingPid()) |
| 5513 | .setCallingUid(Binder.getCallingUid()) |
| 5514 | .setMethod("getServiceStateForSubscriber") |
| 5515 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5516 | .build()); |
| 5517 | |
| 5518 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5519 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5520 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5521 | .setCallingPackage(callingPackage) |
| 5522 | .setCallingPid(Binder.getCallingPid()) |
| 5523 | .setCallingUid(Binder.getCallingUid()) |
| 5524 | .setMethod("getServiceStateForSubscriber") |
| 5525 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5526 | .build()); |
| 5527 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5528 | boolean hasFinePermission = |
| 5529 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5530 | boolean hasCoarsePermission = |
| 5531 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5532 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5533 | final long identity = Binder.clearCallingIdentity(); |
| 5534 | try { |
| 5535 | final Phone phone = getPhone(subId); |
| 5536 | if (phone == null) { |
| 5537 | return null; |
| 5538 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5539 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5540 | ServiceState ss = phone.getServiceState(); |
| 5541 | |
| 5542 | // Scrub out the location info in ServiceState depending on what level of access |
| 5543 | // the caller has. |
| 5544 | if (hasFinePermission) return ss; |
| 5545 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5546 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5547 | } finally { |
| 5548 | Binder.restoreCallingIdentity(identity); |
| 5549 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5550 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5551 | |
| 5552 | /** |
| 5553 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5554 | * |
| 5555 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5556 | * voicemail ringtone. |
| 5557 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5558 | * PhoneAccount. |
| 5559 | */ |
| 5560 | @Override |
| 5561 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5562 | final long identity = Binder.clearCallingIdentity(); |
| 5563 | try { |
| 5564 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5565 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5566 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5567 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5568 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5569 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5570 | } finally { |
| 5571 | Binder.restoreCallingIdentity(identity); |
| 5572 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5573 | } |
| 5574 | |
| 5575 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5576 | * Sets the per-account voicemail ringtone. |
| 5577 | * |
| 5578 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5579 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5580 | * |
| 5581 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5582 | * voicemail ringtone. |
| 5583 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5584 | * PhoneAccount. |
| 5585 | */ |
| 5586 | @Override |
| 5587 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5588 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5589 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5590 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5591 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5592 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5593 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5594 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5595 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5596 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5597 | |
| 5598 | final long identity = Binder.clearCallingIdentity(); |
| 5599 | try { |
| 5600 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5601 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5602 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5603 | } |
| 5604 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5605 | } finally { |
| 5606 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5607 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5608 | } |
| 5609 | |
| 5610 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5611 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5612 | * |
| 5613 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5614 | * voicemail vibration setting. |
| 5615 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5616 | */ |
| 5617 | @Override |
| 5618 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5619 | final long identity = Binder.clearCallingIdentity(); |
| 5620 | try { |
| 5621 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5622 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5623 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5624 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5625 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5626 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5627 | } finally { |
| 5628 | Binder.restoreCallingIdentity(identity); |
| 5629 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5630 | } |
| 5631 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5632 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5633 | * Sets the per-account voicemail vibration. |
| 5634 | * |
| 5635 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5636 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5637 | * |
| 5638 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5639 | * voicemail vibration setting. |
| 5640 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5641 | * specific PhoneAccount. |
| 5642 | */ |
| 5643 | @Override |
| 5644 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5645 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5646 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5647 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5648 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5649 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5650 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5651 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5652 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5653 | } |
| 5654 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5655 | final long identity = Binder.clearCallingIdentity(); |
| 5656 | try { |
| 5657 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5658 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5659 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5660 | } |
| 5661 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5662 | } finally { |
| 5663 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5664 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5668 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5669 | * |
| 5670 | * @throws SecurityException if the caller does not have the required permission |
| 5671 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5672 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5673 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5674 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5675 | } |
| 5676 | |
| 5677 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5678 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5679 | * permission. |
| 5680 | * |
| 5681 | * @throws SecurityException if the caller does not have the required permission |
| 5682 | */ |
| 5683 | private void enforceSendSmsPermission() { |
| 5684 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5685 | } |
| 5686 | |
| 5687 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5688 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5689 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5690 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5691 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5692 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5693 | final long identity = Binder.clearCallingIdentity(); |
| 5694 | try { |
| 5695 | ComponentName componentName = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5696 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5697 | if (componentName == null) { |
| 5698 | throw new SecurityException( |
| 5699 | "Caller not current active visual voicemail package[null]"); |
| 5700 | } |
| 5701 | String vvmPackage = componentName.getPackageName(); |
| 5702 | if (!callingPackage.equals(vvmPackage)) { |
| 5703 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5704 | + vvmPackage + "]"); |
| 5705 | } |
| 5706 | } finally { |
| 5707 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5708 | } |
| 5709 | } |
| 5710 | |
| 5711 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5712 | * Return the application ID for the app type. |
| 5713 | * |
| 5714 | * @param subId the subscription ID that this request applies to. |
| 5715 | * @param appType the uicc app type. |
| 5716 | * @return Application ID for specificied app type, or null if no uicc. |
| 5717 | */ |
| 5718 | @Override |
| 5719 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5720 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5721 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5722 | |
| 5723 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5724 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5725 | if (phone == null) { |
| 5726 | return null; |
| 5727 | } |
| 5728 | String aid = null; |
| 5729 | try { |
| 5730 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5731 | .getApplicationByType(appType).getAid(); |
| 5732 | } catch (Exception e) { |
| 5733 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5734 | } |
| 5735 | return aid; |
| 5736 | } finally { |
| 5737 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5738 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5739 | } |
| 5740 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5741 | /** |
| 5742 | * Return the Electronic Serial Number. |
| 5743 | * |
| 5744 | * @param subId the subscription ID that this request applies to. |
| 5745 | * @return ESN or null if error. |
| 5746 | */ |
| 5747 | @Override |
| 5748 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5749 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5750 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5751 | |
| 5752 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5753 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5754 | if (phone == null) { |
| 5755 | return null; |
| 5756 | } |
| 5757 | String esn = null; |
| 5758 | try { |
| 5759 | esn = phone.getEsn(); |
| 5760 | } catch (Exception e) { |
| 5761 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5762 | } |
| 5763 | return esn; |
| 5764 | } finally { |
| 5765 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5766 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5767 | } |
| 5768 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5769 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5770 | * Return the Preferred Roaming List Version. |
| 5771 | * |
| 5772 | * @param subId the subscription ID that this request applies to. |
| 5773 | * @return PRLVersion or null if error. |
| 5774 | */ |
| 5775 | @Override |
| 5776 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5777 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5778 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5779 | |
| 5780 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5781 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5782 | if (phone == null) { |
| 5783 | return null; |
| 5784 | } |
| 5785 | String cdmaPrlVersion = null; |
| 5786 | try { |
| 5787 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5788 | } catch (Exception e) { |
| 5789 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5790 | } |
| 5791 | return cdmaPrlVersion; |
| 5792 | } finally { |
| 5793 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5794 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5795 | } |
| 5796 | |
| 5797 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5798 | * Get snapshot of Telephony histograms |
| 5799 | * @return List of Telephony histograms |
| 5800 | * @hide |
| 5801 | */ |
| 5802 | @Override |
| 5803 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5804 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5805 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5806 | |
| 5807 | final long identity = Binder.clearCallingIdentity(); |
| 5808 | try { |
| 5809 | return RIL.getTelephonyRILTimingHistograms(); |
| 5810 | } finally { |
| 5811 | Binder.restoreCallingIdentity(identity); |
| 5812 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5813 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5814 | |
| 5815 | /** |
| 5816 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5817 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5818 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5819 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5820 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5821 | * @return Integer with the result of the operation, as defined in {@link TelephonyManager}. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5822 | */ |
| 5823 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5824 | @TelephonyManager.SetCarrierRestrictionResult |
| 5825 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5826 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5827 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5828 | |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5829 | if (carrierRestrictionRules == null) { |
| 5830 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5831 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5832 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5833 | final long identity = Binder.clearCallingIdentity(); |
| 5834 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5835 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5836 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5837 | } finally { |
| 5838 | Binder.restoreCallingIdentity(identity); |
| 5839 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5840 | } |
| 5841 | |
| 5842 | /** |
| 5843 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5844 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5845 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5846 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5847 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5848 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5849 | */ |
| 5850 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5851 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5852 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5853 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5854 | |
| 5855 | final long identity = Binder.clearCallingIdentity(); |
| 5856 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5857 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5858 | if (response instanceof CarrierRestrictionRules) { |
| 5859 | return (CarrierRestrictionRules) response; |
| 5860 | } |
| 5861 | // Response is an Exception of some kind, |
| 5862 | // which is signalled to the user as a NULL retval |
| 5863 | return null; |
| 5864 | } catch (Exception e) { |
| 5865 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5866 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5867 | } finally { |
| 5868 | Binder.restoreCallingIdentity(identity); |
| 5869 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5870 | } |
| 5871 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5872 | /** |
| 5873 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5874 | * @param subId the subscription ID that this action applies to. |
| 5875 | * @param enabled control enable or disable metered apns. |
| 5876 | * {@hide} |
| 5877 | */ |
| 5878 | @Override |
| 5879 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5880 | enforceModifyPermission(); |
| 5881 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5882 | |
| 5883 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5884 | if (phone == null) { |
| 5885 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5886 | return; |
| 5887 | } |
| 5888 | try { |
| 5889 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5890 | } catch (Exception e) { |
| 5891 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5892 | } finally { |
| 5893 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5894 | } |
| 5895 | } |
| 5896 | |
| 5897 | /** |
| 5898 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5899 | * @param subId the subscription ID that this action applies to. |
| 5900 | * @param enabled control enable or disable radio. |
| 5901 | * {@hide} |
| 5902 | */ |
| 5903 | @Override |
| 5904 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5905 | enforceModifyPermission(); |
| 5906 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5907 | |
| 5908 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5909 | if (phone == null) { |
| 5910 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5911 | return; |
| 5912 | } |
| 5913 | try { |
| 5914 | phone.carrierActionSetRadioEnabled(enabled); |
| 5915 | } catch (Exception e) { |
| 5916 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5917 | } finally { |
| 5918 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5919 | } |
| 5920 | } |
| 5921 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5922 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5923 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5924 | * network status based on which carrier apps could apply actions accordingly, |
| 5925 | * enable/disable default url handler for example. |
| 5926 | * |
| 5927 | * @param subId the subscription ID that this action applies to. |
| 5928 | * @param report control start/stop reporting the default network status. |
| 5929 | * {@hide} |
| 5930 | */ |
| 5931 | @Override |
| 5932 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5933 | enforceModifyPermission(); |
| 5934 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5935 | |
| 5936 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5937 | if (phone == null) { |
| 5938 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5939 | return; |
| 5940 | } |
| 5941 | try { |
| 5942 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5943 | } catch (Exception e) { |
| 5944 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5945 | } finally { |
| 5946 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5947 | } |
| 5948 | } |
| 5949 | |
| 5950 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5951 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5952 | * bug report is being generated. |
| 5953 | */ |
| 5954 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5955 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5956 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5957 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5958 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5959 | + Binder.getCallingPid() |
| 5960 | + ", uid=" + Binder.getCallingUid() |
| 5961 | + "without permission " |
| 5962 | + android.Manifest.permission.DUMP); |
| 5963 | return; |
| 5964 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5965 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5966 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5967 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5968 | @Override |
| 5969 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5970 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5971 | throws RemoteException { |
| 5972 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5973 | } |
| 5974 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5975 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5976 | * Get aggregated video call data usage since boot. |
| 5977 | * |
| 5978 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5979 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5980 | * {@hide} |
| 5981 | */ |
| 5982 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5983 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5984 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5985 | null); |
| 5986 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5987 | final long identity = Binder.clearCallingIdentity(); |
| 5988 | try { |
| 5989 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5990 | // records the delta with the corresponding network identity. |
| 5991 | // We just return the total video call data usage snapshot since boot. |
| 5992 | Phone phone = getPhone(subId); |
| 5993 | if (phone != null) { |
| 5994 | return phone.getVtDataUsage(perUidStats); |
| 5995 | } |
| 5996 | return null; |
| 5997 | } finally { |
| 5998 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5999 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6000 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6001 | |
| 6002 | /** |
| 6003 | * Policy control of data connection. Usually used when data limit is passed. |
| 6004 | * @param enabled True if enabling the data, otherwise disabling. |
| 6005 | * @param subId Subscription index |
| 6006 | * {@hide} |
| 6007 | */ |
| 6008 | @Override |
| 6009 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6010 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6011 | |
| 6012 | final long identity = Binder.clearCallingIdentity(); |
| 6013 | try { |
| 6014 | Phone phone = getPhone(subId); |
| 6015 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6016 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6017 | } |
| 6018 | } finally { |
| 6019 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6020 | } |
| 6021 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6022 | |
| 6023 | /** |
| 6024 | * Get Client request stats |
| 6025 | * @return List of Client Request Stats |
| 6026 | * @hide |
| 6027 | */ |
| 6028 | @Override |
| 6029 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6030 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6031 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6032 | return null; |
| 6033 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6034 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6035 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6036 | final long identity = Binder.clearCallingIdentity(); |
| 6037 | try { |
| 6038 | if (phone != null) { |
| 6039 | return phone.getClientRequestStats(); |
| 6040 | } |
| 6041 | |
| 6042 | return null; |
| 6043 | } finally { |
| 6044 | Binder.restoreCallingIdentity(identity); |
| 6045 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6046 | } |
| 6047 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6048 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6049 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6050 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6051 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6052 | |
| 6053 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6054 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6055 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6056 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6057 | * @param state State of SIM (power down, power up, pass through) |
| 6058 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6059 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6060 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6061 | * |
| 6062 | **/ |
| 6063 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6064 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6065 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6066 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6067 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6068 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6069 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6070 | final long identity = Binder.clearCallingIdentity(); |
| 6071 | try { |
| 6072 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6073 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6074 | } |
| 6075 | } finally { |
| 6076 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6077 | } |
| 6078 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6079 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6080 | private boolean isUssdApiAllowed(int subId) { |
| 6081 | CarrierConfigManager configManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6082 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6083 | if (configManager == null) { |
| 6084 | return false; |
| 6085 | } |
| 6086 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6087 | if (pb == null) { |
| 6088 | return false; |
| 6089 | } |
| 6090 | return pb.getBoolean( |
| 6091 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6092 | } |
| 6093 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6094 | /** |
| 6095 | * Check if phone is in emergency callback mode |
| 6096 | * @return true if phone is in emergency callback mode |
| 6097 | * @param subId sub id |
| 6098 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6099 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6100 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6101 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6102 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6103 | |
| 6104 | final long identity = Binder.clearCallingIdentity(); |
| 6105 | try { |
| 6106 | if (phone != null) { |
| 6107 | return phone.isInEcm(); |
| 6108 | } else { |
| 6109 | return false; |
| 6110 | } |
| 6111 | } finally { |
| 6112 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6113 | } |
| 6114 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6115 | |
| 6116 | /** |
| 6117 | * Get the current signal strength information for the given subscription. |
| 6118 | * Because this information is not updated when the device is in a low power state |
| 6119 | * it should not be relied-upon to be current. |
| 6120 | * @param subId Subscription index |
| 6121 | * @return the most recent cached signal strength info from the modem |
| 6122 | */ |
| 6123 | @Override |
| 6124 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6125 | final long identity = Binder.clearCallingIdentity(); |
| 6126 | try { |
| 6127 | Phone p = getPhone(subId); |
| 6128 | if (p == null) { |
| 6129 | return null; |
| 6130 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6131 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6132 | return p.getSignalStrength(); |
| 6133 | } finally { |
| 6134 | Binder.restoreCallingIdentity(identity); |
| 6135 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6136 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6137 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6138 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 6139 | * Get the current modem radio state for the given slot. |
| 6140 | * @param slotIndex slot index. |
| 6141 | * @param callingPackage the name of the package making the call. |
| 6142 | * @return the current radio power state from the modem |
| 6143 | */ |
| 6144 | @Override |
| 6145 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6146 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6147 | if (phone != null) { |
| 6148 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6149 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6150 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6151 | } |
| 6152 | |
| 6153 | final long identity = Binder.clearCallingIdentity(); |
| 6154 | try { |
| 6155 | return phone.getRadioPowerState(); |
| 6156 | } finally { |
| 6157 | Binder.restoreCallingIdentity(identity); |
| 6158 | } |
| 6159 | } |
| 6160 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6161 | } |
| 6162 | |
| 6163 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6164 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6165 | * |
| 6166 | * <p>Requires one of the following permissions: |
| 6167 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6168 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6169 | * privileges. |
| 6170 | * |
| 6171 | * @param subId subscription id |
| 6172 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6173 | * {@code false}. |
| 6174 | */ |
| 6175 | @Override |
| 6176 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6177 | boolean isEnabled = false; |
| 6178 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6179 | try { |
| 6180 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6181 | null /* message */); |
| 6182 | Phone phone = getPhone(subId); |
| 6183 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6184 | } catch (Exception e) { |
| 6185 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6186 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6187 | } finally { |
| 6188 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6189 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6190 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6191 | } |
| 6192 | |
| 6193 | |
| 6194 | /** |
| 6195 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6196 | * |
| 6197 | * <p> Requires permission: |
| 6198 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6199 | * privileges. |
| 6200 | * |
| 6201 | * @param subId subscription id |
| 6202 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6203 | */ |
| 6204 | @Override |
| 6205 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6206 | final long identity = Binder.clearCallingIdentity(); |
| 6207 | try { |
| 6208 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6209 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6210 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6211 | Phone phone = getPhone(subId); |
| 6212 | if (phone != null) { |
| 6213 | phone.setDataRoamingEnabled(isEnabled); |
| 6214 | } |
| 6215 | } finally { |
| 6216 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6217 | } |
| 6218 | } |
| 6219 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6220 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6221 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 6222 | boolean isAllowed = true; |
| 6223 | final long identity = Binder.clearCallingIdentity(); |
| 6224 | try { |
| 6225 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6226 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6227 | Phone phone = getPhone(subId); |
| 6228 | if (phone != null) { |
| 6229 | isAllowed = phone.isCspPlmnEnabled(); |
| 6230 | } |
| 6231 | } finally { |
| 6232 | Binder.restoreCallingIdentity(identity); |
| 6233 | } |
| 6234 | return isAllowed; |
| 6235 | } |
| 6236 | |
| 6237 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6238 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6239 | try { |
| 6240 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
| 6241 | } catch (SecurityException e) { |
| 6242 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6243 | // has carrier privileges on an active UICC |
| 6244 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6245 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6246 | throw new SecurityException("Caller does not have carrier privileges on any UICC"); |
| 6247 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6248 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6249 | |
| 6250 | final long identity = Binder.clearCallingIdentity(); |
| 6251 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6252 | UiccController uiccController = UiccController.getInstance(); |
| 6253 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
| 6254 | |
| 6255 | ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0); |
| 6256 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 6257 | // Remove private info if the caller doesn't have access |
| 6258 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6259 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6260 | UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex()); |
| 6261 | UiccProfile profile = card.getUiccProfile(); |
| 6262 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6263 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6264 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6265 | } else { |
| 6266 | filteredInfos.add(cardInfo); |
| 6267 | } |
| 6268 | } |
| 6269 | return filteredInfos; |
| 6270 | } |
| 6271 | return cardInfos; |
| 6272 | } catch (PackageManager.NameNotFoundException e) { |
| 6273 | // This should not happen since we pass the package info in from TelephonyManager |
| 6274 | throw new SecurityException("Invalid calling package."); |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6275 | } finally { |
| 6276 | Binder.restoreCallingIdentity(identity); |
| 6277 | } |
| 6278 | } |
| 6279 | |
| 6280 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6281 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6282 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6283 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6284 | final long identity = Binder.clearCallingIdentity(); |
| 6285 | try { |
| 6286 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6287 | if (slots == null) { |
| 6288 | Rlog.i(LOG_TAG, "slots is null."); |
| 6289 | return null; |
| 6290 | } |
| 6291 | |
| 6292 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6293 | for (int i = 0; i < slots.length; i++) { |
| 6294 | UiccSlot slot = slots[i]; |
| 6295 | if (slot == null) { |
| 6296 | continue; |
| 6297 | } |
| 6298 | |
| 6299 | String cardId; |
| 6300 | UiccCard card = slot.getUiccCard(); |
| 6301 | if (card != null) { |
| 6302 | cardId = card.getCardId(); |
| 6303 | } else { |
| 6304 | cardId = slot.getIccId(); |
| 6305 | } |
| 6306 | |
| 6307 | int cardState = 0; |
| 6308 | switch (slot.getCardState()) { |
| 6309 | case CARDSTATE_ABSENT: |
| 6310 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6311 | break; |
| 6312 | case CARDSTATE_PRESENT: |
| 6313 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6314 | break; |
| 6315 | case CARDSTATE_ERROR: |
| 6316 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6317 | break; |
| 6318 | case CARDSTATE_RESTRICTED: |
| 6319 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6320 | break; |
| 6321 | default: |
| 6322 | break; |
| 6323 | |
| 6324 | } |
| 6325 | |
| 6326 | infos[i] = new UiccSlotInfo( |
| 6327 | slot.isActive(), |
| 6328 | slot.isEuicc(), |
| 6329 | cardId, |
| 6330 | cardState, |
| 6331 | slot.getPhoneId(), |
Jordan Liu | ef65d87 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6332 | slot.isExtendedApduSupported(), |
| 6333 | slot.isRemovable()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6334 | } |
| 6335 | return infos; |
| 6336 | } finally { |
| 6337 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6338 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6339 | } |
| 6340 | |
| 6341 | @Override |
| 6342 | public boolean switchSlots(int[] physicalSlots) { |
| 6343 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6344 | |
| 6345 | final long identity = Binder.clearCallingIdentity(); |
| 6346 | try { |
| 6347 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6348 | } finally { |
| 6349 | Binder.restoreCallingIdentity(identity); |
| 6350 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6351 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6352 | |
| 6353 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6354 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6355 | final long identity = Binder.clearCallingIdentity(); |
| 6356 | try { |
| 6357 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6358 | } finally { |
| 6359 | Binder.restoreCallingIdentity(identity); |
| 6360 | } |
| 6361 | } |
| 6362 | |
| 6363 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6364 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6365 | enforceModifyPermission(); |
| 6366 | final Phone phone = getPhone(subId); |
| 6367 | if (phone == null) { |
| 6368 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6369 | return; |
| 6370 | } |
| 6371 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6372 | final long identity = Binder.clearCallingIdentity(); |
| 6373 | try { |
| 6374 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6375 | } finally { |
| 6376 | Binder.restoreCallingIdentity(identity); |
| 6377 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6378 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6379 | |
| 6380 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6381 | * A test API to reload the UICC profile. |
| 6382 | * |
| 6383 | * <p>Requires that the calling app has permission |
| 6384 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6385 | * @hide |
| 6386 | */ |
| 6387 | @Override |
| 6388 | public void refreshUiccProfile(int subId) { |
| 6389 | enforceModifyPermission(); |
| 6390 | |
| 6391 | final long identity = Binder.clearCallingIdentity(); |
| 6392 | try { |
| 6393 | Phone phone = getPhone(subId); |
| 6394 | if (phone == null) { |
| 6395 | return; |
| 6396 | } |
| 6397 | UiccCard uiccCard = phone.getUiccCard(); |
| 6398 | if (uiccCard == null) { |
| 6399 | return; |
| 6400 | } |
| 6401 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6402 | if (uiccProfile == null) { |
| 6403 | return; |
| 6404 | } |
| 6405 | uiccProfile.refresh(); |
| 6406 | } finally { |
| 6407 | Binder.restoreCallingIdentity(identity); |
| 6408 | } |
| 6409 | } |
| 6410 | |
| 6411 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6412 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6413 | */ |
| 6414 | private boolean getDefaultDataEnabled() { |
| 6415 | return "true".equalsIgnoreCase( |
| 6416 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6417 | } |
| 6418 | |
| 6419 | /** |
| 6420 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6421 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6422 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6423 | */ |
| 6424 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6425 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6426 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6427 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6428 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6429 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6430 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6431 | return isDataRoamingEnabled; |
| 6432 | } |
| 6433 | |
| 6434 | /** |
| 6435 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6436 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6437 | */ |
| 6438 | private int getDefaultNetworkType(int subId) { |
| 6439 | return Integer.parseInt( |
| 6440 | TelephonyManager.getTelephonyProperty( |
| 6441 | mSubscriptionController.getPhoneId(subId), |
| 6442 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6443 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6444 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6445 | |
| 6446 | @Override |
| 6447 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 6448 | gid1, String gid2, String plmn, String spn) { |
| 6449 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6450 | |
| 6451 | final long identity = Binder.clearCallingIdentity(); |
| 6452 | try { |
| 6453 | final Phone phone = getPhone(subId); |
| 6454 | if (phone == null) { |
| 6455 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6456 | return; |
| 6457 | } |
| 6458 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 6459 | } finally { |
| 6460 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6461 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6462 | } |
| 6463 | |
| 6464 | @Override |
| 6465 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6466 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6467 | |
| 6468 | final long identity = Binder.clearCallingIdentity(); |
| 6469 | try { |
| 6470 | final Phone phone = getPhone(subId); |
| 6471 | if (phone == null) { |
| 6472 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6473 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6474 | } |
| 6475 | return phone.getCarrierIdListVersion(); |
| 6476 | } finally { |
| 6477 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6478 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6479 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6480 | |
| 6481 | @Override |
| 6482 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6483 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6484 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6485 | return -1; |
| 6486 | } |
| 6487 | |
| 6488 | final long identity = Binder.clearCallingIdentity(); |
| 6489 | try { |
| 6490 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6491 | } finally { |
| 6492 | Binder.restoreCallingIdentity(identity); |
| 6493 | } |
| 6494 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6495 | |
| 6496 | @Override |
| 6497 | public int getCdmaRoamingMode(int subId) { |
| 6498 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6499 | mApp, subId, "getCdmaRoamingMode"); |
| 6500 | |
| 6501 | final long identity = Binder.clearCallingIdentity(); |
| 6502 | try { |
| 6503 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6504 | } finally { |
| 6505 | Binder.restoreCallingIdentity(identity); |
| 6506 | } |
| 6507 | } |
| 6508 | |
| 6509 | @Override |
| 6510 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6511 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6512 | mApp, subId, "setCdmaRoamingMode"); |
| 6513 | |
| 6514 | final long identity = Binder.clearCallingIdentity(); |
| 6515 | try { |
| 6516 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6517 | } finally { |
| 6518 | Binder.restoreCallingIdentity(identity); |
| 6519 | } |
| 6520 | } |
| 6521 | |
| 6522 | @Override |
| 6523 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6524 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6525 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6526 | |
| 6527 | final long identity = Binder.clearCallingIdentity(); |
| 6528 | try { |
| 6529 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6530 | } finally { |
| 6531 | Binder.restoreCallingIdentity(identity); |
| 6532 | } |
| 6533 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6534 | |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 6535 | private void ensureUserRunning(int userId) { |
| 6536 | if (!mUserManager.isUserRunning(userId)) { |
| 6537 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6538 | } |
| 6539 | } |
| 6540 | |
| 6541 | /** |
| 6542 | * Returns a list of SMS apps on a given user. |
| 6543 | * |
| 6544 | * Only the shell user (UID 2000 or 0) can call it. |
| 6545 | * Target user must be running. |
| 6546 | */ |
| 6547 | @Override |
| 6548 | public String[] getSmsApps(int userId) { |
| 6549 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6550 | ensureUserRunning(userId); |
| 6551 | |
| 6552 | final Collection<SmsApplicationData> apps = |
| 6553 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6554 | |
| 6555 | String[] ret = new String[apps.size()]; |
| 6556 | int i = 0; |
| 6557 | for (SmsApplicationData app : apps) { |
| 6558 | ret[i++] = app.mPackageName; |
| 6559 | } |
| 6560 | return ret; |
| 6561 | } |
| 6562 | |
| 6563 | /** |
| 6564 | * Returns the default SMS app package name on a given user. |
| 6565 | * |
| 6566 | * Only the shell user (UID 2000 or 0) can call it. |
| 6567 | * Target user must be running. |
| 6568 | */ |
| 6569 | @Override |
| 6570 | public String getDefaultSmsApp(int userId) { |
| 6571 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6572 | ensureUserRunning(userId); |
| 6573 | |
| 6574 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6575 | /* updateIfNeeded= */ true, userId); |
| 6576 | return cn == null ? null : cn.getPackageName(); |
| 6577 | } |
| 6578 | |
| 6579 | /** |
| 6580 | * Set a package as the default SMS app on a given user. |
| 6581 | * |
| 6582 | * Only the shell user (UID 2000 or 0) can call it. |
| 6583 | * Target user must be running. |
| 6584 | */ |
| 6585 | @Override |
| 6586 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6587 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6588 | ensureUserRunning(userId); |
| 6589 | |
| 6590 | boolean found = false; |
| 6591 | for (String pkg : getSmsApps(userId)) { |
| 6592 | if (TextUtils.equals(packageName, pkg)) { |
| 6593 | found = true; |
| 6594 | break; |
| 6595 | } |
| 6596 | } |
| 6597 | if (!found) { |
| 6598 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6599 | } |
| 6600 | |
| 6601 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6602 | } |
| 6603 | |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6604 | @Override |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6605 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6606 | String callingPackage) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6607 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6608 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6609 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6610 | } |
| 6611 | final long identity = Binder.clearCallingIdentity(); |
| 6612 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6613 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6614 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6615 | if (phone.getEmergencyNumberTracker() != null |
| 6616 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6617 | emergencyNumberListInternal.put( |
| 6618 | phone.getSubId(), |
| 6619 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6620 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6621 | } |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6622 | return emergencyNumberListInternal; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6623 | } finally { |
| 6624 | Binder.restoreCallingIdentity(identity); |
| 6625 | } |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6626 | } |
| 6627 | |
| 6628 | @Override |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6629 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6630 | final Phone defaultPhone = getDefaultPhone(); |
| 6631 | if (!exactMatch) { |
| 6632 | TelephonyPermissions |
| 6633 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6634 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6635 | } |
| 6636 | final long identity = Binder.clearCallingIdentity(); |
| 6637 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6638 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6639 | if (phone.getEmergencyNumberTracker() != null |
| 6640 | && phone.getEmergencyNumberTracker() != null) { |
| 6641 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6642 | number, exactMatch)) { |
| 6643 | return true; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6644 | } |
| 6645 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6646 | } |
| 6647 | return false; |
| 6648 | } finally { |
| 6649 | Binder.restoreCallingIdentity(identity); |
| 6650 | } |
| 6651 | } |
| 6652 | |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6653 | /** |
| 6654 | * Update emergency number list for test mode. |
| 6655 | */ |
| 6656 | @Override |
| 6657 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6658 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6659 | "updateEmergencyNumberListTestMode"); |
| 6660 | |
| 6661 | final long identity = Binder.clearCallingIdentity(); |
| 6662 | try { |
| 6663 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6664 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6665 | if (tracker != null) { |
| 6666 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6667 | } |
| 6668 | } |
| 6669 | } finally { |
| 6670 | Binder.restoreCallingIdentity(identity); |
| 6671 | } |
| 6672 | } |
| 6673 | |
| 6674 | /** |
| 6675 | * Get the full emergency number list for test mode. |
| 6676 | */ |
| 6677 | @Override |
| 6678 | public List<String> getEmergencyNumberListTestMode() { |
| 6679 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6680 | "getEmergencyNumberListTestMode"); |
| 6681 | |
| 6682 | final long identity = Binder.clearCallingIdentity(); |
| 6683 | try { |
| 6684 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6685 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6686 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6687 | if (tracker != null) { |
| 6688 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6689 | emergencyNumbers.add(num.getNumber()); |
| 6690 | } |
| 6691 | } |
| 6692 | } |
| 6693 | return new ArrayList<>(emergencyNumbers); |
| 6694 | } finally { |
| 6695 | Binder.restoreCallingIdentity(identity); |
| 6696 | } |
| 6697 | } |
| 6698 | |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6699 | @Override |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6700 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6701 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6702 | Phone phone = getPhone(subId); |
| 6703 | if (phone == null) { |
| 6704 | return null; |
| 6705 | } |
| 6706 | final long identity = Binder.clearCallingIdentity(); |
| 6707 | try { |
| 6708 | UiccProfile profile = UiccController.getInstance() |
| 6709 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6710 | if (profile != null) { |
| 6711 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6712 | } |
| 6713 | } finally { |
| 6714 | Binder.restoreCallingIdentity(identity); |
| 6715 | } |
| 6716 | return null; |
| 6717 | } |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6718 | |
| 6719 | /** |
| 6720 | * Enable or disable a modem stack. |
| 6721 | */ |
| 6722 | @Override |
| 6723 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6724 | enforceModifyPermission(); |
| 6725 | |
| 6726 | final long identity = Binder.clearCallingIdentity(); |
| 6727 | try { |
| 6728 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6729 | if (phone == null) { |
| 6730 | return false; |
| 6731 | } else { |
| 6732 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6733 | } |
| 6734 | } finally { |
| 6735 | Binder.restoreCallingIdentity(identity); |
| 6736 | } |
| 6737 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6738 | |
| 6739 | @Override |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6740 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6741 | enforceModifyPermission(); |
| 6742 | |
| 6743 | final long identity = Binder.clearCallingIdentity(); |
| 6744 | try { |
| 6745 | mTelephonySharedPreferences.edit() |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6746 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6747 | .commit(); |
| 6748 | } finally { |
| 6749 | Binder.restoreCallingIdentity(identity); |
| 6750 | } |
| 6751 | } |
| 6752 | |
| 6753 | @Override |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6754 | @TelephonyManager.IsMultiSimSupportedResult |
| 6755 | public int isMultiSimSupported(String callingPackage) { |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6756 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6757 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 6758 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6759 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6760 | |
| 6761 | final long identity = Binder.clearCallingIdentity(); |
| 6762 | try { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6763 | return isMultiSimSupportedInternal(); |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6764 | } finally { |
| 6765 | Binder.restoreCallingIdentity(identity); |
| 6766 | } |
| 6767 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6768 | |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6769 | @TelephonyManager.IsMultiSimSupportedResult |
| 6770 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6771 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6772 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6773 | if (numPhysicalSlots < 2) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6774 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 6775 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6776 | } |
| 6777 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 6778 | // supported by the modem, indicate that it is restricted. |
| 6779 | PhoneCapability staticCapability = |
| 6780 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 6781 | if (staticCapability == null) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6782 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 6783 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6784 | } |
| 6785 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6786 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 6787 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6788 | } |
| 6789 | // Check if support of multiple SIMs is restricted by carrier |
| 6790 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6791 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6792 | } |
| 6793 | |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6794 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6795 | } |
| 6796 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6797 | /** |
| 6798 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6799 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 6800 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 6801 | * or carrier privileges |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6802 | * @param numOfSims number of active sims we want to switch to |
| 6803 | */ |
| 6804 | @Override |
| 6805 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6806 | if (numOfSims == 1) { |
| 6807 | enforceModifyPermission(); |
| 6808 | } else { |
| 6809 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6810 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6811 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6812 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6813 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6814 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6815 | //only proceed if multi-sim is not restricted |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6816 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6817 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 6818 | return; |
| 6819 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6820 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 6821 | } finally { |
| 6822 | Binder.restoreCallingIdentity(identity); |
| 6823 | } |
| 6824 | } |
| 6825 | |
| 6826 | /** |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6827 | * Get whether reboot is required or not after making changes to modem configurations. |
Nazanin Bakhshi | 4a68f5f | 2019-02-08 14:31:19 -0800 | [diff] [blame] | 6828 | * Return value defaults to true |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6829 | */ |
| 6830 | @Override |
| 6831 | public boolean isRebootRequiredForModemConfigChange() { |
| 6832 | enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange"); |
| 6833 | final long identity = Binder.clearCallingIdentity(); |
| 6834 | try { |
| 6835 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 6836 | } finally { |
| 6837 | Binder.restoreCallingIdentity(identity); |
| 6838 | } |
| 6839 | } |
| 6840 | |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 6841 | private void updateModemStateMetrics() { |
| 6842 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 6843 | // TODO: check the state for each modem if the api is ready. |
| 6844 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 6845 | } |
| 6846 | |
Pengquan Meng | 3aceaec | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 6847 | @Override |
| 6848 | public int[] getSlotsMapping() { |
| 6849 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 6850 | |
| 6851 | final long identity = Binder.clearCallingIdentity(); |
| 6852 | try { |
| 6853 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 6854 | // All logical slots should have a mapping to a physical slot. |
| 6855 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 6856 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 6857 | for (int i = 0; i < slotInfos.length; i++) { |
| 6858 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 6859 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 6860 | } |
| 6861 | } |
| 6862 | return logicalSlotsMapping; |
| 6863 | } finally { |
| 6864 | Binder.restoreCallingIdentity(identity); |
| 6865 | } |
| 6866 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 6867 | |
| 6868 | /** |
| 6869 | * Get the IRadio HAL Version |
| 6870 | */ |
| 6871 | @Override |
| 6872 | public int getRadioHalVersion() { |
| 6873 | Phone phone = getDefaultPhone(); |
| 6874 | if (phone == null) return -1; |
| 6875 | HalVersion hv = phone.getHalVersion(); |
| 6876 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 6877 | return hv.major * 100 + hv.minor; |
| 6878 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6879 | } |