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 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 25 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 26 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 27 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 28 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 29 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 32 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 33 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 34 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 35 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 37 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 48 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 49 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 50 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 51 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 53 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 54 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 55 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 57 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 59 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 61 | import android.provider.Telephony; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 62 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 64 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 65 | import android.telephony.Annotation.ApnType; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 66 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 67 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 68 | import android.telephony.CellIdentity; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 69 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 70 | import android.telephony.CellInfoGsm; |
| 71 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 72 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 73 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 74 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 75 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 76 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 77 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 78 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 79 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 80 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 81 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 82 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 83 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 84 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 85 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 86 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 87 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 88 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 89 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 90 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 91 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 92 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 93 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 94 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 95 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 96 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 97 | import android.telephony.data.ApnSetting; |
| 98 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 99 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 100 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 101 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 102 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 103 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 106 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 107 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 108 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 109 | import android.telephony.ims.feature.MmTelFeature; |
| 110 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 111 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 112 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 113 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 114 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 115 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 116 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 117 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 118 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 119 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 129 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 133 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 154 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.uicc.IccIoResult; |
| 158 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 166 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 167 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 168 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 169 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 170 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 171 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 172 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 173 | import java.io.FileDescriptor; |
| 174 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 175 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 176 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 177 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 178 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 179 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 180 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 181 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 182 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 183 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 184 | |
| 185 | /** |
| 186 | * Implementation of the ITelephony interface. |
| 187 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 188 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 189 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 190 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 191 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 192 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 193 | |
| 194 | // Message codes used with mMainThreadHandler |
| 195 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 196 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 197 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 198 | private static final int CMD_OPEN_CHANNEL = 9; |
| 199 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 200 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 201 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 202 | private static final int CMD_NV_READ_ITEM = 13; |
| 203 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 204 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 205 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 206 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 207 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 208 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 209 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 210 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 211 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 212 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 213 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 214 | private static final int CMD_SEND_ENVELOPE = 25; |
| 215 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 216 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 217 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 218 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 219 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 220 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 221 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 222 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 223 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 224 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 225 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 226 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 227 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 228 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 229 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 230 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 231 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 232 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 233 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 234 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 235 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 236 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 237 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 238 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 239 | private static final int CMD_SWITCH_SLOTS = 50; |
| 240 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 241 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 242 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 243 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 244 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 245 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 246 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 247 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 248 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 249 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 250 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 251 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 252 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 253 | private static final int CMD_MODEM_REBOOT = 64; |
| 254 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 255 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 256 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 257 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 258 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 259 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 260 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 261 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 262 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 263 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 264 | // Parameters of select command. |
| 265 | private static final int SELECT_COMMAND = 0xA4; |
| 266 | private static final int SELECT_P1 = 0x04; |
| 267 | private static final int SELECT_P2 = 0; |
| 268 | private static final int SELECT_P3 = 0x10; |
| 269 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 270 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 271 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 272 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 273 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 274 | /** The singleton instance. */ |
| 275 | private static PhoneInterfaceManager sInstance; |
| 276 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 277 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 278 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 279 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 280 | private AppOpsManager mAppOps; |
| 281 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 282 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 283 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 284 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 285 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 286 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 287 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 288 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 289 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 290 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 291 | // String to store multi SIM allowed |
| 292 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 293 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 294 | // The AID of ISD-R. |
| 295 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 296 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 297 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 298 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 299 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 300 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 301 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 302 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 303 | * A request object to use for transmitting data to an ICC. |
| 304 | */ |
| 305 | private static final class IccAPDUArgument { |
| 306 | public int channel, cla, command, p1, p2, p3; |
| 307 | public String data; |
| 308 | |
| 309 | public IccAPDUArgument(int channel, int cla, int command, |
| 310 | int p1, int p2, int p3, String data) { |
| 311 | this.channel = channel; |
| 312 | this.cla = cla; |
| 313 | this.command = command; |
| 314 | this.p1 = p1; |
| 315 | this.p2 = p2; |
| 316 | this.p3 = p3; |
| 317 | this.data = data; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 322 | * A request object to use for transmitting data to an ICC. |
| 323 | */ |
| 324 | private static final class ManualNetworkSelectionArgument { |
| 325 | public OperatorInfo operatorInfo; |
| 326 | public boolean persistSelection; |
| 327 | |
| 328 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 329 | this.operatorInfo = operatorInfo; |
| 330 | this.persistSelection = persistSelection; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 335 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 336 | * request after sending. The main thread will notify the request when it is complete. |
| 337 | */ |
| 338 | private static final class MainThreadRequest { |
| 339 | /** The argument to use for the request */ |
| 340 | public Object argument; |
| 341 | /** The result of the request that is run on the main thread */ |
| 342 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 343 | // The subscriber id that this request applies to. Defaults to |
| 344 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 345 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 346 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 347 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 348 | public Phone phone; |
| 349 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 350 | public WorkSource workSource; |
| 351 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 352 | public MainThreadRequest(Object argument) { |
| 353 | this.argument = argument; |
| 354 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 355 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 356 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 357 | this.argument = argument; |
| 358 | if (phone != null) { |
| 359 | this.phone = phone; |
| 360 | } |
| 361 | this.workSource = workSource; |
| 362 | } |
| 363 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 364 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 365 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 366 | if (subId != null) { |
| 367 | this.subId = subId; |
| 368 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 369 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 370 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 373 | private static final class IncomingThirdPartyCallArgs { |
| 374 | public final ComponentName component; |
| 375 | public final String callId; |
| 376 | public final String callerDisplayName; |
| 377 | |
| 378 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 379 | String callerDisplayName) { |
| 380 | this.component = component; |
| 381 | this.callId = callId; |
| 382 | this.callerDisplayName = callerDisplayName; |
| 383 | } |
| 384 | } |
| 385 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 386 | /** |
| 387 | * A handler that processes messages on the main thread in the phone process. Since many |
| 388 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 389 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 390 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 391 | * on, which will be notified when the operation completes and will contain the result of the |
| 392 | * request. |
| 393 | * |
| 394 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 395 | * note that request.result must be set to something non-null for the calling thread to |
| 396 | * unblock. |
| 397 | */ |
| 398 | private final class MainThreadHandler extends Handler { |
| 399 | @Override |
| 400 | public void handleMessage(Message msg) { |
| 401 | MainThreadRequest request; |
| 402 | Message onCompleted; |
| 403 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 404 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 405 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 406 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 407 | |
| 408 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 409 | case CMD_HANDLE_USSD_REQUEST: { |
| 410 | request = (MainThreadRequest) msg.obj; |
| 411 | final Phone phone = getPhoneFromRequest(request); |
| 412 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 413 | String ussdRequest = ussdObject.first; |
| 414 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 415 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 416 | if (!isUssdApiAllowed(request.subId)) { |
| 417 | // Carrier does not support use of this API, return failure. |
| 418 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 419 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 420 | Bundle returnData = new Bundle(); |
| 421 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 422 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 423 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 424 | request.result = true; |
| 425 | notifyRequester(request); |
| 426 | return; |
| 427 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 428 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 429 | try { |
| 430 | request.result = phone != null |
| 431 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 432 | } catch (CallStateException cse) { |
| 433 | request.result = false; |
| 434 | } |
| 435 | // Wake up the requesting thread |
| 436 | notifyRequester(request); |
| 437 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 440 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 441 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 442 | final Phone phone = getPhoneFromRequest(request); |
| 443 | request.result = phone != null ? |
| 444 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 445 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 446 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 447 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 448 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 449 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 450 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 451 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 452 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 453 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 454 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 455 | if (uiccCard == null) { |
| 456 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 457 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 458 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 459 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 460 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 461 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 462 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 463 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 464 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 465 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 466 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 467 | break; |
| 468 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 469 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 470 | ar = (AsyncResult) msg.obj; |
| 471 | request = (MainThreadRequest) ar.userObj; |
| 472 | if (ar.exception == null && ar.result != null) { |
| 473 | request.result = ar.result; |
| 474 | } else { |
| 475 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 476 | if (ar.result == null) { |
| 477 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 478 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 479 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 480 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 481 | } else { |
| 482 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 483 | } |
| 484 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 485 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 486 | break; |
| 487 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 488 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 489 | request = (MainThreadRequest) msg.obj; |
| 490 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 491 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 492 | if (uiccCard == null) { |
| 493 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 494 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 495 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 496 | } else { |
| 497 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 498 | request); |
| 499 | uiccCard.iccTransmitApduBasicChannel( |
| 500 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 501 | iccArgument.p3, iccArgument.data, onCompleted); |
| 502 | } |
| 503 | break; |
| 504 | |
| 505 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 506 | ar = (AsyncResult) msg.obj; |
| 507 | request = (MainThreadRequest) ar.userObj; |
| 508 | if (ar.exception == null && ar.result != null) { |
| 509 | request.result = ar.result; |
| 510 | } else { |
| 511 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 512 | if (ar.result == null) { |
| 513 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 514 | } else if (ar.exception instanceof CommandException) { |
| 515 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 516 | ar.exception); |
| 517 | } else { |
| 518 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 519 | } |
| 520 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 521 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 522 | break; |
| 523 | |
| 524 | case CMD_EXCHANGE_SIM_IO: |
| 525 | request = (MainThreadRequest) msg.obj; |
| 526 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 527 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 528 | if (uiccCard == null) { |
| 529 | loge("iccExchangeSimIO: No UICC"); |
| 530 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 531 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | } else { |
| 533 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 534 | request); |
| 535 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 536 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 537 | iccArgument.data, onCompleted); |
| 538 | } |
| 539 | break; |
| 540 | |
| 541 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 542 | ar = (AsyncResult) msg.obj; |
| 543 | request = (MainThreadRequest) ar.userObj; |
| 544 | if (ar.exception == null && ar.result != null) { |
| 545 | request.result = ar.result; |
| 546 | } else { |
| 547 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 548 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 549 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 550 | break; |
| 551 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 552 | case CMD_SEND_ENVELOPE: |
| 553 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 554 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 555 | if (uiccCard == null) { |
| 556 | loge("sendEnvelopeWithStatus: No UICC"); |
| 557 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 558 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 559 | } else { |
| 560 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 561 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 562 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 563 | break; |
| 564 | |
| 565 | case EVENT_SEND_ENVELOPE_DONE: |
| 566 | ar = (AsyncResult) msg.obj; |
| 567 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 568 | if (ar.exception == null && ar.result != null) { |
| 569 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 570 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 571 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 572 | if (ar.result == null) { |
| 573 | loge("sendEnvelopeWithStatus: Empty response"); |
| 574 | } else if (ar.exception instanceof CommandException) { |
| 575 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 576 | ar.exception); |
| 577 | } else { |
| 578 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 579 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 580 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 581 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 582 | break; |
| 583 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 584 | case CMD_OPEN_CHANNEL: |
| 585 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 586 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 587 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 588 | if (uiccCard == null) { |
| 589 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 590 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 591 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 592 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 593 | } else { |
| 594 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 595 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 596 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 597 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 598 | break; |
| 599 | |
| 600 | case EVENT_OPEN_CHANNEL_DONE: |
| 601 | ar = (AsyncResult) msg.obj; |
| 602 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 603 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 604 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 605 | int[] result = (int[]) ar.result; |
| 606 | int channelId = result[0]; |
| 607 | byte[] selectResponse = null; |
| 608 | if (result.length > 1) { |
| 609 | selectResponse = new byte[result.length - 1]; |
| 610 | for (int i = 1; i < result.length; ++i) { |
| 611 | selectResponse[i - 1] = (byte) result[i]; |
| 612 | } |
| 613 | } |
| 614 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 615 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 616 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 617 | if (ar.result == null) { |
| 618 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 619 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 620 | if (ar.exception != null) { |
| 621 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 622 | } |
| 623 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 624 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 625 | if (ar.exception instanceof CommandException) { |
| 626 | CommandException.Error error = |
| 627 | ((CommandException) (ar.exception)).getCommandError(); |
| 628 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 629 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 630 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 631 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 635 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 637 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 638 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 639 | break; |
| 640 | |
| 641 | case CMD_CLOSE_CHANNEL: |
| 642 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 643 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 644 | if (uiccCard == null) { |
| 645 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 646 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 647 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 648 | } else { |
| 649 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 650 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 651 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 652 | break; |
| 653 | |
| 654 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 655 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 656 | break; |
| 657 | |
| 658 | case CMD_NV_READ_ITEM: |
| 659 | request = (MainThreadRequest) msg.obj; |
| 660 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 661 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 662 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 663 | break; |
| 664 | |
| 665 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 666 | ar = (AsyncResult) msg.obj; |
| 667 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 668 | if (ar.exception == null && ar.result != null) { |
| 669 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 670 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 671 | request.result = ""; |
| 672 | if (ar.result == null) { |
| 673 | loge("nvReadItem: Empty response"); |
| 674 | } else if (ar.exception instanceof CommandException) { |
| 675 | loge("nvReadItem: CommandException: " + |
| 676 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 677 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 678 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | } |
| 680 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 681 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | break; |
| 683 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 684 | case CMD_NV_WRITE_ITEM: |
| 685 | request = (MainThreadRequest) msg.obj; |
| 686 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 687 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 688 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 689 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 690 | break; |
| 691 | |
| 692 | case EVENT_NV_WRITE_ITEM_DONE: |
| 693 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 694 | break; |
| 695 | |
| 696 | case CMD_NV_WRITE_CDMA_PRL: |
| 697 | request = (MainThreadRequest) msg.obj; |
| 698 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 699 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 700 | break; |
| 701 | |
| 702 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 703 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 704 | break; |
| 705 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 706 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 707 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 708 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 709 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 710 | break; |
| 711 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 712 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 713 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | break; |
| 715 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 716 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 717 | request = (MainThreadRequest) msg.obj; |
| 718 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 719 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 720 | break; |
| 721 | |
| 722 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 723 | ar = (AsyncResult) msg.obj; |
| 724 | request = (MainThreadRequest) ar.userObj; |
| 725 | if (ar.exception == null && ar.result != null) { |
| 726 | request.result = ar.result; // Integer |
| 727 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 728 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 729 | if (ar.result == null) { |
| 730 | loge("getPreferredNetworkType: Empty response"); |
| 731 | } else if (ar.exception instanceof CommandException) { |
| 732 | loge("getPreferredNetworkType: CommandException: " + |
| 733 | ar.exception); |
| 734 | } else { |
| 735 | loge("getPreferredNetworkType: Unknown exception"); |
| 736 | } |
| 737 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 738 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 739 | break; |
| 740 | |
| 741 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 742 | request = (MainThreadRequest) msg.obj; |
| 743 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 744 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 745 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 746 | break; |
| 747 | |
| 748 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 749 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 750 | break; |
| 751 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 752 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 753 | request = (MainThreadRequest)msg.obj; |
| 754 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 755 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 756 | break; |
| 757 | |
| 758 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 759 | ar = (AsyncResult)msg.obj; |
| 760 | request = (MainThreadRequest)ar.userObj; |
| 761 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 762 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 763 | break; |
| 764 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 765 | case CMD_SET_VOICEMAIL_NUMBER: |
| 766 | request = (MainThreadRequest) msg.obj; |
| 767 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 768 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 769 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 770 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 771 | break; |
| 772 | |
| 773 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 774 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 775 | break; |
| 776 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 777 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 778 | request = (MainThreadRequest) msg.obj; |
| 779 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 780 | request); |
| 781 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 782 | break; |
| 783 | |
| 784 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 785 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 786 | break; |
| 787 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 788 | case CMD_PERFORM_NETWORK_SCAN: |
| 789 | request = (MainThreadRequest) msg.obj; |
| 790 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 791 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 792 | break; |
| 793 | |
| 794 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 795 | ar = (AsyncResult) msg.obj; |
| 796 | request = (MainThreadRequest) ar.userObj; |
| 797 | CellNetworkScanResult cellScanResult; |
| 798 | if (ar.exception == null && ar.result != null) { |
| 799 | cellScanResult = new CellNetworkScanResult( |
| 800 | CellNetworkScanResult.STATUS_SUCCESS, |
| 801 | (List<OperatorInfo>) ar.result); |
| 802 | } else { |
| 803 | if (ar.result == null) { |
| 804 | loge("getCellNetworkScanResults: Empty response"); |
| 805 | } |
| 806 | if (ar.exception != null) { |
| 807 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 808 | } |
| 809 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 810 | if (ar.exception instanceof CommandException) { |
| 811 | CommandException.Error error = |
| 812 | ((CommandException) (ar.exception)).getCommandError(); |
| 813 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 814 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 815 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 816 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 817 | } |
| 818 | } |
| 819 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 820 | } |
| 821 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 822 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 823 | break; |
| 824 | |
| 825 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 826 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 827 | ManualNetworkSelectionArgument selArg = |
| 828 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 829 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 830 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 831 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 832 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 833 | break; |
| 834 | |
| 835 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 836 | ar = (AsyncResult) msg.obj; |
| 837 | request = (MainThreadRequest) ar.userObj; |
| 838 | if (ar.exception == null) { |
| 839 | request.result = true; |
| 840 | } else { |
| 841 | request.result = false; |
| 842 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 843 | } |
| 844 | notifyRequester(request); |
| 845 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 846 | break; |
| 847 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 848 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 849 | request = (MainThreadRequest) msg.obj; |
| 850 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 851 | if (defaultPhone != null) { |
| 852 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 853 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 854 | break; |
| 855 | |
| 856 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 857 | ar = (AsyncResult) msg.obj; |
| 858 | request = (MainThreadRequest) ar.userObj; |
| 859 | if (ar.exception == null && ar.result != null) { |
| 860 | request.result = ar.result; |
| 861 | } else { |
| 862 | if (ar.result == null) { |
| 863 | loge("queryModemActivityInfo: Empty response"); |
| 864 | } else if (ar.exception instanceof CommandException) { |
| 865 | loge("queryModemActivityInfo: CommandException: " + |
| 866 | ar.exception); |
| 867 | } else { |
| 868 | loge("queryModemActivityInfo: Unknown exception"); |
| 869 | } |
| 870 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 871 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 872 | if (request.result == null) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 873 | request.result = new ModemActivityInfo(0, 0, 0, null, 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 874 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 875 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 876 | break; |
| 877 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 878 | case CMD_SET_ALLOWED_CARRIERS: |
| 879 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 880 | CarrierRestrictionRules argument = |
| 881 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 882 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 883 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 884 | break; |
| 885 | |
| 886 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 887 | ar = (AsyncResult) msg.obj; |
| 888 | request = (MainThreadRequest) ar.userObj; |
| 889 | if (ar.exception == null && ar.result != null) { |
| 890 | request.result = ar.result; |
| 891 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 892 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 893 | if (ar.exception instanceof CommandException) { |
| 894 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 895 | CommandException.Error error = |
| 896 | ((CommandException) (ar.exception)).getCommandError(); |
| 897 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 898 | request.result = |
| 899 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 900 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 901 | } else { |
| 902 | loge("setAllowedCarriers: Unknown exception"); |
| 903 | } |
| 904 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 905 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 906 | break; |
| 907 | |
| 908 | case CMD_GET_ALLOWED_CARRIERS: |
| 909 | request = (MainThreadRequest) msg.obj; |
| 910 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 911 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 912 | break; |
| 913 | |
| 914 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 915 | ar = (AsyncResult) msg.obj; |
| 916 | request = (MainThreadRequest) ar.userObj; |
| 917 | if (ar.exception == null && ar.result != null) { |
| 918 | request.result = ar.result; |
| 919 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 920 | request.result = new IllegalStateException( |
| 921 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 922 | if (ar.result == null) { |
| 923 | loge("getAllowedCarriers: Empty response"); |
| 924 | } else if (ar.exception instanceof CommandException) { |
| 925 | loge("getAllowedCarriers: CommandException: " + |
| 926 | ar.exception); |
| 927 | } else { |
| 928 | loge("getAllowedCarriers: Unknown exception"); |
| 929 | } |
| 930 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 931 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 932 | break; |
| 933 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 934 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 935 | ar = (AsyncResult) msg.obj; |
| 936 | request = (MainThreadRequest) ar.userObj; |
| 937 | if (ar.exception == null && ar.result != null) { |
| 938 | request.result = ar.result; |
| 939 | } else { |
| 940 | request.result = new IllegalArgumentException( |
| 941 | "Failed to retrieve Forbidden Plmns"); |
| 942 | if (ar.result == null) { |
| 943 | loge("getForbiddenPlmns: Empty response"); |
| 944 | } else { |
| 945 | loge("getForbiddenPlmns: Unknown exception"); |
| 946 | } |
| 947 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 948 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 949 | break; |
| 950 | |
| 951 | case CMD_GET_FORBIDDEN_PLMNS: |
| 952 | request = (MainThreadRequest) msg.obj; |
| 953 | uiccCard = getUiccCardFromRequest(request); |
| 954 | if (uiccCard == null) { |
| 955 | loge("getForbiddenPlmns() UiccCard is null"); |
| 956 | request.result = new IllegalArgumentException( |
| 957 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 958 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 959 | break; |
| 960 | } |
| 961 | Integer appType = (Integer) request.argument; |
| 962 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 963 | if (uiccApp == null) { |
| 964 | loge("getForbiddenPlmns() no app with specified type -- " |
| 965 | + appType); |
| 966 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 967 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 968 | break; |
| 969 | } else { |
| 970 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 971 | + " specified type -- " + appType); |
| 972 | } |
| 973 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 974 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 975 | onCompleted); |
| 976 | break; |
| 977 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 978 | case CMD_SWITCH_SLOTS: |
| 979 | request = (MainThreadRequest) msg.obj; |
| 980 | int[] physicalSlots = (int[]) request.argument; |
| 981 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 982 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 983 | break; |
| 984 | |
| 985 | case EVENT_SWITCH_SLOTS_DONE: |
| 986 | ar = (AsyncResult) msg.obj; |
| 987 | request = (MainThreadRequest) ar.userObj; |
| 988 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 989 | notifyRequester(request); |
| 990 | break; |
| 991 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 992 | request = (MainThreadRequest) msg.obj; |
| 993 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 994 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 995 | break; |
| 996 | |
| 997 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 998 | ar = (AsyncResult) msg.obj; |
| 999 | request = (MainThreadRequest) ar.userObj; |
| 1000 | if (ar.exception != null) { |
| 1001 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1002 | } else { |
| 1003 | int mode = ((int[]) ar.result)[0]; |
| 1004 | if (mode == 0) { |
| 1005 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1006 | } else { |
| 1007 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1008 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1009 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1010 | notifyRequester(request); |
| 1011 | break; |
| 1012 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1013 | request = (MainThreadRequest) msg.obj; |
| 1014 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1015 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1016 | break; |
| 1017 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1018 | ar = (AsyncResult) msg.obj; |
| 1019 | request = (MainThreadRequest) ar.userObj; |
| 1020 | if (ar.exception != null) { |
| 1021 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1022 | } else { |
| 1023 | request.result = ((int[]) ar.result)[0]; |
| 1024 | } |
| 1025 | notifyRequester(request); |
| 1026 | break; |
| 1027 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1028 | request = (MainThreadRequest) msg.obj; |
| 1029 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1030 | int mode = (int) request.argument; |
| 1031 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1032 | break; |
| 1033 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1034 | ar = (AsyncResult) msg.obj; |
| 1035 | request = (MainThreadRequest) ar.userObj; |
| 1036 | request.result = ar.exception == null; |
| 1037 | notifyRequester(request); |
| 1038 | break; |
| 1039 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1040 | request = (MainThreadRequest) msg.obj; |
| 1041 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1042 | int subscriptionMode = (int) request.argument; |
| 1043 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1044 | break; |
| 1045 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1046 | ar = (AsyncResult) msg.obj; |
| 1047 | request = (MainThreadRequest) ar.userObj; |
| 1048 | request.result = ar.exception == null; |
| 1049 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1050 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1051 | case CMD_GET_ALL_CELL_INFO: |
| 1052 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1053 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1054 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1055 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1056 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1057 | ar = (AsyncResult) msg.obj; |
| 1058 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1059 | // If a timeout occurs, the response will be null |
| 1060 | request.result = (ar.exception == null && ar.result != null) |
| 1061 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1062 | synchronized (request) { |
| 1063 | request.notifyAll(); |
| 1064 | } |
| 1065 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1066 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1067 | request = (MainThreadRequest) msg.obj; |
| 1068 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1069 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1070 | break; |
| 1071 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1072 | ar = (AsyncResult) msg.obj; |
| 1073 | request = (MainThreadRequest) ar.userObj; |
| 1074 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1075 | try { |
| 1076 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1077 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1078 | cb.onError( |
| 1079 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1080 | ar.exception.getClass().getName(), |
| 1081 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1082 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1083 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1084 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1085 | } else { |
| 1086 | // use the result as returned |
| 1087 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1088 | } |
| 1089 | } catch (RemoteException re) { |
| 1090 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1091 | } |
| 1092 | break; |
| 1093 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1094 | request = (MainThreadRequest) msg.obj; |
| 1095 | WorkSource ws = (WorkSource) request.argument; |
| 1096 | Phone phone = getPhoneFromRequest(request); |
| 1097 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1098 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1099 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1100 | ar = (AsyncResult) msg.obj; |
| 1101 | request = (MainThreadRequest) ar.userObj; |
| 1102 | if (ar.exception == null) { |
| 1103 | request.result = ar.result; |
| 1104 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1105 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1106 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1107 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1108 | } |
| 1109 | |
| 1110 | synchronized (request) { |
| 1111 | request.notifyAll(); |
| 1112 | } |
| 1113 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1114 | case CMD_MODEM_REBOOT: |
| 1115 | request = (MainThreadRequest) msg.obj; |
| 1116 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1117 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1118 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1119 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1120 | handleNullReturnEvent(msg, "rebootModem"); |
| 1121 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1122 | case CMD_REQUEST_ENABLE_MODEM: |
| 1123 | request = (MainThreadRequest) msg.obj; |
| 1124 | boolean enable = (boolean) request.argument; |
| 1125 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1126 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1127 | PhoneConfigurationManager.getInstance() |
| 1128 | .enablePhone(request.phone, enable, onCompleted); |
| 1129 | break; |
| 1130 | case EVENT_ENABLE_MODEM_DONE: |
| 1131 | ar = (AsyncResult) msg.obj; |
| 1132 | request = (MainThreadRequest) ar.userObj; |
| 1133 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1134 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1135 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1136 | if ((boolean) request.result) { |
| 1137 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1138 | updateModemStateMetrics(); |
| 1139 | } else { |
| 1140 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1141 | + ar.exception); |
| 1142 | } |
| 1143 | notifyRequester(request); |
| 1144 | break; |
| 1145 | case CMD_GET_MODEM_STATUS: |
| 1146 | request = (MainThreadRequest) msg.obj; |
| 1147 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1148 | PhoneConfigurationManager.getInstance() |
| 1149 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1150 | break; |
| 1151 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1152 | ar = (AsyncResult) msg.obj; |
| 1153 | request = (MainThreadRequest) ar.userObj; |
| 1154 | int id = request.phone.getPhoneId(); |
| 1155 | if (ar.exception == null && ar.result != null) { |
| 1156 | request.result = ar.result; |
| 1157 | //update the cache as modem status has changed |
| 1158 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1159 | (boolean) request.result); |
| 1160 | } else { |
| 1161 | // Return true if modem status cannot be retrieved. For most cases, |
| 1162 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1163 | // and disable modem are not supported. Modem is always on. |
| 1164 | // TODO: this should be fixed in R to support a third |
| 1165 | // status UNKNOWN b/131631629 |
| 1166 | request.result = true; |
| 1167 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1168 | + ar.exception); |
| 1169 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1170 | notifyRequester(request); |
| 1171 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1172 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1173 | ar = (AsyncResult) msg.obj; |
| 1174 | request = (MainThreadRequest) ar.userObj; |
| 1175 | if (ar.exception == null && ar.result != null) { |
| 1176 | request.result = ar.result; |
| 1177 | } else { |
| 1178 | request.result = -1; |
| 1179 | loge("Failed to set Forbidden Plmns"); |
| 1180 | if (ar.result == null) { |
| 1181 | loge("setForbidenPlmns: Empty response"); |
| 1182 | } else if (ar.exception != null) { |
| 1183 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1184 | request.result = -1; |
| 1185 | } else { |
| 1186 | loge("setForbiddenPlmns: Unknown exception"); |
| 1187 | } |
| 1188 | } |
| 1189 | notifyRequester(request); |
| 1190 | break; |
| 1191 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1192 | request = (MainThreadRequest) msg.obj; |
| 1193 | uiccCard = getUiccCardFromRequest(request); |
| 1194 | if (uiccCard == null) { |
| 1195 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1196 | request.result = -1; |
| 1197 | notifyRequester(request); |
| 1198 | break; |
| 1199 | } |
| 1200 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1201 | (Pair<Integer, List<String>>) request.argument; |
| 1202 | appType = setFplmnsArgs.first; |
| 1203 | List<String> fplmns = setFplmnsArgs.second; |
| 1204 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1205 | if (uiccApp == null) { |
| 1206 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1207 | request.result = -1; |
| 1208 | loge("Failed to get UICC App"); |
| 1209 | notifyRequester(request); |
| 1210 | } else { |
| 1211 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1212 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1213 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1214 | } |
| 1215 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1216 | default: |
| 1217 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1218 | break; |
| 1219 | } |
| 1220 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1221 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1222 | private void notifyRequester(MainThreadRequest request) { |
| 1223 | synchronized (request) { |
| 1224 | request.notifyAll(); |
| 1225 | } |
| 1226 | } |
| 1227 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1228 | private void handleNullReturnEvent(Message msg, String command) { |
| 1229 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1230 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1231 | if (ar.exception == null) { |
| 1232 | request.result = true; |
| 1233 | } else { |
| 1234 | request.result = false; |
| 1235 | if (ar.exception instanceof CommandException) { |
| 1236 | loge(command + ": CommandException: " + ar.exception); |
| 1237 | } else { |
| 1238 | loge(command + ": Unknown exception"); |
| 1239 | } |
| 1240 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1241 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1242 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | /** |
| 1246 | * Posts the specified command to be executed on the main thread, |
| 1247 | * waits for the request to complete, and returns the result. |
| 1248 | * @see #sendRequestAsync |
| 1249 | */ |
| 1250 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1251 | return sendRequest( |
| 1252 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | /** |
| 1256 | * Posts the specified command to be executed on the main thread, |
| 1257 | * waits for the request to complete, and returns the result. |
| 1258 | * @see #sendRequestAsync |
| 1259 | */ |
| 1260 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1261 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1262 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | /** |
| 1266 | * Posts the specified command to be executed on the main thread, |
| 1267 | * waits for the request to complete, and returns the result. |
| 1268 | * @see #sendRequestAsync |
| 1269 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1270 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1271 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | /** |
| 1275 | * Posts the specified command to be executed on the main thread, |
| 1276 | * waits for the request to complete, and returns the result. |
| 1277 | * @see #sendRequestAsync |
| 1278 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1279 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1280 | return sendRequest(command, argument, subId, null, workSource); |
| 1281 | } |
| 1282 | |
| 1283 | /** |
| 1284 | * Posts the specified command to be executed on the main thread, |
| 1285 | * waits for the request to complete, and returns the result. |
| 1286 | * @see #sendRequestAsync |
| 1287 | */ |
| 1288 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1289 | return sendRequest( |
| 1290 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1291 | } |
| 1292 | |
| 1293 | /** |
| 1294 | * Posts the specified command to be executed on the main thread, |
| 1295 | * waits for the request to complete, and returns the result. |
| 1296 | * @see #sendRequestAsync |
| 1297 | */ |
| 1298 | private Object sendRequest( |
| 1299 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1300 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1301 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1302 | } |
| 1303 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1304 | MainThreadRequest request = null; |
| 1305 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1306 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1307 | } else if (phone != null) { |
| 1308 | request = new MainThreadRequest(argument, phone, workSource); |
| 1309 | } else { |
| 1310 | request = new MainThreadRequest(argument, subId, workSource); |
| 1311 | } |
| 1312 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1313 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1314 | msg.sendToTarget(); |
| 1315 | |
| 1316 | // Wait for the request to complete |
| 1317 | synchronized (request) { |
| 1318 | while (request.result == null) { |
| 1319 | try { |
| 1320 | request.wait(); |
| 1321 | } catch (InterruptedException e) { |
| 1322 | // Do nothing, go back and wait until the request is complete |
| 1323 | } |
| 1324 | } |
| 1325 | } |
| 1326 | return request.result; |
| 1327 | } |
| 1328 | |
| 1329 | /** |
| 1330 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1331 | * Posts the specified command to be executed on the main thread, and |
| 1332 | * returns immediately. |
| 1333 | * @see #sendRequest |
| 1334 | */ |
| 1335 | private void sendRequestAsync(int command) { |
| 1336 | mMainThreadHandler.sendEmptyMessage(command); |
| 1337 | } |
| 1338 | |
| 1339 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1340 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1341 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1342 | */ |
| 1343 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1344 | sendRequestAsync(command, argument, null, null); |
| 1345 | } |
| 1346 | |
| 1347 | /** |
| 1348 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1349 | * @see {@link #sendRequest(int,Object)} |
| 1350 | */ |
| 1351 | private void sendRequestAsync( |
| 1352 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1353 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1354 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1355 | msg.sendToTarget(); |
| 1356 | } |
| 1357 | |
| 1358 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1359 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1360 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1361 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1362 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1363 | synchronized (PhoneInterfaceManager.class) { |
| 1364 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1365 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1366 | } else { |
| 1367 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1368 | } |
| 1369 | return sInstance; |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1374 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1375 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1376 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1377 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1378 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1379 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1380 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1381 | mTelephonySharedPreferences = |
| 1382 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1383 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1384 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1385 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1386 | publish(); |
| 1387 | } |
| 1388 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1389 | private Phone getDefaultPhone() { |
| 1390 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1391 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1392 | } |
| 1393 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1394 | private void publish() { |
| 1395 | if (DBG) log("publish: " + this); |
| 1396 | |
| 1397 | ServiceManager.addService("phone", this); |
| 1398 | } |
| 1399 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1400 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1401 | if (request.phone != null) { |
| 1402 | return request.phone; |
| 1403 | } else { |
| 1404 | return getPhoneFromSubId(request.subId); |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | private Phone getPhoneFromSubId(int subId) { |
| 1409 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1410 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1411 | } |
| 1412 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1413 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1414 | Phone phone = getPhoneFromRequest(request); |
| 1415 | return phone == null ? null : |
| 1416 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1417 | } |
| 1418 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1419 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1420 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1421 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1422 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1423 | |
| 1424 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1425 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1428 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1429 | if (DBG) log("dial: " + number); |
| 1430 | // No permission check needed here: This is just a wrapper around the |
| 1431 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1432 | // the UI before it does anything. |
| 1433 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1434 | final long identity = Binder.clearCallingIdentity(); |
| 1435 | try { |
| 1436 | String url = createTelUrl(number); |
| 1437 | if (url == null) { |
| 1438 | return; |
| 1439 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1440 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1441 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1442 | PhoneConstants.State state = mCM.getState(subId); |
| 1443 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1444 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1445 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1446 | mApp.startActivity(intent); |
| 1447 | } |
| 1448 | } finally { |
| 1449 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1454 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1457 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1458 | if (DBG) log("call: " + number); |
| 1459 | |
| 1460 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1461 | // need to do a permission check since we're calling startActivity() |
| 1462 | // from the context of the phone app. |
| 1463 | enforceCallPermission(); |
| 1464 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1465 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1466 | != AppOpsManager.MODE_ALLOWED) { |
| 1467 | return; |
| 1468 | } |
| 1469 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1470 | final long identity = Binder.clearCallingIdentity(); |
| 1471 | try { |
| 1472 | String url = createTelUrl(number); |
| 1473 | if (url == null) { |
| 1474 | return; |
| 1475 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1476 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1477 | boolean isValid = false; |
| 1478 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1479 | if (slist != null) { |
| 1480 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1481 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1482 | isValid = true; |
| 1483 | break; |
| 1484 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1485 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1486 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1487 | if (!isValid) { |
| 1488 | return; |
| 1489 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1490 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1491 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1492 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1493 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1494 | mApp.startActivity(intent); |
| 1495 | } finally { |
| 1496 | Binder.restoreCallingIdentity(identity); |
| 1497 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1500 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1501 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1504 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1505 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1506 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1507 | } |
| 1508 | |
| 1509 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1510 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1513 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1514 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1515 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1516 | } |
| 1517 | |
| 1518 | /** {@hide} */ |
| 1519 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1520 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1523 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1524 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1525 | |
| 1526 | final long identity = Binder.clearCallingIdentity(); |
| 1527 | try { |
| 1528 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1529 | checkSimPin.start(); |
| 1530 | return checkSimPin.unlockSim(null, pin); |
| 1531 | } finally { |
| 1532 | Binder.restoreCallingIdentity(identity); |
| 1533 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1536 | /** {@hide} */ |
| 1537 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1538 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1539 | } |
| 1540 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1541 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1542 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1543 | |
| 1544 | final long identity = Binder.clearCallingIdentity(); |
| 1545 | try { |
| 1546 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1547 | checkSimPuk.start(); |
| 1548 | return checkSimPuk.unlockSim(puk, pin); |
| 1549 | } finally { |
| 1550 | Binder.restoreCallingIdentity(identity); |
| 1551 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1555 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1556 | * a synchronous one. |
| 1557 | */ |
| 1558 | private static class UnlockSim extends Thread { |
| 1559 | |
| 1560 | private final IccCard mSimCard; |
| 1561 | |
| 1562 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1563 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1564 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1565 | |
| 1566 | // For replies from SimCard interface |
| 1567 | private Handler mHandler; |
| 1568 | |
| 1569 | // For async handler to identify request type |
| 1570 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1571 | |
| 1572 | public UnlockSim(IccCard simCard) { |
| 1573 | mSimCard = simCard; |
| 1574 | } |
| 1575 | |
| 1576 | @Override |
| 1577 | public void run() { |
| 1578 | Looper.prepare(); |
| 1579 | synchronized (UnlockSim.this) { |
| 1580 | mHandler = new Handler() { |
| 1581 | @Override |
| 1582 | public void handleMessage(Message msg) { |
| 1583 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1584 | switch (msg.what) { |
| 1585 | case SUPPLY_PIN_COMPLETE: |
| 1586 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1587 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1588 | mRetryCount = msg.arg1; |
| 1589 | if (ar.exception != null) { |
| 1590 | if (ar.exception instanceof CommandException && |
| 1591 | ((CommandException)(ar.exception)).getCommandError() |
| 1592 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1593 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1594 | } else { |
| 1595 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1596 | } |
| 1597 | } else { |
| 1598 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1599 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1600 | mDone = true; |
| 1601 | UnlockSim.this.notifyAll(); |
| 1602 | } |
| 1603 | break; |
| 1604 | } |
| 1605 | } |
| 1606 | }; |
| 1607 | UnlockSim.this.notifyAll(); |
| 1608 | } |
| 1609 | Looper.loop(); |
| 1610 | } |
| 1611 | |
| 1612 | /* |
| 1613 | * Use PIN or PUK to unlock SIM card |
| 1614 | * |
| 1615 | * If PUK is null, unlock SIM card with PIN |
| 1616 | * |
| 1617 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1618 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1619 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1620 | |
| 1621 | while (mHandler == null) { |
| 1622 | try { |
| 1623 | wait(); |
| 1624 | } catch (InterruptedException e) { |
| 1625 | Thread.currentThread().interrupt(); |
| 1626 | } |
| 1627 | } |
| 1628 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1629 | |
| 1630 | if (puk == null) { |
| 1631 | mSimCard.supplyPin(pin, callback); |
| 1632 | } else { |
| 1633 | mSimCard.supplyPuk(puk, pin, callback); |
| 1634 | } |
| 1635 | |
| 1636 | while (!mDone) { |
| 1637 | try { |
| 1638 | Log.d(LOG_TAG, "wait for done"); |
| 1639 | wait(); |
| 1640 | } catch (InterruptedException e) { |
| 1641 | // Restore the interrupted status |
| 1642 | Thread.currentThread().interrupt(); |
| 1643 | } |
| 1644 | } |
| 1645 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1646 | int[] resultArray = new int[2]; |
| 1647 | resultArray[0] = mResult; |
| 1648 | resultArray[1] = mRetryCount; |
| 1649 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1654 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1655 | |
| 1656 | } |
| 1657 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1658 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1659 | // No permission check needed here: this call is harmless, and it's |
| 1660 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1661 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1662 | final long identity = Binder.clearCallingIdentity(); |
| 1663 | try { |
| 1664 | final Phone phone = getPhone(subId); |
| 1665 | if (phone != null) { |
| 1666 | phone.updateServiceLocation(); |
| 1667 | } |
| 1668 | } finally { |
| 1669 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1670 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1673 | @Override |
| 1674 | public boolean isRadioOn(String callingPackage) { |
| 1675 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1678 | @Override |
| 1679 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1680 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1681 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1682 | return false; |
| 1683 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1684 | |
| 1685 | final long identity = Binder.clearCallingIdentity(); |
| 1686 | try { |
| 1687 | return isRadioOnForSubscriber(subId); |
| 1688 | } finally { |
| 1689 | Binder.restoreCallingIdentity(identity); |
| 1690 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1694 | final long identity = Binder.clearCallingIdentity(); |
| 1695 | try { |
| 1696 | final Phone phone = getPhone(subId); |
| 1697 | if (phone != null) { |
| 1698 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1699 | } else { |
| 1700 | return false; |
| 1701 | } |
| 1702 | } finally { |
| 1703 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1704 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1708 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1709 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1710 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1711 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1712 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1713 | |
| 1714 | final long identity = Binder.clearCallingIdentity(); |
| 1715 | try { |
| 1716 | final Phone phone = getPhone(subId); |
| 1717 | if (phone != null) { |
| 1718 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1719 | } |
| 1720 | } finally { |
| 1721 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1722 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1726 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1729 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1730 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1731 | |
| 1732 | final long identity = Binder.clearCallingIdentity(); |
| 1733 | try { |
| 1734 | final Phone phone = getPhone(subId); |
| 1735 | if (phone == null) { |
| 1736 | return false; |
| 1737 | } |
| 1738 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1739 | toggleRadioOnOffForSubscriber(subId); |
| 1740 | } |
| 1741 | return true; |
| 1742 | } finally { |
| 1743 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1744 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1745 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1746 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1747 | public boolean needMobileRadioShutdown() { |
| 1748 | /* |
| 1749 | * If any of the Radios are available, it will need to be |
| 1750 | * shutdown. So return true if any Radio is available. |
| 1751 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1752 | final long identity = Binder.clearCallingIdentity(); |
| 1753 | try { |
| 1754 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1755 | Phone phone = PhoneFactory.getPhone(i); |
| 1756 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1757 | } |
| 1758 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1759 | return false; |
| 1760 | } finally { |
| 1761 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1762 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1765 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1766 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1767 | enforceModifyPermission(); |
| 1768 | |
| 1769 | final long identity = Binder.clearCallingIdentity(); |
| 1770 | try { |
| 1771 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1772 | logv("Shutting down Phone " + i); |
| 1773 | shutdownRadioUsingPhoneId(i); |
| 1774 | } |
| 1775 | } finally { |
| 1776 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1781 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1782 | if (phone != null && phone.isRadioAvailable()) { |
| 1783 | phone.shutdownRadio(); |
| 1784 | } |
| 1785 | } |
| 1786 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1787 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1788 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1789 | |
| 1790 | final long identity = Binder.clearCallingIdentity(); |
| 1791 | try { |
| 1792 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1793 | if (defaultPhone != null) { |
| 1794 | defaultPhone.setRadioPower(turnOn); |
| 1795 | return true; |
| 1796 | } else { |
| 1797 | loge("There's no default phone."); |
| 1798 | return false; |
| 1799 | } |
| 1800 | } finally { |
| 1801 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1802 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1805 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1806 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1807 | |
| 1808 | final long identity = Binder.clearCallingIdentity(); |
| 1809 | try { |
| 1810 | final Phone phone = getPhone(subId); |
| 1811 | if (phone != null) { |
| 1812 | phone.setRadioPower(turnOn); |
| 1813 | return true; |
| 1814 | } else { |
| 1815 | return false; |
| 1816 | } |
| 1817 | } finally { |
| 1818 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1819 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1822 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1823 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1824 | public boolean enableDataConnectivity() { |
| 1825 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1826 | |
| 1827 | final long identity = Binder.clearCallingIdentity(); |
| 1828 | try { |
| 1829 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1830 | final Phone phone = getPhone(subId); |
| 1831 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1832 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1833 | return true; |
| 1834 | } else { |
| 1835 | return false; |
| 1836 | } |
| 1837 | } finally { |
| 1838 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1839 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1842 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1843 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1844 | public boolean disableDataConnectivity() { |
| 1845 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1846 | |
| 1847 | final long identity = Binder.clearCallingIdentity(); |
| 1848 | try { |
| 1849 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1850 | final Phone phone = getPhone(subId); |
| 1851 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1852 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1853 | return true; |
| 1854 | } else { |
| 1855 | return false; |
| 1856 | } |
| 1857 | } finally { |
| 1858 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1859 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1862 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1863 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1864 | final long identity = Binder.clearCallingIdentity(); |
| 1865 | try { |
| 1866 | final Phone phone = getPhone(subId); |
| 1867 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1868 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1869 | } else { |
| 1870 | return false; |
| 1871 | } |
| 1872 | } finally { |
| 1873 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1874 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1878 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1879 | } |
| 1880 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1881 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1882 | enforceCallPermission(); |
| 1883 | |
| 1884 | final long identity = Binder.clearCallingIdentity(); |
| 1885 | try { |
| 1886 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1887 | return; |
| 1888 | } |
| 1889 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1890 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1891 | } finally { |
| 1892 | Binder.restoreCallingIdentity(identity); |
| 1893 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1894 | }; |
| 1895 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1896 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1897 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1898 | |
| 1899 | final long identity = Binder.clearCallingIdentity(); |
| 1900 | try { |
| 1901 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1902 | return false; |
| 1903 | } |
| 1904 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1905 | } finally { |
| 1906 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1907 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1908 | } |
| 1909 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1910 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1911 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1912 | } |
| 1913 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1914 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1915 | final long identity = Binder.clearCallingIdentity(); |
| 1916 | try { |
| 1917 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1918 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1919 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1920 | } finally { |
| 1921 | Binder.restoreCallingIdentity(identity); |
| 1922 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1925 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1926 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1927 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1928 | } |
| 1929 | |
| 1930 | @Override |
| 1931 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1932 | final long identity = Binder.clearCallingIdentity(); |
| 1933 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1934 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1935 | if (phone != null) { |
| 1936 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1937 | } else { |
| 1938 | return PhoneConstantConversions.convertDataState( |
| 1939 | PhoneConstants.DataState.DISCONNECTED); |
| 1940 | } |
| 1941 | } finally { |
| 1942 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1943 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1946 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1947 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1948 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1949 | } |
| 1950 | |
| 1951 | @Override |
| 1952 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1953 | final long identity = Binder.clearCallingIdentity(); |
| 1954 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1955 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1956 | if (phone != null) { |
| 1957 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1958 | } else { |
| 1959 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1960 | } |
| 1961 | } finally { |
| 1962 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1963 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1967 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1968 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1969 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1970 | |
| 1971 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1972 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1973 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1974 | .setCallingPackage(callingPackage) |
| 1975 | .setCallingPid(Binder.getCallingPid()) |
| 1976 | .setCallingUid(Binder.getCallingUid()) |
| 1977 | .setMethod("getCellLocation") |
| 1978 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1979 | .build()); |
| 1980 | switch (locationResult) { |
| 1981 | case DENIED_HARD: |
| 1982 | throw new SecurityException("Not allowed to access cell location"); |
| 1983 | case DENIED_SOFT: |
| 1984 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1987 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1988 | final long identity = Binder.clearCallingIdentity(); |
| 1989 | try { |
| 1990 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1991 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1992 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1993 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1994 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1995 | return data; |
| 1996 | } finally { |
| 1997 | Binder.restoreCallingIdentity(identity); |
| 1998 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2001 | @Override |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2002 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) { |
| 2003 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2004 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
| 2005 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2006 | mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) { |
| 2007 | return ""; |
| 2008 | } |
| 2009 | } |
| 2010 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2011 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2012 | // registered cell info, so return a NULL country instead. |
| 2013 | final long identity = Binder.clearCallingIdentity(); |
| 2014 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2015 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2016 | // Get default phone in this case. |
| 2017 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2018 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2019 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2020 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2021 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2022 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 2023 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 2024 | return ""; |
| 2025 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2026 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2027 | if (phone != null) { |
| 2028 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2029 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2030 | if (sst != null) { |
| 2031 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2032 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2033 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2034 | return lt.getCurrentCountry(); |
| 2035 | } else if (emergencyNumberTracker != null) { |
| 2036 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2037 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2038 | } |
| 2039 | } |
| 2040 | } |
| 2041 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2042 | } finally { |
| 2043 | Binder.restoreCallingIdentity(identity); |
| 2044 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2048 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2049 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2052 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2053 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2054 | mApp.enforceCallingOrSelfPermission( |
| 2055 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2056 | |
| 2057 | final long identity = Binder.clearCallingIdentity(); |
| 2058 | try { |
| 2059 | final Phone phone = getPhone(subId); |
| 2060 | if (phone != null) { |
| 2061 | phone.enableLocationUpdates(); |
| 2062 | } |
| 2063 | } finally { |
| 2064 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2065 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | @Override |
| 2069 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2070 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2073 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2074 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2075 | mApp.enforceCallingOrSelfPermission( |
| 2076 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2077 | |
| 2078 | final long identity = Binder.clearCallingIdentity(); |
| 2079 | try { |
| 2080 | final Phone phone = getPhone(subId); |
| 2081 | if (phone != null) { |
| 2082 | phone.disableLocationUpdates(); |
| 2083 | } |
| 2084 | } finally { |
| 2085 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2086 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2087 | } |
| 2088 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2089 | /** |
| 2090 | * Returns the target SDK version number for a given package name. |
| 2091 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2092 | * This call MUST be invoked before clearing the calling UID. |
| 2093 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2094 | * @return target SDK if the package is found or INT_MAX. |
| 2095 | */ |
| 2096 | private int getTargetSdk(String packageName) { |
| 2097 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2098 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2099 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2100 | if (ai != null) return ai.targetSdkVersion; |
| 2101 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2102 | loge("Failed to get package info for pkg=" |
| 2103 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2104 | } |
| 2105 | return Integer.MAX_VALUE; |
| 2106 | } |
| 2107 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2108 | @Override |
| 2109 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2110 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2111 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2112 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2113 | throw new SecurityException( |
| 2114 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2115 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2116 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2117 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2118 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2119 | return null; |
| 2120 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2121 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2122 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2123 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2124 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2125 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2126 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2127 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2128 | for (CellInfo ci : info) { |
| 2129 | if (ci instanceof CellInfoGsm) { |
| 2130 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2131 | } else if (ci instanceof CellInfoWcdma) { |
| 2132 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2133 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2134 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2135 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2138 | private List<CellInfo> getCachedCellInfo() { |
| 2139 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2140 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2141 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2142 | if (info != null) cellInfos.addAll(info); |
| 2143 | } |
| 2144 | return cellInfos; |
| 2145 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2146 | |
| 2147 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2148 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2149 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2150 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2151 | |
| 2152 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2153 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2154 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2155 | .setCallingPackage(callingPackage) |
| 2156 | .setCallingPid(Binder.getCallingPid()) |
| 2157 | .setCallingUid(Binder.getCallingUid()) |
| 2158 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2159 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2160 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2161 | .build()); |
| 2162 | switch (locationResult) { |
| 2163 | case DENIED_HARD: |
| 2164 | throw new SecurityException("Not allowed to access cell info"); |
| 2165 | case DENIED_SOFT: |
| 2166 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2169 | final int targetSdk = getTargetSdk(callingPackage); |
| 2170 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2171 | return getCachedCellInfo(); |
| 2172 | } |
| 2173 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2174 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2175 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2176 | final long identity = Binder.clearCallingIdentity(); |
| 2177 | try { |
| 2178 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2179 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2180 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2181 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2182 | if (info != null) cellInfos.addAll(info); |
| 2183 | } |
| 2184 | return cellInfos; |
| 2185 | } finally { |
| 2186 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2187 | } |
| 2188 | } |
| 2189 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2190 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2191 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2192 | requestCellInfoUpdateInternal( |
| 2193 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2194 | } |
| 2195 | |
| 2196 | @Override |
| 2197 | public void requestCellInfoUpdateWithWorkSource( |
| 2198 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2199 | enforceModifyPermission(); |
| 2200 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2201 | } |
| 2202 | |
| 2203 | private void requestCellInfoUpdateInternal( |
| 2204 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2205 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2206 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2207 | |
| 2208 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2209 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2210 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2211 | .setCallingPackage(callingPackage) |
| 2212 | .setCallingPid(Binder.getCallingPid()) |
| 2213 | .setCallingUid(Binder.getCallingUid()) |
| 2214 | .setMethod("requestCellInfoUpdate") |
| 2215 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2216 | .build()); |
| 2217 | switch (locationResult) { |
| 2218 | case DENIED_HARD: |
| 2219 | throw new SecurityException("Not allowed to access cell info"); |
| 2220 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2221 | try { |
| 2222 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2223 | } catch (RemoteException re) { |
| 2224 | // Drop without consequences |
| 2225 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2226 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2227 | } |
| 2228 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2229 | |
| 2230 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2231 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2232 | |
| 2233 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2234 | } |
| 2235 | |
| 2236 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2237 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2238 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2239 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2240 | |
| 2241 | final long identity = Binder.clearCallingIdentity(); |
| 2242 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2243 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2244 | } finally { |
| 2245 | Binder.restoreCallingIdentity(identity); |
| 2246 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2247 | } |
| 2248 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2249 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2250 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2251 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2252 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2253 | return null; |
| 2254 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2255 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2256 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2257 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2258 | return null; |
| 2259 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2260 | |
| 2261 | final long identity = Binder.clearCallingIdentity(); |
| 2262 | try { |
| 2263 | return phone.getImei(); |
| 2264 | } finally { |
| 2265 | Binder.restoreCallingIdentity(identity); |
| 2266 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2270 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2271 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2272 | String tac = null; |
| 2273 | if (phone != null) { |
| 2274 | String imei = phone.getImei(); |
| 2275 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2276 | } |
| 2277 | return tac; |
| 2278 | } |
| 2279 | |
| 2280 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2281 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2282 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2283 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2284 | return null; |
| 2285 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2286 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2287 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2288 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2289 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2290 | return null; |
| 2291 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2292 | |
| 2293 | final long identity = Binder.clearCallingIdentity(); |
| 2294 | try { |
| 2295 | return phone.getMeid(); |
| 2296 | } finally { |
| 2297 | Binder.restoreCallingIdentity(identity); |
| 2298 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2302 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2303 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2304 | String manufacturerCode = null; |
| 2305 | if (phone != null) { |
| 2306 | String meid = phone.getMeid(); |
| 2307 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2308 | } |
| 2309 | return manufacturerCode; |
| 2310 | } |
| 2311 | |
| 2312 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2313 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2314 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2315 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2316 | return null; |
| 2317 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2318 | int subId = phone.getSubId(); |
| 2319 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2320 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2321 | return null; |
| 2322 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2323 | |
| 2324 | final long identity = Binder.clearCallingIdentity(); |
| 2325 | try { |
| 2326 | return phone.getDeviceSvn(); |
| 2327 | } finally { |
| 2328 | Binder.restoreCallingIdentity(identity); |
| 2329 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2332 | @Override |
| 2333 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2334 | final long identity = Binder.clearCallingIdentity(); |
| 2335 | try { |
| 2336 | final Phone phone = getPhone(subId); |
| 2337 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2338 | } finally { |
| 2339 | Binder.restoreCallingIdentity(identity); |
| 2340 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | @Override |
| 2344 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2345 | final long identity = Binder.clearCallingIdentity(); |
| 2346 | try { |
| 2347 | final Phone phone = getPhone(subId); |
| 2348 | return phone == null ? null : phone.getCarrierName(); |
| 2349 | } finally { |
| 2350 | Binder.restoreCallingIdentity(identity); |
| 2351 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2352 | } |
| 2353 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2354 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2355 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2356 | final long identity = Binder.clearCallingIdentity(); |
| 2357 | try { |
| 2358 | final Phone phone = getPhone(subId); |
| 2359 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2360 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2361 | } finally { |
| 2362 | Binder.restoreCallingIdentity(identity); |
| 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2367 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2368 | final long identity = Binder.clearCallingIdentity(); |
| 2369 | try { |
| 2370 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2371 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2372 | } finally { |
| 2373 | Binder.restoreCallingIdentity(identity); |
| 2374 | } |
| 2375 | } |
| 2376 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2377 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2378 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2379 | if (!isSubscriptionMccMnc) { |
| 2380 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2381 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2382 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2383 | if (phone == null) { |
| 2384 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2385 | } |
| 2386 | final long identity = Binder.clearCallingIdentity(); |
| 2387 | try { |
| 2388 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2389 | } finally { |
| 2390 | Binder.restoreCallingIdentity(identity); |
| 2391 | } |
| 2392 | } |
| 2393 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2394 | // |
| 2395 | // Internal helper methods. |
| 2396 | // |
| 2397 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2398 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2399 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2400 | * |
| 2401 | * @throws SecurityException if the caller does not have the required permission |
| 2402 | */ |
| 2403 | private void enforceModifyPermission() { |
| 2404 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2405 | } |
| 2406 | |
| 2407 | /** |
| 2408 | * Make sure the caller has the CALL_PHONE permission. |
| 2409 | * |
| 2410 | * @throws SecurityException if the caller does not have the required permission |
| 2411 | */ |
| 2412 | private void enforceCallPermission() { |
| 2413 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2414 | } |
| 2415 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2416 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2417 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2418 | "ConnectivityService"); |
| 2419 | } |
| 2420 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2421 | private String createTelUrl(String number) { |
| 2422 | if (TextUtils.isEmpty(number)) { |
| 2423 | return null; |
| 2424 | } |
| 2425 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2426 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2427 | } |
| 2428 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2429 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2430 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2431 | } |
| 2432 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2433 | private static void logv(String msg) { |
| 2434 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2435 | } |
| 2436 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2437 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2438 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2439 | } |
| 2440 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2441 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2442 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2443 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2444 | } |
| 2445 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2446 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2447 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2448 | final long identity = Binder.clearCallingIdentity(); |
| 2449 | try { |
| 2450 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2451 | if (phone == null) { |
| 2452 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2453 | } else { |
| 2454 | return phone.getPhoneType(); |
| 2455 | } |
| 2456 | } finally { |
| 2457 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2458 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2459 | } |
| 2460 | |
| 2461 | /** |
| 2462 | * Returns the CDMA ERI icon index to display |
| 2463 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2464 | @Override |
| 2465 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2466 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2469 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2470 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2471 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2472 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2473 | return -1; |
| 2474 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2475 | |
| 2476 | final long identity = Binder.clearCallingIdentity(); |
| 2477 | try { |
| 2478 | final Phone phone = getPhone(subId); |
| 2479 | if (phone != null) { |
| 2480 | return phone.getCdmaEriIconIndex(); |
| 2481 | } else { |
| 2482 | return -1; |
| 2483 | } |
| 2484 | } finally { |
| 2485 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2486 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | /** |
| 2490 | * Returns the CDMA ERI icon mode, |
| 2491 | * 0 - ON |
| 2492 | * 1 - FLASHING |
| 2493 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2494 | @Override |
| 2495 | public int getCdmaEriIconMode(String callingPackage) { |
| 2496 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2499 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2500 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2501 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2502 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2503 | return -1; |
| 2504 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2505 | |
| 2506 | final long identity = Binder.clearCallingIdentity(); |
| 2507 | try { |
| 2508 | final Phone phone = getPhone(subId); |
| 2509 | if (phone != null) { |
| 2510 | return phone.getCdmaEriIconMode(); |
| 2511 | } else { |
| 2512 | return -1; |
| 2513 | } |
| 2514 | } finally { |
| 2515 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2516 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | /** |
| 2520 | * Returns the CDMA ERI text, |
| 2521 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2522 | @Override |
| 2523 | public String getCdmaEriText(String callingPackage) { |
| 2524 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2527 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2528 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2529 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2530 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2531 | return null; |
| 2532 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2533 | |
| 2534 | final long identity = Binder.clearCallingIdentity(); |
| 2535 | try { |
| 2536 | final Phone phone = getPhone(subId); |
| 2537 | if (phone != null) { |
| 2538 | return phone.getCdmaEriText(); |
| 2539 | } else { |
| 2540 | return null; |
| 2541 | } |
| 2542 | } finally { |
| 2543 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2544 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2548 | * Returns the CDMA MDN. |
| 2549 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2550 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2551 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2552 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2553 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2554 | |
| 2555 | final long identity = Binder.clearCallingIdentity(); |
| 2556 | try { |
| 2557 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2558 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2559 | return phone.getLine1Number(); |
| 2560 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2561 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2562 | return null; |
| 2563 | } |
| 2564 | } finally { |
| 2565 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2566 | } |
| 2567 | } |
| 2568 | |
| 2569 | /** |
| 2570 | * Returns the CDMA MIN. |
| 2571 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2572 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2573 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2574 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2575 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2576 | |
| 2577 | final long identity = Binder.clearCallingIdentity(); |
| 2578 | try { |
| 2579 | final Phone phone = getPhone(subId); |
| 2580 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2581 | return phone.getCdmaMin(); |
| 2582 | } else { |
| 2583 | return null; |
| 2584 | } |
| 2585 | } finally { |
| 2586 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2587 | } |
| 2588 | } |
| 2589 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2590 | @Override |
| 2591 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2592 | INumberVerificationCallback callback, String callingPackage) { |
| 2593 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2594 | != PERMISSION_GRANTED) { |
| 2595 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2596 | } |
| 2597 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2598 | |
| 2599 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2600 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2601 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2602 | } |
| 2603 | |
| 2604 | if (range == null) { |
| 2605 | throw new NullPointerException("Range must be non-null"); |
| 2606 | } |
| 2607 | |
| 2608 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2609 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2610 | |
| 2611 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2612 | } |
| 2613 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2614 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2615 | * Returns true if CDMA provisioning needs to run. |
| 2616 | */ |
| 2617 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2618 | final long identity = Binder.clearCallingIdentity(); |
| 2619 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2620 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2621 | } finally { |
| 2622 | Binder.restoreCallingIdentity(identity); |
| 2623 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2627 | * Sets the voice mail number of a given subId. |
| 2628 | */ |
| 2629 | @Override |
| 2630 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2631 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2632 | |
| 2633 | final long identity = Binder.clearCallingIdentity(); |
| 2634 | try { |
| 2635 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2636 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2637 | return success; |
| 2638 | } finally { |
| 2639 | Binder.restoreCallingIdentity(identity); |
| 2640 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2641 | } |
| 2642 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2643 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2644 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2645 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2646 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2647 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2648 | throw new SecurityException("caller must be system dialer"); |
| 2649 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2650 | |
| 2651 | final long identity = Binder.clearCallingIdentity(); |
| 2652 | try { |
| 2653 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2654 | if (phoneAccountHandle == null) { |
| 2655 | return null; |
| 2656 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2657 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2658 | } finally { |
| 2659 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2660 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2664 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2665 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2666 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2667 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2668 | return null; |
| 2669 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2670 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2671 | final long identity = Binder.clearCallingIdentity(); |
| 2672 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2673 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2674 | } finally { |
| 2675 | Binder.restoreCallingIdentity(identity); |
| 2676 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2680 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2681 | VisualVoicemailSmsFilterSettings settings) { |
| 2682 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2683 | |
| 2684 | final long identity = Binder.clearCallingIdentity(); |
| 2685 | try { |
| 2686 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2687 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2688 | } finally { |
| 2689 | Binder.restoreCallingIdentity(identity); |
| 2690 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2694 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2695 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2696 | |
| 2697 | final long identity = Binder.clearCallingIdentity(); |
| 2698 | try { |
| 2699 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2700 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2701 | } finally { |
| 2702 | Binder.restoreCallingIdentity(identity); |
| 2703 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2707 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2708 | String callingPackage, int subId) { |
| 2709 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2710 | |
| 2711 | final long identity = Binder.clearCallingIdentity(); |
| 2712 | try { |
| 2713 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2714 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2715 | } finally { |
| 2716 | Binder.restoreCallingIdentity(identity); |
| 2717 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2721 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2722 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2723 | |
| 2724 | final long identity = Binder.clearCallingIdentity(); |
| 2725 | try { |
| 2726 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2727 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2728 | } finally { |
| 2729 | Binder.restoreCallingIdentity(identity); |
| 2730 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | @Override |
| 2734 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2735 | String number, int port, String text, PendingIntent sentIntent) { |
| 2736 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2737 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2738 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2739 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2740 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2741 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2742 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2743 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2744 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2745 | * Sets the voice activation state of a given subId. |
| 2746 | */ |
| 2747 | @Override |
| 2748 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2749 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2750 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2751 | |
| 2752 | final long identity = Binder.clearCallingIdentity(); |
| 2753 | try { |
| 2754 | final Phone phone = getPhone(subId); |
| 2755 | if (phone != null) { |
| 2756 | phone.setVoiceActivationState(activationState); |
| 2757 | } else { |
| 2758 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2759 | } |
| 2760 | } finally { |
| 2761 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2762 | } |
| 2763 | } |
| 2764 | |
| 2765 | /** |
| 2766 | * Sets the data activation state of a given subId. |
| 2767 | */ |
| 2768 | @Override |
| 2769 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2770 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2771 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2772 | |
| 2773 | final long identity = Binder.clearCallingIdentity(); |
| 2774 | try { |
| 2775 | final Phone phone = getPhone(subId); |
| 2776 | if (phone != null) { |
| 2777 | phone.setDataActivationState(activationState); |
| 2778 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 2779 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2780 | } |
| 2781 | } finally { |
| 2782 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2783 | } |
| 2784 | } |
| 2785 | |
| 2786 | /** |
| 2787 | * Returns the voice activation state of a given subId. |
| 2788 | */ |
| 2789 | @Override |
| 2790 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2791 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2792 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2793 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2794 | final long identity = Binder.clearCallingIdentity(); |
| 2795 | try { |
| 2796 | if (phone != null) { |
| 2797 | return phone.getVoiceActivationState(); |
| 2798 | } else { |
| 2799 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2800 | } |
| 2801 | } finally { |
| 2802 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | /** |
| 2807 | * Returns the data activation state of a given subId. |
| 2808 | */ |
| 2809 | @Override |
| 2810 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2811 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2812 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2813 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2814 | final long identity = Binder.clearCallingIdentity(); |
| 2815 | try { |
| 2816 | if (phone != null) { |
| 2817 | return phone.getDataActivationState(); |
| 2818 | } else { |
| 2819 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2820 | } |
| 2821 | } finally { |
| 2822 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2823 | } |
| 2824 | } |
| 2825 | |
| 2826 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2827 | * Returns the unread count of voicemails for a subId |
| 2828 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2829 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2830 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2831 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2832 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2833 | return 0; |
| 2834 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2835 | final long identity = Binder.clearCallingIdentity(); |
| 2836 | try { |
| 2837 | final Phone phone = getPhone(subId); |
| 2838 | if (phone != null) { |
| 2839 | return phone.getVoiceMessageCount(); |
| 2840 | } else { |
| 2841 | return 0; |
| 2842 | } |
| 2843 | } finally { |
| 2844 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2845 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2846 | } |
| 2847 | |
| 2848 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2849 | * returns true, if the device is in a state where both voice and data |
| 2850 | * are supported simultaneously. This can change based on location or network condition. |
| 2851 | */ |
| 2852 | @Override |
| 2853 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2854 | final long identity = Binder.clearCallingIdentity(); |
| 2855 | try { |
| 2856 | final Phone phone = getPhone(subId); |
| 2857 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2858 | } finally { |
| 2859 | Binder.restoreCallingIdentity(identity); |
| 2860 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2864 | * Send the dialer code if called from the current default dialer or the caller has |
| 2865 | * carrier privilege. |
| 2866 | * @param inputCode The dialer code to send |
| 2867 | */ |
| 2868 | @Override |
| 2869 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2870 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2871 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2872 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2873 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2874 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2875 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2876 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2877 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2878 | |
| 2879 | final long identity = Binder.clearCallingIdentity(); |
| 2880 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2881 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2882 | } finally { |
| 2883 | Binder.restoreCallingIdentity(identity); |
| 2884 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2885 | } |
| 2886 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2887 | @Override |
| 2888 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2889 | if (!isActiveSubscription(subId)) { |
| 2890 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2891 | } |
| 2892 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2893 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2894 | } |
| 2895 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2896 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2897 | public boolean isInEmergencySmsMode() { |
| 2898 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2899 | final long identity = Binder.clearCallingIdentity(); |
| 2900 | try { |
| 2901 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2902 | if (phone.isInEmergencySmsMode()) { |
| 2903 | return true; |
| 2904 | } |
| 2905 | } |
| 2906 | } finally { |
| 2907 | Binder.restoreCallingIdentity(identity); |
| 2908 | } |
| 2909 | return false; |
| 2910 | } |
| 2911 | |
| 2912 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2913 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2914 | throws RemoteException { |
| 2915 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2916 | final long token = Binder.clearCallingIdentity(); |
| 2917 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2918 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2919 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2920 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2921 | } catch (ImsException e) { |
| 2922 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2923 | } finally { |
| 2924 | Binder.restoreCallingIdentity(token); |
| 2925 | } |
| 2926 | } |
| 2927 | |
| 2928 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2929 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2930 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2931 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2932 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2933 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 2934 | final long token = Binder.clearCallingIdentity(); |
| 2935 | try { |
| 2936 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 2937 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 2938 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2939 | } catch (ImsException e) { |
| 2940 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2941 | + "is inactive, ignoring unregister."); |
| 2942 | // If the subscription is no longer active, just return, since the callback |
| 2943 | // will already have been removed internally. |
| 2944 | } finally { |
| 2945 | Binder.restoreCallingIdentity(token); |
| 2946 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2950 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2951 | throws RemoteException { |
| 2952 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2953 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2954 | final long token = Binder.clearCallingIdentity(); |
| 2955 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2956 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2957 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2958 | } catch (ImsException e) { |
| 2959 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2960 | } finally { |
| 2961 | Binder.restoreCallingIdentity(token); |
| 2962 | } |
| 2963 | } |
| 2964 | |
| 2965 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2966 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2967 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2968 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2969 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2970 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 2971 | |
| 2972 | final long token = Binder.clearCallingIdentity(); |
| 2973 | try { |
| 2974 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 2975 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2976 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 2977 | } catch (ImsException e) { |
| 2978 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2979 | + "is inactive, ignoring unregister."); |
| 2980 | // If the subscription is no longer active, just return, since the callback |
| 2981 | // will already have been removed internally. |
| 2982 | } finally { |
| 2983 | Binder.restoreCallingIdentity(token); |
| 2984 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2988 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2989 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2990 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2991 | final long token = Binder.clearCallingIdentity(); |
| 2992 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2993 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2994 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2995 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2996 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2997 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2998 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2999 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3000 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3001 | } finally { |
| 3002 | Binder.restoreCallingIdentity(token); |
| 3003 | } |
| 3004 | } |
| 3005 | |
| 3006 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3007 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3008 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3009 | final long token = Binder.clearCallingIdentity(); |
| 3010 | try { |
| 3011 | Phone phone = getPhone(subId); |
| 3012 | if (phone == null) return false; |
| 3013 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3014 | } finally { |
| 3015 | Binder.restoreCallingIdentity(token); |
| 3016 | } |
| 3017 | } |
| 3018 | |
| 3019 | @Override |
| 3020 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 3021 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 3022 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3023 | final long token = Binder.clearCallingIdentity(); |
| 3024 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3025 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3026 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3027 | } catch (ImsException e) { |
| 3028 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3029 | } finally { |
| 3030 | Binder.restoreCallingIdentity(token); |
| 3031 | } |
| 3032 | } |
| 3033 | |
| 3034 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3035 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3036 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3037 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3038 | final long identity = Binder.clearCallingIdentity(); |
| 3039 | try { |
| 3040 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3041 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3042 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3043 | } catch (ImsException e) { |
| 3044 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3045 | } finally { |
| 3046 | Binder.restoreCallingIdentity(identity); |
| 3047 | } |
| 3048 | } |
| 3049 | |
| 3050 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3051 | public boolean isVtSettingEnabled(int subId) { |
| 3052 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3053 | final long identity = Binder.clearCallingIdentity(); |
| 3054 | try { |
| 3055 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3056 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3057 | } catch (ImsException e) { |
| 3058 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3059 | } finally { |
| 3060 | Binder.restoreCallingIdentity(identity); |
| 3061 | } |
| 3062 | } |
| 3063 | |
| 3064 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3065 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3066 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3067 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3068 | final long identity = Binder.clearCallingIdentity(); |
| 3069 | try { |
| 3070 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3071 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3072 | } catch (ImsException e) { |
| 3073 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3074 | } finally { |
| 3075 | Binder.restoreCallingIdentity(identity); |
| 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | @Override |
| 3080 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3081 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3082 | final long identity = Binder.clearCallingIdentity(); |
| 3083 | try { |
| 3084 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3085 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3086 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3087 | } catch (ImsException e) { |
| 3088 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3089 | } finally { |
| 3090 | Binder.restoreCallingIdentity(identity); |
| 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3095 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3096 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3097 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3098 | final long identity = Binder.clearCallingIdentity(); |
| 3099 | try { |
| 3100 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3101 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3102 | } catch (ImsException e) { |
| 3103 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3104 | } finally { |
| 3105 | Binder.restoreCallingIdentity(identity); |
| 3106 | } |
| 3107 | } |
| 3108 | |
| 3109 | @Override |
| 3110 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3111 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3112 | final long identity = Binder.clearCallingIdentity(); |
| 3113 | try { |
| 3114 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3115 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3116 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3117 | } catch (ImsException e) { |
| 3118 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3119 | } finally { |
| 3120 | Binder.restoreCallingIdentity(identity); |
| 3121 | } |
| 3122 | } |
| 3123 | |
| 3124 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3125 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3126 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3127 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3128 | final long identity = Binder.clearCallingIdentity(); |
| 3129 | try { |
| 3130 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3131 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3132 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3133 | } catch (ImsException e) { |
| 3134 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3135 | } finally { |
| 3136 | Binder.restoreCallingIdentity(identity); |
| 3137 | } |
| 3138 | } |
| 3139 | |
| 3140 | @Override |
| 3141 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3142 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3143 | "setVoWiFiNonPersistent"); |
| 3144 | final long identity = Binder.clearCallingIdentity(); |
| 3145 | try { |
| 3146 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3147 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3148 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3149 | } catch (ImsException e) { |
| 3150 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3151 | } finally { |
| 3152 | Binder.restoreCallingIdentity(identity); |
| 3153 | } |
| 3154 | } |
| 3155 | |
| 3156 | @Override |
| 3157 | public int getVoWiFiModeSetting(int subId) { |
| 3158 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3159 | final long identity = Binder.clearCallingIdentity(); |
| 3160 | try { |
| 3161 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3162 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3163 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3164 | } catch (ImsException e) { |
| 3165 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3166 | } finally { |
| 3167 | Binder.restoreCallingIdentity(identity); |
| 3168 | } |
| 3169 | } |
| 3170 | |
| 3171 | @Override |
| 3172 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3173 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3174 | "setVoWiFiModeSetting"); |
| 3175 | final long identity = Binder.clearCallingIdentity(); |
| 3176 | try { |
| 3177 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3178 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3179 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3180 | } catch (ImsException e) { |
| 3181 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3182 | } finally { |
| 3183 | Binder.restoreCallingIdentity(identity); |
| 3184 | } |
| 3185 | } |
| 3186 | |
| 3187 | @Override |
| 3188 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3189 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3190 | final long identity = Binder.clearCallingIdentity(); |
| 3191 | try { |
| 3192 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3193 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3194 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3195 | } catch (ImsException e) { |
| 3196 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3197 | } finally { |
| 3198 | Binder.restoreCallingIdentity(identity); |
| 3199 | } |
| 3200 | } |
| 3201 | |
| 3202 | @Override |
| 3203 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3204 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3205 | "setVoWiFiRoamingModeSetting"); |
| 3206 | final long identity = Binder.clearCallingIdentity(); |
| 3207 | try { |
| 3208 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3209 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3210 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3211 | } catch (ImsException e) { |
| 3212 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3213 | } finally { |
| 3214 | Binder.restoreCallingIdentity(identity); |
| 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | @Override |
| 3219 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3220 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3221 | "setRttCapabilityEnabled"); |
| 3222 | final long identity = Binder.clearCallingIdentity(); |
| 3223 | try { |
| 3224 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3225 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3226 | } catch (ImsException e) { |
| 3227 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3228 | } finally { |
| 3229 | Binder.restoreCallingIdentity(identity); |
| 3230 | } |
| 3231 | } |
| 3232 | |
| 3233 | @Override |
| 3234 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3235 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3236 | final long identity = Binder.clearCallingIdentity(); |
| 3237 | try { |
| 3238 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3239 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3240 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3241 | } catch (ImsException e) { |
| 3242 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3243 | } finally { |
| 3244 | Binder.restoreCallingIdentity(identity); |
| 3245 | } |
| 3246 | } |
| 3247 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3248 | @Override |
| 3249 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3250 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3251 | final long identity = Binder.clearCallingIdentity(); |
| 3252 | try { |
| 3253 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3254 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3255 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3256 | } catch (ImsException e) { |
| 3257 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3258 | } finally { |
| 3259 | Binder.restoreCallingIdentity(identity); |
| 3260 | } |
| 3261 | } |
| 3262 | |
| 3263 | @Override |
| 3264 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3265 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3266 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3267 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3268 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3269 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3270 | try { |
| 3271 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3272 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3273 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3274 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3275 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3276 | + "is inactive, ignoring unregister."); |
| 3277 | // If the subscription is no longer active, just return, since the callback will already |
| 3278 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3279 | } finally { |
| 3280 | Binder.restoreCallingIdentity(identity); |
| 3281 | } |
| 3282 | } |
| 3283 | |
| 3284 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3285 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3286 | boolean isProvisioned) { |
| 3287 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3288 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3289 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3290 | } |
| 3291 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3292 | "setProvisioningStatusForCapability"); |
| 3293 | final long identity = Binder.clearCallingIdentity(); |
| 3294 | try { |
| 3295 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3296 | Phone phone = getPhone(subId); |
| 3297 | if (phone == null) { |
| 3298 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3299 | + subId); |
| 3300 | return; |
| 3301 | } |
| 3302 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3303 | return; |
| 3304 | } |
| 3305 | |
| 3306 | // this capability requires provisioning, route to the correct API. |
| 3307 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3308 | switch (capability) { |
| 3309 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3310 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3311 | ims.setVolteProvisioned(isProvisioned); |
| 3312 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3313 | ims.setWfcProvisioned(isProvisioned); |
| 3314 | } |
| 3315 | break; |
| 3316 | } |
| 3317 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3318 | // There is currently no difference in VT provisioning type. |
| 3319 | ims.setVtProvisioned(isProvisioned); |
| 3320 | break; |
| 3321 | } |
| 3322 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3323 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3324 | // change the capability of the feature instead if needed. |
| 3325 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3326 | == isProvisioned) { |
| 3327 | // No change in provisioning. |
| 3328 | return; |
| 3329 | } |
| 3330 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3331 | try { |
| 3332 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3333 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3334 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3335 | + ", Exception" + e.getMessage()); |
| 3336 | } |
| 3337 | break; |
| 3338 | } |
| 3339 | default: { |
| 3340 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3341 | + capability + "', which does not require provisioning."); |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | } finally { |
| 3346 | Binder.restoreCallingIdentity(identity); |
| 3347 | } |
| 3348 | } |
| 3349 | |
| 3350 | @Override |
| 3351 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3352 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3353 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3354 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3355 | } |
| 3356 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3357 | final long identity = Binder.clearCallingIdentity(); |
| 3358 | try { |
| 3359 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3360 | Phone phone = getPhone(subId); |
| 3361 | if (phone == null) { |
| 3362 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3363 | + subId); |
| 3364 | // We will fail with "true" as the provisioning status because this is the default |
| 3365 | // if we do not require provisioning. |
| 3366 | return true; |
| 3367 | } |
| 3368 | |
| 3369 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3370 | return true; |
| 3371 | } |
| 3372 | |
| 3373 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3374 | switch (capability) { |
| 3375 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3376 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3377 | return ims.isVolteProvisionedOnDevice(); |
| 3378 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3379 | return ims.isWfcProvisionedOnDevice(); |
| 3380 | } |
| 3381 | // This should never happen, since we are checking tech above to make sure it |
| 3382 | // is either LTE or IWLAN. |
| 3383 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3384 | + "capability."); |
| 3385 | } |
| 3386 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3387 | // There is currently no difference in VT provisioning type. |
| 3388 | return ims.isVtProvisionedOnDevice(); |
| 3389 | } |
| 3390 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3391 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3392 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3393 | } |
| 3394 | default: { |
| 3395 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3396 | + capability + "', which does not require provisioning."); |
| 3397 | } |
| 3398 | } |
| 3399 | |
| 3400 | } finally { |
| 3401 | Binder.restoreCallingIdentity(identity); |
| 3402 | } |
| 3403 | } |
| 3404 | |
| 3405 | @Override |
| 3406 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3407 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3408 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3409 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3410 | } |
| 3411 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3412 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3413 | return (provisionedBits & capability) > 0; |
| 3414 | } |
| 3415 | |
| 3416 | @Override |
| 3417 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3418 | boolean isProvisioned) { |
| 3419 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3420 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3421 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3422 | } |
| 3423 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3424 | "setProvisioningStatusForCapability"); |
| 3425 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3426 | // If the current provisioning status for capability already matches isProvisioned, |
| 3427 | // do nothing. |
| 3428 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3429 | return; |
| 3430 | } |
| 3431 | if (isProvisioned) { |
| 3432 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3433 | } else { |
| 3434 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | /** |
| 3439 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3440 | * technology. The bitfield should mirror the bitfield defined by |
| 3441 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3442 | */ |
| 3443 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3444 | String key = getMmTelProvisioningKey(subId, tech); |
| 3445 | // Default is no capabilities are provisioned. |
| 3446 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3447 | } |
| 3448 | |
| 3449 | /** |
| 3450 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3451 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3452 | * technology specified. |
| 3453 | * |
| 3454 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3455 | */ |
| 3456 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3457 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3458 | String key = getMmTelProvisioningKey(subId, tech); |
| 3459 | editor.putInt(key, newField); |
| 3460 | editor.commit(); |
| 3461 | } |
| 3462 | |
| 3463 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3464 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3465 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3466 | } |
| 3467 | |
| 3468 | /** |
| 3469 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3470 | * carrier associated with the subscription id. |
| 3471 | */ |
| 3472 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3473 | int capability) { |
| 3474 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3475 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3476 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3477 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3478 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3479 | false); |
| 3480 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3481 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3482 | |
| 3483 | // First check to make sure that the capability requires provisioning. |
| 3484 | switch (capability) { |
| 3485 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3486 | // intentional fallthrough |
| 3487 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3488 | if (requireVoiceVtProvisioning) { |
| 3489 | // Voice and Video requires provisioning |
| 3490 | return true; |
| 3491 | } |
| 3492 | break; |
| 3493 | } |
| 3494 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3495 | if (requireUtProvisioning) { |
| 3496 | // UT requires provisioning |
| 3497 | return true; |
| 3498 | } |
| 3499 | break; |
| 3500 | } |
| 3501 | } |
| 3502 | return false; |
| 3503 | } |
| 3504 | |
| 3505 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3506 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3507 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3508 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3509 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3510 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3511 | final long identity = Binder.clearCallingIdentity(); |
| 3512 | try { |
| 3513 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3514 | int slotId = getSlotIndex(subId); |
| 3515 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3516 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3517 | + subId + "' for key:" + key); |
| 3518 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3519 | } |
| 3520 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3521 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3522 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3523 | + subId + "' for key:" + key); |
| 3524 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3525 | } finally { |
| 3526 | Binder.restoreCallingIdentity(identity); |
| 3527 | } |
| 3528 | } |
| 3529 | |
| 3530 | @Override |
| 3531 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3532 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3533 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3534 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3535 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3536 | final long identity = Binder.clearCallingIdentity(); |
| 3537 | try { |
| 3538 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3539 | int slotId = getSlotIndex(subId); |
| 3540 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3541 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3542 | + subId + "' for key:" + key); |
| 3543 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3544 | } |
| 3545 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3546 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3547 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3548 | + subId + "' for key:" + key); |
| 3549 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3550 | } finally { |
| 3551 | Binder.restoreCallingIdentity(identity); |
| 3552 | } |
| 3553 | } |
| 3554 | |
| 3555 | @Override |
| 3556 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3557 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3558 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3559 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3560 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3561 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3562 | final long identity = Binder.clearCallingIdentity(); |
| 3563 | try { |
| 3564 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3565 | int slotId = getSlotIndex(subId); |
| 3566 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3567 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3568 | + subId + "' for key:" + key); |
| 3569 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3570 | } |
| 3571 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3572 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3573 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3574 | + "' for key:" + key); |
| 3575 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3576 | } finally { |
| 3577 | Binder.restoreCallingIdentity(identity); |
| 3578 | } |
| 3579 | } |
| 3580 | |
| 3581 | @Override |
| 3582 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3583 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3584 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3585 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3587 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3588 | final long identity = Binder.clearCallingIdentity(); |
| 3589 | try { |
| 3590 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3591 | int slotId = getSlotIndex(subId); |
| 3592 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3593 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3594 | + subId + "' for key:" + key); |
| 3595 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3596 | } |
| 3597 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3598 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3599 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3600 | + "' for key:" + key); |
| 3601 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3602 | } finally { |
| 3603 | Binder.restoreCallingIdentity(identity); |
| 3604 | } |
| 3605 | } |
| 3606 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3607 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3608 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3609 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3610 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 3611 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3612 | } |
| 3613 | return slotId; |
| 3614 | } |
| 3615 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3616 | private int getSlotIndex(int subId) { |
| 3617 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3618 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3619 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3620 | } |
| 3621 | return slotId; |
| 3622 | } |
| 3623 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3624 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3625 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3626 | */ |
| 3627 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3628 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3629 | final int targetSdk = getTargetSdk(callingPackage); |
| 3630 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
| 3631 | return getDataNetworkTypeForSubscriber(subId, callingPackage); |
| 3632 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3633 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
| 3634 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3635 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3636 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3637 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3638 | final long identity = Binder.clearCallingIdentity(); |
| 3639 | try { |
| 3640 | final Phone phone = getPhone(subId); |
| 3641 | if (phone != null) { |
| 3642 | return phone.getServiceState().getDataNetworkType(); |
| 3643 | } else { |
| 3644 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3645 | } |
| 3646 | } finally { |
| 3647 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3648 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3649 | } |
| 3650 | |
| 3651 | /** |
| 3652 | * Returns the data network type |
| 3653 | */ |
| 3654 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3655 | public int getDataNetworkType(String callingPackage) { |
| 3656 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | /** |
| 3660 | * Returns the data network type for a subId |
| 3661 | */ |
| 3662 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3663 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3664 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3665 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3666 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3667 | } |
| 3668 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3669 | final long identity = Binder.clearCallingIdentity(); |
| 3670 | try { |
| 3671 | final Phone phone = getPhone(subId); |
| 3672 | if (phone != null) { |
| 3673 | return phone.getServiceState().getDataNetworkType(); |
| 3674 | } else { |
| 3675 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3676 | } |
| 3677 | } finally { |
| 3678 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3679 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3680 | } |
| 3681 | |
| 3682 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3683 | * Returns the Voice network type for a subId |
| 3684 | */ |
| 3685 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3686 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3687 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3688 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3689 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3690 | } |
| 3691 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3692 | final long identity = Binder.clearCallingIdentity(); |
| 3693 | try { |
| 3694 | final Phone phone = getPhone(subId); |
| 3695 | if (phone != null) { |
| 3696 | return phone.getServiceState().getVoiceNetworkType(); |
| 3697 | } else { |
| 3698 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3699 | } |
| 3700 | } finally { |
| 3701 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3702 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3703 | } |
| 3704 | |
| 3705 | /** |
| 3706 | * @return true if a ICC card is present |
| 3707 | */ |
| 3708 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3709 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3710 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3711 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3712 | } |
| 3713 | |
| 3714 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3715 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3716 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3717 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3718 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3719 | final long identity = Binder.clearCallingIdentity(); |
| 3720 | try { |
| 3721 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3722 | if (phone != null) { |
| 3723 | return phone.getIccCard().hasIccCard(); |
| 3724 | } else { |
| 3725 | return false; |
| 3726 | } |
| 3727 | } finally { |
| 3728 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3729 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3730 | } |
| 3731 | |
| 3732 | /** |
| 3733 | * Return if the current radio is LTE on CDMA. This |
| 3734 | * is a tri-state return value as for a period of time |
| 3735 | * the mode may be unknown. |
| 3736 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3737 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3738 | * @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] | 3739 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3740 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3741 | @Override |
| 3742 | public int getLteOnCdmaMode(String callingPackage) { |
| 3743 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3744 | } |
| 3745 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3746 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3747 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3748 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3749 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3750 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3751 | } |
| 3752 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3753 | final long identity = Binder.clearCallingIdentity(); |
| 3754 | try { |
| 3755 | final Phone phone = getPhone(subId); |
| 3756 | if (phone == null) { |
| 3757 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3758 | } else { |
| 3759 | return phone.getLteOnCdmaMode(); |
| 3760 | } |
| 3761 | } finally { |
| 3762 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3763 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3764 | } |
| 3765 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3766 | /** |
| 3767 | * {@hide} |
| 3768 | * Returns Default subId, 0 in the case of single standby. |
| 3769 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3770 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3771 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3772 | } |
| 3773 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3774 | private int getSlotForDefaultSubscription() { |
| 3775 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3776 | } |
| 3777 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3778 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3779 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3780 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3781 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3782 | private boolean isActiveSubscription(int subId) { |
| 3783 | return mSubscriptionController.isActiveSubId(subId); |
| 3784 | } |
| 3785 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3786 | /** |
| 3787 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3788 | */ |
| 3789 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3790 | final long identity = Binder.clearCallingIdentity(); |
| 3791 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3792 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3793 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3794 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3795 | } finally { |
| 3796 | Binder.restoreCallingIdentity(identity); |
| 3797 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | /** |
| 3801 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3802 | */ |
| 3803 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3804 | final long identity = Binder.clearCallingIdentity(); |
| 3805 | try { |
| 3806 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3807 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3808 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3809 | } finally { |
| 3810 | Binder.restoreCallingIdentity(identity); |
| 3811 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3812 | } |
| 3813 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3814 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3815 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3816 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3817 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3818 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3819 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3820 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3821 | if (phoneId == -1) { |
| 3822 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3823 | + " does not correspond to an active phone"); |
| 3824 | } |
| 3825 | return PhoneFactory.getPhone(phoneId); |
| 3826 | } |
| 3827 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3828 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3829 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3830 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3831 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3832 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3833 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3834 | if (DBG) { |
| 3835 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3836 | } |
| 3837 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3838 | p2); |
| 3839 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3840 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3841 | |
| 3842 | @Override |
| 3843 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3844 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3845 | enforceModifyPermission(); |
| 3846 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3847 | if (DBG) { |
| 3848 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3849 | } |
| 3850 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3851 | callingPackage, aid, p2); |
| 3852 | } |
| 3853 | |
| 3854 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3855 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3856 | final long identity = Binder.clearCallingIdentity(); |
| 3857 | try { |
| 3858 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3859 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3860 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3861 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3862 | if (bestComponent == null |
| 3863 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3864 | loge("The calling package is not allowed to access ISD-R."); |
| 3865 | throw new SecurityException( |
| 3866 | "The calling package is not allowed to access ISD-R."); |
| 3867 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3868 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3869 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3870 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3871 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3872 | null /* workSource */); |
| 3873 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3874 | return response; |
| 3875 | } finally { |
| 3876 | Binder.restoreCallingIdentity(identity); |
| 3877 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3881 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3882 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3883 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3884 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3885 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3886 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3887 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3888 | @Override |
| 3889 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3890 | enforceModifyPermission(); |
| 3891 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3892 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3893 | channel); |
| 3894 | } |
| 3895 | |
| 3896 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3897 | final long identity = Binder.clearCallingIdentity(); |
| 3898 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3899 | if (channel < 0) { |
| 3900 | return false; |
| 3901 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3902 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3903 | null /* workSource */); |
| 3904 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3905 | return success; |
| 3906 | } finally { |
| 3907 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3908 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3912 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3913 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3914 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3915 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3916 | if (DBG) { |
| 3917 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3918 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3919 | + p3 + " data=" + data); |
| 3920 | } |
| 3921 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3922 | command, p1, p2, p3, data); |
| 3923 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3924 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3925 | @Override |
| 3926 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3927 | int command, int p1, int p2, int p3, String data) { |
| 3928 | enforceModifyPermission(); |
| 3929 | if (DBG) { |
| 3930 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3931 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3932 | + p3 + " data=" + data); |
| 3933 | } |
| 3934 | return iccTransmitApduLogicalChannelWithPermission( |
| 3935 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3936 | data); |
| 3937 | } |
| 3938 | |
| 3939 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3940 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3941 | final long identity = Binder.clearCallingIdentity(); |
| 3942 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 3943 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3944 | return ""; |
| 3945 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3946 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3947 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3948 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3949 | null /* workSource */); |
| 3950 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3951 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3952 | // Append the returned status code to the end of the response payload. |
| 3953 | String s = Integer.toHexString( |
| 3954 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3955 | if (response.payload != null) { |
| 3956 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3957 | } |
| 3958 | return s; |
| 3959 | } finally { |
| 3960 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3961 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3962 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3963 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3964 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3965 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3966 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3967 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3968 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3969 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3970 | if (DBG) { |
| 3971 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3972 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3973 | } |
| 3974 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3975 | cla, command, p1, p2, p3, data); |
| 3976 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3977 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3978 | @Override |
| 3979 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3980 | int command, int p1, int p2, int p3, String data) { |
| 3981 | enforceModifyPermission(); |
| 3982 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3983 | if (DBG) { |
| 3984 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3985 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3986 | + " data=" + data); |
| 3987 | } |
| 3988 | |
| 3989 | return iccTransmitApduBasicChannelWithPermission( |
| 3990 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3991 | p2, p3, data); |
| 3992 | } |
| 3993 | |
| 3994 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3995 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3996 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3997 | final long identity = Binder.clearCallingIdentity(); |
| 3998 | try { |
| 3999 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4000 | && TextUtils.equals(ISDR_AID, data)) { |
| 4001 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4002 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4003 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4004 | if (bestComponent == null |
| 4005 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4006 | loge("The calling package is not allowed to select ISD-R."); |
| 4007 | throw new SecurityException( |
| 4008 | "The calling package is not allowed to select ISD-R."); |
| 4009 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4010 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4011 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4012 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4013 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4014 | null /* workSource */); |
| 4015 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4016 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4017 | // Append the returned status code to the end of the response payload. |
| 4018 | String s = Integer.toHexString( |
| 4019 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4020 | if (response.payload != null) { |
| 4021 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4022 | } |
| 4023 | return s; |
| 4024 | } finally { |
| 4025 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4026 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
| 4029 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4030 | 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] | 4031 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4032 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4033 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4034 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4035 | final long identity = Binder.clearCallingIdentity(); |
| 4036 | try { |
| 4037 | if (DBG) { |
| 4038 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4039 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4040 | } |
| 4041 | |
| 4042 | IccIoResult response = |
| 4043 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4044 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4045 | subId); |
| 4046 | |
| 4047 | if (DBG) { |
| 4048 | log("Exchange SIM_IO [R]" + response); |
| 4049 | } |
| 4050 | |
| 4051 | byte[] result = null; |
| 4052 | int length = 2; |
| 4053 | if (response.payload != null) { |
| 4054 | length = 2 + response.payload.length; |
| 4055 | result = new byte[length]; |
| 4056 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4057 | } else { |
| 4058 | result = new byte[length]; |
| 4059 | } |
| 4060 | |
| 4061 | result[length - 1] = (byte) response.sw2; |
| 4062 | result[length - 2] = (byte) response.sw1; |
| 4063 | return result; |
| 4064 | } finally { |
| 4065 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4066 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4067 | } |
| 4068 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4069 | /** |
| 4070 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4071 | * on a particular subscription |
| 4072 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4073 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 4074 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4075 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 4076 | return null; |
| 4077 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4078 | |
| 4079 | final long identity = Binder.clearCallingIdentity(); |
| 4080 | try { |
| 4081 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4082 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4083 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4084 | return null; |
| 4085 | } |
| 4086 | Object response = sendRequest( |
| 4087 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4088 | if (response instanceof String[]) { |
| 4089 | return (String[]) response; |
| 4090 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4091 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4092 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4093 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4094 | } finally { |
| 4095 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4096 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4097 | } |
| 4098 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4099 | /** |
| 4100 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4101 | * subscription. |
| 4102 | * |
| 4103 | * @param subId the id of the subscription. |
| 4104 | * @param appType the uicc app type, must be USIM or SIM. |
| 4105 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4106 | * @param callingPackage the op Package name. |
| 4107 | * @return number of fplmns that is successfully written to the SIM. |
| 4108 | */ |
| 4109 | public int setForbiddenPlmns( |
| 4110 | int subId, int appType, List<String> fplmns, String callingPackage) { |
| 4111 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4112 | mApp, subId, callingPackage, "setForbiddenPlmns")) { |
| 4113 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4114 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4115 | } |
| 4116 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4117 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4118 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4119 | } |
| 4120 | if (fplmns == null) { |
| 4121 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4122 | } |
| 4123 | for (String fplmn : fplmns) { |
| 4124 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4125 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4126 | } |
| 4127 | } |
| 4128 | final long identity = Binder.clearCallingIdentity(); |
| 4129 | try { |
| 4130 | Object response = sendRequest( |
| 4131 | CMD_SET_FORBIDDEN_PLMNS, |
| 4132 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4133 | subId); |
| 4134 | return (int) response; |
| 4135 | } finally { |
| 4136 | Binder.restoreCallingIdentity(identity); |
| 4137 | } |
| 4138 | } |
| 4139 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4140 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4141 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4142 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4143 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4144 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4145 | final long identity = Binder.clearCallingIdentity(); |
| 4146 | try { |
| 4147 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4148 | if (response.payload == null) { |
| 4149 | return ""; |
| 4150 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4151 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4152 | // Append the returned status code to the end of the response payload. |
| 4153 | String s = Integer.toHexString( |
| 4154 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4155 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4156 | return s; |
| 4157 | } finally { |
| 4158 | Binder.restoreCallingIdentity(identity); |
| 4159 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4160 | } |
| 4161 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4162 | /** |
| 4163 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4164 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4165 | * |
| 4166 | * @param itemID the ID of the item to read |
| 4167 | * @return the NV item as a String, or null on error. |
| 4168 | */ |
| 4169 | @Override |
| 4170 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4171 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4172 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4173 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4174 | |
| 4175 | final long identity = Binder.clearCallingIdentity(); |
| 4176 | try { |
| 4177 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4178 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4179 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4180 | return value; |
| 4181 | } finally { |
| 4182 | Binder.restoreCallingIdentity(identity); |
| 4183 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | /** |
| 4187 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4188 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4189 | * |
| 4190 | * @param itemID the ID of the item to read |
| 4191 | * @param itemValue the value to write, as a String |
| 4192 | * @return true on success; false on any failure |
| 4193 | */ |
| 4194 | @Override |
| 4195 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4196 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4197 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4198 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4199 | |
| 4200 | final long identity = Binder.clearCallingIdentity(); |
| 4201 | try { |
| 4202 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4203 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4204 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4205 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4206 | return success; |
| 4207 | } finally { |
| 4208 | Binder.restoreCallingIdentity(identity); |
| 4209 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4210 | } |
| 4211 | |
| 4212 | /** |
| 4213 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4214 | * Used for device configuration by some CDMA operators. |
| 4215 | * |
| 4216 | * @param preferredRoamingList byte array containing the new PRL |
| 4217 | * @return true on success; false on any failure |
| 4218 | */ |
| 4219 | @Override |
| 4220 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4221 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4222 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4223 | |
| 4224 | final long identity = Binder.clearCallingIdentity(); |
| 4225 | try { |
| 4226 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4227 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4228 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4229 | return success; |
| 4230 | } finally { |
| 4231 | Binder.restoreCallingIdentity(identity); |
| 4232 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4233 | } |
| 4234 | |
| 4235 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4236 | * 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] | 4237 | * Used for device configuration by some CDMA operators. |
| 4238 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4239 | * @param slotIndex - device slot. |
| 4240 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4241 | * @return true on success; false on any failure |
| 4242 | */ |
| 4243 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4244 | public boolean resetModemConfig(int slotIndex) { |
| 4245 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4246 | if (phone != null) { |
| 4247 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4248 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4249 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4250 | final long identity = Binder.clearCallingIdentity(); |
| 4251 | try { |
| 4252 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4253 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4254 | return success; |
| 4255 | } finally { |
| 4256 | Binder.restoreCallingIdentity(identity); |
| 4257 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4258 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4259 | return false; |
| 4260 | } |
| 4261 | |
| 4262 | /** |
| 4263 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4264 | * |
| 4265 | * @param slotIndex - device slot. |
| 4266 | * |
| 4267 | * @return true on success; false on any failure |
| 4268 | */ |
| 4269 | @Override |
| 4270 | public boolean rebootModem(int slotIndex) { |
| 4271 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4272 | if (phone != null) { |
| 4273 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4274 | mApp, phone.getSubId(), "rebootModem"); |
| 4275 | |
| 4276 | final long identity = Binder.clearCallingIdentity(); |
| 4277 | try { |
| 4278 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4279 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4280 | return success; |
| 4281 | } finally { |
| 4282 | Binder.restoreCallingIdentity(identity); |
| 4283 | } |
| 4284 | } |
| 4285 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4286 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4287 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4288 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4289 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4290 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4291 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4292 | return new String[0]; |
| 4293 | } |
| 4294 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4295 | final long identity = Binder.clearCallingIdentity(); |
| 4296 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4297 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4298 | } finally { |
| 4299 | Binder.restoreCallingIdentity(identity); |
| 4300 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4301 | } |
| 4302 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4303 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4304 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4305 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4306 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4307 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4308 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4309 | |
| 4310 | final long identity = Binder.clearCallingIdentity(); |
| 4311 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4312 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4313 | if (resolver == null) { |
| 4314 | // may happen if the device does not support IMS. |
| 4315 | return; |
| 4316 | } |
| 4317 | resolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4318 | } finally { |
| 4319 | Binder.restoreCallingIdentity(identity); |
| 4320 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4324 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4325 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4326 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4327 | public void disableIms(int slotId) { |
| 4328 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4329 | |
| 4330 | final long identity = Binder.clearCallingIdentity(); |
| 4331 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4332 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4333 | if (resolver == null) { |
| 4334 | // may happen if the device does not support IMS. |
| 4335 | return; |
| 4336 | } |
| 4337 | resolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4338 | } finally { |
| 4339 | Binder.restoreCallingIdentity(identity); |
| 4340 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | /** |
| 4344 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4345 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4346 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4347 | */ |
| 4348 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4349 | IImsServiceFeatureCallback callback) { |
| 4350 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4351 | |
| 4352 | final long identity = Binder.clearCallingIdentity(); |
| 4353 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4354 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4355 | if (resolver == null) { |
| 4356 | // may happen if the device does not support IMS. |
| 4357 | return null; |
| 4358 | } |
| 4359 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4360 | } finally { |
| 4361 | Binder.restoreCallingIdentity(identity); |
| 4362 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4363 | } |
| 4364 | |
| 4365 | /** |
| 4366 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4367 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4368 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4369 | * listener for feature updates. |
| 4370 | */ |
| 4371 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4372 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4373 | |
| 4374 | final long identity = Binder.clearCallingIdentity(); |
| 4375 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4376 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4377 | if (resolver == null) { |
| 4378 | // may happen if the device does not support IMS. |
| 4379 | return null; |
| 4380 | } |
| 4381 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4382 | } finally { |
| 4383 | Binder.restoreCallingIdentity(identity); |
| 4384 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4385 | } |
| 4386 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4387 | /** |
| 4388 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4389 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4390 | */ |
| 4391 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4392 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4393 | |
| 4394 | final long identity = Binder.clearCallingIdentity(); |
| 4395 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4396 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4397 | if (resolver == null) { |
| 4398 | // may happen if the device does not support IMS. |
| 4399 | return null; |
| 4400 | } |
| 4401 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4402 | } finally { |
| 4403 | Binder.restoreCallingIdentity(identity); |
| 4404 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4405 | } |
| 4406 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4407 | /** |
| 4408 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4409 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4410 | */ |
| 4411 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4412 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4413 | |
| 4414 | final long identity = Binder.clearCallingIdentity(); |
| 4415 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4416 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4417 | if (resolver == null) { |
| 4418 | // may happen if the device does not support IMS. |
| 4419 | return null; |
| 4420 | } |
| 4421 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4422 | } finally { |
| 4423 | Binder.restoreCallingIdentity(identity); |
| 4424 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4425 | } |
| 4426 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4427 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4428 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4429 | * |
| 4430 | * @param slotId the slot ID that the ImsService should bind for. |
| 4431 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4432 | * ImsService is the device default ImsService. |
| 4433 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4434 | * to. |
| 4435 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4436 | * @hide |
| 4437 | */ |
| 4438 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4439 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4440 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4441 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4442 | "setImsService"); |
| 4443 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4444 | final long identity = Binder.clearCallingIdentity(); |
| 4445 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4446 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4447 | if (resolver == null) { |
| 4448 | // may happen if the device does not support IMS. |
| 4449 | return false; |
| 4450 | } |
| 4451 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4452 | packageName); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4453 | } finally { |
| 4454 | Binder.restoreCallingIdentity(identity); |
| 4455 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4456 | } |
| 4457 | |
| 4458 | /** |
| 4459 | * Return the ImsService configuration. |
| 4460 | * |
| 4461 | * @param slotId The slot that the ImsService is associated with. |
| 4462 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4463 | * the device default. |
| 4464 | * @return the package name of the ImsService configuration. |
| 4465 | */ |
| 4466 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4467 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4468 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4469 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4470 | "getImsService"); |
| 4471 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4472 | final long identity = Binder.clearCallingIdentity(); |
| 4473 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4474 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4475 | if (resolver == null) { |
| 4476 | // may happen if the device does not support IMS. |
| 4477 | return ""; |
| 4478 | } |
| 4479 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4480 | } finally { |
| 4481 | Binder.restoreCallingIdentity(identity); |
| 4482 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4483 | } |
| 4484 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4485 | public void setImsRegistrationState(boolean registered) { |
| 4486 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4487 | |
| 4488 | final long identity = Binder.clearCallingIdentity(); |
| 4489 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4490 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4491 | } finally { |
| 4492 | Binder.restoreCallingIdentity(identity); |
| 4493 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4494 | } |
| 4495 | |
| 4496 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4497 | * Set the network selection mode to automatic. |
| 4498 | * |
| 4499 | */ |
| 4500 | @Override |
| 4501 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4503 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4504 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4505 | if (!isActiveSubscription(subId)) { |
| 4506 | return; |
| 4507 | } |
| 4508 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4509 | final long identity = Binder.clearCallingIdentity(); |
| 4510 | try { |
| 4511 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4512 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4513 | } finally { |
| 4514 | Binder.restoreCallingIdentity(identity); |
| 4515 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4516 | } |
| 4517 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4518 | /** |
| 4519 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4520 | * |
| 4521 | * @param subId the id of the subscription. |
| 4522 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4523 | * the operator to attach to. |
| 4524 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4525 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4526 | * normal network selection next time. |
| 4527 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4528 | */ |
| 4529 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4530 | public boolean setNetworkSelectionModeManual( |
| 4531 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4532 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4533 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4534 | |
| 4535 | if (!isActiveSubscription(subId)) { |
| 4536 | return false; |
| 4537 | } |
| 4538 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4539 | final long identity = Binder.clearCallingIdentity(); |
| 4540 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4541 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4542 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4543 | if (DBG) { |
| 4544 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4545 | + " operator: " + operatorInfo); |
| 4546 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4547 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4548 | } finally { |
| 4549 | Binder.restoreCallingIdentity(identity); |
| 4550 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4551 | } |
| 4552 | |
| 4553 | /** |
| 4554 | * Scans for available networks. |
| 4555 | */ |
| 4556 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4557 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4558 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4559 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4560 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4561 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4562 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4563 | .setCallingPackage(callingPackage) |
| 4564 | .setCallingPid(Binder.getCallingPid()) |
| 4565 | .setCallingUid(Binder.getCallingUid()) |
| 4566 | .setMethod("getCellNetworkScanResults") |
| 4567 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4568 | .build()); |
| 4569 | switch (locationResult) { |
| 4570 | case DENIED_HARD: |
| 4571 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4572 | case DENIED_SOFT: |
| 4573 | return null; |
| 4574 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4575 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4576 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4577 | try { |
| 4578 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4579 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4580 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4581 | } finally { |
| 4582 | Binder.restoreCallingIdentity(identity); |
| 4583 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4584 | } |
| 4585 | |
| 4586 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4587 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4588 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4589 | * @param subId id of the subscription |
| 4590 | * @param request contains the radio access networks with bands/channels to scan |
| 4591 | * @param messenger callback messenger for scan results or errors |
| 4592 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4593 | * @return the id of the requested scan which can be used to stop the scan. |
| 4594 | */ |
| 4595 | @Override |
| 4596 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4597 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4598 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4599 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4600 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4601 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4602 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4603 | .setCallingPackage(callingPackage) |
| 4604 | .setCallingPid(Binder.getCallingPid()) |
| 4605 | .setCallingUid(Binder.getCallingUid()) |
| 4606 | .setMethod("requestNetworkScan") |
| 4607 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4608 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4609 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4610 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4611 | if (e != null) { |
| 4612 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4613 | throw e; |
| 4614 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4615 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4616 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4617 | } |
| 4618 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4619 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4620 | int callingUid = Binder.getCallingUid(); |
| 4621 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4622 | final long identity = Binder.clearCallingIdentity(); |
| 4623 | try { |
| 4624 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4625 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4626 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4627 | } finally { |
| 4628 | Binder.restoreCallingIdentity(identity); |
| 4629 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4630 | } |
| 4631 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4632 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4633 | NetworkScanRequest request, int subId) { |
| 4634 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4635 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4636 | boolean hasNetworkScanPermission = |
| 4637 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4638 | == PERMISSION_GRANTED; |
| 4639 | |
| 4640 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4641 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4642 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4643 | } |
| 4644 | |
| 4645 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4646 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4647 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4648 | return new SecurityException("Specific channels must not be" |
| 4649 | + " scanned without location access."); |
| 4650 | } |
| 4651 | } |
| 4652 | } |
| 4653 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4654 | return null; |
| 4655 | } |
| 4656 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4657 | /** |
| 4658 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4659 | * |
| 4660 | * @param subId id of the subscription |
| 4661 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4662 | */ |
| 4663 | @Override |
| 4664 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4665 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4666 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4667 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4668 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4669 | final long identity = Binder.clearCallingIdentity(); |
| 4670 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4671 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4672 | } finally { |
| 4673 | Binder.restoreCallingIdentity(identity); |
| 4674 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4675 | } |
| 4676 | |
| 4677 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4678 | * Get the calculated preferred network type. |
| 4679 | * Used for debugging incorrect network type. |
| 4680 | * |
| 4681 | * @return the preferred network type, defined in RILConstants.java. |
| 4682 | */ |
| 4683 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4684 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4685 | final Phone defaultPhone = getDefaultPhone(); |
| 4686 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4687 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4688 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4689 | } |
| 4690 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4691 | final long identity = Binder.clearCallingIdentity(); |
| 4692 | try { |
| 4693 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4694 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4695 | } finally { |
| 4696 | Binder.restoreCallingIdentity(identity); |
| 4697 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4698 | } |
| 4699 | |
| 4700 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4701 | * Get the preferred network type. |
| 4702 | * Used for device configuration by some CDMA operators. |
| 4703 | * |
| 4704 | * @return the preferred network type, defined in RILConstants.java. |
| 4705 | */ |
| 4706 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4707 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4708 | TelephonyPermissions |
| 4709 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4710 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4711 | |
| 4712 | final long identity = Binder.clearCallingIdentity(); |
| 4713 | try { |
| 4714 | if (DBG) log("getPreferredNetworkType"); |
| 4715 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4716 | int networkType = (result != null ? result[0] : -1); |
| 4717 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4718 | return networkType; |
| 4719 | } finally { |
| 4720 | Binder.restoreCallingIdentity(identity); |
| 4721 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4722 | } |
| 4723 | |
| 4724 | /** |
| 4725 | * Set the preferred network type. |
| 4726 | * Used for device configuration by some CDMA operators. |
| 4727 | * |
| 4728 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4729 | * @return true on success; false on any failure. |
| 4730 | */ |
| 4731 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4732 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4733 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4734 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4735 | |
| 4736 | final long identity = Binder.clearCallingIdentity(); |
| 4737 | try { |
| 4738 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4739 | Boolean success = (Boolean) sendRequest( |
| 4740 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4741 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4742 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4743 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4744 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4745 | } |
| 4746 | return success; |
| 4747 | } finally { |
| 4748 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4749 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4750 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4751 | |
| 4752 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4753 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4754 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4755 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4756 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4757 | * @hide |
| 4758 | */ |
| 4759 | @Override |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4760 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4761 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4762 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4763 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4764 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4765 | if (phone != null) { |
| 4766 | return phone.hasMatchedTetherApnSetting(); |
| 4767 | } else { |
| 4768 | return false; |
| 4769 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4770 | } finally { |
| 4771 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4772 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4773 | } |
| 4774 | |
| 4775 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4776 | * Set mobile data enabled |
| 4777 | * Used by the user through settings etc to turn on/off mobile data |
| 4778 | * |
| 4779 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4780 | */ |
| 4781 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4782 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4783 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4784 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4785 | |
| 4786 | final long identity = Binder.clearCallingIdentity(); |
| 4787 | try { |
| 4788 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4789 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4790 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4791 | if (phone != null) { |
| 4792 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4793 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4794 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4795 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4796 | } |
| 4797 | } finally { |
| 4798 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4799 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4800 | } |
| 4801 | |
| 4802 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4803 | * Get the user enabled state of Mobile Data. |
| 4804 | * |
| 4805 | * TODO: remove and use isUserDataEnabled. |
| 4806 | * This can't be removed now because some vendor codes |
| 4807 | * calls through ITelephony directly while they should |
| 4808 | * use TelephonyManager. |
| 4809 | * |
| 4810 | * @return true on enabled |
| 4811 | */ |
| 4812 | @Override |
| 4813 | public boolean getDataEnabled(int subId) { |
| 4814 | return isUserDataEnabled(subId); |
| 4815 | } |
| 4816 | |
| 4817 | /** |
| 4818 | * Get whether mobile data is enabled per user setting. |
| 4819 | * |
| 4820 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4821 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4822 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4823 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4824 | * |
| 4825 | * @return {@code true} if data is enabled else {@code false} |
| 4826 | */ |
| 4827 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4828 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4829 | try { |
| 4830 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4831 | null); |
| 4832 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4833 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4834 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4835 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4836 | |
| 4837 | final long identity = Binder.clearCallingIdentity(); |
| 4838 | try { |
| 4839 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4840 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4841 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4842 | if (phone != null) { |
| 4843 | boolean retVal = phone.isUserDataEnabled(); |
| 4844 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4845 | return retVal; |
| 4846 | } else { |
| 4847 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4848 | return false; |
| 4849 | } |
| 4850 | } finally { |
| 4851 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4852 | } |
| 4853 | } |
| 4854 | |
| 4855 | /** |
| 4856 | * Get whether mobile data is enabled. |
| 4857 | * |
| 4858 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4859 | * whether mobile data is actually enabled. |
| 4860 | * |
| 4861 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4862 | * |
| 4863 | * @return {@code true} if data is enabled else {@code false} |
| 4864 | */ |
| 4865 | @Override |
| 4866 | public boolean isDataEnabled(int subId) { |
| 4867 | try { |
| 4868 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4869 | null); |
| 4870 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4871 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4872 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4873 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4874 | |
| 4875 | final long identity = Binder.clearCallingIdentity(); |
| 4876 | try { |
| 4877 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4878 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4879 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4880 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4881 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4882 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4883 | return retVal; |
| 4884 | } else { |
| 4885 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4886 | return false; |
| 4887 | } |
| 4888 | } finally { |
| 4889 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4890 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4891 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4892 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4893 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 4894 | Phone phone) { |
| 4895 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 4896 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 4897 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 4898 | || subController == null) return privilegeFromSim; |
| 4899 | |
| 4900 | int uid = Binder.getCallingUid(); |
| 4901 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 4902 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 4903 | |
| 4904 | final long identity = Binder.clearCallingIdentity(); |
| 4905 | try { |
| 4906 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 4907 | SubscriptionManager subManager = (SubscriptionManager) |
| 4908 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 4909 | for (String pkg : packages) { |
| 4910 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 4911 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4912 | } |
| 4913 | } |
| 4914 | return privilegeFromSim; |
| 4915 | } finally { |
| 4916 | Binder.restoreCallingIdentity(identity); |
| 4917 | } |
| 4918 | } |
| 4919 | |
| 4920 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 4921 | String pkgName) { |
| 4922 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 4923 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 4924 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 4925 | || subController == null) return privilegeFromSim; |
| 4926 | |
| 4927 | final long identity = Binder.clearCallingIdentity(); |
| 4928 | try { |
| 4929 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 4930 | SubscriptionManager subManager = (SubscriptionManager) |
| 4931 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 4932 | return subManager.canManageSubscription(subInfo, pkgName) |
| 4933 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 4934 | } finally { |
| 4935 | Binder.restoreCallingIdentity(identity); |
| 4936 | } |
| 4937 | } |
| 4938 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4939 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4940 | public int getCarrierPrivilegeStatus(int subId) { |
| 4941 | final Phone phone = getPhone(subId); |
| 4942 | if (phone == null) { |
| 4943 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4944 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4945 | } |
| 4946 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4947 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4948 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4949 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4950 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4951 | |
| 4952 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4953 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 4954 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4955 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4956 | |
| 4957 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4958 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4959 | final Phone phone = getPhone(subId); |
| 4960 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4961 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4962 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4963 | } |
| 4964 | UiccProfile profile = |
| 4965 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4966 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4967 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4968 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4969 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4970 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4971 | profile.getCarrierPrivilegeStatusForUid( |
| 4972 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4973 | } |
| 4974 | |
| 4975 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4976 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 4977 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4978 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 4982 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4983 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4984 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4985 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4986 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4987 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4988 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 4989 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4990 | } |
| 4991 | |
| 4992 | @Override |
| 4993 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4994 | if (TextUtils.isEmpty(pkgName)) |
| 4995 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4996 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4997 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4998 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4999 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5000 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5001 | continue; |
| 5002 | } |
| 5003 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5004 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5005 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5006 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5007 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5008 | break; |
| 5009 | } |
| 5010 | } |
| 5011 | |
| 5012 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5013 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5014 | |
| 5015 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5016 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5017 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5018 | loge("phoneId " + phoneId + " is not valid."); |
| 5019 | return null; |
| 5020 | } |
| 5021 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5022 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5023 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5024 | return null ; |
| 5025 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5026 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5027 | } |
| 5028 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5029 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5030 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5031 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5032 | List<String> privilegedPackages = new ArrayList<>(); |
| 5033 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5034 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5035 | // has UICC in that slot. |
| 5036 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5037 | if (card.hasCarrierPrivilegeRules()) { |
| 5038 | if (packages == null) { |
| 5039 | // Only check packages in user 0 for now |
| 5040 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5041 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5042 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5043 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5044 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5045 | } |
| 5046 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5047 | PackageInfo pkgInfo = packages.get(p); |
| 5048 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5049 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5050 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5051 | privilegedPackages.add(pkgInfo.packageName); |
| 5052 | } |
| 5053 | } |
| 5054 | } |
| 5055 | } |
| 5056 | return privilegedPackages; |
| 5057 | } |
| 5058 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5059 | @Override |
| 5060 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
| 5061 | List<String> privilegedPackages = new ArrayList<>(); |
| 5062 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5063 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5064 | } |
| 5065 | return privilegedPackages; |
| 5066 | } |
| 5067 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5068 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5069 | final Phone phone = getPhone(subId); |
| 5070 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5071 | if (card == null) { |
| 5072 | loge("getIccId: No UICC"); |
| 5073 | return null; |
| 5074 | } |
| 5075 | String iccId = card.getIccId(); |
| 5076 | if (TextUtils.isEmpty(iccId)) { |
| 5077 | loge("getIccId: ICC ID is null or empty."); |
| 5078 | return null; |
| 5079 | } |
| 5080 | return iccId; |
| 5081 | } |
| 5082 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5083 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5084 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5085 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5086 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5087 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5088 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5089 | final long identity = Binder.clearCallingIdentity(); |
| 5090 | try { |
| 5091 | final String iccId = getIccId(subId); |
| 5092 | final Phone phone = getPhone(subId); |
| 5093 | if (phone == null) { |
| 5094 | return false; |
| 5095 | } |
| 5096 | final String subscriberId = phone.getSubscriberId(); |
| 5097 | |
| 5098 | if (DBG_MERGE) { |
| 5099 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5100 | + subscriberId + " to " + number); |
| 5101 | } |
| 5102 | |
| 5103 | if (TextUtils.isEmpty(iccId)) { |
| 5104 | return false; |
| 5105 | } |
| 5106 | |
| 5107 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5108 | |
| 5109 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5110 | if (alphaTag == null) { |
| 5111 | editor.remove(alphaTagPrefKey); |
| 5112 | } else { |
| 5113 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5114 | } |
| 5115 | |
| 5116 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5117 | // track all merged IMSIs based on line number |
| 5118 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5119 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5120 | if (number == null) { |
| 5121 | editor.remove(numberPrefKey); |
| 5122 | editor.remove(subscriberPrefKey); |
| 5123 | } else { |
| 5124 | editor.putString(numberPrefKey, number); |
| 5125 | editor.putString(subscriberPrefKey, subscriberId); |
| 5126 | } |
| 5127 | |
| 5128 | editor.commit(); |
| 5129 | return true; |
| 5130 | } finally { |
| 5131 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5132 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5133 | } |
| 5134 | |
| 5135 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5136 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5137 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5138 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5139 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5140 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5141 | return null; |
| 5142 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5143 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5144 | final long identity = Binder.clearCallingIdentity(); |
| 5145 | try { |
| 5146 | String iccId = getIccId(subId); |
| 5147 | if (iccId != null) { |
| 5148 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5149 | if (DBG_MERGE) { |
| 5150 | log("getLine1NumberForDisplay returning " |
| 5151 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5152 | } |
| 5153 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5154 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5155 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5156 | return null; |
| 5157 | } finally { |
| 5158 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5159 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5160 | } |
| 5161 | |
| 5162 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5163 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5164 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5165 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5166 | return null; |
| 5167 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5168 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5169 | final long identity = Binder.clearCallingIdentity(); |
| 5170 | try { |
| 5171 | String iccId = getIccId(subId); |
| 5172 | if (iccId != null) { |
| 5173 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5174 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5175 | } |
| 5176 | return null; |
| 5177 | } finally { |
| 5178 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5179 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5180 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5181 | |
| 5182 | @Override |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5183 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5184 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5185 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5186 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5187 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 5188 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5189 | return null; |
| 5190 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5191 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5192 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5193 | // the process, where TelephonyManager was instantiated. |
| 5194 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5195 | final long identity = Binder.clearCallingIdentity(); |
| 5196 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5197 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5198 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5199 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5200 | |
| 5201 | // Figure out what subscribers are currently active |
| 5202 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5203 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5204 | // Only consider subs which match the current subId |
| 5205 | // This logic can be simplified. See b/131189269 for progress. |
| 5206 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5207 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5208 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5209 | |
| 5210 | // First pass, find a number override for an active subscriber |
| 5211 | String mergeNumber = null; |
| 5212 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5213 | for (String key : prefs.keySet()) { |
| 5214 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5215 | final String subscriberId = (String) prefs.get(key); |
| 5216 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5217 | final String iccId = key.substring( |
| 5218 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5219 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5220 | mergeNumber = (String) prefs.get(numberKey); |
| 5221 | if (DBG_MERGE) { |
| 5222 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5223 | + " for active subscriber " + subscriberId); |
| 5224 | } |
| 5225 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5226 | break; |
| 5227 | } |
| 5228 | } |
| 5229 | } |
| 5230 | } |
| 5231 | |
| 5232 | // Shortcut when no active merged subscribers |
| 5233 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5234 | return null; |
| 5235 | } |
| 5236 | |
| 5237 | // Second pass, find all subscribers under that line override |
| 5238 | final ArraySet<String> result = new ArraySet<>(); |
| 5239 | for (String key : prefs.keySet()) { |
| 5240 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5241 | final String number = (String) prefs.get(key); |
| 5242 | if (mergeNumber.equals(number)) { |
| 5243 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5244 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5245 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5246 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5247 | result.add(subscriberId); |
| 5248 | } |
| 5249 | } |
| 5250 | } |
| 5251 | } |
| 5252 | |
| 5253 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5254 | Arrays.sort(resultArray); |
| 5255 | if (DBG_MERGE) { |
| 5256 | Slog.d(LOG_TAG, |
| 5257 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5258 | } |
| 5259 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5260 | } finally { |
| 5261 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5262 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5263 | } |
| 5264 | |
| 5265 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5266 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 5267 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 5268 | |
| 5269 | final long identity = Binder.clearCallingIdentity(); |
| 5270 | try { |
| 5271 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5272 | TelephonyManager.class); |
| 5273 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5274 | if (subscriberId == null) { |
| 5275 | if (DBG) { |
| 5276 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 5277 | + subId); |
| 5278 | } |
| 5279 | return null; |
| 5280 | } |
| 5281 | |
| 5282 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5283 | .getSubscriptionInfo(subId); |
| 5284 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5285 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5286 | if (groupUuid == null) { |
| 5287 | return new String[]{subscriberId}; |
| 5288 | } |
| 5289 | |
| 5290 | // Get all subscriberIds from the group. |
| 5291 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5292 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
| 5293 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName()); |
| 5294 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5295 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5296 | if (subscriberId != null) { |
| 5297 | mergedSubscriberIds.add(subscriberId); |
| 5298 | } |
| 5299 | } |
| 5300 | |
| 5301 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5302 | } finally { |
| 5303 | Binder.restoreCallingIdentity(identity); |
| 5304 | |
| 5305 | } |
| 5306 | } |
| 5307 | |
| 5308 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5309 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5310 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5311 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5312 | |
| 5313 | final long identity = Binder.clearCallingIdentity(); |
| 5314 | try { |
| 5315 | final Phone phone = getPhone(subId); |
| 5316 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5317 | } finally { |
| 5318 | Binder.restoreCallingIdentity(identity); |
| 5319 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5320 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5321 | |
| 5322 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5323 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5324 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5325 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5326 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5327 | |
| 5328 | final long identity = Binder.clearCallingIdentity(); |
| 5329 | try { |
| 5330 | final Phone phone = getPhone(subId); |
| 5331 | if (phone == null) { |
| 5332 | return false; |
| 5333 | } |
| 5334 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5335 | cdmaNonRoamingList); |
| 5336 | } finally { |
| 5337 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5338 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5339 | } |
| 5340 | |
| 5341 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5342 | @Deprecated |
| 5343 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5344 | enforceModifyPermission(); |
| 5345 | |
| 5346 | int returnValue = 0; |
| 5347 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5348 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5349 | if(result.exception == null) { |
| 5350 | if (result.result != null) { |
| 5351 | byte[] responseData = (byte[])(result.result); |
| 5352 | if(responseData.length > oemResp.length) { |
| 5353 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5354 | responseData.length + "bytes. Buffer Size is " + |
| 5355 | oemResp.length + "bytes."); |
| 5356 | } |
| 5357 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5358 | returnValue = responseData.length; |
| 5359 | } |
| 5360 | } else { |
| 5361 | CommandException ex = (CommandException) result.exception; |
| 5362 | returnValue = ex.getCommandError().ordinal(); |
| 5363 | if(returnValue > 0) returnValue *= -1; |
| 5364 | } |
| 5365 | } catch (RuntimeException e) { |
| 5366 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5367 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5368 | if(returnValue > 0) returnValue *= -1; |
| 5369 | } |
| 5370 | |
| 5371 | return returnValue; |
| 5372 | } |
| 5373 | |
| 5374 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5375 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5376 | try { |
| 5377 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5378 | } catch (RuntimeException e) { |
| 5379 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5380 | } |
| 5381 | } |
| 5382 | |
| 5383 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5384 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5385 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5386 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5387 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5388 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5389 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5390 | final long identity = Binder.clearCallingIdentity(); |
| 5391 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5392 | TelephonyPermissions |
| 5393 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5394 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5395 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5396 | } finally { |
| 5397 | Binder.restoreCallingIdentity(identity); |
| 5398 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5399 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5400 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5401 | |
| 5402 | @Override |
| 5403 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5404 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5405 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5406 | |
| 5407 | final long identity = Binder.clearCallingIdentity(); |
| 5408 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5409 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5410 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5411 | } finally { |
| 5412 | Binder.restoreCallingIdentity(identity); |
| 5413 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5417 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5418 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5419 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5420 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5421 | return false; |
| 5422 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5423 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5424 | final long identity = Binder.clearCallingIdentity(); |
| 5425 | try { |
| 5426 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5427 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5428 | // In the long run, we may instead need to check if there exists a connection service |
| 5429 | // which can support video calling. |
| 5430 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5431 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5432 | return imsManager.isVtEnabledByPlatform() |
| 5433 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5434 | && imsManager.isVtEnabledByUser(); |
| 5435 | } finally { |
| 5436 | Binder.restoreCallingIdentity(identity); |
| 5437 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5438 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5439 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5440 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5441 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5442 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5443 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5444 | return false; |
| 5445 | } |
| 5446 | |
| 5447 | final long identity = Binder.clearCallingIdentity(); |
| 5448 | try { |
| 5449 | CarrierConfigManager configManager = |
| 5450 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5451 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5452 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5453 | } finally { |
| 5454 | Binder.restoreCallingIdentity(identity); |
| 5455 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5456 | } |
| 5457 | |
| 5458 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5459 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5460 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5461 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5462 | return false; |
| 5463 | } |
| 5464 | |
| 5465 | final long identity = Binder.clearCallingIdentity(); |
| 5466 | try { |
| 5467 | CarrierConfigManager configManager = |
| 5468 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5469 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5470 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5471 | } finally { |
| 5472 | Binder.restoreCallingIdentity(identity); |
| 5473 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5474 | } |
| 5475 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5476 | @Override |
| 5477 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5478 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5479 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5480 | } |
| 5481 | |
| 5482 | @Override |
| 5483 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5484 | final long identity = Binder.clearCallingIdentity(); |
| 5485 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5486 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5487 | } finally { |
| 5488 | Binder.restoreCallingIdentity(identity); |
| 5489 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5490 | } |
| 5491 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5492 | /** |
| 5493 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5494 | * support for the feature and device firmware support. |
| 5495 | * |
| 5496 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5497 | */ |
| 5498 | @Override |
| 5499 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5500 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5501 | final Phone phone = getPhone(subscriptionId); |
| 5502 | if (phone == null) { |
| 5503 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5504 | return false; |
| 5505 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5506 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5507 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5508 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5509 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5510 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5511 | return isCarrierSupported && isDeviceSupported; |
| 5512 | } finally { |
| 5513 | Binder.restoreCallingIdentity(identity); |
| 5514 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5515 | } |
| 5516 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5517 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5518 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 5519 | * RTT setting, will return true if the device and carrier both support RTT. |
| 5520 | * Otherwise. only returns true if the device and carrier both also support RTT. |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5521 | */ |
| 5522 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5523 | final long identity = Binder.clearCallingIdentity(); |
| 5524 | try { |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5525 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 5526 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5527 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5528 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 5529 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 5530 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5531 | } finally { |
| 5532 | Binder.restoreCallingIdentity(identity); |
| 5533 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5534 | } |
| 5535 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5536 | /** |
| 5537 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5538 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5539 | * |
| 5540 | * <p>Requires Permission: |
| 5541 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5542 | */ |
| 5543 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5544 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5545 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5546 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5547 | return null; |
| 5548 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5549 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5550 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5551 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5552 | return null; |
| 5553 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5554 | |
| 5555 | final long identity = Binder.clearCallingIdentity(); |
| 5556 | try { |
| 5557 | return phone.getDeviceId(); |
| 5558 | } finally { |
| 5559 | Binder.restoreCallingIdentity(identity); |
| 5560 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5561 | } |
| 5562 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5563 | /** |
| 5564 | * {@hide} |
| 5565 | * Returns the IMS Registration Status on a particular subid |
| 5566 | * |
| 5567 | * @param subId |
| 5568 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5569 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5570 | Phone phone = getPhone(subId); |
| 5571 | if (phone != null) { |
| 5572 | return phone.isImsRegistered(); |
| 5573 | } else { |
| 5574 | return false; |
| 5575 | } |
| 5576 | } |
| 5577 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5578 | @Override |
| 5579 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5580 | final long identity = Binder.clearCallingIdentity(); |
| 5581 | try { |
| 5582 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5583 | } finally { |
| 5584 | Binder.restoreCallingIdentity(identity); |
| 5585 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5586 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5587 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5588 | @Override |
| 5589 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5590 | final long identity = Binder.clearCallingIdentity(); |
| 5591 | try { |
| 5592 | Phone phone = getPhone(subscriptionId); |
| 5593 | if (phone == null) { |
| 5594 | return null; |
| 5595 | } |
| 5596 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5597 | } finally { |
| 5598 | Binder.restoreCallingIdentity(identity); |
| 5599 | } |
| 5600 | } |
| 5601 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5602 | /** |
| 5603 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5604 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5605 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5606 | final long identity = Binder.clearCallingIdentity(); |
| 5607 | try { |
| 5608 | Phone phone = getPhone(subId); |
| 5609 | if (phone != null) { |
| 5610 | return phone.isWifiCallingEnabled(); |
| 5611 | } else { |
| 5612 | return false; |
| 5613 | } |
| 5614 | } finally { |
| 5615 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5616 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5617 | } |
| 5618 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5619 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5620 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5621 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5622 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5623 | final long identity = Binder.clearCallingIdentity(); |
| 5624 | try { |
| 5625 | Phone phone = getPhone(subId); |
| 5626 | if (phone != null) { |
| 5627 | return phone.isVideoEnabled(); |
| 5628 | } else { |
| 5629 | return false; |
| 5630 | } |
| 5631 | } finally { |
| 5632 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5633 | } |
| 5634 | } |
| 5635 | |
| 5636 | /** |
| 5637 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5638 | * defined in {@link ImsRegistrationImplBase}. |
| 5639 | */ |
| 5640 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5641 | final long identity = Binder.clearCallingIdentity(); |
| 5642 | try { |
| 5643 | Phone phone = getPhone(subId); |
| 5644 | if (phone != null) { |
| 5645 | return phone.getImsRegistrationTech(); |
| 5646 | } else { |
| 5647 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5648 | } |
| 5649 | } finally { |
| 5650 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5651 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5652 | } |
| 5653 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5654 | @Override |
| 5655 | public void factoryReset(int subId) { |
| 5656 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5657 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5658 | return; |
| 5659 | } |
| 5660 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5661 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5662 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5663 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5664 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5665 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5666 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5667 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5668 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5669 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5670 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5671 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5672 | // There has been issues when Sms raw table somehow stores orphan |
| 5673 | // fragments. They lead to garbled message when new fragments come |
| 5674 | // in and combined with those stale ones. In case this happens again, |
| 5675 | // user can reset all network settings which will clean up this table. |
| 5676 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5677 | } finally { |
| 5678 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5679 | } |
| 5680 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5681 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5682 | private void cleanUpSmsRawTable(Context context) { |
| 5683 | ContentResolver resolver = context.getContentResolver(); |
| 5684 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5685 | resolver.delete(uri, null, null); |
| 5686 | } |
| 5687 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5688 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5689 | public String getSimLocaleForSubscriber(int subId) { |
| 5690 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5691 | final Phone phone = getPhone(subId); |
| 5692 | if (phone == null) { |
| 5693 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5694 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5695 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5696 | final long identity = Binder.clearCallingIdentity(); |
| 5697 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5698 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5699 | phone.getContext().getOpPackageName()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5700 | if (info == null) { |
| 5701 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5702 | return null; |
| 5703 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5704 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5705 | // preferences (EF-PL and EF-LI)... |
| 5706 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5707 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5708 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5709 | if (localeFromDefaultSim != null) { |
| 5710 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5711 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5712 | + localeFromDefaultSim); |
| 5713 | return localeFromDefaultSim.toLanguageTag(); |
| 5714 | } else { |
| 5715 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5716 | } |
| 5717 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5718 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5719 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5720 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5721 | // the SIM and carrier preferences does not include a country we add the country |
| 5722 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5723 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5724 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5725 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5726 | return mccLocale.toLanguageTag(); |
| 5727 | } |
| 5728 | |
| 5729 | if (DBG) log("No locale found - returning null"); |
| 5730 | return null; |
| 5731 | } finally { |
| 5732 | Binder.restoreCallingIdentity(identity); |
| 5733 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5734 | } |
| 5735 | |
| 5736 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5737 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5738 | } |
| 5739 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5740 | /** |
| 5741 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5742 | */ |
| 5743 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5744 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5745 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5746 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5747 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5748 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5749 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5750 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5751 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5752 | * representing the state of the modem. |
| 5753 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5754 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5755 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5756 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5757 | */ |
| 5758 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5759 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5760 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5761 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5762 | |
| 5763 | final long identity = Binder.clearCallingIdentity(); |
| 5764 | try { |
| 5765 | ModemActivityInfo ret = null; |
| 5766 | synchronized (mLastModemActivityInfo) { |
| 5767 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5768 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5769 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5770 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5771 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5772 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 5773 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5774 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5775 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5776 | } |
| 5777 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5778 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 5779 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5781 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5782 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 5783 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 5784 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 5785 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5786 | } |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5787 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5788 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5789 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5790 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5791 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 5792 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5793 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5794 | Bundle bundle = new Bundle(); |
| 5795 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5796 | result.send(0, bundle); |
| 5797 | } finally { |
| 5798 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5799 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5800 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5801 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5802 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5803 | // less than total activity duration. |
| 5804 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5805 | if (info == null) { |
| 5806 | return false; |
| 5807 | } |
| 5808 | int activityDurationMs = |
| 5809 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5810 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5811 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 5812 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 5813 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5814 | } |
| 5815 | return (info.isValid() |
| 5816 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5817 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5818 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5819 | && (totalTxTimeMs <= activityDurationMs)); |
| 5820 | } |
| 5821 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5822 | /** |
| 5823 | * {@hide} |
| 5824 | * Returns the service state information on specified subscription. |
| 5825 | */ |
| 5826 | @Override |
| 5827 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5828 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5829 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5830 | return null; |
| 5831 | } |
| 5832 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5833 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5834 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5835 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5836 | .setCallingPackage(callingPackage) |
| 5837 | .setCallingPid(Binder.getCallingPid()) |
| 5838 | .setCallingUid(Binder.getCallingUid()) |
| 5839 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5840 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5841 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5842 | .build()); |
| 5843 | |
| 5844 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5845 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5846 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5847 | .setCallingPackage(callingPackage) |
| 5848 | .setCallingPid(Binder.getCallingPid()) |
| 5849 | .setCallingUid(Binder.getCallingUid()) |
| 5850 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5851 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5852 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5853 | .build()); |
| 5854 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5855 | boolean hasFinePermission = |
| 5856 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5857 | boolean hasCoarsePermission = |
| 5858 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5859 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5860 | final long identity = Binder.clearCallingIdentity(); |
| 5861 | try { |
| 5862 | final Phone phone = getPhone(subId); |
| 5863 | if (phone == null) { |
| 5864 | return null; |
| 5865 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5866 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5867 | ServiceState ss = phone.getServiceState(); |
| 5868 | |
| 5869 | // Scrub out the location info in ServiceState depending on what level of access |
| 5870 | // the caller has. |
| 5871 | if (hasFinePermission) return ss; |
| 5872 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5873 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5874 | } finally { |
| 5875 | Binder.restoreCallingIdentity(identity); |
| 5876 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5877 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5878 | |
| 5879 | /** |
| 5880 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5881 | * |
| 5882 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5883 | * voicemail ringtone. |
| 5884 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5885 | * PhoneAccount. |
| 5886 | */ |
| 5887 | @Override |
| 5888 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5889 | final long identity = Binder.clearCallingIdentity(); |
| 5890 | try { |
| 5891 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5892 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5893 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5894 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5895 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5896 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5897 | } finally { |
| 5898 | Binder.restoreCallingIdentity(identity); |
| 5899 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5900 | } |
| 5901 | |
| 5902 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5903 | * Sets the per-account voicemail ringtone. |
| 5904 | * |
| 5905 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5906 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5907 | * |
| 5908 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5909 | * voicemail ringtone. |
| 5910 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5911 | * PhoneAccount. |
| 5912 | */ |
| 5913 | @Override |
| 5914 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5915 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5916 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5917 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5918 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5919 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5920 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5921 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5922 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5923 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5924 | |
| 5925 | final long identity = Binder.clearCallingIdentity(); |
| 5926 | try { |
| 5927 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5928 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5929 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5930 | } |
| 5931 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5932 | } finally { |
| 5933 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5934 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5935 | } |
| 5936 | |
| 5937 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5938 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5939 | * |
| 5940 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5941 | * voicemail vibration setting. |
| 5942 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5943 | */ |
| 5944 | @Override |
| 5945 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5946 | final long identity = Binder.clearCallingIdentity(); |
| 5947 | try { |
| 5948 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5949 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5950 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5951 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5952 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5953 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5954 | } finally { |
| 5955 | Binder.restoreCallingIdentity(identity); |
| 5956 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5957 | } |
| 5958 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5959 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5960 | * Sets the per-account voicemail vibration. |
| 5961 | * |
| 5962 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5963 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5964 | * |
| 5965 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5966 | * voicemail vibration setting. |
| 5967 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5968 | * specific PhoneAccount. |
| 5969 | */ |
| 5970 | @Override |
| 5971 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5972 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5973 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5974 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5975 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5976 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5977 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5978 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5979 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5980 | } |
| 5981 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5982 | final long identity = Binder.clearCallingIdentity(); |
| 5983 | try { |
| 5984 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5985 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5986 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5987 | } |
| 5988 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5989 | } finally { |
| 5990 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5991 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5992 | } |
| 5993 | |
| 5994 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5995 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5996 | * |
| 5997 | * @throws SecurityException if the caller does not have the required permission |
| 5998 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5999 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6000 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6001 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6002 | } |
| 6003 | |
| 6004 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6005 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6006 | * permission. |
| 6007 | * |
| 6008 | * @throws SecurityException if the caller does not have the required permission |
| 6009 | */ |
| 6010 | private void enforceSendSmsPermission() { |
| 6011 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6012 | } |
| 6013 | |
| 6014 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6015 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6016 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6017 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6018 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6019 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6020 | final long identity = Binder.clearCallingIdentity(); |
| 6021 | try { |
| 6022 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6023 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6024 | if (componentName == null) { |
| 6025 | throw new SecurityException( |
| 6026 | "Caller not current active visual voicemail package[null]"); |
| 6027 | } |
| 6028 | String vvmPackage = componentName.getPackageName(); |
| 6029 | if (!callingPackage.equals(vvmPackage)) { |
| 6030 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6031 | + vvmPackage + "]"); |
| 6032 | } |
| 6033 | } finally { |
| 6034 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6035 | } |
| 6036 | } |
| 6037 | |
| 6038 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6039 | * Return the application ID for the app type. |
| 6040 | * |
| 6041 | * @param subId the subscription ID that this request applies to. |
| 6042 | * @param appType the uicc app type. |
| 6043 | * @return Application ID for specificied app type, or null if no uicc. |
| 6044 | */ |
| 6045 | @Override |
| 6046 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6047 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6048 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6049 | |
| 6050 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6051 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6052 | if (phone == null) { |
| 6053 | return null; |
| 6054 | } |
| 6055 | String aid = null; |
| 6056 | try { |
| 6057 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6058 | .getApplicationByType(appType).getAid(); |
| 6059 | } catch (Exception e) { |
| 6060 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6061 | } |
| 6062 | return aid; |
| 6063 | } finally { |
| 6064 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6065 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6066 | } |
| 6067 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6068 | /** |
| 6069 | * Return the Electronic Serial Number. |
| 6070 | * |
| 6071 | * @param subId the subscription ID that this request applies to. |
| 6072 | * @return ESN or null if error. |
| 6073 | */ |
| 6074 | @Override |
| 6075 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6076 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6077 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6078 | |
| 6079 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6080 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6081 | if (phone == null) { |
| 6082 | return null; |
| 6083 | } |
| 6084 | String esn = null; |
| 6085 | try { |
| 6086 | esn = phone.getEsn(); |
| 6087 | } catch (Exception e) { |
| 6088 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6089 | } |
| 6090 | return esn; |
| 6091 | } finally { |
| 6092 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6093 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6094 | } |
| 6095 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6096 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6097 | * Return the Preferred Roaming List Version. |
| 6098 | * |
| 6099 | * @param subId the subscription ID that this request applies to. |
| 6100 | * @return PRLVersion or null if error. |
| 6101 | */ |
| 6102 | @Override |
| 6103 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6104 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6105 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6106 | |
| 6107 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6108 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6109 | if (phone == null) { |
| 6110 | return null; |
| 6111 | } |
| 6112 | String cdmaPrlVersion = null; |
| 6113 | try { |
| 6114 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6115 | } catch (Exception e) { |
| 6116 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6117 | } |
| 6118 | return cdmaPrlVersion; |
| 6119 | } finally { |
| 6120 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6121 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6122 | } |
| 6123 | |
| 6124 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6125 | * Get snapshot of Telephony histograms |
| 6126 | * @return List of Telephony histograms |
| 6127 | * @hide |
| 6128 | */ |
| 6129 | @Override |
| 6130 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6131 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6132 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6133 | |
| 6134 | final long identity = Binder.clearCallingIdentity(); |
| 6135 | try { |
| 6136 | return RIL.getTelephonyRILTimingHistograms(); |
| 6137 | } finally { |
| 6138 | Binder.restoreCallingIdentity(identity); |
| 6139 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6140 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6141 | |
| 6142 | /** |
| 6143 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6144 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6145 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6146 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6147 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6148 | * @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] | 6149 | */ |
| 6150 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6151 | @TelephonyManager.SetCarrierRestrictionResult |
| 6152 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6153 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6154 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6155 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6156 | if (carrierRestrictionRules == null) { |
| 6157 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6158 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6159 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6160 | final long identity = Binder.clearCallingIdentity(); |
| 6161 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6162 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6163 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6164 | } finally { |
| 6165 | Binder.restoreCallingIdentity(identity); |
| 6166 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6167 | } |
| 6168 | |
| 6169 | /** |
| 6170 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6171 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6172 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6173 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6174 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6175 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6176 | */ |
| 6177 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6178 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6179 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6180 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6181 | |
| 6182 | final long identity = Binder.clearCallingIdentity(); |
| 6183 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6184 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6185 | if (response instanceof CarrierRestrictionRules) { |
| 6186 | return (CarrierRestrictionRules) response; |
| 6187 | } |
| 6188 | // Response is an Exception of some kind, |
| 6189 | // which is signalled to the user as a NULL retval |
| 6190 | return null; |
| 6191 | } catch (Exception e) { |
| 6192 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6193 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6194 | } finally { |
| 6195 | Binder.restoreCallingIdentity(identity); |
| 6196 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6197 | } |
| 6198 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6199 | /** |
| 6200 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6201 | * @param subId the subscription ID that this action applies to. |
| 6202 | * @param enabled control enable or disable metered apns. |
| 6203 | * {@hide} |
| 6204 | */ |
| 6205 | @Override |
| 6206 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6207 | enforceModifyPermission(); |
| 6208 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6209 | |
| 6210 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6211 | if (phone == null) { |
| 6212 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6213 | return; |
| 6214 | } |
| 6215 | try { |
| 6216 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6217 | } catch (Exception e) { |
| 6218 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6219 | } finally { |
| 6220 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6221 | } |
| 6222 | } |
| 6223 | |
| 6224 | /** |
| 6225 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6226 | * @param subId the subscription ID that this action applies to. |
| 6227 | * @param enabled control enable or disable radio. |
| 6228 | * {@hide} |
| 6229 | */ |
| 6230 | @Override |
| 6231 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6232 | enforceModifyPermission(); |
| 6233 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6234 | |
| 6235 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6236 | if (phone == null) { |
| 6237 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6238 | return; |
| 6239 | } |
| 6240 | try { |
| 6241 | phone.carrierActionSetRadioEnabled(enabled); |
| 6242 | } catch (Exception e) { |
| 6243 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6244 | } finally { |
| 6245 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6246 | } |
| 6247 | } |
| 6248 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6249 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6250 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6251 | * network status based on which carrier apps could apply actions accordingly, |
| 6252 | * enable/disable default url handler for example. |
| 6253 | * |
| 6254 | * @param subId the subscription ID that this action applies to. |
| 6255 | * @param report control start/stop reporting the default network status. |
| 6256 | * {@hide} |
| 6257 | */ |
| 6258 | @Override |
| 6259 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6260 | enforceModifyPermission(); |
| 6261 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6262 | |
| 6263 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6264 | if (phone == null) { |
| 6265 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6266 | return; |
| 6267 | } |
| 6268 | try { |
| 6269 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6270 | } catch (Exception e) { |
| 6271 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6272 | } finally { |
| 6273 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6274 | } |
| 6275 | } |
| 6276 | |
| 6277 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6278 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6279 | * @param subId the subscription ID that this action applies to. |
| 6280 | * {@hide} |
| 6281 | */ |
| 6282 | @Override |
| 6283 | public void carrierActionResetAll(int subId) { |
| 6284 | enforceModifyPermission(); |
| 6285 | final Phone phone = getPhone(subId); |
| 6286 | if (phone == null) { |
| 6287 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6288 | return; |
| 6289 | } |
| 6290 | try { |
| 6291 | phone.carrierActionResetAll(); |
| 6292 | } catch (Exception e) { |
| 6293 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6294 | } |
| 6295 | } |
| 6296 | |
| 6297 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6298 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6299 | * bug report is being generated. |
| 6300 | */ |
| 6301 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6302 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6303 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6304 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6305 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6306 | + Binder.getCallingPid() |
| 6307 | + ", uid=" + Binder.getCallingUid() |
| 6308 | + "without permission " |
| 6309 | + android.Manifest.permission.DUMP); |
| 6310 | return; |
| 6311 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6312 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6313 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6314 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6315 | @Override |
| 6316 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6317 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6318 | throws RemoteException { |
| 6319 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 6320 | } |
| 6321 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6322 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6323 | * Get aggregated video call data usage since boot. |
| 6324 | * |
| 6325 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6326 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6327 | * {@hide} |
| 6328 | */ |
| 6329 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6330 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6331 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6332 | null); |
| 6333 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6334 | final long identity = Binder.clearCallingIdentity(); |
| 6335 | try { |
| 6336 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6337 | // records the delta with the corresponding network identity. |
| 6338 | // We just return the total video call data usage snapshot since boot. |
| 6339 | Phone phone = getPhone(subId); |
| 6340 | if (phone != null) { |
| 6341 | return phone.getVtDataUsage(perUidStats); |
| 6342 | } |
| 6343 | return null; |
| 6344 | } finally { |
| 6345 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6346 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6347 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6348 | |
| 6349 | /** |
| 6350 | * Policy control of data connection. Usually used when data limit is passed. |
| 6351 | * @param enabled True if enabling the data, otherwise disabling. |
| 6352 | * @param subId Subscription index |
| 6353 | * {@hide} |
| 6354 | */ |
| 6355 | @Override |
| 6356 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6357 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6358 | |
| 6359 | final long identity = Binder.clearCallingIdentity(); |
| 6360 | try { |
| 6361 | Phone phone = getPhone(subId); |
| 6362 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6363 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6364 | } |
| 6365 | } finally { |
| 6366 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6367 | } |
| 6368 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6369 | |
| 6370 | /** |
| 6371 | * Get Client request stats |
| 6372 | * @return List of Client Request Stats |
| 6373 | * @hide |
| 6374 | */ |
| 6375 | @Override |
| 6376 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6377 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6378 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6379 | return null; |
| 6380 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6381 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6382 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6383 | final long identity = Binder.clearCallingIdentity(); |
| 6384 | try { |
| 6385 | if (phone != null) { |
| 6386 | return phone.getClientRequestStats(); |
| 6387 | } |
| 6388 | |
| 6389 | return null; |
| 6390 | } finally { |
| 6391 | Binder.restoreCallingIdentity(identity); |
| 6392 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6393 | } |
| 6394 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6395 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6396 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6397 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6398 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6399 | |
| 6400 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6401 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6402 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6403 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6404 | * @param state State of SIM (power down, power up, pass through) |
| 6405 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6406 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6407 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6408 | * |
| 6409 | **/ |
| 6410 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6411 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6412 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6413 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6414 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6415 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6416 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6417 | final long identity = Binder.clearCallingIdentity(); |
| 6418 | try { |
| 6419 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6420 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6421 | } |
| 6422 | } finally { |
| 6423 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6424 | } |
| 6425 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6426 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6427 | private boolean isUssdApiAllowed(int subId) { |
| 6428 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6429 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6430 | if (configManager == null) { |
| 6431 | return false; |
| 6432 | } |
| 6433 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6434 | if (pb == null) { |
| 6435 | return false; |
| 6436 | } |
| 6437 | return pb.getBoolean( |
| 6438 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6439 | } |
| 6440 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6441 | /** |
| 6442 | * Check if phone is in emergency callback mode |
| 6443 | * @return true if phone is in emergency callback mode |
| 6444 | * @param subId sub id |
| 6445 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6446 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6447 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6448 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6449 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6450 | |
| 6451 | final long identity = Binder.clearCallingIdentity(); |
| 6452 | try { |
| 6453 | if (phone != null) { |
| 6454 | return phone.isInEcm(); |
| 6455 | } else { |
| 6456 | return false; |
| 6457 | } |
| 6458 | } finally { |
| 6459 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6460 | } |
| 6461 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6462 | |
| 6463 | /** |
| 6464 | * Get the current signal strength information for the given subscription. |
| 6465 | * Because this information is not updated when the device is in a low power state |
| 6466 | * it should not be relied-upon to be current. |
| 6467 | * @param subId Subscription index |
| 6468 | * @return the most recent cached signal strength info from the modem |
| 6469 | */ |
| 6470 | @Override |
| 6471 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6472 | final long identity = Binder.clearCallingIdentity(); |
| 6473 | try { |
| 6474 | Phone p = getPhone(subId); |
| 6475 | if (p == null) { |
| 6476 | return null; |
| 6477 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6478 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6479 | return p.getSignalStrength(); |
| 6480 | } finally { |
| 6481 | Binder.restoreCallingIdentity(identity); |
| 6482 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6483 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6484 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6485 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6486 | * Get the current modem radio state for the given slot. |
| 6487 | * @param slotIndex slot index. |
| 6488 | * @param callingPackage the name of the package making the call. |
| 6489 | * @return the current radio power state from the modem |
| 6490 | */ |
| 6491 | @Override |
| 6492 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6493 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6494 | if (phone != null) { |
| 6495 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6496 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6497 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6498 | } |
| 6499 | |
| 6500 | final long identity = Binder.clearCallingIdentity(); |
| 6501 | try { |
| 6502 | return phone.getRadioPowerState(); |
| 6503 | } finally { |
| 6504 | Binder.restoreCallingIdentity(identity); |
| 6505 | } |
| 6506 | } |
| 6507 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6508 | } |
| 6509 | |
| 6510 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6511 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6512 | * |
| 6513 | * <p>Requires one of the following permissions: |
| 6514 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6515 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6516 | * privileges. |
| 6517 | * |
| 6518 | * @param subId subscription id |
| 6519 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6520 | * {@code false}. |
| 6521 | */ |
| 6522 | @Override |
| 6523 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6524 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6525 | null /* message */); |
| 6526 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6527 | boolean isEnabled = false; |
| 6528 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6529 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6530 | Phone phone = getPhone(subId); |
| 6531 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6532 | } catch (Exception e) { |
| 6533 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6534 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6535 | } finally { |
| 6536 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6537 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6538 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6539 | } |
| 6540 | |
| 6541 | |
| 6542 | /** |
| 6543 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6544 | * |
| 6545 | * <p> Requires permission: |
| 6546 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6547 | * privileges. |
| 6548 | * |
| 6549 | * @param subId subscription id |
| 6550 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6551 | */ |
| 6552 | @Override |
| 6553 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6554 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6555 | mApp, subId, "setDataRoamingEnabled"); |
| 6556 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6557 | final long identity = Binder.clearCallingIdentity(); |
| 6558 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6559 | Phone phone = getPhone(subId); |
| 6560 | if (phone != null) { |
| 6561 | phone.setDataRoamingEnabled(isEnabled); |
| 6562 | } |
| 6563 | } finally { |
| 6564 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6565 | } |
| 6566 | } |
| 6567 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6568 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6569 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6570 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6571 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6572 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6573 | boolean isAllowed = true; |
| 6574 | final long identity = Binder.clearCallingIdentity(); |
| 6575 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6576 | Phone phone = getPhone(subId); |
| 6577 | if (phone != null) { |
| 6578 | isAllowed = phone.isCspPlmnEnabled(); |
| 6579 | } |
| 6580 | } finally { |
| 6581 | Binder.restoreCallingIdentity(identity); |
| 6582 | } |
| 6583 | return isAllowed; |
| 6584 | } |
| 6585 | |
| 6586 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6587 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6588 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6589 | try { |
| 6590 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6591 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6592 | } catch (SecurityException e) { |
| 6593 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6594 | // has carrier privileges on an active UICC |
| 6595 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6596 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6597 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6598 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6599 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6600 | |
| 6601 | final long identity = Binder.clearCallingIdentity(); |
| 6602 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6603 | UiccController uiccController = UiccController.getInstance(); |
| 6604 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6605 | if (hasReadPermission) { |
| 6606 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6607 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6608 | |
| 6609 | // Remove private info if the caller doesn't have access |
| 6610 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6611 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6612 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6613 | // is available |
| 6614 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6615 | if (card == null || card.getUiccProfile() == null) { |
| 6616 | // assume no access if the card or profile is unavailable |
| 6617 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6618 | continue; |
| 6619 | } |
| 6620 | UiccProfile profile = card.getUiccProfile(); |
| 6621 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6622 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6623 | filteredInfos.add(cardInfo); |
| 6624 | } else { |
| 6625 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6626 | } |
| 6627 | } |
| 6628 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6629 | } finally { |
| 6630 | Binder.restoreCallingIdentity(identity); |
| 6631 | } |
| 6632 | } |
| 6633 | |
| 6634 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6635 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6636 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6637 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6638 | final long identity = Binder.clearCallingIdentity(); |
| 6639 | try { |
| 6640 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6641 | if (slots == null) { |
| 6642 | Rlog.i(LOG_TAG, "slots is null."); |
| 6643 | return null; |
| 6644 | } |
| 6645 | |
| 6646 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6647 | for (int i = 0; i < slots.length; i++) { |
| 6648 | UiccSlot slot = slots[i]; |
| 6649 | if (slot == null) { |
| 6650 | continue; |
| 6651 | } |
| 6652 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6653 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6654 | UiccCard card = slot.getUiccCard(); |
| 6655 | if (card != null) { |
| 6656 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6657 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 6658 | cardId = slot.getEid(); |
| 6659 | if (TextUtils.isEmpty(cardId)) { |
| 6660 | cardId = slot.getIccId(); |
| 6661 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6662 | } |
| 6663 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 6664 | if (cardId != null) { |
| 6665 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 6666 | // if cardId is an EID, it's all digits so this is fine |
| 6667 | cardId = IccUtils.stripTrailingFs(cardId); |
| 6668 | } |
| 6669 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6670 | int cardState = 0; |
| 6671 | switch (slot.getCardState()) { |
| 6672 | case CARDSTATE_ABSENT: |
| 6673 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6674 | break; |
| 6675 | case CARDSTATE_PRESENT: |
| 6676 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6677 | break; |
| 6678 | case CARDSTATE_ERROR: |
| 6679 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6680 | break; |
| 6681 | case CARDSTATE_RESTRICTED: |
| 6682 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6683 | break; |
| 6684 | default: |
| 6685 | break; |
| 6686 | |
| 6687 | } |
| 6688 | |
| 6689 | infos[i] = new UiccSlotInfo( |
| 6690 | slot.isActive(), |
| 6691 | slot.isEuicc(), |
| 6692 | cardId, |
| 6693 | cardState, |
| 6694 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6695 | slot.isExtendedApduSupported(), |
| 6696 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6697 | } |
| 6698 | return infos; |
| 6699 | } finally { |
| 6700 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6701 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6702 | } |
| 6703 | |
| 6704 | @Override |
| 6705 | public boolean switchSlots(int[] physicalSlots) { |
| 6706 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6707 | |
| 6708 | final long identity = Binder.clearCallingIdentity(); |
| 6709 | try { |
| 6710 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6711 | } finally { |
| 6712 | Binder.restoreCallingIdentity(identity); |
| 6713 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6714 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6715 | |
| 6716 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6717 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6718 | final long identity = Binder.clearCallingIdentity(); |
| 6719 | try { |
| 6720 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6721 | } finally { |
| 6722 | Binder.restoreCallingIdentity(identity); |
| 6723 | } |
| 6724 | } |
| 6725 | |
| 6726 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6727 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6728 | enforceModifyPermission(); |
| 6729 | final Phone phone = getPhone(subId); |
| 6730 | if (phone == null) { |
| 6731 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6732 | return; |
| 6733 | } |
| 6734 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6735 | final long identity = Binder.clearCallingIdentity(); |
| 6736 | try { |
| 6737 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6738 | } finally { |
| 6739 | Binder.restoreCallingIdentity(identity); |
| 6740 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6741 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6742 | |
| 6743 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6744 | * A test API to reload the UICC profile. |
| 6745 | * |
| 6746 | * <p>Requires that the calling app has permission |
| 6747 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6748 | * @hide |
| 6749 | */ |
| 6750 | @Override |
| 6751 | public void refreshUiccProfile(int subId) { |
| 6752 | enforceModifyPermission(); |
| 6753 | |
| 6754 | final long identity = Binder.clearCallingIdentity(); |
| 6755 | try { |
| 6756 | Phone phone = getPhone(subId); |
| 6757 | if (phone == null) { |
| 6758 | return; |
| 6759 | } |
| 6760 | UiccCard uiccCard = phone.getUiccCard(); |
| 6761 | if (uiccCard == null) { |
| 6762 | return; |
| 6763 | } |
| 6764 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6765 | if (uiccProfile == null) { |
| 6766 | return; |
| 6767 | } |
| 6768 | uiccProfile.refresh(); |
| 6769 | } finally { |
| 6770 | Binder.restoreCallingIdentity(identity); |
| 6771 | } |
| 6772 | } |
| 6773 | |
| 6774 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6775 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6776 | */ |
| 6777 | private boolean getDefaultDataEnabled() { |
| 6778 | return "true".equalsIgnoreCase( |
| 6779 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6780 | } |
| 6781 | |
| 6782 | /** |
| 6783 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6784 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6785 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6786 | */ |
| 6787 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6788 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6789 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6790 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6791 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6792 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6793 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6794 | return isDataRoamingEnabled; |
| 6795 | } |
| 6796 | |
| 6797 | /** |
| 6798 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6799 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6800 | */ |
| 6801 | private int getDefaultNetworkType(int subId) { |
| 6802 | return Integer.parseInt( |
| 6803 | TelephonyManager.getTelephonyProperty( |
| 6804 | mSubscriptionController.getPhoneId(subId), |
| 6805 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6806 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6807 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6808 | |
| 6809 | @Override |
| 6810 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6811 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6812 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6813 | |
| 6814 | final long identity = Binder.clearCallingIdentity(); |
| 6815 | try { |
| 6816 | final Phone phone = getPhone(subId); |
| 6817 | if (phone == null) { |
| 6818 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6819 | return; |
| 6820 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6821 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 6822 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6823 | } finally { |
| 6824 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6825 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6826 | } |
| 6827 | |
| 6828 | @Override |
| 6829 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6830 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6831 | |
| 6832 | final long identity = Binder.clearCallingIdentity(); |
| 6833 | try { |
| 6834 | final Phone phone = getPhone(subId); |
| 6835 | if (phone == null) { |
| 6836 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6837 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6838 | } |
| 6839 | return phone.getCarrierIdListVersion(); |
| 6840 | } finally { |
| 6841 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6842 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6843 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6844 | |
| 6845 | @Override |
| 6846 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6847 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6848 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6849 | return -1; |
| 6850 | } |
| 6851 | |
| 6852 | final long identity = Binder.clearCallingIdentity(); |
| 6853 | try { |
| 6854 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6855 | } finally { |
| 6856 | Binder.restoreCallingIdentity(identity); |
| 6857 | } |
| 6858 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6859 | |
| 6860 | @Override |
| 6861 | public int getCdmaRoamingMode(int subId) { |
| 6862 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6863 | mApp, subId, "getCdmaRoamingMode"); |
| 6864 | |
| 6865 | final long identity = Binder.clearCallingIdentity(); |
| 6866 | try { |
| 6867 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6868 | } finally { |
| 6869 | Binder.restoreCallingIdentity(identity); |
| 6870 | } |
| 6871 | } |
| 6872 | |
| 6873 | @Override |
| 6874 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6875 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6876 | mApp, subId, "setCdmaRoamingMode"); |
| 6877 | |
| 6878 | final long identity = Binder.clearCallingIdentity(); |
| 6879 | try { |
| 6880 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6881 | } finally { |
| 6882 | Binder.restoreCallingIdentity(identity); |
| 6883 | } |
| 6884 | } |
| 6885 | |
| 6886 | @Override |
| 6887 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6888 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6889 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6890 | |
| 6891 | final long identity = Binder.clearCallingIdentity(); |
| 6892 | try { |
| 6893 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6894 | } finally { |
| 6895 | Binder.restoreCallingIdentity(identity); |
| 6896 | } |
| 6897 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 6898 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6899 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6900 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6901 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6902 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6903 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6904 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6905 | } |
| 6906 | final long identity = Binder.clearCallingIdentity(); |
| 6907 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6908 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6909 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6910 | if (phone.getEmergencyNumberTracker() != null |
| 6911 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6912 | emergencyNumberListInternal.put( |
| 6913 | phone.getSubId(), |
| 6914 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6915 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6916 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6917 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6918 | } finally { |
| 6919 | Binder.restoreCallingIdentity(identity); |
| 6920 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6921 | } |
| 6922 | |
| 6923 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6924 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6925 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6926 | if (!exactMatch) { |
| 6927 | TelephonyPermissions |
| 6928 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6929 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6930 | } |
| 6931 | final long identity = Binder.clearCallingIdentity(); |
| 6932 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6933 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6934 | if (phone.getEmergencyNumberTracker() != null |
| 6935 | && phone.getEmergencyNumberTracker() != null) { |
| 6936 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6937 | number, exactMatch)) { |
| 6938 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6939 | } |
| 6940 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6941 | } |
| 6942 | return false; |
| 6943 | } finally { |
| 6944 | Binder.restoreCallingIdentity(identity); |
| 6945 | } |
| 6946 | } |
| 6947 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6948 | /** |
| 6949 | * Update emergency number list for test mode. |
| 6950 | */ |
| 6951 | @Override |
| 6952 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6953 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6954 | "updateEmergencyNumberListTestMode"); |
| 6955 | |
| 6956 | final long identity = Binder.clearCallingIdentity(); |
| 6957 | try { |
| 6958 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6959 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6960 | if (tracker != null) { |
| 6961 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6962 | } |
| 6963 | } |
| 6964 | } finally { |
| 6965 | Binder.restoreCallingIdentity(identity); |
| 6966 | } |
| 6967 | } |
| 6968 | |
| 6969 | /** |
| 6970 | * Get the full emergency number list for test mode. |
| 6971 | */ |
| 6972 | @Override |
| 6973 | public List<String> getEmergencyNumberListTestMode() { |
| 6974 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6975 | "getEmergencyNumberListTestMode"); |
| 6976 | |
| 6977 | final long identity = Binder.clearCallingIdentity(); |
| 6978 | try { |
| 6979 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6980 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6981 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6982 | if (tracker != null) { |
| 6983 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6984 | emergencyNumbers.add(num.getNumber()); |
| 6985 | } |
| 6986 | } |
| 6987 | } |
| 6988 | return new ArrayList<>(emergencyNumbers); |
| 6989 | } finally { |
| 6990 | Binder.restoreCallingIdentity(identity); |
| 6991 | } |
| 6992 | } |
| 6993 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6994 | @Override |
| 6995 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6996 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6997 | Phone phone = getPhone(subId); |
| 6998 | if (phone == null) { |
| 6999 | return null; |
| 7000 | } |
| 7001 | final long identity = Binder.clearCallingIdentity(); |
| 7002 | try { |
| 7003 | UiccProfile profile = UiccController.getInstance() |
| 7004 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7005 | if (profile != null) { |
| 7006 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7007 | } |
| 7008 | } finally { |
| 7009 | Binder.restoreCallingIdentity(identity); |
| 7010 | } |
| 7011 | return null; |
| 7012 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7013 | |
| 7014 | /** |
| 7015 | * Enable or disable a modem stack. |
| 7016 | */ |
| 7017 | @Override |
| 7018 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7019 | enforceModifyPermission(); |
| 7020 | |
| 7021 | final long identity = Binder.clearCallingIdentity(); |
| 7022 | try { |
| 7023 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7024 | if (phone == null) { |
| 7025 | return false; |
| 7026 | } else { |
| 7027 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7028 | } |
| 7029 | } finally { |
| 7030 | Binder.restoreCallingIdentity(identity); |
| 7031 | } |
| 7032 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7033 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7034 | /** |
| 7035 | * Whether a modem stack is enabled or not. |
| 7036 | */ |
| 7037 | @Override |
| 7038 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 7039 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7040 | if (phone == null) return false; |
| 7041 | |
| 7042 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7043 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 7044 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7045 | } |
| 7046 | |
| 7047 | final long identity = Binder.clearCallingIdentity(); |
| 7048 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7049 | try { |
| 7050 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7051 | } catch (NoSuchElementException ex) { |
| 7052 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7053 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7054 | } finally { |
| 7055 | Binder.restoreCallingIdentity(identity); |
| 7056 | } |
| 7057 | } |
| 7058 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7059 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7060 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7061 | enforceModifyPermission(); |
| 7062 | |
| 7063 | final long identity = Binder.clearCallingIdentity(); |
| 7064 | try { |
| 7065 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7066 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7067 | .commit(); |
| 7068 | } finally { |
| 7069 | Binder.restoreCallingIdentity(identity); |
| 7070 | } |
| 7071 | } |
| 7072 | |
| 7073 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7074 | @TelephonyManager.IsMultiSimSupportedResult |
| 7075 | public int isMultiSimSupported(String callingPackage) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7076 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7077 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 7078 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7079 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7080 | |
| 7081 | final long identity = Binder.clearCallingIdentity(); |
| 7082 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7083 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7084 | } finally { |
| 7085 | Binder.restoreCallingIdentity(identity); |
| 7086 | } |
| 7087 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7088 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7089 | @TelephonyManager.IsMultiSimSupportedResult |
| 7090 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7091 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7092 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7093 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7094 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7095 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7096 | } |
| 7097 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7098 | // supported by the modem, indicate that it is restricted. |
| 7099 | PhoneCapability staticCapability = |
| 7100 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7101 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7102 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7103 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7104 | } |
| 7105 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7106 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7107 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7108 | } |
| 7109 | // Check if support of multiple SIMs is restricted by carrier |
| 7110 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7111 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7112 | } |
| 7113 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7114 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7115 | } |
| 7116 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7117 | /** |
| 7118 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7119 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7120 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7121 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7122 | * @param numOfSims number of active sims we want to switch to |
| 7123 | */ |
| 7124 | @Override |
| 7125 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7126 | if (numOfSims == 1) { |
| 7127 | enforceModifyPermission(); |
| 7128 | } else { |
| 7129 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7130 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7131 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7132 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7133 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7134 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7135 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7136 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7137 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7138 | return; |
| 7139 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7140 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7141 | } finally { |
| 7142 | Binder.restoreCallingIdentity(identity); |
| 7143 | } |
| 7144 | } |
| 7145 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7146 | @Override |
| 7147 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7148 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7149 | Phone phone = getPhone(subId); |
| 7150 | if (phone == null) { |
| 7151 | return false; |
| 7152 | } |
| 7153 | final long identity = Binder.clearCallingIdentity(); |
| 7154 | try { |
| 7155 | UiccCard uiccCard = phone.getUiccCard(); |
| 7156 | if (uiccCard == null) { |
| 7157 | return false; |
| 7158 | } |
| 7159 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7160 | if (uiccProfile == null) { |
| 7161 | return false; |
| 7162 | } |
| 7163 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 7164 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 7165 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 7166 | } |
| 7167 | return false; |
| 7168 | } finally { |
| 7169 | Binder.restoreCallingIdentity(identity); |
| 7170 | } |
| 7171 | } |
| 7172 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7173 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7174 | * Get whether making changes to modem configurations will trigger reboot. |
| 7175 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7176 | */ |
| 7177 | @Override |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7178 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) { |
| 7179 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7180 | mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) { |
| 7181 | return false; |
| 7182 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7183 | final long identity = Binder.clearCallingIdentity(); |
| 7184 | try { |
| 7185 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7186 | } finally { |
| 7187 | Binder.restoreCallingIdentity(identity); |
| 7188 | } |
| 7189 | } |
| 7190 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7191 | private void updateModemStateMetrics() { |
| 7192 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7193 | // TODO: check the state for each modem if the api is ready. |
| 7194 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7195 | } |
| 7196 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7197 | @Override |
| 7198 | public int[] getSlotsMapping() { |
| 7199 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7200 | |
| 7201 | final long identity = Binder.clearCallingIdentity(); |
| 7202 | try { |
| 7203 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7204 | // All logical slots should have a mapping to a physical slot. |
| 7205 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7206 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7207 | for (int i = 0; i < slotInfos.length; i++) { |
| 7208 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7209 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7210 | } |
| 7211 | } |
| 7212 | return logicalSlotsMapping; |
| 7213 | } finally { |
| 7214 | Binder.restoreCallingIdentity(identity); |
| 7215 | } |
| 7216 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7217 | |
| 7218 | /** |
| 7219 | * Get the IRadio HAL Version |
| 7220 | */ |
| 7221 | @Override |
| 7222 | public int getRadioHalVersion() { |
| 7223 | Phone phone = getDefaultPhone(); |
| 7224 | if (phone == null) return -1; |
| 7225 | HalVersion hv = phone.getHalVersion(); |
| 7226 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7227 | return hv.major * 100 + hv.minor; |
| 7228 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7229 | |
| 7230 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7231 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7232 | * corresponding network requests on a subId. |
| 7233 | * |
| 7234 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7235 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7236 | * 2) APN is un-metered for this subscription, or |
| 7237 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7238 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7239 | * |
| 7240 | * @return whether data is allowed for a apn type. |
| 7241 | * |
| 7242 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7243 | */ |
| 7244 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7245 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 7246 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 7247 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7248 | |
| 7249 | // Now that all security checks passes, perform the operation as ourselves. |
| 7250 | final long identity = Binder.clearCallingIdentity(); |
| 7251 | try { |
| 7252 | Phone phone = getPhone(subId); |
| 7253 | if (phone == null) return false; |
| 7254 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7255 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7256 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7257 | } finally { |
| 7258 | Binder.restoreCallingIdentity(identity); |
| 7259 | } |
| 7260 | } |
| 7261 | |
| 7262 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7263 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7264 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7265 | |
| 7266 | // Now that all security checks passes, perform the operation as ourselves. |
| 7267 | final long identity = Binder.clearCallingIdentity(); |
| 7268 | try { |
| 7269 | Phone phone = getPhone(subId); |
| 7270 | if (phone == null) return true; // By default return true. |
| 7271 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7272 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7273 | } finally { |
| 7274 | Binder.restoreCallingIdentity(identity); |
| 7275 | } |
| 7276 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7277 | |
| 7278 | @Override |
| 7279 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7280 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7281 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7282 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7283 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7284 | } |
| 7285 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7286 | Intent intent = new Intent(); |
| 7287 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7288 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7289 | // Bring up choose default SMS subscription dialog right now |
| 7290 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7291 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7292 | mApp.startActivity(intent); |
| 7293 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7294 | |
| 7295 | @Override |
| 7296 | public String getMmsUAProfUrl(int subId) { |
| 7297 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7298 | final long identity = Binder.clearCallingIdentity(); |
| 7299 | try { |
| 7300 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7301 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7302 | } finally { |
| 7303 | Binder.restoreCallingIdentity(identity); |
| 7304 | } |
| 7305 | } |
| 7306 | |
| 7307 | @Override |
| 7308 | public String getMmsUserAgent(int subId) { |
| 7309 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7310 | final long identity = Binder.clearCallingIdentity(); |
| 7311 | try { |
| 7312 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7313 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7314 | } finally { |
| 7315 | Binder.restoreCallingIdentity(identity); |
| 7316 | } |
| 7317 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7318 | |
| 7319 | @Override |
| 7320 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7321 | enforceModifyPermission(); |
| 7322 | |
| 7323 | // Now that all security checks passes, perform the operation as ourselves. |
| 7324 | final long identity = Binder.clearCallingIdentity(); |
| 7325 | try { |
| 7326 | Phone phone = getPhone(subId); |
| 7327 | if (phone == null) return false; |
| 7328 | |
| 7329 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7330 | } finally { |
| 7331 | Binder.restoreCallingIdentity(identity); |
| 7332 | } |
| 7333 | } |
| 7334 | |
| 7335 | @Override |
| 7336 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7337 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7338 | |
| 7339 | // Now that all security checks passes, perform the operation as ourselves. |
| 7340 | final long identity = Binder.clearCallingIdentity(); |
| 7341 | try { |
| 7342 | Phone phone = getPhone(subId); |
| 7343 | if (phone == null) return false; |
| 7344 | |
| 7345 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7346 | } finally { |
| 7347 | Binder.restoreCallingIdentity(identity); |
| 7348 | } |
| 7349 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 7350 | |
| 7351 | /** |
| 7352 | * Updates whether conference event pacakge handling is enabled. |
| 7353 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 7354 | * otherwise. |
| 7355 | */ |
| 7356 | @Override |
| 7357 | public void setCepEnabled(boolean isCepEnabled) { |
| 7358 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 7359 | |
| 7360 | final long identity = Binder.clearCallingIdentity(); |
| 7361 | try { |
| 7362 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 7363 | for (Phone phone : PhoneFactory.getPhones()) { |
| 7364 | Phone defaultPhone = phone.getImsPhone(); |
| 7365 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7366 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7367 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 7368 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 7369 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 7370 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 7371 | + imsPhone.getMsisdn()); |
| 7372 | } |
| 7373 | } |
| 7374 | } finally { |
| 7375 | Binder.restoreCallingIdentity(identity); |
| 7376 | } |
| 7377 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7378 | } |