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; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 78 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 79 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 80 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 81 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 82 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 83 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 84 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 85 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 86 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 87 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 88 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 89 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 90 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 91 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 92 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 93 | import android.telephony.data.ApnSetting; |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 94 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 95 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 96 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 97 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 98 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 99 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 100 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 101 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 102 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 103 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 104 | import android.telephony.ims.feature.MmTelFeature; |
| 105 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 106 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 107 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 108 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 109 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 110 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 111 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 112 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 113 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 114 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 115 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 119 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 126 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 128 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.Phone; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.ServiceStateTracker; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.SmsApplication; |
| 141 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.ims.ImsResolver; |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.uicc.IccIoResult; |
| 150 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 156 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 158 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 159 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 160 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 161 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 162 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 163 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 164 | import java.io.FileDescriptor; |
| 165 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 166 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 167 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 168 | import java.util.Arrays; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 169 | import java.util.Collection; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 170 | import java.util.HashMap; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 171 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 172 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 173 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 174 | import java.util.Map; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 175 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 176 | |
| 177 | /** |
| 178 | * Implementation of the ITelephony interface. |
| 179 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 180 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 181 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 182 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 183 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 184 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | |
| 186 | // Message codes used with mMainThreadHandler |
| 187 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 188 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 189 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 190 | private static final int CMD_OPEN_CHANNEL = 9; |
| 191 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 192 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 193 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 194 | private static final int CMD_NV_READ_ITEM = 13; |
| 195 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 196 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 197 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 198 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 199 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 200 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 201 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 202 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 203 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 204 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 205 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 206 | private static final int CMD_SEND_ENVELOPE = 25; |
| 207 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 208 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 209 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 210 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 211 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 212 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 213 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 214 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 215 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 216 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 217 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 218 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 219 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 220 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 221 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 222 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 223 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 224 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 225 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 226 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 227 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 228 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 229 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 230 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 231 | private static final int CMD_SWITCH_SLOTS = 50; |
| 232 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 233 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 234 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 235 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 236 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 237 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 238 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 239 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 240 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 241 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 242 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 243 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 244 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 245 | private static final int CMD_MODEM_REBOOT = 64; |
| 246 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 247 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 248 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 249 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 250 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 251 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 252 | // Parameters of select command. |
| 253 | private static final int SELECT_COMMAND = 0xA4; |
| 254 | private static final int SELECT_P1 = 0x04; |
| 255 | private static final int SELECT_P2 = 0; |
| 256 | private static final int SELECT_P3 = 0x10; |
| 257 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 258 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 259 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 260 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 261 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 262 | /** The singleton instance. */ |
| 263 | private static PhoneInterfaceManager sInstance; |
| 264 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 265 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 266 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 267 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 268 | private AppOpsManager mAppOps; |
| 269 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 270 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 271 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 272 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 273 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 274 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 275 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 276 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 277 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 278 | |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 279 | // String to store multi SIM allowed |
| 280 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 281 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 282 | // The AID of ISD-R. |
| 283 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 284 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 285 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 286 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 287 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 288 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 289 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 290 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 291 | * A request object to use for transmitting data to an ICC. |
| 292 | */ |
| 293 | private static final class IccAPDUArgument { |
| 294 | public int channel, cla, command, p1, p2, p3; |
| 295 | public String data; |
| 296 | |
| 297 | public IccAPDUArgument(int channel, int cla, int command, |
| 298 | int p1, int p2, int p3, String data) { |
| 299 | this.channel = channel; |
| 300 | this.cla = cla; |
| 301 | this.command = command; |
| 302 | this.p1 = p1; |
| 303 | this.p2 = p2; |
| 304 | this.p3 = p3; |
| 305 | this.data = data; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 310 | * A request object to use for transmitting data to an ICC. |
| 311 | */ |
| 312 | private static final class ManualNetworkSelectionArgument { |
| 313 | public OperatorInfo operatorInfo; |
| 314 | public boolean persistSelection; |
| 315 | |
| 316 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 317 | this.operatorInfo = operatorInfo; |
| 318 | this.persistSelection = persistSelection; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 323 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 324 | * request after sending. The main thread will notify the request when it is complete. |
| 325 | */ |
| 326 | private static final class MainThreadRequest { |
| 327 | /** The argument to use for the request */ |
| 328 | public Object argument; |
| 329 | /** The result of the request that is run on the main thread */ |
| 330 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 331 | // The subscriber id that this request applies to. Defaults to |
| 332 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 333 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 334 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 335 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 336 | public Phone phone; |
| 337 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 338 | public WorkSource workSource; |
| 339 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 340 | public MainThreadRequest(Object argument) { |
| 341 | this.argument = argument; |
| 342 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 343 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 344 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 345 | this.argument = argument; |
| 346 | if (phone != null) { |
| 347 | this.phone = phone; |
| 348 | } |
| 349 | this.workSource = workSource; |
| 350 | } |
| 351 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 352 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 353 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 354 | if (subId != null) { |
| 355 | this.subId = subId; |
| 356 | } |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 357 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 358 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 361 | private static final class IncomingThirdPartyCallArgs { |
| 362 | public final ComponentName component; |
| 363 | public final String callId; |
| 364 | public final String callerDisplayName; |
| 365 | |
| 366 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 367 | String callerDisplayName) { |
| 368 | this.component = component; |
| 369 | this.callId = callId; |
| 370 | this.callerDisplayName = callerDisplayName; |
| 371 | } |
| 372 | } |
| 373 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 374 | /** |
| 375 | * A handler that processes messages on the main thread in the phone process. Since many |
| 376 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 377 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 378 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 379 | * on, which will be notified when the operation completes and will contain the result of the |
| 380 | * request. |
| 381 | * |
| 382 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 383 | * note that request.result must be set to something non-null for the calling thread to |
| 384 | * unblock. |
| 385 | */ |
| 386 | private final class MainThreadHandler extends Handler { |
| 387 | @Override |
| 388 | public void handleMessage(Message msg) { |
| 389 | MainThreadRequest request; |
| 390 | Message onCompleted; |
| 391 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 392 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 393 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 394 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 395 | |
| 396 | switch (msg.what) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 397 | case CMD_HANDLE_USSD_REQUEST: { |
| 398 | request = (MainThreadRequest) msg.obj; |
| 399 | final Phone phone = getPhoneFromRequest(request); |
| 400 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 401 | String ussdRequest = ussdObject.first; |
| 402 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 403 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 404 | if (!isUssdApiAllowed(request.subId)) { |
| 405 | // Carrier does not support use of this API, return failure. |
| 406 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 407 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 408 | Bundle returnData = new Bundle(); |
| 409 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 410 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 411 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 412 | request.result = true; |
| 413 | notifyRequester(request); |
| 414 | return; |
| 415 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 416 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 417 | try { |
| 418 | request.result = phone != null |
| 419 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 420 | } catch (CallStateException cse) { |
| 421 | request.result = false; |
| 422 | } |
| 423 | // Wake up the requesting thread |
| 424 | notifyRequester(request); |
| 425 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 428 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 429 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 430 | final Phone phone = getPhoneFromRequest(request); |
| 431 | request.result = phone != null ? |
| 432 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 433 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 434 | // Wake up the requesting thread |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 435 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 436 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 437 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 438 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 439 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 440 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 441 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 442 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 443 | if (uiccCard == null) { |
| 444 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 445 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 446 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 447 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 448 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 449 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 450 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 451 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 452 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 453 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 454 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 455 | break; |
| 456 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 457 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 458 | ar = (AsyncResult) msg.obj; |
| 459 | request = (MainThreadRequest) ar.userObj; |
| 460 | if (ar.exception == null && ar.result != null) { |
| 461 | request.result = ar.result; |
| 462 | } else { |
| 463 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 464 | if (ar.result == null) { |
| 465 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 466 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 467 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 468 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 469 | } else { |
| 470 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 471 | } |
| 472 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 473 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 474 | break; |
| 475 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 476 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 477 | request = (MainThreadRequest) msg.obj; |
| 478 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 479 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 480 | if (uiccCard == null) { |
| 481 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 482 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 483 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 484 | } else { |
| 485 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 486 | request); |
| 487 | uiccCard.iccTransmitApduBasicChannel( |
| 488 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 489 | iccArgument.p3, iccArgument.data, onCompleted); |
| 490 | } |
| 491 | break; |
| 492 | |
| 493 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 494 | ar = (AsyncResult) msg.obj; |
| 495 | request = (MainThreadRequest) ar.userObj; |
| 496 | if (ar.exception == null && ar.result != null) { |
| 497 | request.result = ar.result; |
| 498 | } else { |
| 499 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 500 | if (ar.result == null) { |
| 501 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 502 | } else if (ar.exception instanceof CommandException) { |
| 503 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 504 | ar.exception); |
| 505 | } else { |
| 506 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 507 | } |
| 508 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 509 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 510 | break; |
| 511 | |
| 512 | case CMD_EXCHANGE_SIM_IO: |
| 513 | request = (MainThreadRequest) msg.obj; |
| 514 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 515 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 516 | if (uiccCard == null) { |
| 517 | loge("iccExchangeSimIO: No UICC"); |
| 518 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 519 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 520 | } else { |
| 521 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 522 | request); |
| 523 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 524 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 525 | iccArgument.data, onCompleted); |
| 526 | } |
| 527 | break; |
| 528 | |
| 529 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 530 | ar = (AsyncResult) msg.obj; |
| 531 | request = (MainThreadRequest) ar.userObj; |
| 532 | if (ar.exception == null && ar.result != null) { |
| 533 | request.result = ar.result; |
| 534 | } else { |
| 535 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 536 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 537 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 538 | break; |
| 539 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 540 | case CMD_SEND_ENVELOPE: |
| 541 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 542 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 543 | if (uiccCard == null) { |
| 544 | loge("sendEnvelopeWithStatus: No UICC"); |
| 545 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 546 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 547 | } else { |
| 548 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 549 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 550 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 551 | break; |
| 552 | |
| 553 | case EVENT_SEND_ENVELOPE_DONE: |
| 554 | ar = (AsyncResult) msg.obj; |
| 555 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 556 | if (ar.exception == null && ar.result != null) { |
| 557 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 558 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 559 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 560 | if (ar.result == null) { |
| 561 | loge("sendEnvelopeWithStatus: Empty response"); |
| 562 | } else if (ar.exception instanceof CommandException) { |
| 563 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 564 | ar.exception); |
| 565 | } else { |
| 566 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 567 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 568 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 569 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 570 | break; |
| 571 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 572 | case CMD_OPEN_CHANNEL: |
| 573 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 574 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 575 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 576 | if (uiccCard == null) { |
| 577 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 578 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 579 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 580 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 581 | } else { |
| 582 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 583 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 584 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 585 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 586 | break; |
| 587 | |
| 588 | case EVENT_OPEN_CHANNEL_DONE: |
| 589 | ar = (AsyncResult) msg.obj; |
| 590 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 591 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 592 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 593 | int[] result = (int[]) ar.result; |
| 594 | int channelId = result[0]; |
| 595 | byte[] selectResponse = null; |
| 596 | if (result.length > 1) { |
| 597 | selectResponse = new byte[result.length - 1]; |
| 598 | for (int i = 1; i < result.length; ++i) { |
| 599 | selectResponse[i - 1] = (byte) result[i]; |
| 600 | } |
| 601 | } |
| 602 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 603 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 604 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 605 | if (ar.result == null) { |
| 606 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 607 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 608 | if (ar.exception != null) { |
| 609 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 610 | } |
| 611 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 612 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 613 | if (ar.exception instanceof CommandException) { |
| 614 | CommandException.Error error = |
| 615 | ((CommandException) (ar.exception)).getCommandError(); |
| 616 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 617 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 618 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 619 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 623 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 624 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 625 | request.result = openChannelResp; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 626 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 627 | break; |
| 628 | |
| 629 | case CMD_CLOSE_CHANNEL: |
| 630 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 631 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 632 | if (uiccCard == null) { |
| 633 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 634 | request.result = false; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 635 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 636 | } else { |
| 637 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 638 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 639 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 640 | break; |
| 641 | |
| 642 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 643 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 644 | break; |
| 645 | |
| 646 | case CMD_NV_READ_ITEM: |
| 647 | request = (MainThreadRequest) msg.obj; |
| 648 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 649 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 650 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 651 | break; |
| 652 | |
| 653 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 654 | ar = (AsyncResult) msg.obj; |
| 655 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 656 | if (ar.exception == null && ar.result != null) { |
| 657 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 658 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 659 | request.result = ""; |
| 660 | if (ar.result == null) { |
| 661 | loge("nvReadItem: Empty response"); |
| 662 | } else if (ar.exception instanceof CommandException) { |
| 663 | loge("nvReadItem: CommandException: " + |
| 664 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 665 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 666 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 667 | } |
| 668 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 669 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 670 | break; |
| 671 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 672 | case CMD_NV_WRITE_ITEM: |
| 673 | request = (MainThreadRequest) msg.obj; |
| 674 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 675 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 676 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 677 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 678 | break; |
| 679 | |
| 680 | case EVENT_NV_WRITE_ITEM_DONE: |
| 681 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 682 | break; |
| 683 | |
| 684 | case CMD_NV_WRITE_CDMA_PRL: |
| 685 | request = (MainThreadRequest) msg.obj; |
| 686 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 687 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 688 | break; |
| 689 | |
| 690 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 691 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 692 | break; |
| 693 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 694 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 695 | request = (MainThreadRequest) msg.obj; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 696 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 697 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | break; |
| 699 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 700 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 701 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 702 | break; |
| 703 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 704 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 705 | request = (MainThreadRequest) msg.obj; |
| 706 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 707 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 708 | break; |
| 709 | |
| 710 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 711 | ar = (AsyncResult) msg.obj; |
| 712 | request = (MainThreadRequest) ar.userObj; |
| 713 | if (ar.exception == null && ar.result != null) { |
| 714 | request.result = ar.result; // Integer |
| 715 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 716 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 717 | if (ar.result == null) { |
| 718 | loge("getPreferredNetworkType: Empty response"); |
| 719 | } else if (ar.exception instanceof CommandException) { |
| 720 | loge("getPreferredNetworkType: CommandException: " + |
| 721 | ar.exception); |
| 722 | } else { |
| 723 | loge("getPreferredNetworkType: Unknown exception"); |
| 724 | } |
| 725 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 726 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 730 | request = (MainThreadRequest) msg.obj; |
| 731 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 732 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 733 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 737 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 738 | break; |
| 739 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 740 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 741 | request = (MainThreadRequest)msg.obj; |
| 742 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 743 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 747 | ar = (AsyncResult)msg.obj; |
| 748 | request = (MainThreadRequest)ar.userObj; |
| 749 | request.result = ar; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 750 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 751 | break; |
| 752 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 753 | case CMD_SET_VOICEMAIL_NUMBER: |
| 754 | request = (MainThreadRequest) msg.obj; |
| 755 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 756 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 757 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 758 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 759 | break; |
| 760 | |
| 761 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 762 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 763 | break; |
| 764 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 765 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 766 | request = (MainThreadRequest) msg.obj; |
| 767 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 768 | request); |
| 769 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 770 | break; |
| 771 | |
| 772 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 773 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 774 | break; |
| 775 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 776 | case CMD_PERFORM_NETWORK_SCAN: |
| 777 | request = (MainThreadRequest) msg.obj; |
| 778 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 779 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 780 | break; |
| 781 | |
| 782 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 783 | ar = (AsyncResult) msg.obj; |
| 784 | request = (MainThreadRequest) ar.userObj; |
| 785 | CellNetworkScanResult cellScanResult; |
| 786 | if (ar.exception == null && ar.result != null) { |
| 787 | cellScanResult = new CellNetworkScanResult( |
| 788 | CellNetworkScanResult.STATUS_SUCCESS, |
| 789 | (List<OperatorInfo>) ar.result); |
| 790 | } else { |
| 791 | if (ar.result == null) { |
| 792 | loge("getCellNetworkScanResults: Empty response"); |
| 793 | } |
| 794 | if (ar.exception != null) { |
| 795 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 796 | } |
| 797 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 798 | if (ar.exception instanceof CommandException) { |
| 799 | CommandException.Error error = |
| 800 | ((CommandException) (ar.exception)).getCommandError(); |
| 801 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 802 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 803 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 804 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 805 | } |
| 806 | } |
| 807 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 808 | } |
| 809 | request.result = cellScanResult; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 810 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 811 | break; |
| 812 | |
| 813 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 814 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 815 | ManualNetworkSelectionArgument selArg = |
| 816 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 817 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 818 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 819 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 820 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 821 | break; |
| 822 | |
| 823 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 824 | ar = (AsyncResult) msg.obj; |
| 825 | request = (MainThreadRequest) ar.userObj; |
| 826 | if (ar.exception == null) { |
| 827 | request.result = true; |
| 828 | } else { |
| 829 | request.result = false; |
| 830 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 831 | } |
| 832 | notifyRequester(request); |
| 833 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 834 | break; |
| 835 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 836 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 837 | request = (MainThreadRequest) msg.obj; |
| 838 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | c56281c | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 839 | if (defaultPhone != null) { |
| 840 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 841 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 842 | break; |
| 843 | |
| 844 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 845 | ar = (AsyncResult) msg.obj; |
| 846 | request = (MainThreadRequest) ar.userObj; |
| 847 | if (ar.exception == null && ar.result != null) { |
| 848 | request.result = ar.result; |
| 849 | } else { |
| 850 | if (ar.result == null) { |
| 851 | loge("queryModemActivityInfo: Empty response"); |
| 852 | } else if (ar.exception instanceof CommandException) { |
| 853 | loge("queryModemActivityInfo: CommandException: " + |
| 854 | ar.exception); |
| 855 | } else { |
| 856 | loge("queryModemActivityInfo: Unknown exception"); |
| 857 | } |
| 858 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 859 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 860 | if (request.result == null) { |
| 861 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 862 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 863 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 864 | break; |
| 865 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 866 | case CMD_SET_ALLOWED_CARRIERS: |
| 867 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 868 | CarrierRestrictionRules argument = |
| 869 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 870 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 871 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 872 | break; |
| 873 | |
| 874 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 875 | ar = (AsyncResult) msg.obj; |
| 876 | request = (MainThreadRequest) ar.userObj; |
| 877 | if (ar.exception == null && ar.result != null) { |
| 878 | request.result = ar.result; |
| 879 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 880 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 881 | if (ar.exception instanceof CommandException) { |
| 882 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 883 | CommandException.Error error = |
| 884 | ((CommandException) (ar.exception)).getCommandError(); |
| 885 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 886 | request.result = |
| 887 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 888 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 889 | } else { |
| 890 | loge("setAllowedCarriers: Unknown exception"); |
| 891 | } |
| 892 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 893 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 894 | break; |
| 895 | |
| 896 | case CMD_GET_ALLOWED_CARRIERS: |
| 897 | request = (MainThreadRequest) msg.obj; |
| 898 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 899 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 900 | break; |
| 901 | |
| 902 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 903 | ar = (AsyncResult) msg.obj; |
| 904 | request = (MainThreadRequest) ar.userObj; |
| 905 | if (ar.exception == null && ar.result != null) { |
| 906 | request.result = ar.result; |
| 907 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 908 | request.result = new IllegalStateException( |
| 909 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 910 | if (ar.result == null) { |
| 911 | loge("getAllowedCarriers: Empty response"); |
| 912 | } else if (ar.exception instanceof CommandException) { |
| 913 | loge("getAllowedCarriers: CommandException: " + |
| 914 | ar.exception); |
| 915 | } else { |
| 916 | loge("getAllowedCarriers: Unknown exception"); |
| 917 | } |
| 918 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 919 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 920 | break; |
| 921 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 922 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 923 | ar = (AsyncResult) msg.obj; |
| 924 | request = (MainThreadRequest) ar.userObj; |
| 925 | if (ar.exception == null && ar.result != null) { |
| 926 | request.result = ar.result; |
| 927 | } else { |
| 928 | request.result = new IllegalArgumentException( |
| 929 | "Failed to retrieve Forbidden Plmns"); |
| 930 | if (ar.result == null) { |
| 931 | loge("getForbiddenPlmns: Empty response"); |
| 932 | } else { |
| 933 | loge("getForbiddenPlmns: Unknown exception"); |
| 934 | } |
| 935 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 936 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 937 | break; |
| 938 | |
| 939 | case CMD_GET_FORBIDDEN_PLMNS: |
| 940 | request = (MainThreadRequest) msg.obj; |
| 941 | uiccCard = getUiccCardFromRequest(request); |
| 942 | if (uiccCard == null) { |
| 943 | loge("getForbiddenPlmns() UiccCard is null"); |
| 944 | request.result = new IllegalArgumentException( |
| 945 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 946 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 947 | break; |
| 948 | } |
| 949 | Integer appType = (Integer) request.argument; |
| 950 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 951 | if (uiccApp == null) { |
| 952 | loge("getForbiddenPlmns() no app with specified type -- " |
| 953 | + appType); |
| 954 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 955 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 956 | break; |
| 957 | } else { |
| 958 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 959 | + " specified type -- " + appType); |
| 960 | } |
| 961 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 962 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 963 | onCompleted); |
| 964 | break; |
| 965 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 966 | case CMD_SWITCH_SLOTS: |
| 967 | request = (MainThreadRequest) msg.obj; |
| 968 | int[] physicalSlots = (int[]) request.argument; |
| 969 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 970 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 971 | break; |
| 972 | |
| 973 | case EVENT_SWITCH_SLOTS_DONE: |
| 974 | ar = (AsyncResult) msg.obj; |
| 975 | request = (MainThreadRequest) ar.userObj; |
| 976 | request.result = (ar.exception == null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 977 | notifyRequester(request); |
| 978 | break; |
| 979 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 980 | request = (MainThreadRequest) msg.obj; |
| 981 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 982 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 983 | break; |
| 984 | |
| 985 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 986 | ar = (AsyncResult) msg.obj; |
| 987 | request = (MainThreadRequest) ar.userObj; |
| 988 | if (ar.exception != null) { |
| 989 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 990 | } else { |
| 991 | int mode = ((int[]) ar.result)[0]; |
| 992 | if (mode == 0) { |
| 993 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 994 | } else { |
| 995 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 996 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 997 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 998 | notifyRequester(request); |
| 999 | break; |
| 1000 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1001 | request = (MainThreadRequest) msg.obj; |
| 1002 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1003 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1004 | break; |
| 1005 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1006 | ar = (AsyncResult) msg.obj; |
| 1007 | request = (MainThreadRequest) ar.userObj; |
| 1008 | if (ar.exception != null) { |
| 1009 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1010 | } else { |
| 1011 | request.result = ((int[]) ar.result)[0]; |
| 1012 | } |
| 1013 | notifyRequester(request); |
| 1014 | break; |
| 1015 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1016 | request = (MainThreadRequest) msg.obj; |
| 1017 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1018 | int mode = (int) request.argument; |
| 1019 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1020 | break; |
| 1021 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1022 | ar = (AsyncResult) msg.obj; |
| 1023 | request = (MainThreadRequest) ar.userObj; |
| 1024 | request.result = ar.exception == null; |
| 1025 | notifyRequester(request); |
| 1026 | break; |
| 1027 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1028 | request = (MainThreadRequest) msg.obj; |
| 1029 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1030 | int subscriptionMode = (int) request.argument; |
| 1031 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1032 | break; |
| 1033 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1034 | ar = (AsyncResult) msg.obj; |
| 1035 | request = (MainThreadRequest) ar.userObj; |
| 1036 | request.result = ar.exception == null; |
| 1037 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1038 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1039 | case CMD_GET_ALL_CELL_INFO: |
| 1040 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1041 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1042 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1043 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1044 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1045 | ar = (AsyncResult) msg.obj; |
| 1046 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1047 | // If a timeout occurs, the response will be null |
| 1048 | request.result = (ar.exception == null && ar.result != null) |
| 1049 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1050 | synchronized (request) { |
| 1051 | request.notifyAll(); |
| 1052 | } |
| 1053 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1054 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1055 | request = (MainThreadRequest) msg.obj; |
| 1056 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1057 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1058 | break; |
| 1059 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1060 | ar = (AsyncResult) msg.obj; |
| 1061 | request = (MainThreadRequest) ar.userObj; |
| 1062 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1063 | try { |
| 1064 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1065 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1066 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1067 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1068 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1069 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1070 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1071 | } else { |
| 1072 | // use the result as returned |
| 1073 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1074 | } |
| 1075 | } catch (RemoteException re) { |
| 1076 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1077 | } |
| 1078 | break; |
| 1079 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1080 | request = (MainThreadRequest) msg.obj; |
| 1081 | WorkSource ws = (WorkSource) request.argument; |
| 1082 | Phone phone = getPhoneFromRequest(request); |
| 1083 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1084 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1085 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1086 | ar = (AsyncResult) msg.obj; |
| 1087 | request = (MainThreadRequest) ar.userObj; |
| 1088 | if (ar.exception == null) { |
| 1089 | request.result = ar.result; |
| 1090 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1091 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1092 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1093 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1094 | } |
| 1095 | |
| 1096 | synchronized (request) { |
| 1097 | request.notifyAll(); |
| 1098 | } |
| 1099 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1100 | case CMD_MODEM_REBOOT: |
| 1101 | request = (MainThreadRequest) msg.obj; |
| 1102 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1103 | defaultPhone.rebootModem(onCompleted); |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1104 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1105 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1106 | handleNullReturnEvent(msg, "rebootModem"); |
| 1107 | break; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1108 | case CMD_REQUEST_ENABLE_MODEM: |
| 1109 | request = (MainThreadRequest) msg.obj; |
| 1110 | boolean enable = (boolean) request.argument; |
| 1111 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1112 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1113 | PhoneConfigurationManager.getInstance() |
| 1114 | .enablePhone(request.phone, enable, onCompleted); |
| 1115 | break; |
| 1116 | case EVENT_ENABLE_MODEM_DONE: |
| 1117 | ar = (AsyncResult) msg.obj; |
| 1118 | request = (MainThreadRequest) ar.userObj; |
| 1119 | request.result = (ar.exception == null); |
Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1120 | //update the cache as modem status has changed |
| 1121 | mPhoneConfigurationManager.addToPhoneStatusCache( |
| 1122 | request.phone.getPhoneId(), msg.arg1 == 1); |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 1123 | updateModemStateMetrics(); |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1124 | notifyRequester(request); |
| 1125 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1126 | default: |
| 1127 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1128 | break; |
| 1129 | } |
| 1130 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1131 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1132 | private void notifyRequester(MainThreadRequest request) { |
| 1133 | synchronized (request) { |
| 1134 | request.notifyAll(); |
| 1135 | } |
| 1136 | } |
| 1137 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1138 | private void handleNullReturnEvent(Message msg, String command) { |
| 1139 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1140 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1141 | if (ar.exception == null) { |
| 1142 | request.result = true; |
| 1143 | } else { |
| 1144 | request.result = false; |
| 1145 | if (ar.exception instanceof CommandException) { |
| 1146 | loge(command + ": CommandException: " + ar.exception); |
| 1147 | } else { |
| 1148 | loge(command + ": Unknown exception"); |
| 1149 | } |
| 1150 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1151 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1152 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | /** |
| 1156 | * Posts the specified command to be executed on the main thread, |
| 1157 | * waits for the request to complete, and returns the result. |
| 1158 | * @see #sendRequestAsync |
| 1159 | */ |
| 1160 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1161 | return sendRequest( |
| 1162 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | /** |
| 1166 | * Posts the specified command to be executed on the main thread, |
| 1167 | * waits for the request to complete, and returns the result. |
| 1168 | * @see #sendRequestAsync |
| 1169 | */ |
| 1170 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1171 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1172 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * Posts the specified command to be executed on the main thread, |
| 1177 | * waits for the request to complete, and returns the result. |
| 1178 | * @see #sendRequestAsync |
| 1179 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1180 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1181 | return sendRequest(command, argument, subId, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | /** |
| 1185 | * Posts the specified command to be executed on the main thread, |
| 1186 | * waits for the request to complete, and returns the result. |
| 1187 | * @see #sendRequestAsync |
| 1188 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1189 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1190 | return sendRequest(command, argument, subId, null, workSource); |
| 1191 | } |
| 1192 | |
| 1193 | /** |
| 1194 | * Posts the specified command to be executed on the main thread, |
| 1195 | * waits for the request to complete, and returns the result. |
| 1196 | * @see #sendRequestAsync |
| 1197 | */ |
| 1198 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1199 | return sendRequest( |
| 1200 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1201 | } |
| 1202 | |
| 1203 | /** |
| 1204 | * Posts the specified command to be executed on the main thread, |
| 1205 | * waits for the request to complete, and returns the result. |
| 1206 | * @see #sendRequestAsync |
| 1207 | */ |
| 1208 | private Object sendRequest( |
| 1209 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1210 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1211 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1212 | } |
| 1213 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1214 | MainThreadRequest request = null; |
| 1215 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1216 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1217 | } else if (phone != null) { |
| 1218 | request = new MainThreadRequest(argument, phone, workSource); |
| 1219 | } else { |
| 1220 | request = new MainThreadRequest(argument, subId, workSource); |
| 1221 | } |
| 1222 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1223 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1224 | msg.sendToTarget(); |
| 1225 | |
| 1226 | // Wait for the request to complete |
| 1227 | synchronized (request) { |
| 1228 | while (request.result == null) { |
| 1229 | try { |
| 1230 | request.wait(); |
| 1231 | } catch (InterruptedException e) { |
| 1232 | // Do nothing, go back and wait until the request is complete |
| 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | return request.result; |
| 1237 | } |
| 1238 | |
| 1239 | /** |
| 1240 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1241 | * Posts the specified command to be executed on the main thread, and |
| 1242 | * returns immediately. |
| 1243 | * @see #sendRequest |
| 1244 | */ |
| 1245 | private void sendRequestAsync(int command) { |
| 1246 | mMainThreadHandler.sendEmptyMessage(command); |
| 1247 | } |
| 1248 | |
| 1249 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1250 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1251 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1252 | */ |
| 1253 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1254 | sendRequestAsync(command, argument, null, null); |
| 1255 | } |
| 1256 | |
| 1257 | /** |
| 1258 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1259 | * @see {@link #sendRequest(int,Object)} |
| 1260 | */ |
| 1261 | private void sendRequestAsync( |
| 1262 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1263 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1264 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1265 | msg.sendToTarget(); |
| 1266 | } |
| 1267 | |
| 1268 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1269 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1270 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1271 | */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1272 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1273 | synchronized (PhoneInterfaceManager.class) { |
| 1274 | if (sInstance == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1275 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1276 | } else { |
| 1277 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1278 | } |
| 1279 | return sInstance; |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1284 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1285 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1286 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1287 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1288 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1289 | mMainThreadHandler = new MainThreadHandler(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1290 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1291 | mTelephonySharedPreferences = |
| 1292 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1293 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1294 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1295 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1296 | publish(); |
| 1297 | } |
| 1298 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1299 | private Phone getDefaultPhone() { |
| 1300 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1301 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1302 | } |
| 1303 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1304 | private void publish() { |
| 1305 | if (DBG) log("publish: " + this); |
| 1306 | |
| 1307 | ServiceManager.addService("phone", this); |
| 1308 | } |
| 1309 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1310 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1311 | if (request.phone != null) { |
| 1312 | return request.phone; |
| 1313 | } else { |
| 1314 | return getPhoneFromSubId(request.subId); |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | private Phone getPhoneFromSubId(int subId) { |
| 1319 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1320 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1321 | } |
| 1322 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1323 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1324 | Phone phone = getPhoneFromRequest(request); |
| 1325 | return phone == null ? null : |
| 1326 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1327 | } |
| 1328 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1329 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1330 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1331 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1332 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1333 | |
| 1334 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1335 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1338 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1339 | if (DBG) log("dial: " + number); |
| 1340 | // No permission check needed here: This is just a wrapper around the |
| 1341 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1342 | // the UI before it does anything. |
| 1343 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1344 | final long identity = Binder.clearCallingIdentity(); |
| 1345 | try { |
| 1346 | String url = createTelUrl(number); |
| 1347 | if (url == null) { |
| 1348 | return; |
| 1349 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1350 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1351 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1352 | PhoneConstants.State state = mCM.getState(subId); |
| 1353 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1354 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1355 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1356 | mApp.startActivity(intent); |
| 1357 | } |
| 1358 | } finally { |
| 1359 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1364 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1367 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1368 | if (DBG) log("call: " + number); |
| 1369 | |
| 1370 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1371 | // need to do a permission check since we're calling startActivity() |
| 1372 | // from the context of the phone app. |
| 1373 | enforceCallPermission(); |
| 1374 | |
| 1375 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1376 | != AppOpsManager.MODE_ALLOWED) { |
| 1377 | return; |
| 1378 | } |
| 1379 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1380 | final long identity = Binder.clearCallingIdentity(); |
| 1381 | try { |
| 1382 | String url = createTelUrl(number); |
| 1383 | if (url == null) { |
| 1384 | return; |
| 1385 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1386 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1387 | boolean isValid = false; |
| 1388 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1389 | if (slist != null) { |
| 1390 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1391 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1392 | isValid = true; |
| 1393 | break; |
| 1394 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1395 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1396 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1397 | if (!isValid) { |
| 1398 | return; |
| 1399 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1400 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1401 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1402 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1403 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1404 | mApp.startActivity(intent); |
| 1405 | } finally { |
| 1406 | Binder.restoreCallingIdentity(identity); |
| 1407 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1410 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1411 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1414 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1415 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1416 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1417 | } |
| 1418 | |
| 1419 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1420 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1421 | } |
| 1422 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1423 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1424 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1425 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1426 | } |
| 1427 | |
| 1428 | /** {@hide} */ |
| 1429 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1430 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1431 | } |
| 1432 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1433 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1434 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1435 | |
| 1436 | final long identity = Binder.clearCallingIdentity(); |
| 1437 | try { |
| 1438 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1439 | checkSimPin.start(); |
| 1440 | return checkSimPin.unlockSim(null, pin); |
| 1441 | } finally { |
| 1442 | Binder.restoreCallingIdentity(identity); |
| 1443 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1446 | /** {@hide} */ |
| 1447 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1448 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1451 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1452 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1453 | |
| 1454 | final long identity = Binder.clearCallingIdentity(); |
| 1455 | try { |
| 1456 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1457 | checkSimPuk.start(); |
| 1458 | return checkSimPuk.unlockSim(puk, pin); |
| 1459 | } finally { |
| 1460 | Binder.restoreCallingIdentity(identity); |
| 1461 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1465 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1466 | * a synchronous one. |
| 1467 | */ |
| 1468 | private static class UnlockSim extends Thread { |
| 1469 | |
| 1470 | private final IccCard mSimCard; |
| 1471 | |
| 1472 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1473 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1474 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1475 | |
| 1476 | // For replies from SimCard interface |
| 1477 | private Handler mHandler; |
| 1478 | |
| 1479 | // For async handler to identify request type |
| 1480 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1481 | |
| 1482 | public UnlockSim(IccCard simCard) { |
| 1483 | mSimCard = simCard; |
| 1484 | } |
| 1485 | |
| 1486 | @Override |
| 1487 | public void run() { |
| 1488 | Looper.prepare(); |
| 1489 | synchronized (UnlockSim.this) { |
| 1490 | mHandler = new Handler() { |
| 1491 | @Override |
| 1492 | public void handleMessage(Message msg) { |
| 1493 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1494 | switch (msg.what) { |
| 1495 | case SUPPLY_PIN_COMPLETE: |
| 1496 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1497 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1498 | mRetryCount = msg.arg1; |
| 1499 | if (ar.exception != null) { |
| 1500 | if (ar.exception instanceof CommandException && |
| 1501 | ((CommandException)(ar.exception)).getCommandError() |
| 1502 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1503 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1504 | } else { |
| 1505 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1506 | } |
| 1507 | } else { |
| 1508 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1509 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1510 | mDone = true; |
| 1511 | UnlockSim.this.notifyAll(); |
| 1512 | } |
| 1513 | break; |
| 1514 | } |
| 1515 | } |
| 1516 | }; |
| 1517 | UnlockSim.this.notifyAll(); |
| 1518 | } |
| 1519 | Looper.loop(); |
| 1520 | } |
| 1521 | |
| 1522 | /* |
| 1523 | * Use PIN or PUK to unlock SIM card |
| 1524 | * |
| 1525 | * If PUK is null, unlock SIM card with PIN |
| 1526 | * |
| 1527 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1528 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1529 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1530 | |
| 1531 | while (mHandler == null) { |
| 1532 | try { |
| 1533 | wait(); |
| 1534 | } catch (InterruptedException e) { |
| 1535 | Thread.currentThread().interrupt(); |
| 1536 | } |
| 1537 | } |
| 1538 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1539 | |
| 1540 | if (puk == null) { |
| 1541 | mSimCard.supplyPin(pin, callback); |
| 1542 | } else { |
| 1543 | mSimCard.supplyPuk(puk, pin, callback); |
| 1544 | } |
| 1545 | |
| 1546 | while (!mDone) { |
| 1547 | try { |
| 1548 | Log.d(LOG_TAG, "wait for done"); |
| 1549 | wait(); |
| 1550 | } catch (InterruptedException e) { |
| 1551 | // Restore the interrupted status |
| 1552 | Thread.currentThread().interrupt(); |
| 1553 | } |
| 1554 | } |
| 1555 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1556 | int[] resultArray = new int[2]; |
| 1557 | resultArray[0] = mResult; |
| 1558 | resultArray[1] = mRetryCount; |
| 1559 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1564 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1565 | |
| 1566 | } |
| 1567 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1568 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1569 | // No permission check needed here: this call is harmless, and it's |
| 1570 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1571 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1572 | final long identity = Binder.clearCallingIdentity(); |
| 1573 | try { |
| 1574 | final Phone phone = getPhone(subId); |
| 1575 | if (phone != null) { |
| 1576 | phone.updateServiceLocation(); |
| 1577 | } |
| 1578 | } finally { |
| 1579 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1580 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1583 | @Override |
| 1584 | public boolean isRadioOn(String callingPackage) { |
| 1585 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1588 | @Override |
| 1589 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1590 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1591 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1592 | return false; |
| 1593 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1594 | |
| 1595 | final long identity = Binder.clearCallingIdentity(); |
| 1596 | try { |
| 1597 | return isRadioOnForSubscriber(subId); |
| 1598 | } finally { |
| 1599 | Binder.restoreCallingIdentity(identity); |
| 1600 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1604 | final long identity = Binder.clearCallingIdentity(); |
| 1605 | try { |
| 1606 | final Phone phone = getPhone(subId); |
| 1607 | if (phone != null) { |
| 1608 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1609 | } else { |
| 1610 | return false; |
| 1611 | } |
| 1612 | } finally { |
| 1613 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1614 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1618 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1619 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1620 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1621 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1622 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1623 | |
| 1624 | final long identity = Binder.clearCallingIdentity(); |
| 1625 | try { |
| 1626 | final Phone phone = getPhone(subId); |
| 1627 | if (phone != null) { |
| 1628 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1629 | } |
| 1630 | } finally { |
| 1631 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1632 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1636 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1639 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1640 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1641 | |
| 1642 | final long identity = Binder.clearCallingIdentity(); |
| 1643 | try { |
| 1644 | final Phone phone = getPhone(subId); |
| 1645 | if (phone == null) { |
| 1646 | return false; |
| 1647 | } |
| 1648 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1649 | toggleRadioOnOffForSubscriber(subId); |
| 1650 | } |
| 1651 | return true; |
| 1652 | } finally { |
| 1653 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1654 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1655 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1656 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1657 | public boolean needMobileRadioShutdown() { |
| 1658 | /* |
| 1659 | * If any of the Radios are available, it will need to be |
| 1660 | * shutdown. So return true if any Radio is available. |
| 1661 | */ |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1662 | final long identity = Binder.clearCallingIdentity(); |
| 1663 | try { |
| 1664 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1665 | Phone phone = PhoneFactory.getPhone(i); |
| 1666 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1667 | } |
| 1668 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1669 | return false; |
| 1670 | } finally { |
| 1671 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1672 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1675 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1676 | public void shutdownMobileRadios() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1677 | enforceModifyPermission(); |
| 1678 | |
| 1679 | final long identity = Binder.clearCallingIdentity(); |
| 1680 | try { |
| 1681 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1682 | logv("Shutting down Phone " + i); |
| 1683 | shutdownRadioUsingPhoneId(i); |
| 1684 | } |
| 1685 | } finally { |
| 1686 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1691 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1692 | if (phone != null && phone.isRadioAvailable()) { |
| 1693 | phone.shutdownRadio(); |
| 1694 | } |
| 1695 | } |
| 1696 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1697 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1698 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1699 | |
| 1700 | final long identity = Binder.clearCallingIdentity(); |
| 1701 | try { |
| 1702 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1703 | if (defaultPhone != null) { |
| 1704 | defaultPhone.setRadioPower(turnOn); |
| 1705 | return true; |
| 1706 | } else { |
| 1707 | loge("There's no default phone."); |
| 1708 | return false; |
| 1709 | } |
| 1710 | } finally { |
| 1711 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1712 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1715 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1716 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1717 | |
| 1718 | final long identity = Binder.clearCallingIdentity(); |
| 1719 | try { |
| 1720 | final Phone phone = getPhone(subId); |
| 1721 | if (phone != null) { |
| 1722 | phone.setRadioPower(turnOn); |
| 1723 | return true; |
| 1724 | } else { |
| 1725 | return false; |
| 1726 | } |
| 1727 | } finally { |
| 1728 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1729 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1732 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1733 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1734 | public boolean enableDataConnectivity() { |
| 1735 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1736 | |
| 1737 | final long identity = Binder.clearCallingIdentity(); |
| 1738 | try { |
| 1739 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1740 | final Phone phone = getPhone(subId); |
| 1741 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1742 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1743 | return true; |
| 1744 | } else { |
| 1745 | return false; |
| 1746 | } |
| 1747 | } finally { |
| 1748 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1749 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1752 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1753 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1754 | public boolean disableDataConnectivity() { |
| 1755 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1756 | |
| 1757 | final long identity = Binder.clearCallingIdentity(); |
| 1758 | try { |
| 1759 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1760 | final Phone phone = getPhone(subId); |
| 1761 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1762 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1763 | return true; |
| 1764 | } else { |
| 1765 | return false; |
| 1766 | } |
| 1767 | } finally { |
| 1768 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1769 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1772 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1773 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1774 | final long identity = Binder.clearCallingIdentity(); |
| 1775 | try { |
| 1776 | final Phone phone = getPhone(subId); |
| 1777 | if (phone != null) { |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1778 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1779 | } else { |
| 1780 | return false; |
| 1781 | } |
| 1782 | } finally { |
| 1783 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1784 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1788 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1791 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1792 | enforceCallPermission(); |
| 1793 | |
| 1794 | final long identity = Binder.clearCallingIdentity(); |
| 1795 | try { |
| 1796 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1797 | return; |
| 1798 | } |
| 1799 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1800 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1801 | } finally { |
| 1802 | Binder.restoreCallingIdentity(identity); |
| 1803 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1804 | }; |
| 1805 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1806 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1807 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1808 | |
| 1809 | final long identity = Binder.clearCallingIdentity(); |
| 1810 | try { |
| 1811 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1812 | return false; |
| 1813 | } |
| 1814 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1815 | } finally { |
| 1816 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1817 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1820 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1821 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1824 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1825 | final long identity = Binder.clearCallingIdentity(); |
| 1826 | try { |
| 1827 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1828 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1829 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1830 | } finally { |
| 1831 | Binder.restoreCallingIdentity(identity); |
| 1832 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1835 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1836 | public int getDataState() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1837 | final long identity = Binder.clearCallingIdentity(); |
| 1838 | try { |
| 1839 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1840 | if (phone != null) { |
| 1841 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1842 | } else { |
| 1843 | return PhoneConstantConversions.convertDataState( |
| 1844 | PhoneConstants.DataState.DISCONNECTED); |
| 1845 | } |
| 1846 | } finally { |
| 1847 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1848 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1851 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1852 | public int getDataActivity() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1853 | final long identity = Binder.clearCallingIdentity(); |
| 1854 | try { |
| 1855 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1856 | if (phone != null) { |
| 1857 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1858 | } else { |
| 1859 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1860 | } |
| 1861 | } finally { |
| 1862 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1863 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1864 | } |
| 1865 | |
| 1866 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1867 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1868 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1869 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1870 | |
| 1871 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1872 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1873 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1874 | .setCallingPackage(callingPackage) |
| 1875 | .setCallingPid(Binder.getCallingPid()) |
| 1876 | .setCallingUid(Binder.getCallingUid()) |
| 1877 | .setMethod("getCellLocation") |
| 1878 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1879 | .build()); |
| 1880 | switch (locationResult) { |
| 1881 | case DENIED_HARD: |
| 1882 | throw new SecurityException("Not allowed to access cell location"); |
| 1883 | case DENIED_SOFT: |
| 1884 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1887 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1888 | final long identity = Binder.clearCallingIdentity(); |
| 1889 | try { |
| 1890 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1891 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1892 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1893 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1894 | cl.fillInNotifierBundle(data); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1895 | return data; |
| 1896 | } finally { |
| 1897 | Binder.restoreCallingIdentity(identity); |
| 1898 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1901 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1902 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1903 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1904 | // registered cell info, so return a NULL country instead. |
| 1905 | final long identity = Binder.clearCallingIdentity(); |
| 1906 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1907 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1908 | // Get default phone in this case. |
| 1909 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1910 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1911 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1912 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1913 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1914 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1915 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1916 | return ""; |
| 1917 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1918 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1919 | if (phone != null) { |
| 1920 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1921 | if (sst != null) { |
| 1922 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1923 | if (lt != null) { |
| 1924 | return lt.getCurrentCountry(); |
| 1925 | } |
| 1926 | } |
| 1927 | } |
| 1928 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1929 | } finally { |
| 1930 | Binder.restoreCallingIdentity(identity); |
| 1931 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1935 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1936 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1939 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1940 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1941 | mApp.enforceCallingOrSelfPermission( |
| 1942 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1943 | |
| 1944 | final long identity = Binder.clearCallingIdentity(); |
| 1945 | try { |
| 1946 | final Phone phone = getPhone(subId); |
| 1947 | if (phone != null) { |
| 1948 | phone.enableLocationUpdates(); |
| 1949 | } |
| 1950 | } finally { |
| 1951 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1952 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | @Override |
| 1956 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1957 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1960 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1961 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1962 | mApp.enforceCallingOrSelfPermission( |
| 1963 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1964 | |
| 1965 | final long identity = Binder.clearCallingIdentity(); |
| 1966 | try { |
| 1967 | final Phone phone = getPhone(subId); |
| 1968 | if (phone != null) { |
| 1969 | phone.disableLocationUpdates(); |
| 1970 | } |
| 1971 | } finally { |
| 1972 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1973 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1976 | /** |
| 1977 | * Returns the target SDK version number for a given package name. |
| 1978 | * |
| 1979 | * @return target SDK if the package is found or INT_MAX. |
| 1980 | */ |
| 1981 | private int getTargetSdk(String packageName) { |
| 1982 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1983 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 1984 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1985 | if (ai != null) return ai.targetSdkVersion; |
| 1986 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1987 | } |
| 1988 | return Integer.MAX_VALUE; |
| 1989 | } |
| 1990 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1991 | @Override |
| 1992 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1993 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1994 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1995 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1996 | throw new SecurityException( |
| 1997 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1998 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1999 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2000 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 2001 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2002 | return null; |
| 2003 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2004 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2005 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2006 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2007 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2008 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2009 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2010 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2011 | for (CellInfo ci : info) { |
| 2012 | if (ci instanceof CellInfoGsm) { |
| 2013 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2014 | } else if (ci instanceof CellInfoWcdma) { |
| 2015 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2016 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2017 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2018 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2019 | } |
| 2020 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2021 | private List<CellInfo> getCachedCellInfo() { |
| 2022 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2023 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2024 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2025 | if (info != null) cellInfos.addAll(info); |
| 2026 | } |
| 2027 | return cellInfos; |
| 2028 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2029 | |
| 2030 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2031 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2032 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2033 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2034 | |
| 2035 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2036 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2037 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2038 | .setCallingPackage(callingPackage) |
| 2039 | .setCallingPid(Binder.getCallingPid()) |
| 2040 | .setCallingUid(Binder.getCallingUid()) |
| 2041 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2042 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2043 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2044 | .build()); |
| 2045 | switch (locationResult) { |
| 2046 | case DENIED_HARD: |
| 2047 | throw new SecurityException("Not allowed to access cell info"); |
| 2048 | case DENIED_SOFT: |
| 2049 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2052 | final int targetSdk = getTargetSdk(callingPackage); |
| 2053 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2054 | return getCachedCellInfo(); |
| 2055 | } |
| 2056 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2057 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2058 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2059 | final long identity = Binder.clearCallingIdentity(); |
| 2060 | try { |
| 2061 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2062 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2063 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2064 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2065 | if (info != null) cellInfos.addAll(info); |
| 2066 | } |
| 2067 | return cellInfos; |
| 2068 | } finally { |
| 2069 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2070 | } |
| 2071 | } |
| 2072 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2073 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2074 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2075 | requestCellInfoUpdateInternal( |
| 2076 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2077 | } |
| 2078 | |
| 2079 | @Override |
| 2080 | public void requestCellInfoUpdateWithWorkSource( |
| 2081 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2082 | enforceModifyPermission(); |
| 2083 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2084 | } |
| 2085 | |
| 2086 | private void requestCellInfoUpdateInternal( |
| 2087 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2088 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2089 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2090 | |
| 2091 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2092 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2093 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2094 | .setCallingPackage(callingPackage) |
| 2095 | .setCallingPid(Binder.getCallingPid()) |
| 2096 | .setCallingUid(Binder.getCallingUid()) |
| 2097 | .setMethod("requestCellInfoUpdate") |
| 2098 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2099 | .build()); |
| 2100 | switch (locationResult) { |
| 2101 | case DENIED_HARD: |
| 2102 | throw new SecurityException("Not allowed to access cell info"); |
| 2103 | case DENIED_SOFT: |
| 2104 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | final Phone phone = getPhone(subId); |
| 2108 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2109 | |
| 2110 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2111 | } |
| 2112 | |
| 2113 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2114 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2115 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2116 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2117 | |
| 2118 | final long identity = Binder.clearCallingIdentity(); |
| 2119 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2120 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2121 | } finally { |
| 2122 | Binder.restoreCallingIdentity(identity); |
| 2123 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2126 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2127 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2128 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2129 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2130 | return null; |
| 2131 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2132 | int subId = phone.getSubId(); |
| 2133 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2134 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 2135 | return null; |
| 2136 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2137 | |
| 2138 | final long identity = Binder.clearCallingIdentity(); |
| 2139 | try { |
| 2140 | return phone.getImei(); |
| 2141 | } finally { |
| 2142 | Binder.restoreCallingIdentity(identity); |
| 2143 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2147 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2148 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2149 | String tac = null; |
| 2150 | if (phone != null) { |
| 2151 | String imei = phone.getImei(); |
| 2152 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2153 | } |
| 2154 | return tac; |
| 2155 | } |
| 2156 | |
| 2157 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2158 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2159 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2160 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2161 | return null; |
| 2162 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2163 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2164 | int subId = phone.getSubId(); |
| 2165 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2166 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 2167 | return null; |
| 2168 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2169 | |
| 2170 | final long identity = Binder.clearCallingIdentity(); |
| 2171 | try { |
| 2172 | return phone.getMeid(); |
| 2173 | } finally { |
| 2174 | Binder.restoreCallingIdentity(identity); |
| 2175 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2179 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2180 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2181 | String manufacturerCode = null; |
| 2182 | if (phone != null) { |
| 2183 | String meid = phone.getMeid(); |
| 2184 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2185 | } |
| 2186 | return manufacturerCode; |
| 2187 | } |
| 2188 | |
| 2189 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2190 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2191 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2192 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2193 | return null; |
| 2194 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2195 | int subId = phone.getSubId(); |
| 2196 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2197 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2198 | return null; |
| 2199 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2200 | |
| 2201 | final long identity = Binder.clearCallingIdentity(); |
| 2202 | try { |
| 2203 | return phone.getDeviceSvn(); |
| 2204 | } finally { |
| 2205 | Binder.restoreCallingIdentity(identity); |
| 2206 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2207 | } |
| 2208 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2209 | @Override |
| 2210 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2211 | final long identity = Binder.clearCallingIdentity(); |
| 2212 | try { |
| 2213 | final Phone phone = getPhone(subId); |
| 2214 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2215 | } finally { |
| 2216 | Binder.restoreCallingIdentity(identity); |
| 2217 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | @Override |
| 2221 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2222 | final long identity = Binder.clearCallingIdentity(); |
| 2223 | try { |
| 2224 | final Phone phone = getPhone(subId); |
| 2225 | return phone == null ? null : phone.getCarrierName(); |
| 2226 | } finally { |
| 2227 | Binder.restoreCallingIdentity(identity); |
| 2228 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2229 | } |
| 2230 | |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2231 | @Override |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2232 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2233 | final long identity = Binder.clearCallingIdentity(); |
| 2234 | try { |
| 2235 | final Phone phone = getPhone(subId); |
| 2236 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2237 | : phone.getSpecificCarrierId(); |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2238 | } finally { |
| 2239 | Binder.restoreCallingIdentity(identity); |
| 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | @Override |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2244 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2245 | final long identity = Binder.clearCallingIdentity(); |
| 2246 | try { |
| 2247 | final Phone phone = getPhone(subId); |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2248 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2249 | } finally { |
| 2250 | Binder.restoreCallingIdentity(identity); |
| 2251 | } |
| 2252 | } |
| 2253 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2254 | @Override |
chen xu | 4ca4e69 | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2255 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2256 | if (!isSubscriptionMccMnc) { |
| 2257 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2258 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2259 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2260 | if (phone == null) { |
| 2261 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2262 | } |
| 2263 | final long identity = Binder.clearCallingIdentity(); |
| 2264 | try { |
| 2265 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2266 | } finally { |
| 2267 | Binder.restoreCallingIdentity(identity); |
| 2268 | } |
| 2269 | } |
| 2270 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2271 | // |
| 2272 | // Internal helper methods. |
| 2273 | // |
| 2274 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2275 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2276 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2277 | * |
| 2278 | * @throws SecurityException if the caller does not have the required permission |
| 2279 | */ |
| 2280 | private void enforceModifyPermission() { |
| 2281 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2282 | } |
| 2283 | |
| 2284 | /** |
| 2285 | * Make sure the caller has the CALL_PHONE permission. |
| 2286 | * |
| 2287 | * @throws SecurityException if the caller does not have the required permission |
| 2288 | */ |
| 2289 | private void enforceCallPermission() { |
| 2290 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2291 | } |
| 2292 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2293 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2294 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2295 | "ConnectivityService"); |
| 2296 | } |
| 2297 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2298 | private String createTelUrl(String number) { |
| 2299 | if (TextUtils.isEmpty(number)) { |
| 2300 | return null; |
| 2301 | } |
| 2302 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2303 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2304 | } |
| 2305 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2306 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2307 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2308 | } |
| 2309 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2310 | private static void logv(String msg) { |
| 2311 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2312 | } |
| 2313 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2314 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2315 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2316 | } |
| 2317 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2318 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2319 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2320 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2323 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2324 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2325 | final long identity = Binder.clearCallingIdentity(); |
| 2326 | try { |
| 2327 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2328 | if (phone == null) { |
| 2329 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2330 | } else { |
| 2331 | return phone.getPhoneType(); |
| 2332 | } |
| 2333 | } finally { |
| 2334 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2335 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | /** |
| 2339 | * Returns the CDMA ERI icon index to display |
| 2340 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2341 | @Override |
| 2342 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2343 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2346 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2347 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2348 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2349 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2350 | return -1; |
| 2351 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2352 | |
| 2353 | final long identity = Binder.clearCallingIdentity(); |
| 2354 | try { |
| 2355 | final Phone phone = getPhone(subId); |
| 2356 | if (phone != null) { |
| 2357 | return phone.getCdmaEriIconIndex(); |
| 2358 | } else { |
| 2359 | return -1; |
| 2360 | } |
| 2361 | } finally { |
| 2362 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2363 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | /** |
| 2367 | * Returns the CDMA ERI icon mode, |
| 2368 | * 0 - ON |
| 2369 | * 1 - FLASHING |
| 2370 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2371 | @Override |
| 2372 | public int getCdmaEriIconMode(String callingPackage) { |
| 2373 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2376 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2377 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2378 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2379 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2380 | return -1; |
| 2381 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2382 | |
| 2383 | final long identity = Binder.clearCallingIdentity(); |
| 2384 | try { |
| 2385 | final Phone phone = getPhone(subId); |
| 2386 | if (phone != null) { |
| 2387 | return phone.getCdmaEriIconMode(); |
| 2388 | } else { |
| 2389 | return -1; |
| 2390 | } |
| 2391 | } finally { |
| 2392 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2393 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | /** |
| 2397 | * Returns the CDMA ERI text, |
| 2398 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2399 | @Override |
| 2400 | public String getCdmaEriText(String callingPackage) { |
| 2401 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2402 | } |
| 2403 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2404 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2405 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2406 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2407 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2408 | return null; |
| 2409 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2410 | |
| 2411 | final long identity = Binder.clearCallingIdentity(); |
| 2412 | try { |
| 2413 | final Phone phone = getPhone(subId); |
| 2414 | if (phone != null) { |
| 2415 | return phone.getCdmaEriText(); |
| 2416 | } else { |
| 2417 | return null; |
| 2418 | } |
| 2419 | } finally { |
| 2420 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2421 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2425 | * Returns the CDMA MDN. |
| 2426 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2427 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2428 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2429 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2430 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2431 | |
| 2432 | final long identity = Binder.clearCallingIdentity(); |
| 2433 | try { |
| 2434 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2435 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2436 | return phone.getLine1Number(); |
| 2437 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2438 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2439 | return null; |
| 2440 | } |
| 2441 | } finally { |
| 2442 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2443 | } |
| 2444 | } |
| 2445 | |
| 2446 | /** |
| 2447 | * Returns the CDMA MIN. |
| 2448 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2449 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2450 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2451 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2452 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2453 | |
| 2454 | final long identity = Binder.clearCallingIdentity(); |
| 2455 | try { |
| 2456 | final Phone phone = getPhone(subId); |
| 2457 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2458 | return phone.getCdmaMin(); |
| 2459 | } else { |
| 2460 | return null; |
| 2461 | } |
| 2462 | } finally { |
| 2463 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2464 | } |
| 2465 | } |
| 2466 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2467 | @Override |
| 2468 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2469 | INumberVerificationCallback callback, String callingPackage) { |
| 2470 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2471 | != PERMISSION_GRANTED) { |
| 2472 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2473 | } |
| 2474 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2475 | |
| 2476 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2477 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2478 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2479 | } |
| 2480 | |
| 2481 | if (range == null) { |
| 2482 | throw new NullPointerException("Range must be non-null"); |
| 2483 | } |
| 2484 | |
| 2485 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2486 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2487 | |
| 2488 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2489 | } |
| 2490 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2491 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2492 | * Returns true if CDMA provisioning needs to run. |
| 2493 | */ |
| 2494 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2495 | final long identity = Binder.clearCallingIdentity(); |
| 2496 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2497 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2498 | } finally { |
| 2499 | Binder.restoreCallingIdentity(identity); |
| 2500 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2504 | * Sets the voice mail number of a given subId. |
| 2505 | */ |
| 2506 | @Override |
| 2507 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2508 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2509 | |
| 2510 | final long identity = Binder.clearCallingIdentity(); |
| 2511 | try { |
| 2512 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2513 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2514 | return success; |
| 2515 | } finally { |
| 2516 | Binder.restoreCallingIdentity(identity); |
| 2517 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2518 | } |
| 2519 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2520 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2521 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2522 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2523 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2524 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2525 | throw new SecurityException("caller must be system dialer"); |
| 2526 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2527 | |
| 2528 | final long identity = Binder.clearCallingIdentity(); |
| 2529 | try { |
| 2530 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2531 | if (phoneAccountHandle == null) { |
| 2532 | return null; |
| 2533 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2534 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2535 | } finally { |
| 2536 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2537 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2541 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2542 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2543 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2544 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2545 | return null; |
| 2546 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2547 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2548 | final long identity = Binder.clearCallingIdentity(); |
| 2549 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2550 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2551 | } finally { |
| 2552 | Binder.restoreCallingIdentity(identity); |
| 2553 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2557 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2558 | VisualVoicemailSmsFilterSettings settings) { |
| 2559 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2560 | |
| 2561 | final long identity = Binder.clearCallingIdentity(); |
| 2562 | try { |
| 2563 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2564 | mApp, callingPackage, subId, settings); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2565 | } finally { |
| 2566 | Binder.restoreCallingIdentity(identity); |
| 2567 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2571 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2572 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2573 | |
| 2574 | final long identity = Binder.clearCallingIdentity(); |
| 2575 | try { |
| 2576 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2577 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2578 | } finally { |
| 2579 | Binder.restoreCallingIdentity(identity); |
| 2580 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2584 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2585 | String callingPackage, int subId) { |
| 2586 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2587 | |
| 2588 | final long identity = Binder.clearCallingIdentity(); |
| 2589 | try { |
| 2590 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2591 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2592 | } finally { |
| 2593 | Binder.restoreCallingIdentity(identity); |
| 2594 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2598 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2599 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2600 | |
| 2601 | final long identity = Binder.clearCallingIdentity(); |
| 2602 | try { |
| 2603 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2604 | mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2605 | } finally { |
| 2606 | Binder.restoreCallingIdentity(identity); |
| 2607 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | @Override |
| 2611 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2612 | String number, int port, String text, PendingIntent sentIntent) { |
| 2613 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2614 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2615 | enforceSendSmsPermission(); |
| 2616 | // Make the calls as the phone process. |
| 2617 | final long identity = Binder.clearCallingIdentity(); |
| 2618 | try { |
| 2619 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2620 | if (port == 0) { |
| 2621 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2622 | sentIntent, null, false); |
| 2623 | } else { |
| 2624 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2625 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2626 | (short) port, data, sentIntent, null); |
| 2627 | } |
| 2628 | } finally { |
| 2629 | Binder.restoreCallingIdentity(identity); |
| 2630 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2631 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2632 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2633 | * Sets the voice activation state of a given subId. |
| 2634 | */ |
| 2635 | @Override |
| 2636 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2638 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2639 | |
| 2640 | final long identity = Binder.clearCallingIdentity(); |
| 2641 | try { |
| 2642 | final Phone phone = getPhone(subId); |
| 2643 | if (phone != null) { |
| 2644 | phone.setVoiceActivationState(activationState); |
| 2645 | } else { |
| 2646 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2647 | } |
| 2648 | } finally { |
| 2649 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2650 | } |
| 2651 | } |
| 2652 | |
| 2653 | /** |
| 2654 | * Sets the data activation state of a given subId. |
| 2655 | */ |
| 2656 | @Override |
| 2657 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2658 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2659 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2660 | |
| 2661 | final long identity = Binder.clearCallingIdentity(); |
| 2662 | try { |
| 2663 | final Phone phone = getPhone(subId); |
| 2664 | if (phone != null) { |
| 2665 | phone.setDataActivationState(activationState); |
| 2666 | } else { |
| 2667 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2668 | } |
| 2669 | } finally { |
| 2670 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2671 | } |
| 2672 | } |
| 2673 | |
| 2674 | /** |
| 2675 | * Returns the voice activation state of a given subId. |
| 2676 | */ |
| 2677 | @Override |
| 2678 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2679 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2680 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2681 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2682 | final long identity = Binder.clearCallingIdentity(); |
| 2683 | try { |
| 2684 | if (phone != null) { |
| 2685 | return phone.getVoiceActivationState(); |
| 2686 | } else { |
| 2687 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2688 | } |
| 2689 | } finally { |
| 2690 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2691 | } |
| 2692 | } |
| 2693 | |
| 2694 | /** |
| 2695 | * Returns the data activation state of a given subId. |
| 2696 | */ |
| 2697 | @Override |
| 2698 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2699 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2700 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2701 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2702 | final long identity = Binder.clearCallingIdentity(); |
| 2703 | try { |
| 2704 | if (phone != null) { |
| 2705 | return phone.getDataActivationState(); |
| 2706 | } else { |
| 2707 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2708 | } |
| 2709 | } finally { |
| 2710 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2711 | } |
| 2712 | } |
| 2713 | |
| 2714 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2715 | * Returns the unread count of voicemails for a subId |
| 2716 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2717 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2718 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2719 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2720 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2721 | return 0; |
| 2722 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2723 | final long identity = Binder.clearCallingIdentity(); |
| 2724 | try { |
| 2725 | final Phone phone = getPhone(subId); |
| 2726 | if (phone != null) { |
| 2727 | return phone.getVoiceMessageCount(); |
| 2728 | } else { |
| 2729 | return 0; |
| 2730 | } |
| 2731 | } finally { |
| 2732 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2733 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2737 | * returns true, if the device is in a state where both voice and data |
| 2738 | * are supported simultaneously. This can change based on location or network condition. |
| 2739 | */ |
| 2740 | @Override |
| 2741 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2742 | final long identity = Binder.clearCallingIdentity(); |
| 2743 | try { |
| 2744 | final Phone phone = getPhone(subId); |
| 2745 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2746 | } finally { |
| 2747 | Binder.restoreCallingIdentity(identity); |
| 2748 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2752 | * Send the dialer code if called from the current default dialer or the caller has |
| 2753 | * carrier privilege. |
| 2754 | * @param inputCode The dialer code to send |
| 2755 | */ |
| 2756 | @Override |
| 2757 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2758 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2759 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2760 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2761 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2762 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2763 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2764 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2765 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2766 | |
| 2767 | final long identity = Binder.clearCallingIdentity(); |
| 2768 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2769 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2770 | } finally { |
| 2771 | Binder.restoreCallingIdentity(identity); |
| 2772 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2776 | * Returns the data network type. |
| 2777 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2778 | * |
| 2779 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2780 | */ |
| 2781 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2782 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2783 | final long identity = Binder.clearCallingIdentity(); |
| 2784 | try { |
| 2785 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2786 | if (phone != null) { |
| 2787 | return phone.getServiceState().getDataNetworkType(); |
| 2788 | } else { |
| 2789 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2790 | } |
| 2791 | } finally { |
| 2792 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2793 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2794 | } |
| 2795 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2796 | @Override |
| 2797 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2798 | if (!isActiveSubscription(subId)) { |
| 2799 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2800 | } |
| 2801 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2802 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2803 | } |
| 2804 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2805 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2806 | public boolean isInEmergencySmsMode() { |
| 2807 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2808 | final long identity = Binder.clearCallingIdentity(); |
| 2809 | try { |
| 2810 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2811 | if (phone.isInEmergencySmsMode()) { |
| 2812 | return true; |
| 2813 | } |
| 2814 | } |
| 2815 | } finally { |
| 2816 | Binder.restoreCallingIdentity(identity); |
| 2817 | } |
| 2818 | return false; |
| 2819 | } |
| 2820 | |
| 2821 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2822 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2823 | throws RemoteException { |
| 2824 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2825 | final long token = Binder.clearCallingIdentity(); |
| 2826 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2827 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2828 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2829 | .addRegistrationCallbackForSubscription(c, subId); |
| 2830 | } finally { |
| 2831 | Binder.restoreCallingIdentity(token); |
| 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2836 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2837 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2838 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2839 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2840 | } |
| 2841 | Binder.withCleanCallingIdentity(() -> { |
| 2842 | try { |
| 2843 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2844 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2845 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2846 | } catch (IllegalArgumentException e) { |
| 2847 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2848 | + "is inactive, ignoring unregister."); |
| 2849 | // If the subscription is no longer active, just return, since the callback |
| 2850 | // will already have been removed internally. |
| 2851 | } |
| 2852 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2856 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2857 | throws RemoteException { |
| 2858 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2859 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2860 | final long token = Binder.clearCallingIdentity(); |
| 2861 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2862 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2863 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2864 | } finally { |
| 2865 | Binder.restoreCallingIdentity(token); |
| 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2870 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2871 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2872 | |
| 2873 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2874 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2875 | } |
| 2876 | Binder.withCleanCallingIdentity(() -> { |
| 2877 | try { |
| 2878 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2879 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2880 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2881 | } catch (IllegalArgumentException e) { |
| 2882 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2883 | + "is inactive, ignoring unregister."); |
| 2884 | // If the subscription is no longer active, just return, since the callback |
| 2885 | // will already have been removed internally. |
| 2886 | } |
| 2887 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2891 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2892 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2893 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2894 | final long token = Binder.clearCallingIdentity(); |
| 2895 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2896 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2897 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2898 | } catch (ImsException e) { |
| 2899 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2900 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2901 | } catch (IllegalArgumentException e) { |
| 2902 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2903 | return false; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2904 | } finally { |
| 2905 | Binder.restoreCallingIdentity(token); |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2910 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2911 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2912 | final long token = Binder.clearCallingIdentity(); |
| 2913 | try { |
| 2914 | Phone phone = getPhone(subId); |
| 2915 | if (phone == null) return false; |
| 2916 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2917 | } finally { |
| 2918 | Binder.restoreCallingIdentity(token); |
| 2919 | } |
| 2920 | } |
| 2921 | |
| 2922 | @Override |
| 2923 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2924 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2925 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2926 | final long token = Binder.clearCallingIdentity(); |
| 2927 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2928 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2929 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2930 | } finally { |
| 2931 | Binder.restoreCallingIdentity(token); |
| 2932 | } |
| 2933 | } |
| 2934 | |
| 2935 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2936 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2937 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2938 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2939 | final long identity = Binder.clearCallingIdentity(); |
| 2940 | try { |
| 2941 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2942 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2943 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2944 | } finally { |
| 2945 | Binder.restoreCallingIdentity(identity); |
| 2946 | } |
| 2947 | } |
| 2948 | |
| 2949 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2950 | public boolean isVtSettingEnabled(int subId) { |
| 2951 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2952 | final long identity = Binder.clearCallingIdentity(); |
| 2953 | try { |
| 2954 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2955 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2956 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2957 | } finally { |
| 2958 | Binder.restoreCallingIdentity(identity); |
| 2959 | } |
| 2960 | } |
| 2961 | |
| 2962 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2963 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2964 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2965 | "setVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2966 | final long identity = Binder.clearCallingIdentity(); |
| 2967 | try { |
| 2968 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2969 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2970 | } finally { |
| 2971 | Binder.restoreCallingIdentity(identity); |
| 2972 | } |
| 2973 | } |
| 2974 | |
| 2975 | @Override |
| 2976 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2977 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2978 | final long identity = Binder.clearCallingIdentity(); |
| 2979 | try { |
| 2980 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2981 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2982 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2983 | } finally { |
| 2984 | Binder.restoreCallingIdentity(identity); |
| 2985 | } |
| 2986 | } |
| 2987 | |
| 2988 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2989 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2990 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2991 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2992 | final long identity = Binder.clearCallingIdentity(); |
| 2993 | try { |
| 2994 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2995 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2996 | } finally { |
| 2997 | Binder.restoreCallingIdentity(identity); |
| 2998 | } |
| 2999 | } |
| 3000 | |
| 3001 | @Override |
| 3002 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3003 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3004 | final long identity = Binder.clearCallingIdentity(); |
| 3005 | try { |
| 3006 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3007 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3008 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 3009 | } finally { |
| 3010 | Binder.restoreCallingIdentity(identity); |
| 3011 | } |
| 3012 | } |
| 3013 | |
| 3014 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3015 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3016 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3017 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3018 | final long identity = Binder.clearCallingIdentity(); |
| 3019 | try { |
| 3020 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3021 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3022 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 3023 | } finally { |
| 3024 | Binder.restoreCallingIdentity(identity); |
| 3025 | } |
| 3026 | } |
| 3027 | |
| 3028 | @Override |
| 3029 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3030 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3031 | "setVoWiFiNonPersistent"); |
| 3032 | final long identity = Binder.clearCallingIdentity(); |
| 3033 | try { |
| 3034 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3035 | boolean isRoaming = TelephonyManager.from( |
| 3036 | getPhone(subId).getContext()).isNetworkRoaming(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3037 | ImsManager.getInstance(mApp, |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3038 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3039 | } finally { |
| 3040 | Binder.restoreCallingIdentity(identity); |
| 3041 | } |
| 3042 | } |
| 3043 | |
| 3044 | @Override |
| 3045 | public int getVoWiFiModeSetting(int subId) { |
| 3046 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3047 | final long identity = Binder.clearCallingIdentity(); |
| 3048 | try { |
| 3049 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3050 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3051 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3052 | } finally { |
| 3053 | Binder.restoreCallingIdentity(identity); |
| 3054 | } |
| 3055 | } |
| 3056 | |
| 3057 | @Override |
| 3058 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3059 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3060 | "setVoWiFiModeSetting"); |
| 3061 | final long identity = Binder.clearCallingIdentity(); |
| 3062 | try { |
| 3063 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3064 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3065 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3066 | } finally { |
| 3067 | Binder.restoreCallingIdentity(identity); |
| 3068 | } |
| 3069 | } |
| 3070 | |
| 3071 | @Override |
| 3072 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3073 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3074 | final long identity = Binder.clearCallingIdentity(); |
| 3075 | try { |
| 3076 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3077 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3078 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3079 | } finally { |
| 3080 | Binder.restoreCallingIdentity(identity); |
| 3081 | } |
| 3082 | } |
| 3083 | |
| 3084 | @Override |
| 3085 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3086 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3087 | "setVoWiFiRoamingModeSetting"); |
| 3088 | final long identity = Binder.clearCallingIdentity(); |
| 3089 | try { |
| 3090 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3091 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3092 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3093 | } finally { |
| 3094 | Binder.restoreCallingIdentity(identity); |
| 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | @Override |
| 3099 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3100 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3101 | "setRttCapabilityEnabled"); |
| 3102 | final long identity = Binder.clearCallingIdentity(); |
| 3103 | try { |
| 3104 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3105 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3106 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3107 | } finally { |
| 3108 | Binder.restoreCallingIdentity(identity); |
| 3109 | } |
| 3110 | } |
| 3111 | |
| 3112 | @Override |
| 3113 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3114 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3115 | final long identity = Binder.clearCallingIdentity(); |
| 3116 | try { |
| 3117 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3118 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3119 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3120 | } finally { |
| 3121 | Binder.restoreCallingIdentity(identity); |
| 3122 | } |
| 3123 | } |
| 3124 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3125 | @Override |
| 3126 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3127 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3128 | final long identity = Binder.clearCallingIdentity(); |
| 3129 | try { |
| 3130 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3131 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3132 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3133 | } finally { |
| 3134 | Binder.restoreCallingIdentity(identity); |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | @Override |
| 3139 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3140 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3141 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3142 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3143 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3144 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3145 | try { |
| 3146 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3147 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3148 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3149 | } catch (IllegalArgumentException e) { |
| 3150 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3151 | + "is inactive, ignoring unregister."); |
| 3152 | // If the subscription is no longer active, just return, since the callback will already |
| 3153 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3154 | } finally { |
| 3155 | Binder.restoreCallingIdentity(identity); |
| 3156 | } |
| 3157 | } |
| 3158 | |
| 3159 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3160 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3161 | boolean isProvisioned) { |
| 3162 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3163 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3164 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3165 | } |
| 3166 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3167 | "setProvisioningStatusForCapability"); |
| 3168 | final long identity = Binder.clearCallingIdentity(); |
| 3169 | try { |
| 3170 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3171 | Phone phone = getPhone(subId); |
| 3172 | if (phone == null) { |
| 3173 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3174 | + subId); |
| 3175 | return; |
| 3176 | } |
| 3177 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3178 | return; |
| 3179 | } |
| 3180 | |
| 3181 | // this capability requires provisioning, route to the correct API. |
| 3182 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3183 | switch (capability) { |
| 3184 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3185 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3186 | ims.setVolteProvisioned(isProvisioned); |
| 3187 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3188 | ims.setWfcProvisioned(isProvisioned); |
| 3189 | } |
| 3190 | break; |
| 3191 | } |
| 3192 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3193 | // There is currently no difference in VT provisioning type. |
| 3194 | ims.setVtProvisioned(isProvisioned); |
| 3195 | break; |
| 3196 | } |
| 3197 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3198 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3199 | // change the capability of the feature instead if needed. |
| 3200 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3201 | == isProvisioned) { |
| 3202 | // No change in provisioning. |
| 3203 | return; |
| 3204 | } |
| 3205 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3206 | try { |
| 3207 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3208 | } catch (ImsException e) { |
| 3209 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3210 | + ", Exception" + e.getMessage()); |
| 3211 | } |
| 3212 | break; |
| 3213 | } |
| 3214 | default: { |
| 3215 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3216 | + capability + "', which does not require provisioning."); |
| 3217 | } |
| 3218 | } |
| 3219 | |
| 3220 | } finally { |
| 3221 | Binder.restoreCallingIdentity(identity); |
| 3222 | } |
| 3223 | } |
| 3224 | |
| 3225 | @Override |
| 3226 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3227 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3228 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3229 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3230 | } |
| 3231 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3232 | final long identity = Binder.clearCallingIdentity(); |
| 3233 | try { |
| 3234 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3235 | Phone phone = getPhone(subId); |
| 3236 | if (phone == null) { |
| 3237 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3238 | + subId); |
| 3239 | // We will fail with "true" as the provisioning status because this is the default |
| 3240 | // if we do not require provisioning. |
| 3241 | return true; |
| 3242 | } |
| 3243 | |
| 3244 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3245 | return true; |
| 3246 | } |
| 3247 | |
| 3248 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3249 | switch (capability) { |
| 3250 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3251 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3252 | return ims.isVolteProvisionedOnDevice(); |
| 3253 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3254 | return ims.isWfcProvisionedOnDevice(); |
| 3255 | } |
| 3256 | // This should never happen, since we are checking tech above to make sure it |
| 3257 | // is either LTE or IWLAN. |
| 3258 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3259 | + "capability."); |
| 3260 | } |
| 3261 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3262 | // There is currently no difference in VT provisioning type. |
| 3263 | return ims.isVtProvisionedOnDevice(); |
| 3264 | } |
| 3265 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3266 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3267 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3268 | } |
| 3269 | default: { |
| 3270 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3271 | + capability + "', which does not require provisioning."); |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | } finally { |
| 3276 | Binder.restoreCallingIdentity(identity); |
| 3277 | } |
| 3278 | } |
| 3279 | |
| 3280 | @Override |
| 3281 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3282 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3283 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3284 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3285 | } |
| 3286 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3287 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3288 | return (provisionedBits & capability) > 0; |
| 3289 | } |
| 3290 | |
| 3291 | @Override |
| 3292 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3293 | boolean isProvisioned) { |
| 3294 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3295 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3296 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3297 | } |
| 3298 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3299 | "setProvisioningStatusForCapability"); |
| 3300 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3301 | // If the current provisioning status for capability already matches isProvisioned, |
| 3302 | // do nothing. |
| 3303 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3304 | return; |
| 3305 | } |
| 3306 | if (isProvisioned) { |
| 3307 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3308 | } else { |
| 3309 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3310 | } |
| 3311 | } |
| 3312 | |
| 3313 | /** |
| 3314 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3315 | * technology. The bitfield should mirror the bitfield defined by |
| 3316 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3317 | */ |
| 3318 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3319 | String key = getMmTelProvisioningKey(subId, tech); |
| 3320 | // Default is no capabilities are provisioned. |
| 3321 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3322 | } |
| 3323 | |
| 3324 | /** |
| 3325 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3326 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3327 | * technology specified. |
| 3328 | * |
| 3329 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3330 | */ |
| 3331 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3332 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3333 | String key = getMmTelProvisioningKey(subId, tech); |
| 3334 | editor.putInt(key, newField); |
| 3335 | editor.commit(); |
| 3336 | } |
| 3337 | |
| 3338 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3339 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3340 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3341 | } |
| 3342 | |
| 3343 | /** |
| 3344 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3345 | * carrier associated with the subscription id. |
| 3346 | */ |
| 3347 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3348 | int capability) { |
| 3349 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3350 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3351 | boolean requireUtProvisioning = c.getBoolean( |
| 3352 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3353 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3354 | // the no-SIM case, where we would normally shortcut this to false. |
| 3355 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3356 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3357 | false); |
| 3358 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3359 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3360 | |
| 3361 | // First check to make sure that the capability requires provisioning. |
| 3362 | switch (capability) { |
| 3363 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3364 | // intentional fallthrough |
| 3365 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3366 | if (requireVoiceVtProvisioning) { |
| 3367 | // Voice and Video requires provisioning |
| 3368 | return true; |
| 3369 | } |
| 3370 | break; |
| 3371 | } |
| 3372 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3373 | if (requireUtProvisioning) { |
| 3374 | // UT requires provisioning |
| 3375 | return true; |
| 3376 | } |
| 3377 | break; |
| 3378 | } |
| 3379 | } |
| 3380 | return false; |
| 3381 | } |
| 3382 | |
| 3383 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3384 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3385 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3386 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3387 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3388 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3389 | final long identity = Binder.clearCallingIdentity(); |
| 3390 | try { |
| 3391 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3392 | int slotId = getSlotIndex(subId); |
| 3393 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3394 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3395 | + subId + "' for key:" + key); |
| 3396 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3397 | } |
| 3398 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3399 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3400 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3401 | + subId + "' for key:" + key); |
| 3402 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3403 | } finally { |
| 3404 | Binder.restoreCallingIdentity(identity); |
| 3405 | } |
| 3406 | } |
| 3407 | |
| 3408 | @Override |
| 3409 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3410 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3411 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3412 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3413 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3414 | final long identity = Binder.clearCallingIdentity(); |
| 3415 | try { |
| 3416 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3417 | int slotId = getSlotIndex(subId); |
| 3418 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3419 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3420 | + subId + "' for key:" + key); |
| 3421 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3422 | } |
| 3423 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3424 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3425 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3426 | + subId + "' for key:" + key); |
| 3427 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3428 | } finally { |
| 3429 | Binder.restoreCallingIdentity(identity); |
| 3430 | } |
| 3431 | } |
| 3432 | |
| 3433 | @Override |
| 3434 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3435 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3436 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3437 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3438 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3439 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3440 | final long identity = Binder.clearCallingIdentity(); |
| 3441 | try { |
| 3442 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3443 | int slotId = getSlotIndex(subId); |
| 3444 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3445 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3446 | + subId + "' for key:" + key); |
| 3447 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3448 | } |
| 3449 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3450 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3451 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3452 | + "' for key:" + key); |
| 3453 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3454 | } finally { |
| 3455 | Binder.restoreCallingIdentity(identity); |
| 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | @Override |
| 3460 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3461 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3462 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3463 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3464 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3465 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3466 | final long identity = Binder.clearCallingIdentity(); |
| 3467 | try { |
| 3468 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3469 | int slotId = getSlotIndex(subId); |
| 3470 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3471 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3472 | + subId + "' for key:" + key); |
| 3473 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3474 | } |
| 3475 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3476 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3477 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3478 | + "' for key:" + key); |
| 3479 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3480 | } finally { |
| 3481 | Binder.restoreCallingIdentity(identity); |
| 3482 | } |
| 3483 | } |
| 3484 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3485 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3486 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3487 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3488 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3489 | } |
| 3490 | return slotId; |
| 3491 | } |
| 3492 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3493 | private int getSlotIndex(int subId) { |
| 3494 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3495 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3496 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3497 | } |
| 3498 | return slotId; |
| 3499 | } |
| 3500 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3501 | /** |
| 3502 | * Returns the network type for a subId |
| 3503 | */ |
| 3504 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3505 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3506 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3507 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3508 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3509 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3510 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3511 | final long identity = Binder.clearCallingIdentity(); |
| 3512 | try { |
| 3513 | final Phone phone = getPhone(subId); |
| 3514 | if (phone != null) { |
| 3515 | return phone.getServiceState().getDataNetworkType(); |
| 3516 | } else { |
| 3517 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3518 | } |
| 3519 | } finally { |
| 3520 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3521 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | /** |
| 3525 | * Returns the data network type |
| 3526 | */ |
| 3527 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3528 | public int getDataNetworkType(String callingPackage) { |
| 3529 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | /** |
| 3533 | * Returns the data network type for a subId |
| 3534 | */ |
| 3535 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3536 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3537 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3538 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3539 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3540 | } |
| 3541 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3542 | final long identity = Binder.clearCallingIdentity(); |
| 3543 | try { |
| 3544 | final Phone phone = getPhone(subId); |
| 3545 | if (phone != null) { |
| 3546 | return phone.getServiceState().getDataNetworkType(); |
| 3547 | } else { |
| 3548 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3549 | } |
| 3550 | } finally { |
| 3551 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3552 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3556 | * Returns the Voice network type for a subId |
| 3557 | */ |
| 3558 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3559 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3560 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3561 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3562 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3563 | } |
| 3564 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3565 | final long identity = Binder.clearCallingIdentity(); |
| 3566 | try { |
| 3567 | final Phone phone = getPhone(subId); |
| 3568 | if (phone != null) { |
| 3569 | return phone.getServiceState().getVoiceNetworkType(); |
| 3570 | } else { |
| 3571 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3572 | } |
| 3573 | } finally { |
| 3574 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3575 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3576 | } |
| 3577 | |
| 3578 | /** |
| 3579 | * @return true if a ICC card is present |
| 3580 | */ |
| 3581 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3582 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3583 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3584 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
| 3587 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3588 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3589 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3590 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3591 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3592 | final long identity = Binder.clearCallingIdentity(); |
| 3593 | try { |
| 3594 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3595 | if (phone != null) { |
| 3596 | return phone.getIccCard().hasIccCard(); |
| 3597 | } else { |
| 3598 | return false; |
| 3599 | } |
| 3600 | } finally { |
| 3601 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3602 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
| 3605 | /** |
| 3606 | * Return if the current radio is LTE on CDMA. This |
| 3607 | * is a tri-state return value as for a period of time |
| 3608 | * the mode may be unknown. |
| 3609 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3610 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3611 | * @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] | 3612 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3613 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3614 | @Override |
| 3615 | public int getLteOnCdmaMode(String callingPackage) { |
| 3616 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3617 | } |
| 3618 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3619 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3620 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3621 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3622 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3623 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3624 | } |
| 3625 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3626 | final long identity = Binder.clearCallingIdentity(); |
| 3627 | try { |
| 3628 | final Phone phone = getPhone(subId); |
| 3629 | if (phone == null) { |
| 3630 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3631 | } else { |
| 3632 | return phone.getLteOnCdmaMode(); |
| 3633 | } |
| 3634 | } finally { |
| 3635 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3636 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3637 | } |
| 3638 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3639 | /** |
| 3640 | * {@hide} |
| 3641 | * Returns Default subId, 0 in the case of single standby. |
| 3642 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3643 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3644 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3647 | private int getSlotForDefaultSubscription() { |
| 3648 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3649 | } |
| 3650 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3651 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3652 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3653 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3654 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3655 | private boolean isActiveSubscription(int subId) { |
| 3656 | return mSubscriptionController.isActiveSubId(subId); |
| 3657 | } |
| 3658 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3659 | /** |
| 3660 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3661 | */ |
| 3662 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3663 | final long identity = Binder.clearCallingIdentity(); |
| 3664 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3665 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3666 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3667 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3668 | } finally { |
| 3669 | Binder.restoreCallingIdentity(identity); |
| 3670 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | /** |
| 3674 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3675 | */ |
| 3676 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3677 | final long identity = Binder.clearCallingIdentity(); |
| 3678 | try { |
| 3679 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3680 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3681 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3682 | } finally { |
| 3683 | Binder.restoreCallingIdentity(identity); |
| 3684 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3685 | } |
| 3686 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3687 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3688 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3689 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3690 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3691 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3692 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3693 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3694 | if (phoneId == -1) { |
| 3695 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3696 | + " does not correspond to an active phone"); |
| 3697 | } |
| 3698 | return PhoneFactory.getPhone(phoneId); |
| 3699 | } |
| 3700 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3701 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3702 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3703 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3704 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3705 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3706 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3707 | if (DBG) { |
| 3708 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3709 | } |
| 3710 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3711 | p2); |
| 3712 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3713 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3714 | |
| 3715 | @Override |
| 3716 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3717 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3718 | enforceModifyPermission(); |
| 3719 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3720 | if (DBG) { |
| 3721 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3722 | } |
| 3723 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3724 | callingPackage, aid, p2); |
| 3725 | } |
| 3726 | |
| 3727 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3728 | String callingPackage, String aid, int p2) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3729 | final long identity = Binder.clearCallingIdentity(); |
| 3730 | try { |
| 3731 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3732 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3733 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3734 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3735 | if (bestComponent == null |
| 3736 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3737 | loge("The calling package is not allowed to access ISD-R."); |
| 3738 | throw new SecurityException( |
| 3739 | "The calling package is not allowed to access ISD-R."); |
| 3740 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3741 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3742 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3743 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3744 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3745 | null /* workSource */); |
| 3746 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3747 | return response; |
| 3748 | } finally { |
| 3749 | Binder.restoreCallingIdentity(identity); |
| 3750 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3751 | } |
| 3752 | |
| 3753 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3754 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3755 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3756 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3757 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3758 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3759 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3760 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3761 | @Override |
| 3762 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3763 | enforceModifyPermission(); |
| 3764 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3765 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3766 | channel); |
| 3767 | } |
| 3768 | |
| 3769 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3770 | final long identity = Binder.clearCallingIdentity(); |
| 3771 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3772 | if (channel < 0) { |
| 3773 | return false; |
| 3774 | } |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3775 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3776 | null /* workSource */); |
| 3777 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3778 | return success; |
| 3779 | } finally { |
| 3780 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3781 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3785 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3786 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3787 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3788 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3789 | if (DBG) { |
| 3790 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3791 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3792 | + p3 + " data=" + data); |
| 3793 | } |
| 3794 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3795 | command, p1, p2, p3, data); |
| 3796 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3797 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3798 | @Override |
| 3799 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3800 | int command, int p1, int p2, int p3, String data) { |
| 3801 | enforceModifyPermission(); |
| 3802 | if (DBG) { |
| 3803 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3804 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3805 | + p3 + " data=" + data); |
| 3806 | } |
| 3807 | return iccTransmitApduLogicalChannelWithPermission( |
| 3808 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3809 | data); |
| 3810 | } |
| 3811 | |
| 3812 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3813 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3814 | final long identity = Binder.clearCallingIdentity(); |
| 3815 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3816 | if (channel < 0) { |
| 3817 | return ""; |
| 3818 | } |
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 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3821 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3822 | null /* workSource */); |
| 3823 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3824 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3825 | // Append the returned status code to the end of the response payload. |
| 3826 | String s = Integer.toHexString( |
| 3827 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3828 | if (response.payload != null) { |
| 3829 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3830 | } |
| 3831 | return s; |
| 3832 | } finally { |
| 3833 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3834 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3835 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3836 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3837 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3838 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3839 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3840 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3841 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3842 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3843 | if (DBG) { |
| 3844 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3845 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3846 | } |
| 3847 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3848 | cla, command, p1, p2, p3, data); |
| 3849 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3850 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3851 | @Override |
| 3852 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3853 | int command, int p1, int p2, int p3, String data) { |
| 3854 | enforceModifyPermission(); |
| 3855 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3856 | if (DBG) { |
| 3857 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3858 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3859 | + " data=" + data); |
| 3860 | } |
| 3861 | |
| 3862 | return iccTransmitApduBasicChannelWithPermission( |
| 3863 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3864 | p2, p3, data); |
| 3865 | } |
| 3866 | |
| 3867 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3868 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3869 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3870 | final long identity = Binder.clearCallingIdentity(); |
| 3871 | try { |
| 3872 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3873 | && TextUtils.equals(ISDR_AID, data)) { |
| 3874 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3875 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3876 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3877 | if (bestComponent == null |
| 3878 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3879 | loge("The calling package is not allowed to select ISD-R."); |
| 3880 | throw new SecurityException( |
| 3881 | "The calling package is not allowed to select ISD-R."); |
| 3882 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3883 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3884 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3885 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3886 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 3887 | null /* workSource */); |
| 3888 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3889 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3890 | // Append the returned status code to the end of the response payload. |
| 3891 | String s = Integer.toHexString( |
| 3892 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3893 | if (response.payload != null) { |
| 3894 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3895 | } |
| 3896 | return s; |
| 3897 | } finally { |
| 3898 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3899 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3903 | 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] | 3904 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3905 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3906 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3907 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3908 | final long identity = Binder.clearCallingIdentity(); |
| 3909 | try { |
| 3910 | if (DBG) { |
| 3911 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3912 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3913 | } |
| 3914 | |
| 3915 | IccIoResult response = |
| 3916 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3917 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3918 | subId); |
| 3919 | |
| 3920 | if (DBG) { |
| 3921 | log("Exchange SIM_IO [R]" + response); |
| 3922 | } |
| 3923 | |
| 3924 | byte[] result = null; |
| 3925 | int length = 2; |
| 3926 | if (response.payload != null) { |
| 3927 | length = 2 + response.payload.length; |
| 3928 | result = new byte[length]; |
| 3929 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3930 | } else { |
| 3931 | result = new byte[length]; |
| 3932 | } |
| 3933 | |
| 3934 | result[length - 1] = (byte) response.sw2; |
| 3935 | result[length - 2] = (byte) response.sw1; |
| 3936 | return result; |
| 3937 | } finally { |
| 3938 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3939 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3940 | } |
| 3941 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3942 | /** |
| 3943 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3944 | * on a particular subscription |
| 3945 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3946 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3947 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3948 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3949 | return null; |
| 3950 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3951 | |
| 3952 | final long identity = Binder.clearCallingIdentity(); |
| 3953 | try { |
| 3954 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3955 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3956 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3957 | return null; |
| 3958 | } |
| 3959 | Object response = sendRequest( |
| 3960 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3961 | if (response instanceof String[]) { |
| 3962 | return (String[]) response; |
| 3963 | } |
| 3964 | // Response is an Exception of some kind, |
| 3965 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3966 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3967 | } finally { |
| 3968 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3969 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3970 | } |
| 3971 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3972 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3973 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3974 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3975 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3976 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3977 | final long identity = Binder.clearCallingIdentity(); |
| 3978 | try { |
| 3979 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3980 | if (response.payload == null) { |
| 3981 | return ""; |
| 3982 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3983 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3984 | // Append the returned status code to the end of the response payload. |
| 3985 | String s = Integer.toHexString( |
| 3986 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3987 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3988 | return s; |
| 3989 | } finally { |
| 3990 | Binder.restoreCallingIdentity(identity); |
| 3991 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3992 | } |
| 3993 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3994 | /** |
| 3995 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3996 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3997 | * |
| 3998 | * @param itemID the ID of the item to read |
| 3999 | * @return the NV item as a String, or null on error. |
| 4000 | */ |
| 4001 | @Override |
| 4002 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4003 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4004 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4005 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4006 | |
| 4007 | final long identity = Binder.clearCallingIdentity(); |
| 4008 | try { |
| 4009 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4010 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4011 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4012 | return value; |
| 4013 | } finally { |
| 4014 | Binder.restoreCallingIdentity(identity); |
| 4015 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | /** |
| 4019 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4020 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4021 | * |
| 4022 | * @param itemID the ID of the item to read |
| 4023 | * @param itemValue the value to write, as a String |
| 4024 | * @return true on success; false on any failure |
| 4025 | */ |
| 4026 | @Override |
| 4027 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4028 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4029 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4030 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4031 | |
| 4032 | final long identity = Binder.clearCallingIdentity(); |
| 4033 | try { |
| 4034 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4035 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4036 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4037 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4038 | return success; |
| 4039 | } finally { |
| 4040 | Binder.restoreCallingIdentity(identity); |
| 4041 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4042 | } |
| 4043 | |
| 4044 | /** |
| 4045 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4046 | * Used for device configuration by some CDMA operators. |
| 4047 | * |
| 4048 | * @param preferredRoamingList byte array containing the new PRL |
| 4049 | * @return true on success; false on any failure |
| 4050 | */ |
| 4051 | @Override |
| 4052 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4053 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4054 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4055 | |
| 4056 | final long identity = Binder.clearCallingIdentity(); |
| 4057 | try { |
| 4058 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4059 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4060 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4061 | return success; |
| 4062 | } finally { |
| 4063 | Binder.restoreCallingIdentity(identity); |
| 4064 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4068 | * 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] | 4069 | * Used for device configuration by some CDMA operators. |
| 4070 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4071 | * @param slotIndex - device slot. |
| 4072 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4073 | * @return true on success; false on any failure |
| 4074 | */ |
| 4075 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4076 | public boolean resetModemConfig(int slotIndex) { |
| 4077 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4078 | if (phone != null) { |
| 4079 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4080 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4081 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4082 | final long identity = Binder.clearCallingIdentity(); |
| 4083 | try { |
| 4084 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4085 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4086 | return success; |
| 4087 | } finally { |
| 4088 | Binder.restoreCallingIdentity(identity); |
| 4089 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4090 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4091 | return false; |
| 4092 | } |
| 4093 | |
| 4094 | /** |
| 4095 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4096 | * |
| 4097 | * @param slotIndex - device slot. |
| 4098 | * |
| 4099 | * @return true on success; false on any failure |
| 4100 | */ |
| 4101 | @Override |
| 4102 | public boolean rebootModem(int slotIndex) { |
| 4103 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4104 | if (phone != null) { |
| 4105 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4106 | mApp, phone.getSubId(), "rebootModem"); |
| 4107 | |
| 4108 | final long identity = Binder.clearCallingIdentity(); |
| 4109 | try { |
| 4110 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4111 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4112 | return success; |
| 4113 | } finally { |
| 4114 | Binder.restoreCallingIdentity(identity); |
| 4115 | } |
| 4116 | } |
| 4117 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4118 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4119 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4120 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4121 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4122 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4123 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4124 | return new String[0]; |
| 4125 | } |
| 4126 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4127 | final long identity = Binder.clearCallingIdentity(); |
| 4128 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4129 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4130 | } finally { |
| 4131 | Binder.restoreCallingIdentity(identity); |
| 4132 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4133 | } |
| 4134 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4135 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4136 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4137 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4138 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4139 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4140 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4141 | |
| 4142 | final long identity = Binder.clearCallingIdentity(); |
| 4143 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4144 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4145 | if (resolver == null) { |
| 4146 | // may happen if the device does not support IMS. |
| 4147 | return; |
| 4148 | } |
| 4149 | resolver.enableIms(slotId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4150 | } finally { |
| 4151 | Binder.restoreCallingIdentity(identity); |
| 4152 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4156 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4157 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4158 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4159 | public void disableIms(int slotId) { |
| 4160 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4161 | |
| 4162 | final long identity = Binder.clearCallingIdentity(); |
| 4163 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4164 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4165 | if (resolver == null) { |
| 4166 | // may happen if the device does not support IMS. |
| 4167 | return; |
| 4168 | } |
| 4169 | resolver.disableIms(slotId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4170 | } finally { |
| 4171 | Binder.restoreCallingIdentity(identity); |
| 4172 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4173 | } |
| 4174 | |
| 4175 | /** |
| 4176 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4177 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4178 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4179 | */ |
| 4180 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4181 | IImsServiceFeatureCallback callback) { |
| 4182 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4183 | |
| 4184 | final long identity = Binder.clearCallingIdentity(); |
| 4185 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4186 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4187 | if (resolver == null) { |
| 4188 | // may happen if the device does not support IMS. |
| 4189 | return null; |
| 4190 | } |
| 4191 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4192 | } finally { |
| 4193 | Binder.restoreCallingIdentity(identity); |
| 4194 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4195 | } |
| 4196 | |
| 4197 | /** |
| 4198 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4199 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4200 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4201 | * listener for feature updates. |
| 4202 | */ |
| 4203 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4204 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4205 | |
| 4206 | final long identity = Binder.clearCallingIdentity(); |
| 4207 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4208 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4209 | if (resolver == null) { |
| 4210 | // may happen if the device does not support IMS. |
| 4211 | return null; |
| 4212 | } |
| 4213 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4214 | } finally { |
| 4215 | Binder.restoreCallingIdentity(identity); |
| 4216 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4217 | } |
| 4218 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4219 | /** |
| 4220 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4221 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4222 | */ |
| 4223 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4224 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4225 | |
| 4226 | final long identity = Binder.clearCallingIdentity(); |
| 4227 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4228 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4229 | if (resolver == null) { |
| 4230 | // may happen if the device does not support IMS. |
| 4231 | return null; |
| 4232 | } |
| 4233 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4234 | } finally { |
| 4235 | Binder.restoreCallingIdentity(identity); |
| 4236 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4237 | } |
| 4238 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4239 | /** |
| 4240 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4241 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4242 | */ |
| 4243 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4244 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4245 | |
| 4246 | final long identity = Binder.clearCallingIdentity(); |
| 4247 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4248 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4249 | if (resolver == null) { |
| 4250 | // may happen if the device does not support IMS. |
| 4251 | return null; |
| 4252 | } |
| 4253 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4254 | } finally { |
| 4255 | Binder.restoreCallingIdentity(identity); |
| 4256 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4257 | } |
| 4258 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4259 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4260 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4261 | * |
| 4262 | * @param slotId the slot ID that the ImsService should bind for. |
| 4263 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4264 | * ImsService is the device default ImsService. |
| 4265 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4266 | * to. |
| 4267 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4268 | * @hide |
| 4269 | */ |
| 4270 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4271 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4272 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4273 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4274 | "setImsService"); |
| 4275 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4276 | final long identity = Binder.clearCallingIdentity(); |
| 4277 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4278 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4279 | if (resolver == null) { |
| 4280 | // may happen if the device does not support IMS. |
| 4281 | return false; |
| 4282 | } |
| 4283 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4284 | packageName); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4285 | } finally { |
| 4286 | Binder.restoreCallingIdentity(identity); |
| 4287 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | /** |
| 4291 | * Return the ImsService configuration. |
| 4292 | * |
| 4293 | * @param slotId The slot that the ImsService is associated with. |
| 4294 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4295 | * the device default. |
| 4296 | * @return the package name of the ImsService configuration. |
| 4297 | */ |
| 4298 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4299 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4300 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4301 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4302 | "getImsService"); |
| 4303 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4304 | final long identity = Binder.clearCallingIdentity(); |
| 4305 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4306 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4307 | if (resolver == null) { |
| 4308 | // may happen if the device does not support IMS. |
| 4309 | return ""; |
| 4310 | } |
| 4311 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4312 | } finally { |
| 4313 | Binder.restoreCallingIdentity(identity); |
| 4314 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4315 | } |
| 4316 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4317 | public void setImsRegistrationState(boolean registered) { |
| 4318 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4319 | |
| 4320 | final long identity = Binder.clearCallingIdentity(); |
| 4321 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4322 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4323 | } finally { |
| 4324 | Binder.restoreCallingIdentity(identity); |
| 4325 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4329 | * Set the network selection mode to automatic. |
| 4330 | * |
| 4331 | */ |
| 4332 | @Override |
| 4333 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4334 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4335 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4336 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4337 | if (!isActiveSubscription(subId)) { |
| 4338 | return; |
| 4339 | } |
| 4340 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4341 | final long identity = Binder.clearCallingIdentity(); |
| 4342 | try { |
| 4343 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4344 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4345 | } finally { |
| 4346 | Binder.restoreCallingIdentity(identity); |
| 4347 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4348 | } |
| 4349 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4350 | /** |
| 4351 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4352 | * |
| 4353 | * @param subId the id of the subscription. |
| 4354 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4355 | * the operator to attach to. |
| 4356 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4357 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4358 | * normal network selection next time. |
| 4359 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4360 | */ |
| 4361 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4362 | public boolean setNetworkSelectionModeManual( |
| 4363 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4364 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4365 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4366 | |
| 4367 | if (!isActiveSubscription(subId)) { |
| 4368 | return false; |
| 4369 | } |
| 4370 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4371 | final long identity = Binder.clearCallingIdentity(); |
| 4372 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4373 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4374 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4375 | if (DBG) { |
| 4376 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4377 | + " operator: " + operatorInfo); |
| 4378 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4379 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4380 | } finally { |
| 4381 | Binder.restoreCallingIdentity(identity); |
| 4382 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4383 | } |
| 4384 | |
| 4385 | /** |
| 4386 | * Scans for available networks. |
| 4387 | */ |
| 4388 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4389 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4390 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4391 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4392 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4393 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4394 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4395 | .setCallingPackage(callingPackage) |
| 4396 | .setCallingPid(Binder.getCallingPid()) |
| 4397 | .setCallingUid(Binder.getCallingUid()) |
| 4398 | .setMethod("getCellNetworkScanResults") |
| 4399 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4400 | .build()); |
| 4401 | switch (locationResult) { |
| 4402 | case DENIED_HARD: |
| 4403 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4404 | case DENIED_SOFT: |
| 4405 | return null; |
| 4406 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4407 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4408 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4409 | try { |
| 4410 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4411 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4412 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4413 | } finally { |
| 4414 | Binder.restoreCallingIdentity(identity); |
| 4415 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4416 | } |
| 4417 | |
| 4418 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4419 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4420 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4421 | * @param subId id of the subscription |
| 4422 | * @param request contains the radio access networks with bands/channels to scan |
| 4423 | * @param messenger callback messenger for scan results or errors |
| 4424 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4425 | * @return the id of the requested scan which can be used to stop the scan. |
| 4426 | */ |
| 4427 | @Override |
| 4428 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4429 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4430 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4431 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4432 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4433 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4434 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4435 | .setCallingPackage(callingPackage) |
| 4436 | .setCallingPid(Binder.getCallingPid()) |
| 4437 | .setCallingUid(Binder.getCallingUid()) |
| 4438 | .setMethod("requestNetworkScan") |
| 4439 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4440 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4441 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
| 4442 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request); |
| 4443 | if (e != null) { |
| 4444 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4445 | throw e; |
| 4446 | } else { |
Hall Liu | 46dd96a | 2019-04-03 12:50:44 -0700 | [diff] [blame] | 4447 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4448 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4449 | } |
| 4450 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4451 | } |
yinxu | 612a819 | 2019-04-18 10:38:27 -0700 | [diff] [blame] | 4452 | final long identity = Binder.clearCallingIdentity(); |
| 4453 | try { |
| 4454 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4455 | request, messenger, binder, getPhone(subId), |
| 4456 | callingPackage); |
| 4457 | } finally { |
| 4458 | Binder.restoreCallingIdentity(identity); |
| 4459 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4460 | } |
| 4461 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4462 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
| 4463 | NetworkScanRequest request) { |
| 4464 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4465 | != PERMISSION_GRANTED) { |
| 4466 | return new SecurityException("permission.NETWORK_SCAN is needed for network scans" |
| 4467 | + " without location access."); |
| 4468 | } |
| 4469 | |
| 4470 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4471 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4472 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4473 | return new SecurityException("Specific channels must not be" |
| 4474 | + " scanned without location access."); |
| 4475 | } |
| 4476 | } |
| 4477 | } |
| 4478 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4479 | return null; |
| 4480 | } |
| 4481 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4482 | /** |
| 4483 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4484 | * |
| 4485 | * @param subId id of the subscription |
| 4486 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4487 | */ |
| 4488 | @Override |
| 4489 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4490 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4491 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4492 | |
| 4493 | final long identity = Binder.clearCallingIdentity(); |
| 4494 | try { |
| 4495 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 4496 | } finally { |
| 4497 | Binder.restoreCallingIdentity(identity); |
| 4498 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4499 | } |
| 4500 | |
| 4501 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4502 | * Get the calculated preferred network type. |
| 4503 | * Used for debugging incorrect network type. |
| 4504 | * |
| 4505 | * @return the preferred network type, defined in RILConstants.java. |
| 4506 | */ |
| 4507 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4508 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4509 | final Phone defaultPhone = getDefaultPhone(); |
| 4510 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4511 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4512 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4513 | } |
| 4514 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4515 | final long identity = Binder.clearCallingIdentity(); |
| 4516 | try { |
| 4517 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4518 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4519 | } finally { |
| 4520 | Binder.restoreCallingIdentity(identity); |
| 4521 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4522 | } |
| 4523 | |
| 4524 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4525 | * Get the preferred network type. |
| 4526 | * Used for device configuration by some CDMA operators. |
| 4527 | * |
| 4528 | * @return the preferred network type, defined in RILConstants.java. |
| 4529 | */ |
| 4530 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4531 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | 4848cd0 | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4532 | TelephonyPermissions |
| 4533 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4534 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4535 | |
| 4536 | final long identity = Binder.clearCallingIdentity(); |
| 4537 | try { |
| 4538 | if (DBG) log("getPreferredNetworkType"); |
| 4539 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4540 | int networkType = (result != null ? result[0] : -1); |
| 4541 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4542 | return networkType; |
| 4543 | } finally { |
| 4544 | Binder.restoreCallingIdentity(identity); |
| 4545 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4546 | } |
| 4547 | |
| 4548 | /** |
| 4549 | * Set the preferred network type. |
| 4550 | * Used for device configuration by some CDMA operators. |
| 4551 | * |
| 4552 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4553 | * @return true on success; false on any failure. |
| 4554 | */ |
| 4555 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4556 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4557 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4558 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4559 | |
| 4560 | final long identity = Binder.clearCallingIdentity(); |
| 4561 | try { |
| 4562 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4563 | Boolean success = (Boolean) sendRequest( |
| 4564 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4565 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4566 | if (success) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4567 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4568 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4569 | } |
| 4570 | return success; |
| 4571 | } finally { |
| 4572 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4573 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4574 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4575 | |
| 4576 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4577 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4578 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4579 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4580 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4581 | * @hide |
| 4582 | */ |
| 4583 | @Override |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4584 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4585 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4586 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4587 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4588 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4589 | if (phone != null) { |
| 4590 | return phone.hasMatchedTetherApnSetting(); |
| 4591 | } else { |
| 4592 | return false; |
| 4593 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4594 | } finally { |
| 4595 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4596 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4600 | * Set mobile data enabled |
| 4601 | * Used by the user through settings etc to turn on/off mobile data |
| 4602 | * |
| 4603 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4604 | */ |
| 4605 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4606 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4607 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4608 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4609 | |
| 4610 | final long identity = Binder.clearCallingIdentity(); |
| 4611 | try { |
| 4612 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4613 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4614 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4615 | if (phone != null) { |
| 4616 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4617 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4618 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4619 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4620 | } |
| 4621 | } finally { |
| 4622 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4623 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4627 | * Get the user enabled state of Mobile Data. |
| 4628 | * |
| 4629 | * TODO: remove and use isUserDataEnabled. |
| 4630 | * This can't be removed now because some vendor codes |
| 4631 | * calls through ITelephony directly while they should |
| 4632 | * use TelephonyManager. |
| 4633 | * |
| 4634 | * @return true on enabled |
| 4635 | */ |
| 4636 | @Override |
| 4637 | public boolean getDataEnabled(int subId) { |
| 4638 | return isUserDataEnabled(subId); |
| 4639 | } |
| 4640 | |
| 4641 | /** |
| 4642 | * Get whether mobile data is enabled per user setting. |
| 4643 | * |
| 4644 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4645 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4646 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4647 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4648 | * |
| 4649 | * @return {@code true} if data is enabled else {@code false} |
| 4650 | */ |
| 4651 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4652 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4653 | try { |
| 4654 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4655 | null); |
| 4656 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4657 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4658 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4659 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4660 | |
| 4661 | final long identity = Binder.clearCallingIdentity(); |
| 4662 | try { |
| 4663 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4664 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4665 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4666 | if (phone != null) { |
| 4667 | boolean retVal = phone.isUserDataEnabled(); |
| 4668 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4669 | return retVal; |
| 4670 | } else { |
| 4671 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4672 | return false; |
| 4673 | } |
| 4674 | } finally { |
| 4675 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4676 | } |
| 4677 | } |
| 4678 | |
| 4679 | /** |
| 4680 | * Get whether mobile data is enabled. |
| 4681 | * |
| 4682 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4683 | * whether mobile data is actually enabled. |
| 4684 | * |
| 4685 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4686 | * |
| 4687 | * @return {@code true} if data is enabled else {@code false} |
| 4688 | */ |
| 4689 | @Override |
| 4690 | public boolean isDataEnabled(int subId) { |
| 4691 | try { |
| 4692 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4693 | null); |
| 4694 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4695 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4696 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4697 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4698 | |
| 4699 | final long identity = Binder.clearCallingIdentity(); |
| 4700 | try { |
| 4701 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4702 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4703 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4704 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4705 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4706 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4707 | return retVal; |
| 4708 | } else { |
| 4709 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4710 | return false; |
| 4711 | } |
| 4712 | } finally { |
| 4713 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4714 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4715 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4716 | |
| 4717 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4718 | public int getCarrierPrivilegeStatus(int subId) { |
| 4719 | final Phone phone = getPhone(subId); |
| 4720 | if (phone == null) { |
| 4721 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4722 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4723 | } |
| 4724 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4725 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4726 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4727 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4728 | } |
| 4729 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4730 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4731 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4732 | |
| 4733 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4734 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4735 | final Phone phone = getPhone(subId); |
| 4736 | if (phone == null) { |
| 4737 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4738 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4739 | } |
| 4740 | UiccProfile profile = |
| 4741 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4742 | if (profile == null) { |
| 4743 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4744 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4745 | } |
| 4746 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4747 | } |
| 4748 | |
| 4749 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4750 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4751 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4752 | if (TextUtils.isEmpty(pkgName)) |
| 4753 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4754 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4755 | if (card == null) { |
| 4756 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4757 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4758 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4759 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4760 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4761 | } |
| 4762 | |
| 4763 | @Override |
| 4764 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4765 | if (TextUtils.isEmpty(pkgName)) |
| 4766 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4767 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4768 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4769 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4770 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4771 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4772 | continue; |
| 4773 | } |
| 4774 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4775 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4776 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4777 | break; |
| 4778 | } |
| 4779 | } |
| 4780 | |
| 4781 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4782 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4783 | |
| 4784 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4785 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4786 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4787 | loge("phoneId " + phoneId + " is not valid."); |
| 4788 | return null; |
| 4789 | } |
| 4790 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4791 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4792 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4793 | return null ; |
| 4794 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4795 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4796 | } |
| 4797 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4798 | @Override |
| 4799 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4800 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4801 | List<String> privilegedPackages = new ArrayList<>(); |
| 4802 | List<PackageInfo> packages = null; |
| 4803 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4804 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4805 | if (card == null) { |
| 4806 | // No UICC in that slot. |
| 4807 | continue; |
| 4808 | } |
| 4809 | if (card.hasCarrierPrivilegeRules()) { |
| 4810 | if (packages == null) { |
| 4811 | // Only check packages in user 0 for now |
| 4812 | packages = pm.getInstalledPackagesAsUser( |
| 4813 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4814 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4815 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4816 | } |
| 4817 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4818 | PackageInfo pkgInfo = packages.get(p); |
| 4819 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4820 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4821 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4822 | privilegedPackages.add(pkgInfo.packageName); |
| 4823 | } |
| 4824 | } |
| 4825 | } |
| 4826 | } |
| 4827 | return privilegedPackages; |
| 4828 | } |
| 4829 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4830 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4831 | final Phone phone = getPhone(subId); |
| 4832 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4833 | if (card == null) { |
| 4834 | loge("getIccId: No UICC"); |
| 4835 | return null; |
| 4836 | } |
| 4837 | String iccId = card.getIccId(); |
| 4838 | if (TextUtils.isEmpty(iccId)) { |
| 4839 | loge("getIccId: ICC ID is null or empty."); |
| 4840 | return null; |
| 4841 | } |
| 4842 | return iccId; |
| 4843 | } |
| 4844 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4845 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4846 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4847 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4848 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4849 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4850 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4851 | final long identity = Binder.clearCallingIdentity(); |
| 4852 | try { |
| 4853 | final String iccId = getIccId(subId); |
| 4854 | final Phone phone = getPhone(subId); |
| 4855 | if (phone == null) { |
| 4856 | return false; |
| 4857 | } |
| 4858 | final String subscriberId = phone.getSubscriberId(); |
| 4859 | |
| 4860 | if (DBG_MERGE) { |
| 4861 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4862 | + subscriberId + " to " + number); |
| 4863 | } |
| 4864 | |
| 4865 | if (TextUtils.isEmpty(iccId)) { |
| 4866 | return false; |
| 4867 | } |
| 4868 | |
| 4869 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4870 | |
| 4871 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4872 | if (alphaTag == null) { |
| 4873 | editor.remove(alphaTagPrefKey); |
| 4874 | } else { |
| 4875 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4876 | } |
| 4877 | |
| 4878 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4879 | // track all merged IMSIs based on line number |
| 4880 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4881 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4882 | if (number == null) { |
| 4883 | editor.remove(numberPrefKey); |
| 4884 | editor.remove(subscriberPrefKey); |
| 4885 | } else { |
| 4886 | editor.putString(numberPrefKey, number); |
| 4887 | editor.putString(subscriberPrefKey, subscriberId); |
| 4888 | } |
| 4889 | |
| 4890 | editor.commit(); |
| 4891 | return true; |
| 4892 | } finally { |
| 4893 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4894 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4898 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4899 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4900 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4901 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4902 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4903 | return null; |
| 4904 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4905 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4906 | final long identity = Binder.clearCallingIdentity(); |
| 4907 | try { |
| 4908 | String iccId = getIccId(subId); |
| 4909 | if (iccId != null) { |
| 4910 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4911 | if (DBG_MERGE) { |
| 4912 | log("getLine1NumberForDisplay returning " |
| 4913 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4914 | } |
| 4915 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4916 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4917 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4918 | return null; |
| 4919 | } finally { |
| 4920 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4921 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4925 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4926 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4927 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4928 | return null; |
| 4929 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4930 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4931 | final long identity = Binder.clearCallingIdentity(); |
| 4932 | try { |
| 4933 | String iccId = getIccId(subId); |
| 4934 | if (iccId != null) { |
| 4935 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4936 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4937 | } |
| 4938 | return null; |
| 4939 | } finally { |
| 4940 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4941 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4942 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4943 | |
| 4944 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4945 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4946 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4947 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4948 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4949 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4950 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4951 | return null; |
| 4952 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4953 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4954 | final long identity = Binder.clearCallingIdentity(); |
| 4955 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4956 | final Context context = mApp; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4957 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4958 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4959 | |
| 4960 | // Figure out what subscribers are currently active |
| 4961 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4962 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4963 | // the process, where TelephonyManager was instantiated. |
| 4964 | // Otherwise AppOps check will fail. |
| 4965 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4966 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4967 | for (int subId : subIds) { |
| 4968 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4969 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4970 | |
| 4971 | // First pass, find a number override for an active subscriber |
| 4972 | String mergeNumber = null; |
| 4973 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4974 | for (String key : prefs.keySet()) { |
| 4975 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4976 | final String subscriberId = (String) prefs.get(key); |
| 4977 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4978 | final String iccId = key.substring( |
| 4979 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4980 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4981 | mergeNumber = (String) prefs.get(numberKey); |
| 4982 | if (DBG_MERGE) { |
| 4983 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4984 | + " for active subscriber " + subscriberId); |
| 4985 | } |
| 4986 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4987 | break; |
| 4988 | } |
| 4989 | } |
| 4990 | } |
| 4991 | } |
| 4992 | |
| 4993 | // Shortcut when no active merged subscribers |
| 4994 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4995 | return null; |
| 4996 | } |
| 4997 | |
| 4998 | // Second pass, find all subscribers under that line override |
| 4999 | final ArraySet<String> result = new ArraySet<>(); |
| 5000 | for (String key : prefs.keySet()) { |
| 5001 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5002 | final String number = (String) prefs.get(key); |
| 5003 | if (mergeNumber.equals(number)) { |
| 5004 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5005 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5006 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5007 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5008 | result.add(subscriberId); |
| 5009 | } |
| 5010 | } |
| 5011 | } |
| 5012 | } |
| 5013 | |
| 5014 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5015 | Arrays.sort(resultArray); |
| 5016 | if (DBG_MERGE) { |
| 5017 | Slog.d(LOG_TAG, |
| 5018 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5019 | } |
| 5020 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5021 | } finally { |
| 5022 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5023 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5027 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5028 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5029 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5030 | |
| 5031 | final long identity = Binder.clearCallingIdentity(); |
| 5032 | try { |
| 5033 | final Phone phone = getPhone(subId); |
| 5034 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5035 | } finally { |
| 5036 | Binder.restoreCallingIdentity(identity); |
| 5037 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5038 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5039 | |
| 5040 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5041 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5042 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5043 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5044 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5045 | |
| 5046 | final long identity = Binder.clearCallingIdentity(); |
| 5047 | try { |
| 5048 | final Phone phone = getPhone(subId); |
| 5049 | if (phone == null) { |
| 5050 | return false; |
| 5051 | } |
| 5052 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5053 | cdmaNonRoamingList); |
| 5054 | } finally { |
| 5055 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5056 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5057 | } |
| 5058 | |
| 5059 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5060 | @Deprecated |
| 5061 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5062 | enforceModifyPermission(); |
| 5063 | |
| 5064 | int returnValue = 0; |
| 5065 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5066 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5067 | if(result.exception == null) { |
| 5068 | if (result.result != null) { |
| 5069 | byte[] responseData = (byte[])(result.result); |
| 5070 | if(responseData.length > oemResp.length) { |
| 5071 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5072 | responseData.length + "bytes. Buffer Size is " + |
| 5073 | oemResp.length + "bytes."); |
| 5074 | } |
| 5075 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5076 | returnValue = responseData.length; |
| 5077 | } |
| 5078 | } else { |
| 5079 | CommandException ex = (CommandException) result.exception; |
| 5080 | returnValue = ex.getCommandError().ordinal(); |
| 5081 | if(returnValue > 0) returnValue *= -1; |
| 5082 | } |
| 5083 | } catch (RuntimeException e) { |
| 5084 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5085 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5086 | if(returnValue > 0) returnValue *= -1; |
| 5087 | } |
| 5088 | |
| 5089 | return returnValue; |
| 5090 | } |
| 5091 | |
| 5092 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5093 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5094 | try { |
| 5095 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5096 | } catch (RuntimeException e) { |
| 5097 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5098 | } |
| 5099 | } |
| 5100 | |
| 5101 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5102 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5103 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5104 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5105 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5106 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5107 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5108 | final long identity = Binder.clearCallingIdentity(); |
| 5109 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5110 | TelephonyPermissions |
| 5111 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5112 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5113 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5114 | } finally { |
| 5115 | Binder.restoreCallingIdentity(identity); |
| 5116 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5117 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5118 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5119 | |
| 5120 | @Override |
| 5121 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5122 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5123 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5124 | |
| 5125 | final long identity = Binder.clearCallingIdentity(); |
| 5126 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5127 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5128 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5129 | } finally { |
| 5130 | Binder.restoreCallingIdentity(identity); |
| 5131 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5132 | } |
| 5133 | |
| 5134 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5135 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5136 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5137 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5138 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5139 | return false; |
| 5140 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5141 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5142 | final long identity = Binder.clearCallingIdentity(); |
| 5143 | try { |
| 5144 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5145 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5146 | // In the long run, we may instead need to check if there exists a connection service |
| 5147 | // which can support video calling. |
| 5148 | ImsManager imsManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5149 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5150 | return imsManager.isVtEnabledByPlatform() |
| 5151 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5152 | && imsManager.isVtEnabledByUser(); |
| 5153 | } finally { |
| 5154 | Binder.restoreCallingIdentity(identity); |
| 5155 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5156 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5157 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5158 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5159 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5160 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5161 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5162 | return false; |
| 5163 | } |
| 5164 | |
| 5165 | final long identity = Binder.clearCallingIdentity(); |
| 5166 | try { |
| 5167 | CarrierConfigManager configManager = |
| 5168 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5169 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5170 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5171 | } finally { |
| 5172 | Binder.restoreCallingIdentity(identity); |
| 5173 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5174 | } |
| 5175 | |
| 5176 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5177 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5178 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5179 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5180 | return false; |
| 5181 | } |
| 5182 | |
| 5183 | final long identity = Binder.clearCallingIdentity(); |
| 5184 | try { |
| 5185 | CarrierConfigManager configManager = |
| 5186 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5187 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5188 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5189 | } finally { |
| 5190 | Binder.restoreCallingIdentity(identity); |
| 5191 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5192 | } |
| 5193 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5194 | @Override |
| 5195 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5196 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5197 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5198 | } |
| 5199 | |
| 5200 | @Override |
| 5201 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5202 | final long identity = Binder.clearCallingIdentity(); |
| 5203 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5204 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5205 | } finally { |
| 5206 | Binder.restoreCallingIdentity(identity); |
| 5207 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5208 | } |
| 5209 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5210 | /** |
| 5211 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5212 | * support for the feature and device firmware support. |
| 5213 | * |
| 5214 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5215 | */ |
| 5216 | @Override |
| 5217 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5218 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5219 | final Phone phone = getPhone(subscriptionId); |
| 5220 | if (phone == null) { |
| 5221 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5222 | return false; |
| 5223 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5224 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5225 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5226 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5227 | boolean isDeviceSupported = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5228 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5229 | return isCarrierSupported && isDeviceSupported; |
| 5230 | } finally { |
| 5231 | Binder.restoreCallingIdentity(identity); |
| 5232 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5233 | } |
| 5234 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5235 | /** |
| 5236 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 5237 | * both also support RTT. |
| 5238 | */ |
| 5239 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5240 | final long identity = Binder.clearCallingIdentity(); |
| 5241 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5242 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5243 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5244 | } finally { |
| 5245 | Binder.restoreCallingIdentity(identity); |
| 5246 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5247 | } |
| 5248 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5249 | /** |
| 5250 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5251 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5252 | * |
| 5253 | * <p>Requires Permission: |
| 5254 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5255 | */ |
| 5256 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5257 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5258 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5259 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5260 | return null; |
| 5261 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5262 | int subId = phone.getSubId(); |
| 5263 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5264 | mApp, subId, callingPackage, "getDeviceId")) { |
| 5265 | return null; |
| 5266 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5267 | |
| 5268 | final long identity = Binder.clearCallingIdentity(); |
| 5269 | try { |
| 5270 | return phone.getDeviceId(); |
| 5271 | } finally { |
| 5272 | Binder.restoreCallingIdentity(identity); |
| 5273 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5274 | } |
| 5275 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5276 | /** |
| 5277 | * {@hide} |
| 5278 | * Returns the IMS Registration Status on a particular subid |
| 5279 | * |
| 5280 | * @param subId |
| 5281 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5282 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5283 | Phone phone = getPhone(subId); |
| 5284 | if (phone != null) { |
| 5285 | return phone.isImsRegistered(); |
| 5286 | } else { |
| 5287 | return false; |
| 5288 | } |
| 5289 | } |
| 5290 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5291 | @Override |
| 5292 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5293 | final long identity = Binder.clearCallingIdentity(); |
| 5294 | try { |
| 5295 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5296 | } finally { |
| 5297 | Binder.restoreCallingIdentity(identity); |
| 5298 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5299 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5300 | |
Tyler Gunn | 327a972 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5301 | @Override |
| 5302 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5303 | final long identity = Binder.clearCallingIdentity(); |
| 5304 | try { |
| 5305 | Phone phone = getPhone(subscriptionId); |
| 5306 | if (phone == null) { |
| 5307 | return null; |
| 5308 | } |
| 5309 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5310 | } finally { |
| 5311 | Binder.restoreCallingIdentity(identity); |
| 5312 | } |
| 5313 | } |
| 5314 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5315 | /** |
| 5316 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5317 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5318 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5319 | final long identity = Binder.clearCallingIdentity(); |
| 5320 | try { |
| 5321 | Phone phone = getPhone(subId); |
| 5322 | if (phone != null) { |
| 5323 | return phone.isWifiCallingEnabled(); |
| 5324 | } else { |
| 5325 | return false; |
| 5326 | } |
| 5327 | } finally { |
| 5328 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5329 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5330 | } |
| 5331 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5332 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5333 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5334 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5335 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5336 | final long identity = Binder.clearCallingIdentity(); |
| 5337 | try { |
| 5338 | Phone phone = getPhone(subId); |
| 5339 | if (phone != null) { |
| 5340 | return phone.isVideoEnabled(); |
| 5341 | } else { |
| 5342 | return false; |
| 5343 | } |
| 5344 | } finally { |
| 5345 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5346 | } |
| 5347 | } |
| 5348 | |
| 5349 | /** |
| 5350 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5351 | * defined in {@link ImsRegistrationImplBase}. |
| 5352 | */ |
| 5353 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5354 | final long identity = Binder.clearCallingIdentity(); |
| 5355 | try { |
| 5356 | Phone phone = getPhone(subId); |
| 5357 | if (phone != null) { |
| 5358 | return phone.getImsRegistrationTech(); |
| 5359 | } else { |
| 5360 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5361 | } |
| 5362 | } finally { |
| 5363 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5364 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5365 | } |
| 5366 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5367 | @Override |
| 5368 | public void factoryReset(int subId) { |
| 5369 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5370 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5371 | return; |
| 5372 | } |
| 5373 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5374 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5375 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5376 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5377 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5378 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5379 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5380 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5381 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5382 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5383 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5384 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5385 | // There has been issues when Sms raw table somehow stores orphan |
| 5386 | // fragments. They lead to garbled message when new fragments come |
| 5387 | // in and combined with those stale ones. In case this happens again, |
| 5388 | // user can reset all network settings which will clean up this table. |
| 5389 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5390 | } finally { |
| 5391 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5392 | } |
| 5393 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5394 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5395 | private void cleanUpSmsRawTable(Context context) { |
| 5396 | ContentResolver resolver = context.getContentResolver(); |
| 5397 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5398 | resolver.delete(uri, null, null); |
| 5399 | } |
| 5400 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5401 | @Override |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5402 | public String getSimLocaleForSubscriber(int subId) { |
| 5403 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5404 | final Phone phone = getPhone(subId); |
| 5405 | if (phone == null) { |
| 5406 | log("getSimLocaleForSubscriber, invalid subId"); |
Pengquan Meng | 9c29148 | 2019-01-28 16:26:29 -0800 | [diff] [blame] | 5407 | return null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5408 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5409 | final long identity = Binder.clearCallingIdentity(); |
| 5410 | try { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5411 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5412 | phone.getContext().getOpPackageName()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5413 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5414 | // preferences (EF-PL and EF-LI)... |
| 5415 | final int mcc = info.getMcc(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5416 | String simLanguage = null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5417 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5418 | if (localeFromDefaultSim != null) { |
| 5419 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5420 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5421 | + localeFromDefaultSim); |
| 5422 | return localeFromDefaultSim.toLanguageTag(); |
| 5423 | } else { |
| 5424 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5425 | } |
| 5426 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5427 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5428 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5429 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5430 | // the SIM and carrier preferences does not include a country we add the country |
| 5431 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5432 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5433 | if (mccLocale != null) { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5434 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5435 | return mccLocale.toLanguageTag(); |
| 5436 | } |
| 5437 | |
| 5438 | if (DBG) log("No locale found - returning null"); |
| 5439 | return null; |
| 5440 | } finally { |
| 5441 | Binder.restoreCallingIdentity(identity); |
| 5442 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5443 | } |
| 5444 | |
| 5445 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5446 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5447 | } |
| 5448 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5449 | /** |
| 5450 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5451 | */ |
| 5452 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5453 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5454 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5455 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5456 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5457 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5458 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5459 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5460 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5461 | * representing the state of the modem. |
| 5462 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5463 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5464 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5465 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5466 | */ |
| 5467 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5468 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5469 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5470 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5471 | |
| 5472 | final long identity = Binder.clearCallingIdentity(); |
| 5473 | try { |
| 5474 | ModemActivityInfo ret = null; |
| 5475 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5476 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5477 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 5478 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5479 | if (isModemActivityInfoValid(info)) { |
| 5480 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5481 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 5482 | mergedTxTimeMs[i] = |
| 5483 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 5484 | } |
| 5485 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 5486 | mLastModemActivityInfo.setSleepTimeMillis( |
| 5487 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 5488 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5489 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5490 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5491 | mLastModemActivityInfo.setRxTimeMillis( |
| 5492 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5493 | mLastModemActivityInfo.setEnergyUsed( |
| 5494 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5495 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5496 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5497 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5498 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5499 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5500 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5501 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5502 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5503 | Bundle bundle = new Bundle(); |
| 5504 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5505 | result.send(0, bundle); |
| 5506 | } finally { |
| 5507 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5508 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5509 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5510 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5511 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5512 | // less than total activity duration. |
| 5513 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5514 | if (info == null) { |
| 5515 | return false; |
| 5516 | } |
| 5517 | int activityDurationMs = |
| 5518 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5519 | int totalTxTimeMs = 0; |
| 5520 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5521 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5522 | } |
| 5523 | return (info.isValid() |
| 5524 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5525 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5526 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5527 | && (totalTxTimeMs <= activityDurationMs)); |
| 5528 | } |
| 5529 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5530 | /** |
| 5531 | * {@hide} |
| 5532 | * Returns the service state information on specified subscription. |
| 5533 | */ |
| 5534 | @Override |
| 5535 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5536 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5537 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5538 | return null; |
| 5539 | } |
| 5540 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5541 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5542 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5543 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5544 | .setCallingPackage(callingPackage) |
| 5545 | .setCallingPid(Binder.getCallingPid()) |
| 5546 | .setCallingUid(Binder.getCallingUid()) |
| 5547 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | 8b0cba2 | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5548 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5549 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5550 | .build()); |
| 5551 | |
| 5552 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5553 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5554 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5555 | .setCallingPackage(callingPackage) |
| 5556 | .setCallingPid(Binder.getCallingPid()) |
| 5557 | .setCallingUid(Binder.getCallingUid()) |
| 5558 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | 8b0cba2 | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5559 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5560 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5561 | .build()); |
| 5562 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5563 | boolean hasFinePermission = |
| 5564 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5565 | boolean hasCoarsePermission = |
| 5566 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5567 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5568 | final long identity = Binder.clearCallingIdentity(); |
| 5569 | try { |
| 5570 | final Phone phone = getPhone(subId); |
| 5571 | if (phone == null) { |
| 5572 | return null; |
| 5573 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5574 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5575 | ServiceState ss = phone.getServiceState(); |
| 5576 | |
| 5577 | // Scrub out the location info in ServiceState depending on what level of access |
| 5578 | // the caller has. |
| 5579 | if (hasFinePermission) return ss; |
| 5580 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5581 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5582 | } finally { |
| 5583 | Binder.restoreCallingIdentity(identity); |
| 5584 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5585 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5586 | |
| 5587 | /** |
| 5588 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5589 | * |
| 5590 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5591 | * voicemail ringtone. |
| 5592 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5593 | * PhoneAccount. |
| 5594 | */ |
| 5595 | @Override |
| 5596 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5597 | final long identity = Binder.clearCallingIdentity(); |
| 5598 | try { |
| 5599 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5600 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5601 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5602 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5603 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5604 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5605 | } finally { |
| 5606 | Binder.restoreCallingIdentity(identity); |
| 5607 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5608 | } |
| 5609 | |
| 5610 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5611 | * Sets the per-account voicemail ringtone. |
| 5612 | * |
| 5613 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5614 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5615 | * |
| 5616 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5617 | * voicemail ringtone. |
| 5618 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5619 | * PhoneAccount. |
| 5620 | */ |
| 5621 | @Override |
| 5622 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5623 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5624 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5625 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5626 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5627 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5628 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5629 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5630 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5631 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5632 | |
| 5633 | final long identity = Binder.clearCallingIdentity(); |
| 5634 | try { |
| 5635 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5636 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5637 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5638 | } |
| 5639 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5640 | } finally { |
| 5641 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5642 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5643 | } |
| 5644 | |
| 5645 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5646 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5647 | * |
| 5648 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5649 | * voicemail vibration setting. |
| 5650 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5651 | */ |
| 5652 | @Override |
| 5653 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5654 | final long identity = Binder.clearCallingIdentity(); |
| 5655 | try { |
| 5656 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5657 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5658 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5659 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5660 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5661 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5662 | } finally { |
| 5663 | Binder.restoreCallingIdentity(identity); |
| 5664 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5665 | } |
| 5666 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5667 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5668 | * Sets the per-account voicemail vibration. |
| 5669 | * |
| 5670 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5671 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5672 | * |
| 5673 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5674 | * voicemail vibration setting. |
| 5675 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5676 | * specific PhoneAccount. |
| 5677 | */ |
| 5678 | @Override |
| 5679 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5680 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5681 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5682 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5683 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5684 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5685 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5686 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5687 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5688 | } |
| 5689 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5690 | final long identity = Binder.clearCallingIdentity(); |
| 5691 | try { |
| 5692 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5693 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5694 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5695 | } |
| 5696 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5697 | } finally { |
| 5698 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5699 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5700 | } |
| 5701 | |
| 5702 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5703 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5704 | * |
| 5705 | * @throws SecurityException if the caller does not have the required permission |
| 5706 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5707 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5708 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5709 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5710 | } |
| 5711 | |
| 5712 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5713 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5714 | * permission. |
| 5715 | * |
| 5716 | * @throws SecurityException if the caller does not have the required permission |
| 5717 | */ |
| 5718 | private void enforceSendSmsPermission() { |
| 5719 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5720 | } |
| 5721 | |
| 5722 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5723 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5724 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5725 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5726 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5727 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5728 | final long identity = Binder.clearCallingIdentity(); |
| 5729 | try { |
| 5730 | ComponentName componentName = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5731 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5732 | if (componentName == null) { |
| 5733 | throw new SecurityException( |
| 5734 | "Caller not current active visual voicemail package[null]"); |
| 5735 | } |
| 5736 | String vvmPackage = componentName.getPackageName(); |
| 5737 | if (!callingPackage.equals(vvmPackage)) { |
| 5738 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5739 | + vvmPackage + "]"); |
| 5740 | } |
| 5741 | } finally { |
| 5742 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5743 | } |
| 5744 | } |
| 5745 | |
| 5746 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5747 | * Return the application ID for the app type. |
| 5748 | * |
| 5749 | * @param subId the subscription ID that this request applies to. |
| 5750 | * @param appType the uicc app type. |
| 5751 | * @return Application ID for specificied app type, or null if no uicc. |
| 5752 | */ |
| 5753 | @Override |
| 5754 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5755 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5756 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5757 | |
| 5758 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5759 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5760 | if (phone == null) { |
| 5761 | return null; |
| 5762 | } |
| 5763 | String aid = null; |
| 5764 | try { |
| 5765 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5766 | .getApplicationByType(appType).getAid(); |
| 5767 | } catch (Exception e) { |
| 5768 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5769 | } |
| 5770 | return aid; |
| 5771 | } finally { |
| 5772 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5773 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5774 | } |
| 5775 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5776 | /** |
| 5777 | * Return the Electronic Serial Number. |
| 5778 | * |
| 5779 | * @param subId the subscription ID that this request applies to. |
| 5780 | * @return ESN or null if error. |
| 5781 | */ |
| 5782 | @Override |
| 5783 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5784 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5785 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5786 | |
| 5787 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5788 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5789 | if (phone == null) { |
| 5790 | return null; |
| 5791 | } |
| 5792 | String esn = null; |
| 5793 | try { |
| 5794 | esn = phone.getEsn(); |
| 5795 | } catch (Exception e) { |
| 5796 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5797 | } |
| 5798 | return esn; |
| 5799 | } finally { |
| 5800 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5801 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5802 | } |
| 5803 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5804 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5805 | * Return the Preferred Roaming List Version. |
| 5806 | * |
| 5807 | * @param subId the subscription ID that this request applies to. |
| 5808 | * @return PRLVersion or null if error. |
| 5809 | */ |
| 5810 | @Override |
| 5811 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5812 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5813 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5814 | |
| 5815 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5816 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5817 | if (phone == null) { |
| 5818 | return null; |
| 5819 | } |
| 5820 | String cdmaPrlVersion = null; |
| 5821 | try { |
| 5822 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5823 | } catch (Exception e) { |
| 5824 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5825 | } |
| 5826 | return cdmaPrlVersion; |
| 5827 | } finally { |
| 5828 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5829 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5830 | } |
| 5831 | |
| 5832 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5833 | * Get snapshot of Telephony histograms |
| 5834 | * @return List of Telephony histograms |
| 5835 | * @hide |
| 5836 | */ |
| 5837 | @Override |
| 5838 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5839 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5840 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5841 | |
| 5842 | final long identity = Binder.clearCallingIdentity(); |
| 5843 | try { |
| 5844 | return RIL.getTelephonyRILTimingHistograms(); |
| 5845 | } finally { |
| 5846 | Binder.restoreCallingIdentity(identity); |
| 5847 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5848 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5849 | |
| 5850 | /** |
| 5851 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5852 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5853 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5854 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5855 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5856 | * @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] | 5857 | */ |
| 5858 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5859 | @TelephonyManager.SetCarrierRestrictionResult |
| 5860 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5861 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5862 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5863 | |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5864 | if (carrierRestrictionRules == null) { |
| 5865 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5866 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5867 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5868 | final long identity = Binder.clearCallingIdentity(); |
| 5869 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5870 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5871 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5872 | } finally { |
| 5873 | Binder.restoreCallingIdentity(identity); |
| 5874 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5875 | } |
| 5876 | |
| 5877 | /** |
| 5878 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5879 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5880 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5881 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5882 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5883 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5884 | */ |
| 5885 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5886 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5887 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5888 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5889 | |
| 5890 | final long identity = Binder.clearCallingIdentity(); |
| 5891 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5892 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5893 | if (response instanceof CarrierRestrictionRules) { |
| 5894 | return (CarrierRestrictionRules) response; |
| 5895 | } |
| 5896 | // Response is an Exception of some kind, |
| 5897 | // which is signalled to the user as a NULL retval |
| 5898 | return null; |
| 5899 | } catch (Exception e) { |
| 5900 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5901 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5902 | } finally { |
| 5903 | Binder.restoreCallingIdentity(identity); |
| 5904 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5905 | } |
| 5906 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5907 | /** |
| 5908 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5909 | * @param subId the subscription ID that this action applies to. |
| 5910 | * @param enabled control enable or disable metered apns. |
| 5911 | * {@hide} |
| 5912 | */ |
| 5913 | @Override |
| 5914 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5915 | enforceModifyPermission(); |
| 5916 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5917 | |
| 5918 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5919 | if (phone == null) { |
| 5920 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5921 | return; |
| 5922 | } |
| 5923 | try { |
| 5924 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5925 | } catch (Exception e) { |
| 5926 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5927 | } finally { |
| 5928 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5929 | } |
| 5930 | } |
| 5931 | |
| 5932 | /** |
| 5933 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5934 | * @param subId the subscription ID that this action applies to. |
| 5935 | * @param enabled control enable or disable radio. |
| 5936 | * {@hide} |
| 5937 | */ |
| 5938 | @Override |
| 5939 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5940 | enforceModifyPermission(); |
| 5941 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5942 | |
| 5943 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5944 | if (phone == null) { |
| 5945 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5946 | return; |
| 5947 | } |
| 5948 | try { |
| 5949 | phone.carrierActionSetRadioEnabled(enabled); |
| 5950 | } catch (Exception e) { |
| 5951 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5952 | } finally { |
| 5953 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5954 | } |
| 5955 | } |
| 5956 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5957 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5958 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5959 | * network status based on which carrier apps could apply actions accordingly, |
| 5960 | * enable/disable default url handler for example. |
| 5961 | * |
| 5962 | * @param subId the subscription ID that this action applies to. |
| 5963 | * @param report control start/stop reporting the default network status. |
| 5964 | * {@hide} |
| 5965 | */ |
| 5966 | @Override |
| 5967 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5968 | enforceModifyPermission(); |
| 5969 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5970 | |
| 5971 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5972 | if (phone == null) { |
| 5973 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5974 | return; |
| 5975 | } |
| 5976 | try { |
| 5977 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5978 | } catch (Exception e) { |
| 5979 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5980 | } finally { |
| 5981 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5982 | } |
| 5983 | } |
| 5984 | |
| 5985 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5986 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5987 | * bug report is being generated. |
| 5988 | */ |
| 5989 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5990 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5991 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5992 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5993 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5994 | + Binder.getCallingPid() |
| 5995 | + ", uid=" + Binder.getCallingUid() |
| 5996 | + "without permission " |
| 5997 | + android.Manifest.permission.DUMP); |
| 5998 | return; |
| 5999 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6000 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6001 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6002 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6003 | @Override |
| 6004 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6005 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6006 | throws RemoteException { |
| 6007 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 6008 | } |
| 6009 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6010 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6011 | * Get aggregated video call data usage since boot. |
| 6012 | * |
| 6013 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6014 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6015 | * {@hide} |
| 6016 | */ |
| 6017 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6018 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6019 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6020 | null); |
| 6021 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6022 | final long identity = Binder.clearCallingIdentity(); |
| 6023 | try { |
| 6024 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6025 | // records the delta with the corresponding network identity. |
| 6026 | // We just return the total video call data usage snapshot since boot. |
| 6027 | Phone phone = getPhone(subId); |
| 6028 | if (phone != null) { |
| 6029 | return phone.getVtDataUsage(perUidStats); |
| 6030 | } |
| 6031 | return null; |
| 6032 | } finally { |
| 6033 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6034 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6035 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6036 | |
| 6037 | /** |
| 6038 | * Policy control of data connection. Usually used when data limit is passed. |
| 6039 | * @param enabled True if enabling the data, otherwise disabling. |
| 6040 | * @param subId Subscription index |
| 6041 | * {@hide} |
| 6042 | */ |
| 6043 | @Override |
| 6044 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6045 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6046 | |
| 6047 | final long identity = Binder.clearCallingIdentity(); |
| 6048 | try { |
| 6049 | Phone phone = getPhone(subId); |
| 6050 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6051 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6052 | } |
| 6053 | } finally { |
| 6054 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6055 | } |
| 6056 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6057 | |
| 6058 | /** |
| 6059 | * Get Client request stats |
| 6060 | * @return List of Client Request Stats |
| 6061 | * @hide |
| 6062 | */ |
| 6063 | @Override |
| 6064 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6065 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6066 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6067 | return null; |
| 6068 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6069 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6070 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6071 | final long identity = Binder.clearCallingIdentity(); |
| 6072 | try { |
| 6073 | if (phone != null) { |
| 6074 | return phone.getClientRequestStats(); |
| 6075 | } |
| 6076 | |
| 6077 | return null; |
| 6078 | } finally { |
| 6079 | Binder.restoreCallingIdentity(identity); |
| 6080 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6081 | } |
| 6082 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6083 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6084 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6085 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6086 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6087 | |
| 6088 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6089 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6090 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6091 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6092 | * @param state State of SIM (power down, power up, pass through) |
| 6093 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6094 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6095 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6096 | * |
| 6097 | **/ |
| 6098 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6099 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6100 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6101 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6102 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6103 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6104 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6105 | final long identity = Binder.clearCallingIdentity(); |
| 6106 | try { |
| 6107 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6108 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6109 | } |
| 6110 | } finally { |
| 6111 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6112 | } |
| 6113 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6114 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6115 | private boolean isUssdApiAllowed(int subId) { |
| 6116 | CarrierConfigManager configManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6117 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6118 | if (configManager == null) { |
| 6119 | return false; |
| 6120 | } |
| 6121 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6122 | if (pb == null) { |
| 6123 | return false; |
| 6124 | } |
| 6125 | return pb.getBoolean( |
| 6126 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6127 | } |
| 6128 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6129 | /** |
| 6130 | * Check if phone is in emergency callback mode |
| 6131 | * @return true if phone is in emergency callback mode |
| 6132 | * @param subId sub id |
| 6133 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6134 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6135 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6136 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6137 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6138 | |
| 6139 | final long identity = Binder.clearCallingIdentity(); |
| 6140 | try { |
| 6141 | if (phone != null) { |
| 6142 | return phone.isInEcm(); |
| 6143 | } else { |
| 6144 | return false; |
| 6145 | } |
| 6146 | } finally { |
| 6147 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6148 | } |
| 6149 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6150 | |
| 6151 | /** |
| 6152 | * Get the current signal strength information for the given subscription. |
| 6153 | * Because this information is not updated when the device is in a low power state |
| 6154 | * it should not be relied-upon to be current. |
| 6155 | * @param subId Subscription index |
| 6156 | * @return the most recent cached signal strength info from the modem |
| 6157 | */ |
| 6158 | @Override |
| 6159 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6160 | final long identity = Binder.clearCallingIdentity(); |
| 6161 | try { |
| 6162 | Phone p = getPhone(subId); |
| 6163 | if (p == null) { |
| 6164 | return null; |
| 6165 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6166 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6167 | return p.getSignalStrength(); |
| 6168 | } finally { |
| 6169 | Binder.restoreCallingIdentity(identity); |
| 6170 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6171 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6172 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6173 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 6174 | * Get the current modem radio state for the given slot. |
| 6175 | * @param slotIndex slot index. |
| 6176 | * @param callingPackage the name of the package making the call. |
| 6177 | * @return the current radio power state from the modem |
| 6178 | */ |
| 6179 | @Override |
| 6180 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6181 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6182 | if (phone != null) { |
| 6183 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6184 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6185 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6186 | } |
| 6187 | |
| 6188 | final long identity = Binder.clearCallingIdentity(); |
| 6189 | try { |
| 6190 | return phone.getRadioPowerState(); |
| 6191 | } finally { |
| 6192 | Binder.restoreCallingIdentity(identity); |
| 6193 | } |
| 6194 | } |
| 6195 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6196 | } |
| 6197 | |
| 6198 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6199 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6200 | * |
| 6201 | * <p>Requires one of the following permissions: |
| 6202 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6203 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6204 | * privileges. |
| 6205 | * |
| 6206 | * @param subId subscription id |
| 6207 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6208 | * {@code false}. |
| 6209 | */ |
| 6210 | @Override |
| 6211 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6212 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6213 | null /* message */); |
| 6214 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6215 | boolean isEnabled = false; |
| 6216 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6217 | try { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6218 | Phone phone = getPhone(subId); |
| 6219 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6220 | } catch (Exception e) { |
| 6221 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6222 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6223 | } finally { |
| 6224 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6225 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6226 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6227 | } |
| 6228 | |
| 6229 | |
| 6230 | /** |
| 6231 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6232 | * |
| 6233 | * <p> Requires permission: |
| 6234 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6235 | * privileges. |
| 6236 | * |
| 6237 | * @param subId subscription id |
| 6238 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6239 | */ |
| 6240 | @Override |
| 6241 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6242 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6243 | mApp, subId, "setDataRoamingEnabled"); |
| 6244 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6245 | final long identity = Binder.clearCallingIdentity(); |
| 6246 | try { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6247 | Phone phone = getPhone(subId); |
| 6248 | if (phone != null) { |
| 6249 | phone.setDataRoamingEnabled(isEnabled); |
| 6250 | } |
| 6251 | } finally { |
| 6252 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6253 | } |
| 6254 | } |
| 6255 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6256 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6257 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6258 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6259 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6260 | |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6261 | boolean isAllowed = true; |
| 6262 | final long identity = Binder.clearCallingIdentity(); |
| 6263 | try { |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6264 | Phone phone = getPhone(subId); |
| 6265 | if (phone != null) { |
| 6266 | isAllowed = phone.isCspPlmnEnabled(); |
| 6267 | } |
| 6268 | } finally { |
| 6269 | Binder.restoreCallingIdentity(identity); |
| 6270 | } |
| 6271 | return isAllowed; |
| 6272 | } |
| 6273 | |
| 6274 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6275 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6276 | try { |
| 6277 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
| 6278 | } catch (SecurityException e) { |
| 6279 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6280 | // has carrier privileges on an active UICC |
| 6281 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6282 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6283 | throw new SecurityException("Caller does not have carrier privileges on any UICC"); |
| 6284 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6285 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6286 | |
| 6287 | final long identity = Binder.clearCallingIdentity(); |
| 6288 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6289 | UiccController uiccController = UiccController.getInstance(); |
| 6290 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
| 6291 | |
| 6292 | ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0); |
| 6293 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 6294 | // Remove private info if the caller doesn't have access |
| 6295 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6296 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6297 | UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex()); |
| 6298 | UiccProfile profile = card.getUiccProfile(); |
| 6299 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6300 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6301 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6302 | } else { |
| 6303 | filteredInfos.add(cardInfo); |
| 6304 | } |
| 6305 | } |
| 6306 | return filteredInfos; |
| 6307 | } |
| 6308 | return cardInfos; |
| 6309 | } catch (PackageManager.NameNotFoundException e) { |
| 6310 | // This should not happen since we pass the package info in from TelephonyManager |
| 6311 | throw new SecurityException("Invalid calling package."); |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6312 | } finally { |
| 6313 | Binder.restoreCallingIdentity(identity); |
| 6314 | } |
| 6315 | } |
| 6316 | |
| 6317 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6318 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6319 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6320 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6321 | final long identity = Binder.clearCallingIdentity(); |
| 6322 | try { |
| 6323 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6324 | if (slots == null) { |
| 6325 | Rlog.i(LOG_TAG, "slots is null."); |
| 6326 | return null; |
| 6327 | } |
| 6328 | |
| 6329 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6330 | for (int i = 0; i < slots.length; i++) { |
| 6331 | UiccSlot slot = slots[i]; |
| 6332 | if (slot == null) { |
| 6333 | continue; |
| 6334 | } |
| 6335 | |
| 6336 | String cardId; |
| 6337 | UiccCard card = slot.getUiccCard(); |
| 6338 | if (card != null) { |
| 6339 | cardId = card.getCardId(); |
| 6340 | } else { |
| 6341 | cardId = slot.getIccId(); |
| 6342 | } |
| 6343 | |
| 6344 | int cardState = 0; |
| 6345 | switch (slot.getCardState()) { |
| 6346 | case CARDSTATE_ABSENT: |
| 6347 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6348 | break; |
| 6349 | case CARDSTATE_PRESENT: |
| 6350 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6351 | break; |
| 6352 | case CARDSTATE_ERROR: |
| 6353 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6354 | break; |
| 6355 | case CARDSTATE_RESTRICTED: |
| 6356 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6357 | break; |
| 6358 | default: |
| 6359 | break; |
| 6360 | |
| 6361 | } |
| 6362 | |
| 6363 | infos[i] = new UiccSlotInfo( |
| 6364 | slot.isActive(), |
| 6365 | slot.isEuicc(), |
| 6366 | cardId, |
| 6367 | cardState, |
| 6368 | slot.getPhoneId(), |
Jordan Liu | ef65d87 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6369 | slot.isExtendedApduSupported(), |
| 6370 | slot.isRemovable()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6371 | } |
| 6372 | return infos; |
| 6373 | } finally { |
| 6374 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6375 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6376 | } |
| 6377 | |
| 6378 | @Override |
| 6379 | public boolean switchSlots(int[] physicalSlots) { |
| 6380 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6381 | |
| 6382 | final long identity = Binder.clearCallingIdentity(); |
| 6383 | try { |
| 6384 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6385 | } finally { |
| 6386 | Binder.restoreCallingIdentity(identity); |
| 6387 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6388 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6389 | |
| 6390 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6391 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6392 | final long identity = Binder.clearCallingIdentity(); |
| 6393 | try { |
| 6394 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6395 | } finally { |
| 6396 | Binder.restoreCallingIdentity(identity); |
| 6397 | } |
| 6398 | } |
| 6399 | |
| 6400 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6401 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6402 | enforceModifyPermission(); |
| 6403 | final Phone phone = getPhone(subId); |
| 6404 | if (phone == null) { |
| 6405 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6406 | return; |
| 6407 | } |
| 6408 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6409 | final long identity = Binder.clearCallingIdentity(); |
| 6410 | try { |
| 6411 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6412 | } finally { |
| 6413 | Binder.restoreCallingIdentity(identity); |
| 6414 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6415 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6416 | |
| 6417 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6418 | * A test API to reload the UICC profile. |
| 6419 | * |
| 6420 | * <p>Requires that the calling app has permission |
| 6421 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6422 | * @hide |
| 6423 | */ |
| 6424 | @Override |
| 6425 | public void refreshUiccProfile(int subId) { |
| 6426 | enforceModifyPermission(); |
| 6427 | |
| 6428 | final long identity = Binder.clearCallingIdentity(); |
| 6429 | try { |
| 6430 | Phone phone = getPhone(subId); |
| 6431 | if (phone == null) { |
| 6432 | return; |
| 6433 | } |
| 6434 | UiccCard uiccCard = phone.getUiccCard(); |
| 6435 | if (uiccCard == null) { |
| 6436 | return; |
| 6437 | } |
| 6438 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6439 | if (uiccProfile == null) { |
| 6440 | return; |
| 6441 | } |
| 6442 | uiccProfile.refresh(); |
| 6443 | } finally { |
| 6444 | Binder.restoreCallingIdentity(identity); |
| 6445 | } |
| 6446 | } |
| 6447 | |
| 6448 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6449 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6450 | */ |
| 6451 | private boolean getDefaultDataEnabled() { |
| 6452 | return "true".equalsIgnoreCase( |
| 6453 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6454 | } |
| 6455 | |
| 6456 | /** |
| 6457 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6458 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6459 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6460 | */ |
| 6461 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6462 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6463 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6464 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6465 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6466 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6467 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6468 | return isDataRoamingEnabled; |
| 6469 | } |
| 6470 | |
| 6471 | /** |
| 6472 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6473 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6474 | */ |
| 6475 | private int getDefaultNetworkType(int subId) { |
| 6476 | return Integer.parseInt( |
| 6477 | TelephonyManager.getTelephonyProperty( |
| 6478 | mSubscriptionController.getPhoneId(subId), |
| 6479 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6480 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6481 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6482 | |
| 6483 | @Override |
| 6484 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 6485 | gid1, String gid2, String plmn, String spn) { |
| 6486 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6487 | |
| 6488 | final long identity = Binder.clearCallingIdentity(); |
| 6489 | try { |
| 6490 | final Phone phone = getPhone(subId); |
| 6491 | if (phone == null) { |
| 6492 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6493 | return; |
| 6494 | } |
| 6495 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 6496 | } finally { |
| 6497 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6498 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6499 | } |
| 6500 | |
| 6501 | @Override |
| 6502 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6503 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6504 | |
| 6505 | final long identity = Binder.clearCallingIdentity(); |
| 6506 | try { |
| 6507 | final Phone phone = getPhone(subId); |
| 6508 | if (phone == null) { |
| 6509 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6510 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6511 | } |
| 6512 | return phone.getCarrierIdListVersion(); |
| 6513 | } finally { |
| 6514 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6515 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6516 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6517 | |
| 6518 | @Override |
| 6519 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6520 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6521 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6522 | return -1; |
| 6523 | } |
| 6524 | |
| 6525 | final long identity = Binder.clearCallingIdentity(); |
| 6526 | try { |
| 6527 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6528 | } finally { |
| 6529 | Binder.restoreCallingIdentity(identity); |
| 6530 | } |
| 6531 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6532 | |
| 6533 | @Override |
| 6534 | public int getCdmaRoamingMode(int subId) { |
| 6535 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6536 | mApp, subId, "getCdmaRoamingMode"); |
| 6537 | |
| 6538 | final long identity = Binder.clearCallingIdentity(); |
| 6539 | try { |
| 6540 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6541 | } finally { |
| 6542 | Binder.restoreCallingIdentity(identity); |
| 6543 | } |
| 6544 | } |
| 6545 | |
| 6546 | @Override |
| 6547 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6548 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6549 | mApp, subId, "setCdmaRoamingMode"); |
| 6550 | |
| 6551 | final long identity = Binder.clearCallingIdentity(); |
| 6552 | try { |
| 6553 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6554 | } finally { |
| 6555 | Binder.restoreCallingIdentity(identity); |
| 6556 | } |
| 6557 | } |
| 6558 | |
| 6559 | @Override |
| 6560 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6561 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6562 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6563 | |
| 6564 | final long identity = Binder.clearCallingIdentity(); |
| 6565 | try { |
| 6566 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6567 | } finally { |
| 6568 | Binder.restoreCallingIdentity(identity); |
| 6569 | } |
| 6570 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6571 | |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 6572 | private void ensureUserRunning(int userId) { |
| 6573 | if (!mUserManager.isUserRunning(userId)) { |
| 6574 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6575 | } |
| 6576 | } |
| 6577 | |
| 6578 | /** |
| 6579 | * Returns a list of SMS apps on a given user. |
| 6580 | * |
| 6581 | * Only the shell user (UID 2000 or 0) can call it. |
| 6582 | * Target user must be running. |
| 6583 | */ |
| 6584 | @Override |
| 6585 | public String[] getSmsApps(int userId) { |
| 6586 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6587 | ensureUserRunning(userId); |
| 6588 | |
| 6589 | final Collection<SmsApplicationData> apps = |
| 6590 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6591 | |
| 6592 | String[] ret = new String[apps.size()]; |
| 6593 | int i = 0; |
| 6594 | for (SmsApplicationData app : apps) { |
| 6595 | ret[i++] = app.mPackageName; |
| 6596 | } |
| 6597 | return ret; |
| 6598 | } |
| 6599 | |
| 6600 | /** |
| 6601 | * Returns the default SMS app package name on a given user. |
| 6602 | * |
| 6603 | * Only the shell user (UID 2000 or 0) can call it. |
| 6604 | * Target user must be running. |
| 6605 | */ |
| 6606 | @Override |
| 6607 | public String getDefaultSmsApp(int userId) { |
| 6608 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6609 | ensureUserRunning(userId); |
| 6610 | |
| 6611 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6612 | /* updateIfNeeded= */ true, userId); |
| 6613 | return cn == null ? null : cn.getPackageName(); |
| 6614 | } |
| 6615 | |
| 6616 | /** |
| 6617 | * Set a package as the default SMS app on a given user. |
| 6618 | * |
| 6619 | * Only the shell user (UID 2000 or 0) can call it. |
| 6620 | * Target user must be running. |
| 6621 | */ |
| 6622 | @Override |
| 6623 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6624 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6625 | ensureUserRunning(userId); |
| 6626 | |
| 6627 | boolean found = false; |
| 6628 | for (String pkg : getSmsApps(userId)) { |
| 6629 | if (TextUtils.equals(packageName, pkg)) { |
| 6630 | found = true; |
| 6631 | break; |
| 6632 | } |
| 6633 | } |
| 6634 | if (!found) { |
| 6635 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6636 | } |
| 6637 | |
| 6638 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6639 | } |
| 6640 | |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6641 | @Override |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6642 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6643 | String callingPackage) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6644 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6645 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6646 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6647 | } |
| 6648 | final long identity = Binder.clearCallingIdentity(); |
| 6649 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6650 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6651 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6652 | if (phone.getEmergencyNumberTracker() != null |
| 6653 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6654 | emergencyNumberListInternal.put( |
| 6655 | phone.getSubId(), |
| 6656 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6657 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6658 | } |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6659 | return emergencyNumberListInternal; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6660 | } finally { |
| 6661 | Binder.restoreCallingIdentity(identity); |
| 6662 | } |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6663 | } |
| 6664 | |
| 6665 | @Override |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6666 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6667 | final Phone defaultPhone = getDefaultPhone(); |
| 6668 | if (!exactMatch) { |
| 6669 | TelephonyPermissions |
| 6670 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6671 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6672 | } |
| 6673 | final long identity = Binder.clearCallingIdentity(); |
| 6674 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6675 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6676 | if (phone.getEmergencyNumberTracker() != null |
| 6677 | && phone.getEmergencyNumberTracker() != null) { |
| 6678 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6679 | number, exactMatch)) { |
| 6680 | return true; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6681 | } |
| 6682 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6683 | } |
| 6684 | return false; |
| 6685 | } finally { |
| 6686 | Binder.restoreCallingIdentity(identity); |
| 6687 | } |
| 6688 | } |
| 6689 | |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6690 | /** |
| 6691 | * Update emergency number list for test mode. |
| 6692 | */ |
| 6693 | @Override |
| 6694 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6695 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6696 | "updateEmergencyNumberListTestMode"); |
| 6697 | |
| 6698 | final long identity = Binder.clearCallingIdentity(); |
| 6699 | try { |
| 6700 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6701 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6702 | if (tracker != null) { |
| 6703 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6704 | } |
| 6705 | } |
| 6706 | } finally { |
| 6707 | Binder.restoreCallingIdentity(identity); |
| 6708 | } |
| 6709 | } |
| 6710 | |
| 6711 | /** |
| 6712 | * Get the full emergency number list for test mode. |
| 6713 | */ |
| 6714 | @Override |
| 6715 | public List<String> getEmergencyNumberListTestMode() { |
| 6716 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6717 | "getEmergencyNumberListTestMode"); |
| 6718 | |
| 6719 | final long identity = Binder.clearCallingIdentity(); |
| 6720 | try { |
| 6721 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6722 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6723 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6724 | if (tracker != null) { |
| 6725 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6726 | emergencyNumbers.add(num.getNumber()); |
| 6727 | } |
| 6728 | } |
| 6729 | } |
| 6730 | return new ArrayList<>(emergencyNumbers); |
| 6731 | } finally { |
| 6732 | Binder.restoreCallingIdentity(identity); |
| 6733 | } |
| 6734 | } |
| 6735 | |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6736 | @Override |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6737 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6738 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6739 | Phone phone = getPhone(subId); |
| 6740 | if (phone == null) { |
| 6741 | return null; |
| 6742 | } |
| 6743 | final long identity = Binder.clearCallingIdentity(); |
| 6744 | try { |
| 6745 | UiccProfile profile = UiccController.getInstance() |
| 6746 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6747 | if (profile != null) { |
| 6748 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6749 | } |
| 6750 | } finally { |
| 6751 | Binder.restoreCallingIdentity(identity); |
| 6752 | } |
| 6753 | return null; |
| 6754 | } |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6755 | |
| 6756 | /** |
| 6757 | * Enable or disable a modem stack. |
| 6758 | */ |
| 6759 | @Override |
| 6760 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6761 | enforceModifyPermission(); |
| 6762 | |
| 6763 | final long identity = Binder.clearCallingIdentity(); |
| 6764 | try { |
| 6765 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6766 | if (phone == null) { |
| 6767 | return false; |
| 6768 | } else { |
| 6769 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6770 | } |
| 6771 | } finally { |
| 6772 | Binder.restoreCallingIdentity(identity); |
| 6773 | } |
| 6774 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6775 | |
Malcolm Chen | 33f55e1 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6776 | /** |
| 6777 | * Whether a modem stack is enabled or not. |
| 6778 | */ |
| 6779 | @Override |
| 6780 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 6781 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6782 | if (phone == null) return false; |
| 6783 | |
| 6784 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6785 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 6786 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6787 | } |
| 6788 | |
| 6789 | final long identity = Binder.clearCallingIdentity(); |
| 6790 | try { |
| 6791 | return PhoneConfigurationManager.getInstance().getPhoneStatus(phone); |
| 6792 | } finally { |
| 6793 | Binder.restoreCallingIdentity(identity); |
| 6794 | } |
| 6795 | } |
| 6796 | |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6797 | @Override |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6798 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6799 | enforceModifyPermission(); |
| 6800 | |
| 6801 | final long identity = Binder.clearCallingIdentity(); |
| 6802 | try { |
| 6803 | mTelephonySharedPreferences.edit() |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6804 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6805 | .commit(); |
| 6806 | } finally { |
| 6807 | Binder.restoreCallingIdentity(identity); |
| 6808 | } |
| 6809 | } |
| 6810 | |
| 6811 | @Override |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6812 | @TelephonyManager.IsMultiSimSupportedResult |
| 6813 | public int isMultiSimSupported(String callingPackage) { |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6814 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6815 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 6816 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6817 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6818 | |
| 6819 | final long identity = Binder.clearCallingIdentity(); |
| 6820 | try { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6821 | return isMultiSimSupportedInternal(); |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6822 | } finally { |
| 6823 | Binder.restoreCallingIdentity(identity); |
| 6824 | } |
| 6825 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6826 | |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6827 | @TelephonyManager.IsMultiSimSupportedResult |
| 6828 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6829 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6830 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6831 | if (numPhysicalSlots < 2) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6832 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 6833 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6834 | } |
| 6835 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 6836 | // supported by the modem, indicate that it is restricted. |
| 6837 | PhoneCapability staticCapability = |
| 6838 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 6839 | if (staticCapability == null) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6840 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 6841 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6842 | } |
| 6843 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6844 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 6845 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6846 | } |
| 6847 | // Check if support of multiple SIMs is restricted by carrier |
| 6848 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6849 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6850 | } |
| 6851 | |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6852 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6853 | } |
| 6854 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6855 | /** |
| 6856 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6857 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 6858 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 6859 | * or carrier privileges |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6860 | * @param numOfSims number of active sims we want to switch to |
| 6861 | */ |
| 6862 | @Override |
| 6863 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6864 | if (numOfSims == 1) { |
| 6865 | enforceModifyPermission(); |
| 6866 | } else { |
| 6867 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6868 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6869 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6870 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6871 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6872 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6873 | //only proceed if multi-sim is not restricted |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6874 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6875 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 6876 | return; |
| 6877 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6878 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 6879 | } finally { |
| 6880 | Binder.restoreCallingIdentity(identity); |
| 6881 | } |
| 6882 | } |
| 6883 | |
| 6884 | /** |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6885 | * 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] | 6886 | * Return value defaults to true |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6887 | */ |
| 6888 | @Override |
| 6889 | public boolean isRebootRequiredForModemConfigChange() { |
| 6890 | enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange"); |
| 6891 | final long identity = Binder.clearCallingIdentity(); |
| 6892 | try { |
| 6893 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 6894 | } finally { |
| 6895 | Binder.restoreCallingIdentity(identity); |
| 6896 | } |
| 6897 | } |
| 6898 | |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 6899 | private void updateModemStateMetrics() { |
| 6900 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 6901 | // TODO: check the state for each modem if the api is ready. |
| 6902 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 6903 | } |
| 6904 | |
Pengquan Meng | 3aceaec | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 6905 | @Override |
| 6906 | public int[] getSlotsMapping() { |
| 6907 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 6908 | |
| 6909 | final long identity = Binder.clearCallingIdentity(); |
| 6910 | try { |
| 6911 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 6912 | // All logical slots should have a mapping to a physical slot. |
| 6913 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 6914 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 6915 | for (int i = 0; i < slotInfos.length; i++) { |
| 6916 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 6917 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 6918 | } |
| 6919 | } |
| 6920 | return logicalSlotsMapping; |
| 6921 | } finally { |
| 6922 | Binder.restoreCallingIdentity(identity); |
| 6923 | } |
| 6924 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 6925 | |
| 6926 | /** |
| 6927 | * Get the IRadio HAL Version |
| 6928 | */ |
| 6929 | @Override |
| 6930 | public int getRadioHalVersion() { |
| 6931 | Phone phone = getDefaultPhone(); |
| 6932 | if (phone == null) return -1; |
| 6933 | HalVersion hv = phone.getHalVersion(); |
| 6934 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 6935 | return hv.major * 100 + hv.minor; |
| 6936 | } |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 6937 | |
| 6938 | /** |
Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame^] | 6939 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 6940 | * corresponding network requests on a subId. |
| 6941 | * |
| 6942 | * Data is enabled if: |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 6943 | * 1) user data is turned on, or |
Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame^] | 6944 | * 2) APN is un-metered for this subscription, or |
| 6945 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 6946 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 6947 | * |
| 6948 | * @return whether data is allowed for a apn type. |
| 6949 | * |
| 6950 | * @hide |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 6951 | */ |
| 6952 | @Override |
Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame^] | 6953 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 6954 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame^] | 6955 | mApp, subId, callingPackage, "isDataEnabledForApn")) { |
| 6956 | throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn"); |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 6957 | } |
| 6958 | |
| 6959 | // Now that all security checks passes, perform the operation as ourselves. |
| 6960 | final long identity = Binder.clearCallingIdentity(); |
| 6961 | try { |
| 6962 | Phone phone = getPhone(subId); |
| 6963 | if (phone == null) return false; |
| 6964 | |
| 6965 | boolean isMetered = ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString( |
Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame^] | 6966 | apnType), phone); |
| 6967 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 6968 | } finally { |
| 6969 | Binder.restoreCallingIdentity(identity); |
| 6970 | } |
| 6971 | } |
| 6972 | |
| 6973 | @Override |
| 6974 | public boolean isApnMetered(int apnType, int subId) { |
| 6975 | enforceReadPrivilegedPermission("isApnMetered"); |
| 6976 | |
| 6977 | // Now that all security checks passes, perform the operation as ourselves. |
| 6978 | final long identity = Binder.clearCallingIdentity(); |
| 6979 | try { |
| 6980 | Phone phone = getPhone(subId); |
| 6981 | if (phone == null) return true; // By default return true. |
| 6982 | |
| 6983 | return ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString( |
| 6984 | apnType), phone); |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 6985 | } finally { |
| 6986 | Binder.restoreCallingIdentity(identity); |
| 6987 | } |
| 6988 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6989 | } |