Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 22 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 23 | import android.Manifest.permission; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 24 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 26 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 27 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 28 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 31 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 32 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 33 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 34 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 36 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.Uri; |
| 38 | import android.os.AsyncResult; |
| 39 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 40 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
| 42 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.Looper; |
| 45 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 46 | import android.os.Messenger; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 47 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 48 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 49 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 50 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 52 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 53 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 54 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 59 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 60 | import android.provider.Telephony; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 61 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 62 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 63 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 64 | import android.telephony.Annotation.ApnType; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 65 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 66 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 67 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 68 | import android.telephony.CellInfoGsm; |
| 69 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 70 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 71 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 72 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 73 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 74 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 75 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 76 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 77 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 78 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 79 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 80 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 81 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 82 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 83 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 84 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 85 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 86 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 87 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 88 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 89 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 90 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 91 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 92 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 93 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 94 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 95 | import android.telephony.data.ApnSetting; |
| 96 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 97 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 98 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 99 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 100 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 101 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 102 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 103 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 104 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 105 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 107 | import android.telephony.ims.feature.MmTelFeature; |
| 108 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 109 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 110 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 111 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 112 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 113 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 114 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 115 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 116 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 117 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 121 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 125 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 129 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 131 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.ServiceStateTracker; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.SmsApplication; |
| 144 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
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; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.uicc.IccIoResult; |
| 156 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 164 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 165 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 166 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 167 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 168 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 169 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 170 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 171 | import java.io.FileDescriptor; |
| 172 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 173 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 174 | import java.util.Arrays; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 175 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 176 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 177 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 178 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 179 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 180 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 181 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 182 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 183 | |
| 184 | /** |
| 185 | * Implementation of the ITelephony interface. |
| 186 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 187 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 188 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 189 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 190 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 191 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | |
| 193 | // Message codes used with mMainThreadHandler |
| 194 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 195 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 196 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 197 | private static final int CMD_OPEN_CHANNEL = 9; |
| 198 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 199 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 200 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 201 | private static final int CMD_NV_READ_ITEM = 13; |
| 202 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 203 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 204 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 205 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 206 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 207 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 208 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 209 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 210 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 211 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 212 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 213 | private static final int CMD_SEND_ENVELOPE = 25; |
| 214 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 215 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 216 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 217 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 218 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 219 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 220 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 221 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 222 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 223 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 224 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 225 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 226 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 227 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 228 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 229 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 230 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 231 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 232 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 233 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 234 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 235 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 236 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 237 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 238 | private static final int CMD_SWITCH_SLOTS = 50; |
| 239 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 240 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 241 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 242 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 243 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 244 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 245 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 246 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 247 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 248 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 249 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 250 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 251 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 252 | private static final int CMD_MODEM_REBOOT = 64; |
| 253 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 254 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 255 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 256 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 257 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 258 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 259 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 260 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 261 | // Parameters of select command. |
| 262 | private static final int SELECT_COMMAND = 0xA4; |
| 263 | private static final int SELECT_P1 = 0x04; |
| 264 | private static final int SELECT_P2 = 0; |
| 265 | private static final int SELECT_P3 = 0x10; |
| 266 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 267 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 268 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 269 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 270 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 271 | /** The singleton instance. */ |
| 272 | private static PhoneInterfaceManager sInstance; |
| 273 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 274 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 275 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 276 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 277 | private AppOpsManager mAppOps; |
| 278 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 279 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 280 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 281 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 282 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 283 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 284 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 285 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 286 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 287 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 288 | // String to store multi SIM allowed |
| 289 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 290 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 291 | // The AID of ISD-R. |
| 292 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 293 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 294 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 295 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 296 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 297 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 298 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 299 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 300 | * A request object to use for transmitting data to an ICC. |
| 301 | */ |
| 302 | private static final class IccAPDUArgument { |
| 303 | public int channel, cla, command, p1, p2, p3; |
| 304 | public String data; |
| 305 | |
| 306 | public IccAPDUArgument(int channel, int cla, int command, |
| 307 | int p1, int p2, int p3, String data) { |
| 308 | this.channel = channel; |
| 309 | this.cla = cla; |
| 310 | this.command = command; |
| 311 | this.p1 = p1; |
| 312 | this.p2 = p2; |
| 313 | this.p3 = p3; |
| 314 | this.data = data; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 319 | * A request object to use for transmitting data to an ICC. |
| 320 | */ |
| 321 | private static final class ManualNetworkSelectionArgument { |
| 322 | public OperatorInfo operatorInfo; |
| 323 | public boolean persistSelection; |
| 324 | |
| 325 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 326 | this.operatorInfo = operatorInfo; |
| 327 | this.persistSelection = persistSelection; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 332 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 333 | * request after sending. The main thread will notify the request when it is complete. |
| 334 | */ |
| 335 | private static final class MainThreadRequest { |
| 336 | /** The argument to use for the request */ |
| 337 | public Object argument; |
| 338 | /** The result of the request that is run on the main thread */ |
| 339 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 340 | // The subscriber id that this request applies to. Defaults to |
| 341 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 342 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 343 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 344 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 345 | public Phone phone; |
| 346 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 347 | public WorkSource workSource; |
| 348 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 349 | public MainThreadRequest(Object argument) { |
| 350 | this.argument = argument; |
| 351 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 352 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 353 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 354 | this.argument = argument; |
| 355 | if (phone != null) { |
| 356 | this.phone = phone; |
| 357 | } |
| 358 | this.workSource = workSource; |
| 359 | } |
| 360 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 361 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 362 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 363 | if (subId != null) { |
| 364 | this.subId = subId; |
| 365 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 366 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 367 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 370 | private static final class IncomingThirdPartyCallArgs { |
| 371 | public final ComponentName component; |
| 372 | public final String callId; |
| 373 | public final String callerDisplayName; |
| 374 | |
| 375 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 376 | String callerDisplayName) { |
| 377 | this.component = component; |
| 378 | this.callId = callId; |
| 379 | this.callerDisplayName = callerDisplayName; |
| 380 | } |
| 381 | } |
| 382 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 383 | /** |
| 384 | * A handler that processes messages on the main thread in the phone process. Since many |
| 385 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 386 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 387 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 388 | * on, which will be notified when the operation completes and will contain the result of the |
| 389 | * request. |
| 390 | * |
| 391 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 392 | * note that request.result must be set to something non-null for the calling thread to |
| 393 | * unblock. |
| 394 | */ |
| 395 | private final class MainThreadHandler extends Handler { |
| 396 | @Override |
| 397 | public void handleMessage(Message msg) { |
| 398 | MainThreadRequest request; |
| 399 | Message onCompleted; |
| 400 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 401 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 402 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 403 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 404 | |
| 405 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 406 | case CMD_HANDLE_USSD_REQUEST: { |
| 407 | request = (MainThreadRequest) msg.obj; |
| 408 | final Phone phone = getPhoneFromRequest(request); |
| 409 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 410 | String ussdRequest = ussdObject.first; |
| 411 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 412 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 413 | if (!isUssdApiAllowed(request.subId)) { |
| 414 | // Carrier does not support use of this API, return failure. |
| 415 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 416 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 417 | Bundle returnData = new Bundle(); |
| 418 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 419 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 420 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 421 | request.result = true; |
| 422 | notifyRequester(request); |
| 423 | return; |
| 424 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 425 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 426 | try { |
| 427 | request.result = phone != null |
| 428 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 429 | } catch (CallStateException cse) { |
| 430 | request.result = false; |
| 431 | } |
| 432 | // Wake up the requesting thread |
| 433 | notifyRequester(request); |
| 434 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 437 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 438 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 439 | final Phone phone = getPhoneFromRequest(request); |
| 440 | request.result = phone != null ? |
| 441 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 442 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 443 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 444 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 445 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 446 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 447 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 448 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 449 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 450 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 451 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 452 | if (uiccCard == null) { |
| 453 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 454 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 455 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 456 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 457 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 458 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 459 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 460 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 461 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 462 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 463 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 464 | break; |
| 465 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 466 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 467 | ar = (AsyncResult) msg.obj; |
| 468 | request = (MainThreadRequest) ar.userObj; |
| 469 | if (ar.exception == null && ar.result != null) { |
| 470 | request.result = ar.result; |
| 471 | } else { |
| 472 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 473 | if (ar.result == null) { |
| 474 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 475 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 476 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 477 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 478 | } else { |
| 479 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 480 | } |
| 481 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 482 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 483 | break; |
| 484 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 485 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 486 | request = (MainThreadRequest) msg.obj; |
| 487 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 488 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 489 | if (uiccCard == null) { |
| 490 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 491 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 492 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 493 | } else { |
| 494 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 495 | request); |
| 496 | uiccCard.iccTransmitApduBasicChannel( |
| 497 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 498 | iccArgument.p3, iccArgument.data, onCompleted); |
| 499 | } |
| 500 | break; |
| 501 | |
| 502 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 503 | ar = (AsyncResult) msg.obj; |
| 504 | request = (MainThreadRequest) ar.userObj; |
| 505 | if (ar.exception == null && ar.result != null) { |
| 506 | request.result = ar.result; |
| 507 | } else { |
| 508 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 509 | if (ar.result == null) { |
| 510 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 511 | } else if (ar.exception instanceof CommandException) { |
| 512 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 513 | ar.exception); |
| 514 | } else { |
| 515 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 516 | } |
| 517 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 518 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 519 | break; |
| 520 | |
| 521 | case CMD_EXCHANGE_SIM_IO: |
| 522 | request = (MainThreadRequest) msg.obj; |
| 523 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 524 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 525 | if (uiccCard == null) { |
| 526 | loge("iccExchangeSimIO: No UICC"); |
| 527 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 528 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 529 | } else { |
| 530 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 531 | request); |
| 532 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 533 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 534 | iccArgument.data, onCompleted); |
| 535 | } |
| 536 | break; |
| 537 | |
| 538 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 539 | ar = (AsyncResult) msg.obj; |
| 540 | request = (MainThreadRequest) ar.userObj; |
| 541 | if (ar.exception == null && ar.result != null) { |
| 542 | request.result = ar.result; |
| 543 | } else { |
| 544 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 545 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 546 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 547 | break; |
| 548 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 549 | case CMD_SEND_ENVELOPE: |
| 550 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 551 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 552 | if (uiccCard == null) { |
| 553 | loge("sendEnvelopeWithStatus: No UICC"); |
| 554 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 555 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 556 | } else { |
| 557 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 558 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 559 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 560 | break; |
| 561 | |
| 562 | case EVENT_SEND_ENVELOPE_DONE: |
| 563 | ar = (AsyncResult) msg.obj; |
| 564 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 565 | if (ar.exception == null && ar.result != null) { |
| 566 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 567 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 568 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 569 | if (ar.result == null) { |
| 570 | loge("sendEnvelopeWithStatus: Empty response"); |
| 571 | } else if (ar.exception instanceof CommandException) { |
| 572 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 573 | ar.exception); |
| 574 | } else { |
| 575 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 576 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 577 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 578 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 579 | break; |
| 580 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 581 | case CMD_OPEN_CHANNEL: |
| 582 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 583 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 584 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 585 | if (uiccCard == null) { |
| 586 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 587 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 588 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 589 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 590 | } else { |
| 591 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 592 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 593 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 594 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 595 | break; |
| 596 | |
| 597 | case EVENT_OPEN_CHANNEL_DONE: |
| 598 | ar = (AsyncResult) msg.obj; |
| 599 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 600 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 601 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 602 | int[] result = (int[]) ar.result; |
| 603 | int channelId = result[0]; |
| 604 | byte[] selectResponse = null; |
| 605 | if (result.length > 1) { |
| 606 | selectResponse = new byte[result.length - 1]; |
| 607 | for (int i = 1; i < result.length; ++i) { |
| 608 | selectResponse[i - 1] = (byte) result[i]; |
| 609 | } |
| 610 | } |
| 611 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 612 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 613 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 614 | if (ar.result == null) { |
| 615 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 616 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 617 | if (ar.exception != null) { |
| 618 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 619 | } |
| 620 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 621 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 622 | if (ar.exception instanceof CommandException) { |
| 623 | CommandException.Error error = |
| 624 | ((CommandException) (ar.exception)).getCommandError(); |
| 625 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 626 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 627 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 628 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 632 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 633 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 634 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 635 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | break; |
| 637 | |
| 638 | case CMD_CLOSE_CHANNEL: |
| 639 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 640 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 641 | if (uiccCard == null) { |
| 642 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 643 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 644 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 645 | } else { |
| 646 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 647 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 648 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | break; |
| 650 | |
| 651 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 652 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 653 | break; |
| 654 | |
| 655 | case CMD_NV_READ_ITEM: |
| 656 | request = (MainThreadRequest) msg.obj; |
| 657 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 658 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 659 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 660 | break; |
| 661 | |
| 662 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | ar = (AsyncResult) msg.obj; |
| 664 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 665 | if (ar.exception == null && ar.result != null) { |
| 666 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 667 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 668 | request.result = ""; |
| 669 | if (ar.result == null) { |
| 670 | loge("nvReadItem: Empty response"); |
| 671 | } else if (ar.exception instanceof CommandException) { |
| 672 | loge("nvReadItem: CommandException: " + |
| 673 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 675 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 676 | } |
| 677 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 678 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | break; |
| 680 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 681 | case CMD_NV_WRITE_ITEM: |
| 682 | request = (MainThreadRequest) msg.obj; |
| 683 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 684 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 685 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 686 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 687 | break; |
| 688 | |
| 689 | case EVENT_NV_WRITE_ITEM_DONE: |
| 690 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 691 | break; |
| 692 | |
| 693 | case CMD_NV_WRITE_CDMA_PRL: |
| 694 | request = (MainThreadRequest) msg.obj; |
| 695 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 696 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 697 | break; |
| 698 | |
| 699 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 700 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 701 | break; |
| 702 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 703 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 704 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 705 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 706 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 707 | break; |
| 708 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 709 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 710 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 711 | break; |
| 712 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 713 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 714 | request = (MainThreadRequest) msg.obj; |
| 715 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 716 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 717 | break; |
| 718 | |
| 719 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 720 | ar = (AsyncResult) msg.obj; |
| 721 | request = (MainThreadRequest) ar.userObj; |
| 722 | if (ar.exception == null && ar.result != null) { |
| 723 | request.result = ar.result; // Integer |
| 724 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 725 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 726 | if (ar.result == null) { |
| 727 | loge("getPreferredNetworkType: Empty response"); |
| 728 | } else if (ar.exception instanceof CommandException) { |
| 729 | loge("getPreferredNetworkType: CommandException: " + |
| 730 | ar.exception); |
| 731 | } else { |
| 732 | loge("getPreferredNetworkType: Unknown exception"); |
| 733 | } |
| 734 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 735 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 736 | break; |
| 737 | |
| 738 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 739 | request = (MainThreadRequest) msg.obj; |
| 740 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 741 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 742 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 743 | break; |
| 744 | |
| 745 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 746 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 747 | break; |
| 748 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 749 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 750 | request = (MainThreadRequest)msg.obj; |
| 751 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 752 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 753 | break; |
| 754 | |
| 755 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 756 | ar = (AsyncResult)msg.obj; |
| 757 | request = (MainThreadRequest)ar.userObj; |
| 758 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 759 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 760 | break; |
| 761 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 762 | case CMD_SET_VOICEMAIL_NUMBER: |
| 763 | request = (MainThreadRequest) msg.obj; |
| 764 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 765 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 766 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 767 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 768 | break; |
| 769 | |
| 770 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 771 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 772 | break; |
| 773 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 774 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 775 | request = (MainThreadRequest) msg.obj; |
| 776 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 777 | request); |
| 778 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 779 | break; |
| 780 | |
| 781 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 782 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 783 | break; |
| 784 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 785 | case CMD_PERFORM_NETWORK_SCAN: |
| 786 | request = (MainThreadRequest) msg.obj; |
| 787 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 788 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 789 | break; |
| 790 | |
| 791 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 792 | ar = (AsyncResult) msg.obj; |
| 793 | request = (MainThreadRequest) ar.userObj; |
| 794 | CellNetworkScanResult cellScanResult; |
| 795 | if (ar.exception == null && ar.result != null) { |
| 796 | cellScanResult = new CellNetworkScanResult( |
| 797 | CellNetworkScanResult.STATUS_SUCCESS, |
| 798 | (List<OperatorInfo>) ar.result); |
| 799 | } else { |
| 800 | if (ar.result == null) { |
| 801 | loge("getCellNetworkScanResults: Empty response"); |
| 802 | } |
| 803 | if (ar.exception != null) { |
| 804 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 805 | } |
| 806 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 807 | if (ar.exception instanceof CommandException) { |
| 808 | CommandException.Error error = |
| 809 | ((CommandException) (ar.exception)).getCommandError(); |
| 810 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 811 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 812 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 813 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 814 | } |
| 815 | } |
| 816 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 817 | } |
| 818 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 819 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 820 | break; |
| 821 | |
| 822 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 823 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 824 | ManualNetworkSelectionArgument selArg = |
| 825 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 826 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 827 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 828 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 829 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 830 | break; |
| 831 | |
| 832 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 833 | ar = (AsyncResult) msg.obj; |
| 834 | request = (MainThreadRequest) ar.userObj; |
| 835 | if (ar.exception == null) { |
| 836 | request.result = true; |
| 837 | } else { |
| 838 | request.result = false; |
| 839 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 840 | } |
| 841 | notifyRequester(request); |
| 842 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 843 | break; |
| 844 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 845 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 846 | request = (MainThreadRequest) msg.obj; |
| 847 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 848 | if (defaultPhone != null) { |
| 849 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 850 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 851 | break; |
| 852 | |
| 853 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 854 | ar = (AsyncResult) msg.obj; |
| 855 | request = (MainThreadRequest) ar.userObj; |
| 856 | if (ar.exception == null && ar.result != null) { |
| 857 | request.result = ar.result; |
| 858 | } else { |
| 859 | if (ar.result == null) { |
| 860 | loge("queryModemActivityInfo: Empty response"); |
| 861 | } else if (ar.exception instanceof CommandException) { |
| 862 | loge("queryModemActivityInfo: CommandException: " + |
| 863 | ar.exception); |
| 864 | } else { |
| 865 | loge("queryModemActivityInfo: Unknown exception"); |
| 866 | } |
| 867 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 868 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 869 | if (request.result == null) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 870 | request.result = new ModemActivityInfo(0, 0, 0, null, 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 871 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 872 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 873 | break; |
| 874 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 875 | case CMD_SET_ALLOWED_CARRIERS: |
| 876 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 877 | CarrierRestrictionRules argument = |
| 878 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 879 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 880 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 881 | break; |
| 882 | |
| 883 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 884 | ar = (AsyncResult) msg.obj; |
| 885 | request = (MainThreadRequest) ar.userObj; |
| 886 | if (ar.exception == null && ar.result != null) { |
| 887 | request.result = ar.result; |
| 888 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 889 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 890 | if (ar.exception instanceof CommandException) { |
| 891 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 892 | CommandException.Error error = |
| 893 | ((CommandException) (ar.exception)).getCommandError(); |
| 894 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 895 | request.result = |
| 896 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 897 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 898 | } else { |
| 899 | loge("setAllowedCarriers: Unknown exception"); |
| 900 | } |
| 901 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 902 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 903 | break; |
| 904 | |
| 905 | case CMD_GET_ALLOWED_CARRIERS: |
| 906 | request = (MainThreadRequest) msg.obj; |
| 907 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 908 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 909 | break; |
| 910 | |
| 911 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 912 | ar = (AsyncResult) msg.obj; |
| 913 | request = (MainThreadRequest) ar.userObj; |
| 914 | if (ar.exception == null && ar.result != null) { |
| 915 | request.result = ar.result; |
| 916 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 917 | request.result = new IllegalStateException( |
| 918 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 919 | if (ar.result == null) { |
| 920 | loge("getAllowedCarriers: Empty response"); |
| 921 | } else if (ar.exception instanceof CommandException) { |
| 922 | loge("getAllowedCarriers: CommandException: " + |
| 923 | ar.exception); |
| 924 | } else { |
| 925 | loge("getAllowedCarriers: Unknown exception"); |
| 926 | } |
| 927 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 928 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 929 | break; |
| 930 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 931 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 932 | ar = (AsyncResult) msg.obj; |
| 933 | request = (MainThreadRequest) ar.userObj; |
| 934 | if (ar.exception == null && ar.result != null) { |
| 935 | request.result = ar.result; |
| 936 | } else { |
| 937 | request.result = new IllegalArgumentException( |
| 938 | "Failed to retrieve Forbidden Plmns"); |
| 939 | if (ar.result == null) { |
| 940 | loge("getForbiddenPlmns: Empty response"); |
| 941 | } else { |
| 942 | loge("getForbiddenPlmns: Unknown exception"); |
| 943 | } |
| 944 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 945 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 946 | break; |
| 947 | |
| 948 | case CMD_GET_FORBIDDEN_PLMNS: |
| 949 | request = (MainThreadRequest) msg.obj; |
| 950 | uiccCard = getUiccCardFromRequest(request); |
| 951 | if (uiccCard == null) { |
| 952 | loge("getForbiddenPlmns() UiccCard is null"); |
| 953 | request.result = new IllegalArgumentException( |
| 954 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 955 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 956 | break; |
| 957 | } |
| 958 | Integer appType = (Integer) request.argument; |
| 959 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 960 | if (uiccApp == null) { |
| 961 | loge("getForbiddenPlmns() no app with specified type -- " |
| 962 | + appType); |
| 963 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 964 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 965 | break; |
| 966 | } else { |
| 967 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 968 | + " specified type -- " + appType); |
| 969 | } |
| 970 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 971 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 972 | onCompleted); |
| 973 | break; |
| 974 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 975 | case CMD_SWITCH_SLOTS: |
| 976 | request = (MainThreadRequest) msg.obj; |
| 977 | int[] physicalSlots = (int[]) request.argument; |
| 978 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 979 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 980 | break; |
| 981 | |
| 982 | case EVENT_SWITCH_SLOTS_DONE: |
| 983 | ar = (AsyncResult) msg.obj; |
| 984 | request = (MainThreadRequest) ar.userObj; |
| 985 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 986 | notifyRequester(request); |
| 987 | break; |
| 988 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 989 | request = (MainThreadRequest) msg.obj; |
| 990 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 991 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 992 | break; |
| 993 | |
| 994 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 995 | ar = (AsyncResult) msg.obj; |
| 996 | request = (MainThreadRequest) ar.userObj; |
| 997 | if (ar.exception != null) { |
| 998 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 999 | } else { |
| 1000 | int mode = ((int[]) ar.result)[0]; |
| 1001 | if (mode == 0) { |
| 1002 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1003 | } else { |
| 1004 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1005 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1006 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1007 | notifyRequester(request); |
| 1008 | break; |
| 1009 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1010 | request = (MainThreadRequest) msg.obj; |
| 1011 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1012 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1013 | break; |
| 1014 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1015 | ar = (AsyncResult) msg.obj; |
| 1016 | request = (MainThreadRequest) ar.userObj; |
| 1017 | if (ar.exception != null) { |
| 1018 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1019 | } else { |
| 1020 | request.result = ((int[]) ar.result)[0]; |
| 1021 | } |
| 1022 | notifyRequester(request); |
| 1023 | break; |
| 1024 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1025 | request = (MainThreadRequest) msg.obj; |
| 1026 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1027 | int mode = (int) request.argument; |
| 1028 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1029 | break; |
| 1030 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1031 | ar = (AsyncResult) msg.obj; |
| 1032 | request = (MainThreadRequest) ar.userObj; |
| 1033 | request.result = ar.exception == null; |
| 1034 | notifyRequester(request); |
| 1035 | break; |
| 1036 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1037 | request = (MainThreadRequest) msg.obj; |
| 1038 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1039 | int subscriptionMode = (int) request.argument; |
| 1040 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1041 | break; |
| 1042 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1043 | ar = (AsyncResult) msg.obj; |
| 1044 | request = (MainThreadRequest) ar.userObj; |
| 1045 | request.result = ar.exception == null; |
| 1046 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1047 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1048 | case CMD_GET_ALL_CELL_INFO: |
| 1049 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1050 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1051 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1052 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1053 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1054 | ar = (AsyncResult) msg.obj; |
| 1055 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1056 | // If a timeout occurs, the response will be null |
| 1057 | request.result = (ar.exception == null && ar.result != null) |
| 1058 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1059 | synchronized (request) { |
| 1060 | request.notifyAll(); |
| 1061 | } |
| 1062 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1063 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1064 | request = (MainThreadRequest) msg.obj; |
| 1065 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1066 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1067 | break; |
| 1068 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1069 | ar = (AsyncResult) msg.obj; |
| 1070 | request = (MainThreadRequest) ar.userObj; |
| 1071 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1072 | try { |
| 1073 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1074 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1075 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1076 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1077 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1078 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1079 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1080 | } else { |
| 1081 | // use the result as returned |
| 1082 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1083 | } |
| 1084 | } catch (RemoteException re) { |
| 1085 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1086 | } |
| 1087 | break; |
| 1088 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1089 | request = (MainThreadRequest) msg.obj; |
| 1090 | WorkSource ws = (WorkSource) request.argument; |
| 1091 | Phone phone = getPhoneFromRequest(request); |
| 1092 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1093 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1094 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1095 | ar = (AsyncResult) msg.obj; |
| 1096 | request = (MainThreadRequest) ar.userObj; |
| 1097 | if (ar.exception == null) { |
| 1098 | request.result = ar.result; |
| 1099 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1100 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1101 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1102 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1103 | } |
| 1104 | |
| 1105 | synchronized (request) { |
| 1106 | request.notifyAll(); |
| 1107 | } |
| 1108 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1109 | case CMD_MODEM_REBOOT: |
| 1110 | request = (MainThreadRequest) msg.obj; |
| 1111 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1112 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1113 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1114 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1115 | handleNullReturnEvent(msg, "rebootModem"); |
| 1116 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1117 | case CMD_REQUEST_ENABLE_MODEM: |
| 1118 | request = (MainThreadRequest) msg.obj; |
| 1119 | boolean enable = (boolean) request.argument; |
| 1120 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1121 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1122 | PhoneConfigurationManager.getInstance() |
| 1123 | .enablePhone(request.phone, enable, onCompleted); |
| 1124 | break; |
| 1125 | case EVENT_ENABLE_MODEM_DONE: |
| 1126 | ar = (AsyncResult) msg.obj; |
| 1127 | request = (MainThreadRequest) ar.userObj; |
| 1128 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1129 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1130 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1131 | if ((boolean) request.result) { |
| 1132 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1133 | updateModemStateMetrics(); |
| 1134 | } else { |
| 1135 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1136 | + ar.exception); |
| 1137 | } |
| 1138 | notifyRequester(request); |
| 1139 | break; |
| 1140 | case CMD_GET_MODEM_STATUS: |
| 1141 | request = (MainThreadRequest) msg.obj; |
| 1142 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1143 | PhoneConfigurationManager.getInstance() |
| 1144 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1145 | break; |
| 1146 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1147 | ar = (AsyncResult) msg.obj; |
| 1148 | request = (MainThreadRequest) ar.userObj; |
| 1149 | int id = request.phone.getPhoneId(); |
| 1150 | if (ar.exception == null && ar.result != null) { |
| 1151 | request.result = ar.result; |
| 1152 | //update the cache as modem status has changed |
| 1153 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1154 | (boolean) request.result); |
| 1155 | } else { |
| 1156 | // Return true if modem status cannot be retrieved. For most cases, |
| 1157 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1158 | // and disable modem are not supported. Modem is always on. |
| 1159 | // TODO: this should be fixed in R to support a third |
| 1160 | // status UNKNOWN b/131631629 |
| 1161 | request.result = true; |
| 1162 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1163 | + ar.exception); |
| 1164 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1165 | notifyRequester(request); |
| 1166 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1167 | default: |
| 1168 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1169 | break; |
| 1170 | } |
| 1171 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1172 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1173 | private void notifyRequester(MainThreadRequest request) { |
| 1174 | synchronized (request) { |
| 1175 | request.notifyAll(); |
| 1176 | } |
| 1177 | } |
| 1178 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1179 | private void handleNullReturnEvent(Message msg, String command) { |
| 1180 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1181 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1182 | if (ar.exception == null) { |
| 1183 | request.result = true; |
| 1184 | } else { |
| 1185 | request.result = false; |
| 1186 | if (ar.exception instanceof CommandException) { |
| 1187 | loge(command + ": CommandException: " + ar.exception); |
| 1188 | } else { |
| 1189 | loge(command + ": Unknown exception"); |
| 1190 | } |
| 1191 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1192 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1193 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | /** |
| 1197 | * Posts the specified command to be executed on the main thread, |
| 1198 | * waits for the request to complete, and returns the result. |
| 1199 | * @see #sendRequestAsync |
| 1200 | */ |
| 1201 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1202 | return sendRequest( |
| 1203 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | /** |
| 1207 | * Posts the specified command to be executed on the main thread, |
| 1208 | * waits for the request to complete, and returns the result. |
| 1209 | * @see #sendRequestAsync |
| 1210 | */ |
| 1211 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1212 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1213 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | /** |
| 1217 | * Posts the specified command to be executed on the main thread, |
| 1218 | * waits for the request to complete, and returns the result. |
| 1219 | * @see #sendRequestAsync |
| 1220 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1221 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1222 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | /** |
| 1226 | * Posts the specified command to be executed on the main thread, |
| 1227 | * waits for the request to complete, and returns the result. |
| 1228 | * @see #sendRequestAsync |
| 1229 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1230 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1231 | return sendRequest(command, argument, subId, null, workSource); |
| 1232 | } |
| 1233 | |
| 1234 | /** |
| 1235 | * Posts the specified command to be executed on the main thread, |
| 1236 | * waits for the request to complete, and returns the result. |
| 1237 | * @see #sendRequestAsync |
| 1238 | */ |
| 1239 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1240 | return sendRequest( |
| 1241 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1242 | } |
| 1243 | |
| 1244 | /** |
| 1245 | * Posts the specified command to be executed on the main thread, |
| 1246 | * waits for the request to complete, and returns the result. |
| 1247 | * @see #sendRequestAsync |
| 1248 | */ |
| 1249 | private Object sendRequest( |
| 1250 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1251 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1252 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1253 | } |
| 1254 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1255 | MainThreadRequest request = null; |
| 1256 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1257 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1258 | } else if (phone != null) { |
| 1259 | request = new MainThreadRequest(argument, phone, workSource); |
| 1260 | } else { |
| 1261 | request = new MainThreadRequest(argument, subId, workSource); |
| 1262 | } |
| 1263 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1264 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1265 | msg.sendToTarget(); |
| 1266 | |
| 1267 | // Wait for the request to complete |
| 1268 | synchronized (request) { |
| 1269 | while (request.result == null) { |
| 1270 | try { |
| 1271 | request.wait(); |
| 1272 | } catch (InterruptedException e) { |
| 1273 | // Do nothing, go back and wait until the request is complete |
| 1274 | } |
| 1275 | } |
| 1276 | } |
| 1277 | return request.result; |
| 1278 | } |
| 1279 | |
| 1280 | /** |
| 1281 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1282 | * Posts the specified command to be executed on the main thread, and |
| 1283 | * returns immediately. |
| 1284 | * @see #sendRequest |
| 1285 | */ |
| 1286 | private void sendRequestAsync(int command) { |
| 1287 | mMainThreadHandler.sendEmptyMessage(command); |
| 1288 | } |
| 1289 | |
| 1290 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1291 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1292 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1293 | */ |
| 1294 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1295 | sendRequestAsync(command, argument, null, null); |
| 1296 | } |
| 1297 | |
| 1298 | /** |
| 1299 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1300 | * @see {@link #sendRequest(int,Object)} |
| 1301 | */ |
| 1302 | private void sendRequestAsync( |
| 1303 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1304 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1305 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1306 | msg.sendToTarget(); |
| 1307 | } |
| 1308 | |
| 1309 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1310 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1311 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1312 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1313 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1314 | synchronized (PhoneInterfaceManager.class) { |
| 1315 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1316 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1317 | } else { |
| 1318 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1319 | } |
| 1320 | return sInstance; |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1325 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1326 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1327 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1328 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1329 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1330 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1331 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1332 | mTelephonySharedPreferences = |
| 1333 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1334 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1335 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1336 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1337 | publish(); |
| 1338 | } |
| 1339 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1340 | private Phone getDefaultPhone() { |
| 1341 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1342 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1343 | } |
| 1344 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1345 | private void publish() { |
| 1346 | if (DBG) log("publish: " + this); |
| 1347 | |
| 1348 | ServiceManager.addService("phone", this); |
| 1349 | } |
| 1350 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1351 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1352 | if (request.phone != null) { |
| 1353 | return request.phone; |
| 1354 | } else { |
| 1355 | return getPhoneFromSubId(request.subId); |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | private Phone getPhoneFromSubId(int subId) { |
| 1360 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1361 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1362 | } |
| 1363 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1364 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1365 | Phone phone = getPhoneFromRequest(request); |
| 1366 | return phone == null ? null : |
| 1367 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1368 | } |
| 1369 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1370 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1371 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1372 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1373 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1374 | |
| 1375 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1376 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1379 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1380 | if (DBG) log("dial: " + number); |
| 1381 | // No permission check needed here: This is just a wrapper around the |
| 1382 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1383 | // the UI before it does anything. |
| 1384 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1385 | final long identity = Binder.clearCallingIdentity(); |
| 1386 | try { |
| 1387 | String url = createTelUrl(number); |
| 1388 | if (url == null) { |
| 1389 | return; |
| 1390 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1391 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1392 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1393 | PhoneConstants.State state = mCM.getState(subId); |
| 1394 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1395 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1396 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1397 | mApp.startActivity(intent); |
| 1398 | } |
| 1399 | } finally { |
| 1400 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1405 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1408 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1409 | if (DBG) log("call: " + number); |
| 1410 | |
| 1411 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1412 | // need to do a permission check since we're calling startActivity() |
| 1413 | // from the context of the phone app. |
| 1414 | enforceCallPermission(); |
| 1415 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1416 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1417 | != AppOpsManager.MODE_ALLOWED) { |
| 1418 | return; |
| 1419 | } |
| 1420 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1421 | final long identity = Binder.clearCallingIdentity(); |
| 1422 | try { |
| 1423 | String url = createTelUrl(number); |
| 1424 | if (url == null) { |
| 1425 | return; |
| 1426 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1427 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1428 | boolean isValid = false; |
| 1429 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1430 | if (slist != null) { |
| 1431 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1432 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1433 | isValid = true; |
| 1434 | break; |
| 1435 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1436 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1437 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1438 | if (!isValid) { |
| 1439 | return; |
| 1440 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1441 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1442 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1443 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1444 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1445 | mApp.startActivity(intent); |
| 1446 | } finally { |
| 1447 | Binder.restoreCallingIdentity(identity); |
| 1448 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1451 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1452 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1455 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1456 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1457 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1458 | } |
| 1459 | |
| 1460 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1461 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1464 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1465 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1466 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1467 | } |
| 1468 | |
| 1469 | /** {@hide} */ |
| 1470 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1471 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1474 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1475 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1476 | |
| 1477 | final long identity = Binder.clearCallingIdentity(); |
| 1478 | try { |
| 1479 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1480 | checkSimPin.start(); |
| 1481 | return checkSimPin.unlockSim(null, pin); |
| 1482 | } finally { |
| 1483 | Binder.restoreCallingIdentity(identity); |
| 1484 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1487 | /** {@hide} */ |
| 1488 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1489 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1492 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1493 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1494 | |
| 1495 | final long identity = Binder.clearCallingIdentity(); |
| 1496 | try { |
| 1497 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1498 | checkSimPuk.start(); |
| 1499 | return checkSimPuk.unlockSim(puk, pin); |
| 1500 | } finally { |
| 1501 | Binder.restoreCallingIdentity(identity); |
| 1502 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1506 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1507 | * a synchronous one. |
| 1508 | */ |
| 1509 | private static class UnlockSim extends Thread { |
| 1510 | |
| 1511 | private final IccCard mSimCard; |
| 1512 | |
| 1513 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1514 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1515 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1516 | |
| 1517 | // For replies from SimCard interface |
| 1518 | private Handler mHandler; |
| 1519 | |
| 1520 | // For async handler to identify request type |
| 1521 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1522 | |
| 1523 | public UnlockSim(IccCard simCard) { |
| 1524 | mSimCard = simCard; |
| 1525 | } |
| 1526 | |
| 1527 | @Override |
| 1528 | public void run() { |
| 1529 | Looper.prepare(); |
| 1530 | synchronized (UnlockSim.this) { |
| 1531 | mHandler = new Handler() { |
| 1532 | @Override |
| 1533 | public void handleMessage(Message msg) { |
| 1534 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1535 | switch (msg.what) { |
| 1536 | case SUPPLY_PIN_COMPLETE: |
| 1537 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1538 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1539 | mRetryCount = msg.arg1; |
| 1540 | if (ar.exception != null) { |
| 1541 | if (ar.exception instanceof CommandException && |
| 1542 | ((CommandException)(ar.exception)).getCommandError() |
| 1543 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1544 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1545 | } else { |
| 1546 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1547 | } |
| 1548 | } else { |
| 1549 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1550 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1551 | mDone = true; |
| 1552 | UnlockSim.this.notifyAll(); |
| 1553 | } |
| 1554 | break; |
| 1555 | } |
| 1556 | } |
| 1557 | }; |
| 1558 | UnlockSim.this.notifyAll(); |
| 1559 | } |
| 1560 | Looper.loop(); |
| 1561 | } |
| 1562 | |
| 1563 | /* |
| 1564 | * Use PIN or PUK to unlock SIM card |
| 1565 | * |
| 1566 | * If PUK is null, unlock SIM card with PIN |
| 1567 | * |
| 1568 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1569 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1570 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1571 | |
| 1572 | while (mHandler == null) { |
| 1573 | try { |
| 1574 | wait(); |
| 1575 | } catch (InterruptedException e) { |
| 1576 | Thread.currentThread().interrupt(); |
| 1577 | } |
| 1578 | } |
| 1579 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1580 | |
| 1581 | if (puk == null) { |
| 1582 | mSimCard.supplyPin(pin, callback); |
| 1583 | } else { |
| 1584 | mSimCard.supplyPuk(puk, pin, callback); |
| 1585 | } |
| 1586 | |
| 1587 | while (!mDone) { |
| 1588 | try { |
| 1589 | Log.d(LOG_TAG, "wait for done"); |
| 1590 | wait(); |
| 1591 | } catch (InterruptedException e) { |
| 1592 | // Restore the interrupted status |
| 1593 | Thread.currentThread().interrupt(); |
| 1594 | } |
| 1595 | } |
| 1596 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1597 | int[] resultArray = new int[2]; |
| 1598 | resultArray[0] = mResult; |
| 1599 | resultArray[1] = mRetryCount; |
| 1600 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1605 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1606 | |
| 1607 | } |
| 1608 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1609 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1610 | // No permission check needed here: this call is harmless, and it's |
| 1611 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1612 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1613 | final long identity = Binder.clearCallingIdentity(); |
| 1614 | try { |
| 1615 | final Phone phone = getPhone(subId); |
| 1616 | if (phone != null) { |
| 1617 | phone.updateServiceLocation(); |
| 1618 | } |
| 1619 | } finally { |
| 1620 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1621 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1624 | @Override |
| 1625 | public boolean isRadioOn(String callingPackage) { |
| 1626 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1629 | @Override |
| 1630 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1631 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1632 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1633 | return false; |
| 1634 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1635 | |
| 1636 | final long identity = Binder.clearCallingIdentity(); |
| 1637 | try { |
| 1638 | return isRadioOnForSubscriber(subId); |
| 1639 | } finally { |
| 1640 | Binder.restoreCallingIdentity(identity); |
| 1641 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1645 | final long identity = Binder.clearCallingIdentity(); |
| 1646 | try { |
| 1647 | final Phone phone = getPhone(subId); |
| 1648 | if (phone != null) { |
| 1649 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1650 | } else { |
| 1651 | return false; |
| 1652 | } |
| 1653 | } finally { |
| 1654 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1655 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1659 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1660 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1661 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1662 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1663 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1664 | |
| 1665 | final long identity = Binder.clearCallingIdentity(); |
| 1666 | try { |
| 1667 | final Phone phone = getPhone(subId); |
| 1668 | if (phone != null) { |
| 1669 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1670 | } |
| 1671 | } finally { |
| 1672 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1673 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1677 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1678 | } |
| 1679 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1680 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1681 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1682 | |
| 1683 | final long identity = Binder.clearCallingIdentity(); |
| 1684 | try { |
| 1685 | final Phone phone = getPhone(subId); |
| 1686 | if (phone == null) { |
| 1687 | return false; |
| 1688 | } |
| 1689 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1690 | toggleRadioOnOffForSubscriber(subId); |
| 1691 | } |
| 1692 | return true; |
| 1693 | } finally { |
| 1694 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1695 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1696 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1697 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1698 | public boolean needMobileRadioShutdown() { |
| 1699 | /* |
| 1700 | * If any of the Radios are available, it will need to be |
| 1701 | * shutdown. So return true if any Radio is available. |
| 1702 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1703 | final long identity = Binder.clearCallingIdentity(); |
| 1704 | try { |
| 1705 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1706 | Phone phone = PhoneFactory.getPhone(i); |
| 1707 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1708 | } |
| 1709 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1710 | return false; |
| 1711 | } finally { |
| 1712 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1713 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1716 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1717 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1718 | enforceModifyPermission(); |
| 1719 | |
| 1720 | final long identity = Binder.clearCallingIdentity(); |
| 1721 | try { |
| 1722 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1723 | logv("Shutting down Phone " + i); |
| 1724 | shutdownRadioUsingPhoneId(i); |
| 1725 | } |
| 1726 | } finally { |
| 1727 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1728 | } |
| 1729 | } |
| 1730 | |
| 1731 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1732 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1733 | if (phone != null && phone.isRadioAvailable()) { |
| 1734 | phone.shutdownRadio(); |
| 1735 | } |
| 1736 | } |
| 1737 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1738 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1739 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1740 | |
| 1741 | final long identity = Binder.clearCallingIdentity(); |
| 1742 | try { |
| 1743 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1744 | if (defaultPhone != null) { |
| 1745 | defaultPhone.setRadioPower(turnOn); |
| 1746 | return true; |
| 1747 | } else { |
| 1748 | loge("There's no default phone."); |
| 1749 | return false; |
| 1750 | } |
| 1751 | } finally { |
| 1752 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1753 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1756 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1757 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1758 | |
| 1759 | final long identity = Binder.clearCallingIdentity(); |
| 1760 | try { |
| 1761 | final Phone phone = getPhone(subId); |
| 1762 | if (phone != null) { |
| 1763 | phone.setRadioPower(turnOn); |
| 1764 | return true; |
| 1765 | } else { |
| 1766 | return false; |
| 1767 | } |
| 1768 | } finally { |
| 1769 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1770 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1773 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1774 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1775 | public boolean enableDataConnectivity() { |
| 1776 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1777 | |
| 1778 | final long identity = Binder.clearCallingIdentity(); |
| 1779 | try { |
| 1780 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1781 | final Phone phone = getPhone(subId); |
| 1782 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1783 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1784 | return true; |
| 1785 | } else { |
| 1786 | return false; |
| 1787 | } |
| 1788 | } finally { |
| 1789 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1790 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1793 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1794 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1795 | public boolean disableDataConnectivity() { |
| 1796 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1797 | |
| 1798 | final long identity = Binder.clearCallingIdentity(); |
| 1799 | try { |
| 1800 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1801 | final Phone phone = getPhone(subId); |
| 1802 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1803 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1804 | return true; |
| 1805 | } else { |
| 1806 | return false; |
| 1807 | } |
| 1808 | } finally { |
| 1809 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1810 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1813 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1814 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1815 | final long identity = Binder.clearCallingIdentity(); |
| 1816 | try { |
| 1817 | final Phone phone = getPhone(subId); |
| 1818 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1819 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1820 | } else { |
| 1821 | return false; |
| 1822 | } |
| 1823 | } finally { |
| 1824 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1825 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1829 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1832 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1833 | enforceCallPermission(); |
| 1834 | |
| 1835 | final long identity = Binder.clearCallingIdentity(); |
| 1836 | try { |
| 1837 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1838 | return; |
| 1839 | } |
| 1840 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1841 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1842 | } finally { |
| 1843 | Binder.restoreCallingIdentity(identity); |
| 1844 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1845 | }; |
| 1846 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1847 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1848 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1849 | |
| 1850 | final long identity = Binder.clearCallingIdentity(); |
| 1851 | try { |
| 1852 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1853 | return false; |
| 1854 | } |
| 1855 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1856 | } finally { |
| 1857 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1858 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1861 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1862 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1865 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1866 | final long identity = Binder.clearCallingIdentity(); |
| 1867 | try { |
| 1868 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1869 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1870 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1871 | } finally { |
| 1872 | Binder.restoreCallingIdentity(identity); |
| 1873 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1874 | } |
| 1875 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1876 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1877 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1878 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1879 | } |
| 1880 | |
| 1881 | @Override |
| 1882 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1883 | final long identity = Binder.clearCallingIdentity(); |
| 1884 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1885 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1886 | if (phone != null) { |
| 1887 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1888 | } else { |
| 1889 | return PhoneConstantConversions.convertDataState( |
| 1890 | PhoneConstants.DataState.DISCONNECTED); |
| 1891 | } |
| 1892 | } finally { |
| 1893 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1894 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1897 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1898 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1899 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1900 | } |
| 1901 | |
| 1902 | @Override |
| 1903 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1904 | final long identity = Binder.clearCallingIdentity(); |
| 1905 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1906 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1907 | if (phone != null) { |
| 1908 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1909 | } else { |
| 1910 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1911 | } |
| 1912 | } finally { |
| 1913 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1914 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1918 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1919 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1920 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1921 | |
| 1922 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1923 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1924 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1925 | .setCallingPackage(callingPackage) |
| 1926 | .setCallingPid(Binder.getCallingPid()) |
| 1927 | .setCallingUid(Binder.getCallingUid()) |
| 1928 | .setMethod("getCellLocation") |
| 1929 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1930 | .build()); |
| 1931 | switch (locationResult) { |
| 1932 | case DENIED_HARD: |
| 1933 | throw new SecurityException("Not allowed to access cell location"); |
| 1934 | case DENIED_SOFT: |
| 1935 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1938 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1939 | final long identity = Binder.clearCallingIdentity(); |
| 1940 | try { |
| 1941 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1942 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1943 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1944 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1945 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1946 | return data; |
| 1947 | } finally { |
| 1948 | Binder.restoreCallingIdentity(identity); |
| 1949 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1952 | @Override |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 1953 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) { |
| 1954 | if (!TextUtils.isEmpty(callingPackage)) { |
| 1955 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
| 1956 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 1957 | mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) { |
| 1958 | return ""; |
| 1959 | } |
| 1960 | } |
| 1961 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1962 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1963 | // registered cell info, so return a NULL country instead. |
| 1964 | final long identity = Binder.clearCallingIdentity(); |
| 1965 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1966 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1967 | // Get default phone in this case. |
| 1968 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1969 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1970 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1971 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1972 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1973 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1974 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1975 | return ""; |
| 1976 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1977 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1978 | if (phone != null) { |
| 1979 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 1980 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1981 | if (sst != null) { |
| 1982 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1983 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 1984 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 1985 | return lt.getCurrentCountry(); |
| 1986 | } else if (emergencyNumberTracker != null) { |
| 1987 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 1988 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1989 | } |
| 1990 | } |
| 1991 | } |
| 1992 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1993 | } finally { |
| 1994 | Binder.restoreCallingIdentity(identity); |
| 1995 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1999 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2000 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2003 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2004 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2005 | mApp.enforceCallingOrSelfPermission( |
| 2006 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2007 | |
| 2008 | final long identity = Binder.clearCallingIdentity(); |
| 2009 | try { |
| 2010 | final Phone phone = getPhone(subId); |
| 2011 | if (phone != null) { |
| 2012 | phone.enableLocationUpdates(); |
| 2013 | } |
| 2014 | } finally { |
| 2015 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2016 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | @Override |
| 2020 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2021 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2022 | } |
| 2023 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2024 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2025 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2026 | mApp.enforceCallingOrSelfPermission( |
| 2027 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2028 | |
| 2029 | final long identity = Binder.clearCallingIdentity(); |
| 2030 | try { |
| 2031 | final Phone phone = getPhone(subId); |
| 2032 | if (phone != null) { |
| 2033 | phone.disableLocationUpdates(); |
| 2034 | } |
| 2035 | } finally { |
| 2036 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2037 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2040 | /** |
| 2041 | * Returns the target SDK version number for a given package name. |
| 2042 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2043 | * This call MUST be invoked before clearing the calling UID. |
| 2044 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2045 | * @return target SDK if the package is found or INT_MAX. |
| 2046 | */ |
| 2047 | private int getTargetSdk(String packageName) { |
| 2048 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2049 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2050 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2051 | if (ai != null) return ai.targetSdkVersion; |
| 2052 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2053 | loge("Failed to get package info for pkg=" |
| 2054 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2055 | } |
| 2056 | return Integer.MAX_VALUE; |
| 2057 | } |
| 2058 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2059 | @Override |
| 2060 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2061 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2062 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2063 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2064 | throw new SecurityException( |
| 2065 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2066 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2067 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2068 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2069 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2070 | return null; |
| 2071 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2072 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2073 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2074 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2075 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2076 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2077 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2078 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2079 | for (CellInfo ci : info) { |
| 2080 | if (ci instanceof CellInfoGsm) { |
| 2081 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2082 | } else if (ci instanceof CellInfoWcdma) { |
| 2083 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2084 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2085 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2086 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2087 | } |
| 2088 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2089 | private List<CellInfo> getCachedCellInfo() { |
| 2090 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2091 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2092 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2093 | if (info != null) cellInfos.addAll(info); |
| 2094 | } |
| 2095 | return cellInfos; |
| 2096 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2097 | |
| 2098 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2099 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2100 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2101 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2102 | |
| 2103 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2104 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2105 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2106 | .setCallingPackage(callingPackage) |
| 2107 | .setCallingPid(Binder.getCallingPid()) |
| 2108 | .setCallingUid(Binder.getCallingUid()) |
| 2109 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2110 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2111 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2112 | .build()); |
| 2113 | switch (locationResult) { |
| 2114 | case DENIED_HARD: |
| 2115 | throw new SecurityException("Not allowed to access cell info"); |
| 2116 | case DENIED_SOFT: |
| 2117 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2118 | } |
| 2119 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2120 | final int targetSdk = getTargetSdk(callingPackage); |
| 2121 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2122 | return getCachedCellInfo(); |
| 2123 | } |
| 2124 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2125 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2126 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2127 | final long identity = Binder.clearCallingIdentity(); |
| 2128 | try { |
| 2129 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2130 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2131 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2132 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2133 | if (info != null) cellInfos.addAll(info); |
| 2134 | } |
| 2135 | return cellInfos; |
| 2136 | } finally { |
| 2137 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2138 | } |
| 2139 | } |
| 2140 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2141 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2142 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2143 | requestCellInfoUpdateInternal( |
| 2144 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2145 | } |
| 2146 | |
| 2147 | @Override |
| 2148 | public void requestCellInfoUpdateWithWorkSource( |
| 2149 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2150 | enforceModifyPermission(); |
| 2151 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2152 | } |
| 2153 | |
| 2154 | private void requestCellInfoUpdateInternal( |
| 2155 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2156 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2157 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2158 | |
| 2159 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2160 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2161 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2162 | .setCallingPackage(callingPackage) |
| 2163 | .setCallingPid(Binder.getCallingPid()) |
| 2164 | .setCallingUid(Binder.getCallingUid()) |
| 2165 | .setMethod("requestCellInfoUpdate") |
| 2166 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2167 | .build()); |
| 2168 | switch (locationResult) { |
| 2169 | case DENIED_HARD: |
| 2170 | throw new SecurityException("Not allowed to access cell info"); |
| 2171 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2172 | try { |
| 2173 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2174 | } catch (RemoteException re) { |
| 2175 | // Drop without consequences |
| 2176 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2177 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2178 | } |
| 2179 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2180 | |
| 2181 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2182 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2183 | |
| 2184 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2185 | } |
| 2186 | |
| 2187 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2188 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2189 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2190 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2191 | |
| 2192 | final long identity = Binder.clearCallingIdentity(); |
| 2193 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2194 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2195 | } finally { |
| 2196 | Binder.restoreCallingIdentity(identity); |
| 2197 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2198 | } |
| 2199 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2200 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2201 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2202 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2203 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2204 | return null; |
| 2205 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2206 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2207 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2208 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2209 | return null; |
| 2210 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2211 | |
| 2212 | final long identity = Binder.clearCallingIdentity(); |
| 2213 | try { |
| 2214 | return phone.getImei(); |
| 2215 | } finally { |
| 2216 | Binder.restoreCallingIdentity(identity); |
| 2217 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2221 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2222 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2223 | String tac = null; |
| 2224 | if (phone != null) { |
| 2225 | String imei = phone.getImei(); |
| 2226 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2227 | } |
| 2228 | return tac; |
| 2229 | } |
| 2230 | |
| 2231 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2232 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2233 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2234 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2235 | return null; |
| 2236 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2237 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2238 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2239 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2240 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2241 | return null; |
| 2242 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2243 | |
| 2244 | final long identity = Binder.clearCallingIdentity(); |
| 2245 | try { |
| 2246 | return phone.getMeid(); |
| 2247 | } finally { |
| 2248 | Binder.restoreCallingIdentity(identity); |
| 2249 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2253 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2254 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2255 | String manufacturerCode = null; |
| 2256 | if (phone != null) { |
| 2257 | String meid = phone.getMeid(); |
| 2258 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2259 | } |
| 2260 | return manufacturerCode; |
| 2261 | } |
| 2262 | |
| 2263 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2264 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2265 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2266 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2267 | return null; |
| 2268 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2269 | int subId = phone.getSubId(); |
| 2270 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2271 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2272 | return null; |
| 2273 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2274 | |
| 2275 | final long identity = Binder.clearCallingIdentity(); |
| 2276 | try { |
| 2277 | return phone.getDeviceSvn(); |
| 2278 | } finally { |
| 2279 | Binder.restoreCallingIdentity(identity); |
| 2280 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2283 | @Override |
| 2284 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2285 | final long identity = Binder.clearCallingIdentity(); |
| 2286 | try { |
| 2287 | final Phone phone = getPhone(subId); |
| 2288 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2289 | } finally { |
| 2290 | Binder.restoreCallingIdentity(identity); |
| 2291 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | @Override |
| 2295 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2296 | final long identity = Binder.clearCallingIdentity(); |
| 2297 | try { |
| 2298 | final Phone phone = getPhone(subId); |
| 2299 | return phone == null ? null : phone.getCarrierName(); |
| 2300 | } finally { |
| 2301 | Binder.restoreCallingIdentity(identity); |
| 2302 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2303 | } |
| 2304 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2305 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2306 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2307 | final long identity = Binder.clearCallingIdentity(); |
| 2308 | try { |
| 2309 | final Phone phone = getPhone(subId); |
| 2310 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2311 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2312 | } finally { |
| 2313 | Binder.restoreCallingIdentity(identity); |
| 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2318 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2319 | final long identity = Binder.clearCallingIdentity(); |
| 2320 | try { |
| 2321 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2322 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2323 | } finally { |
| 2324 | Binder.restoreCallingIdentity(identity); |
| 2325 | } |
| 2326 | } |
| 2327 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2328 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2329 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2330 | if (!isSubscriptionMccMnc) { |
| 2331 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2332 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2333 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2334 | if (phone == null) { |
| 2335 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2336 | } |
| 2337 | final long identity = Binder.clearCallingIdentity(); |
| 2338 | try { |
| 2339 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2340 | } finally { |
| 2341 | Binder.restoreCallingIdentity(identity); |
| 2342 | } |
| 2343 | } |
| 2344 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2345 | // |
| 2346 | // Internal helper methods. |
| 2347 | // |
| 2348 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2349 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2350 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2351 | * |
| 2352 | * @throws SecurityException if the caller does not have the required permission |
| 2353 | */ |
| 2354 | private void enforceModifyPermission() { |
| 2355 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2356 | } |
| 2357 | |
| 2358 | /** |
| 2359 | * Make sure the caller has the CALL_PHONE permission. |
| 2360 | * |
| 2361 | * @throws SecurityException if the caller does not have the required permission |
| 2362 | */ |
| 2363 | private void enforceCallPermission() { |
| 2364 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2365 | } |
| 2366 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2367 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2368 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2369 | "ConnectivityService"); |
| 2370 | } |
| 2371 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2372 | private String createTelUrl(String number) { |
| 2373 | if (TextUtils.isEmpty(number)) { |
| 2374 | return null; |
| 2375 | } |
| 2376 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2377 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2380 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2381 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2382 | } |
| 2383 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2384 | private static void logv(String msg) { |
| 2385 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2386 | } |
| 2387 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2388 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2389 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2390 | } |
| 2391 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2392 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2394 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2397 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2398 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2399 | final long identity = Binder.clearCallingIdentity(); |
| 2400 | try { |
| 2401 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2402 | if (phone == null) { |
| 2403 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2404 | } else { |
| 2405 | return phone.getPhoneType(); |
| 2406 | } |
| 2407 | } finally { |
| 2408 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2409 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | /** |
| 2413 | * Returns the CDMA ERI icon index to display |
| 2414 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2415 | @Override |
| 2416 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2417 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2418 | } |
| 2419 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2420 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2421 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2422 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2423 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2424 | return -1; |
| 2425 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2426 | |
| 2427 | final long identity = Binder.clearCallingIdentity(); |
| 2428 | try { |
| 2429 | final Phone phone = getPhone(subId); |
| 2430 | if (phone != null) { |
| 2431 | return phone.getCdmaEriIconIndex(); |
| 2432 | } else { |
| 2433 | return -1; |
| 2434 | } |
| 2435 | } finally { |
| 2436 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2437 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | /** |
| 2441 | * Returns the CDMA ERI icon mode, |
| 2442 | * 0 - ON |
| 2443 | * 1 - FLASHING |
| 2444 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2445 | @Override |
| 2446 | public int getCdmaEriIconMode(String callingPackage) { |
| 2447 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2448 | } |
| 2449 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2450 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2451 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2452 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2453 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2454 | return -1; |
| 2455 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2456 | |
| 2457 | final long identity = Binder.clearCallingIdentity(); |
| 2458 | try { |
| 2459 | final Phone phone = getPhone(subId); |
| 2460 | if (phone != null) { |
| 2461 | return phone.getCdmaEriIconMode(); |
| 2462 | } else { |
| 2463 | return -1; |
| 2464 | } |
| 2465 | } finally { |
| 2466 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2467 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | /** |
| 2471 | * Returns the CDMA ERI text, |
| 2472 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2473 | @Override |
| 2474 | public String getCdmaEriText(String callingPackage) { |
| 2475 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2478 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2479 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2480 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2481 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2482 | return null; |
| 2483 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2484 | |
| 2485 | final long identity = Binder.clearCallingIdentity(); |
| 2486 | try { |
| 2487 | final Phone phone = getPhone(subId); |
| 2488 | if (phone != null) { |
| 2489 | return phone.getCdmaEriText(); |
| 2490 | } else { |
| 2491 | return null; |
| 2492 | } |
| 2493 | } finally { |
| 2494 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2495 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2499 | * Returns the CDMA MDN. |
| 2500 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2501 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2502 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2503 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2504 | mApp, subId, "getCdmaMdn"); |
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); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2509 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2510 | return phone.getLine1Number(); |
| 2511 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2512 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2513 | return null; |
| 2514 | } |
| 2515 | } finally { |
| 2516 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2517 | } |
| 2518 | } |
| 2519 | |
| 2520 | /** |
| 2521 | * Returns the CDMA MIN. |
| 2522 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2523 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2524 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2525 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2526 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2527 | |
| 2528 | final long identity = Binder.clearCallingIdentity(); |
| 2529 | try { |
| 2530 | final Phone phone = getPhone(subId); |
| 2531 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2532 | return phone.getCdmaMin(); |
| 2533 | } else { |
| 2534 | return null; |
| 2535 | } |
| 2536 | } finally { |
| 2537 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2538 | } |
| 2539 | } |
| 2540 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2541 | @Override |
| 2542 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2543 | INumberVerificationCallback callback, String callingPackage) { |
| 2544 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2545 | != PERMISSION_GRANTED) { |
| 2546 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2547 | } |
| 2548 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2549 | |
| 2550 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2551 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2552 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2553 | } |
| 2554 | |
| 2555 | if (range == null) { |
| 2556 | throw new NullPointerException("Range must be non-null"); |
| 2557 | } |
| 2558 | |
| 2559 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2560 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2561 | |
| 2562 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2563 | } |
| 2564 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2565 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2566 | * Returns true if CDMA provisioning needs to run. |
| 2567 | */ |
| 2568 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2569 | final long identity = Binder.clearCallingIdentity(); |
| 2570 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2571 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2572 | } finally { |
| 2573 | Binder.restoreCallingIdentity(identity); |
| 2574 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2578 | * Sets the voice mail number of a given subId. |
| 2579 | */ |
| 2580 | @Override |
| 2581 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2582 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2583 | |
| 2584 | final long identity = Binder.clearCallingIdentity(); |
| 2585 | try { |
| 2586 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2587 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2588 | return success; |
| 2589 | } finally { |
| 2590 | Binder.restoreCallingIdentity(identity); |
| 2591 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2592 | } |
| 2593 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2594 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2595 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2596 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2597 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2598 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2599 | throw new SecurityException("caller must be system dialer"); |
| 2600 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2601 | |
| 2602 | final long identity = Binder.clearCallingIdentity(); |
| 2603 | try { |
| 2604 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2605 | if (phoneAccountHandle == null) { |
| 2606 | return null; |
| 2607 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2608 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2609 | } finally { |
| 2610 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2611 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2615 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2616 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2617 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2618 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2619 | return null; |
| 2620 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2621 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2622 | final long identity = Binder.clearCallingIdentity(); |
| 2623 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2624 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2625 | } finally { |
| 2626 | Binder.restoreCallingIdentity(identity); |
| 2627 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2631 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2632 | VisualVoicemailSmsFilterSettings settings) { |
| 2633 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2634 | |
| 2635 | final long identity = Binder.clearCallingIdentity(); |
| 2636 | try { |
| 2637 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2638 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2639 | } finally { |
| 2640 | Binder.restoreCallingIdentity(identity); |
| 2641 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2645 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2646 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2647 | |
| 2648 | final long identity = Binder.clearCallingIdentity(); |
| 2649 | try { |
| 2650 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2651 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2652 | } finally { |
| 2653 | Binder.restoreCallingIdentity(identity); |
| 2654 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
| 2657 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2658 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2659 | String callingPackage, int subId) { |
| 2660 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2661 | |
| 2662 | final long identity = Binder.clearCallingIdentity(); |
| 2663 | try { |
| 2664 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2665 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2666 | } finally { |
| 2667 | Binder.restoreCallingIdentity(identity); |
| 2668 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2672 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2673 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2674 | |
| 2675 | final long identity = Binder.clearCallingIdentity(); |
| 2676 | try { |
| 2677 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2678 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2679 | } finally { |
| 2680 | Binder.restoreCallingIdentity(identity); |
| 2681 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | @Override |
| 2685 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2686 | String number, int port, String text, PendingIntent sentIntent) { |
| 2687 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2688 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2689 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2690 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2691 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2692 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2693 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2694 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2695 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2696 | * Sets the voice activation state of a given subId. |
| 2697 | */ |
| 2698 | @Override |
| 2699 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2700 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2701 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2702 | |
| 2703 | final long identity = Binder.clearCallingIdentity(); |
| 2704 | try { |
| 2705 | final Phone phone = getPhone(subId); |
| 2706 | if (phone != null) { |
| 2707 | phone.setVoiceActivationState(activationState); |
| 2708 | } else { |
| 2709 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2710 | } |
| 2711 | } finally { |
| 2712 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2713 | } |
| 2714 | } |
| 2715 | |
| 2716 | /** |
| 2717 | * Sets the data activation state of a given subId. |
| 2718 | */ |
| 2719 | @Override |
| 2720 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2721 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2722 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2723 | |
| 2724 | final long identity = Binder.clearCallingIdentity(); |
| 2725 | try { |
| 2726 | final Phone phone = getPhone(subId); |
| 2727 | if (phone != null) { |
| 2728 | phone.setDataActivationState(activationState); |
| 2729 | } else { |
| 2730 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2731 | } |
| 2732 | } finally { |
| 2733 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | /** |
| 2738 | * Returns the voice activation state of a given subId. |
| 2739 | */ |
| 2740 | @Override |
| 2741 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2742 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2743 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2744 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2745 | final long identity = Binder.clearCallingIdentity(); |
| 2746 | try { |
| 2747 | if (phone != null) { |
| 2748 | return phone.getVoiceActivationState(); |
| 2749 | } else { |
| 2750 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2751 | } |
| 2752 | } finally { |
| 2753 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2754 | } |
| 2755 | } |
| 2756 | |
| 2757 | /** |
| 2758 | * Returns the data activation state of a given subId. |
| 2759 | */ |
| 2760 | @Override |
| 2761 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2762 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2763 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2764 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2765 | final long identity = Binder.clearCallingIdentity(); |
| 2766 | try { |
| 2767 | if (phone != null) { |
| 2768 | return phone.getDataActivationState(); |
| 2769 | } else { |
| 2770 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2771 | } |
| 2772 | } finally { |
| 2773 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2774 | } |
| 2775 | } |
| 2776 | |
| 2777 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2778 | * Returns the unread count of voicemails for a subId |
| 2779 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2780 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2781 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2782 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2783 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2784 | return 0; |
| 2785 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2786 | final long identity = Binder.clearCallingIdentity(); |
| 2787 | try { |
| 2788 | final Phone phone = getPhone(subId); |
| 2789 | if (phone != null) { |
| 2790 | return phone.getVoiceMessageCount(); |
| 2791 | } else { |
| 2792 | return 0; |
| 2793 | } |
| 2794 | } finally { |
| 2795 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2796 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2800 | * returns true, if the device is in a state where both voice and data |
| 2801 | * are supported simultaneously. This can change based on location or network condition. |
| 2802 | */ |
| 2803 | @Override |
| 2804 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2805 | final long identity = Binder.clearCallingIdentity(); |
| 2806 | try { |
| 2807 | final Phone phone = getPhone(subId); |
| 2808 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2809 | } finally { |
| 2810 | Binder.restoreCallingIdentity(identity); |
| 2811 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2815 | * Send the dialer code if called from the current default dialer or the caller has |
| 2816 | * carrier privilege. |
| 2817 | * @param inputCode The dialer code to send |
| 2818 | */ |
| 2819 | @Override |
| 2820 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2821 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2822 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2823 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2824 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2825 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2826 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2827 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2828 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2829 | |
| 2830 | final long identity = Binder.clearCallingIdentity(); |
| 2831 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2832 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2833 | } finally { |
| 2834 | Binder.restoreCallingIdentity(identity); |
| 2835 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2836 | } |
| 2837 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2838 | @Override |
| 2839 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2840 | if (!isActiveSubscription(subId)) { |
| 2841 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2842 | } |
| 2843 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2844 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2845 | } |
| 2846 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2847 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2848 | public boolean isInEmergencySmsMode() { |
| 2849 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2850 | final long identity = Binder.clearCallingIdentity(); |
| 2851 | try { |
| 2852 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2853 | if (phone.isInEmergencySmsMode()) { |
| 2854 | return true; |
| 2855 | } |
| 2856 | } |
| 2857 | } finally { |
| 2858 | Binder.restoreCallingIdentity(identity); |
| 2859 | } |
| 2860 | return false; |
| 2861 | } |
| 2862 | |
| 2863 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2864 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2865 | throws RemoteException { |
| 2866 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2867 | final long token = Binder.clearCallingIdentity(); |
| 2868 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2869 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2870 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2871 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2872 | } catch (ImsException e) { |
| 2873 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2874 | } finally { |
| 2875 | Binder.restoreCallingIdentity(token); |
| 2876 | } |
| 2877 | } |
| 2878 | |
| 2879 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2880 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2881 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2882 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2883 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2884 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 2885 | final long token = Binder.clearCallingIdentity(); |
| 2886 | try { |
| 2887 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 2888 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 2889 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2890 | } catch (ImsException e) { |
| 2891 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2892 | + "is inactive, ignoring unregister."); |
| 2893 | // If the subscription is no longer active, just return, since the callback |
| 2894 | // will already have been removed internally. |
| 2895 | } finally { |
| 2896 | Binder.restoreCallingIdentity(token); |
| 2897 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2898 | } |
| 2899 | |
| 2900 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2901 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2902 | throws RemoteException { |
| 2903 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2904 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2905 | final long token = Binder.clearCallingIdentity(); |
| 2906 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2907 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2908 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2909 | } catch (ImsException e) { |
| 2910 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2911 | } finally { |
| 2912 | Binder.restoreCallingIdentity(token); |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2917 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2918 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2919 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2920 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2921 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 2922 | |
| 2923 | final long token = Binder.clearCallingIdentity(); |
| 2924 | try { |
| 2925 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 2926 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2927 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 2928 | } catch (ImsException e) { |
| 2929 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2930 | + "is inactive, ignoring unregister."); |
| 2931 | // If the subscription is no longer active, just return, since the callback |
| 2932 | // will already have been removed internally. |
| 2933 | } finally { |
| 2934 | Binder.restoreCallingIdentity(token); |
| 2935 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2939 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2940 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2941 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2942 | final long token = Binder.clearCallingIdentity(); |
| 2943 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2944 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2945 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2946 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2947 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2948 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2949 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2950 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2951 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2952 | } finally { |
| 2953 | Binder.restoreCallingIdentity(token); |
| 2954 | } |
| 2955 | } |
| 2956 | |
| 2957 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2958 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2959 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2960 | final long token = Binder.clearCallingIdentity(); |
| 2961 | try { |
| 2962 | Phone phone = getPhone(subId); |
| 2963 | if (phone == null) return false; |
| 2964 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2965 | } finally { |
| 2966 | Binder.restoreCallingIdentity(token); |
| 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | @Override |
| 2971 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2972 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2973 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2974 | final long token = Binder.clearCallingIdentity(); |
| 2975 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2976 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2977 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2978 | } catch (ImsException e) { |
| 2979 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2980 | } finally { |
| 2981 | Binder.restoreCallingIdentity(token); |
| 2982 | } |
| 2983 | } |
| 2984 | |
| 2985 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2986 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2987 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2988 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2989 | final long identity = Binder.clearCallingIdentity(); |
| 2990 | try { |
| 2991 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2992 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2993 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2994 | } catch (ImsException e) { |
| 2995 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2996 | } finally { |
| 2997 | Binder.restoreCallingIdentity(identity); |
| 2998 | } |
| 2999 | } |
| 3000 | |
| 3001 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3002 | public boolean isVtSettingEnabled(int subId) { |
| 3003 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3004 | final long identity = Binder.clearCallingIdentity(); |
| 3005 | try { |
| 3006 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3007 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3008 | } catch (ImsException e) { |
| 3009 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3010 | } finally { |
| 3011 | Binder.restoreCallingIdentity(identity); |
| 3012 | } |
| 3013 | } |
| 3014 | |
| 3015 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3016 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3018 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3019 | final long identity = Binder.clearCallingIdentity(); |
| 3020 | try { |
| 3021 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3022 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3023 | } catch (ImsException e) { |
| 3024 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3025 | } finally { |
| 3026 | Binder.restoreCallingIdentity(identity); |
| 3027 | } |
| 3028 | } |
| 3029 | |
| 3030 | @Override |
| 3031 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3032 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3033 | final long identity = Binder.clearCallingIdentity(); |
| 3034 | try { |
| 3035 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3036 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3037 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3038 | } catch (ImsException e) { |
| 3039 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3040 | } finally { |
| 3041 | Binder.restoreCallingIdentity(identity); |
| 3042 | } |
| 3043 | } |
| 3044 | |
| 3045 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3046 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3047 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3048 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3049 | final long identity = Binder.clearCallingIdentity(); |
| 3050 | try { |
| 3051 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3052 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3053 | } catch (ImsException e) { |
| 3054 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3055 | } finally { |
| 3056 | Binder.restoreCallingIdentity(identity); |
| 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | @Override |
| 3061 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3062 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3063 | final long identity = Binder.clearCallingIdentity(); |
| 3064 | try { |
| 3065 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3066 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3067 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3068 | } catch (ImsException e) { |
| 3069 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3070 | } finally { |
| 3071 | Binder.restoreCallingIdentity(identity); |
| 3072 | } |
| 3073 | } |
| 3074 | |
| 3075 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3076 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3077 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3078 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3079 | final long identity = Binder.clearCallingIdentity(); |
| 3080 | try { |
| 3081 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3082 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3083 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3084 | } catch (ImsException e) { |
| 3085 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3086 | } finally { |
| 3087 | Binder.restoreCallingIdentity(identity); |
| 3088 | } |
| 3089 | } |
| 3090 | |
| 3091 | @Override |
| 3092 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3093 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3094 | "setVoWiFiNonPersistent"); |
| 3095 | final long identity = Binder.clearCallingIdentity(); |
| 3096 | try { |
| 3097 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3098 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3099 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3100 | } catch (ImsException e) { |
| 3101 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3102 | } finally { |
| 3103 | Binder.restoreCallingIdentity(identity); |
| 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | @Override |
| 3108 | public int getVoWiFiModeSetting(int subId) { |
| 3109 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3110 | final long identity = Binder.clearCallingIdentity(); |
| 3111 | try { |
| 3112 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3113 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3114 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3115 | } catch (ImsException e) { |
| 3116 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3117 | } finally { |
| 3118 | Binder.restoreCallingIdentity(identity); |
| 3119 | } |
| 3120 | } |
| 3121 | |
| 3122 | @Override |
| 3123 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3124 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3125 | "setVoWiFiModeSetting"); |
| 3126 | final long identity = Binder.clearCallingIdentity(); |
| 3127 | try { |
| 3128 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3129 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3130 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3131 | } catch (ImsException e) { |
| 3132 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3133 | } finally { |
| 3134 | Binder.restoreCallingIdentity(identity); |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | @Override |
| 3139 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3140 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3141 | final long identity = Binder.clearCallingIdentity(); |
| 3142 | try { |
| 3143 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3144 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3145 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3146 | } catch (ImsException e) { |
| 3147 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3148 | } finally { |
| 3149 | Binder.restoreCallingIdentity(identity); |
| 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | @Override |
| 3154 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3155 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3156 | "setVoWiFiRoamingModeSetting"); |
| 3157 | final long identity = Binder.clearCallingIdentity(); |
| 3158 | try { |
| 3159 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3160 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3161 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3162 | } catch (ImsException e) { |
| 3163 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3164 | } finally { |
| 3165 | Binder.restoreCallingIdentity(identity); |
| 3166 | } |
| 3167 | } |
| 3168 | |
| 3169 | @Override |
| 3170 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3171 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3172 | "setRttCapabilityEnabled"); |
| 3173 | final long identity = Binder.clearCallingIdentity(); |
| 3174 | try { |
| 3175 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3176 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3177 | } catch (ImsException e) { |
| 3178 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3179 | } finally { |
| 3180 | Binder.restoreCallingIdentity(identity); |
| 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | @Override |
| 3185 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3186 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3187 | final long identity = Binder.clearCallingIdentity(); |
| 3188 | try { |
| 3189 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3190 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3191 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3192 | } catch (ImsException e) { |
| 3193 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3194 | } finally { |
| 3195 | Binder.restoreCallingIdentity(identity); |
| 3196 | } |
| 3197 | } |
| 3198 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3199 | @Override |
| 3200 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3201 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3202 | final long identity = Binder.clearCallingIdentity(); |
| 3203 | try { |
| 3204 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3205 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3206 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3207 | } catch (ImsException e) { |
| 3208 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3209 | } finally { |
| 3210 | Binder.restoreCallingIdentity(identity); |
| 3211 | } |
| 3212 | } |
| 3213 | |
| 3214 | @Override |
| 3215 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3216 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3217 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3218 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3219 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3220 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3221 | try { |
| 3222 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3223 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3224 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3225 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3226 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3227 | + "is inactive, ignoring unregister."); |
| 3228 | // If the subscription is no longer active, just return, since the callback will already |
| 3229 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3230 | } finally { |
| 3231 | Binder.restoreCallingIdentity(identity); |
| 3232 | } |
| 3233 | } |
| 3234 | |
| 3235 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3236 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3237 | boolean isProvisioned) { |
| 3238 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3239 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3240 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3241 | } |
| 3242 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3243 | "setProvisioningStatusForCapability"); |
| 3244 | final long identity = Binder.clearCallingIdentity(); |
| 3245 | try { |
| 3246 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3247 | Phone phone = getPhone(subId); |
| 3248 | if (phone == null) { |
| 3249 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3250 | + subId); |
| 3251 | return; |
| 3252 | } |
| 3253 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3254 | return; |
| 3255 | } |
| 3256 | |
| 3257 | // this capability requires provisioning, route to the correct API. |
| 3258 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3259 | switch (capability) { |
| 3260 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3261 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3262 | ims.setVolteProvisioned(isProvisioned); |
| 3263 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3264 | ims.setWfcProvisioned(isProvisioned); |
| 3265 | } |
| 3266 | break; |
| 3267 | } |
| 3268 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3269 | // There is currently no difference in VT provisioning type. |
| 3270 | ims.setVtProvisioned(isProvisioned); |
| 3271 | break; |
| 3272 | } |
| 3273 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3274 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3275 | // change the capability of the feature instead if needed. |
| 3276 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3277 | == isProvisioned) { |
| 3278 | // No change in provisioning. |
| 3279 | return; |
| 3280 | } |
| 3281 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3282 | try { |
| 3283 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3284 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3285 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3286 | + ", Exception" + e.getMessage()); |
| 3287 | } |
| 3288 | break; |
| 3289 | } |
| 3290 | default: { |
| 3291 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3292 | + capability + "', which does not require provisioning."); |
| 3293 | } |
| 3294 | } |
| 3295 | |
| 3296 | } finally { |
| 3297 | Binder.restoreCallingIdentity(identity); |
| 3298 | } |
| 3299 | } |
| 3300 | |
| 3301 | @Override |
| 3302 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3303 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3304 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3305 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3306 | } |
| 3307 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3308 | final long identity = Binder.clearCallingIdentity(); |
| 3309 | try { |
| 3310 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3311 | Phone phone = getPhone(subId); |
| 3312 | if (phone == null) { |
| 3313 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3314 | + subId); |
| 3315 | // We will fail with "true" as the provisioning status because this is the default |
| 3316 | // if we do not require provisioning. |
| 3317 | return true; |
| 3318 | } |
| 3319 | |
| 3320 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3321 | return true; |
| 3322 | } |
| 3323 | |
| 3324 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3325 | switch (capability) { |
| 3326 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3327 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3328 | return ims.isVolteProvisionedOnDevice(); |
| 3329 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3330 | return ims.isWfcProvisionedOnDevice(); |
| 3331 | } |
| 3332 | // This should never happen, since we are checking tech above to make sure it |
| 3333 | // is either LTE or IWLAN. |
| 3334 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3335 | + "capability."); |
| 3336 | } |
| 3337 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3338 | // There is currently no difference in VT provisioning type. |
| 3339 | return ims.isVtProvisionedOnDevice(); |
| 3340 | } |
| 3341 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3342 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3343 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3344 | } |
| 3345 | default: { |
| 3346 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3347 | + capability + "', which does not require provisioning."); |
| 3348 | } |
| 3349 | } |
| 3350 | |
| 3351 | } finally { |
| 3352 | Binder.restoreCallingIdentity(identity); |
| 3353 | } |
| 3354 | } |
| 3355 | |
| 3356 | @Override |
| 3357 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3358 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3359 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3360 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3361 | } |
| 3362 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3363 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3364 | return (provisionedBits & capability) > 0; |
| 3365 | } |
| 3366 | |
| 3367 | @Override |
| 3368 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3369 | boolean isProvisioned) { |
| 3370 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3371 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3372 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3373 | } |
| 3374 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3375 | "setProvisioningStatusForCapability"); |
| 3376 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3377 | // If the current provisioning status for capability already matches isProvisioned, |
| 3378 | // do nothing. |
| 3379 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3380 | return; |
| 3381 | } |
| 3382 | if (isProvisioned) { |
| 3383 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3384 | } else { |
| 3385 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3386 | } |
| 3387 | } |
| 3388 | |
| 3389 | /** |
| 3390 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3391 | * technology. The bitfield should mirror the bitfield defined by |
| 3392 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3393 | */ |
| 3394 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3395 | String key = getMmTelProvisioningKey(subId, tech); |
| 3396 | // Default is no capabilities are provisioned. |
| 3397 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3398 | } |
| 3399 | |
| 3400 | /** |
| 3401 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3402 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3403 | * technology specified. |
| 3404 | * |
| 3405 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3406 | */ |
| 3407 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3408 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3409 | String key = getMmTelProvisioningKey(subId, tech); |
| 3410 | editor.putInt(key, newField); |
| 3411 | editor.commit(); |
| 3412 | } |
| 3413 | |
| 3414 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3415 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3416 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3417 | } |
| 3418 | |
| 3419 | /** |
| 3420 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3421 | * carrier associated with the subscription id. |
| 3422 | */ |
| 3423 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3424 | int capability) { |
| 3425 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3426 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3427 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3428 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3429 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3430 | false); |
| 3431 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3432 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3433 | |
| 3434 | // First check to make sure that the capability requires provisioning. |
| 3435 | switch (capability) { |
| 3436 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3437 | // intentional fallthrough |
| 3438 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3439 | if (requireVoiceVtProvisioning) { |
| 3440 | // Voice and Video requires provisioning |
| 3441 | return true; |
| 3442 | } |
| 3443 | break; |
| 3444 | } |
| 3445 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3446 | if (requireUtProvisioning) { |
| 3447 | // UT requires provisioning |
| 3448 | return true; |
| 3449 | } |
| 3450 | break; |
| 3451 | } |
| 3452 | } |
| 3453 | return false; |
| 3454 | } |
| 3455 | |
| 3456 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3457 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3458 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3459 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3460 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3461 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3462 | final long identity = Binder.clearCallingIdentity(); |
| 3463 | try { |
| 3464 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3465 | int slotId = getSlotIndex(subId); |
| 3466 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3467 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3468 | + subId + "' for key:" + key); |
| 3469 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3470 | } |
| 3471 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3472 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3473 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3474 | + subId + "' for key:" + key); |
| 3475 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3476 | } finally { |
| 3477 | Binder.restoreCallingIdentity(identity); |
| 3478 | } |
| 3479 | } |
| 3480 | |
| 3481 | @Override |
| 3482 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3483 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3484 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3485 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3486 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3487 | final long identity = Binder.clearCallingIdentity(); |
| 3488 | try { |
| 3489 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3490 | int slotId = getSlotIndex(subId); |
| 3491 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3492 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3493 | + subId + "' for key:" + key); |
| 3494 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3495 | } |
| 3496 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3497 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3498 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3499 | + subId + "' for key:" + key); |
| 3500 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3501 | } finally { |
| 3502 | Binder.restoreCallingIdentity(identity); |
| 3503 | } |
| 3504 | } |
| 3505 | |
| 3506 | @Override |
| 3507 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3508 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3509 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3510 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3511 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3512 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3513 | final long identity = Binder.clearCallingIdentity(); |
| 3514 | try { |
| 3515 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3516 | int slotId = getSlotIndex(subId); |
| 3517 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3518 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3519 | + subId + "' for key:" + key); |
| 3520 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3521 | } |
| 3522 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3523 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3524 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3525 | + "' for key:" + key); |
| 3526 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3527 | } finally { |
| 3528 | Binder.restoreCallingIdentity(identity); |
| 3529 | } |
| 3530 | } |
| 3531 | |
| 3532 | @Override |
| 3533 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3534 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3535 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3536 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3537 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3538 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3539 | final long identity = Binder.clearCallingIdentity(); |
| 3540 | try { |
| 3541 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3542 | int slotId = getSlotIndex(subId); |
| 3543 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3544 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3545 | + subId + "' for key:" + key); |
| 3546 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3547 | } |
| 3548 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3549 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3550 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3551 | + "' for key:" + key); |
| 3552 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3553 | } finally { |
| 3554 | Binder.restoreCallingIdentity(identity); |
| 3555 | } |
| 3556 | } |
| 3557 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3558 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3559 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3560 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3561 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 3562 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3563 | } |
| 3564 | return slotId; |
| 3565 | } |
| 3566 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3567 | private int getSlotIndex(int subId) { |
| 3568 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3569 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3570 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3571 | } |
| 3572 | return slotId; |
| 3573 | } |
| 3574 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3575 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3576 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3577 | */ |
| 3578 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3579 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3580 | final int targetSdk = getTargetSdk(callingPackage); |
| 3581 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
| 3582 | return getDataNetworkTypeForSubscriber(subId, callingPackage); |
| 3583 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3584 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
| 3585 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3586 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3587 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3588 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3589 | final long identity = Binder.clearCallingIdentity(); |
| 3590 | try { |
| 3591 | final Phone phone = getPhone(subId); |
| 3592 | if (phone != null) { |
| 3593 | return phone.getServiceState().getDataNetworkType(); |
| 3594 | } else { |
| 3595 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3596 | } |
| 3597 | } finally { |
| 3598 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3599 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | /** |
| 3603 | * Returns the data network type |
| 3604 | */ |
| 3605 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3606 | public int getDataNetworkType(String callingPackage) { |
| 3607 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | /** |
| 3611 | * Returns the data network type for a subId |
| 3612 | */ |
| 3613 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3614 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3615 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3616 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3617 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3618 | } |
| 3619 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3620 | final long identity = Binder.clearCallingIdentity(); |
| 3621 | try { |
| 3622 | final Phone phone = getPhone(subId); |
| 3623 | if (phone != null) { |
| 3624 | return phone.getServiceState().getDataNetworkType(); |
| 3625 | } else { |
| 3626 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3627 | } |
| 3628 | } finally { |
| 3629 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3630 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3631 | } |
| 3632 | |
| 3633 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3634 | * Returns the Voice network type for a subId |
| 3635 | */ |
| 3636 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3637 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3638 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3639 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3640 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3641 | } |
| 3642 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3643 | final long identity = Binder.clearCallingIdentity(); |
| 3644 | try { |
| 3645 | final Phone phone = getPhone(subId); |
| 3646 | if (phone != null) { |
| 3647 | return phone.getServiceState().getVoiceNetworkType(); |
| 3648 | } else { |
| 3649 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3650 | } |
| 3651 | } finally { |
| 3652 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3653 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3654 | } |
| 3655 | |
| 3656 | /** |
| 3657 | * @return true if a ICC card is present |
| 3658 | */ |
| 3659 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3660 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3661 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3662 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3666 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3667 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3668 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3669 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3670 | final long identity = Binder.clearCallingIdentity(); |
| 3671 | try { |
| 3672 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3673 | if (phone != null) { |
| 3674 | return phone.getIccCard().hasIccCard(); |
| 3675 | } else { |
| 3676 | return false; |
| 3677 | } |
| 3678 | } finally { |
| 3679 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3680 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3681 | } |
| 3682 | |
| 3683 | /** |
| 3684 | * Return if the current radio is LTE on CDMA. This |
| 3685 | * is a tri-state return value as for a period of time |
| 3686 | * the mode may be unknown. |
| 3687 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3688 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3689 | * @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] | 3690 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3691 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3692 | @Override |
| 3693 | public int getLteOnCdmaMode(String callingPackage) { |
| 3694 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3695 | } |
| 3696 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3697 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3698 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3699 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3700 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3701 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3702 | } |
| 3703 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3704 | final long identity = Binder.clearCallingIdentity(); |
| 3705 | try { |
| 3706 | final Phone phone = getPhone(subId); |
| 3707 | if (phone == null) { |
| 3708 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3709 | } else { |
| 3710 | return phone.getLteOnCdmaMode(); |
| 3711 | } |
| 3712 | } finally { |
| 3713 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3714 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3715 | } |
| 3716 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3717 | /** |
| 3718 | * {@hide} |
| 3719 | * Returns Default subId, 0 in the case of single standby. |
| 3720 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3721 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3722 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3723 | } |
| 3724 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3725 | private int getSlotForDefaultSubscription() { |
| 3726 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3727 | } |
| 3728 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3729 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3730 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3731 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3732 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3733 | private boolean isActiveSubscription(int subId) { |
| 3734 | return mSubscriptionController.isActiveSubId(subId); |
| 3735 | } |
| 3736 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3737 | /** |
| 3738 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3739 | */ |
| 3740 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3741 | final long identity = Binder.clearCallingIdentity(); |
| 3742 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3743 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3744 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3745 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3746 | } finally { |
| 3747 | Binder.restoreCallingIdentity(identity); |
| 3748 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | /** |
| 3752 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3753 | */ |
| 3754 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3755 | final long identity = Binder.clearCallingIdentity(); |
| 3756 | try { |
| 3757 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3758 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3759 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3760 | } finally { |
| 3761 | Binder.restoreCallingIdentity(identity); |
| 3762 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3763 | } |
| 3764 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3765 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3766 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3767 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3768 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3769 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3770 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3771 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3772 | if (phoneId == -1) { |
| 3773 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3774 | + " does not correspond to an active phone"); |
| 3775 | } |
| 3776 | return PhoneFactory.getPhone(phoneId); |
| 3777 | } |
| 3778 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3779 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3780 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3781 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3782 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3783 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3784 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3785 | if (DBG) { |
| 3786 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3787 | } |
| 3788 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3789 | p2); |
| 3790 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3791 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3792 | |
| 3793 | @Override |
| 3794 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3795 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3796 | enforceModifyPermission(); |
| 3797 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3798 | if (DBG) { |
| 3799 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3800 | } |
| 3801 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3802 | callingPackage, aid, p2); |
| 3803 | } |
| 3804 | |
| 3805 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3806 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3807 | final long identity = Binder.clearCallingIdentity(); |
| 3808 | try { |
| 3809 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3810 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3811 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3812 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3813 | if (bestComponent == null |
| 3814 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3815 | loge("The calling package is not allowed to access ISD-R."); |
| 3816 | throw new SecurityException( |
| 3817 | "The calling package is not allowed to access ISD-R."); |
| 3818 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3819 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3820 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3821 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3822 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3823 | null /* workSource */); |
| 3824 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3825 | return response; |
| 3826 | } finally { |
| 3827 | Binder.restoreCallingIdentity(identity); |
| 3828 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3829 | } |
| 3830 | |
| 3831 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3832 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3833 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3834 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3835 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3836 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3837 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3838 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3839 | @Override |
| 3840 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3841 | enforceModifyPermission(); |
| 3842 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3843 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3844 | channel); |
| 3845 | } |
| 3846 | |
| 3847 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3848 | final long identity = Binder.clearCallingIdentity(); |
| 3849 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3850 | if (channel < 0) { |
| 3851 | return false; |
| 3852 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3853 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3854 | null /* workSource */); |
| 3855 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3856 | return success; |
| 3857 | } finally { |
| 3858 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3859 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3863 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3864 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3865 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3866 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3867 | if (DBG) { |
| 3868 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3869 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3870 | + p3 + " data=" + data); |
| 3871 | } |
| 3872 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3873 | command, p1, p2, p3, data); |
| 3874 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3875 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3876 | @Override |
| 3877 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3878 | int command, int p1, int p2, int p3, String data) { |
| 3879 | enforceModifyPermission(); |
| 3880 | if (DBG) { |
| 3881 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3882 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3883 | + p3 + " data=" + data); |
| 3884 | } |
| 3885 | return iccTransmitApduLogicalChannelWithPermission( |
| 3886 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3887 | data); |
| 3888 | } |
| 3889 | |
| 3890 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3891 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3892 | final long identity = Binder.clearCallingIdentity(); |
| 3893 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 3894 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3895 | return ""; |
| 3896 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3897 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3898 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3899 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3900 | null /* workSource */); |
| 3901 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3902 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3903 | // Append the returned status code to the end of the response payload. |
| 3904 | String s = Integer.toHexString( |
| 3905 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3906 | if (response.payload != null) { |
| 3907 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3908 | } |
| 3909 | return s; |
| 3910 | } finally { |
| 3911 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3912 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3913 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3914 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3915 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3916 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3917 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3918 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3919 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3920 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3921 | if (DBG) { |
| 3922 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3923 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3924 | } |
| 3925 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3926 | cla, command, p1, p2, p3, data); |
| 3927 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3928 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3929 | @Override |
| 3930 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3931 | int command, int p1, int p2, int p3, String data) { |
| 3932 | enforceModifyPermission(); |
| 3933 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3934 | if (DBG) { |
| 3935 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3936 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3937 | + " data=" + data); |
| 3938 | } |
| 3939 | |
| 3940 | return iccTransmitApduBasicChannelWithPermission( |
| 3941 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3942 | p2, p3, data); |
| 3943 | } |
| 3944 | |
| 3945 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3946 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3947 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3948 | final long identity = Binder.clearCallingIdentity(); |
| 3949 | try { |
| 3950 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3951 | && TextUtils.equals(ISDR_AID, data)) { |
| 3952 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3953 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3954 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3955 | if (bestComponent == null |
| 3956 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3957 | loge("The calling package is not allowed to select ISD-R."); |
| 3958 | throw new SecurityException( |
| 3959 | "The calling package is not allowed to select ISD-R."); |
| 3960 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3961 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3962 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3963 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3964 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 3965 | null /* workSource */); |
| 3966 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3967 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3968 | // Append the returned status code to the end of the response payload. |
| 3969 | String s = Integer.toHexString( |
| 3970 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3971 | if (response.payload != null) { |
| 3972 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3973 | } |
| 3974 | return s; |
| 3975 | } finally { |
| 3976 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3977 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3978 | } |
| 3979 | |
| 3980 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3981 | 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] | 3982 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3983 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3984 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3985 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3986 | final long identity = Binder.clearCallingIdentity(); |
| 3987 | try { |
| 3988 | if (DBG) { |
| 3989 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3990 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3991 | } |
| 3992 | |
| 3993 | IccIoResult response = |
| 3994 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3995 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3996 | subId); |
| 3997 | |
| 3998 | if (DBG) { |
| 3999 | log("Exchange SIM_IO [R]" + response); |
| 4000 | } |
| 4001 | |
| 4002 | byte[] result = null; |
| 4003 | int length = 2; |
| 4004 | if (response.payload != null) { |
| 4005 | length = 2 + response.payload.length; |
| 4006 | result = new byte[length]; |
| 4007 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4008 | } else { |
| 4009 | result = new byte[length]; |
| 4010 | } |
| 4011 | |
| 4012 | result[length - 1] = (byte) response.sw2; |
| 4013 | result[length - 2] = (byte) response.sw1; |
| 4014 | return result; |
| 4015 | } finally { |
| 4016 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4017 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4018 | } |
| 4019 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4020 | /** |
| 4021 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4022 | * on a particular subscription |
| 4023 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4024 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 4025 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4026 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 4027 | return null; |
| 4028 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4029 | |
| 4030 | final long identity = Binder.clearCallingIdentity(); |
| 4031 | try { |
| 4032 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4033 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4034 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4035 | return null; |
| 4036 | } |
| 4037 | Object response = sendRequest( |
| 4038 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4039 | if (response instanceof String[]) { |
| 4040 | return (String[]) response; |
| 4041 | } |
| 4042 | // Response is an Exception of some kind, |
| 4043 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4044 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4045 | } finally { |
| 4046 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4047 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4048 | } |
| 4049 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4050 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4051 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4052 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4053 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4054 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4055 | final long identity = Binder.clearCallingIdentity(); |
| 4056 | try { |
| 4057 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4058 | if (response.payload == null) { |
| 4059 | return ""; |
| 4060 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4061 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4062 | // Append the returned status code to the end of the response payload. |
| 4063 | String s = Integer.toHexString( |
| 4064 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4065 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4066 | return s; |
| 4067 | } finally { |
| 4068 | Binder.restoreCallingIdentity(identity); |
| 4069 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4070 | } |
| 4071 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4072 | /** |
| 4073 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4074 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4075 | * |
| 4076 | * @param itemID the ID of the item to read |
| 4077 | * @return the NV item as a String, or null on error. |
| 4078 | */ |
| 4079 | @Override |
| 4080 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4081 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4082 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4083 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4084 | |
| 4085 | final long identity = Binder.clearCallingIdentity(); |
| 4086 | try { |
| 4087 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4088 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4089 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4090 | return value; |
| 4091 | } finally { |
| 4092 | Binder.restoreCallingIdentity(identity); |
| 4093 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | /** |
| 4097 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4098 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4099 | * |
| 4100 | * @param itemID the ID of the item to read |
| 4101 | * @param itemValue the value to write, as a String |
| 4102 | * @return true on success; false on any failure |
| 4103 | */ |
| 4104 | @Override |
| 4105 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4106 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4107 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4108 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4109 | |
| 4110 | final long identity = Binder.clearCallingIdentity(); |
| 4111 | try { |
| 4112 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4113 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4114 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4115 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4116 | return success; |
| 4117 | } finally { |
| 4118 | Binder.restoreCallingIdentity(identity); |
| 4119 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4120 | } |
| 4121 | |
| 4122 | /** |
| 4123 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4124 | * Used for device configuration by some CDMA operators. |
| 4125 | * |
| 4126 | * @param preferredRoamingList byte array containing the new PRL |
| 4127 | * @return true on success; false on any failure |
| 4128 | */ |
| 4129 | @Override |
| 4130 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4131 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4132 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4133 | |
| 4134 | final long identity = Binder.clearCallingIdentity(); |
| 4135 | try { |
| 4136 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4137 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4138 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4139 | return success; |
| 4140 | } finally { |
| 4141 | Binder.restoreCallingIdentity(identity); |
| 4142 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4143 | } |
| 4144 | |
| 4145 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4146 | * 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] | 4147 | * Used for device configuration by some CDMA operators. |
| 4148 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4149 | * @param slotIndex - device slot. |
| 4150 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4151 | * @return true on success; false on any failure |
| 4152 | */ |
| 4153 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4154 | public boolean resetModemConfig(int slotIndex) { |
| 4155 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4156 | if (phone != null) { |
| 4157 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4158 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4159 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4160 | final long identity = Binder.clearCallingIdentity(); |
| 4161 | try { |
| 4162 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4163 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4164 | return success; |
| 4165 | } finally { |
| 4166 | Binder.restoreCallingIdentity(identity); |
| 4167 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4168 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4169 | return false; |
| 4170 | } |
| 4171 | |
| 4172 | /** |
| 4173 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4174 | * |
| 4175 | * @param slotIndex - device slot. |
| 4176 | * |
| 4177 | * @return true on success; false on any failure |
| 4178 | */ |
| 4179 | @Override |
| 4180 | public boolean rebootModem(int slotIndex) { |
| 4181 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4182 | if (phone != null) { |
| 4183 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4184 | mApp, phone.getSubId(), "rebootModem"); |
| 4185 | |
| 4186 | final long identity = Binder.clearCallingIdentity(); |
| 4187 | try { |
| 4188 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4189 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4190 | return success; |
| 4191 | } finally { |
| 4192 | Binder.restoreCallingIdentity(identity); |
| 4193 | } |
| 4194 | } |
| 4195 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4196 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4197 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4198 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4199 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4200 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4201 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4202 | return new String[0]; |
| 4203 | } |
| 4204 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4205 | final long identity = Binder.clearCallingIdentity(); |
| 4206 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4207 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4208 | } finally { |
| 4209 | Binder.restoreCallingIdentity(identity); |
| 4210 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4211 | } |
| 4212 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4213 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4214 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4215 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4216 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4217 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4218 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4219 | |
| 4220 | final long identity = Binder.clearCallingIdentity(); |
| 4221 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4222 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4223 | if (resolver == null) { |
| 4224 | // may happen if the device does not support IMS. |
| 4225 | return; |
| 4226 | } |
| 4227 | resolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4228 | } finally { |
| 4229 | Binder.restoreCallingIdentity(identity); |
| 4230 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4231 | } |
| 4232 | |
| 4233 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4234 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4235 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4236 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4237 | public void disableIms(int slotId) { |
| 4238 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4239 | |
| 4240 | final long identity = Binder.clearCallingIdentity(); |
| 4241 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4242 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4243 | if (resolver == null) { |
| 4244 | // may happen if the device does not support IMS. |
| 4245 | return; |
| 4246 | } |
| 4247 | resolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4248 | } finally { |
| 4249 | Binder.restoreCallingIdentity(identity); |
| 4250 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4251 | } |
| 4252 | |
| 4253 | /** |
| 4254 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4255 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4256 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4257 | */ |
| 4258 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4259 | IImsServiceFeatureCallback callback) { |
| 4260 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4261 | |
| 4262 | final long identity = Binder.clearCallingIdentity(); |
| 4263 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4264 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4265 | if (resolver == null) { |
| 4266 | // may happen if the device does not support IMS. |
| 4267 | return null; |
| 4268 | } |
| 4269 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4270 | } finally { |
| 4271 | Binder.restoreCallingIdentity(identity); |
| 4272 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4273 | } |
| 4274 | |
| 4275 | /** |
| 4276 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4277 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4278 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4279 | * listener for feature updates. |
| 4280 | */ |
| 4281 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4282 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4283 | |
| 4284 | final long identity = Binder.clearCallingIdentity(); |
| 4285 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4286 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4287 | if (resolver == null) { |
| 4288 | // may happen if the device does not support IMS. |
| 4289 | return null; |
| 4290 | } |
| 4291 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4292 | } finally { |
| 4293 | Binder.restoreCallingIdentity(identity); |
| 4294 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4295 | } |
| 4296 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4297 | /** |
| 4298 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4299 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4300 | */ |
| 4301 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4302 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4303 | |
| 4304 | final long identity = Binder.clearCallingIdentity(); |
| 4305 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4306 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4307 | if (resolver == null) { |
| 4308 | // may happen if the device does not support IMS. |
| 4309 | return null; |
| 4310 | } |
| 4311 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4312 | } finally { |
| 4313 | Binder.restoreCallingIdentity(identity); |
| 4314 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4315 | } |
| 4316 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4317 | /** |
| 4318 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4319 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4320 | */ |
| 4321 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4322 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4323 | |
| 4324 | final long identity = Binder.clearCallingIdentity(); |
| 4325 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4326 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4327 | if (resolver == null) { |
| 4328 | // may happen if the device does not support IMS. |
| 4329 | return null; |
| 4330 | } |
| 4331 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4332 | } finally { |
| 4333 | Binder.restoreCallingIdentity(identity); |
| 4334 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4335 | } |
| 4336 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4337 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4338 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4339 | * |
| 4340 | * @param slotId the slot ID that the ImsService should bind for. |
| 4341 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4342 | * ImsService is the device default ImsService. |
| 4343 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4344 | * to. |
| 4345 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4346 | * @hide |
| 4347 | */ |
| 4348 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4349 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4350 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4351 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4352 | "setImsService"); |
| 4353 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4354 | final long identity = Binder.clearCallingIdentity(); |
| 4355 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4356 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4357 | if (resolver == null) { |
| 4358 | // may happen if the device does not support IMS. |
| 4359 | return false; |
| 4360 | } |
| 4361 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4362 | packageName); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4363 | } finally { |
| 4364 | Binder.restoreCallingIdentity(identity); |
| 4365 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | /** |
| 4369 | * Return the ImsService configuration. |
| 4370 | * |
| 4371 | * @param slotId The slot that the ImsService is associated with. |
| 4372 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4373 | * the device default. |
| 4374 | * @return the package name of the ImsService configuration. |
| 4375 | */ |
| 4376 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4377 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4378 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4379 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4380 | "getImsService"); |
| 4381 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4382 | final long identity = Binder.clearCallingIdentity(); |
| 4383 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4384 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4385 | if (resolver == null) { |
| 4386 | // may happen if the device does not support IMS. |
| 4387 | return ""; |
| 4388 | } |
| 4389 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4390 | } finally { |
| 4391 | Binder.restoreCallingIdentity(identity); |
| 4392 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4393 | } |
| 4394 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4395 | public void setImsRegistrationState(boolean registered) { |
| 4396 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4397 | |
| 4398 | final long identity = Binder.clearCallingIdentity(); |
| 4399 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4400 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4401 | } finally { |
| 4402 | Binder.restoreCallingIdentity(identity); |
| 4403 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4404 | } |
| 4405 | |
| 4406 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4407 | * Set the network selection mode to automatic. |
| 4408 | * |
| 4409 | */ |
| 4410 | @Override |
| 4411 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4412 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4413 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4414 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4415 | if (!isActiveSubscription(subId)) { |
| 4416 | return; |
| 4417 | } |
| 4418 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4419 | final long identity = Binder.clearCallingIdentity(); |
| 4420 | try { |
| 4421 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4422 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4423 | } finally { |
| 4424 | Binder.restoreCallingIdentity(identity); |
| 4425 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4426 | } |
| 4427 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4428 | /** |
| 4429 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4430 | * |
| 4431 | * @param subId the id of the subscription. |
| 4432 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4433 | * the operator to attach to. |
| 4434 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4435 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4436 | * normal network selection next time. |
| 4437 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4438 | */ |
| 4439 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4440 | public boolean setNetworkSelectionModeManual( |
| 4441 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4442 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4443 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4444 | |
| 4445 | if (!isActiveSubscription(subId)) { |
| 4446 | return false; |
| 4447 | } |
| 4448 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4449 | final long identity = Binder.clearCallingIdentity(); |
| 4450 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4451 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4452 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4453 | if (DBG) { |
| 4454 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4455 | + " operator: " + operatorInfo); |
| 4456 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4457 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4458 | } finally { |
| 4459 | Binder.restoreCallingIdentity(identity); |
| 4460 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | /** |
| 4464 | * Scans for available networks. |
| 4465 | */ |
| 4466 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4467 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4468 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4469 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4470 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4471 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4472 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4473 | .setCallingPackage(callingPackage) |
| 4474 | .setCallingPid(Binder.getCallingPid()) |
| 4475 | .setCallingUid(Binder.getCallingUid()) |
| 4476 | .setMethod("getCellNetworkScanResults") |
| 4477 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4478 | .build()); |
| 4479 | switch (locationResult) { |
| 4480 | case DENIED_HARD: |
| 4481 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4482 | case DENIED_SOFT: |
| 4483 | return null; |
| 4484 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4485 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4486 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4487 | try { |
| 4488 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4489 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4490 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4491 | } finally { |
| 4492 | Binder.restoreCallingIdentity(identity); |
| 4493 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4494 | } |
| 4495 | |
| 4496 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4497 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4498 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4499 | * @param subId id of the subscription |
| 4500 | * @param request contains the radio access networks with bands/channels to scan |
| 4501 | * @param messenger callback messenger for scan results or errors |
| 4502 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4503 | * @return the id of the requested scan which can be used to stop the scan. |
| 4504 | */ |
| 4505 | @Override |
| 4506 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4507 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4508 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4509 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4510 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4511 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4512 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4513 | .setCallingPackage(callingPackage) |
| 4514 | .setCallingPid(Binder.getCallingPid()) |
| 4515 | .setCallingUid(Binder.getCallingUid()) |
| 4516 | .setMethod("requestNetworkScan") |
| 4517 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4518 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4519 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4520 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4521 | if (e != null) { |
| 4522 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4523 | throw e; |
| 4524 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4525 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4526 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4527 | } |
| 4528 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4529 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4530 | int callingUid = Binder.getCallingUid(); |
| 4531 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4532 | final long identity = Binder.clearCallingIdentity(); |
| 4533 | try { |
| 4534 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4535 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4536 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4537 | } finally { |
| 4538 | Binder.restoreCallingIdentity(identity); |
| 4539 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4540 | } |
| 4541 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4542 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4543 | NetworkScanRequest request, int subId) { |
| 4544 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4545 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4546 | boolean hasNetworkScanPermission = |
| 4547 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4548 | == PERMISSION_GRANTED; |
| 4549 | |
| 4550 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4551 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4552 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4553 | } |
| 4554 | |
| 4555 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4556 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4557 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4558 | return new SecurityException("Specific channels must not be" |
| 4559 | + " scanned without location access."); |
| 4560 | } |
| 4561 | } |
| 4562 | } |
| 4563 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4564 | return null; |
| 4565 | } |
| 4566 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4567 | /** |
| 4568 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4569 | * |
| 4570 | * @param subId id of the subscription |
| 4571 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4572 | */ |
| 4573 | @Override |
| 4574 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4575 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4576 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4577 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4578 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4579 | final long identity = Binder.clearCallingIdentity(); |
| 4580 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4581 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4582 | } finally { |
| 4583 | Binder.restoreCallingIdentity(identity); |
| 4584 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4588 | * Get the calculated preferred network type. |
| 4589 | * Used for debugging incorrect network type. |
| 4590 | * |
| 4591 | * @return the preferred network type, defined in RILConstants.java. |
| 4592 | */ |
| 4593 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4594 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4595 | final Phone defaultPhone = getDefaultPhone(); |
| 4596 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4597 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4598 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4599 | } |
| 4600 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4601 | final long identity = Binder.clearCallingIdentity(); |
| 4602 | try { |
| 4603 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4604 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4605 | } finally { |
| 4606 | Binder.restoreCallingIdentity(identity); |
| 4607 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4611 | * Get the preferred network type. |
| 4612 | * Used for device configuration by some CDMA operators. |
| 4613 | * |
| 4614 | * @return the preferred network type, defined in RILConstants.java. |
| 4615 | */ |
| 4616 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4617 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4618 | TelephonyPermissions |
| 4619 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4620 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4621 | |
| 4622 | final long identity = Binder.clearCallingIdentity(); |
| 4623 | try { |
| 4624 | if (DBG) log("getPreferredNetworkType"); |
| 4625 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4626 | int networkType = (result != null ? result[0] : -1); |
| 4627 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4628 | return networkType; |
| 4629 | } finally { |
| 4630 | Binder.restoreCallingIdentity(identity); |
| 4631 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | /** |
| 4635 | * Set the preferred network type. |
| 4636 | * Used for device configuration by some CDMA operators. |
| 4637 | * |
| 4638 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4639 | * @return true on success; false on any failure. |
| 4640 | */ |
| 4641 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4642 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4643 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4644 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4645 | |
| 4646 | final long identity = Binder.clearCallingIdentity(); |
| 4647 | try { |
| 4648 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4649 | Boolean success = (Boolean) sendRequest( |
| 4650 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4651 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4652 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4653 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4654 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4655 | } |
| 4656 | return success; |
| 4657 | } finally { |
| 4658 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4659 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4660 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4661 | |
| 4662 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4663 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4664 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4665 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4666 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4667 | * @hide |
| 4668 | */ |
| 4669 | @Override |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4670 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4671 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4672 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4673 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4674 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4675 | if (phone != null) { |
| 4676 | return phone.hasMatchedTetherApnSetting(); |
| 4677 | } else { |
| 4678 | return false; |
| 4679 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4680 | } finally { |
| 4681 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4682 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4683 | } |
| 4684 | |
| 4685 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4686 | * Set mobile data enabled |
| 4687 | * Used by the user through settings etc to turn on/off mobile data |
| 4688 | * |
| 4689 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4690 | */ |
| 4691 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4692 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4693 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4694 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4695 | |
| 4696 | final long identity = Binder.clearCallingIdentity(); |
| 4697 | try { |
| 4698 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4699 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4700 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4701 | if (phone != null) { |
| 4702 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4703 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4704 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4705 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4706 | } |
| 4707 | } finally { |
| 4708 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4709 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4713 | * Get the user enabled state of Mobile Data. |
| 4714 | * |
| 4715 | * TODO: remove and use isUserDataEnabled. |
| 4716 | * This can't be removed now because some vendor codes |
| 4717 | * calls through ITelephony directly while they should |
| 4718 | * use TelephonyManager. |
| 4719 | * |
| 4720 | * @return true on enabled |
| 4721 | */ |
| 4722 | @Override |
| 4723 | public boolean getDataEnabled(int subId) { |
| 4724 | return isUserDataEnabled(subId); |
| 4725 | } |
| 4726 | |
| 4727 | /** |
| 4728 | * Get whether mobile data is enabled per user setting. |
| 4729 | * |
| 4730 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4731 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4732 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4733 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4734 | * |
| 4735 | * @return {@code true} if data is enabled else {@code false} |
| 4736 | */ |
| 4737 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4738 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4739 | try { |
| 4740 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4741 | null); |
| 4742 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4743 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4744 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4745 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4746 | |
| 4747 | final long identity = Binder.clearCallingIdentity(); |
| 4748 | try { |
| 4749 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4750 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4751 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4752 | if (phone != null) { |
| 4753 | boolean retVal = phone.isUserDataEnabled(); |
| 4754 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4755 | return retVal; |
| 4756 | } else { |
| 4757 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4758 | return false; |
| 4759 | } |
| 4760 | } finally { |
| 4761 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4762 | } |
| 4763 | } |
| 4764 | |
| 4765 | /** |
| 4766 | * Get whether mobile data is enabled. |
| 4767 | * |
| 4768 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4769 | * whether mobile data is actually enabled. |
| 4770 | * |
| 4771 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4772 | * |
| 4773 | * @return {@code true} if data is enabled else {@code false} |
| 4774 | */ |
| 4775 | @Override |
| 4776 | public boolean isDataEnabled(int subId) { |
| 4777 | try { |
| 4778 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4779 | null); |
| 4780 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4781 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4782 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4783 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4784 | |
| 4785 | final long identity = Binder.clearCallingIdentity(); |
| 4786 | try { |
| 4787 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4788 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4789 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4790 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4791 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4792 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4793 | return retVal; |
| 4794 | } else { |
| 4795 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4796 | return false; |
| 4797 | } |
| 4798 | } finally { |
| 4799 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4800 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4801 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4802 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4803 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 4804 | Phone phone) { |
| 4805 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 4806 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 4807 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 4808 | || subController == null) return privilegeFromSim; |
| 4809 | |
| 4810 | int uid = Binder.getCallingUid(); |
| 4811 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 4812 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 4813 | |
| 4814 | final long identity = Binder.clearCallingIdentity(); |
| 4815 | try { |
| 4816 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 4817 | SubscriptionManager subManager = (SubscriptionManager) |
| 4818 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 4819 | for (String pkg : packages) { |
| 4820 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 4821 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4822 | } |
| 4823 | } |
| 4824 | return privilegeFromSim; |
| 4825 | } finally { |
| 4826 | Binder.restoreCallingIdentity(identity); |
| 4827 | } |
| 4828 | } |
| 4829 | |
| 4830 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 4831 | String pkgName) { |
| 4832 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 4833 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 4834 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 4835 | || subController == null) return privilegeFromSim; |
| 4836 | |
| 4837 | final long identity = Binder.clearCallingIdentity(); |
| 4838 | try { |
| 4839 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 4840 | SubscriptionManager subManager = (SubscriptionManager) |
| 4841 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 4842 | return subManager.canManageSubscription(subInfo, pkgName) |
| 4843 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 4844 | } finally { |
| 4845 | Binder.restoreCallingIdentity(identity); |
| 4846 | } |
| 4847 | } |
| 4848 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4849 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4850 | public int getCarrierPrivilegeStatus(int subId) { |
| 4851 | final Phone phone = getPhone(subId); |
| 4852 | if (phone == null) { |
| 4853 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4854 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4855 | } |
| 4856 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4857 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4858 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4859 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4860 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4861 | |
| 4862 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4863 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 4864 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4865 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4866 | |
| 4867 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4868 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4869 | final Phone phone = getPhone(subId); |
| 4870 | if (phone == null) { |
| 4871 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4872 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4873 | } |
| 4874 | UiccProfile profile = |
| 4875 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4876 | if (profile == null) { |
| 4877 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4878 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4879 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4880 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4881 | profile.getCarrierPrivilegeStatusForUid( |
| 4882 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4883 | } |
| 4884 | |
| 4885 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4886 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 4887 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4888 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4889 | } |
| 4890 | |
| 4891 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 4892 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4893 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4894 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4895 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4896 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4897 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4898 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 4899 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4900 | } |
| 4901 | |
| 4902 | @Override |
| 4903 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4904 | if (TextUtils.isEmpty(pkgName)) |
| 4905 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4906 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4907 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4908 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4909 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4910 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4911 | continue; |
| 4912 | } |
| 4913 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4914 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4915 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 4916 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4917 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4918 | break; |
| 4919 | } |
| 4920 | } |
| 4921 | |
| 4922 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4923 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4924 | |
| 4925 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4926 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4927 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4928 | loge("phoneId " + phoneId + " is not valid."); |
| 4929 | return null; |
| 4930 | } |
| 4931 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4932 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4933 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4934 | return null ; |
| 4935 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4936 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4937 | } |
| 4938 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4939 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4940 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4941 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4942 | List<String> privilegedPackages = new ArrayList<>(); |
| 4943 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4944 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 4945 | // has UICC in that slot. |
| 4946 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4947 | if (card.hasCarrierPrivilegeRules()) { |
| 4948 | if (packages == null) { |
| 4949 | // Only check packages in user 0 for now |
| 4950 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4951 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4952 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 4953 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 4954 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4955 | } |
| 4956 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4957 | PackageInfo pkgInfo = packages.get(p); |
| 4958 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4959 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4960 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4961 | privilegedPackages.add(pkgInfo.packageName); |
| 4962 | } |
| 4963 | } |
| 4964 | } |
| 4965 | } |
| 4966 | return privilegedPackages; |
| 4967 | } |
| 4968 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4969 | @Override |
| 4970 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
| 4971 | List<String> privilegedPackages = new ArrayList<>(); |
| 4972 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4973 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 4974 | } |
| 4975 | return privilegedPackages; |
| 4976 | } |
| 4977 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4978 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4979 | final Phone phone = getPhone(subId); |
| 4980 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4981 | if (card == null) { |
| 4982 | loge("getIccId: No UICC"); |
| 4983 | return null; |
| 4984 | } |
| 4985 | String iccId = card.getIccId(); |
| 4986 | if (TextUtils.isEmpty(iccId)) { |
| 4987 | loge("getIccId: ICC ID is null or empty."); |
| 4988 | return null; |
| 4989 | } |
| 4990 | return iccId; |
| 4991 | } |
| 4992 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4993 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4994 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4995 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4996 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4997 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4998 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4999 | final long identity = Binder.clearCallingIdentity(); |
| 5000 | try { |
| 5001 | final String iccId = getIccId(subId); |
| 5002 | final Phone phone = getPhone(subId); |
| 5003 | if (phone == null) { |
| 5004 | return false; |
| 5005 | } |
| 5006 | final String subscriberId = phone.getSubscriberId(); |
| 5007 | |
| 5008 | if (DBG_MERGE) { |
| 5009 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5010 | + subscriberId + " to " + number); |
| 5011 | } |
| 5012 | |
| 5013 | if (TextUtils.isEmpty(iccId)) { |
| 5014 | return false; |
| 5015 | } |
| 5016 | |
| 5017 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5018 | |
| 5019 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5020 | if (alphaTag == null) { |
| 5021 | editor.remove(alphaTagPrefKey); |
| 5022 | } else { |
| 5023 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5024 | } |
| 5025 | |
| 5026 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5027 | // track all merged IMSIs based on line number |
| 5028 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5029 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5030 | if (number == null) { |
| 5031 | editor.remove(numberPrefKey); |
| 5032 | editor.remove(subscriberPrefKey); |
| 5033 | } else { |
| 5034 | editor.putString(numberPrefKey, number); |
| 5035 | editor.putString(subscriberPrefKey, subscriberId); |
| 5036 | } |
| 5037 | |
| 5038 | editor.commit(); |
| 5039 | return true; |
| 5040 | } finally { |
| 5041 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5042 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5043 | } |
| 5044 | |
| 5045 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5046 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5047 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5048 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5049 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5050 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5051 | return null; |
| 5052 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5053 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5054 | final long identity = Binder.clearCallingIdentity(); |
| 5055 | try { |
| 5056 | String iccId = getIccId(subId); |
| 5057 | if (iccId != null) { |
| 5058 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5059 | if (DBG_MERGE) { |
| 5060 | log("getLine1NumberForDisplay returning " |
| 5061 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5062 | } |
| 5063 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5064 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5065 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5066 | return null; |
| 5067 | } finally { |
| 5068 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5069 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5073 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5074 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5075 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5076 | return null; |
| 5077 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5078 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5079 | final long identity = Binder.clearCallingIdentity(); |
| 5080 | try { |
| 5081 | String iccId = getIccId(subId); |
| 5082 | if (iccId != null) { |
| 5083 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5084 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5085 | } |
| 5086 | return null; |
| 5087 | } finally { |
| 5088 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5089 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5090 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5091 | |
| 5092 | @Override |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5093 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5094 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5095 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5096 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5097 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 5098 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5099 | return null; |
| 5100 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5101 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5102 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5103 | // the process, where TelephonyManager was instantiated. |
| 5104 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5105 | final long identity = Binder.clearCallingIdentity(); |
| 5106 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5107 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5108 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5109 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5110 | |
| 5111 | // Figure out what subscribers are currently active |
| 5112 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5113 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5114 | // Only consider subs which match the current subId |
| 5115 | // This logic can be simplified. See b/131189269 for progress. |
| 5116 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5117 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5118 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5119 | |
| 5120 | // First pass, find a number override for an active subscriber |
| 5121 | String mergeNumber = null; |
| 5122 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5123 | for (String key : prefs.keySet()) { |
| 5124 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5125 | final String subscriberId = (String) prefs.get(key); |
| 5126 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5127 | final String iccId = key.substring( |
| 5128 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5129 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5130 | mergeNumber = (String) prefs.get(numberKey); |
| 5131 | if (DBG_MERGE) { |
| 5132 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5133 | + " for active subscriber " + subscriberId); |
| 5134 | } |
| 5135 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5136 | break; |
| 5137 | } |
| 5138 | } |
| 5139 | } |
| 5140 | } |
| 5141 | |
| 5142 | // Shortcut when no active merged subscribers |
| 5143 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5144 | return null; |
| 5145 | } |
| 5146 | |
| 5147 | // Second pass, find all subscribers under that line override |
| 5148 | final ArraySet<String> result = new ArraySet<>(); |
| 5149 | for (String key : prefs.keySet()) { |
| 5150 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5151 | final String number = (String) prefs.get(key); |
| 5152 | if (mergeNumber.equals(number)) { |
| 5153 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5154 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5155 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5156 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5157 | result.add(subscriberId); |
| 5158 | } |
| 5159 | } |
| 5160 | } |
| 5161 | } |
| 5162 | |
| 5163 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5164 | Arrays.sort(resultArray); |
| 5165 | if (DBG_MERGE) { |
| 5166 | Slog.d(LOG_TAG, |
| 5167 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5168 | } |
| 5169 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5170 | } finally { |
| 5171 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5172 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5173 | } |
| 5174 | |
| 5175 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5176 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 5177 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 5178 | |
| 5179 | final long identity = Binder.clearCallingIdentity(); |
| 5180 | try { |
| 5181 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5182 | TelephonyManager.class); |
| 5183 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5184 | if (subscriberId == null) { |
| 5185 | if (DBG) { |
| 5186 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 5187 | + subId); |
| 5188 | } |
| 5189 | return null; |
| 5190 | } |
| 5191 | |
| 5192 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5193 | .getSubscriptionInfo(subId); |
| 5194 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5195 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5196 | if (groupUuid == null) { |
| 5197 | return new String[]{subscriberId}; |
| 5198 | } |
| 5199 | |
| 5200 | // Get all subscriberIds from the group. |
| 5201 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5202 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
| 5203 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName()); |
| 5204 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5205 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5206 | if (subscriberId != null) { |
| 5207 | mergedSubscriberIds.add(subscriberId); |
| 5208 | } |
| 5209 | } |
| 5210 | |
| 5211 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5212 | } finally { |
| 5213 | Binder.restoreCallingIdentity(identity); |
| 5214 | |
| 5215 | } |
| 5216 | } |
| 5217 | |
| 5218 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5219 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5220 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5221 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5222 | |
| 5223 | final long identity = Binder.clearCallingIdentity(); |
| 5224 | try { |
| 5225 | final Phone phone = getPhone(subId); |
| 5226 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5227 | } finally { |
| 5228 | Binder.restoreCallingIdentity(identity); |
| 5229 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5230 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5231 | |
| 5232 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5233 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5234 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5235 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5236 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5237 | |
| 5238 | final long identity = Binder.clearCallingIdentity(); |
| 5239 | try { |
| 5240 | final Phone phone = getPhone(subId); |
| 5241 | if (phone == null) { |
| 5242 | return false; |
| 5243 | } |
| 5244 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5245 | cdmaNonRoamingList); |
| 5246 | } finally { |
| 5247 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5248 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5249 | } |
| 5250 | |
| 5251 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5252 | @Deprecated |
| 5253 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5254 | enforceModifyPermission(); |
| 5255 | |
| 5256 | int returnValue = 0; |
| 5257 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5258 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5259 | if(result.exception == null) { |
| 5260 | if (result.result != null) { |
| 5261 | byte[] responseData = (byte[])(result.result); |
| 5262 | if(responseData.length > oemResp.length) { |
| 5263 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5264 | responseData.length + "bytes. Buffer Size is " + |
| 5265 | oemResp.length + "bytes."); |
| 5266 | } |
| 5267 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5268 | returnValue = responseData.length; |
| 5269 | } |
| 5270 | } else { |
| 5271 | CommandException ex = (CommandException) result.exception; |
| 5272 | returnValue = ex.getCommandError().ordinal(); |
| 5273 | if(returnValue > 0) returnValue *= -1; |
| 5274 | } |
| 5275 | } catch (RuntimeException e) { |
| 5276 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5277 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5278 | if(returnValue > 0) returnValue *= -1; |
| 5279 | } |
| 5280 | |
| 5281 | return returnValue; |
| 5282 | } |
| 5283 | |
| 5284 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5285 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5286 | try { |
| 5287 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5288 | } catch (RuntimeException e) { |
| 5289 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5290 | } |
| 5291 | } |
| 5292 | |
| 5293 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5294 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5295 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5296 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5297 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5298 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5299 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5300 | final long identity = Binder.clearCallingIdentity(); |
| 5301 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5302 | TelephonyPermissions |
| 5303 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5304 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5305 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5306 | } finally { |
| 5307 | Binder.restoreCallingIdentity(identity); |
| 5308 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5309 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5310 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5311 | |
| 5312 | @Override |
| 5313 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5314 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5315 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5316 | |
| 5317 | final long identity = Binder.clearCallingIdentity(); |
| 5318 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5319 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5320 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5321 | } finally { |
| 5322 | Binder.restoreCallingIdentity(identity); |
| 5323 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5324 | } |
| 5325 | |
| 5326 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5327 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5328 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5329 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5330 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5331 | return false; |
| 5332 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5333 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5334 | final long identity = Binder.clearCallingIdentity(); |
| 5335 | try { |
| 5336 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5337 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5338 | // In the long run, we may instead need to check if there exists a connection service |
| 5339 | // which can support video calling. |
| 5340 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5341 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5342 | return imsManager.isVtEnabledByPlatform() |
| 5343 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5344 | && imsManager.isVtEnabledByUser(); |
| 5345 | } finally { |
| 5346 | Binder.restoreCallingIdentity(identity); |
| 5347 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5348 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5349 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5350 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5351 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5352 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5353 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5354 | return false; |
| 5355 | } |
| 5356 | |
| 5357 | final long identity = Binder.clearCallingIdentity(); |
| 5358 | try { |
| 5359 | CarrierConfigManager configManager = |
| 5360 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5361 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5362 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5363 | } finally { |
| 5364 | Binder.restoreCallingIdentity(identity); |
| 5365 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5369 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5370 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5371 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5372 | return false; |
| 5373 | } |
| 5374 | |
| 5375 | final long identity = Binder.clearCallingIdentity(); |
| 5376 | try { |
| 5377 | CarrierConfigManager configManager = |
| 5378 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5379 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5380 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5381 | } finally { |
| 5382 | Binder.restoreCallingIdentity(identity); |
| 5383 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5384 | } |
| 5385 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5386 | @Override |
| 5387 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5388 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5389 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | @Override |
| 5393 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5394 | final long identity = Binder.clearCallingIdentity(); |
| 5395 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5396 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5397 | } finally { |
| 5398 | Binder.restoreCallingIdentity(identity); |
| 5399 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5400 | } |
| 5401 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5402 | /** |
| 5403 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5404 | * support for the feature and device firmware support. |
| 5405 | * |
| 5406 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5407 | */ |
| 5408 | @Override |
| 5409 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5410 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5411 | final Phone phone = getPhone(subscriptionId); |
| 5412 | if (phone == null) { |
| 5413 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5414 | return false; |
| 5415 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5416 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5417 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5418 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5419 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5420 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5421 | return isCarrierSupported && isDeviceSupported; |
| 5422 | } finally { |
| 5423 | Binder.restoreCallingIdentity(identity); |
| 5424 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5425 | } |
| 5426 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5427 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5428 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 5429 | * RTT setting, will return true if the device and carrier both support RTT. |
| 5430 | * 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] | 5431 | */ |
| 5432 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5433 | final long identity = Binder.clearCallingIdentity(); |
| 5434 | try { |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5435 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 5436 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5437 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5438 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 5439 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 5440 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5441 | } finally { |
| 5442 | Binder.restoreCallingIdentity(identity); |
| 5443 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5444 | } |
| 5445 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5446 | /** |
| 5447 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5448 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5449 | * |
| 5450 | * <p>Requires Permission: |
| 5451 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5452 | */ |
| 5453 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5454 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5455 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5456 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5457 | return null; |
| 5458 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5459 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5460 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5461 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5462 | return null; |
| 5463 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5464 | |
| 5465 | final long identity = Binder.clearCallingIdentity(); |
| 5466 | try { |
| 5467 | return phone.getDeviceId(); |
| 5468 | } finally { |
| 5469 | Binder.restoreCallingIdentity(identity); |
| 5470 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5471 | } |
| 5472 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5473 | /** |
| 5474 | * {@hide} |
| 5475 | * Returns the IMS Registration Status on a particular subid |
| 5476 | * |
| 5477 | * @param subId |
| 5478 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5479 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5480 | Phone phone = getPhone(subId); |
| 5481 | if (phone != null) { |
| 5482 | return phone.isImsRegistered(); |
| 5483 | } else { |
| 5484 | return false; |
| 5485 | } |
| 5486 | } |
| 5487 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5488 | @Override |
| 5489 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5490 | final long identity = Binder.clearCallingIdentity(); |
| 5491 | try { |
| 5492 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5493 | } finally { |
| 5494 | Binder.restoreCallingIdentity(identity); |
| 5495 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5496 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5497 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5498 | @Override |
| 5499 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5500 | final long identity = Binder.clearCallingIdentity(); |
| 5501 | try { |
| 5502 | Phone phone = getPhone(subscriptionId); |
| 5503 | if (phone == null) { |
| 5504 | return null; |
| 5505 | } |
| 5506 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5507 | } finally { |
| 5508 | Binder.restoreCallingIdentity(identity); |
| 5509 | } |
| 5510 | } |
| 5511 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5512 | /** |
| 5513 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5514 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5515 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5516 | final long identity = Binder.clearCallingIdentity(); |
| 5517 | try { |
| 5518 | Phone phone = getPhone(subId); |
| 5519 | if (phone != null) { |
| 5520 | return phone.isWifiCallingEnabled(); |
| 5521 | } else { |
| 5522 | return false; |
| 5523 | } |
| 5524 | } finally { |
| 5525 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5526 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5527 | } |
| 5528 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5529 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5530 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5531 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5532 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5533 | final long identity = Binder.clearCallingIdentity(); |
| 5534 | try { |
| 5535 | Phone phone = getPhone(subId); |
| 5536 | if (phone != null) { |
| 5537 | return phone.isVideoEnabled(); |
| 5538 | } else { |
| 5539 | return false; |
| 5540 | } |
| 5541 | } finally { |
| 5542 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5543 | } |
| 5544 | } |
| 5545 | |
| 5546 | /** |
| 5547 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5548 | * defined in {@link ImsRegistrationImplBase}. |
| 5549 | */ |
| 5550 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5551 | final long identity = Binder.clearCallingIdentity(); |
| 5552 | try { |
| 5553 | Phone phone = getPhone(subId); |
| 5554 | if (phone != null) { |
| 5555 | return phone.getImsRegistrationTech(); |
| 5556 | } else { |
| 5557 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5558 | } |
| 5559 | } finally { |
| 5560 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5561 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5562 | } |
| 5563 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5564 | @Override |
| 5565 | public void factoryReset(int subId) { |
| 5566 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5567 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5568 | return; |
| 5569 | } |
| 5570 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5571 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5572 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5573 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5574 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5575 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5576 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5577 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5578 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5579 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5580 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5581 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5582 | // There has been issues when Sms raw table somehow stores orphan |
| 5583 | // fragments. They lead to garbled message when new fragments come |
| 5584 | // in and combined with those stale ones. In case this happens again, |
| 5585 | // user can reset all network settings which will clean up this table. |
| 5586 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5587 | } finally { |
| 5588 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5589 | } |
| 5590 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5591 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5592 | private void cleanUpSmsRawTable(Context context) { |
| 5593 | ContentResolver resolver = context.getContentResolver(); |
| 5594 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5595 | resolver.delete(uri, null, null); |
| 5596 | } |
| 5597 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5598 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5599 | public String getSimLocaleForSubscriber(int subId) { |
| 5600 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5601 | final Phone phone = getPhone(subId); |
| 5602 | if (phone == null) { |
| 5603 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5604 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5605 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5606 | final long identity = Binder.clearCallingIdentity(); |
| 5607 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5608 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5609 | phone.getContext().getOpPackageName()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5610 | if (info == null) { |
| 5611 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5612 | return null; |
| 5613 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5614 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5615 | // preferences (EF-PL and EF-LI)... |
| 5616 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5617 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5618 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5619 | if (localeFromDefaultSim != null) { |
| 5620 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5621 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5622 | + localeFromDefaultSim); |
| 5623 | return localeFromDefaultSim.toLanguageTag(); |
| 5624 | } else { |
| 5625 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5626 | } |
| 5627 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5628 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5629 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5630 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5631 | // the SIM and carrier preferences does not include a country we add the country |
| 5632 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5633 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5634 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5635 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5636 | return mccLocale.toLanguageTag(); |
| 5637 | } |
| 5638 | |
| 5639 | if (DBG) log("No locale found - returning null"); |
| 5640 | return null; |
| 5641 | } finally { |
| 5642 | Binder.restoreCallingIdentity(identity); |
| 5643 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5644 | } |
| 5645 | |
| 5646 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5647 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5648 | } |
| 5649 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5650 | /** |
| 5651 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5652 | */ |
| 5653 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5654 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5655 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5656 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5657 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5658 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5659 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5660 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5661 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5662 | * representing the state of the modem. |
| 5663 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5664 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5665 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5666 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5667 | */ |
| 5668 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5669 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5670 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5671 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5672 | |
| 5673 | final long identity = Binder.clearCallingIdentity(); |
| 5674 | try { |
| 5675 | ModemActivityInfo ret = null; |
| 5676 | synchronized (mLastModemActivityInfo) { |
| 5677 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5678 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5679 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5680 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5681 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5682 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 5683 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5684 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5685 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5686 | } |
| 5687 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5688 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 5689 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5690 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5691 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5692 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 5693 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 5694 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 5695 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5696 | } |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5697 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5698 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5699 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5700 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5701 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 5702 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5703 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5704 | Bundle bundle = new Bundle(); |
| 5705 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5706 | result.send(0, bundle); |
| 5707 | } finally { |
| 5708 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5709 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5710 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5711 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5712 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5713 | // less than total activity duration. |
| 5714 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5715 | if (info == null) { |
| 5716 | return false; |
| 5717 | } |
| 5718 | int activityDurationMs = |
| 5719 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5720 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5721 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 5722 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 5723 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5724 | } |
| 5725 | return (info.isValid() |
| 5726 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5727 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5728 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5729 | && (totalTxTimeMs <= activityDurationMs)); |
| 5730 | } |
| 5731 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5732 | /** |
| 5733 | * {@hide} |
| 5734 | * Returns the service state information on specified subscription. |
| 5735 | */ |
| 5736 | @Override |
| 5737 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5738 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5739 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5740 | return null; |
| 5741 | } |
| 5742 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5743 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5744 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5745 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5746 | .setCallingPackage(callingPackage) |
| 5747 | .setCallingPid(Binder.getCallingPid()) |
| 5748 | .setCallingUid(Binder.getCallingUid()) |
| 5749 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5750 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5751 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5752 | .build()); |
| 5753 | |
| 5754 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5755 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5756 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5757 | .setCallingPackage(callingPackage) |
| 5758 | .setCallingPid(Binder.getCallingPid()) |
| 5759 | .setCallingUid(Binder.getCallingUid()) |
| 5760 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5761 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5762 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5763 | .build()); |
| 5764 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5765 | boolean hasFinePermission = |
| 5766 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5767 | boolean hasCoarsePermission = |
| 5768 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5769 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5770 | final long identity = Binder.clearCallingIdentity(); |
| 5771 | try { |
| 5772 | final Phone phone = getPhone(subId); |
| 5773 | if (phone == null) { |
| 5774 | return null; |
| 5775 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5776 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5777 | ServiceState ss = phone.getServiceState(); |
| 5778 | |
| 5779 | // Scrub out the location info in ServiceState depending on what level of access |
| 5780 | // the caller has. |
| 5781 | if (hasFinePermission) return ss; |
| 5782 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5783 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5784 | } finally { |
| 5785 | Binder.restoreCallingIdentity(identity); |
| 5786 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5787 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5788 | |
| 5789 | /** |
| 5790 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5791 | * |
| 5792 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5793 | * voicemail ringtone. |
| 5794 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5795 | * PhoneAccount. |
| 5796 | */ |
| 5797 | @Override |
| 5798 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5799 | final long identity = Binder.clearCallingIdentity(); |
| 5800 | try { |
| 5801 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5802 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5803 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5804 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5805 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5806 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5807 | } finally { |
| 5808 | Binder.restoreCallingIdentity(identity); |
| 5809 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5810 | } |
| 5811 | |
| 5812 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5813 | * Sets the per-account voicemail ringtone. |
| 5814 | * |
| 5815 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5816 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5817 | * |
| 5818 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5819 | * voicemail ringtone. |
| 5820 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5821 | * PhoneAccount. |
| 5822 | */ |
| 5823 | @Override |
| 5824 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5825 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5826 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5827 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5828 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5829 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5830 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5831 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5832 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5833 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5834 | |
| 5835 | final long identity = Binder.clearCallingIdentity(); |
| 5836 | try { |
| 5837 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5838 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5839 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5840 | } |
| 5841 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5842 | } finally { |
| 5843 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5844 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5845 | } |
| 5846 | |
| 5847 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5848 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5849 | * |
| 5850 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5851 | * voicemail vibration setting. |
| 5852 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5853 | */ |
| 5854 | @Override |
| 5855 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5856 | final long identity = Binder.clearCallingIdentity(); |
| 5857 | try { |
| 5858 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5859 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5860 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5861 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5862 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5863 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5864 | } finally { |
| 5865 | Binder.restoreCallingIdentity(identity); |
| 5866 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5867 | } |
| 5868 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5869 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5870 | * Sets the per-account voicemail vibration. |
| 5871 | * |
| 5872 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5873 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5874 | * |
| 5875 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5876 | * voicemail vibration setting. |
| 5877 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5878 | * specific PhoneAccount. |
| 5879 | */ |
| 5880 | @Override |
| 5881 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5882 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5883 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5884 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5885 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5886 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5887 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5888 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5889 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5890 | } |
| 5891 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5892 | final long identity = Binder.clearCallingIdentity(); |
| 5893 | try { |
| 5894 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5895 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5896 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5897 | } |
| 5898 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5899 | } finally { |
| 5900 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5901 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5905 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5906 | * |
| 5907 | * @throws SecurityException if the caller does not have the required permission |
| 5908 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5909 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5910 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5911 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5915 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5916 | * permission. |
| 5917 | * |
| 5918 | * @throws SecurityException if the caller does not have the required permission |
| 5919 | */ |
| 5920 | private void enforceSendSmsPermission() { |
| 5921 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5922 | } |
| 5923 | |
| 5924 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5925 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5926 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5927 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5928 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5929 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5930 | final long identity = Binder.clearCallingIdentity(); |
| 5931 | try { |
| 5932 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5933 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5934 | if (componentName == null) { |
| 5935 | throw new SecurityException( |
| 5936 | "Caller not current active visual voicemail package[null]"); |
| 5937 | } |
| 5938 | String vvmPackage = componentName.getPackageName(); |
| 5939 | if (!callingPackage.equals(vvmPackage)) { |
| 5940 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5941 | + vvmPackage + "]"); |
| 5942 | } |
| 5943 | } finally { |
| 5944 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5945 | } |
| 5946 | } |
| 5947 | |
| 5948 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5949 | * Return the application ID for the app type. |
| 5950 | * |
| 5951 | * @param subId the subscription ID that this request applies to. |
| 5952 | * @param appType the uicc app type. |
| 5953 | * @return Application ID for specificied app type, or null if no uicc. |
| 5954 | */ |
| 5955 | @Override |
| 5956 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5957 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5958 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5959 | |
| 5960 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5961 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5962 | if (phone == null) { |
| 5963 | return null; |
| 5964 | } |
| 5965 | String aid = null; |
| 5966 | try { |
| 5967 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5968 | .getApplicationByType(appType).getAid(); |
| 5969 | } catch (Exception e) { |
| 5970 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5971 | } |
| 5972 | return aid; |
| 5973 | } finally { |
| 5974 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5975 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5976 | } |
| 5977 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5978 | /** |
| 5979 | * Return the Electronic Serial Number. |
| 5980 | * |
| 5981 | * @param subId the subscription ID that this request applies to. |
| 5982 | * @return ESN or null if error. |
| 5983 | */ |
| 5984 | @Override |
| 5985 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5986 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5987 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5988 | |
| 5989 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5990 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5991 | if (phone == null) { |
| 5992 | return null; |
| 5993 | } |
| 5994 | String esn = null; |
| 5995 | try { |
| 5996 | esn = phone.getEsn(); |
| 5997 | } catch (Exception e) { |
| 5998 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5999 | } |
| 6000 | return esn; |
| 6001 | } finally { |
| 6002 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6003 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6004 | } |
| 6005 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6006 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6007 | * Return the Preferred Roaming List Version. |
| 6008 | * |
| 6009 | * @param subId the subscription ID that this request applies to. |
| 6010 | * @return PRLVersion or null if error. |
| 6011 | */ |
| 6012 | @Override |
| 6013 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6014 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6015 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6016 | |
| 6017 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6018 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6019 | if (phone == null) { |
| 6020 | return null; |
| 6021 | } |
| 6022 | String cdmaPrlVersion = null; |
| 6023 | try { |
| 6024 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6025 | } catch (Exception e) { |
| 6026 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6027 | } |
| 6028 | return cdmaPrlVersion; |
| 6029 | } finally { |
| 6030 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6031 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6032 | } |
| 6033 | |
| 6034 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6035 | * Get snapshot of Telephony histograms |
| 6036 | * @return List of Telephony histograms |
| 6037 | * @hide |
| 6038 | */ |
| 6039 | @Override |
| 6040 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6041 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6042 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6043 | |
| 6044 | final long identity = Binder.clearCallingIdentity(); |
| 6045 | try { |
| 6046 | return RIL.getTelephonyRILTimingHistograms(); |
| 6047 | } finally { |
| 6048 | Binder.restoreCallingIdentity(identity); |
| 6049 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6050 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6051 | |
| 6052 | /** |
| 6053 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6054 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6055 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6056 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6057 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6058 | * @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] | 6059 | */ |
| 6060 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6061 | @TelephonyManager.SetCarrierRestrictionResult |
| 6062 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6063 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6064 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6065 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6066 | if (carrierRestrictionRules == null) { |
| 6067 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6068 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6069 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6070 | final long identity = Binder.clearCallingIdentity(); |
| 6071 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6072 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6073 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6074 | } finally { |
| 6075 | Binder.restoreCallingIdentity(identity); |
| 6076 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6077 | } |
| 6078 | |
| 6079 | /** |
| 6080 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6081 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6082 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6083 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6084 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6085 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6086 | */ |
| 6087 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6088 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6089 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6090 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6091 | |
| 6092 | final long identity = Binder.clearCallingIdentity(); |
| 6093 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6094 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6095 | if (response instanceof CarrierRestrictionRules) { |
| 6096 | return (CarrierRestrictionRules) response; |
| 6097 | } |
| 6098 | // Response is an Exception of some kind, |
| 6099 | // which is signalled to the user as a NULL retval |
| 6100 | return null; |
| 6101 | } catch (Exception e) { |
| 6102 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6103 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6104 | } finally { |
| 6105 | Binder.restoreCallingIdentity(identity); |
| 6106 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6107 | } |
| 6108 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6109 | /** |
| 6110 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6111 | * @param subId the subscription ID that this action applies to. |
| 6112 | * @param enabled control enable or disable metered apns. |
| 6113 | * {@hide} |
| 6114 | */ |
| 6115 | @Override |
| 6116 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6117 | enforceModifyPermission(); |
| 6118 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6119 | |
| 6120 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6121 | if (phone == null) { |
| 6122 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6123 | return; |
| 6124 | } |
| 6125 | try { |
| 6126 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6127 | } catch (Exception e) { |
| 6128 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6129 | } finally { |
| 6130 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6131 | } |
| 6132 | } |
| 6133 | |
| 6134 | /** |
| 6135 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6136 | * @param subId the subscription ID that this action applies to. |
| 6137 | * @param enabled control enable or disable radio. |
| 6138 | * {@hide} |
| 6139 | */ |
| 6140 | @Override |
| 6141 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6142 | enforceModifyPermission(); |
| 6143 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6144 | |
| 6145 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6146 | if (phone == null) { |
| 6147 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6148 | return; |
| 6149 | } |
| 6150 | try { |
| 6151 | phone.carrierActionSetRadioEnabled(enabled); |
| 6152 | } catch (Exception e) { |
| 6153 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6154 | } finally { |
| 6155 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6156 | } |
| 6157 | } |
| 6158 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6159 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6160 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6161 | * network status based on which carrier apps could apply actions accordingly, |
| 6162 | * enable/disable default url handler for example. |
| 6163 | * |
| 6164 | * @param subId the subscription ID that this action applies to. |
| 6165 | * @param report control start/stop reporting the default network status. |
| 6166 | * {@hide} |
| 6167 | */ |
| 6168 | @Override |
| 6169 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6170 | enforceModifyPermission(); |
| 6171 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6172 | |
| 6173 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6174 | if (phone == null) { |
| 6175 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6176 | return; |
| 6177 | } |
| 6178 | try { |
| 6179 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6180 | } catch (Exception e) { |
| 6181 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6182 | } finally { |
| 6183 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6184 | } |
| 6185 | } |
| 6186 | |
| 6187 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6188 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6189 | * @param subId the subscription ID that this action applies to. |
| 6190 | * {@hide} |
| 6191 | */ |
| 6192 | @Override |
| 6193 | public void carrierActionResetAll(int subId) { |
| 6194 | enforceModifyPermission(); |
| 6195 | final Phone phone = getPhone(subId); |
| 6196 | if (phone == null) { |
| 6197 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6198 | return; |
| 6199 | } |
| 6200 | try { |
| 6201 | phone.carrierActionResetAll(); |
| 6202 | } catch (Exception e) { |
| 6203 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6204 | } |
| 6205 | } |
| 6206 | |
| 6207 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6208 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6209 | * bug report is being generated. |
| 6210 | */ |
| 6211 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6212 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6213 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6214 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6215 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6216 | + Binder.getCallingPid() |
| 6217 | + ", uid=" + Binder.getCallingUid() |
| 6218 | + "without permission " |
| 6219 | + android.Manifest.permission.DUMP); |
| 6220 | return; |
| 6221 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6222 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6223 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6224 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6225 | @Override |
| 6226 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6227 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6228 | throws RemoteException { |
| 6229 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 6230 | } |
| 6231 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6232 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6233 | * Get aggregated video call data usage since boot. |
| 6234 | * |
| 6235 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6236 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6237 | * {@hide} |
| 6238 | */ |
| 6239 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6240 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6241 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6242 | null); |
| 6243 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6244 | final long identity = Binder.clearCallingIdentity(); |
| 6245 | try { |
| 6246 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6247 | // records the delta with the corresponding network identity. |
| 6248 | // We just return the total video call data usage snapshot since boot. |
| 6249 | Phone phone = getPhone(subId); |
| 6250 | if (phone != null) { |
| 6251 | return phone.getVtDataUsage(perUidStats); |
| 6252 | } |
| 6253 | return null; |
| 6254 | } finally { |
| 6255 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6256 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6257 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6258 | |
| 6259 | /** |
| 6260 | * Policy control of data connection. Usually used when data limit is passed. |
| 6261 | * @param enabled True if enabling the data, otherwise disabling. |
| 6262 | * @param subId Subscription index |
| 6263 | * {@hide} |
| 6264 | */ |
| 6265 | @Override |
| 6266 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6267 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6268 | |
| 6269 | final long identity = Binder.clearCallingIdentity(); |
| 6270 | try { |
| 6271 | Phone phone = getPhone(subId); |
| 6272 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6273 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6274 | } |
| 6275 | } finally { |
| 6276 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6277 | } |
| 6278 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6279 | |
| 6280 | /** |
| 6281 | * Get Client request stats |
| 6282 | * @return List of Client Request Stats |
| 6283 | * @hide |
| 6284 | */ |
| 6285 | @Override |
| 6286 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6287 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6288 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6289 | return null; |
| 6290 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6291 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6293 | final long identity = Binder.clearCallingIdentity(); |
| 6294 | try { |
| 6295 | if (phone != null) { |
| 6296 | return phone.getClientRequestStats(); |
| 6297 | } |
| 6298 | |
| 6299 | return null; |
| 6300 | } finally { |
| 6301 | Binder.restoreCallingIdentity(identity); |
| 6302 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6303 | } |
| 6304 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6305 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6306 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6307 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6308 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6309 | |
| 6310 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6311 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6312 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6313 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6314 | * @param state State of SIM (power down, power up, pass through) |
| 6315 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6316 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6317 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6318 | * |
| 6319 | **/ |
| 6320 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6321 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6322 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6323 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6324 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6325 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6326 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6327 | final long identity = Binder.clearCallingIdentity(); |
| 6328 | try { |
| 6329 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6330 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6331 | } |
| 6332 | } finally { |
| 6333 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6334 | } |
| 6335 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6336 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6337 | private boolean isUssdApiAllowed(int subId) { |
| 6338 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6339 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6340 | if (configManager == null) { |
| 6341 | return false; |
| 6342 | } |
| 6343 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6344 | if (pb == null) { |
| 6345 | return false; |
| 6346 | } |
| 6347 | return pb.getBoolean( |
| 6348 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6349 | } |
| 6350 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6351 | /** |
| 6352 | * Check if phone is in emergency callback mode |
| 6353 | * @return true if phone is in emergency callback mode |
| 6354 | * @param subId sub id |
| 6355 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6356 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6357 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6358 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6359 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6360 | |
| 6361 | final long identity = Binder.clearCallingIdentity(); |
| 6362 | try { |
| 6363 | if (phone != null) { |
| 6364 | return phone.isInEcm(); |
| 6365 | } else { |
| 6366 | return false; |
| 6367 | } |
| 6368 | } finally { |
| 6369 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6370 | } |
| 6371 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6372 | |
| 6373 | /** |
| 6374 | * Get the current signal strength information for the given subscription. |
| 6375 | * Because this information is not updated when the device is in a low power state |
| 6376 | * it should not be relied-upon to be current. |
| 6377 | * @param subId Subscription index |
| 6378 | * @return the most recent cached signal strength info from the modem |
| 6379 | */ |
| 6380 | @Override |
| 6381 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6382 | final long identity = Binder.clearCallingIdentity(); |
| 6383 | try { |
| 6384 | Phone p = getPhone(subId); |
| 6385 | if (p == null) { |
| 6386 | return null; |
| 6387 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6388 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6389 | return p.getSignalStrength(); |
| 6390 | } finally { |
| 6391 | Binder.restoreCallingIdentity(identity); |
| 6392 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6393 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6394 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6395 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6396 | * Get the current modem radio state for the given slot. |
| 6397 | * @param slotIndex slot index. |
| 6398 | * @param callingPackage the name of the package making the call. |
| 6399 | * @return the current radio power state from the modem |
| 6400 | */ |
| 6401 | @Override |
| 6402 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6403 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6404 | if (phone != null) { |
| 6405 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6406 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6407 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6408 | } |
| 6409 | |
| 6410 | final long identity = Binder.clearCallingIdentity(); |
| 6411 | try { |
| 6412 | return phone.getRadioPowerState(); |
| 6413 | } finally { |
| 6414 | Binder.restoreCallingIdentity(identity); |
| 6415 | } |
| 6416 | } |
| 6417 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6418 | } |
| 6419 | |
| 6420 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6421 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6422 | * |
| 6423 | * <p>Requires one of the following permissions: |
| 6424 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6425 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6426 | * privileges. |
| 6427 | * |
| 6428 | * @param subId subscription id |
| 6429 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6430 | * {@code false}. |
| 6431 | */ |
| 6432 | @Override |
| 6433 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6434 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6435 | null /* message */); |
| 6436 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6437 | boolean isEnabled = false; |
| 6438 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6439 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6440 | Phone phone = getPhone(subId); |
| 6441 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6442 | } catch (Exception e) { |
| 6443 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6444 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6445 | } finally { |
| 6446 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6447 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6448 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6449 | } |
| 6450 | |
| 6451 | |
| 6452 | /** |
| 6453 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6454 | * |
| 6455 | * <p> Requires permission: |
| 6456 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6457 | * privileges. |
| 6458 | * |
| 6459 | * @param subId subscription id |
| 6460 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6461 | */ |
| 6462 | @Override |
| 6463 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6464 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6465 | mApp, subId, "setDataRoamingEnabled"); |
| 6466 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6467 | final long identity = Binder.clearCallingIdentity(); |
| 6468 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6469 | Phone phone = getPhone(subId); |
| 6470 | if (phone != null) { |
| 6471 | phone.setDataRoamingEnabled(isEnabled); |
| 6472 | } |
| 6473 | } finally { |
| 6474 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6475 | } |
| 6476 | } |
| 6477 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6478 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6479 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6480 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6481 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6482 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6483 | boolean isAllowed = true; |
| 6484 | final long identity = Binder.clearCallingIdentity(); |
| 6485 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6486 | Phone phone = getPhone(subId); |
| 6487 | if (phone != null) { |
| 6488 | isAllowed = phone.isCspPlmnEnabled(); |
| 6489 | } |
| 6490 | } finally { |
| 6491 | Binder.restoreCallingIdentity(identity); |
| 6492 | } |
| 6493 | return isAllowed; |
| 6494 | } |
| 6495 | |
| 6496 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6497 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6498 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6499 | try { |
| 6500 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6501 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6502 | } catch (SecurityException e) { |
| 6503 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6504 | // has carrier privileges on an active UICC |
| 6505 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6506 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6507 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6508 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6509 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6510 | |
| 6511 | final long identity = Binder.clearCallingIdentity(); |
| 6512 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6513 | UiccController uiccController = UiccController.getInstance(); |
| 6514 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6515 | if (hasReadPermission) { |
| 6516 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6517 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6518 | |
| 6519 | // Remove private info if the caller doesn't have access |
| 6520 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6521 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6522 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6523 | // is available |
| 6524 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6525 | if (card == null || card.getUiccProfile() == null) { |
| 6526 | // assume no access if the card or profile is unavailable |
| 6527 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6528 | continue; |
| 6529 | } |
| 6530 | UiccProfile profile = card.getUiccProfile(); |
| 6531 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6532 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6533 | filteredInfos.add(cardInfo); |
| 6534 | } else { |
| 6535 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6536 | } |
| 6537 | } |
| 6538 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6539 | } finally { |
| 6540 | Binder.restoreCallingIdentity(identity); |
| 6541 | } |
| 6542 | } |
| 6543 | |
| 6544 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6545 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6546 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6547 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6548 | final long identity = Binder.clearCallingIdentity(); |
| 6549 | try { |
| 6550 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6551 | if (slots == null) { |
| 6552 | Rlog.i(LOG_TAG, "slots is null."); |
| 6553 | return null; |
| 6554 | } |
| 6555 | |
| 6556 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6557 | for (int i = 0; i < slots.length; i++) { |
| 6558 | UiccSlot slot = slots[i]; |
| 6559 | if (slot == null) { |
| 6560 | continue; |
| 6561 | } |
| 6562 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6563 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6564 | UiccCard card = slot.getUiccCard(); |
| 6565 | if (card != null) { |
| 6566 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6567 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 6568 | cardId = slot.getEid(); |
| 6569 | if (TextUtils.isEmpty(cardId)) { |
| 6570 | cardId = slot.getIccId(); |
| 6571 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6572 | } |
| 6573 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 6574 | if (cardId != null) { |
| 6575 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 6576 | // if cardId is an EID, it's all digits so this is fine |
| 6577 | cardId = IccUtils.stripTrailingFs(cardId); |
| 6578 | } |
| 6579 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6580 | int cardState = 0; |
| 6581 | switch (slot.getCardState()) { |
| 6582 | case CARDSTATE_ABSENT: |
| 6583 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6584 | break; |
| 6585 | case CARDSTATE_PRESENT: |
| 6586 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6587 | break; |
| 6588 | case CARDSTATE_ERROR: |
| 6589 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6590 | break; |
| 6591 | case CARDSTATE_RESTRICTED: |
| 6592 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6593 | break; |
| 6594 | default: |
| 6595 | break; |
| 6596 | |
| 6597 | } |
| 6598 | |
| 6599 | infos[i] = new UiccSlotInfo( |
| 6600 | slot.isActive(), |
| 6601 | slot.isEuicc(), |
| 6602 | cardId, |
| 6603 | cardState, |
| 6604 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6605 | slot.isExtendedApduSupported(), |
| 6606 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6607 | } |
| 6608 | return infos; |
| 6609 | } finally { |
| 6610 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6611 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6612 | } |
| 6613 | |
| 6614 | @Override |
| 6615 | public boolean switchSlots(int[] physicalSlots) { |
| 6616 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6617 | |
| 6618 | final long identity = Binder.clearCallingIdentity(); |
| 6619 | try { |
| 6620 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6621 | } finally { |
| 6622 | Binder.restoreCallingIdentity(identity); |
| 6623 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6624 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6625 | |
| 6626 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6627 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6628 | final long identity = Binder.clearCallingIdentity(); |
| 6629 | try { |
| 6630 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6631 | } finally { |
| 6632 | Binder.restoreCallingIdentity(identity); |
| 6633 | } |
| 6634 | } |
| 6635 | |
| 6636 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6637 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6638 | enforceModifyPermission(); |
| 6639 | final Phone phone = getPhone(subId); |
| 6640 | if (phone == null) { |
| 6641 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6642 | return; |
| 6643 | } |
| 6644 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6645 | final long identity = Binder.clearCallingIdentity(); |
| 6646 | try { |
| 6647 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6648 | } finally { |
| 6649 | Binder.restoreCallingIdentity(identity); |
| 6650 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6651 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6652 | |
| 6653 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6654 | * A test API to reload the UICC profile. |
| 6655 | * |
| 6656 | * <p>Requires that the calling app has permission |
| 6657 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6658 | * @hide |
| 6659 | */ |
| 6660 | @Override |
| 6661 | public void refreshUiccProfile(int subId) { |
| 6662 | enforceModifyPermission(); |
| 6663 | |
| 6664 | final long identity = Binder.clearCallingIdentity(); |
| 6665 | try { |
| 6666 | Phone phone = getPhone(subId); |
| 6667 | if (phone == null) { |
| 6668 | return; |
| 6669 | } |
| 6670 | UiccCard uiccCard = phone.getUiccCard(); |
| 6671 | if (uiccCard == null) { |
| 6672 | return; |
| 6673 | } |
| 6674 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6675 | if (uiccProfile == null) { |
| 6676 | return; |
| 6677 | } |
| 6678 | uiccProfile.refresh(); |
| 6679 | } finally { |
| 6680 | Binder.restoreCallingIdentity(identity); |
| 6681 | } |
| 6682 | } |
| 6683 | |
| 6684 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6685 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6686 | */ |
| 6687 | private boolean getDefaultDataEnabled() { |
| 6688 | return "true".equalsIgnoreCase( |
| 6689 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6690 | } |
| 6691 | |
| 6692 | /** |
| 6693 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6694 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6695 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6696 | */ |
| 6697 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6698 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6699 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6700 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6701 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6702 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6703 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6704 | return isDataRoamingEnabled; |
| 6705 | } |
| 6706 | |
| 6707 | /** |
| 6708 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6709 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6710 | */ |
| 6711 | private int getDefaultNetworkType(int subId) { |
| 6712 | return Integer.parseInt( |
| 6713 | TelephonyManager.getTelephonyProperty( |
| 6714 | mSubscriptionController.getPhoneId(subId), |
| 6715 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6716 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6717 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6718 | |
| 6719 | @Override |
| 6720 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6721 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6722 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6723 | |
| 6724 | final long identity = Binder.clearCallingIdentity(); |
| 6725 | try { |
| 6726 | final Phone phone = getPhone(subId); |
| 6727 | if (phone == null) { |
| 6728 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6729 | return; |
| 6730 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6731 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 6732 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6733 | } finally { |
| 6734 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6735 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6736 | } |
| 6737 | |
| 6738 | @Override |
| 6739 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6740 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6741 | |
| 6742 | final long identity = Binder.clearCallingIdentity(); |
| 6743 | try { |
| 6744 | final Phone phone = getPhone(subId); |
| 6745 | if (phone == null) { |
| 6746 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6747 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6748 | } |
| 6749 | return phone.getCarrierIdListVersion(); |
| 6750 | } finally { |
| 6751 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6752 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6753 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6754 | |
| 6755 | @Override |
| 6756 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6757 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6758 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6759 | return -1; |
| 6760 | } |
| 6761 | |
| 6762 | final long identity = Binder.clearCallingIdentity(); |
| 6763 | try { |
| 6764 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6765 | } finally { |
| 6766 | Binder.restoreCallingIdentity(identity); |
| 6767 | } |
| 6768 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6769 | |
| 6770 | @Override |
| 6771 | public int getCdmaRoamingMode(int subId) { |
| 6772 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6773 | mApp, subId, "getCdmaRoamingMode"); |
| 6774 | |
| 6775 | final long identity = Binder.clearCallingIdentity(); |
| 6776 | try { |
| 6777 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6778 | } finally { |
| 6779 | Binder.restoreCallingIdentity(identity); |
| 6780 | } |
| 6781 | } |
| 6782 | |
| 6783 | @Override |
| 6784 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6785 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6786 | mApp, subId, "setCdmaRoamingMode"); |
| 6787 | |
| 6788 | final long identity = Binder.clearCallingIdentity(); |
| 6789 | try { |
| 6790 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6791 | } finally { |
| 6792 | Binder.restoreCallingIdentity(identity); |
| 6793 | } |
| 6794 | } |
| 6795 | |
| 6796 | @Override |
| 6797 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6798 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6799 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6800 | |
| 6801 | final long identity = Binder.clearCallingIdentity(); |
| 6802 | try { |
| 6803 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6804 | } finally { |
| 6805 | Binder.restoreCallingIdentity(identity); |
| 6806 | } |
| 6807 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 6808 | |
| 6809 | private void ensureUserRunning(int userId) { |
| 6810 | if (!mUserManager.isUserRunning(userId)) { |
| 6811 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6812 | } |
| 6813 | } |
| 6814 | |
| 6815 | /** |
| 6816 | * Returns a list of SMS apps on a given user. |
| 6817 | * |
| 6818 | * Only the shell user (UID 2000 or 0) can call it. |
| 6819 | * Target user must be running. |
| 6820 | */ |
| 6821 | @Override |
| 6822 | public String[] getSmsApps(int userId) { |
| 6823 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6824 | ensureUserRunning(userId); |
| 6825 | |
| 6826 | final Collection<SmsApplicationData> apps = |
| 6827 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6828 | |
| 6829 | String[] ret = new String[apps.size()]; |
| 6830 | int i = 0; |
| 6831 | for (SmsApplicationData app : apps) { |
| 6832 | ret[i++] = app.mPackageName; |
| 6833 | } |
| 6834 | return ret; |
| 6835 | } |
| 6836 | |
| 6837 | /** |
| 6838 | * Returns the default SMS app package name on a given user. |
| 6839 | * |
| 6840 | * Only the shell user (UID 2000 or 0) can call it. |
| 6841 | * Target user must be running. |
| 6842 | */ |
| 6843 | @Override |
| 6844 | public String getDefaultSmsApp(int userId) { |
| 6845 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6846 | ensureUserRunning(userId); |
| 6847 | |
| 6848 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6849 | /* updateIfNeeded= */ true, userId); |
| 6850 | return cn == null ? null : cn.getPackageName(); |
| 6851 | } |
| 6852 | |
| 6853 | /** |
| 6854 | * Set a package as the default SMS app on a given user. |
| 6855 | * |
| 6856 | * Only the shell user (UID 2000 or 0) can call it. |
| 6857 | * Target user must be running. |
| 6858 | */ |
| 6859 | @Override |
| 6860 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6861 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6862 | ensureUserRunning(userId); |
| 6863 | |
| 6864 | boolean found = false; |
| 6865 | for (String pkg : getSmsApps(userId)) { |
| 6866 | if (TextUtils.equals(packageName, pkg)) { |
| 6867 | found = true; |
| 6868 | break; |
| 6869 | } |
| 6870 | } |
| 6871 | if (!found) { |
| 6872 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6873 | } |
| 6874 | |
| 6875 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6876 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6877 | |
| 6878 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6879 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6880 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6881 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6882 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6883 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6884 | } |
| 6885 | final long identity = Binder.clearCallingIdentity(); |
| 6886 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6887 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6888 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6889 | if (phone.getEmergencyNumberTracker() != null |
| 6890 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6891 | emergencyNumberListInternal.put( |
| 6892 | phone.getSubId(), |
| 6893 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6894 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6895 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6896 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6897 | } finally { |
| 6898 | Binder.restoreCallingIdentity(identity); |
| 6899 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6900 | } |
| 6901 | |
| 6902 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6903 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6904 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6905 | if (!exactMatch) { |
| 6906 | TelephonyPermissions |
| 6907 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6908 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6909 | } |
| 6910 | final long identity = Binder.clearCallingIdentity(); |
| 6911 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6912 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6913 | if (phone.getEmergencyNumberTracker() != null |
| 6914 | && phone.getEmergencyNumberTracker() != null) { |
| 6915 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6916 | number, exactMatch)) { |
| 6917 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6918 | } |
| 6919 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6920 | } |
| 6921 | return false; |
| 6922 | } finally { |
| 6923 | Binder.restoreCallingIdentity(identity); |
| 6924 | } |
| 6925 | } |
| 6926 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6927 | /** |
| 6928 | * Update emergency number list for test mode. |
| 6929 | */ |
| 6930 | @Override |
| 6931 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6932 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6933 | "updateEmergencyNumberListTestMode"); |
| 6934 | |
| 6935 | final long identity = Binder.clearCallingIdentity(); |
| 6936 | try { |
| 6937 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6938 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6939 | if (tracker != null) { |
| 6940 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6941 | } |
| 6942 | } |
| 6943 | } finally { |
| 6944 | Binder.restoreCallingIdentity(identity); |
| 6945 | } |
| 6946 | } |
| 6947 | |
| 6948 | /** |
| 6949 | * Get the full emergency number list for test mode. |
| 6950 | */ |
| 6951 | @Override |
| 6952 | public List<String> getEmergencyNumberListTestMode() { |
| 6953 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6954 | "getEmergencyNumberListTestMode"); |
| 6955 | |
| 6956 | final long identity = Binder.clearCallingIdentity(); |
| 6957 | try { |
| 6958 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6959 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6960 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6961 | if (tracker != null) { |
| 6962 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6963 | emergencyNumbers.add(num.getNumber()); |
| 6964 | } |
| 6965 | } |
| 6966 | } |
| 6967 | return new ArrayList<>(emergencyNumbers); |
| 6968 | } finally { |
| 6969 | Binder.restoreCallingIdentity(identity); |
| 6970 | } |
| 6971 | } |
| 6972 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6973 | @Override |
| 6974 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6975 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6976 | Phone phone = getPhone(subId); |
| 6977 | if (phone == null) { |
| 6978 | return null; |
| 6979 | } |
| 6980 | final long identity = Binder.clearCallingIdentity(); |
| 6981 | try { |
| 6982 | UiccProfile profile = UiccController.getInstance() |
| 6983 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6984 | if (profile != null) { |
| 6985 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6986 | } |
| 6987 | } finally { |
| 6988 | Binder.restoreCallingIdentity(identity); |
| 6989 | } |
| 6990 | return null; |
| 6991 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6992 | |
| 6993 | /** |
| 6994 | * Enable or disable a modem stack. |
| 6995 | */ |
| 6996 | @Override |
| 6997 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6998 | enforceModifyPermission(); |
| 6999 | |
| 7000 | final long identity = Binder.clearCallingIdentity(); |
| 7001 | try { |
| 7002 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7003 | if (phone == null) { |
| 7004 | return false; |
| 7005 | } else { |
| 7006 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7007 | } |
| 7008 | } finally { |
| 7009 | Binder.restoreCallingIdentity(identity); |
| 7010 | } |
| 7011 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7012 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7013 | /** |
| 7014 | * Whether a modem stack is enabled or not. |
| 7015 | */ |
| 7016 | @Override |
| 7017 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 7018 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7019 | if (phone == null) return false; |
| 7020 | |
| 7021 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7022 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 7023 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7024 | } |
| 7025 | |
| 7026 | final long identity = Binder.clearCallingIdentity(); |
| 7027 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7028 | try { |
| 7029 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7030 | } catch (NoSuchElementException ex) { |
| 7031 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7032 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7033 | } finally { |
| 7034 | Binder.restoreCallingIdentity(identity); |
| 7035 | } |
| 7036 | } |
| 7037 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7038 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7039 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7040 | enforceModifyPermission(); |
| 7041 | |
| 7042 | final long identity = Binder.clearCallingIdentity(); |
| 7043 | try { |
| 7044 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7045 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7046 | .commit(); |
| 7047 | } finally { |
| 7048 | Binder.restoreCallingIdentity(identity); |
| 7049 | } |
| 7050 | } |
| 7051 | |
| 7052 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7053 | @TelephonyManager.IsMultiSimSupportedResult |
| 7054 | public int isMultiSimSupported(String callingPackage) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7055 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7056 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 7057 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7058 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7059 | |
| 7060 | final long identity = Binder.clearCallingIdentity(); |
| 7061 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7062 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7063 | } finally { |
| 7064 | Binder.restoreCallingIdentity(identity); |
| 7065 | } |
| 7066 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7067 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7068 | @TelephonyManager.IsMultiSimSupportedResult |
| 7069 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7070 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7071 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7072 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7073 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7074 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7075 | } |
| 7076 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7077 | // supported by the modem, indicate that it is restricted. |
| 7078 | PhoneCapability staticCapability = |
| 7079 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7080 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7081 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7082 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7083 | } |
| 7084 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7085 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7086 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7087 | } |
| 7088 | // Check if support of multiple SIMs is restricted by carrier |
| 7089 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7090 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7091 | } |
| 7092 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7093 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7094 | } |
| 7095 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7096 | /** |
| 7097 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7098 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7099 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7100 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7101 | * @param numOfSims number of active sims we want to switch to |
| 7102 | */ |
| 7103 | @Override |
| 7104 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7105 | if (numOfSims == 1) { |
| 7106 | enforceModifyPermission(); |
| 7107 | } else { |
| 7108 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7109 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7110 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7111 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7112 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7113 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7114 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7115 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7116 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7117 | return; |
| 7118 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7119 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7120 | } finally { |
| 7121 | Binder.restoreCallingIdentity(identity); |
| 7122 | } |
| 7123 | } |
| 7124 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7125 | @Override |
| 7126 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7127 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7128 | Phone phone = getPhone(subId); |
| 7129 | if (phone == null) { |
| 7130 | return false; |
| 7131 | } |
| 7132 | final long identity = Binder.clearCallingIdentity(); |
| 7133 | try { |
| 7134 | UiccCard uiccCard = phone.getUiccCard(); |
| 7135 | if (uiccCard == null) { |
| 7136 | return false; |
| 7137 | } |
| 7138 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7139 | if (uiccProfile == null) { |
| 7140 | return false; |
| 7141 | } |
| 7142 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 7143 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 7144 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 7145 | } |
| 7146 | return false; |
| 7147 | } finally { |
| 7148 | Binder.restoreCallingIdentity(identity); |
| 7149 | } |
| 7150 | } |
| 7151 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7152 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7153 | * Get whether making changes to modem configurations will trigger reboot. |
| 7154 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7155 | */ |
| 7156 | @Override |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7157 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) { |
| 7158 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7159 | mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) { |
| 7160 | return false; |
| 7161 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7162 | final long identity = Binder.clearCallingIdentity(); |
| 7163 | try { |
| 7164 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7165 | } finally { |
| 7166 | Binder.restoreCallingIdentity(identity); |
| 7167 | } |
| 7168 | } |
| 7169 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7170 | private void updateModemStateMetrics() { |
| 7171 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7172 | // TODO: check the state for each modem if the api is ready. |
| 7173 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7174 | } |
| 7175 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7176 | @Override |
| 7177 | public int[] getSlotsMapping() { |
| 7178 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7179 | |
| 7180 | final long identity = Binder.clearCallingIdentity(); |
| 7181 | try { |
| 7182 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7183 | // All logical slots should have a mapping to a physical slot. |
| 7184 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7185 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7186 | for (int i = 0; i < slotInfos.length; i++) { |
| 7187 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7188 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7189 | } |
| 7190 | } |
| 7191 | return logicalSlotsMapping; |
| 7192 | } finally { |
| 7193 | Binder.restoreCallingIdentity(identity); |
| 7194 | } |
| 7195 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7196 | |
| 7197 | /** |
| 7198 | * Get the IRadio HAL Version |
| 7199 | */ |
| 7200 | @Override |
| 7201 | public int getRadioHalVersion() { |
| 7202 | Phone phone = getDefaultPhone(); |
| 7203 | if (phone == null) return -1; |
| 7204 | HalVersion hv = phone.getHalVersion(); |
| 7205 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7206 | return hv.major * 100 + hv.minor; |
| 7207 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7208 | |
| 7209 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7210 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7211 | * corresponding network requests on a subId. |
| 7212 | * |
| 7213 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7214 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7215 | * 2) APN is un-metered for this subscription, or |
| 7216 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7217 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7218 | * |
| 7219 | * @return whether data is allowed for a apn type. |
| 7220 | * |
| 7221 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7222 | */ |
| 7223 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7224 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7225 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7226 | mApp, subId, callingPackage, "isDataEnabledForApn")) { |
| 7227 | throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7228 | } |
| 7229 | |
| 7230 | // Now that all security checks passes, perform the operation as ourselves. |
| 7231 | final long identity = Binder.clearCallingIdentity(); |
| 7232 | try { |
| 7233 | Phone phone = getPhone(subId); |
| 7234 | if (phone == null) return false; |
| 7235 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7236 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7237 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7238 | } finally { |
| 7239 | Binder.restoreCallingIdentity(identity); |
| 7240 | } |
| 7241 | } |
| 7242 | |
| 7243 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7244 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7245 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7246 | |
| 7247 | // Now that all security checks passes, perform the operation as ourselves. |
| 7248 | final long identity = Binder.clearCallingIdentity(); |
| 7249 | try { |
| 7250 | Phone phone = getPhone(subId); |
| 7251 | if (phone == null) return true; // By default return true. |
| 7252 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7253 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7254 | } finally { |
| 7255 | Binder.restoreCallingIdentity(identity); |
| 7256 | } |
| 7257 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7258 | |
| 7259 | @Override |
| 7260 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7261 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7262 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7263 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7264 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7265 | } |
| 7266 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7267 | Intent intent = new Intent(); |
| 7268 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7269 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7270 | // Bring up choose default SMS subscription dialog right now |
| 7271 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7272 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7273 | mApp.startActivity(intent); |
| 7274 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7275 | |
| 7276 | @Override |
| 7277 | public String getMmsUAProfUrl(int subId) { |
| 7278 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7279 | final long identity = Binder.clearCallingIdentity(); |
| 7280 | try { |
| 7281 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7282 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7283 | } finally { |
| 7284 | Binder.restoreCallingIdentity(identity); |
| 7285 | } |
| 7286 | } |
| 7287 | |
| 7288 | @Override |
| 7289 | public String getMmsUserAgent(int subId) { |
| 7290 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7291 | final long identity = Binder.clearCallingIdentity(); |
| 7292 | try { |
| 7293 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7294 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7295 | } finally { |
| 7296 | Binder.restoreCallingIdentity(identity); |
| 7297 | } |
| 7298 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7299 | |
| 7300 | @Override |
| 7301 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7302 | enforceModifyPermission(); |
| 7303 | |
| 7304 | // Now that all security checks passes, perform the operation as ourselves. |
| 7305 | final long identity = Binder.clearCallingIdentity(); |
| 7306 | try { |
| 7307 | Phone phone = getPhone(subId); |
| 7308 | if (phone == null) return false; |
| 7309 | |
| 7310 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7311 | } finally { |
| 7312 | Binder.restoreCallingIdentity(identity); |
| 7313 | } |
| 7314 | } |
| 7315 | |
| 7316 | @Override |
| 7317 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7318 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7319 | |
| 7320 | // Now that all security checks passes, perform the operation as ourselves. |
| 7321 | final long identity = Binder.clearCallingIdentity(); |
| 7322 | try { |
| 7323 | Phone phone = getPhone(subId); |
| 7324 | if (phone == null) return false; |
| 7325 | |
| 7326 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7327 | } finally { |
| 7328 | Binder.restoreCallingIdentity(identity); |
| 7329 | } |
| 7330 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7331 | } |