| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
| Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 24 | import android.Manifest; |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 25 | import android.Manifest.permission; |
| changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 26 | import android.annotation.NonNull; |
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 27 | import android.annotation.Nullable; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 28 | import android.app.AppOpsManager; |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 29 | import android.app.PendingIntent; |
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 30 | import android.content.ComponentName; |
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 31 | import android.content.ContentResolver; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 34 | import android.content.SharedPreferences; |
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
| Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
| Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 55 | import android.os.SystemClock; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 57 | import android.os.UserManager; |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 59 | import android.preference.PreferenceManager; |
| Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 60 | import android.provider.DeviceConfig; |
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 61 | import android.provider.Settings; |
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 62 | import android.provider.Telephony; |
| Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 63 | import android.sysprop.TelephonyProperties; |
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccount; |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 65 | import android.telecom.PhoneAccountHandle; |
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 66 | import android.telecom.TelecomManager; |
| Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 67 | import android.telephony.Annotation.ApnType; |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 68 | import android.telephony.Annotation.ThermalMitigationResult; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 69 | import android.telephony.CallForwardingInfo; |
| Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 70 | import android.telephony.CarrierBandwidth; |
| Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 71 | import android.telephony.CarrierConfigManager; |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 72 | import android.telephony.CarrierRestrictionRules; |
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 73 | import android.telephony.CellIdentity; |
| Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 74 | import android.telephony.CellIdentityCdma; |
| 75 | import android.telephony.CellIdentityGsm; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 76 | import android.telephony.CellInfo; |
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 77 | import android.telephony.CellInfoGsm; |
| 78 | import android.telephony.CellInfoWcdma; |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 79 | import android.telephony.ClientRequestStats; |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 80 | import android.telephony.DataThrottlingRequest; |
| Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 81 | import android.telephony.IBootstrapAuthenticationCallback; |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 82 | import android.telephony.ICellInfoCallback; |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 83 | import android.telephony.IccOpenLogicalChannelResponse; |
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 84 | import android.telephony.LocationAccessPolicy; |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 85 | import android.telephony.ModemActivityInfo; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 86 | import android.telephony.NeighboringCellInfo; |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 87 | import android.telephony.NetworkScanRequest; |
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 88 | import android.telephony.PhoneCapability; |
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 89 | import android.telephony.PhoneNumberRange; |
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 90 | import android.telephony.RadioAccessFamily; |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 91 | import android.telephony.RadioAccessSpecifier; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 92 | import android.telephony.ServiceState; |
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 93 | import android.telephony.SignalStrength; |
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 94 | import android.telephony.SignalStrengthUpdateRequest; |
| 95 | import android.telephony.SignalThresholdInfo; |
| Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 96 | import android.telephony.SubscriptionInfo; |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 97 | import android.telephony.SubscriptionManager; |
| Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 98 | import android.telephony.TelephonyFrameworkInitializer; |
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 99 | import android.telephony.TelephonyHistogram; |
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 100 | import android.telephony.TelephonyManager; |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 101 | import android.telephony.TelephonyScanManager; |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 102 | import android.telephony.ThermalMitigationRequest; |
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 103 | import android.telephony.UiccCardInfo; |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 104 | import android.telephony.UiccSlotInfo; |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 105 | import android.telephony.UssdResponse; |
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 106 | import android.telephony.VisualVoicemailSmsFilterSettings; |
| Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 107 | import android.telephony.data.ApnSetting; |
| 108 | import android.telephony.emergency.EmergencyNumber; |
| Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 109 | import android.telephony.gba.GbaAuthRequest; |
| 110 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 111 | import android.telephony.ims.ImsException; |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.ProvisioningManager; |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 113 | import android.telephony.ims.RcsClientConfiguration; |
| Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 114 | import android.telephony.ims.RegistrationManager; |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IImsConfig; |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IImsConfigCallback; |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IImsRegistration; |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 119 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 120 | import android.telephony.ims.aidl.IRcsConfigCallback; |
| Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 121 | import android.telephony.ims.feature.ImsFeature; |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 122 | import android.telephony.ims.feature.MmTelFeature; |
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 123 | import android.telephony.ims.feature.RcsFeature; |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 124 | import android.telephony.ims.stub.ImsConfigImplBase; |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 125 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | import android.text.TextUtils; |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 127 | import android.util.ArraySet; |
| Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 128 | import android.util.EventLog; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import android.util.Log; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 130 | import android.util.Pair; |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 131 | |
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 132 | import com.android.ims.ImsManager; |
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 133 | import com.android.ims.internal.IImsServiceFeatureCallback; |
| James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 134 | import com.android.ims.rcs.uce.eab.EabUtil; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.CallForwardInfo; |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.CallManager; |
| Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.CallStateException; |
| pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.CarrierInfoManager; |
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.CarrierResolver; |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.CellNetworkScanResult; |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.CommandException; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.CommandsInterface; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.DefaultPhoneNotifier; |
| Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.GbaManager; |
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.HalVersion; |
| Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.IBooleanConsumer; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.IIntegerConsumer; |
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.INumberVerificationCallback; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.ITelephony; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.IccCard; |
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.LocaleTracker; |
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.NetworkScanRequestTracker; |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.OperatorInfo; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.Phone; |
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.PhoneConfigurationManager; |
| Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.PhoneConstantConversions; |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.PhoneConstants; |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.PhoneFactory; |
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.ProxyController; |
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.RIL; |
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.ServiceStateTracker; |
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.SmsController; |
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.SmsPermissions; |
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.SubscriptionController; |
| Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 166 | import com.android.internal.telephony.TelephonyIntents; |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.TelephonyPermissions; |
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.euicc.EuiccConnector; |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.ims.ImsResolver; |
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 173 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
| Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccIoResult; |
| changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.IccRecords; |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.IccUtils; |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.SIMRecords; |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccCard; |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccCardApplication; |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccController; |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.UiccProfile; |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.UiccSlot; |
| zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 185 | import com.android.internal.telephony.util.LocaleUtils; |
| fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 187 | import com.android.internal.util.FunctionalUtils; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 188 | import com.android.internal.util.HexDump; |
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 189 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 190 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 191 | import com.android.phone.vvm.RemoteVvmTaskManager; |
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 192 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
| Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 193 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 194 | import com.android.services.telephony.TelecomAccountRegistry; |
| 195 | import com.android.services.telephony.TelephonyConnectionService; |
| Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 196 | import com.android.telephony.Rlog; |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 197 | |
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 198 | import java.io.FileDescriptor; |
| 199 | import java.io.PrintWriter; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 | import java.util.ArrayList; |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 201 | import java.util.Arrays; |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 202 | import java.util.HashMap; |
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 203 | import java.util.HashSet; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 204 | import java.util.List; |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 205 | import java.util.Locale; |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 206 | import java.util.Map; |
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 207 | import java.util.NoSuchElementException; |
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 208 | import java.util.Objects; |
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 209 | import java.util.Set; |
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 210 | import java.util.concurrent.atomic.AtomicBoolean; |
| Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 211 | import java.util.function.Consumer; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 212 | |
| 213 | /** |
| 214 | * Implementation of the ITelephony interface. |
| 215 | */ |
| Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 216 | public class PhoneInterfaceManager extends ITelephony.Stub { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 217 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 218 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 219 | private static final boolean DBG_LOC = false; |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 220 | private static final boolean DBG_MERGE = false; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 221 | |
| 222 | // Message codes used with mMainThreadHandler |
| 223 | private static final int CMD_HANDLE_PIN_MMI = 1; |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 224 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 225 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 226 | private static final int CMD_OPEN_CHANNEL = 9; |
| 227 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 228 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 229 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 230 | private static final int CMD_NV_READ_ITEM = 13; |
| 231 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 232 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 233 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 234 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 235 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 236 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 237 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 238 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 239 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
| Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 240 | private static final int CMD_SEND_ENVELOPE = 25; |
| 241 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 242 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 243 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
| Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 244 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 245 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 246 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 247 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 248 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 249 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 250 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 251 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 252 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 253 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 254 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 255 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 256 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 257 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 258 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 259 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 260 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 261 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 262 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 263 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 264 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 265 | private static final int CMD_SWITCH_SLOTS = 50; |
| 266 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 267 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 268 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 269 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 270 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 271 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 272 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 273 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 274 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 275 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 276 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 277 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 278 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 279 | private static final int CMD_MODEM_REBOOT = 64; |
| 280 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 281 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 282 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 283 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 284 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 285 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 286 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 287 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 288 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
| Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 289 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 290 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 291 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 292 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 293 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 294 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
| Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 295 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 296 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 297 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 298 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 299 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 300 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 301 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 302 | private static final int CMD_GET_CALL_WAITING = 87; |
| 303 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 304 | private static final int CMD_SET_CALL_WAITING = 89; |
| 305 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
| Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 306 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 307 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 308 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 309 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
| Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 310 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 311 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 312 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 313 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 314 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 315 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
| Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 316 | private static final int CMD_SET_SIM_POWER = 101; |
| 317 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 318 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 319 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 320 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 321 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 322 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 323 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 324 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 325 | |
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 326 | // Parameters of select command. |
| 327 | private static final int SELECT_COMMAND = 0xA4; |
| 328 | private static final int SELECT_P1 = 0x04; |
| 329 | private static final int SELECT_P2 = 0; |
| 330 | private static final int SELECT_P3 = 0x10; |
| 331 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 332 | /** The singleton instance. */ |
| 333 | private static PhoneInterfaceManager sInstance; |
| 334 | |
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 335 | private PhoneGlobals mApp; |
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 336 | private CallManager mCM; |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 337 | private ImsResolver mImsResolver; |
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 338 | private UserManager mUserManager; |
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 339 | private AppOpsManager mAppOps; |
| 340 | private MainThreadHandler mMainThreadHandler; |
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 341 | private SubscriptionController mSubscriptionController; |
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 342 | private SharedPreferences mTelephonySharedPreferences; |
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 343 | private PhoneConfigurationManager mPhoneConfigurationManager; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 344 | |
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 345 | /** User Activity */ |
| 346 | private AtomicBoolean mNotifyUserActivity; |
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 347 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 348 | |
| Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 349 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 350 | |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 351 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 352 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 353 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 354 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 355 | |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 356 | // String to store multi SIM allowed |
| 357 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 358 | |
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 359 | // The AID of ISD-R. |
| 360 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 361 | |
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 362 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 363 | |
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 364 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 365 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 366 | |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 367 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 368 | |
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 369 | /** |
| Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 370 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 371 | */ |
| 372 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 373 | "reset_network_erase_modem_config_enabled"; |
| 374 | |
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 375 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 376 | |
| Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 377 | /** |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 378 | * A request object to use for transmitting data to an ICC. |
| 379 | */ |
| 380 | private static final class IccAPDUArgument { |
| 381 | public int channel, cla, command, p1, p2, p3; |
| 382 | public String data; |
| 383 | |
| 384 | public IccAPDUArgument(int channel, int cla, int command, |
| 385 | int p1, int p2, int p3, String data) { |
| 386 | this.channel = channel; |
| 387 | this.cla = cla; |
| 388 | this.command = command; |
| 389 | this.p1 = p1; |
| 390 | this.p2 = p2; |
| 391 | this.p3 = p3; |
| 392 | this.data = data; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /** |
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 397 | * A request object to use for transmitting data to an ICC. |
| 398 | */ |
| 399 | private static final class ManualNetworkSelectionArgument { |
| 400 | public OperatorInfo operatorInfo; |
| 401 | public boolean persistSelection; |
| 402 | |
| 403 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 404 | this.operatorInfo = operatorInfo; |
| 405 | this.persistSelection = persistSelection; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /** |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 410 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 411 | * request after sending. The main thread will notify the request when it is complete. |
| 412 | */ |
| 413 | private static final class MainThreadRequest { |
| 414 | /** The argument to use for the request */ |
| 415 | public Object argument; |
| 416 | /** The result of the request that is run on the main thread */ |
| 417 | public Object result; |
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 418 | // The subscriber id that this request applies to. Defaults to |
| 419 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 420 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 421 | |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 422 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 423 | public Phone phone; |
| 424 | |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 425 | public WorkSource workSource; |
| 426 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | public MainThreadRequest(Object argument) { |
| 428 | this.argument = argument; |
| 429 | } |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 430 | |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 431 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 432 | this.argument = argument; |
| 433 | if (phone != null) { |
| 434 | this.phone = phone; |
| 435 | } |
| 436 | this.workSource = workSource; |
| 437 | } |
| 438 | |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 439 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 440 | this.argument = argument; |
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 441 | if (subId != null) { |
| 442 | this.subId = subId; |
| 443 | } |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 444 | this.workSource = workSource; |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 445 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 448 | private static final class IncomingThirdPartyCallArgs { |
| 449 | public final ComponentName component; |
| 450 | public final String callId; |
| 451 | public final String callerDisplayName; |
| 452 | |
| 453 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 454 | String callerDisplayName) { |
| 455 | this.component = component; |
| 456 | this.callId = callId; |
| 457 | this.callerDisplayName = callerDisplayName; |
| 458 | } |
| 459 | } |
| 460 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 461 | /** |
| 462 | * A handler that processes messages on the main thread in the phone process. Since many |
| 463 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 464 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 465 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 466 | * on, which will be notified when the operation completes and will contain the result of the |
| 467 | * request. |
| 468 | * |
| 469 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 470 | * note that request.result must be set to something non-null for the calling thread to |
| 471 | * unblock. |
| 472 | */ |
| 473 | private final class MainThreadHandler extends Handler { |
| 474 | @Override |
| 475 | public void handleMessage(Message msg) { |
| 476 | MainThreadRequest request; |
| 477 | Message onCompleted; |
| 478 | AsyncResult ar; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 479 | UiccCard uiccCard; |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 480 | IccAPDUArgument iccArgument; |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 481 | final Phone defaultPhone = getDefaultPhone(); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 482 | |
| 483 | switch (msg.what) { |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 484 | case CMD_HANDLE_USSD_REQUEST: { |
| 485 | request = (MainThreadRequest) msg.obj; |
| 486 | final Phone phone = getPhoneFromRequest(request); |
| 487 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 488 | String ussdRequest = ussdObject.first; |
| 489 | ResultReceiver wrappedCallback = ussdObject.second; |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 490 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 491 | if (!isUssdApiAllowed(request.subId)) { |
| 492 | // Carrier does not support use of this API, return failure. |
| 493 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 494 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 495 | Bundle returnData = new Bundle(); |
| 496 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 497 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 498 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 499 | request.result = true; |
| 500 | notifyRequester(request); |
| 501 | return; |
| 502 | } |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 503 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 504 | try { |
| 505 | request.result = phone != null |
| 506 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 507 | } catch (CallStateException cse) { |
| 508 | request.result = false; |
| 509 | } |
| 510 | // Wake up the requesting thread |
| 511 | notifyRequester(request); |
| 512 | break; |
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 515 | case CMD_HANDLE_PIN_MMI: { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 516 | request = (MainThreadRequest) msg.obj; |
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 517 | final Phone phone = getPhoneFromRequest(request); |
| 518 | request.result = phone != null ? |
| 519 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 520 | : false; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 521 | // Wake up the requesting thread |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 522 | notifyRequester(request); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 523 | break; |
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 524 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 525 | |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 526 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 527 | request = (MainThreadRequest) msg.obj; |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 528 | iccArgument = (IccAPDUArgument) request.argument; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 529 | uiccCard = getUiccCardFromRequest(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 530 | if (uiccCard == null) { |
| 531 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 532 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 533 | notifyRequester(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 534 | } else { |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 535 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 536 | request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 537 | uiccCard.iccTransmitApduLogicalChannel( |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 538 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 539 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 540 | onCompleted); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 541 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 542 | break; |
| 543 | |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 544 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 545 | ar = (AsyncResult) msg.obj; |
| 546 | request = (MainThreadRequest) ar.userObj; |
| 547 | if (ar.exception == null && ar.result != null) { |
| 548 | request.result = ar.result; |
| 549 | } else { |
| 550 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 551 | if (ar.result == null) { |
| 552 | loge("iccTransmitApduLogicalChannel: Empty response"); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 553 | } else if (ar.exception instanceof CommandException) { |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 554 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 555 | ar.exception); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 556 | } else { |
| 557 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 558 | } |
| 559 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 560 | notifyRequester(request); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 561 | break; |
| 562 | |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 563 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 564 | request = (MainThreadRequest) msg.obj; |
| 565 | iccArgument = (IccAPDUArgument) request.argument; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 566 | uiccCard = getUiccCardFromRequest(request); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 567 | if (uiccCard == null) { |
| 568 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 569 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 570 | notifyRequester(request); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 571 | } else { |
| 572 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 573 | request); |
| 574 | uiccCard.iccTransmitApduBasicChannel( |
| 575 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 576 | iccArgument.p3, iccArgument.data, onCompleted); |
| 577 | } |
| 578 | break; |
| 579 | |
| 580 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 581 | ar = (AsyncResult) msg.obj; |
| 582 | request = (MainThreadRequest) ar.userObj; |
| 583 | if (ar.exception == null && ar.result != null) { |
| 584 | request.result = ar.result; |
| 585 | } else { |
| 586 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 587 | if (ar.result == null) { |
| 588 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 589 | } else if (ar.exception instanceof CommandException) { |
| 590 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 591 | ar.exception); |
| 592 | } else { |
| 593 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 594 | } |
| 595 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 596 | notifyRequester(request); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 597 | break; |
| 598 | |
| 599 | case CMD_EXCHANGE_SIM_IO: |
| 600 | request = (MainThreadRequest) msg.obj; |
| 601 | iccArgument = (IccAPDUArgument) request.argument; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 602 | uiccCard = getUiccCardFromRequest(request); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 603 | if (uiccCard == null) { |
| 604 | loge("iccExchangeSimIO: No UICC"); |
| 605 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 606 | notifyRequester(request); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 607 | } else { |
| 608 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 609 | request); |
| 610 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 611 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 612 | iccArgument.data, onCompleted); |
| 613 | } |
| 614 | break; |
| 615 | |
| 616 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 617 | ar = (AsyncResult) msg.obj; |
| 618 | request = (MainThreadRequest) ar.userObj; |
| 619 | if (ar.exception == null && ar.result != null) { |
| 620 | request.result = ar.result; |
| 621 | } else { |
| 622 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 623 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 624 | notifyRequester(request); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 625 | break; |
| 626 | |
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 627 | case CMD_SEND_ENVELOPE: |
| 628 | request = (MainThreadRequest) msg.obj; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 629 | uiccCard = getUiccCardFromRequest(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 630 | if (uiccCard == null) { |
| 631 | loge("sendEnvelopeWithStatus: No UICC"); |
| 632 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 633 | notifyRequester(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 634 | } else { |
| 635 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 636 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 637 | } |
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 638 | break; |
| 639 | |
| 640 | case EVENT_SEND_ENVELOPE_DONE: |
| 641 | ar = (AsyncResult) msg.obj; |
| 642 | request = (MainThreadRequest) ar.userObj; |
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 643 | if (ar.exception == null && ar.result != null) { |
| 644 | request.result = ar.result; |
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 645 | } else { |
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 646 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 647 | if (ar.result == null) { |
| 648 | loge("sendEnvelopeWithStatus: Empty response"); |
| 649 | } else if (ar.exception instanceof CommandException) { |
| 650 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 651 | ar.exception); |
| 652 | } else { |
| 653 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 654 | } |
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 655 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 656 | notifyRequester(request); |
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 657 | break; |
| 658 | |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 659 | case CMD_OPEN_CHANNEL: |
| 660 | request = (MainThreadRequest) msg.obj; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 661 | uiccCard = getUiccCardFromRequest(request); |
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 662 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 663 | if (uiccCard == null) { |
| 664 | loge("iccOpenLogicalChannel: No UICC"); |
| Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 665 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 666 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 667 | notifyRequester(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 668 | } else { |
| 669 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 670 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 671 | openChannelArgs.second, onCompleted); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 672 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 673 | break; |
| 674 | |
| 675 | case EVENT_OPEN_CHANNEL_DONE: |
| 676 | ar = (AsyncResult) msg.obj; |
| 677 | request = (MainThreadRequest) ar.userObj; |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 678 | IccOpenLogicalChannelResponse openChannelResp; |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | if (ar.exception == null && ar.result != null) { |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 680 | int[] result = (int[]) ar.result; |
| 681 | int channelId = result[0]; |
| 682 | byte[] selectResponse = null; |
| 683 | if (result.length > 1) { |
| 684 | selectResponse = new byte[result.length - 1]; |
| 685 | for (int i = 1; i < result.length; ++i) { |
| 686 | selectResponse[i - 1] = (byte) result[i]; |
| 687 | } |
| 688 | } |
| 689 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 690 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 691 | } else { |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 692 | if (ar.result == null) { |
| 693 | loge("iccOpenLogicalChannel: Empty response"); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 694 | } |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 695 | if (ar.exception != null) { |
| 696 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 697 | } |
| 698 | |
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 699 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 700 | if (ar.exception instanceof CommandException) { |
| 701 | CommandException.Error error = |
| 702 | ((CommandException) (ar.exception)).getCommandError(); |
| 703 | if (error == CommandException.Error.MISSING_RESOURCE) { |
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 704 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 705 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 706 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 710 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 711 | } |
| Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 712 | request.result = openChannelResp; |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 713 | notifyRequester(request); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 714 | break; |
| 715 | |
| 716 | case CMD_CLOSE_CHANNEL: |
| 717 | request = (MainThreadRequest) msg.obj; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 718 | uiccCard = getUiccCardFromRequest(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 719 | if (uiccCard == null) { |
| 720 | loge("iccCloseLogicalChannel: No UICC"); |
| Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 721 | request.result = false; |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 722 | notifyRequester(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 723 | } else { |
| 724 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 725 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 726 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | case EVENT_CLOSE_CHANNEL_DONE: |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 730 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 731 | break; |
| 732 | |
| 733 | case CMD_NV_READ_ITEM: |
| 734 | request = (MainThreadRequest) msg.obj; |
| 735 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 736 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 737 | request.workSource); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 738 | break; |
| 739 | |
| 740 | case EVENT_NV_READ_ITEM_DONE: |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | ar = (AsyncResult) msg.obj; |
| 742 | request = (MainThreadRequest) ar.userObj; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 743 | if (ar.exception == null && ar.result != null) { |
| 744 | request.result = ar.result; // String |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 745 | } else { |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 746 | request.result = ""; |
| 747 | if (ar.result == null) { |
| 748 | loge("nvReadItem: Empty response"); |
| 749 | } else if (ar.exception instanceof CommandException) { |
| 750 | loge("nvReadItem: CommandException: " + |
| 751 | ar.exception); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 752 | } else { |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 753 | loge("nvReadItem: Unknown exception"); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 754 | } |
| 755 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 756 | notifyRequester(request); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 757 | break; |
| 758 | |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 759 | case CMD_NV_WRITE_ITEM: |
| 760 | request = (MainThreadRequest) msg.obj; |
| 761 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 762 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 763 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 764 | request.workSource); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 765 | break; |
| 766 | |
| 767 | case EVENT_NV_WRITE_ITEM_DONE: |
| 768 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 769 | break; |
| 770 | |
| 771 | case CMD_NV_WRITE_CDMA_PRL: |
| 772 | request = (MainThreadRequest) msg.obj; |
| 773 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 774 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 778 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 779 | break; |
| 780 | |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 781 | case CMD_RESET_MODEM_CONFIG: |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 782 | request = (MainThreadRequest) msg.obj; |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 783 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 784 | defaultPhone.resetModemConfig(onCompleted); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 785 | break; |
| 786 | |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 787 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 788 | handleNullReturnEvent(msg, "resetModemConfig"); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 789 | break; |
| 790 | |
| Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 791 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 792 | request = (MainThreadRequest) msg.obj; |
| 793 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 794 | request); |
| 795 | Phone phone = getPhoneFromRequest(request); |
| 796 | if (phone != null) { |
| 797 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 798 | } else { |
| 799 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 800 | request.result = false; |
| 801 | notifyRequester(request); |
| 802 | } |
| 803 | break; |
| 804 | } |
| 805 | |
| 806 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 807 | ar = (AsyncResult) msg.obj; |
| 808 | request = (MainThreadRequest) ar.userObj; |
| 809 | if (ar.exception == null && ar.result != null) { |
| 810 | request.result = ar.result; |
| 811 | } else { |
| 812 | // request.result must be set to something non-null |
| 813 | // for the calling thread to unblock |
| 814 | if (request.result != null) { |
| 815 | request.result = ar.result; |
| 816 | } else { |
| 817 | request.result = false; |
| 818 | } |
| 819 | if (ar.result == null) { |
| 820 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 821 | } else if (ar.exception instanceof CommandException) { |
| 822 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 823 | + ar.exception); |
| 824 | } else { |
| 825 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 826 | } |
| 827 | } |
| 828 | notifyRequester(request); |
| 829 | break; |
| 830 | |
| 831 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 832 | request = (MainThreadRequest) msg.obj; |
| 833 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 834 | Phone phone = getPhoneFromRequest(request); |
| 835 | if (phone != null) { |
| 836 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 837 | request.workSource); |
| 838 | } else { |
| 839 | loge("enableNrDualConnectivity: No phone object"); |
| 840 | request.result = |
| 841 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 842 | notifyRequester(request); |
| 843 | } |
| 844 | break; |
| 845 | } |
| 846 | |
| 847 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 848 | ar = (AsyncResult) msg.obj; |
| 849 | request = (MainThreadRequest) ar.userObj; |
| 850 | if (ar.exception == null) { |
| 851 | request.result = |
| 852 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 853 | } else { |
| 854 | request.result = |
| 855 | TelephonyManager |
| 856 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 857 | if (ar.exception instanceof CommandException) { |
| 858 | CommandException.Error error = |
| 859 | ((CommandException) (ar.exception)).getCommandError(); |
| 860 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 861 | request.result = |
| 862 | TelephonyManager |
| 863 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame^] | 864 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 865 | request.result = |
| 866 | TelephonyManager |
| 867 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 868 | } |
| 869 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 870 | + ar.exception); |
| 871 | } else { |
| 872 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 873 | } |
| 874 | } |
| 875 | notifyRequester(request); |
| 876 | break; |
| 877 | } |
| 878 | |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 879 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 880 | request = (MainThreadRequest) msg.obj; |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 881 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 882 | request); |
| 883 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 884 | break; |
| 885 | |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 886 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 887 | ar = (AsyncResult) msg.obj; |
| 888 | request = (MainThreadRequest) ar.userObj; |
| 889 | if (ar.exception == null && ar.result != null) { |
| 890 | request.result = ar.result; // Integer |
| 891 | } else { |
| Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 892 | // request.result must be set to something non-null |
| 893 | // for the calling thread to unblock |
| 894 | request.result = new int[]{-1}; |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 895 | if (ar.result == null) { |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 896 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 897 | } else if (ar.exception instanceof CommandException) { |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 898 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 899 | + ar.exception); |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 900 | } else { |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 901 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 902 | } |
| 903 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 904 | notifyRequester(request); |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 905 | break; |
| 906 | |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 907 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 908 | request = (MainThreadRequest) msg.obj; |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 909 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 910 | request); |
| 911 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 912 | (Pair<Integer, Long>) request.argument; |
| 913 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 914 | reasonWithNetworkTypes.first, |
| 915 | reasonWithNetworkTypes.second, |
| 916 | onCompleted); |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 917 | break; |
| 918 | |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 919 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 920 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 921 | break; |
| 922 | |
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 923 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 924 | request = (MainThreadRequest)msg.obj; |
| 925 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 926 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 927 | break; |
| 928 | |
| 929 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 930 | ar = (AsyncResult)msg.obj; |
| 931 | request = (MainThreadRequest)ar.userObj; |
| 932 | request.result = ar; |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 933 | notifyRequester(request); |
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 934 | break; |
| 935 | |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 936 | case CMD_SET_VOICEMAIL_NUMBER: |
| 937 | request = (MainThreadRequest) msg.obj; |
| 938 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 939 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 940 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 941 | onCompleted); |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 942 | break; |
| 943 | |
| 944 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 945 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 946 | break; |
| 947 | |
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 948 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 949 | request = (MainThreadRequest) msg.obj; |
| 950 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 951 | request); |
| 952 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 953 | break; |
| 954 | |
| 955 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 956 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 957 | break; |
| 958 | |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 959 | case CMD_PERFORM_NETWORK_SCAN: |
| 960 | request = (MainThreadRequest) msg.obj; |
| 961 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 962 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 963 | break; |
| 964 | |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 965 | case CMD_GET_CALL_FORWARDING: { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 966 | request = (MainThreadRequest) msg.obj; |
| 967 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 968 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 969 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 970 | request.argument; |
| 971 | int callForwardingReason = args.first; |
| 972 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 973 | break; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 974 | } |
| 975 | case EVENT_GET_CALL_FORWARDING_DONE: { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 976 | ar = (AsyncResult) msg.obj; |
| 977 | request = (MainThreadRequest) ar.userObj; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 978 | TelephonyManager.CallForwardingInfoCallback callback = |
| 979 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 980 | request.argument).second; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 981 | if (ar.exception == null && ar.result != null) { |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 982 | CallForwardingInfo callForwardingInfo = null; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 983 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 984 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 985 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 986 | // any service for voice call. |
| 987 | if ((callForwardInfo.serviceClass |
| 988 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 989 | callForwardingInfo = new CallForwardingInfo(true, |
| 990 | callForwardInfo.reason, |
| 991 | callForwardInfo.number, |
| 992 | callForwardInfo.timeSeconds); |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 993 | break; |
| 994 | } |
| 995 | } |
| 996 | // Didn't find a call forward info for voice call. |
| 997 | if (callForwardingInfo == null) { |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 998 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 999 | 0 /* reason */, null /* number */, 0 /* timeout */); |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1000 | } |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1001 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1002 | } else { |
| 1003 | if (ar.result == null) { |
| 1004 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1005 | } |
| 1006 | if (ar.exception != null) { |
| 1007 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1008 | } |
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1009 | int errorCode = TelephonyManager |
| 1010 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1011 | if (ar.exception instanceof CommandException) { |
| 1012 | CommandException.Error error = |
| 1013 | ((CommandException) (ar.exception)).getCommandError(); |
| 1014 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1015 | errorCode = TelephonyManager |
| 1016 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1017 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1018 | errorCode = TelephonyManager |
| 1019 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1020 | } |
| 1021 | } |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1022 | callback.onError(errorCode); |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1023 | } |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1024 | break; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1025 | } |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1026 | |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1027 | case CMD_SET_CALL_FORWARDING: { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1028 | request = (MainThreadRequest) msg.obj; |
| 1029 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1030 | request = (MainThreadRequest) msg.obj; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1031 | CallForwardingInfo callForwardingInfoToSet = |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1032 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1033 | request.argument).first; |
| 1034 | request.phone.setCallForwardingOption( |
| 1035 | callForwardingInfoToSet.isEnabled() |
| 1036 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1037 | : CommandsInterface.CF_ACTION_DISABLE, |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1038 | callForwardingInfoToSet.getReason(), |
| 1039 | callForwardingInfoToSet.getNumber(), |
| 1040 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1041 | break; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1042 | } |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1043 | |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1044 | case EVENT_SET_CALL_FORWARDING_DONE: { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1045 | ar = (AsyncResult) msg.obj; |
| 1046 | request = (MainThreadRequest) ar.userObj; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1047 | Consumer<Integer> callback = |
| 1048 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1049 | request.argument).second; |
| 1050 | if (ar.exception != null) { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1051 | loge("setCallForwarding exception: " + ar.exception); |
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1052 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1053 | .RESULT_ERROR_UNKNOWN; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1054 | if (ar.exception instanceof CommandException) { |
| 1055 | CommandException.Error error = |
| 1056 | ((CommandException) (ar.exception)).getCommandError(); |
| 1057 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1058 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1059 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1060 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1061 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1062 | .RESULT_ERROR_NOT_SUPPORTED; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1063 | } |
| 1064 | } |
| 1065 | callback.accept(errorCode); |
| 1066 | } else { |
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1067 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1068 | } |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1069 | break; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1070 | } |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1071 | |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1072 | case CMD_GET_CALL_WAITING: { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1073 | request = (MainThreadRequest) msg.obj; |
| 1074 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1075 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1076 | break; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1077 | } |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1078 | |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1079 | case EVENT_GET_CALL_WAITING_DONE: { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1080 | ar = (AsyncResult) msg.obj; |
| 1081 | request = (MainThreadRequest) ar.userObj; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1082 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1083 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1084 | if (ar.exception == null && ar.result != null) { |
| Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1085 | int[] callForwardResults = (int[]) ar.result; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1086 | // Service Class is a bit mask per 3gpp 27.007. |
| 1087 | // Search for any service for voice call. |
| Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1088 | if (callForwardResults.length > 1 |
| 1089 | && ((callForwardResults[1] |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1090 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
| Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1091 | callForwardingStatus = callForwardResults[0] == 0 |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1092 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1093 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1094 | } else { |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1095 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1096 | } |
| 1097 | } else { |
| 1098 | if (ar.result == null) { |
| 1099 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1100 | } |
| 1101 | if (ar.exception != null) { |
| 1102 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1103 | } |
| 1104 | if (ar.exception instanceof CommandException) { |
| 1105 | CommandException.Error error = |
| 1106 | ((CommandException) (ar.exception)).getCommandError(); |
| 1107 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1108 | callForwardingStatus = |
| 1109 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1110 | } |
| 1111 | } |
| 1112 | } |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1113 | callback.accept(callForwardingStatus); |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1114 | break; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1115 | } |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1116 | |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1117 | case CMD_SET_CALL_WAITING: { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1118 | request = (MainThreadRequest) msg.obj; |
| 1119 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1120 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1121 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1122 | break; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1123 | } |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1124 | |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1125 | case EVENT_SET_CALL_WAITING_DONE: { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1126 | ar = (AsyncResult) msg.obj; |
| 1127 | request = (MainThreadRequest) ar.userObj; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1128 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1129 | Consumer<Integer> callback = |
| 1130 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1131 | if (ar.exception != null) { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1132 | loge("setCallWaiting exception: " + ar.exception); |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1133 | if (ar.exception instanceof CommandException) { |
| 1134 | CommandException.Error error = |
| 1135 | ((CommandException) (ar.exception)).getCommandError(); |
| 1136 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1137 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1138 | } else { |
| 1139 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1140 | } |
| 1141 | } else { |
| 1142 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1143 | } |
| 1144 | } else { |
| 1145 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1146 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1147 | } |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1148 | break; |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1149 | } |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1150 | |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1151 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1152 | ar = (AsyncResult) msg.obj; |
| 1153 | request = (MainThreadRequest) ar.userObj; |
| 1154 | CellNetworkScanResult cellScanResult; |
| 1155 | if (ar.exception == null && ar.result != null) { |
| 1156 | cellScanResult = new CellNetworkScanResult( |
| 1157 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1158 | (List<OperatorInfo>) ar.result); |
| 1159 | } else { |
| 1160 | if (ar.result == null) { |
| 1161 | loge("getCellNetworkScanResults: Empty response"); |
| 1162 | } |
| 1163 | if (ar.exception != null) { |
| 1164 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1165 | } |
| 1166 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1167 | if (ar.exception instanceof CommandException) { |
| 1168 | CommandException.Error error = |
| 1169 | ((CommandException) (ar.exception)).getCommandError(); |
| 1170 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1171 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1172 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1173 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1174 | } |
| 1175 | } |
| 1176 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1177 | } |
| 1178 | request.result = cellScanResult; |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1179 | notifyRequester(request); |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1180 | break; |
| 1181 | |
| 1182 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1183 | request = (MainThreadRequest) msg.obj; |
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1184 | ManualNetworkSelectionArgument selArg = |
| 1185 | (ManualNetworkSelectionArgument) request.argument; |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1186 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1187 | request); |
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1188 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1189 | selArg.persistSelection, onCompleted); |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1190 | break; |
| 1191 | |
| 1192 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
| Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1193 | ar = (AsyncResult) msg.obj; |
| 1194 | request = (MainThreadRequest) ar.userObj; |
| 1195 | if (ar.exception == null) { |
| 1196 | request.result = true; |
| 1197 | } else { |
| 1198 | request.result = false; |
| 1199 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1200 | } |
| 1201 | notifyRequester(request); |
| 1202 | mApp.onNetworkSelectionChanged(request.subId); |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1203 | break; |
| 1204 | |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1205 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1206 | request = (MainThreadRequest) msg.obj; |
| 1207 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
| James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1208 | if (defaultPhone != null) { |
| 1209 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1210 | } else { |
| 1211 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1212 | Bundle bundle = new Bundle(); |
| 1213 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1214 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1215 | result.send(0, bundle); |
| James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1216 | } |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1217 | break; |
| 1218 | |
| 1219 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1220 | ar = (AsyncResult) msg.obj; |
| 1221 | request = (MainThreadRequest) ar.userObj; |
| sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1222 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1223 | |
| 1224 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1225 | if (ar.exception == null && ar.result != null) { |
| sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1226 | // Update the last modem activity info and the result of the request. |
| 1227 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1228 | if (isModemActivityInfoValid(info)) { |
| 1229 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1230 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1231 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1232 | .getTransmitTimeMillis(); |
| 1233 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1234 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1235 | } |
| 1236 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1237 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1238 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1239 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1240 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1241 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1242 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1243 | info.getReceiveTimeMillis() |
| 1244 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1245 | } |
| 1246 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1247 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1248 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1249 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1250 | mLastModemActivityInfo.getReceiveTimeMillis()); |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1251 | } else { |
| 1252 | if (ar.result == null) { |
| 1253 | loge("queryModemActivityInfo: Empty response"); |
| 1254 | } else if (ar.exception instanceof CommandException) { |
| 1255 | loge("queryModemActivityInfo: CommandException: " + |
| 1256 | ar.exception); |
| 1257 | } else { |
| 1258 | loge("queryModemActivityInfo: Unknown exception"); |
| 1259 | } |
| 1260 | } |
| sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1261 | Bundle bundle = new Bundle(); |
| 1262 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1263 | result.send(0, bundle); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1264 | notifyRequester(request); |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1265 | break; |
| 1266 | |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1267 | case CMD_SET_ALLOWED_CARRIERS: |
| 1268 | request = (MainThreadRequest) msg.obj; |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1269 | CarrierRestrictionRules argument = |
| 1270 | (CarrierRestrictionRules) request.argument; |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1271 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1272 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1273 | break; |
| 1274 | |
| 1275 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1276 | ar = (AsyncResult) msg.obj; |
| 1277 | request = (MainThreadRequest) ar.userObj; |
| 1278 | if (ar.exception == null && ar.result != null) { |
| 1279 | request.result = ar.result; |
| 1280 | } else { |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1281 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1282 | if (ar.exception instanceof CommandException) { |
| 1283 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1284 | CommandException.Error error = |
| 1285 | ((CommandException) (ar.exception)).getCommandError(); |
| 1286 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1287 | request.result = |
| 1288 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1289 | } |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1290 | } else { |
| 1291 | loge("setAllowedCarriers: Unknown exception"); |
| 1292 | } |
| 1293 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1294 | notifyRequester(request); |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1295 | break; |
| 1296 | |
| 1297 | case CMD_GET_ALLOWED_CARRIERS: |
| 1298 | request = (MainThreadRequest) msg.obj; |
| 1299 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1300 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1301 | break; |
| 1302 | |
| 1303 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1304 | ar = (AsyncResult) msg.obj; |
| 1305 | request = (MainThreadRequest) ar.userObj; |
| 1306 | if (ar.exception == null && ar.result != null) { |
| 1307 | request.result = ar.result; |
| 1308 | } else { |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1309 | request.result = new IllegalStateException( |
| 1310 | "Failed to get carrier restrictions"); |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1311 | if (ar.result == null) { |
| 1312 | loge("getAllowedCarriers: Empty response"); |
| 1313 | } else if (ar.exception instanceof CommandException) { |
| 1314 | loge("getAllowedCarriers: CommandException: " + |
| 1315 | ar.exception); |
| 1316 | } else { |
| 1317 | loge("getAllowedCarriers: Unknown exception"); |
| 1318 | } |
| 1319 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1320 | notifyRequester(request); |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1321 | break; |
| 1322 | |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1323 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1324 | ar = (AsyncResult) msg.obj; |
| 1325 | request = (MainThreadRequest) ar.userObj; |
| 1326 | if (ar.exception == null && ar.result != null) { |
| 1327 | request.result = ar.result; |
| 1328 | } else { |
| 1329 | request.result = new IllegalArgumentException( |
| 1330 | "Failed to retrieve Forbidden Plmns"); |
| 1331 | if (ar.result == null) { |
| 1332 | loge("getForbiddenPlmns: Empty response"); |
| 1333 | } else { |
| 1334 | loge("getForbiddenPlmns: Unknown exception"); |
| 1335 | } |
| 1336 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1337 | notifyRequester(request); |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1338 | break; |
| 1339 | |
| 1340 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1341 | request = (MainThreadRequest) msg.obj; |
| 1342 | uiccCard = getUiccCardFromRequest(request); |
| 1343 | if (uiccCard == null) { |
| 1344 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1345 | request.result = new IllegalArgumentException( |
| 1346 | "getForbiddenPlmns() UiccCard is null"); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1347 | notifyRequester(request); |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1348 | break; |
| 1349 | } |
| 1350 | Integer appType = (Integer) request.argument; |
| 1351 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1352 | if (uiccApp == null) { |
| 1353 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1354 | + appType); |
| 1355 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1356 | notifyRequester(request); |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1357 | break; |
| 1358 | } else { |
| 1359 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1360 | + " specified type -- " + appType); |
| 1361 | } |
| 1362 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1363 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1364 | onCompleted); |
| 1365 | break; |
| 1366 | |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1367 | case CMD_SWITCH_SLOTS: |
| 1368 | request = (MainThreadRequest) msg.obj; |
| 1369 | int[] physicalSlots = (int[]) request.argument; |
| 1370 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1371 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1372 | break; |
| 1373 | |
| 1374 | case EVENT_SWITCH_SLOTS_DONE: |
| 1375 | ar = (AsyncResult) msg.obj; |
| 1376 | request = (MainThreadRequest) ar.userObj; |
| 1377 | request.result = (ar.exception == null); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1378 | notifyRequester(request); |
| 1379 | break; |
| 1380 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1381 | request = (MainThreadRequest) msg.obj; |
| 1382 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1383 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1384 | break; |
| 1385 | |
| 1386 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1387 | ar = (AsyncResult) msg.obj; |
| 1388 | request = (MainThreadRequest) ar.userObj; |
| 1389 | if (ar.exception != null) { |
| 1390 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1391 | } else { |
| 1392 | int mode = ((int[]) ar.result)[0]; |
| 1393 | if (mode == 0) { |
| 1394 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1395 | } else { |
| 1396 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1397 | } |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1398 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1399 | notifyRequester(request); |
| 1400 | break; |
| 1401 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1402 | request = (MainThreadRequest) msg.obj; |
| 1403 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1404 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1405 | break; |
| 1406 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1407 | ar = (AsyncResult) msg.obj; |
| 1408 | request = (MainThreadRequest) ar.userObj; |
| 1409 | if (ar.exception != null) { |
| 1410 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1411 | } else { |
| 1412 | request.result = ((int[]) ar.result)[0]; |
| 1413 | } |
| 1414 | notifyRequester(request); |
| 1415 | break; |
| 1416 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1417 | request = (MainThreadRequest) msg.obj; |
| 1418 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1419 | int mode = (int) request.argument; |
| 1420 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1421 | break; |
| 1422 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1423 | ar = (AsyncResult) msg.obj; |
| 1424 | request = (MainThreadRequest) ar.userObj; |
| 1425 | request.result = ar.exception == null; |
| 1426 | notifyRequester(request); |
| 1427 | break; |
| Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1428 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1429 | request = (MainThreadRequest) msg.obj; |
| 1430 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1431 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1432 | break; |
| 1433 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1434 | ar = (AsyncResult) msg.obj; |
| 1435 | request = (MainThreadRequest) ar.userObj; |
| 1436 | if (ar.exception != null) { |
| 1437 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1438 | } else { |
| 1439 | request.result = ((int[]) ar.result)[0]; |
| 1440 | } |
| 1441 | notifyRequester(request); |
| 1442 | break; |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1443 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1444 | request = (MainThreadRequest) msg.obj; |
| 1445 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1446 | int subscriptionMode = (int) request.argument; |
| Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1447 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1448 | subscriptionMode, onCompleted); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1449 | break; |
| 1450 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1451 | ar = (AsyncResult) msg.obj; |
| 1452 | request = (MainThreadRequest) ar.userObj; |
| 1453 | request.result = ar.exception == null; |
| 1454 | notifyRequester(request); |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1455 | break; |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1456 | case CMD_GET_ALL_CELL_INFO: |
| 1457 | request = (MainThreadRequest) msg.obj; |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1458 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1459 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1460 | break; |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1461 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1462 | ar = (AsyncResult) msg.obj; |
| 1463 | request = (MainThreadRequest) ar.userObj; |
| Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1464 | // If a timeout occurs, the response will be null |
| 1465 | request.result = (ar.exception == null && ar.result != null) |
| 1466 | ? ar.result : new ArrayList<CellInfo>(); |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1467 | synchronized (request) { |
| 1468 | request.notifyAll(); |
| 1469 | } |
| 1470 | break; |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1471 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1472 | request = (MainThreadRequest) msg.obj; |
| 1473 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1474 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1475 | break; |
| 1476 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1477 | ar = (AsyncResult) msg.obj; |
| 1478 | request = (MainThreadRequest) ar.userObj; |
| 1479 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1480 | try { |
| 1481 | if (ar.exception != null) { |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1482 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
| Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1483 | cb.onError( |
| 1484 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1485 | ar.exception.getClass().getName(), |
| 1486 | ar.exception.toString()); |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1487 | } else if (ar.result == null) { |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1488 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
| Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1489 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1490 | } else { |
| 1491 | // use the result as returned |
| 1492 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1493 | } |
| 1494 | } catch (RemoteException re) { |
| 1495 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1496 | } |
| 1497 | break; |
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1498 | case CMD_GET_CELL_LOCATION: { |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1499 | request = (MainThreadRequest) msg.obj; |
| 1500 | WorkSource ws = (WorkSource) request.argument; |
| 1501 | Phone phone = getPhoneFromRequest(request); |
| Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1502 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1503 | break; |
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1504 | } |
| 1505 | case EVENT_GET_CELL_LOCATION_DONE: { |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1506 | ar = (AsyncResult) msg.obj; |
| 1507 | request = (MainThreadRequest) ar.userObj; |
| 1508 | if (ar.exception == null) { |
| 1509 | request.result = ar.result; |
| 1510 | } else { |
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1511 | Phone phone = getPhoneFromRequest(request); |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1512 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1513 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | synchronized (request) { |
| 1517 | request.notifyAll(); |
| 1518 | } |
| 1519 | break; |
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1520 | } |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1521 | case CMD_MODEM_REBOOT: |
| 1522 | request = (MainThreadRequest) msg.obj; |
| 1523 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1524 | defaultPhone.rebootModem(onCompleted); |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1525 | break; |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1526 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1527 | handleNullReturnEvent(msg, "rebootModem"); |
| 1528 | break; |
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1529 | case CMD_REQUEST_ENABLE_MODEM: |
| 1530 | request = (MainThreadRequest) msg.obj; |
| 1531 | boolean enable = (boolean) request.argument; |
| 1532 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
| Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1533 | onCompleted.arg1 = enable ? 1 : 0; |
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1534 | PhoneConfigurationManager.getInstance() |
| 1535 | .enablePhone(request.phone, enable, onCompleted); |
| 1536 | break; |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1537 | case EVENT_ENABLE_MODEM_DONE: { |
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1538 | ar = (AsyncResult) msg.obj; |
| 1539 | request = (MainThreadRequest) ar.userObj; |
| 1540 | request.result = (ar.exception == null); |
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1541 | int phoneId = request.phone.getPhoneId(); |
| Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1542 | //update the cache as modem status has changed |
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1543 | if ((boolean) request.result) { |
| 1544 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1545 | updateModemStateMetrics(); |
| 1546 | } else { |
| 1547 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1548 | + ar.exception); |
| 1549 | } |
| 1550 | notifyRequester(request); |
| 1551 | break; |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1552 | } |
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1553 | case CMD_GET_MODEM_STATUS: |
| 1554 | request = (MainThreadRequest) msg.obj; |
| 1555 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1556 | PhoneConfigurationManager.getInstance() |
| 1557 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1558 | break; |
| 1559 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1560 | ar = (AsyncResult) msg.obj; |
| 1561 | request = (MainThreadRequest) ar.userObj; |
| 1562 | int id = request.phone.getPhoneId(); |
| 1563 | if (ar.exception == null && ar.result != null) { |
| 1564 | request.result = ar.result; |
| 1565 | //update the cache as modem status has changed |
| 1566 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1567 | (boolean) request.result); |
| 1568 | } else { |
| 1569 | // Return true if modem status cannot be retrieved. For most cases, |
| 1570 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1571 | // and disable modem are not supported. Modem is always on. |
| 1572 | // TODO: this should be fixed in R to support a third |
| 1573 | // status UNKNOWN b/131631629 |
| 1574 | request.result = true; |
| 1575 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1576 | + ar.exception); |
| 1577 | } |
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1578 | notifyRequester(request); |
| 1579 | break; |
| Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1580 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1581 | request = (MainThreadRequest) msg.obj; |
| 1582 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1583 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1584 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1585 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1586 | break; |
| 1587 | } |
| 1588 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1589 | ar = (AsyncResult) msg.obj; |
| 1590 | request = (MainThreadRequest) ar.userObj; |
| 1591 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1592 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1593 | args.second.accept(ar.exception == null); |
| 1594 | notifyRequester(request); |
| 1595 | break; |
| 1596 | } |
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1597 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1598 | request = (MainThreadRequest) msg.obj; |
| 1599 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1600 | Phone phone = getPhoneFromRequest(request); |
| 1601 | if (phone != null) { |
| 1602 | phone.getSystemSelectionChannels(onCompleted); |
| 1603 | } else { |
| 1604 | loge("getSystemSelectionChannels: No phone object"); |
| 1605 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1606 | notifyRequester(request); |
| 1607 | } |
| 1608 | break; |
| 1609 | } |
| 1610 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1611 | ar = (AsyncResult) msg.obj; |
| 1612 | request = (MainThreadRequest) ar.userObj; |
| 1613 | if (ar.exception == null && ar.result != null) { |
| 1614 | request.result = ar.result; |
| 1615 | } else { |
| 1616 | request.result = new IllegalArgumentException( |
| 1617 | "Failed to retrieve system selection channels"); |
| 1618 | if (ar.result == null) { |
| 1619 | loge("getSystemSelectionChannels: Empty response"); |
| 1620 | } else { |
| 1621 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1622 | } |
| 1623 | } |
| 1624 | notifyRequester(request); |
| 1625 | break; |
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1626 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1627 | ar = (AsyncResult) msg.obj; |
| 1628 | request = (MainThreadRequest) ar.userObj; |
| 1629 | if (ar.exception == null && ar.result != null) { |
| 1630 | request.result = ar.result; |
| 1631 | } else { |
| 1632 | request.result = -1; |
| 1633 | loge("Failed to set Forbidden Plmns"); |
| 1634 | if (ar.result == null) { |
| 1635 | loge("setForbidenPlmns: Empty response"); |
| 1636 | } else if (ar.exception != null) { |
| 1637 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1638 | request.result = -1; |
| 1639 | } else { |
| 1640 | loge("setForbiddenPlmns: Unknown exception"); |
| 1641 | } |
| 1642 | } |
| 1643 | notifyRequester(request); |
| 1644 | break; |
| 1645 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1646 | request = (MainThreadRequest) msg.obj; |
| 1647 | uiccCard = getUiccCardFromRequest(request); |
| 1648 | if (uiccCard == null) { |
| 1649 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1650 | request.result = -1; |
| 1651 | notifyRequester(request); |
| 1652 | break; |
| 1653 | } |
| 1654 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1655 | (Pair<Integer, List<String>>) request.argument; |
| 1656 | appType = setFplmnsArgs.first; |
| 1657 | List<String> fplmns = setFplmnsArgs.second; |
| 1658 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1659 | if (uiccApp == null) { |
| 1660 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1661 | request.result = -1; |
| 1662 | loge("Failed to get UICC App"); |
| 1663 | notifyRequester(request); |
| 1664 | } else { |
| 1665 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1666 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1667 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1668 | } |
| yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1669 | break; |
| Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1670 | case CMD_ERASE_MODEM_CONFIG: |
| 1671 | request = (MainThreadRequest) msg.obj; |
| 1672 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1673 | defaultPhone.eraseModemConfig(onCompleted); |
| 1674 | break; |
| 1675 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1676 | handleNullReturnEvent(msg, "eraseModemConfig"); |
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1677 | break; |
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1678 | |
| 1679 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1680 | request = (MainThreadRequest) msg.obj; |
| 1681 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1682 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1683 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1684 | changed.first, changed.second, onCompleted); |
| 1685 | break; |
| 1686 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1687 | ar = (AsyncResult) msg.obj; |
| 1688 | request = (MainThreadRequest) ar.userObj; |
| 1689 | if (ar.exception == null) { |
| 1690 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1691 | // If the operation is successful, update the PIN storage |
| 1692 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1693 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1694 | UiccController.getInstance().getPinStorage() |
| 1695 | .storePin(passwords.second, phoneId); |
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1696 | } else { |
| 1697 | request.result = msg.arg1; |
| 1698 | } |
| 1699 | notifyRequester(request); |
| 1700 | break; |
| 1701 | |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1702 | case CMD_SET_ICC_LOCK_ENABLED: { |
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1703 | request = (MainThreadRequest) msg.obj; |
| 1704 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1705 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1706 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1707 | enabled.first, enabled.second, onCompleted); |
| 1708 | break; |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1709 | } |
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1710 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1711 | ar = (AsyncResult) msg.obj; |
| 1712 | request = (MainThreadRequest) ar.userObj; |
| 1713 | if (ar.exception == null) { |
| 1714 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1715 | // If the operation is successful, update the PIN storage |
| 1716 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1717 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1718 | if (enabled.first) { |
| 1719 | UiccController.getInstance().getPinStorage() |
| 1720 | .storePin(enabled.second, phoneId); |
| 1721 | } else { |
| 1722 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1723 | } |
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1724 | } else { |
| 1725 | request.result = msg.arg1; |
| 1726 | } |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1727 | |
| 1728 | |
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1729 | notifyRequester(request); |
| 1730 | break; |
| 1731 | |
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1732 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1733 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
| Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1734 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1735 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1736 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1737 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1738 | break; |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1739 | |
| 1740 | case CMD_SET_DATA_THROTTLING: { |
| 1741 | request = (MainThreadRequest) msg.obj; |
| 1742 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1743 | DataThrottlingRequest dataThrottlingRequest = |
| 1744 | (DataThrottlingRequest) request.argument; |
| 1745 | Phone phone = getPhoneFromRequest(request); |
| 1746 | if (phone != null) { |
| 1747 | phone.setDataThrottling(onCompleted, |
| 1748 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1749 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1750 | } else { |
| 1751 | loge("setDataThrottling: No phone object"); |
| 1752 | request.result = |
| 1753 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1754 | notifyRequester(request); |
| 1755 | } |
| 1756 | |
| 1757 | break; |
| 1758 | } |
| 1759 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1760 | ar = (AsyncResult) msg.obj; |
| 1761 | request = (MainThreadRequest) ar.userObj; |
| 1762 | |
| 1763 | if (ar.exception == null) { |
| 1764 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1765 | } else if (ar.exception instanceof CommandException) { |
| 1766 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1767 | CommandException.Error error = |
| 1768 | ((CommandException) (ar.exception)).getCommandError(); |
| 1769 | |
| 1770 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1771 | request.result = TelephonyManager |
| 1772 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1773 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1774 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1775 | } else { |
| 1776 | request.result = |
| 1777 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1778 | } |
| 1779 | } else { |
| 1780 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1781 | } |
| 1782 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1783 | notifyRequester(request); |
| 1784 | break; |
| Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1785 | |
| 1786 | case CMD_SET_SIM_POWER: { |
| 1787 | request = (MainThreadRequest) msg.obj; |
| 1788 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1789 | request = (MainThreadRequest) msg.obj; |
| 1790 | int stateToSet = |
| 1791 | ((Pair<Integer, IIntegerConsumer>) |
| 1792 | request.argument).first; |
| 1793 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1794 | break; |
| 1795 | } |
| 1796 | case EVENT_SET_SIM_POWER_DONE: { |
| 1797 | ar = (AsyncResult) msg.obj; |
| 1798 | request = (MainThreadRequest) ar.userObj; |
| 1799 | IIntegerConsumer callback = |
| 1800 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1801 | if (ar.exception != null) { |
| 1802 | loge("setSimPower exception: " + ar.exception); |
| 1803 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1804 | .RESULT_ERROR_UNKNOWN; |
| 1805 | if (ar.exception instanceof CommandException) { |
| 1806 | CommandException.Error error = |
| 1807 | ((CommandException) (ar.exception)).getCommandError(); |
| 1808 | if (error == CommandException.Error.SIM_ERR) { |
| 1809 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1810 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1811 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1812 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1813 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1814 | } else { |
| 1815 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1816 | } |
| 1817 | } |
| 1818 | try { |
| 1819 | callback.accept(errorCode); |
| 1820 | } catch (RemoteException e) { |
| 1821 | // Ignore if the remote process is no longer available to call back. |
| 1822 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1823 | } |
| 1824 | } else { |
| 1825 | try { |
| 1826 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1827 | } catch (RemoteException e) { |
| 1828 | // Ignore if the remote process is no longer available to call back. |
| 1829 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1830 | } |
| 1831 | } |
| 1832 | break; |
| 1833 | } |
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1834 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1835 | request = (MainThreadRequest) msg.obj; |
| 1836 | |
| 1837 | final Phone phone = getPhoneFromRequest(request); |
| 1838 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1839 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1840 | notifyRequester(request); |
| 1841 | break; |
| 1842 | } |
| 1843 | |
| 1844 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1845 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1846 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1847 | request); |
| 1848 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1849 | request.subId, pair.first /*callingUid*/, |
| 1850 | pair.second /*request*/, onCompleted); |
| 1851 | break; |
| 1852 | } |
| 1853 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1854 | ar = (AsyncResult) msg.obj; |
| 1855 | request = (MainThreadRequest) ar.userObj; |
| 1856 | // request.result will be the exception of ar if present, true otherwise. |
| 1857 | // Be cautious not to leave result null which will wait() forever |
| 1858 | request.result = ar.exception != null ? ar.exception : true; |
| 1859 | notifyRequester(request); |
| 1860 | break; |
| 1861 | } |
| 1862 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1863 | request = (MainThreadRequest) msg.obj; |
| 1864 | |
| 1865 | Phone phone = getPhoneFromRequest(request); |
| 1866 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1867 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1868 | notifyRequester(request); |
| 1869 | break; |
| 1870 | } |
| 1871 | |
| 1872 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1873 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1874 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1875 | request); |
| 1876 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1877 | request.subId, pair.first /*callingUid*/, |
| 1878 | pair.second /*request*/, onCompleted); |
| 1879 | break; |
| 1880 | } |
| 1881 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1882 | ar = (AsyncResult) msg.obj; |
| 1883 | request = (MainThreadRequest) ar.userObj; |
| 1884 | request.result = ar.exception != null ? ar.exception : true; |
| 1885 | notifyRequester(request); |
| 1886 | break; |
| 1887 | } |
| Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1888 | |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1889 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1890 | request = (MainThreadRequest) msg.obj; |
| 1891 | request.result = |
| 1892 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1893 | notifyRequester(request); |
| 1894 | break; |
| 1895 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1896 | default: |
| 1897 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1898 | break; |
| 1899 | } |
| 1900 | } |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1901 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1902 | private void notifyRequester(MainThreadRequest request) { |
| 1903 | synchronized (request) { |
| 1904 | request.notifyAll(); |
| 1905 | } |
| 1906 | } |
| 1907 | |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1908 | private void handleNullReturnEvent(Message msg, String command) { |
| 1909 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1910 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1911 | if (ar.exception == null) { |
| 1912 | request.result = true; |
| 1913 | } else { |
| 1914 | request.result = false; |
| 1915 | if (ar.exception instanceof CommandException) { |
| 1916 | loge(command + ": CommandException: " + ar.exception); |
| 1917 | } else { |
| 1918 | loge(command + ": Unknown exception"); |
| 1919 | } |
| 1920 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1921 | notifyRequester(request); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1922 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | /** |
| 1926 | * Posts the specified command to be executed on the main thread, |
| 1927 | * waits for the request to complete, and returns the result. |
| 1928 | * @see #sendRequestAsync |
| 1929 | */ |
| 1930 | private Object sendRequest(int command, Object argument) { |
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1931 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 1932 | null, -1 /*timeoutInMs*/); |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | /** |
| 1936 | * Posts the specified command to be executed on the main thread, |
| 1937 | * waits for the request to complete, and returns the result. |
| 1938 | * @see #sendRequestAsync |
| 1939 | */ |
| 1940 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1941 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1942 | null, workSource, -1 /*timeoutInMs*/); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | /** |
| 1946 | * Posts the specified command to be executed on the main thread, |
| 1947 | * waits for the request to complete, and returns the result. |
| 1948 | * @see #sendRequestAsync |
| 1949 | */ |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1950 | private Object sendRequest(int command, Object argument, Integer subId) { |
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1951 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 1952 | } |
| 1953 | |
| 1954 | /** |
| 1955 | * Posts the specified command to be executed on the main thread, |
| 1956 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 1957 | * if not timeout or null otherwise. |
| 1958 | * @see #sendRequestAsync |
| 1959 | */ |
| 1960 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 1961 | long timeoutInMs) { |
| 1962 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | /** |
| 1966 | * Posts the specified command to be executed on the main thread, |
| 1967 | * waits for the request to complete, and returns the result. |
| 1968 | * @see #sendRequestAsync |
| 1969 | */ |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1970 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1971 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | /** |
| 1975 | * Posts the specified command to be executed on the main thread, |
| 1976 | * waits for the request to complete, and returns the result. |
| 1977 | * @see #sendRequestAsync |
| 1978 | */ |
| 1979 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1980 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 1981 | workSource, -1 /*timeoutInMs*/); |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | /** |
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1985 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 1986 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 1987 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1988 | * @see #sendRequestAsync |
| 1989 | */ |
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1990 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 1991 | WorkSource workSource, long timeoutInMs) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1992 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1993 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1994 | } |
| 1995 | |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1996 | MainThreadRequest request = null; |
| 1997 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1998 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1999 | } else if (phone != null) { |
| 2000 | request = new MainThreadRequest(argument, phone, workSource); |
| 2001 | } else { |
| 2002 | request = new MainThreadRequest(argument, subId, workSource); |
| 2003 | } |
| 2004 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2005 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2006 | msg.sendToTarget(); |
| 2007 | |
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2008 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2009 | synchronized (request) { |
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2010 | if (timeoutInMs >= 0) { |
| 2011 | // Wait for at least timeoutInMs before returning null request result |
| 2012 | long now = SystemClock.elapsedRealtime(); |
| 2013 | long deadline = now + timeoutInMs; |
| 2014 | while (request == null && now < deadline) { |
| 2015 | try { |
| 2016 | request.wait(deadline - now); |
| 2017 | } catch (InterruptedException e) { |
| 2018 | // Do nothing, go back and check if request is completed or timeout |
| 2019 | } finally { |
| 2020 | now = SystemClock.elapsedRealtime(); |
| 2021 | } |
| 2022 | } |
| 2023 | } else { |
| 2024 | // Wait for the request to complete |
| 2025 | while (request.result == null) { |
| 2026 | try { |
| 2027 | request.wait(); |
| 2028 | } catch (InterruptedException e) { |
| 2029 | // Do nothing, go back and wait until the request is complete |
| 2030 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2031 | } |
| 2032 | } |
| 2033 | } |
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2034 | if (request.result == null) { |
| 2035 | Log.wtf(LOG_TAG, |
| 2036 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2037 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2038 | return request.result; |
| 2039 | } |
| 2040 | |
| 2041 | /** |
| 2042 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2043 | * Posts the specified command to be executed on the main thread, and |
| 2044 | * returns immediately. |
| 2045 | * @see #sendRequest |
| 2046 | */ |
| 2047 | private void sendRequestAsync(int command) { |
| 2048 | mMainThreadHandler.sendEmptyMessage(command); |
| 2049 | } |
| 2050 | |
| 2051 | /** |
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2052 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2053 | * @see {@link #sendRequest(int)} |
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2054 | */ |
| 2055 | private void sendRequestAsync(int command, Object argument) { |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2056 | sendRequestAsync(command, argument, null, null); |
| 2057 | } |
| 2058 | |
| 2059 | /** |
| 2060 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2061 | * @see {@link #sendRequest(int,Object)} |
| 2062 | */ |
| 2063 | private void sendRequestAsync( |
| 2064 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2065 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2066 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2067 | msg.sendToTarget(); |
| 2068 | } |
| 2069 | |
| 2070 | /** |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2071 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2072 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2073 | */ |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2074 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2075 | synchronized (PhoneInterfaceManager.class) { |
| 2076 | if (sInstance == null) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2077 | sInstance = new PhoneInterfaceManager(app); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2078 | } else { |
| 2079 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2080 | } |
| 2081 | return sInstance; |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | /** Private constructor; @see init() */ |
| Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2086 | private PhoneInterfaceManager(PhoneGlobals app) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2087 | mApp = app; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2088 | mCM = PhoneGlobals.getInstance().mCM; |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2089 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2090 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2091 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2092 | mMainThreadHandler = new MainThreadHandler(); |
| Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2093 | mSubscriptionController = SubscriptionController.getInstance(); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2094 | mTelephonySharedPreferences = |
| 2095 | PreferenceManager.getDefaultSharedPreferences(mApp); |
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2096 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2097 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
| Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2098 | mNotifyUserActivity = new AtomicBoolean(false); |
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2099 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2100 | publish(); |
| 2101 | } |
| 2102 | |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2103 | private Phone getDefaultPhone() { |
| 2104 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2105 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2106 | } |
| 2107 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2108 | private void publish() { |
| 2109 | if (DBG) log("publish: " + this); |
| 2110 | |
| Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2111 | TelephonyFrameworkInitializer |
| 2112 | .getTelephonyServiceManager() |
| 2113 | .getTelephonyServiceRegisterer() |
| 2114 | .register(this); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2117 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2118 | if (request.phone != null) { |
| 2119 | return request.phone; |
| 2120 | } else { |
| 2121 | return getPhoneFromSubId(request.subId); |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | private Phone getPhoneFromSubId(int subId) { |
| 2126 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2127 | ? getDefaultPhone() : getPhone(subId); |
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2128 | } |
| 2129 | |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2130 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2131 | Phone phone = getPhoneFromRequest(request); |
| 2132 | return phone == null ? null : |
| 2133 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2134 | } |
| 2135 | |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2136 | // returns phone associated with the subId. |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2137 | private Phone getPhone(int subId) { |
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2138 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2139 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2140 | |
| Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2141 | private void sendEraseModemConfig(Phone phone) { |
| 2142 | if (phone != null) { |
| 2143 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2144 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2145 | final long identity = Binder.clearCallingIdentity(); |
| 2146 | try { |
| 2147 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2148 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2149 | } finally { |
| 2150 | Binder.restoreCallingIdentity(identity); |
| 2151 | } |
| 2152 | } |
| 2153 | } |
| 2154 | |
| Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2155 | private boolean isImsAvailableOnDevice() { |
| 2156 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2157 | if (pm == null) { |
| 2158 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2159 | // so do not throw error and allow. |
| 2160 | return true; |
| 2161 | } |
| 2162 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2163 | } |
| 2164 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2165 | public void dial(String number) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2166 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2169 | public void dialForSubscriber(int subId, String number) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2170 | if (DBG) log("dial: " + number); |
| 2171 | // No permission check needed here: This is just a wrapper around the |
| 2172 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2173 | // the UI before it does anything. |
| 2174 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2175 | final long identity = Binder.clearCallingIdentity(); |
| 2176 | try { |
| 2177 | String url = createTelUrl(number); |
| 2178 | if (url == null) { |
| 2179 | return; |
| 2180 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2181 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2182 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2183 | PhoneConstants.State state = mCM.getState(subId); |
| 2184 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2185 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2186 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2187 | mApp.startActivity(intent); |
| 2188 | } |
| 2189 | } finally { |
| 2190 | Binder.restoreCallingIdentity(identity); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2191 | } |
| 2192 | } |
| 2193 | |
| 2194 | public void call(String callingPackage, String number) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2195 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2198 | public void callForSubscriber(int subId, String callingPackage, String number) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2199 | if (DBG) log("call: " + number); |
| 2200 | |
| 2201 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2202 | // need to do a permission check since we're calling startActivity() |
| 2203 | // from the context of the phone app. |
| 2204 | enforceCallPermission(); |
| 2205 | |
| Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2206 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2207 | != AppOpsManager.MODE_ALLOWED) { |
| 2208 | return; |
| 2209 | } |
| 2210 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2211 | final long identity = Binder.clearCallingIdentity(); |
| 2212 | try { |
| 2213 | String url = createTelUrl(number); |
| 2214 | if (url == null) { |
| 2215 | return; |
| 2216 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2217 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2218 | boolean isValid = false; |
| 2219 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2220 | if (slist != null) { |
| 2221 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2222 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2223 | isValid = true; |
| 2224 | break; |
| 2225 | } |
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2226 | } |
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2227 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2228 | if (!isValid) { |
| 2229 | return; |
| 2230 | } |
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2231 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2232 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2233 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2234 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2235 | mApp.startActivity(intent); |
| 2236 | } finally { |
| 2237 | Binder.restoreCallingIdentity(identity); |
| 2238 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2239 | } |
| 2240 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2241 | public boolean supplyPinForSubscriber(int subId, String pin) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2242 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2243 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2244 | } |
| 2245 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2246 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2247 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2248 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2249 | } |
| 2250 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2251 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2252 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2253 | |
| 2254 | final long identity = Binder.clearCallingIdentity(); |
| 2255 | try { |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2256 | Phone phone = getPhone(subId); |
| 2257 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2258 | checkSimPin.start(); |
| 2259 | return checkSimPin.unlockSim(null, pin); |
| 2260 | } finally { |
| 2261 | Binder.restoreCallingIdentity(identity); |
| 2262 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2265 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2266 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2267 | |
| 2268 | final long identity = Binder.clearCallingIdentity(); |
| 2269 | try { |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2270 | Phone phone = getPhone(subId); |
| 2271 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2272 | checkSimPuk.start(); |
| 2273 | return checkSimPuk.unlockSim(puk, pin); |
| 2274 | } finally { |
| 2275 | Binder.restoreCallingIdentity(identity); |
| 2276 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | /** |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2280 | * Helper thread to turn async call to SimCard#supplyPin into |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2281 | * a synchronous one. |
| 2282 | */ |
| 2283 | private static class UnlockSim extends Thread { |
| 2284 | |
| 2285 | private final IccCard mSimCard; |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2286 | private final int mPhoneId; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2287 | |
| 2288 | private boolean mDone = false; |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2289 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2290 | private int mRetryCount = -1; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2291 | |
| 2292 | // For replies from SimCard interface |
| 2293 | private Handler mHandler; |
| 2294 | |
| 2295 | // For async handler to identify request type |
| 2296 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2297 | |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2298 | UnlockSim(int phoneId, IccCard simCard) { |
| 2299 | mPhoneId = phoneId; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2300 | mSimCard = simCard; |
| 2301 | } |
| 2302 | |
| 2303 | @Override |
| 2304 | public void run() { |
| 2305 | Looper.prepare(); |
| 2306 | synchronized (UnlockSim.this) { |
| 2307 | mHandler = new Handler() { |
| 2308 | @Override |
| 2309 | public void handleMessage(Message msg) { |
| 2310 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2311 | switch (msg.what) { |
| 2312 | case SUPPLY_PIN_COMPLETE: |
| 2313 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2314 | synchronized (UnlockSim.this) { |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2315 | mRetryCount = msg.arg1; |
| 2316 | if (ar.exception != null) { |
| 2317 | if (ar.exception instanceof CommandException && |
| 2318 | ((CommandException)(ar.exception)).getCommandError() |
| 2319 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2320 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2321 | } //When UiccCardApp dispose,handle message and return exception |
| 2322 | else if (ar.exception instanceof CommandException && |
| 2323 | ((CommandException) (ar.exception)).getCommandError() |
| 2324 | == CommandException.Error.ABORTED) { |
| 2325 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2326 | } else { |
| 2327 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2328 | } |
| 2329 | } else { |
| 2330 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2331 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2332 | mDone = true; |
| 2333 | UnlockSim.this.notifyAll(); |
| 2334 | } |
| 2335 | break; |
| 2336 | } |
| 2337 | } |
| 2338 | }; |
| 2339 | UnlockSim.this.notifyAll(); |
| 2340 | } |
| 2341 | Looper.loop(); |
| 2342 | } |
| 2343 | |
| 2344 | /* |
| 2345 | * Use PIN or PUK to unlock SIM card |
| 2346 | * |
| 2347 | * If PUK is null, unlock SIM card with PIN |
| 2348 | * |
| 2349 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2350 | */ |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2351 | synchronized int[] unlockSim(String puk, String pin) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2352 | |
| 2353 | while (mHandler == null) { |
| 2354 | try { |
| 2355 | wait(); |
| 2356 | } catch (InterruptedException e) { |
| 2357 | Thread.currentThread().interrupt(); |
| 2358 | } |
| 2359 | } |
| 2360 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2361 | |
| 2362 | if (puk == null) { |
| 2363 | mSimCard.supplyPin(pin, callback); |
| 2364 | } else { |
| 2365 | mSimCard.supplyPuk(puk, pin, callback); |
| 2366 | } |
| 2367 | |
| 2368 | while (!mDone) { |
| 2369 | try { |
| 2370 | Log.d(LOG_TAG, "wait for done"); |
| 2371 | wait(); |
| 2372 | } catch (InterruptedException e) { |
| 2373 | // Restore the interrupted status |
| 2374 | Thread.currentThread().interrupt(); |
| 2375 | } |
| 2376 | } |
| 2377 | Log.d(LOG_TAG, "done"); |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2378 | int[] resultArray = new int[2]; |
| 2379 | resultArray[0] = mResult; |
| 2380 | resultArray[1] = mRetryCount; |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2381 | |
| 2382 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2383 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2384 | } |
| 2385 | |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2386 | return resultArray; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2387 | } |
| 2388 | } |
| 2389 | |
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2390 | /** |
| 2391 | * This method has been removed due to privacy and stability concerns. |
| 2392 | */ |
| 2393 | @Override |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2394 | public void updateServiceLocation() { |
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2395 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2396 | return; |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2397 | } |
| 2398 | |
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2399 | @Override |
| 2400 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2401 | mApp.getSystemService(AppOpsManager.class) |
| 2402 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2403 | |
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2404 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2405 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2406 | // Callers targeting S have no business invoking this method. |
| 2407 | return; |
| 2408 | } |
| 2409 | |
| 2410 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2411 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2412 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2413 | .setCallingPackage(callingPackage) |
| 2414 | .setCallingFeatureId(null) |
| 2415 | .setCallingPid(Binder.getCallingPid()) |
| 2416 | .setCallingUid(Binder.getCallingUid()) |
| 2417 | .setMethod("updateServiceLocation") |
| 2418 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2419 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2420 | .build()); |
| 2421 | // Apps that lack location permission have no business calling this method; |
| 2422 | // however, because no permission was declared in the public API, denials must |
| 2423 | // all be "soft". |
| 2424 | switch (locationResult) { |
| 2425 | case DENIED_HARD: /* fall through */ |
| 2426 | case DENIED_SOFT: |
| 2427 | return; |
| 2428 | } |
| 2429 | |
| 2430 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2431 | final long identity = Binder.clearCallingIdentity(); |
| 2432 | try { |
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2433 | final Phone phone = getPhone(getDefaultSubscription()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2434 | if (phone != null) { |
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2435 | phone.updateServiceLocation(workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2436 | } |
| 2437 | } finally { |
| 2438 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2439 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2442 | @Deprecated |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2443 | @Override |
| 2444 | public boolean isRadioOn(String callingPackage) { |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2445 | return isRadioOnWithFeature(callingPackage, null); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2446 | } |
| 2447 | |
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2448 | |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2449 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2450 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2451 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2452 | callingFeatureId); |
| 2453 | } |
| 2454 | |
| 2455 | @Deprecated |
| 2456 | @Override |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2457 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2458 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2459 | } |
| 2460 | |
| 2461 | @Override |
| 2462 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2463 | String callingFeatureId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2464 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2465 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2466 | return false; |
| 2467 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2468 | |
| 2469 | final long identity = Binder.clearCallingIdentity(); |
| 2470 | try { |
| 2471 | return isRadioOnForSubscriber(subId); |
| 2472 | } finally { |
| 2473 | Binder.restoreCallingIdentity(identity); |
| 2474 | } |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | private boolean isRadioOnForSubscriber(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2478 | final long identity = Binder.clearCallingIdentity(); |
| 2479 | try { |
| 2480 | final Phone phone = getPhone(subId); |
| 2481 | if (phone != null) { |
| 2482 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2483 | } else { |
| 2484 | return false; |
| 2485 | } |
| 2486 | } finally { |
| 2487 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2488 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | public void toggleRadioOnOff() { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2492 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2493 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2494 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2495 | public void toggleRadioOnOffForSubscriber(int subId) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2496 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2497 | |
| 2498 | final long identity = Binder.clearCallingIdentity(); |
| 2499 | try { |
| 2500 | final Phone phone = getPhone(subId); |
| 2501 | if (phone != null) { |
| 2502 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2503 | } |
| 2504 | } finally { |
| 2505 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2506 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | public boolean setRadio(boolean turnOn) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2510 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2511 | } |
| 2512 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2513 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2514 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2515 | |
| 2516 | final long identity = Binder.clearCallingIdentity(); |
| 2517 | try { |
| 2518 | final Phone phone = getPhone(subId); |
| 2519 | if (phone == null) { |
| 2520 | return false; |
| 2521 | } |
| 2522 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2523 | toggleRadioOnOffForSubscriber(subId); |
| 2524 | } |
| 2525 | return true; |
| 2526 | } finally { |
| 2527 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2528 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2529 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2530 | |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2531 | public boolean needMobileRadioShutdown() { |
| Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2532 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2533 | /* |
| 2534 | * If any of the Radios are available, it will need to be |
| 2535 | * shutdown. So return true if any Radio is available. |
| 2536 | */ |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2537 | final long identity = Binder.clearCallingIdentity(); |
| 2538 | try { |
| 2539 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2540 | Phone phone = PhoneFactory.getPhone(i); |
| 2541 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2542 | } |
| 2543 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2544 | return false; |
| 2545 | } finally { |
| 2546 | Binder.restoreCallingIdentity(identity); |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2547 | } |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2550 | @Override |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2551 | public void shutdownMobileRadios() { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2552 | enforceModifyPermission(); |
| 2553 | |
| 2554 | final long identity = Binder.clearCallingIdentity(); |
| 2555 | try { |
| 2556 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2557 | logv("Shutting down Phone " + i); |
| 2558 | shutdownRadioUsingPhoneId(i); |
| 2559 | } |
| 2560 | } finally { |
| 2561 | Binder.restoreCallingIdentity(identity); |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2562 | } |
| 2563 | } |
| 2564 | |
| 2565 | private void shutdownRadioUsingPhoneId(int phoneId) { |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2566 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2567 | if (phone != null && phone.isRadioAvailable()) { |
| 2568 | phone.shutdownRadio(); |
| 2569 | } |
| 2570 | } |
| 2571 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2572 | public boolean setRadioPower(boolean turnOn) { |
| Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2573 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2574 | |
| 2575 | final long identity = Binder.clearCallingIdentity(); |
| 2576 | try { |
| 2577 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2578 | if (defaultPhone != null) { |
| 2579 | defaultPhone.setRadioPower(turnOn); |
| 2580 | return true; |
| 2581 | } else { |
| 2582 | loge("There's no default phone."); |
| 2583 | return false; |
| 2584 | } |
| 2585 | } finally { |
| 2586 | Binder.restoreCallingIdentity(identity); |
| Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2587 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2590 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2591 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2592 | |
| 2593 | final long identity = Binder.clearCallingIdentity(); |
| 2594 | try { |
| 2595 | final Phone phone = getPhone(subId); |
| 2596 | if (phone != null) { |
| 2597 | phone.setRadioPower(turnOn); |
| 2598 | return true; |
| 2599 | } else { |
| 2600 | return false; |
| 2601 | } |
| 2602 | } finally { |
| 2603 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2604 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2605 | } |
| 2606 | |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2607 | // FIXME: subId version needed |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2608 | @Override |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2609 | public boolean enableDataConnectivity() { |
| 2610 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2611 | |
| 2612 | final long identity = Binder.clearCallingIdentity(); |
| 2613 | try { |
| 2614 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2615 | final Phone phone = getPhone(subId); |
| 2616 | if (phone != null) { |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2617 | phone.getDataEnabledSettings().setDataEnabled( |
| 2618 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | return true; |
| 2620 | } else { |
| 2621 | return false; |
| 2622 | } |
| 2623 | } finally { |
| 2624 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2625 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2628 | // FIXME: subId version needed |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2629 | @Override |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2630 | public boolean disableDataConnectivity() { |
| 2631 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2632 | |
| 2633 | final long identity = Binder.clearCallingIdentity(); |
| 2634 | try { |
| 2635 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2636 | final Phone phone = getPhone(subId); |
| 2637 | if (phone != null) { |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2638 | phone.getDataEnabledSettings().setDataEnabled( |
| 2639 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2640 | return true; |
| 2641 | } else { |
| 2642 | return false; |
| 2643 | } |
| 2644 | } finally { |
| 2645 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2646 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2647 | } |
| 2648 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2649 | @Override |
| Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2650 | public boolean isDataConnectivityPossible(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2651 | final long identity = Binder.clearCallingIdentity(); |
| 2652 | try { |
| 2653 | final Phone phone = getPhone(subId); |
| 2654 | if (phone != null) { |
| Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2655 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2656 | } else { |
| 2657 | return false; |
| 2658 | } |
| 2659 | } finally { |
| 2660 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2661 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | public boolean handlePinMmi(String dialString) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2665 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2666 | } |
| 2667 | |
| pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2668 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2669 | enforceCallPermission(); |
| 2670 | |
| 2671 | final long identity = Binder.clearCallingIdentity(); |
| 2672 | try { |
| 2673 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2674 | return; |
| 2675 | } |
| 2676 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2677 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2678 | } finally { |
| 2679 | Binder.restoreCallingIdentity(identity); |
| 2680 | } |
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2681 | }; |
| 2682 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2683 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2684 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2685 | |
| 2686 | final long identity = Binder.clearCallingIdentity(); |
| 2687 | try { |
| 2688 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2689 | return false; |
| 2690 | } |
| 2691 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2692 | } finally { |
| 2693 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2694 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2695 | } |
| 2696 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2697 | public int getCallState() { |
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2698 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2699 | } |
| 2700 | |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2701 | public int getCallStateForSlot(int slotIndex) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2702 | final long identity = Binder.clearCallingIdentity(); |
| 2703 | try { |
| 2704 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2705 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2706 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2707 | } finally { |
| 2708 | Binder.restoreCallingIdentity(identity); |
| 2709 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2710 | } |
| 2711 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2712 | @Override |
| Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2713 | public int getDataState() { |
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2714 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2715 | } |
| 2716 | |
| 2717 | @Override |
| 2718 | public int getDataStateForSubId(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2719 | final long identity = Binder.clearCallingIdentity(); |
| 2720 | try { |
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2721 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2722 | if (phone != null) { |
| 2723 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2724 | } else { |
| 2725 | return PhoneConstantConversions.convertDataState( |
| 2726 | PhoneConstants.DataState.DISCONNECTED); |
| 2727 | } |
| 2728 | } finally { |
| 2729 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2730 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2731 | } |
| 2732 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2733 | @Override |
| Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2734 | public int getDataActivity() { |
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2735 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2736 | } |
| 2737 | |
| 2738 | @Override |
| 2739 | public int getDataActivityForSubId(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2740 | final long identity = Binder.clearCallingIdentity(); |
| 2741 | try { |
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2742 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2743 | if (phone != null) { |
| 2744 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2745 | } else { |
| 2746 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2747 | } |
| 2748 | } finally { |
| 2749 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2750 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | @Override |
| Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2754 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2755 | mApp.getSystemService(AppOpsManager.class) |
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2756 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2757 | |
| 2758 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2759 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2760 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2761 | .setCallingPackage(callingPackage) |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2762 | .setCallingFeatureId(callingFeatureId) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2763 | .setCallingPid(Binder.getCallingPid()) |
| 2764 | .setCallingUid(Binder.getCallingUid()) |
| 2765 | .setMethod("getCellLocation") |
| Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2766 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2767 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2768 | .build()); |
| 2769 | switch (locationResult) { |
| 2770 | case DENIED_HARD: |
| 2771 | throw new SecurityException("Not allowed to access cell location"); |
| 2772 | case DENIED_SOFT: |
| Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2773 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2774 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2775 | } |
| 2776 | |
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2777 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2778 | final long identity = Binder.clearCallingIdentity(); |
| 2779 | try { |
| 2780 | if (DBG_LOC) log("getCellLocation: is active user"); |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2781 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2782 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2783 | } finally { |
| 2784 | Binder.restoreCallingIdentity(identity); |
| 2785 | } |
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2788 | @Override |
| Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2789 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2790 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2791 | // registered cell info, so return a NULL country instead. |
| 2792 | final long identity = Binder.clearCallingIdentity(); |
| 2793 | try { |
| Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2794 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2795 | // Get default phone in this case. |
| 2796 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2797 | } |
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2798 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2799 | Phone phone = PhoneFactory.getPhone(phoneId); |
| Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2800 | if (phone == null) return ""; |
| 2801 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2802 | if (sst == null) return ""; |
| 2803 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2804 | if (lt == null) return ""; |
| 2805 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2806 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2807 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2808 | } finally { |
| 2809 | Binder.restoreCallingIdentity(identity); |
| 2810 | } |
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2813 | /** |
| 2814 | * This method was removed due to potential issues caused by performing partial |
| 2815 | * updates of service state, and lack of a credible use case. |
| 2816 | * |
| 2817 | * This has the ability to break the telephony implementation by disabling notification of |
| 2818 | * changes in device connectivity. DO NOT USE THIS! |
| 2819 | */ |
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2820 | @Override |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2821 | public void enableLocationUpdates() { |
| 2822 | mApp.enforceCallingOrSelfPermission( |
| 2823 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2824 | } |
| 2825 | |
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2826 | /** |
| 2827 | * This method was removed due to potential issues caused by performing partial |
| 2828 | * updates of service state, and lack of a credible use case. |
| 2829 | * |
| 2830 | * This has the ability to break the telephony implementation by disabling notification of |
| 2831 | * changes in device connectivity. DO NOT USE THIS! |
| 2832 | */ |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2833 | @Override |
| 2834 | public void disableLocationUpdates() { |
| 2835 | mApp.enforceCallingOrSelfPermission( |
| 2836 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | @Override |
| 2840 | @SuppressWarnings("unchecked") |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2841 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2842 | String callingFeatureId) { |
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2843 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
| Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2844 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2845 | throw new SecurityException( |
| 2846 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2847 | } |
| Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2848 | |
| Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2849 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2850 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2851 | return null; |
| 2852 | } |
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2853 | |
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2854 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2855 | |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2856 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2857 | if (info == null) return null; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2858 | |
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2859 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2860 | for (CellInfo ci : info) { |
| 2861 | if (ci instanceof CellInfoGsm) { |
| 2862 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2863 | } else if (ci instanceof CellInfoWcdma) { |
| 2864 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2865 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2866 | } |
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2867 | return (neighbors.size()) > 0 ? neighbors : null; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2868 | } |
| 2869 | |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2870 | private List<CellInfo> getCachedCellInfo() { |
| 2871 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2872 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2873 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2874 | if (info != null) cellInfos.addAll(info); |
| 2875 | } |
| 2876 | return cellInfos; |
| 2877 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2878 | |
| 2879 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2880 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2881 | mApp.getSystemService(AppOpsManager.class) |
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2882 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2883 | |
| 2884 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2885 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2886 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2887 | .setCallingPackage(callingPackage) |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2888 | .setCallingFeatureId(callingFeatureId) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2889 | .setCallingPid(Binder.getCallingPid()) |
| 2890 | .setCallingUid(Binder.getCallingUid()) |
| 2891 | .setMethod("getAllCellInfo") |
| Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2892 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2893 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2894 | .build()); |
| 2895 | switch (locationResult) { |
| 2896 | case DENIED_HARD: |
| 2897 | throw new SecurityException("Not allowed to access cell info"); |
| 2898 | case DENIED_SOFT: |
| 2899 | return new ArrayList<>(); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2900 | } |
| 2901 | |
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2902 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2903 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2904 | return getCachedCellInfo(); |
| 2905 | } |
| 2906 | |
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2907 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2908 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2909 | final long identity = Binder.clearCallingIdentity(); |
| 2910 | try { |
| 2911 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2912 | for (Phone phone : PhoneFactory.getPhones()) { |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2913 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2914 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2915 | if (info != null) cellInfos.addAll(info); |
| 2916 | } |
| 2917 | return cellInfos; |
| 2918 | } finally { |
| 2919 | Binder.restoreCallingIdentity(identity); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2920 | } |
| 2921 | } |
| 2922 | |
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2923 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2924 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2925 | String callingFeatureId) { |
| 2926 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2927 | getWorkSource(Binder.getCallingUid())); |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2928 | } |
| 2929 | |
| 2930 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2931 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2932 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2933 | enforceModifyPermission(); |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2934 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2935 | } |
| 2936 | |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2937 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2938 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2939 | mApp.getSystemService(AppOpsManager.class) |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2940 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2941 | |
| 2942 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2943 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2944 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2945 | .setCallingPackage(callingPackage) |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2946 | .setCallingFeatureId(callingFeatureId) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2947 | .setCallingPid(Binder.getCallingPid()) |
| 2948 | .setCallingUid(Binder.getCallingUid()) |
| 2949 | .setMethod("requestCellInfoUpdate") |
| Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2950 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2951 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2952 | .build()); |
| 2953 | switch (locationResult) { |
| 2954 | case DENIED_HARD: |
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2955 | if (TelephonyPermissions |
| 2956 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
| Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2957 | // Safetynet logging for b/154934934 |
| 2958 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2959 | } |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2960 | throw new SecurityException("Not allowed to access cell info"); |
| 2961 | case DENIED_SOFT: |
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2962 | if (TelephonyPermissions |
| 2963 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
| Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2964 | // Safetynet logging for b/154934934 |
| 2965 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2966 | } |
| Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2967 | try { |
| 2968 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2969 | } catch (RemoteException re) { |
| 2970 | // Drop without consequences |
| 2971 | } |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2972 | return; |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2973 | } |
| 2974 | |
| Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2975 | |
| 2976 | final Phone phone = getPhoneFromSubId(subId); |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2977 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2978 | |
| 2979 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2980 | } |
| 2981 | |
| 2982 | @Override |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2983 | public void setCellInfoListRate(int rateInMillis) { |
| Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2984 | enforceModifyPermission(); |
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2985 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2986 | |
| 2987 | final long identity = Binder.clearCallingIdentity(); |
| 2988 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2989 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2990 | } finally { |
| 2991 | Binder.restoreCallingIdentity(identity); |
| 2992 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2995 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2996 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2997 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2998 | if (phone == null) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2999 | return null; |
| 3000 | } |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3001 | int subId = phone.getSubId(); |
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3002 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3003 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3004 | return null; |
| 3005 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3006 | |
| 3007 | final long identity = Binder.clearCallingIdentity(); |
| 3008 | try { |
| 3009 | return phone.getImei(); |
| 3010 | } finally { |
| 3011 | Binder.restoreCallingIdentity(identity); |
| 3012 | } |
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | @Override |
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3016 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3017 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3018 | String tac = null; |
| 3019 | if (phone != null) { |
| 3020 | String imei = phone.getImei(); |
| 3021 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3022 | } |
| 3023 | return tac; |
| 3024 | } |
| 3025 | |
| 3026 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3027 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3028 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3029 | if (phone == null) { |
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3030 | return null; |
| 3031 | } |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3032 | |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3033 | int subId = phone.getSubId(); |
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3034 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3035 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3036 | return null; |
| 3037 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3038 | |
| 3039 | final long identity = Binder.clearCallingIdentity(); |
| 3040 | try { |
| 3041 | return phone.getMeid(); |
| 3042 | } finally { |
| 3043 | Binder.restoreCallingIdentity(identity); |
| 3044 | } |
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3045 | } |
| 3046 | |
| 3047 | @Override |
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3048 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3049 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3050 | String manufacturerCode = null; |
| 3051 | if (phone != null) { |
| 3052 | String meid = phone.getMeid(); |
| 3053 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3054 | } |
| 3055 | return manufacturerCode; |
| 3056 | } |
| 3057 | |
| 3058 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3059 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3060 | String callingFeatureId) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3061 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3062 | if (phone == null) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3063 | return null; |
| 3064 | } |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3065 | int subId = phone.getSubId(); |
| 3066 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3067 | mApp, subId, callingPackage, callingFeatureId, |
| 3068 | "getDeviceSoftwareVersionForSlot")) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3069 | return null; |
| 3070 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3071 | |
| 3072 | final long identity = Binder.clearCallingIdentity(); |
| 3073 | try { |
| 3074 | return phone.getDeviceSvn(); |
| 3075 | } finally { |
| 3076 | Binder.restoreCallingIdentity(identity); |
| 3077 | } |
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3078 | } |
| 3079 | |
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3080 | @Override |
| 3081 | public int getSubscriptionCarrierId(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3082 | final long identity = Binder.clearCallingIdentity(); |
| 3083 | try { |
| 3084 | final Phone phone = getPhone(subId); |
| 3085 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3086 | } finally { |
| 3087 | Binder.restoreCallingIdentity(identity); |
| 3088 | } |
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | @Override |
| 3092 | public String getSubscriptionCarrierName(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3093 | final long identity = Binder.clearCallingIdentity(); |
| 3094 | try { |
| 3095 | final Phone phone = getPhone(subId); |
| 3096 | return phone == null ? null : phone.getCarrierName(); |
| 3097 | } finally { |
| 3098 | Binder.restoreCallingIdentity(identity); |
| 3099 | } |
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3100 | } |
| 3101 | |
| calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3102 | @Override |
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3103 | public int getSubscriptionSpecificCarrierId(int subId) { |
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3104 | final long identity = Binder.clearCallingIdentity(); |
| 3105 | try { |
| 3106 | final Phone phone = getPhone(subId); |
| 3107 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3108 | : phone.getSpecificCarrierId(); |
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3109 | } finally { |
| 3110 | Binder.restoreCallingIdentity(identity); |
| 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | @Override |
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3115 | public String getSubscriptionSpecificCarrierName(int subId) { |
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3116 | final long identity = Binder.clearCallingIdentity(); |
| 3117 | try { |
| 3118 | final Phone phone = getPhone(subId); |
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3119 | return phone == null ? null : phone.getSpecificCarrierName(); |
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3120 | } finally { |
| 3121 | Binder.restoreCallingIdentity(identity); |
| 3122 | } |
| 3123 | } |
| 3124 | |
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3125 | @Override |
| chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3126 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3127 | if (!isSubscriptionMccMnc) { |
| 3128 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3129 | } |
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3130 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3131 | if (phone == null) { |
| 3132 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3133 | } |
| 3134 | final long identity = Binder.clearCallingIdentity(); |
| 3135 | try { |
| 3136 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3137 | } finally { |
| 3138 | Binder.restoreCallingIdentity(identity); |
| 3139 | } |
| 3140 | } |
| 3141 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3142 | // |
| 3143 | // Internal helper methods. |
| 3144 | // |
| 3145 | |
| Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3146 | /** |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3147 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3148 | * |
| 3149 | * @throws SecurityException if the caller does not have the required permission |
| 3150 | */ |
| 3151 | private void enforceModifyPermission() { |
| 3152 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3153 | } |
| 3154 | |
| Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3155 | /** |
| 3156 | * Make sure the caller is system. |
| 3157 | * |
| 3158 | * @throws SecurityException if the caller is not system. |
| 3159 | */ |
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3160 | private static void enforceSystemCaller() { |
| Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3161 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3162 | throw new SecurityException("Caller must be system"); |
| 3163 | } |
| 3164 | } |
| 3165 | |
| Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3166 | private void enforceActiveEmergencySessionPermission() { |
| 3167 | mApp.enforceCallingOrSelfPermission( |
| 3168 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3169 | } |
| 3170 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3171 | /** |
| 3172 | * Make sure the caller has the CALL_PHONE permission. |
| 3173 | * |
| 3174 | * @throws SecurityException if the caller does not have the required permission |
| 3175 | */ |
| 3176 | private void enforceCallPermission() { |
| 3177 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3178 | } |
| 3179 | |
| paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3180 | private void enforceSettingsPermission() { |
| 3181 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3182 | } |
| 3183 | |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3184 | private void enforceRebootPermission() { |
| 3185 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3186 | } |
| 3187 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3188 | private String createTelUrl(String number) { |
| 3189 | if (TextUtils.isEmpty(number)) { |
| 3190 | return null; |
| 3191 | } |
| 3192 | |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3193 | return "tel:" + number; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3194 | } |
| 3195 | |
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3196 | private static void log(String msg) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3197 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3198 | } |
| 3199 | |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3200 | private static void logv(String msg) { |
| 3201 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3202 | } |
| 3203 | |
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3204 | private static void loge(String msg) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3205 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3206 | } |
| 3207 | |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3208 | @Override |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3209 | public int getActivePhoneType() { |
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3210 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3211 | } |
| 3212 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3213 | @Override |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3214 | public int getActivePhoneTypeForSlot(int slotIndex) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3215 | final long identity = Binder.clearCallingIdentity(); |
| 3216 | try { |
| 3217 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3218 | if (phone == null) { |
| 3219 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3220 | } else { |
| 3221 | return phone.getPhoneType(); |
| 3222 | } |
| 3223 | } finally { |
| 3224 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3225 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | /** |
| 3229 | * Returns the CDMA ERI icon index to display |
| 3230 | */ |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3231 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3232 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3233 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3234 | callingFeatureId); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3235 | } |
| 3236 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3237 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3238 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3239 | String callingFeatureId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3240 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3241 | mApp, subId, callingPackage, callingFeatureId, |
| 3242 | "getCdmaEriIconIndexForSubscriber")) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3243 | return -1; |
| 3244 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3245 | |
| 3246 | final long identity = Binder.clearCallingIdentity(); |
| 3247 | try { |
| 3248 | final Phone phone = getPhone(subId); |
| 3249 | if (phone != null) { |
| 3250 | return phone.getCdmaEriIconIndex(); |
| 3251 | } else { |
| 3252 | return -1; |
| 3253 | } |
| 3254 | } finally { |
| 3255 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3256 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | /** |
| 3260 | * Returns the CDMA ERI icon mode, |
| 3261 | * 0 - ON |
| 3262 | * 1 - FLASHING |
| 3263 | */ |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3264 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3265 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3266 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3267 | callingFeatureId); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3268 | } |
| 3269 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3270 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3271 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3272 | String callingFeatureId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3273 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3274 | mApp, subId, callingPackage, callingFeatureId, |
| 3275 | "getCdmaEriIconModeForSubscriber")) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3276 | return -1; |
| 3277 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3278 | |
| 3279 | final long identity = Binder.clearCallingIdentity(); |
| 3280 | try { |
| 3281 | final Phone phone = getPhone(subId); |
| 3282 | if (phone != null) { |
| 3283 | return phone.getCdmaEriIconMode(); |
| 3284 | } else { |
| 3285 | return -1; |
| 3286 | } |
| 3287 | } finally { |
| 3288 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3289 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3290 | } |
| 3291 | |
| 3292 | /** |
| 3293 | * Returns the CDMA ERI text, |
| 3294 | */ |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3295 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3296 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3297 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3298 | callingFeatureId); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3299 | } |
| 3300 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3301 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3302 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3303 | String callingFeatureId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3304 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3305 | mApp, subId, callingPackage, callingFeatureId, |
| 3306 | "getCdmaEriIconTextForSubscriber")) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3307 | return null; |
| 3308 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3309 | |
| 3310 | final long identity = Binder.clearCallingIdentity(); |
| 3311 | try { |
| 3312 | final Phone phone = getPhone(subId); |
| 3313 | if (phone != null) { |
| 3314 | return phone.getCdmaEriText(); |
| 3315 | } else { |
| 3316 | return null; |
| 3317 | } |
| 3318 | } finally { |
| 3319 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3320 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | /** |
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3324 | * Returns the CDMA MDN. |
| 3325 | */ |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3326 | @Override |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3327 | public String getCdmaMdn(int subId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3328 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3329 | mApp, subId, "getCdmaMdn"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3330 | |
| 3331 | final long identity = Binder.clearCallingIdentity(); |
| 3332 | try { |
| 3333 | final Phone phone = getPhone(subId); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3334 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3335 | return phone.getLine1Number(); |
| 3336 | } else { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3337 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3338 | return null; |
| 3339 | } |
| 3340 | } finally { |
| 3341 | Binder.restoreCallingIdentity(identity); |
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | /** |
| 3346 | * Returns the CDMA MIN. |
| 3347 | */ |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3348 | @Override |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3349 | public String getCdmaMin(int subId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3350 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3351 | mApp, subId, "getCdmaMin"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3352 | |
| 3353 | final long identity = Binder.clearCallingIdentity(); |
| 3354 | try { |
| 3355 | final Phone phone = getPhone(subId); |
| 3356 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3357 | return phone.getCdmaMin(); |
| 3358 | } else { |
| 3359 | return null; |
| 3360 | } |
| 3361 | } finally { |
| 3362 | Binder.restoreCallingIdentity(identity); |
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3363 | } |
| 3364 | } |
| 3365 | |
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3366 | @Override |
| 3367 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3368 | INumberVerificationCallback callback, String callingPackage) { |
| 3369 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3370 | != PERMISSION_GRANTED) { |
| 3371 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3372 | } |
| 3373 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3374 | |
| 3375 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3376 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3377 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3378 | + "calling package: " + callingPackage |
| 3379 | + ", configured package: " + authorizedPackage); |
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | if (range == null) { |
| 3383 | throw new NullPointerException("Range must be non-null"); |
| 3384 | } |
| 3385 | |
| 3386 | timeoutMillis = Math.min(timeoutMillis, |
| Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3387 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3388 | |
| 3389 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3390 | } |
| 3391 | |
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3392 | /** |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3393 | * Returns true if CDMA provisioning needs to run. |
| 3394 | */ |
| 3395 | public boolean needsOtaServiceProvisioning() { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3396 | final long identity = Binder.clearCallingIdentity(); |
| 3397 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3398 | return getDefaultPhone().needsOtaServiceProvisioning(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3399 | } finally { |
| 3400 | Binder.restoreCallingIdentity(identity); |
| 3401 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | /** |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3405 | * Sets the voice mail number of a given subId. |
| 3406 | */ |
| 3407 | @Override |
| 3408 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3409 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3410 | mApp, subId, "setVoiceMailNumber"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3411 | |
| 3412 | final long identity = Binder.clearCallingIdentity(); |
| 3413 | try { |
| 3414 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3415 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3416 | return success; |
| 3417 | } finally { |
| 3418 | Binder.restoreCallingIdentity(identity); |
| 3419 | } |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3420 | } |
| 3421 | |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3422 | @Override |
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3423 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3424 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3425 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3426 | String systemDialer = tm.getSystemDialerPackage(); |
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3427 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3428 | throw new SecurityException("caller must be system dialer"); |
| 3429 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3430 | |
| 3431 | final long identity = Binder.clearCallingIdentity(); |
| 3432 | try { |
| 3433 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3434 | if (phoneAccountHandle == null) { |
| 3435 | return null; |
| 3436 | } |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3437 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3438 | } finally { |
| 3439 | Binder.restoreCallingIdentity(identity); |
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3440 | } |
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3441 | } |
| 3442 | |
| 3443 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3444 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3445 | int subId) { |
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3446 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3447 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3448 | mApp, subId, callingPackage, callingFeatureId, |
| 3449 | "getVisualVoicemailPackageName")) { |
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3450 | return null; |
| 3451 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3452 | |
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3453 | final long identity = Binder.clearCallingIdentity(); |
| 3454 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3455 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3456 | } finally { |
| 3457 | Binder.restoreCallingIdentity(identity); |
| 3458 | } |
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3459 | } |
| 3460 | |
| 3461 | @Override |
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3462 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3463 | VisualVoicemailSmsFilterSettings settings) { |
| 3464 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3465 | |
| 3466 | final long identity = Binder.clearCallingIdentity(); |
| 3467 | try { |
| 3468 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3469 | mApp, callingPackage, subId, settings); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3470 | } finally { |
| 3471 | Binder.restoreCallingIdentity(identity); |
| 3472 | } |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3473 | } |
| 3474 | |
| 3475 | @Override |
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3476 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3477 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3478 | |
| 3479 | final long identity = Binder.clearCallingIdentity(); |
| 3480 | try { |
| 3481 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3482 | mApp, callingPackage, subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3483 | } finally { |
| 3484 | Binder.restoreCallingIdentity(identity); |
| 3485 | } |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | @Override |
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3489 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3490 | String callingPackage, int subId) { |
| 3491 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3492 | |
| 3493 | final long identity = Binder.clearCallingIdentity(); |
| 3494 | try { |
| 3495 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3496 | mApp, callingPackage, subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3497 | } finally { |
| 3498 | Binder.restoreCallingIdentity(identity); |
| 3499 | } |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | @Override |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3503 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3504 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3505 | |
| 3506 | final long identity = Binder.clearCallingIdentity(); |
| 3507 | try { |
| 3508 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3509 | mApp, subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3510 | } finally { |
| 3511 | Binder.restoreCallingIdentity(identity); |
| 3512 | } |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | @Override |
| Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3516 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3517 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3518 | PendingIntent sentIntent) { |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3519 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3520 | enforceVisualVoicemailPackage(callingPackage, subId); |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3521 | enforceSendSmsPermission(); |
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3522 | SmsController smsController = PhoneFactory.getSmsController(); |
| Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3523 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3524 | subId, number, port, text, sentIntent); |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3525 | } |
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3526 | |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3527 | /** |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3528 | * Sets the voice activation state of a given subId. |
| 3529 | */ |
| 3530 | @Override |
| 3531 | public void setVoiceActivationState(int subId, int activationState) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3532 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3533 | mApp, subId, "setVoiceActivationState"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3534 | |
| 3535 | final long identity = Binder.clearCallingIdentity(); |
| 3536 | try { |
| 3537 | final Phone phone = getPhone(subId); |
| 3538 | if (phone != null) { |
| 3539 | phone.setVoiceActivationState(activationState); |
| 3540 | } else { |
| 3541 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3542 | } |
| 3543 | } finally { |
| 3544 | Binder.restoreCallingIdentity(identity); |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3545 | } |
| 3546 | } |
| 3547 | |
| 3548 | /** |
| 3549 | * Sets the data activation state of a given subId. |
| 3550 | */ |
| 3551 | @Override |
| 3552 | public void setDataActivationState(int subId, int activationState) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3553 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3554 | mApp, subId, "setDataActivationState"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3555 | |
| 3556 | final long identity = Binder.clearCallingIdentity(); |
| 3557 | try { |
| 3558 | final Phone phone = getPhone(subId); |
| 3559 | if (phone != null) { |
| 3560 | phone.setDataActivationState(activationState); |
| 3561 | } else { |
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3562 | loge("setDataActivationState fails with invalid subId: " + subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3563 | } |
| 3564 | } finally { |
| 3565 | Binder.restoreCallingIdentity(identity); |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3566 | } |
| 3567 | } |
| 3568 | |
| 3569 | /** |
| 3570 | * Returns the voice activation state of a given subId. |
| 3571 | */ |
| 3572 | @Override |
| 3573 | public int getVoiceActivationState(int subId, String callingPackage) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3574 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3575 | |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3576 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3577 | final long identity = Binder.clearCallingIdentity(); |
| 3578 | try { |
| 3579 | if (phone != null) { |
| 3580 | return phone.getVoiceActivationState(); |
| 3581 | } else { |
| 3582 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3583 | } |
| 3584 | } finally { |
| 3585 | Binder.restoreCallingIdentity(identity); |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3586 | } |
| 3587 | } |
| 3588 | |
| 3589 | /** |
| 3590 | * Returns the data activation state of a given subId. |
| 3591 | */ |
| 3592 | @Override |
| 3593 | public int getDataActivationState(int subId, String callingPackage) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3594 | enforceReadPrivilegedPermission("getDataActivationState"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3595 | |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3596 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3597 | final long identity = Binder.clearCallingIdentity(); |
| 3598 | try { |
| 3599 | if (phone != null) { |
| 3600 | return phone.getDataActivationState(); |
| 3601 | } else { |
| 3602 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3603 | } |
| 3604 | } finally { |
| 3605 | Binder.restoreCallingIdentity(identity); |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3606 | } |
| 3607 | } |
| 3608 | |
| 3609 | /** |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3610 | * Returns the unread count of voicemails for a subId |
| 3611 | */ |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3612 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3613 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3614 | String callingFeatureId) { |
| Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3615 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3616 | mApp, subId, callingPackage, callingFeatureId, |
| 3617 | "getVoiceMessageCountForSubscriber")) { |
| Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3618 | return 0; |
| 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.getVoiceMessageCount(); |
| 3625 | } else { |
| 3626 | return 0; |
| 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 | /** |
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3634 | * returns true, if the device is in a state where both voice and data |
| 3635 | * are supported simultaneously. This can change based on location or network condition. |
| 3636 | */ |
| 3637 | @Override |
| 3638 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3639 | final long identity = Binder.clearCallingIdentity(); |
| 3640 | try { |
| 3641 | final Phone phone = getPhone(subId); |
| 3642 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3643 | } finally { |
| 3644 | Binder.restoreCallingIdentity(identity); |
| 3645 | } |
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | /** |
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3649 | * Send the dialer code if called from the current default dialer or the caller has |
| 3650 | * carrier privilege. |
| 3651 | * @param inputCode The dialer code to send |
| 3652 | */ |
| 3653 | @Override |
| 3654 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3655 | final Phone defaultPhone = getDefaultPhone(); |
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3656 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3657 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3658 | String defaultDialer = tm.getDefaultDialerPackage(); |
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3659 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3660 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3661 | getDefaultSubscription(), "sendDialerSpecialCode"); |
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3662 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3663 | |
| 3664 | final long identity = Binder.clearCallingIdentity(); |
| 3665 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3666 | defaultPhone.sendDialerSpecialCode(inputCode); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3667 | } finally { |
| 3668 | Binder.restoreCallingIdentity(identity); |
| 3669 | } |
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3670 | } |
| 3671 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3672 | @Override |
| 3673 | public int getNetworkSelectionMode(int subId) { |
| shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3674 | TelephonyPermissions |
| 3675 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3676 | mApp, subId, "getNetworkSelectionMode"); |
| 3677 | final long identity = Binder.clearCallingIdentity(); |
| 3678 | try { |
| 3679 | if (!isActiveSubscription(subId)) { |
| 3680 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3681 | } |
| 3682 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3683 | } finally { |
| 3684 | Binder.restoreCallingIdentity(identity); |
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3685 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3686 | } |
| 3687 | |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3688 | @Override |
| Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3689 | public boolean isInEmergencySmsMode() { |
| 3690 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3691 | final long identity = Binder.clearCallingIdentity(); |
| 3692 | try { |
| 3693 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3694 | if (phone.isInEmergencySmsMode()) { |
| 3695 | return true; |
| 3696 | } |
| 3697 | } |
| 3698 | } finally { |
| 3699 | Binder.restoreCallingIdentity(identity); |
| 3700 | } |
| 3701 | return false; |
| 3702 | } |
| 3703 | |
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3704 | /** |
| 3705 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3706 | * @param subId The subscription to use to check the configuration. |
| 3707 | * @param c The callback that will be used to send the result. |
| 3708 | */ |
| Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3709 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3710 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3711 | throws RemoteException { |
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3712 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3713 | mApp, subId, "registerImsRegistrationCallback"); |
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3714 | |
| Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3715 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3716 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3717 | "IMS not available on device."); |
| 3718 | } |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3719 | final long token = Binder.clearCallingIdentity(); |
| 3720 | try { |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3721 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3722 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3723 | .addRegistrationCallbackForSubscription(c, subId); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3724 | } catch (ImsException e) { |
| 3725 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3726 | } finally { |
| 3727 | Binder.restoreCallingIdentity(token); |
| 3728 | } |
| 3729 | } |
| 3730 | |
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3731 | /** |
| 3732 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3733 | * @param subId The subscription to use to check the configuration. |
| 3734 | * @param c The callback that will be used to send the result. |
| 3735 | */ |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3736 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3737 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3738 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3739 | mApp, subId, "unregisterImsRegistrationCallback"); |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3740 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3741 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3742 | } |
| Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3743 | final long token = Binder.clearCallingIdentity(); |
| 3744 | try { |
| 3745 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3746 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3747 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3748 | } catch (ImsException e) { |
| 3749 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3750 | + "is inactive, ignoring unregister."); |
| 3751 | // If the subscription is no longer active, just return, since the callback |
| 3752 | // will already have been removed internally. |
| 3753 | } finally { |
| 3754 | Binder.restoreCallingIdentity(token); |
| 3755 | } |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3756 | } |
| 3757 | |
| Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3758 | /** |
| 3759 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3760 | */ |
| 3761 | @Override |
| 3762 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3763 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3764 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3765 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3766 | "IMS not available on device."); |
| 3767 | } |
| 3768 | final long token = Binder.clearCallingIdentity(); |
| 3769 | try { |
| 3770 | Phone phone = getPhone(subId); |
| 3771 | if (phone == null) { |
| 3772 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3773 | + subId + "'"); |
| 3774 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3775 | } |
| 3776 | phone.getImsRegistrationState(regState -> { |
| 3777 | try { |
| 3778 | consumer.accept((regState == null) |
| 3779 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3780 | } catch (RemoteException e) { |
| 3781 | // Ignore if the remote process is no longer available to call back. |
| 3782 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3783 | } |
| 3784 | }); |
| 3785 | } finally { |
| 3786 | Binder.restoreCallingIdentity(token); |
| 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | /** |
| 3791 | * Get the transport type for the IMS service registration state. |
| 3792 | */ |
| 3793 | @Override |
| 3794 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3795 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3796 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
| Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3797 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3798 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3799 | "IMS not available on device."); |
| 3800 | } |
| 3801 | final long token = Binder.clearCallingIdentity(); |
| 3802 | try { |
| 3803 | Phone phone = getPhone(subId); |
| 3804 | if (phone == null) { |
| 3805 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3806 | + subId + "'"); |
| 3807 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3808 | } |
| 3809 | phone.getImsRegistrationTech(regTech -> { |
| 3810 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3811 | int regTechConverted = (regTech == null) |
| 3812 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3813 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3814 | regTechConverted); |
| 3815 | try { |
| 3816 | consumer.accept(regTechConverted); |
| 3817 | } catch (RemoteException e) { |
| 3818 | // Ignore if the remote process is no longer available to call back. |
| 3819 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3820 | } |
| 3821 | }); |
| 3822 | } finally { |
| 3823 | Binder.restoreCallingIdentity(token); |
| 3824 | } |
| 3825 | } |
| 3826 | |
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3827 | /** |
| 3828 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3829 | * @param subId The subscription to use to check the configuration. |
| 3830 | * @param c The callback that will be used to send the result. |
| 3831 | */ |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3832 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3833 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3834 | throws RemoteException { |
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3835 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3836 | mApp, subId, "registerMmTelCapabilityCallback"); |
| Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3837 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3838 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3839 | "IMS not available on device."); |
| 3840 | } |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3841 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3842 | final long token = Binder.clearCallingIdentity(); |
| 3843 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3844 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3845 | .addCapabilitiesCallbackForSubscription(c, subId); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3846 | } catch (ImsException e) { |
| 3847 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3848 | } finally { |
| 3849 | Binder.restoreCallingIdentity(token); |
| 3850 | } |
| 3851 | } |
| 3852 | |
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3853 | /** |
| 3854 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3855 | * @param subId The subscription to use to check the configuration. |
| 3856 | * @param c The callback that will be used to send the result. |
| 3857 | */ |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3858 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3859 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3860 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3861 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3862 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3863 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3864 | } |
| Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3865 | |
| 3866 | final long token = Binder.clearCallingIdentity(); |
| 3867 | try { |
| 3868 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3869 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3870 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3871 | } catch (ImsException e) { |
| 3872 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3873 | + "is inactive, ignoring unregister."); |
| 3874 | // If the subscription is no longer active, just return, since the callback |
| 3875 | // will already have been removed internally. |
| 3876 | } finally { |
| 3877 | Binder.restoreCallingIdentity(token); |
| 3878 | } |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3882 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3883 | enforceReadPrivilegedPermission("isCapable"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3884 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3885 | final long token = Binder.clearCallingIdentity(); |
| 3886 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3887 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3888 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3889 | } catch (com.android.ims.ImsException e) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3890 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3891 | return false; |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3892 | } catch (ImsException e) { |
| Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3893 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3894 | return false; |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3895 | } finally { |
| 3896 | Binder.restoreCallingIdentity(token); |
| 3897 | } |
| 3898 | } |
| 3899 | |
| 3900 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3901 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3902 | enforceReadPrivilegedPermission("isAvailable"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3903 | final long token = Binder.clearCallingIdentity(); |
| 3904 | try { |
| 3905 | Phone phone = getPhone(subId); |
| 3906 | if (phone == null) return false; |
| 3907 | return phone.isImsCapabilityAvailable(capability, regTech); |
| Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3908 | } catch (com.android.ims.ImsException e) { |
| 3909 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3910 | return false; |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3911 | } finally { |
| 3912 | Binder.restoreCallingIdentity(token); |
| 3913 | } |
| 3914 | } |
| 3915 | |
| Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3916 | /** |
| 3917 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3918 | * subscription. |
| 3919 | * @param subId The subscription to use to check the configuration. |
| 3920 | * @param callback The callback that will be used to send the result. |
| 3921 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3922 | * @param transportType The transport type of the MmTelFeature capability. |
| 3923 | */ |
| 3924 | @Override |
| 3925 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3926 | int transportType) { |
| 3927 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3928 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3929 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3930 | "IMS not available on device."); |
| 3931 | } |
| 3932 | final long token = Binder.clearCallingIdentity(); |
| 3933 | try { |
| 3934 | int slotId = getSlotIndex(subId); |
| 3935 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3936 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3937 | + subId + "'"); |
| 3938 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3939 | } |
| 3940 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3941 | transportType, aBoolean -> { |
| 3942 | try { |
| 3943 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3944 | } catch (RemoteException e) { |
| 3945 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3946 | + "running. Ignore"); |
| 3947 | } |
| 3948 | }); |
| 3949 | } finally { |
| 3950 | Binder.restoreCallingIdentity(token); |
| 3951 | } |
| 3952 | } |
| 3953 | |
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3954 | /** |
| 3955 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3956 | * @param subId The subscription to use to check the configuration. |
| 3957 | */ |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3958 | @Override |
| 3959 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3960 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3961 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3962 | |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3963 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3964 | final long token = Binder.clearCallingIdentity(); |
| 3965 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3966 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3967 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3968 | } catch (ImsException e) { |
| 3969 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3970 | } finally { |
| 3971 | Binder.restoreCallingIdentity(token); |
| 3972 | } |
| 3973 | } |
| 3974 | |
| 3975 | @Override |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3976 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3977 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3978 | "setAdvancedCallingSettingEnabled"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3979 | final long identity = Binder.clearCallingIdentity(); |
| 3980 | try { |
| 3981 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3982 | ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3983 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3984 | } catch (ImsException e) { |
| 3985 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3986 | } finally { |
| 3987 | Binder.restoreCallingIdentity(identity); |
| 3988 | } |
| 3989 | } |
| 3990 | |
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3991 | /** |
| 3992 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3993 | * @param subId The subscription to use to check the configuration. |
| 3994 | */ |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3995 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3996 | public boolean isVtSettingEnabled(int subId) { |
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3997 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3998 | mApp, subId, "isVtSettingEnabled"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3999 | final long identity = Binder.clearCallingIdentity(); |
| 4000 | try { |
| 4001 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4002 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 4003 | } catch (ImsException e) { |
| 4004 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4005 | } finally { |
| 4006 | Binder.restoreCallingIdentity(identity); |
| 4007 | } |
| 4008 | } |
| 4009 | |
| 4010 | @Override |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4011 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4012 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4013 | "setVtSettingEnabled"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4014 | final long identity = Binder.clearCallingIdentity(); |
| 4015 | try { |
| 4016 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4017 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4018 | } catch (ImsException e) { |
| 4019 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4020 | } finally { |
| 4021 | Binder.restoreCallingIdentity(identity); |
| 4022 | } |
| 4023 | } |
| 4024 | |
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4025 | /** |
| 4026 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4027 | * @param subId The subscription to use to check the configuration. |
| 4028 | */ |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4029 | @Override |
| 4030 | public boolean isVoWiFiSettingEnabled(int subId) { |
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4031 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4032 | mApp, subId, "isVoWiFiSettingEnabled"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4033 | final long identity = Binder.clearCallingIdentity(); |
| 4034 | try { |
| 4035 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4036 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4037 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4038 | } catch (ImsException e) { |
| 4039 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4040 | } finally { |
| 4041 | Binder.restoreCallingIdentity(identity); |
| 4042 | } |
| 4043 | } |
| 4044 | |
| 4045 | @Override |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4046 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4047 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4048 | "setVoWiFiSettingEnabled"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4049 | final long identity = Binder.clearCallingIdentity(); |
| 4050 | try { |
| 4051 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4052 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4053 | } catch (ImsException e) { |
| 4054 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4055 | } finally { |
| 4056 | Binder.restoreCallingIdentity(identity); |
| 4057 | } |
| 4058 | } |
| 4059 | |
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4060 | /** |
| 4061 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4062 | * @param subId The subscription to use to check the configuration. |
| 4063 | */ |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4064 | @Override |
| 4065 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4066 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4067 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4068 | final long identity = Binder.clearCallingIdentity(); |
| 4069 | try { |
| 4070 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4071 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4072 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4073 | } catch (ImsException e) { |
| 4074 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4075 | } finally { |
| 4076 | Binder.restoreCallingIdentity(identity); |
| 4077 | } |
| 4078 | } |
| 4079 | |
| 4080 | @Override |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4081 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4082 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4083 | "setVoWiFiRoamingSettingEnabled"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4084 | final long identity = Binder.clearCallingIdentity(); |
| 4085 | try { |
| 4086 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4087 | ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4088 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4089 | } catch (ImsException e) { |
| 4090 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4091 | } finally { |
| 4092 | Binder.restoreCallingIdentity(identity); |
| 4093 | } |
| 4094 | } |
| 4095 | |
| 4096 | @Override |
| 4097 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4098 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4099 | "setVoWiFiNonPersistent"); |
| 4100 | final long identity = Binder.clearCallingIdentity(); |
| 4101 | try { |
| 4102 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4103 | ImsManager.getInstance(mApp, |
| Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4104 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4105 | } catch (ImsException e) { |
| 4106 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4107 | } finally { |
| 4108 | Binder.restoreCallingIdentity(identity); |
| 4109 | } |
| 4110 | } |
| 4111 | |
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4112 | /** |
| 4113 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4114 | * @param subId The subscription to use to check the configuration. |
| 4115 | */ |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4116 | @Override |
| 4117 | public int getVoWiFiModeSetting(int subId) { |
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4118 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4119 | mApp, subId, "getVoWiFiModeSetting"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4120 | final long identity = Binder.clearCallingIdentity(); |
| 4121 | try { |
| 4122 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4123 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4124 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4125 | } catch (ImsException e) { |
| 4126 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4127 | } finally { |
| 4128 | Binder.restoreCallingIdentity(identity); |
| 4129 | } |
| 4130 | } |
| 4131 | |
| 4132 | @Override |
| 4133 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4135 | "setVoWiFiModeSetting"); |
| 4136 | final long identity = Binder.clearCallingIdentity(); |
| 4137 | try { |
| 4138 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4139 | ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4140 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4141 | } catch (ImsException e) { |
| 4142 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4143 | } finally { |
| 4144 | Binder.restoreCallingIdentity(identity); |
| 4145 | } |
| 4146 | } |
| 4147 | |
| 4148 | @Override |
| 4149 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4150 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4151 | final long identity = Binder.clearCallingIdentity(); |
| 4152 | try { |
| 4153 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4154 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4155 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4156 | } catch (ImsException e) { |
| 4157 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4158 | } finally { |
| 4159 | Binder.restoreCallingIdentity(identity); |
| 4160 | } |
| 4161 | } |
| 4162 | |
| 4163 | @Override |
| 4164 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4165 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4166 | "setVoWiFiRoamingModeSetting"); |
| 4167 | final long identity = Binder.clearCallingIdentity(); |
| 4168 | try { |
| 4169 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4170 | ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4171 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4172 | } catch (ImsException e) { |
| 4173 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4174 | } finally { |
| 4175 | Binder.restoreCallingIdentity(identity); |
| 4176 | } |
| 4177 | } |
| 4178 | |
| 4179 | @Override |
| 4180 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4181 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4182 | "setRttCapabilityEnabled"); |
| 4183 | final long identity = Binder.clearCallingIdentity(); |
| 4184 | try { |
| 4185 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4186 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4187 | } catch (ImsException e) { |
| 4188 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4189 | } finally { |
| 4190 | Binder.restoreCallingIdentity(identity); |
| 4191 | } |
| 4192 | } |
| 4193 | |
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4194 | /** |
| 4195 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4196 | * @param subId The subscription to use to check the configuration. |
| 4197 | */ |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4198 | @Override |
| 4199 | public boolean isTtyOverVolteEnabled(int subId) { |
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4200 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4201 | mApp, subId, "isTtyOverVolteEnabled"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4202 | final long identity = Binder.clearCallingIdentity(); |
| 4203 | try { |
| 4204 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4205 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4206 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4207 | } catch (ImsException e) { |
| 4208 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4209 | } finally { |
| 4210 | Binder.restoreCallingIdentity(identity); |
| 4211 | } |
| 4212 | } |
| 4213 | |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4214 | @Override |
| 4215 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4216 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4217 | final long identity = Binder.clearCallingIdentity(); |
| 4218 | try { |
| Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4219 | if (!isImsAvailableOnDevice()) { |
| 4220 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4221 | "IMS not available on device."); |
| Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4222 | } |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4223 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4224 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4225 | .addProvisioningCallbackForSubscription(callback, subId); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4226 | } catch (ImsException e) { |
| 4227 | throw new ServiceSpecificException(e.getCode()); |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4228 | } finally { |
| 4229 | Binder.restoreCallingIdentity(identity); |
| 4230 | } |
| 4231 | } |
| 4232 | |
| 4233 | @Override |
| 4234 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4235 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4236 | final long identity = Binder.clearCallingIdentity(); |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4237 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4238 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4239 | } |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4240 | try { |
| 4241 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4242 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4243 | .removeProvisioningCallbackForSubscription(callback, subId); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4244 | } catch (ImsException e) { |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4245 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4246 | + "is inactive, ignoring unregister."); |
| 4247 | // If the subscription is no longer active, just return, since the callback will already |
| 4248 | // have been removed internally. |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4249 | } finally { |
| 4250 | Binder.restoreCallingIdentity(identity); |
| 4251 | } |
| 4252 | } |
| 4253 | |
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4254 | |
| 4255 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4256 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4257 | message); |
| 4258 | } |
| 4259 | |
| 4260 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4261 | boolean isMmtelCapability) { |
| 4262 | Phone phone = getPhone(subId); |
| 4263 | if (phone == null) { |
| 4264 | loge("phone instance null for subid " + subId); |
| 4265 | return false; |
| 4266 | } |
| 4267 | if (isMmtelCapability) { |
| 4268 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4269 | return false; |
| 4270 | } |
| 4271 | } else { |
| 4272 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4273 | return false; |
| 4274 | } |
| 4275 | } |
| 4276 | return true; |
| 4277 | } |
| 4278 | |
| 4279 | @Override |
| 4280 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4281 | boolean isProvisioned) { |
| 4282 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4283 | |
| 4284 | final long identity = Binder.clearCallingIdentity(); |
| 4285 | try { |
| 4286 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4287 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4288 | return; |
| 4289 | } |
| 4290 | |
| 4291 | // this capability requires provisioning, route to the correct API. |
| 4292 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4293 | switch (capability) { |
| 4294 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4295 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4296 | ims.setEabProvisioned(isProvisioned); |
| 4297 | break; |
| 4298 | default: { |
| 4299 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4300 | + "rcs capability '" + capability + "', which does not require " |
| 4301 | + "provisioning."); |
| 4302 | } |
| 4303 | } |
| 4304 | } finally { |
| 4305 | Binder.restoreCallingIdentity(identity); |
| 4306 | } |
| 4307 | |
| 4308 | } |
| 4309 | |
| 4310 | |
| 4311 | @Override |
| 4312 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4313 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4314 | final long identity = Binder.clearCallingIdentity(); |
| 4315 | try { |
| 4316 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4317 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4318 | return true; |
| 4319 | } |
| 4320 | |
| 4321 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4322 | switch (capability) { |
| 4323 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4324 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4325 | return ims.isEabProvisionedOnDevice(); |
| 4326 | |
| 4327 | default: { |
| 4328 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4329 | + "capability '" + capability + "', which does not require " |
| 4330 | + "provisioning."); |
| 4331 | } |
| 4332 | } |
| 4333 | |
| 4334 | } finally { |
| 4335 | Binder.restoreCallingIdentity(identity); |
| 4336 | } |
| 4337 | } |
| 4338 | |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4339 | @Override |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4340 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4341 | boolean isProvisioned) { |
| 4342 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4343 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4344 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4345 | } |
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4346 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4347 | final long identity = Binder.clearCallingIdentity(); |
| 4348 | try { |
| 4349 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4350 | if (!isImsProvisioningRequired(subId, capability, true)) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4351 | return; |
| 4352 | } |
| 4353 | |
| 4354 | // this capability requires provisioning, route to the correct API. |
| 4355 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4356 | switch (capability) { |
| 4357 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4358 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4359 | ims.setVolteProvisioned(isProvisioned); |
| 4360 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4361 | ims.setWfcProvisioned(isProvisioned); |
| 4362 | } |
| 4363 | break; |
| 4364 | } |
| 4365 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4366 | // There is currently no difference in VT provisioning type. |
| 4367 | ims.setVtProvisioned(isProvisioned); |
| 4368 | break; |
| 4369 | } |
| 4370 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4371 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4372 | // change the capability of the feature instead if needed. |
| 4373 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4374 | == isProvisioned) { |
| 4375 | // No change in provisioning. |
| 4376 | return; |
| 4377 | } |
| 4378 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4379 | try { |
| 4380 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4381 | } catch (com.android.ims.ImsException e) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4382 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4383 | + ", Exception" + e.getMessage()); |
| 4384 | } |
| 4385 | break; |
| 4386 | } |
| 4387 | default: { |
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4388 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4389 | + "MmTel capability '" + capability + "', which does not require " |
| 4390 | + "provisioning. "); |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4391 | } |
| 4392 | } |
| 4393 | |
| 4394 | } finally { |
| 4395 | Binder.restoreCallingIdentity(identity); |
| 4396 | } |
| 4397 | } |
| 4398 | |
| 4399 | @Override |
| 4400 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4401 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4402 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4403 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4404 | } |
| 4405 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4406 | final long identity = Binder.clearCallingIdentity(); |
| 4407 | try { |
| 4408 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4409 | if (!isImsProvisioningRequired(subId, capability, true)) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4410 | return true; |
| 4411 | } |
| 4412 | |
| 4413 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4414 | switch (capability) { |
| 4415 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4416 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4417 | return ims.isVolteProvisionedOnDevice(); |
| 4418 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4419 | return ims.isWfcProvisionedOnDevice(); |
| 4420 | } |
| 4421 | // This should never happen, since we are checking tech above to make sure it |
| 4422 | // is either LTE or IWLAN. |
| 4423 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4424 | + "capability."); |
| 4425 | } |
| 4426 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4427 | // There is currently no difference in VT provisioning type. |
| 4428 | return ims.isVtProvisionedOnDevice(); |
| 4429 | } |
| 4430 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4431 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4432 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4433 | } |
| 4434 | default: { |
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4435 | throw new IllegalArgumentException( |
| 4436 | "Tried to get provisioning for MmTel capability '" + capability |
| 4437 | + "', which does not require provisioning."); |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4438 | } |
| 4439 | } |
| 4440 | |
| 4441 | } finally { |
| 4442 | Binder.restoreCallingIdentity(identity); |
| 4443 | } |
| 4444 | } |
| 4445 | |
| 4446 | @Override |
| 4447 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4448 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4449 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4450 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4451 | } |
| 4452 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4453 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4454 | return (provisionedBits & capability) > 0; |
| 4455 | } |
| 4456 | |
| 4457 | @Override |
| 4458 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4459 | boolean isProvisioned) { |
| 4460 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4461 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4462 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4463 | } |
| 4464 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4465 | "setProvisioningStatusForCapability"); |
| 4466 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4467 | // If the current provisioning status for capability already matches isProvisioned, |
| 4468 | // do nothing. |
| 4469 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4470 | return; |
| 4471 | } |
| 4472 | if (isProvisioned) { |
| 4473 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4474 | } else { |
| 4475 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4476 | } |
| 4477 | } |
| 4478 | |
| 4479 | /** |
| 4480 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4481 | * technology. The bitfield should mirror the bitfield defined by |
| 4482 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4483 | */ |
| 4484 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4485 | String key = getMmTelProvisioningKey(subId, tech); |
| 4486 | // Default is no capabilities are provisioned. |
| 4487 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4488 | } |
| 4489 | |
| 4490 | /** |
| 4491 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4492 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4493 | * technology specified. |
| 4494 | * |
| 4495 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4496 | */ |
| 4497 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4498 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4499 | String key = getMmTelProvisioningKey(subId, tech); |
| 4500 | editor.putInt(key, newField); |
| 4501 | editor.commit(); |
| 4502 | } |
| 4503 | |
| 4504 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4505 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4506 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4507 | } |
| 4508 | |
| 4509 | /** |
| 4510 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4511 | * carrier associated with the subscription id. |
| 4512 | */ |
| 4513 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4514 | int capability) { |
| 4515 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4516 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4517 | boolean requireUtProvisioning = c.getBoolean( |
| Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4518 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4519 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4520 | false); |
| 4521 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4522 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4523 | |
| 4524 | // First check to make sure that the capability requires provisioning. |
| 4525 | switch (capability) { |
| 4526 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4527 | // intentional fallthrough |
| 4528 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4529 | if (requireVoiceVtProvisioning) { |
| 4530 | // Voice and Video requires provisioning |
| 4531 | return true; |
| 4532 | } |
| 4533 | break; |
| 4534 | } |
| 4535 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4536 | if (requireUtProvisioning) { |
| 4537 | // UT requires provisioning |
| 4538 | return true; |
| 4539 | } |
| 4540 | break; |
| 4541 | } |
| 4542 | } |
| 4543 | return false; |
| 4544 | } |
| 4545 | |
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4546 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4547 | int capability) { |
| 4548 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4549 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4550 | |
| 4551 | boolean requireRcsProvisioning = c.getBoolean( |
| 4552 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4553 | |
| 4554 | // First check to make sure that the capability requires provisioning. |
| 4555 | switch (capability) { |
| 4556 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4557 | // intentional fallthrough |
| 4558 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4559 | if (requireRcsProvisioning) { |
| 4560 | // OPTION or PRESENCE requires provisioning |
| 4561 | return true; |
| 4562 | } |
| 4563 | break; |
| 4564 | } |
| 4565 | } |
| 4566 | return false; |
| 4567 | } |
| 4568 | |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4569 | @Override |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4570 | public int getImsProvisioningInt(int subId, int key) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4571 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4572 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4573 | } |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4574 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4575 | final long identity = Binder.clearCallingIdentity(); |
| 4576 | try { |
| 4577 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4578 | int slotId = getSlotIndex(subId); |
| 4579 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4580 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4581 | + subId + "' for key:" + key); |
| 4582 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4583 | } |
| 4584 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4585 | } catch (com.android.ims.ImsException e) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4586 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4587 | + subId + "' for key:" + key); |
| 4588 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4589 | } finally { |
| 4590 | Binder.restoreCallingIdentity(identity); |
| 4591 | } |
| 4592 | } |
| 4593 | |
| 4594 | @Override |
| 4595 | public String getImsProvisioningString(int subId, int key) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4596 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4597 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4598 | } |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4599 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4600 | final long identity = Binder.clearCallingIdentity(); |
| 4601 | try { |
| 4602 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4603 | int slotId = getSlotIndex(subId); |
| 4604 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4605 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4606 | + subId + "' for key:" + key); |
| 4607 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4608 | } |
| 4609 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4610 | } catch (com.android.ims.ImsException e) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4611 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4612 | + subId + "' for key:" + key); |
| 4613 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4614 | } finally { |
| 4615 | Binder.restoreCallingIdentity(identity); |
| 4616 | } |
| 4617 | } |
| 4618 | |
| 4619 | @Override |
| 4620 | public int setImsProvisioningInt(int subId, int key, int value) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4621 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4622 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4623 | } |
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4625 | "setImsProvisioningInt"); |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4626 | final long identity = Binder.clearCallingIdentity(); |
| 4627 | try { |
| 4628 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4629 | int slotId = getSlotIndex(subId); |
| 4630 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4631 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4632 | + subId + "' for key:" + key); |
| 4633 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4634 | } |
| 4635 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4636 | } catch (com.android.ims.ImsException e) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4637 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4638 | + "' for key:" + key); |
| 4639 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4640 | } finally { |
| 4641 | Binder.restoreCallingIdentity(identity); |
| 4642 | } |
| 4643 | } |
| 4644 | |
| 4645 | @Override |
| 4646 | public int setImsProvisioningString(int subId, int key, String value) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4647 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4648 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4649 | } |
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4650 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4651 | "setImsProvisioningString"); |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4652 | final long identity = Binder.clearCallingIdentity(); |
| 4653 | try { |
| 4654 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4655 | int slotId = getSlotIndex(subId); |
| 4656 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4657 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4658 | + subId + "' for key:" + key); |
| 4659 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4660 | } |
| 4661 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4662 | } catch (com.android.ims.ImsException e) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4663 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4664 | + "' for key:" + key); |
| 4665 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4666 | } finally { |
| 4667 | Binder.restoreCallingIdentity(identity); |
| 4668 | } |
| 4669 | } |
| 4670 | |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4671 | private int getSlotIndexOrException(int subId) throws ImsException { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4672 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4673 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4674 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4675 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4676 | } |
| 4677 | return slotId; |
| 4678 | } |
| 4679 | |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4680 | private int getSlotIndex(int subId) { |
| 4681 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4682 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4683 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4684 | } |
| 4685 | return slotId; |
| 4686 | } |
| 4687 | |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4688 | /** |
| Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4689 | * Returns the data network type for a subId; does not throw SecurityException. |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4690 | */ |
| 4691 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4692 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4693 | String callingFeatureId) { |
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4694 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
| Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4695 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4696 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
| Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4697 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
| Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4698 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4699 | mApp, subId, callingPackage, callingFeatureId, |
| 4700 | "getNetworkTypeForSubscriber")) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4701 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4702 | } |
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4703 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4704 | final long identity = Binder.clearCallingIdentity(); |
| 4705 | try { |
| 4706 | final Phone phone = getPhone(subId); |
| 4707 | if (phone != null) { |
| 4708 | return phone.getServiceState().getDataNetworkType(); |
| 4709 | } else { |
| 4710 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4711 | } |
| 4712 | } finally { |
| 4713 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4714 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | /** |
| 4718 | * Returns the data network type |
| 4719 | */ |
| 4720 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4721 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4722 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4723 | callingFeatureId); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4724 | } |
| 4725 | |
| 4726 | /** |
| 4727 | * Returns the data network type for a subId |
| 4728 | */ |
| 4729 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4730 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4731 | String callingFeatureId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4732 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4733 | mApp, subId, callingPackage, callingFeatureId, |
| 4734 | "getDataNetworkTypeForSubscriber")) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4735 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4736 | } |
| 4737 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4738 | final long identity = Binder.clearCallingIdentity(); |
| 4739 | try { |
| 4740 | final Phone phone = getPhone(subId); |
| 4741 | if (phone != null) { |
| 4742 | return phone.getServiceState().getDataNetworkType(); |
| 4743 | } else { |
| 4744 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4745 | } |
| 4746 | } finally { |
| 4747 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4748 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4749 | } |
| 4750 | |
| 4751 | /** |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4752 | * Returns the Voice network type for a subId |
| 4753 | */ |
| 4754 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4755 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4756 | String callingFeatureId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4757 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4758 | mApp, subId, callingPackage, callingFeatureId, |
| 4759 | "getDataNetworkTypeForSubscriber")) { |
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4760 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4761 | } |
| 4762 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4763 | final long identity = Binder.clearCallingIdentity(); |
| 4764 | try { |
| 4765 | final Phone phone = getPhone(subId); |
| 4766 | if (phone != null) { |
| 4767 | return phone.getServiceState().getVoiceNetworkType(); |
| 4768 | } else { |
| 4769 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4770 | } |
| 4771 | } finally { |
| 4772 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4773 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4774 | } |
| 4775 | |
| 4776 | /** |
| 4777 | * @return true if a ICC card is present |
| 4778 | */ |
| 4779 | public boolean hasIccCard() { |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4780 | // FIXME Make changes to pass defaultSimId of type int |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4781 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4782 | getDefaultSubscription())); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | /** |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4786 | * @return true if a ICC card is present for a slotIndex |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4787 | */ |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4788 | @Override |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4789 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4790 | final long identity = Binder.clearCallingIdentity(); |
| 4791 | try { |
| 4792 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4793 | if (phone != null) { |
| 4794 | return phone.getIccCard().hasIccCard(); |
| 4795 | } else { |
| 4796 | return false; |
| 4797 | } |
| 4798 | } finally { |
| 4799 | Binder.restoreCallingIdentity(identity); |
| Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4800 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4801 | } |
| 4802 | |
| 4803 | /** |
| 4804 | * Return if the current radio is LTE on CDMA. This |
| 4805 | * is a tri-state return value as for a period of time |
| 4806 | * the mode may be unknown. |
| 4807 | * |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4808 | * @param callingPackage the name of the package making the call. |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4809 | * @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] | 4810 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4811 | */ |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4812 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4813 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4814 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4815 | callingFeatureId); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4816 | } |
| 4817 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4818 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4819 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4820 | String callingFeatureId) { |
| Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4821 | try { |
| 4822 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4823 | } catch (SecurityException e) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4824 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4825 | } |
| 4826 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4827 | final long identity = Binder.clearCallingIdentity(); |
| 4828 | try { |
| 4829 | final Phone phone = getPhone(subId); |
| 4830 | if (phone == null) { |
| 4831 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4832 | } else { |
| Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4833 | return TelephonyProperties.lte_on_cdma_device() |
| 4834 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4835 | } |
| 4836 | } finally { |
| 4837 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4838 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4839 | } |
| 4840 | |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4841 | /** |
| 4842 | * {@hide} |
| 4843 | * Returns Default subId, 0 in the case of single standby. |
| 4844 | */ |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4845 | private int getDefaultSubscription() { |
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4846 | return mSubscriptionController.getDefaultSubId(); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4847 | } |
| 4848 | |
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4849 | private int getSlotForDefaultSubscription() { |
| 4850 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4851 | } |
| 4852 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4853 | private int getPreferredVoiceSubscription() { |
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4854 | return mSubscriptionController.getDefaultVoiceSubId(); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4855 | } |
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4856 | |
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4857 | private boolean isActiveSubscription(int subId) { |
| 4858 | return mSubscriptionController.isActiveSubId(subId); |
| 4859 | } |
| 4860 | |
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4861 | /** |
| 4862 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4863 | */ |
| 4864 | public int getWhenToMakeWifiCalls() { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4865 | final long identity = Binder.clearCallingIdentity(); |
| 4866 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4867 | return Settings.System.getInt(mApp.getContentResolver(), |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4868 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4869 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4870 | } finally { |
| 4871 | Binder.restoreCallingIdentity(identity); |
| 4872 | } |
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4873 | } |
| 4874 | |
| 4875 | /** |
| 4876 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4877 | */ |
| 4878 | public void setWhenToMakeWifiCalls(int preference) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4879 | final long identity = Binder.clearCallingIdentity(); |
| 4880 | try { |
| 4881 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4882 | Settings.System.putInt(mApp.getContentResolver(), |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4883 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4884 | } finally { |
| 4885 | Binder.restoreCallingIdentity(identity); |
| 4886 | } |
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4887 | } |
| 4888 | |
| Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4889 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
| Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4890 | // TODO: Use a build property to choose this value. |
| Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4891 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4892 | } |
| Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4893 | |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4894 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4895 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4896 | if (phoneId == -1) { |
| 4897 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4898 | + " does not correspond to an active phone"); |
| 4899 | } |
| 4900 | return PhoneFactory.getPhone(phoneId); |
| 4901 | } |
| 4902 | |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4903 | @Override |
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4904 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4905 | int subId, String callingPackage, String aid, int p2) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4906 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4907 | mApp, subId, "iccOpenLogicalChannel"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4908 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4909 | if (DBG) { |
| 4910 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4911 | } |
| 4912 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4913 | p2); |
| 4914 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4915 | |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4916 | |
| 4917 | @Override |
| 4918 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4919 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4920 | enforceModifyPermission(); |
| 4921 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4922 | if (DBG) { |
| 4923 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4924 | } |
| 4925 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4926 | callingPackage, aid, p2); |
| 4927 | } |
| 4928 | |
| 4929 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4930 | String callingPackage, String aid, int p2) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4931 | final long identity = Binder.clearCallingIdentity(); |
| 4932 | try { |
| 4933 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4934 | // Only allows LPA to open logical channel to ISD-R. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4935 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4936 | .getContext().getPackageManager()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4937 | if (bestComponent == null |
| 4938 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4939 | loge("The calling package is not allowed to access ISD-R."); |
| 4940 | throw new SecurityException( |
| 4941 | "The calling package is not allowed to access ISD-R."); |
| 4942 | } |
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4943 | } |
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4944 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4945 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4946 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4947 | null /* workSource */); |
| 4948 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4949 | return response; |
| 4950 | } finally { |
| 4951 | Binder.restoreCallingIdentity(identity); |
| 4952 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4953 | } |
| 4954 | |
| 4955 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4956 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4957 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4958 | mApp, subId, "iccCloseLogicalChannel"); |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4959 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4960 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4961 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4962 | |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4963 | @Override |
| 4964 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4965 | enforceModifyPermission(); |
| 4966 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4967 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4968 | channel); |
| 4969 | } |
| 4970 | |
| 4971 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4972 | final long identity = Binder.clearCallingIdentity(); |
| 4973 | try { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4974 | if (channel < 0) { |
| 4975 | return false; |
| 4976 | } |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4977 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4978 | null /* workSource */); |
| 4979 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4980 | return success; |
| 4981 | } finally { |
| 4982 | Binder.restoreCallingIdentity(identity); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4983 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4984 | } |
| 4985 | |
| 4986 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4987 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4988 | int command, int p1, int p2, int p3, String data) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4989 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4990 | mApp, subId, "iccTransmitApduLogicalChannel"); |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4991 | if (DBG) { |
| 4992 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4993 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4994 | + p3 + " data=" + data); |
| 4995 | } |
| 4996 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4997 | command, p1, p2, p3, data); |
| 4998 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4999 | |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5000 | @Override |
| 5001 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5002 | int command, int p1, int p2, int p3, String data) { |
| 5003 | enforceModifyPermission(); |
| 5004 | if (DBG) { |
| 5005 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5006 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5007 | + p3 + " data=" + data); |
| 5008 | } |
| 5009 | return iccTransmitApduLogicalChannelWithPermission( |
| 5010 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5011 | data); |
| 5012 | } |
| 5013 | |
| 5014 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5015 | int command, int p1, int p2, int p3, String data) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5016 | final long identity = Binder.clearCallingIdentity(); |
| 5017 | try { |
| Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5018 | if (channel <= 0) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5019 | return ""; |
| 5020 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5021 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5022 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5023 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5024 | null /* workSource */); |
| 5025 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5026 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5027 | // Append the returned status code to the end of the response payload. |
| 5028 | String s = Integer.toHexString( |
| 5029 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5030 | if (response.payload != null) { |
| 5031 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5032 | } |
| 5033 | return s; |
| 5034 | } finally { |
| 5035 | Binder.restoreCallingIdentity(identity); |
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5036 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5037 | } |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5038 | |
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5039 | @Override |
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5040 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5041 | int command, int p1, int p2, int p3, String data) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5042 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5043 | mApp, subId, "iccTransmitApduBasicChannel"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5044 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5045 | if (DBG) { |
| 5046 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5047 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5048 | } |
| 5049 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5050 | cla, command, p1, p2, p3, data); |
| 5051 | } |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5052 | |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5053 | @Override |
| 5054 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5055 | int command, int p1, int p2, int p3, String data) { |
| 5056 | enforceModifyPermission(); |
| 5057 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5058 | if (DBG) { |
| 5059 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5060 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5061 | + " data=" + data); |
| 5062 | } |
| 5063 | |
| 5064 | return iccTransmitApduBasicChannelWithPermission( |
| 5065 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5066 | p2, p3, data); |
| 5067 | } |
| 5068 | |
| 5069 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5070 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5071 | int cla, int command, int p1, int p2, int p3, String data) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5072 | final long identity = Binder.clearCallingIdentity(); |
| 5073 | try { |
| 5074 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5075 | && TextUtils.equals(ISDR_AID, data)) { |
| 5076 | // Only allows LPA to select ISD-R. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5077 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5078 | .getContext().getPackageManager()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5079 | if (bestComponent == null |
| 5080 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5081 | loge("The calling package is not allowed to select ISD-R."); |
| 5082 | throw new SecurityException( |
| 5083 | "The calling package is not allowed to select ISD-R."); |
| 5084 | } |
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5085 | } |
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5086 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5087 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5088 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5089 | null /* workSource */); |
| 5090 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5091 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5092 | // Append the returned status code to the end of the response payload. |
| 5093 | String s = Integer.toHexString( |
| 5094 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5095 | if (response.payload != null) { |
| 5096 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5097 | } |
| 5098 | return s; |
| 5099 | } finally { |
| 5100 | Binder.restoreCallingIdentity(identity); |
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5101 | } |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5105 | 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] | 5106 | String filePath) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5107 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5108 | mApp, subId, "iccExchangeSimIO"); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5109 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5110 | final long identity = Binder.clearCallingIdentity(); |
| 5111 | try { |
| 5112 | if (DBG) { |
| 5113 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5114 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5115 | } |
| 5116 | |
| 5117 | IccIoResult response = |
| 5118 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5119 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5120 | subId); |
| 5121 | |
| 5122 | if (DBG) { |
| 5123 | log("Exchange SIM_IO [R]" + response); |
| 5124 | } |
| 5125 | |
| 5126 | byte[] result = null; |
| 5127 | int length = 2; |
| 5128 | if (response.payload != null) { |
| 5129 | length = 2 + response.payload.length; |
| 5130 | result = new byte[length]; |
| 5131 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5132 | } else { |
| 5133 | result = new byte[length]; |
| 5134 | } |
| 5135 | |
| 5136 | result[length - 1] = (byte) response.sw2; |
| 5137 | result[length - 2] = (byte) response.sw1; |
| 5138 | return result; |
| 5139 | } finally { |
| 5140 | Binder.restoreCallingIdentity(identity); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5141 | } |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5142 | } |
| 5143 | |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5144 | /** |
| 5145 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5146 | * on a particular subscription |
| 5147 | */ |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5148 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5149 | String callingFeatureId) { |
| sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5150 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5151 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
| sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5152 | return null; |
| 5153 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5154 | |
| 5155 | final long identity = Binder.clearCallingIdentity(); |
| 5156 | try { |
| 5157 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5158 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5159 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5160 | return null; |
| 5161 | } |
| 5162 | Object response = sendRequest( |
| 5163 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5164 | if (response instanceof String[]) { |
| 5165 | return (String[]) response; |
| 5166 | } |
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5167 | // Response is an Exception of some kind |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5168 | // which is signalled to the user as a NULL retval |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5169 | return null; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5170 | } finally { |
| 5171 | Binder.restoreCallingIdentity(identity); |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5172 | } |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5173 | } |
| 5174 | |
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5175 | /** |
| 5176 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5177 | * subscription. |
| 5178 | * |
| 5179 | * @param subId the id of the subscription. |
| 5180 | * @param appType the uicc app type, must be USIM or SIM. |
| 5181 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5182 | * @param callingPackage the op Package name. |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5183 | * @param callingFeatureId the feature in the package. |
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5184 | * @return number of fplmns that is successfully written to the SIM. |
| 5185 | */ |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5186 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5187 | String callingFeatureId) { |
| 5188 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5189 | callingFeatureId, "setForbiddenPlmns")) { |
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5190 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5191 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5192 | } |
| 5193 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5194 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5195 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5196 | } |
| 5197 | if (fplmns == null) { |
| 5198 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5199 | } |
| 5200 | for (String fplmn : fplmns) { |
| 5201 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5202 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5203 | } |
| 5204 | } |
| 5205 | final long identity = Binder.clearCallingIdentity(); |
| 5206 | try { |
| 5207 | Object response = sendRequest( |
| 5208 | CMD_SET_FORBIDDEN_PLMNS, |
| 5209 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5210 | subId); |
| 5211 | return (int) response; |
| 5212 | } finally { |
| 5213 | Binder.restoreCallingIdentity(identity); |
| 5214 | } |
| 5215 | } |
| 5216 | |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5217 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5218 | public String sendEnvelopeWithStatus(int subId, String content) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5219 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5220 | mApp, subId, "sendEnvelopeWithStatus"); |
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5221 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5222 | final long identity = Binder.clearCallingIdentity(); |
| 5223 | try { |
| 5224 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5225 | if (response.payload == null) { |
| 5226 | return ""; |
| 5227 | } |
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5228 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5229 | // Append the returned status code to the end of the response payload. |
| 5230 | String s = Integer.toHexString( |
| 5231 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5232 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5233 | return s; |
| 5234 | } finally { |
| 5235 | Binder.restoreCallingIdentity(identity); |
| 5236 | } |
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5237 | } |
| 5238 | |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5239 | /** |
| 5240 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5241 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5242 | * |
| 5243 | * @param itemID the ID of the item to read |
| 5244 | * @return the NV item as a String, or null on error. |
| 5245 | */ |
| 5246 | @Override |
| 5247 | public String nvReadItem(int itemID) { |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5248 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5249 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5250 | mApp, getDefaultSubscription(), "nvReadItem"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5251 | |
| 5252 | final long identity = Binder.clearCallingIdentity(); |
| 5253 | try { |
| 5254 | if (DBG) log("nvReadItem: item " + itemID); |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5255 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5256 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5257 | return value; |
| 5258 | } finally { |
| 5259 | Binder.restoreCallingIdentity(identity); |
| 5260 | } |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5261 | } |
| 5262 | |
| 5263 | /** |
| 5264 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5265 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5266 | * |
| 5267 | * @param itemID the ID of the item to read |
| 5268 | * @param itemValue the value to write, as a String |
| 5269 | * @return true on success; false on any failure |
| 5270 | */ |
| 5271 | @Override |
| 5272 | public boolean nvWriteItem(int itemID, String itemValue) { |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5273 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5274 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5275 | mApp, getDefaultSubscription(), "nvWriteItem"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5276 | |
| 5277 | final long identity = Binder.clearCallingIdentity(); |
| 5278 | try { |
| 5279 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5280 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5281 | new Pair<Integer, String>(itemID, itemValue), workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5282 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5283 | return success; |
| 5284 | } finally { |
| 5285 | Binder.restoreCallingIdentity(identity); |
| 5286 | } |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5287 | } |
| 5288 | |
| 5289 | /** |
| 5290 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5291 | * Used for device configuration by some CDMA operators. |
| 5292 | * |
| 5293 | * @param preferredRoamingList byte array containing the new PRL |
| 5294 | * @return true on success; false on any failure |
| 5295 | */ |
| 5296 | @Override |
| 5297 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5298 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5299 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5300 | |
| 5301 | final long identity = Binder.clearCallingIdentity(); |
| 5302 | try { |
| 5303 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5304 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5305 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5306 | return success; |
| 5307 | } finally { |
| 5308 | Binder.restoreCallingIdentity(identity); |
| 5309 | } |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | /** |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5313 | * 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] | 5314 | * Used for device configuration by some CDMA operators. |
| 5315 | * |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5316 | * @param slotIndex - device slot. |
| 5317 | * |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5318 | * @return true on success; false on any failure |
| 5319 | */ |
| 5320 | @Override |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5321 | public boolean resetModemConfig(int slotIndex) { |
| 5322 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5323 | if (phone != null) { |
| 5324 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5325 | mApp, phone.getSubId(), "resetModemConfig"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5326 | |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5327 | final long identity = Binder.clearCallingIdentity(); |
| 5328 | try { |
| 5329 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5330 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5331 | return success; |
| 5332 | } finally { |
| 5333 | Binder.restoreCallingIdentity(identity); |
| 5334 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5335 | } |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5336 | return false; |
| 5337 | } |
| 5338 | |
| 5339 | /** |
| 5340 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5341 | * |
| 5342 | * @param slotIndex - device slot. |
| 5343 | * |
| 5344 | * @return true on success; false on any failure |
| 5345 | */ |
| 5346 | @Override |
| 5347 | public boolean rebootModem(int slotIndex) { |
| 5348 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5349 | if (phone != null) { |
| 5350 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5351 | mApp, phone.getSubId(), "rebootModem"); |
| 5352 | |
| 5353 | final long identity = Binder.clearCallingIdentity(); |
| 5354 | try { |
| 5355 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5356 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5357 | return success; |
| 5358 | } finally { |
| 5359 | Binder.restoreCallingIdentity(identity); |
| 5360 | } |
| 5361 | } |
| 5362 | return false; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5363 | } |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5364 | |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5365 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5366 | String callingFeatureId) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5367 | final Phone defaultPhone = getDefaultPhone(); |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5368 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5369 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5370 | return new String[0]; |
| 5371 | } |
| 5372 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5373 | final long identity = Binder.clearCallingIdentity(); |
| 5374 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5375 | return defaultPhone.getPcscfAddress(apnType); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5376 | } finally { |
| 5377 | Binder.restoreCallingIdentity(identity); |
| 5378 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5379 | } |
| 5380 | |
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5381 | /** |
| Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5382 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5383 | * {@link #disableIms(int)}. |
| 5384 | * @param slotIndex device slot. |
| 5385 | */ |
| 5386 | public void resetIms(int slotIndex) { |
| 5387 | enforceModifyPermission(); |
| 5388 | |
| 5389 | final long identity = Binder.clearCallingIdentity(); |
| 5390 | try { |
| 5391 | if (mImsResolver == null) { |
| 5392 | // may happen if the does not support IMS. |
| 5393 | return; |
| 5394 | } |
| 5395 | mImsResolver.disableIms(slotIndex); |
| 5396 | mImsResolver.enableIms(slotIndex); |
| 5397 | } finally { |
| 5398 | Binder.restoreCallingIdentity(identity); |
| 5399 | } |
| 5400 | } |
| 5401 | |
| 5402 | /** |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5403 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5404 | * status updates, if not already enabled. |
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5405 | */ |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5406 | public void enableIms(int slotId) { |
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5407 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5408 | |
| 5409 | final long identity = Binder.clearCallingIdentity(); |
| 5410 | try { |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5411 | if (mImsResolver == null) { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5412 | // may happen if the device does not support IMS. |
| 5413 | return; |
| 5414 | } |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5415 | mImsResolver.enableIms(slotId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5416 | } finally { |
| 5417 | Binder.restoreCallingIdentity(identity); |
| 5418 | } |
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5419 | } |
| 5420 | |
| 5421 | /** |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5422 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5423 | * status updates to disabled. |
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5424 | */ |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5425 | public void disableIms(int slotId) { |
| 5426 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5427 | |
| 5428 | final long identity = Binder.clearCallingIdentity(); |
| 5429 | try { |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5430 | if (mImsResolver == null) { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5431 | // may happen if the device does not support IMS. |
| 5432 | return; |
| 5433 | } |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5434 | mImsResolver.disableIms(slotId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5435 | } finally { |
| 5436 | Binder.restoreCallingIdentity(identity); |
| 5437 | } |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | /** |
| Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5441 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5442 | * callback. |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5443 | */ |
| Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5444 | @Override |
| Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5445 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5446 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5447 | |
| 5448 | final long identity = Binder.clearCallingIdentity(); |
| 5449 | try { |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5450 | if (mImsResolver == null) { |
| Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5451 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5452 | "Device does not support IMS"); |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5453 | } |
| Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5454 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5455 | } finally { |
| 5456 | Binder.restoreCallingIdentity(identity); |
| 5457 | } |
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5458 | } |
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5459 | /** |
| Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5460 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5461 | */ |
| Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5462 | @Override |
| 5463 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
| Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5464 | enforceModifyPermission(); |
| 5465 | |
| 5466 | final long identity = Binder.clearCallingIdentity(); |
| 5467 | try { |
| 5468 | if (mImsResolver == null) return; |
| Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5469 | mImsResolver.unregisterImsFeatureCallback(callback); |
| Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5470 | } finally { |
| 5471 | Binder.restoreCallingIdentity(identity); |
| 5472 | } |
| 5473 | } |
| 5474 | |
| 5475 | /** |
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5476 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5477 | * specified or null if IMS is not supported on the slot specified. |
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5478 | */ |
| 5479 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5480 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5481 | |
| 5482 | final long identity = Binder.clearCallingIdentity(); |
| 5483 | try { |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5484 | if (mImsResolver == null) { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5485 | // may happen if the device does not support IMS. |
| 5486 | return null; |
| 5487 | } |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5488 | return mImsResolver.getImsRegistration(slotId, feature); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5489 | } finally { |
| 5490 | Binder.restoreCallingIdentity(identity); |
| 5491 | } |
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5492 | } |
| 5493 | |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5494 | /** |
| 5495 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5496 | * specified or null if IMS is not supported on the slot specified. |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5497 | */ |
| 5498 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5499 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5500 | |
| 5501 | final long identity = Binder.clearCallingIdentity(); |
| 5502 | try { |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5503 | if (mImsResolver == null) { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5504 | // may happen if the device does not support IMS. |
| 5505 | return null; |
| 5506 | } |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5507 | return mImsResolver.getImsConfig(slotId, feature); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5508 | } finally { |
| 5509 | Binder.restoreCallingIdentity(identity); |
| 5510 | } |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5511 | } |
| 5512 | |
| Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5513 | /** |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5514 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5515 | * |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5516 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5517 | * @param isCarrierService true if the ImsService is the carrier override, false if the |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5518 | * ImsService is the device default ImsService. |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5519 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5520 | * @param packageName The name of the package that the current configuration will be replaced |
| 5521 | * with. |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5522 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5523 | */ |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5524 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5525 | int[] featureTypes, String packageName) { |
| 5526 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5527 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5528 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5529 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5530 | "setBoundImsServiceOverride"); |
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5531 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5532 | final long identity = Binder.clearCallingIdentity(); |
| 5533 | try { |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5534 | if (mImsResolver == null) { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5535 | // may happen if the device does not support IMS. |
| 5536 | return false; |
| 5537 | } |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5538 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5539 | for (int featureType : featureTypes) { |
| 5540 | featureConfig.put(featureType, packageName); |
| 5541 | } |
| 5542 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5543 | featureConfig); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5544 | } finally { |
| 5545 | Binder.restoreCallingIdentity(identity); |
| 5546 | } |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5547 | } |
| 5548 | |
| 5549 | /** |
| Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5550 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5551 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5552 | * |
| 5553 | * This should only be used for testing. |
| 5554 | * |
| 5555 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5556 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5557 | */ |
| 5558 | @Override |
| 5559 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5560 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5561 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5562 | "clearCarrierImsServiceOverride"); |
| 5563 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5564 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5565 | "clearCarrierImsServiceOverride"); |
| 5566 | |
| 5567 | final long identity = Binder.clearCallingIdentity(); |
| 5568 | try { |
| 5569 | if (mImsResolver == null) { |
| 5570 | // may happen if the device does not support IMS. |
| 5571 | return false; |
| 5572 | } |
| 5573 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5574 | } finally { |
| 5575 | Binder.restoreCallingIdentity(identity); |
| 5576 | } |
| 5577 | } |
| 5578 | |
| 5579 | /** |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5580 | * Return the package name of the currently bound ImsService. |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5581 | * |
| 5582 | * @param slotId The slot that the ImsService is associated with. |
| 5583 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5584 | * the device default. |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5585 | * @param featureType The feature associated with the queried configuration. |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5586 | * @return the package name of the ImsService configuration. |
| 5587 | */ |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5588 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5589 | @ImsFeature.FeatureType int featureType) { |
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5590 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5591 | TelephonyPermissions |
| 5592 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5593 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5594 | "getBoundImsServicePackage"); |
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5595 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5596 | final long identity = Binder.clearCallingIdentity(); |
| 5597 | try { |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5598 | if (mImsResolver == null) { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5599 | // may happen if the device does not support IMS. |
| 5600 | return ""; |
| 5601 | } |
| Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5602 | // TODO: change API to query RCS separately. |
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5603 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5604 | featureType); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5605 | } finally { |
| 5606 | Binder.restoreCallingIdentity(identity); |
| 5607 | } |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5608 | } |
| 5609 | |
| Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5610 | /** |
| 5611 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5612 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5613 | * @param callback A callback with an integer containing the |
| 5614 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5615 | */ |
| 5616 | @Override |
| 5617 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5618 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5619 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5620 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5621 | "IMS not available on device."); |
| 5622 | } |
| 5623 | final long token = Binder.clearCallingIdentity(); |
| 5624 | try { |
| 5625 | int slotId = getSlotIndex(subId); |
| 5626 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5627 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5628 | + subId + "'"); |
| 5629 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5630 | } |
| 5631 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5632 | try { |
| 5633 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5634 | } catch (RemoteException e) { |
| 5635 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5636 | + "Ignore"); |
| 5637 | } |
| 5638 | }); |
| 5639 | } finally { |
| 5640 | Binder.restoreCallingIdentity(token); |
| 5641 | } |
| 5642 | } |
| 5643 | |
| Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5644 | /** |
| 5645 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5646 | */ |
| 5647 | public void setImsRegistrationState(final boolean registered) { |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5648 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5649 | |
| 5650 | final long identity = Binder.clearCallingIdentity(); |
| 5651 | try { |
| Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5652 | // NOTE: Before S, this method only set the default phone. |
| 5653 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5654 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5655 | phone.setImsRegistrationState(registered); |
| 5656 | } |
| 5657 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5658 | } finally { |
| 5659 | Binder.restoreCallingIdentity(identity); |
| 5660 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5661 | } |
| 5662 | |
| 5663 | /** |
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5664 | * Set the network selection mode to automatic. |
| 5665 | * |
| 5666 | */ |
| 5667 | @Override |
| 5668 | public void setNetworkSelectionModeAutomatic(int subId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5669 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5670 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5671 | |
| 5672 | final long identity = Binder.clearCallingIdentity(); |
| 5673 | try { |
| shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5674 | if (!isActiveSubscription(subId)) { |
| 5675 | return; |
| 5676 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5677 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5678 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5679 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5680 | } finally { |
| 5681 | Binder.restoreCallingIdentity(identity); |
| 5682 | } |
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5683 | } |
| 5684 | |
| Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5685 | /** |
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5686 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5687 | * |
| 5688 | * @param subId the id of the subscription. |
| 5689 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5690 | * the operator to attach to. |
| 5691 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5692 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5693 | * normal network selection next time. |
| 5694 | * @return {@code true} on success; {@code true} on any failure. |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5695 | */ |
| 5696 | @Override |
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5697 | public boolean setNetworkSelectionModeManual( |
| 5698 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5699 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5700 | mApp, subId, "setNetworkSelectionModeManual"); |
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5701 | |
| 5702 | if (!isActiveSubscription(subId)) { |
| 5703 | return false; |
| 5704 | } |
| 5705 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5706 | final long identity = Binder.clearCallingIdentity(); |
| 5707 | try { |
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5708 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5709 | persistSelection); |
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5710 | if (DBG) { |
| 5711 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5712 | + " operator: " + operatorInfo); |
| 5713 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5714 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5715 | } finally { |
| 5716 | Binder.restoreCallingIdentity(identity); |
| 5717 | } |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5718 | } |
| shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5719 | /** |
| 5720 | * Get the manual network selection |
| 5721 | * |
| 5722 | * @param subId the id of the subscription. |
| 5723 | * |
| 5724 | * @return the previously saved user selected PLMN |
| 5725 | */ |
| 5726 | @Override |
| 5727 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5728 | TelephonyPermissions |
| 5729 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5730 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5731 | |
| 5732 | final long identity = Binder.clearCallingIdentity(); |
| 5733 | try { |
| 5734 | if (!isActiveSubscription(subId)) { |
| 5735 | return ""; |
| 5736 | } |
| 5737 | |
| 5738 | final Phone phone = getPhone(subId); |
| 5739 | if (phone == null) { |
| 5740 | return ""; |
| 5741 | } |
| 5742 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5743 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5744 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5745 | } finally { |
| 5746 | Binder.restoreCallingIdentity(identity); |
| 5747 | } |
| 5748 | } |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5749 | |
| 5750 | /** |
| 5751 | * Scans for available networks. |
| 5752 | */ |
| 5753 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5754 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5755 | String callingFeatureId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5756 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5757 | mApp, subId, "getCellNetworkScanResults"); |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5758 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5759 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5760 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5761 | .setCallingPackage(callingPackage) |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5762 | .setCallingFeatureId(callingFeatureId) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5763 | .setCallingPid(Binder.getCallingPid()) |
| 5764 | .setCallingUid(Binder.getCallingUid()) |
| 5765 | .setMethod("getCellNetworkScanResults") |
| 5766 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5767 | .build()); |
| 5768 | switch (locationResult) { |
| 5769 | case DENIED_HARD: |
| 5770 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5771 | case DENIED_SOFT: |
| 5772 | return null; |
| 5773 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5774 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5775 | long identity = Binder.clearCallingIdentity(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5776 | try { |
| 5777 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5778 | return (CellNetworkScanResult) sendRequest( |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5779 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | } finally { |
| 5781 | Binder.restoreCallingIdentity(identity); |
| 5782 | } |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5783 | } |
| 5784 | |
| 5785 | /** |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5786 | * Get the call forwarding info, given the call forwarding reason. |
| 5787 | */ |
| 5788 | @Override |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5789 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5790 | ICallForwardingInfoCallback callback) { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5791 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5792 | long identity = Binder.clearCallingIdentity(); |
| 5793 | try { |
| 5794 | if (DBG) { |
| 5795 | log("getCallForwarding: subId " + subId |
| 5796 | + " callForwardingReason" + callForwardingReason); |
| 5797 | } |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5798 | |
| 5799 | Phone phone = getPhone(subId); |
| 5800 | if (phone == null) { |
| 5801 | try { |
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5802 | callback.onError( |
| 5803 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5804 | } catch (RemoteException e) { |
| 5805 | // ignore |
| 5806 | } |
| 5807 | return; |
| 5808 | } |
| 5809 | |
| 5810 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5811 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5812 | @Override |
| 5813 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5814 | try { |
| 5815 | callback.onCallForwardingInfoAvailable(info); |
| 5816 | } catch (RemoteException e) { |
| 5817 | // ignore |
| 5818 | } |
| 5819 | } |
| 5820 | |
| 5821 | @Override |
| 5822 | public void onError(int error) { |
| 5823 | try { |
| 5824 | callback.onError(error); |
| 5825 | } catch (RemoteException e) { |
| 5826 | // ignore |
| 5827 | } |
| 5828 | } |
| 5829 | }); |
| 5830 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5831 | } finally { |
| 5832 | Binder.restoreCallingIdentity(identity); |
| 5833 | } |
| 5834 | } |
| 5835 | |
| 5836 | /** |
| 5837 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5838 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5839 | */ |
| 5840 | @Override |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5841 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5842 | IIntegerConsumer callback) { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5843 | enforceModifyPermission(); |
| 5844 | long identity = Binder.clearCallingIdentity(); |
| 5845 | try { |
| 5846 | if (DBG) { |
| 5847 | log("setCallForwarding: subId " + subId |
| 5848 | + " callForwardingInfo" + callForwardingInfo); |
| 5849 | } |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5850 | |
| 5851 | Phone phone = getPhone(subId); |
| 5852 | if (phone == null) { |
| 5853 | try { |
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5854 | callback.accept( |
| 5855 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5856 | } catch (RemoteException e) { |
| 5857 | // ignore |
| 5858 | } |
| 5859 | return; |
| 5860 | } |
| 5861 | |
| 5862 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5863 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5864 | |
| 5865 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5866 | } finally { |
| 5867 | Binder.restoreCallingIdentity(identity); |
| 5868 | } |
| 5869 | } |
| 5870 | |
| 5871 | /** |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5872 | * Get the call waiting status for a subId. |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5873 | */ |
| 5874 | @Override |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5875 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5876 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5877 | long identity = Binder.clearCallingIdentity(); |
| 5878 | try { |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5879 | |
| 5880 | Phone phone = getPhone(subId); |
| 5881 | if (phone == null) { |
| 5882 | try { |
| 5883 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5884 | } catch (RemoteException e) { |
| 5885 | // ignore |
| 5886 | } |
| 5887 | return; |
| 5888 | } |
| 5889 | |
| 5890 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5891 | |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5892 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5893 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5894 | } finally { |
| 5895 | Binder.restoreCallingIdentity(identity); |
| 5896 | } |
| 5897 | } |
| 5898 | |
| 5899 | /** |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5900 | * Sets whether call waiting is enabled for a given subId. |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5901 | */ |
| 5902 | @Override |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5903 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5904 | enforceModifyPermission(); |
| 5905 | long identity = Binder.clearCallingIdentity(); |
| 5906 | try { |
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5907 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5908 | |
| 5909 | Phone phone = getPhone(subId); |
| 5910 | if (phone == null) { |
| 5911 | try { |
| 5912 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5913 | } catch (RemoteException e) { |
| 5914 | // ignore |
| 5915 | } |
| 5916 | return; |
| 5917 | } |
| 5918 | |
| 5919 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5920 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5921 | |
| 5922 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5923 | } finally { |
| 5924 | Binder.restoreCallingIdentity(identity); |
| 5925 | } |
| 5926 | } |
| 5927 | |
| 5928 | /** |
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5929 | * Starts a new network scan and returns the id of this scan. |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5930 | * |
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5931 | * @param subId id of the subscription |
| 5932 | * @param request contains the radio access networks with bands/channels to scan |
| 5933 | * @param messenger callback messenger for scan results or errors |
| 5934 | * @param binder for the purpose of auto clean when the user thread crashes |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5935 | * @return the id of the requested scan which can be used to stop the scan. |
| 5936 | */ |
| 5937 | @Override |
| 5938 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5939 | IBinder binder, String callingPackage, String callingFeatureId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5940 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5941 | mApp, subId, "requestNetworkScan"); |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5942 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5943 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5944 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5945 | .setCallingPackage(callingPackage) |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5946 | .setCallingFeatureId(callingFeatureId) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5947 | .setCallingPid(Binder.getCallingPid()) |
| 5948 | .setCallingUid(Binder.getCallingUid()) |
| 5949 | .setMethod("requestNetworkScan") |
| 5950 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5951 | .build()); |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5952 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
| Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5953 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5954 | request, subId, callingPackage); |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5955 | if (e != null) { |
| 5956 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5957 | throw e; |
| 5958 | } else { |
| Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5959 | loge(e.getMessage()); |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5960 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5961 | } |
| 5962 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5963 | } |
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5964 | int callingUid = Binder.getCallingUid(); |
| 5965 | int callingPid = Binder.getCallingPid(); |
| Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5966 | final long identity = Binder.clearCallingIdentity(); |
| 5967 | try { |
| 5968 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5969 | request, messenger, binder, getPhone(subId), |
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5970 | callingUid, callingPid, callingPackage); |
| Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5971 | } finally { |
| 5972 | Binder.restoreCallingIdentity(identity); |
| 5973 | } |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5974 | } |
| 5975 | |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5976 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
| Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5977 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5978 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5979 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5980 | boolean hasNetworkScanPermission = |
| 5981 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5982 | == PERMISSION_GRANTED; |
| 5983 | |
| 5984 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5985 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5986 | + " for network scans without location access."); |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5987 | } |
| 5988 | |
| 5989 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5990 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5991 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5992 | return new SecurityException("Specific channels must not be" |
| 5993 | + " scanned without location access."); |
| 5994 | } |
| 5995 | } |
| 5996 | } |
| 5997 | |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5998 | return null; |
| 5999 | } |
| 6000 | |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6001 | /** |
| 6002 | * Stops an existing network scan with the given scanId. |
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6003 | * |
| 6004 | * @param subId id of the subscription |
| 6005 | * @param scanId id of the scan that needs to be stopped |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6006 | */ |
| 6007 | @Override |
| 6008 | public void stopNetworkScan(int subId, int scanId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6009 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6010 | mApp, subId, "stopNetworkScan"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6011 | |
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6012 | int callingUid = Binder.getCallingUid(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6013 | final long identity = Binder.clearCallingIdentity(); |
| 6014 | try { |
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6015 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6016 | } finally { |
| 6017 | Binder.restoreCallingIdentity(identity); |
| 6018 | } |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6019 | } |
| 6020 | |
| 6021 | /** |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6022 | * Get the allowed network types bitmask. |
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6023 | * |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6024 | * @return the allowed network types bitmask, defined in RILConstants.java. |
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6025 | */ |
| 6026 | @Override |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6027 | public int getAllowedNetworkTypesBitmask(int subId) { |
| Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6028 | TelephonyPermissions |
| 6029 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6030 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6031 | |
| 6032 | final long identity = Binder.clearCallingIdentity(); |
| 6033 | try { |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6034 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6035 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6036 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6037 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6038 | return networkTypesBitmask; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6039 | } finally { |
| 6040 | Binder.restoreCallingIdentity(identity); |
| 6041 | } |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6042 | } |
| 6043 | |
| 6044 | /** |
| Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6045 | * Get the allowed network types for certain reason. |
| 6046 | * |
| 6047 | * @param subId the id of the subscription. |
| 6048 | * @param reason the reason the allowed network type change is taking place |
| 6049 | * @return the allowed network types. |
| 6050 | */ |
| 6051 | @Override |
| 6052 | public long getAllowedNetworkTypesForReason(int subId, |
| 6053 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6054 | TelephonyPermissions |
| 6055 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6056 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6057 | final long identity = Binder.clearCallingIdentity(); |
| 6058 | try { |
| 6059 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6060 | } finally { |
| 6061 | Binder.restoreCallingIdentity(identity); |
| 6062 | } |
| 6063 | } |
| 6064 | |
| 6065 | /** |
| Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6066 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6067 | * @param subId subscription id of the sim card |
| 6068 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6069 | * This can be passed following states |
| 6070 | * <ol> |
| 6071 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6072 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6073 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6074 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6075 | * </ol> |
| 6076 | * @return operation result. |
| 6077 | */ |
| 6078 | @Override |
| 6079 | public int setNrDualConnectivityState(int subId, |
| 6080 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6081 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6082 | mApp, subId, "enableNRDualConnectivity"); |
| 6083 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6084 | final long identity = Binder.clearCallingIdentity(); |
| 6085 | try { |
| 6086 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6087 | nrDualConnectivityState, subId, |
| 6088 | workSource); |
| 6089 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6090 | return result; |
| 6091 | } finally { |
| 6092 | Binder.restoreCallingIdentity(identity); |
| 6093 | } |
| 6094 | } |
| 6095 | |
| 6096 | /** |
| 6097 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6098 | * @return true if dual connectivity is enabled else false |
| 6099 | */ |
| 6100 | @Override |
| 6101 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6102 | TelephonyPermissions |
| 6103 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6104 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6105 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6106 | final long identity = Binder.clearCallingIdentity(); |
| 6107 | try { |
| 6108 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6109 | null, subId, workSource); |
| 6110 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6111 | return isEnabled; |
| 6112 | } finally { |
| 6113 | Binder.restoreCallingIdentity(identity); |
| 6114 | } |
| 6115 | } |
| 6116 | |
| 6117 | /** |
| Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6118 | * get carrier bandwidth per primary and secondary carrier |
| 6119 | * @param subId subscription id of the sim card |
| 6120 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6121 | */ |
| 6122 | @Override |
| 6123 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6124 | TelephonyPermissions |
| 6125 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6126 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6127 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6128 | final long identity = Binder.clearCallingIdentity(); |
| 6129 | try { |
| 6130 | CarrierBandwidth carrierBandwidth = |
| 6131 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6132 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6133 | return carrierBandwidth; |
| 6134 | } finally { |
| 6135 | Binder.restoreCallingIdentity(identity); |
| 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | /** |
| Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6140 | * Set the allowed network types of the device and |
| 6141 | * provide the reason triggering the allowed network change. |
| 6142 | * |
| 6143 | * @param subId the id of the subscription. |
| 6144 | * @param reason the reason the allowed network type change is taking place |
| 6145 | * @param allowedNetworkTypes the allowed network types. |
| 6146 | * @return true on success; false on any failure. |
| 6147 | */ |
| 6148 | @Override |
| 6149 | public boolean setAllowedNetworkTypesForReason(int subId, |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6150 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6151 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
| Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6152 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6153 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6154 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
| 6155 | Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); |
| 6156 | return false; |
| 6157 | } |
| 6158 | |
| 6159 | if (DBG) { |
| 6160 | log("setAllowedNetworkTypesForReason: " + reason |
| 6161 | + " value: " + allowedNetworkTypes); |
| 6162 | } |
| Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6163 | final long identity = Binder.clearCallingIdentity(); |
| 6164 | try { |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6165 | Boolean success = (Boolean) sendRequest( |
| 6166 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6167 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6168 | |
| 6169 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6170 | return success; |
| Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6171 | } finally { |
| 6172 | Binder.restoreCallingIdentity(identity); |
| 6173 | } |
| 6174 | } |
| 6175 | |
| 6176 | /** |
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6177 | * Check whether DUN APN is required for tethering with subId. |
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6178 | * |
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6179 | * @param subId the id of the subscription to require tethering. |
| Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6180 | * @return {@code true} if DUN APN is required for tethering. |
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6181 | * @hide |
| 6182 | */ |
| 6183 | @Override |
| SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6184 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6185 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6186 | final long identity = Binder.clearCallingIdentity(); |
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6187 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6188 | try { |
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6189 | if (phone != null) { |
| 6190 | return phone.hasMatchedTetherApnSetting(); |
| 6191 | } else { |
| 6192 | return false; |
| 6193 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6194 | } finally { |
| 6195 | Binder.restoreCallingIdentity(identity); |
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6196 | } |
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | /** |
| Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6200 | * Enable or disable always reporting signal strength changes from radio. |
| 6201 | * |
| 6202 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6203 | */ |
| 6204 | @Override |
| 6205 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6206 | enforceModifyPermission(); |
| 6207 | enforceSystemCaller(); |
| 6208 | |
| 6209 | final long identity = Binder.clearCallingIdentity(); |
| 6210 | final Phone phone = getPhone(subId); |
| 6211 | try { |
| 6212 | if (phone != null) { |
| 6213 | if (DBG) { |
| 6214 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6215 | + " isEnable=" + isEnable); |
| 6216 | } |
| 6217 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6218 | } else { |
| 6219 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6220 | + subId); |
| 6221 | } |
| 6222 | } finally { |
| 6223 | Binder.restoreCallingIdentity(identity); |
| 6224 | } |
| 6225 | } |
| 6226 | |
| 6227 | /** |
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6228 | * Get the user enabled state of Mobile Data. |
| 6229 | * |
| 6230 | * TODO: remove and use isUserDataEnabled. |
| 6231 | * This can't be removed now because some vendor codes |
| 6232 | * calls through ITelephony directly while they should |
| 6233 | * use TelephonyManager. |
| 6234 | * |
| 6235 | * @return true on enabled |
| 6236 | */ |
| 6237 | @Override |
| 6238 | public boolean getDataEnabled(int subId) { |
| 6239 | return isUserDataEnabled(subId); |
| 6240 | } |
| 6241 | |
| 6242 | /** |
| 6243 | * Get whether mobile data is enabled per user setting. |
| 6244 | * |
| 6245 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6246 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6247 | * |
| Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6248 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6249 | * |
| 6250 | * @return {@code true} if data is enabled else {@code false} |
| 6251 | */ |
| 6252 | @Override |
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6253 | public boolean isUserDataEnabled(int subId) { |
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6254 | try { |
| 6255 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6256 | null); |
| 6257 | } catch (Exception e) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6258 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6259 | mApp, subId, "isUserDataEnabled"); |
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6260 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6261 | |
| 6262 | final long identity = Binder.clearCallingIdentity(); |
| 6263 | try { |
| 6264 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6265 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6266 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6267 | if (phone != null) { |
| 6268 | boolean retVal = phone.isUserDataEnabled(); |
| 6269 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6270 | return retVal; |
| 6271 | } else { |
| 6272 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6273 | return false; |
| 6274 | } |
| 6275 | } finally { |
| 6276 | Binder.restoreCallingIdentity(identity); |
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6277 | } |
| 6278 | } |
| 6279 | |
| 6280 | /** |
| Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6281 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6282 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6283 | * whether the network policy allows data connections. |
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6284 | * |
| Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6285 | * @return {@code true} if the overall data connection is capable; {@code false} if not. |
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6286 | */ |
| 6287 | @Override |
| 6288 | public boolean isDataEnabled(int subId) { |
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6289 | try { |
| 6290 | try { |
| 6291 | mApp.enforceCallingOrSelfPermission( |
| 6292 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6293 | null); |
| 6294 | } catch (Exception e) { |
| 6295 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6296 | "isDataEnabled"); |
| 6297 | } |
| 6298 | } catch (Exception e) { |
| 6299 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6300 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6301 | |
| 6302 | final long identity = Binder.clearCallingIdentity(); |
| 6303 | try { |
| 6304 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6305 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6306 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6307 | if (phone != null) { |
| Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6308 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6309 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6310 | return retVal; |
| 6311 | } else { |
| 6312 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6313 | return false; |
| 6314 | } |
| 6315 | } finally { |
| 6316 | Binder.restoreCallingIdentity(identity); |
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6317 | } |
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6318 | } |
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6319 | |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6320 | /** |
| 6321 | * Check if data is enabled for a specific reason |
| 6322 | * @param subId Subscription index |
| 6323 | * @param reason the reason the data enable change is taking place |
| 6324 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6325 | */ |
| 6326 | @Override |
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6327 | public boolean isDataEnabledForReason(int subId, |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6328 | @TelephonyManager.DataEnabledReason int reason) { |
| 6329 | try { |
| 6330 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6331 | null); |
| 6332 | } catch (Exception e) { |
| 6333 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6334 | "isDataEnabledForReason"); |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6335 | } |
| 6336 | |
| 6337 | |
| 6338 | final long identity = Binder.clearCallingIdentity(); |
| 6339 | try { |
| 6340 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6341 | if (DBG) { |
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6342 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6343 | + " reason=" + reason); |
| 6344 | } |
| 6345 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6346 | if (phone != null) { |
| 6347 | boolean retVal; |
| 6348 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6349 | retVal = phone.isUserDataEnabled(); |
| 6350 | } else { |
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6351 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6352 | } |
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6353 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6354 | return retVal; |
| 6355 | } else { |
| 6356 | if (DBG) { |
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6357 | loge("isDataEnabledForReason: no phone subId=" |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6358 | + subId + " retVal=false"); |
| 6359 | } |
| 6360 | return false; |
| 6361 | } |
| 6362 | } finally { |
| 6363 | Binder.restoreCallingIdentity(identity); |
| 6364 | } |
| 6365 | } |
| 6366 | |
| Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6367 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6368 | Phone phone) { |
| Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6369 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6370 | // Skip the check if it's one of these special uids |
| 6371 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6372 | } |
| 6373 | |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6374 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6375 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6376 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6377 | || subController == null) return privilegeFromSim; |
| 6378 | |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6379 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6380 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6381 | |
| 6382 | final long identity = Binder.clearCallingIdentity(); |
| 6383 | try { |
| Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6384 | int subId = phone.getSubId(); |
| 6385 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6386 | // A test override is in place for the privileges for this subId, so don't try to |
| 6387 | // read the subscription privileges. |
| 6388 | return privilegeFromSim; |
| 6389 | } |
| 6390 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6391 | SubscriptionManager subManager = (SubscriptionManager) |
| 6392 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6393 | for (String pkg : packages) { |
| 6394 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6395 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6396 | } |
| 6397 | } |
| 6398 | return privilegeFromSim; |
| 6399 | } finally { |
| 6400 | Binder.restoreCallingIdentity(identity); |
| 6401 | } |
| 6402 | } |
| 6403 | |
| 6404 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6405 | String pkgName) { |
| 6406 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6407 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6408 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6409 | || subController == null) return privilegeFromSim; |
| 6410 | |
| 6411 | final long identity = Binder.clearCallingIdentity(); |
| 6412 | try { |
| Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6413 | int subId = phone.getSubId(); |
| 6414 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6415 | // A test override is in place for the privileges for this subId, so don't try to |
| 6416 | // read the subscription privileges. |
| 6417 | return privilegeFromSim; |
| 6418 | } |
| 6419 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6420 | SubscriptionManager subManager = (SubscriptionManager) |
| 6421 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6422 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6423 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6424 | } finally { |
| 6425 | Binder.restoreCallingIdentity(identity); |
| 6426 | } |
| 6427 | } |
| 6428 | |
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6429 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6430 | public int getCarrierPrivilegeStatus(int subId) { |
| 6431 | final Phone phone = getPhone(subId); |
| 6432 | if (phone == null) { |
| 6433 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6434 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6435 | } |
| 6436 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6437 | if (card == null) { |
| Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6438 | loge("getCarrierPrivilegeStatus: No UICC"); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6439 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6440 | } |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6441 | |
| 6442 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6443 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6444 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6445 | } |
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6446 | |
| 6447 | @Override |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6448 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6449 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6450 | final Phone phone = getPhone(subId); |
| 6451 | if (phone == null) { |
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6452 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6453 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6454 | } |
| 6455 | UiccProfile profile = |
| 6456 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6457 | if (profile == null) { |
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6458 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6459 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6460 | } |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6461 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6462 | profile.getCarrierPrivilegeStatusForUid( |
| Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6463 | phone.getContext().getPackageManager(), uid), uid, phone); |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6464 | } |
| 6465 | |
| 6466 | @Override |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6467 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6468 | if (TextUtils.isEmpty(pkgName)) { |
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6469 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6470 | } |
| 6471 | |
| 6472 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6473 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6474 | if (card == null) { |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6475 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6476 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6477 | } |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6478 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6479 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6480 | getPhone(phoneId), pkgName); |
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6481 | } |
| 6482 | |
| 6483 | @Override |
| 6484 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6485 | if (TextUtils.isEmpty(pkgName)) |
| 6486 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6487 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6488 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6489 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6490 | if (card == null) { |
| Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6491 | // No UICC in that slot. |
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6492 | continue; |
| 6493 | } |
| 6494 | |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6495 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6496 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6497 | getPhone(i), pkgName); |
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6498 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6499 | break; |
| 6500 | } |
| 6501 | } |
| 6502 | |
| 6503 | return result; |
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6504 | } |
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6505 | |
| 6506 | @Override |
| Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6507 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6508 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6509 | loge("phoneId " + phoneId + " is not valid."); |
| 6510 | return null; |
| 6511 | } |
| 6512 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6513 | if (card == null) { |
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6514 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6515 | return null ; |
| 6516 | } |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6517 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6518 | } |
| 6519 | |
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6520 | @Override |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6521 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6522 | PackageManager pm = mApp.getPackageManager(); |
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6523 | List<String> privilegedPackages = new ArrayList<>(); |
| 6524 | List<PackageInfo> packages = null; |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6525 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6526 | // has UICC in that slot. |
| 6527 | if (card != null) { |
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6528 | if (card.hasCarrierPrivilegeRules()) { |
| 6529 | if (packages == null) { |
| 6530 | // Only check packages in user 0 for now |
| 6531 | packages = pm.getInstalledPackagesAsUser( |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6532 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6533 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6534 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6535 | UserHandle.SYSTEM.getIdentifier()); |
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6536 | } |
| 6537 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6538 | PackageInfo pkgInfo = packages.get(p); |
| 6539 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6540 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6541 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6542 | privilegedPackages.add(pkgInfo.packageName); |
| 6543 | } |
| 6544 | } |
| 6545 | } |
| 6546 | } |
| 6547 | return privilegedPackages; |
| 6548 | } |
| 6549 | |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6550 | @Override |
| 6551 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
| Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6552 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6553 | |
| 6554 | final long identity = Binder.clearCallingIdentity(); |
| 6555 | |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6556 | List<String> privilegedPackages = new ArrayList<>(); |
| Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6557 | try { |
| 6558 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6559 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6560 | } |
| 6561 | } finally { |
| 6562 | Binder.restoreCallingIdentity(identity); |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6563 | } |
| 6564 | return privilegedPackages; |
| 6565 | } |
| 6566 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6567 | private String getIccId(int subId) { |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6568 | final Phone phone = getPhone(subId); |
| 6569 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6570 | if (card == null) { |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6571 | return null; |
| 6572 | } |
| 6573 | String iccId = card.getIccId(); |
| 6574 | if (TextUtils.isEmpty(iccId)) { |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6575 | return null; |
| 6576 | } |
| 6577 | return iccId; |
| 6578 | } |
| 6579 | |
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6580 | @Override |
| Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6581 | public void setCallComposerStatus(int subId, int status) { |
| 6582 | enforceModifyPermission(); |
| 6583 | |
| 6584 | final long identity = Binder.clearCallingIdentity(); |
| 6585 | try { |
| 6586 | Phone phone = getPhone(subId); |
| 6587 | if (phone != null) { |
| 6588 | Phone defaultPhone = phone.getImsPhone(); |
| 6589 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6590 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6591 | imsPhone.setCallComposerStatus(status); |
| Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6592 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6593 | .updateImsServiceConfig(); |
| Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6594 | } |
| 6595 | } |
| Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6596 | } catch (ImsException e) { |
| 6597 | throw new ServiceSpecificException(e.getCode()); |
| 6598 | } finally { |
| Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6599 | Binder.restoreCallingIdentity(identity); |
| 6600 | } |
| 6601 | } |
| 6602 | |
| 6603 | @Override |
| 6604 | public int getCallComposerStatus(int subId) { |
| 6605 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6606 | |
| 6607 | final long identity = Binder.clearCallingIdentity(); |
| 6608 | try { |
| 6609 | Phone phone = getPhone(subId); |
| 6610 | if (phone != null) { |
| 6611 | Phone defaultPhone = phone.getImsPhone(); |
| 6612 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6613 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6614 | return imsPhone.getCallComposerStatus(); |
| 6615 | } |
| 6616 | } |
| 6617 | } finally { |
| 6618 | Binder.restoreCallingIdentity(identity); |
| 6619 | } |
| 6620 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6621 | } |
| 6622 | |
| 6623 | @Override |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6624 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6625 | String number) { |
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6626 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6627 | subId, "setLine1NumberForDisplayForSubscriber"); |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6628 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6629 | final long identity = Binder.clearCallingIdentity(); |
| 6630 | try { |
| 6631 | final String iccId = getIccId(subId); |
| 6632 | final Phone phone = getPhone(subId); |
| 6633 | if (phone == null) { |
| 6634 | return false; |
| 6635 | } |
| 6636 | final String subscriberId = phone.getSubscriberId(); |
| 6637 | |
| 6638 | if (DBG_MERGE) { |
| Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6639 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6640 | + subscriberId + " to " + number); |
| 6641 | } |
| 6642 | |
| 6643 | if (TextUtils.isEmpty(iccId)) { |
| 6644 | return false; |
| 6645 | } |
| 6646 | |
| 6647 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6648 | |
| 6649 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6650 | if (alphaTag == null) { |
| 6651 | editor.remove(alphaTagPrefKey); |
| 6652 | } else { |
| 6653 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6654 | } |
| 6655 | |
| 6656 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6657 | // track all merged IMSIs based on line number |
| 6658 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6659 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6660 | if (number == null) { |
| 6661 | editor.remove(numberPrefKey); |
| 6662 | editor.remove(subscriberPrefKey); |
| 6663 | } else { |
| 6664 | editor.putString(numberPrefKey, number); |
| 6665 | editor.putString(subscriberPrefKey, subscriberId); |
| 6666 | } |
| 6667 | |
| 6668 | editor.commit(); |
| 6669 | return true; |
| 6670 | } finally { |
| 6671 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6672 | } |
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6673 | } |
| 6674 | |
| 6675 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6676 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6677 | String callingFeatureId) { |
| Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6678 | // This is open to apps with WRITE_SMS. |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6679 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6680 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6681 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6682 | return null; |
| 6683 | } |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6684 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6685 | final long identity = Binder.clearCallingIdentity(); |
| 6686 | try { |
| 6687 | String iccId = getIccId(subId); |
| 6688 | if (iccId != null) { |
| 6689 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6690 | if (DBG_MERGE) { |
| 6691 | log("getLine1NumberForDisplay returning " |
| 6692 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6693 | } |
| 6694 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6695 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6696 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6697 | return null; |
| 6698 | } finally { |
| 6699 | Binder.restoreCallingIdentity(identity); |
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6700 | } |
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6701 | } |
| 6702 | |
| 6703 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6704 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6705 | String callingFeatureId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6706 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6707 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6708 | return null; |
| 6709 | } |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6710 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6711 | final long identity = Binder.clearCallingIdentity(); |
| 6712 | try { |
| 6713 | String iccId = getIccId(subId); |
| 6714 | if (iccId != null) { |
| 6715 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6716 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6717 | } |
| 6718 | return null; |
| 6719 | } finally { |
| 6720 | Binder.restoreCallingIdentity(identity); |
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6721 | } |
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6722 | } |
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6723 | |
| 6724 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6725 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6726 | String callingFeatureId) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6727 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6728 | // about carrier-privileged callers not having access. |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6729 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6730 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6731 | callingFeatureId, "getMergedSubscriberIds")) { |
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6732 | return null; |
| 6733 | } |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6734 | |
| Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6735 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6736 | // the process, where TelephonyManager was instantiated. |
| 6737 | // Otherwise AppOps check will fail. |
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6738 | final long identity = Binder.clearCallingIdentity(); |
| 6739 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6740 | final Context context = mApp; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6741 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6742 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6743 | |
| 6744 | // Figure out what subscribers are currently active |
| 6745 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6746 | |
| Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6747 | // Only consider subs which match the current subId |
| 6748 | // This logic can be simplified. See b/131189269 for progress. |
| 6749 | if (isActiveSubscription(subId)) { |
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6750 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6751 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6752 | |
| 6753 | // First pass, find a number override for an active subscriber |
| 6754 | String mergeNumber = null; |
| 6755 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6756 | for (String key : prefs.keySet()) { |
| 6757 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6758 | final String subscriberId = (String) prefs.get(key); |
| 6759 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6760 | final String iccId = key.substring( |
| 6761 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6762 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6763 | mergeNumber = (String) prefs.get(numberKey); |
| 6764 | if (DBG_MERGE) { |
| Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6765 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6766 | + " for active subscriber " + subscriberId); |
| 6767 | } |
| 6768 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6769 | break; |
| 6770 | } |
| 6771 | } |
| 6772 | } |
| 6773 | } |
| 6774 | |
| 6775 | // Shortcut when no active merged subscribers |
| 6776 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6777 | return null; |
| 6778 | } |
| 6779 | |
| 6780 | // Second pass, find all subscribers under that line override |
| 6781 | final ArraySet<String> result = new ArraySet<>(); |
| 6782 | for (String key : prefs.keySet()) { |
| 6783 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6784 | final String number = (String) prefs.get(key); |
| 6785 | if (mergeNumber.equals(number)) { |
| 6786 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6787 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6788 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6789 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6790 | result.add(subscriberId); |
| 6791 | } |
| 6792 | } |
| 6793 | } |
| 6794 | } |
| 6795 | |
| 6796 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6797 | Arrays.sort(resultArray); |
| 6798 | if (DBG_MERGE) { |
| Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6799 | Rlog.d(LOG_TAG, |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6800 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6801 | } |
| 6802 | return resultArray; |
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6803 | } finally { |
| 6804 | Binder.restoreCallingIdentity(identity); |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6805 | } |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6806 | } |
| 6807 | |
| 6808 | @Override |
| zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6809 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6810 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6811 | |
| 6812 | final long identity = Binder.clearCallingIdentity(); |
| 6813 | try { |
| 6814 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6815 | TelephonyManager.class); |
| 6816 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6817 | if (subscriberId == null) { |
| 6818 | if (DBG) { |
| zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6819 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6820 | + subId); |
| 6821 | } |
| 6822 | return null; |
| 6823 | } |
| 6824 | |
| 6825 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6826 | .getSubscriptionInfo(subId); |
| 6827 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6828 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6829 | if (groupUuid == null) { |
| 6830 | return new String[]{subscriberId}; |
| 6831 | } |
| 6832 | |
| 6833 | // Get all subscriberIds from the group. |
| 6834 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6835 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6836 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6837 | mApp.getAttributionTag()); |
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6838 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6839 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6840 | if (subscriberId != null) { |
| 6841 | mergedSubscriberIds.add(subscriberId); |
| 6842 | } |
| 6843 | } |
| 6844 | |
| 6845 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6846 | } finally { |
| 6847 | Binder.restoreCallingIdentity(identity); |
| 6848 | |
| 6849 | } |
| 6850 | } |
| 6851 | |
| 6852 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6853 | public boolean setOperatorBrandOverride(int subId, String brand) { |
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6854 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6855 | subId, "setOperatorBrandOverride"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6856 | |
| 6857 | final long identity = Binder.clearCallingIdentity(); |
| 6858 | try { |
| 6859 | final Phone phone = getPhone(subId); |
| 6860 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6861 | } finally { |
| 6862 | Binder.restoreCallingIdentity(identity); |
| 6863 | } |
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6864 | } |
| Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6865 | |
| 6866 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6867 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6868 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6869 | List<String> cdmaNonRoamingList) { |
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6870 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6871 | mApp, subId, "setRoamingOverride"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6872 | |
| 6873 | final long identity = Binder.clearCallingIdentity(); |
| 6874 | try { |
| 6875 | final Phone phone = getPhone(subId); |
| 6876 | if (phone == null) { |
| 6877 | return false; |
| 6878 | } |
| 6879 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6880 | cdmaNonRoamingList); |
| 6881 | } finally { |
| 6882 | Binder.restoreCallingIdentity(identity); |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6883 | } |
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6884 | } |
| 6885 | |
| 6886 | @Override |
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6887 | @Deprecated |
| 6888 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6889 | enforceModifyPermission(); |
| 6890 | |
| 6891 | int returnValue = 0; |
| 6892 | try { |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6893 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6894 | if(result.exception == null) { |
| 6895 | if (result.result != null) { |
| 6896 | byte[] responseData = (byte[])(result.result); |
| 6897 | if(responseData.length > oemResp.length) { |
| 6898 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6899 | responseData.length + "bytes. Buffer Size is " + |
| 6900 | oemResp.length + "bytes."); |
| 6901 | } |
| 6902 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6903 | returnValue = responseData.length; |
| 6904 | } |
| 6905 | } else { |
| 6906 | CommandException ex = (CommandException) result.exception; |
| 6907 | returnValue = ex.getCommandError().ordinal(); |
| 6908 | if(returnValue > 0) returnValue *= -1; |
| 6909 | } |
| 6910 | } catch (RuntimeException e) { |
| 6911 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6912 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6913 | if(returnValue > 0) returnValue *= -1; |
| 6914 | } |
| 6915 | |
| 6916 | return returnValue; |
| 6917 | } |
| 6918 | |
| 6919 | @Override |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6920 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6921 | Phone phone = PhoneFactory.getPhone(phoneId); |
| Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6922 | try { |
| 6923 | TelephonyPermissions |
| 6924 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6925 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6926 | } catch (SecurityException e) { |
| 6927 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6928 | throw e; |
| 6929 | } |
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6930 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6931 | if (phone == null) { |
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6932 | return raf; |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6933 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6934 | final long identity = Binder.clearCallingIdentity(); |
| 6935 | try { |
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6936 | TelephonyPermissions |
| 6937 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6938 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6939 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6940 | } finally { |
| 6941 | Binder.restoreCallingIdentity(identity); |
| 6942 | } |
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6943 | return raf; |
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6944 | } |
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6945 | |
| 6946 | @Override |
| 6947 | public void enableVideoCalling(boolean enable) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6948 | final Phone defaultPhone = getDefaultPhone(); |
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6949 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6950 | |
| 6951 | final long identity = Binder.clearCallingIdentity(); |
| 6952 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6953 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6954 | defaultPhone.getPhoneId()).setVtSetting(enable); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6955 | } finally { |
| 6956 | Binder.restoreCallingIdentity(identity); |
| 6957 | } |
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6958 | } |
| 6959 | |
| 6960 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6961 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6962 | final Phone defaultPhone = getDefaultPhone(); |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6963 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6964 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
| Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6965 | return false; |
| 6966 | } |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6967 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6968 | final long identity = Binder.clearCallingIdentity(); |
| 6969 | try { |
| 6970 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6971 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6972 | // In the long run, we may instead need to check if there exists a connection service |
| 6973 | // which can support video calling. |
| 6974 | ImsManager imsManager = |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6975 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6976 | return imsManager.isVtEnabledByPlatform() |
| 6977 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6978 | && imsManager.isVtEnabledByUser(); |
| 6979 | } finally { |
| 6980 | Binder.restoreCallingIdentity(identity); |
| 6981 | } |
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6982 | } |
| Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6983 | |
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6984 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6985 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6986 | String callingFeatureId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6987 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6988 | mApp, subId, callingPackage, callingFeatureId, |
| 6989 | "isVideoCallingEnabled")) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6990 | return false; |
| 6991 | } |
| 6992 | |
| 6993 | final long identity = Binder.clearCallingIdentity(); |
| 6994 | try { |
| 6995 | CarrierConfigManager configManager = |
| 6996 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6997 | return configManager.getConfigForSubId(subId) |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6998 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6999 | } finally { |
| 7000 | Binder.restoreCallingIdentity(identity); |
| 7001 | } |
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7002 | } |
| 7003 | |
| 7004 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7005 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7006 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7007 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7008 | return false; |
| 7009 | } |
| 7010 | |
| 7011 | final long identity = Binder.clearCallingIdentity(); |
| 7012 | try { |
| 7013 | CarrierConfigManager configManager = |
| 7014 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7015 | return configManager.getConfigForSubId(subId) |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7016 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7017 | } finally { |
| 7018 | Binder.restoreCallingIdentity(identity); |
| 7019 | } |
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7020 | } |
| 7021 | |
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7022 | @Override |
| 7023 | public boolean isTtyModeSupported() { |
| Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7024 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
| Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7025 | return telecomManager.isTtySupported(); |
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7026 | } |
| 7027 | |
| 7028 | @Override |
| 7029 | public boolean isHearingAidCompatibilitySupported() { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7030 | final long identity = Binder.clearCallingIdentity(); |
| 7031 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7032 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7033 | } finally { |
| 7034 | Binder.restoreCallingIdentity(identity); |
| 7035 | } |
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7036 | } |
| 7037 | |
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7038 | /** |
| 7039 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7040 | * support for the feature and device firmware support. |
| 7041 | * |
| 7042 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7043 | */ |
| 7044 | @Override |
| 7045 | public boolean isRttSupported(int subscriptionId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7046 | final long identity = Binder.clearCallingIdentity(); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7047 | final Phone phone = getPhone(subscriptionId); |
| 7048 | if (phone == null) { |
| 7049 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7050 | return false; |
| 7051 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7052 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7053 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7054 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7055 | boolean isDeviceSupported = |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7056 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7057 | return isCarrierSupported && isDeviceSupported; |
| 7058 | } finally { |
| 7059 | Binder.restoreCallingIdentity(identity); |
| 7060 | } |
| Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7061 | } |
| 7062 | |
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7063 | /** |
| Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7064 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7065 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7066 | * 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] | 7067 | */ |
| 7068 | public boolean isRttEnabled(int subscriptionId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7069 | final long identity = Binder.clearCallingIdentity(); |
| 7070 | try { |
| Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7071 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7072 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7073 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7074 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7075 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7076 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7077 | } finally { |
| 7078 | Binder.restoreCallingIdentity(identity); |
| 7079 | } |
| Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7080 | } |
| 7081 | |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7082 | @Deprecated |
| 7083 | @Override |
| 7084 | public String getDeviceId(String callingPackage) { |
| 7085 | return getDeviceIdWithFeature(callingPackage, null); |
| 7086 | } |
| 7087 | |
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7088 | /** |
| 7089 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7090 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7091 | * |
| 7092 | * <p>Requires Permission: |
| 7093 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7094 | */ |
| 7095 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7096 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7097 | final Phone phone = PhoneFactory.getPhone(0); |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7098 | if (phone == null) { |
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7099 | return null; |
| 7100 | } |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7101 | int subId = phone.getSubId(); |
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7102 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7103 | callingPackage, callingFeatureId, "getDeviceId")) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7104 | return null; |
| 7105 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7106 | |
| 7107 | final long identity = Binder.clearCallingIdentity(); |
| 7108 | try { |
| 7109 | return phone.getDeviceId(); |
| 7110 | } finally { |
| 7111 | Binder.restoreCallingIdentity(identity); |
| 7112 | } |
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7113 | } |
| 7114 | |
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7115 | /** |
| 7116 | * {@hide} |
| 7117 | * Returns the IMS Registration Status on a particular subid |
| 7118 | * |
| 7119 | * @param subId |
| 7120 | */ |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7121 | public boolean isImsRegistered(int subId) { |
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7122 | Phone phone = getPhone(subId); |
| 7123 | if (phone != null) { |
| 7124 | return phone.isImsRegistered(); |
| 7125 | } else { |
| 7126 | return false; |
| 7127 | } |
| 7128 | } |
| 7129 | |
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7130 | @Override |
| 7131 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7132 | final long identity = Binder.clearCallingIdentity(); |
| 7133 | try { |
| 7134 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7135 | } finally { |
| 7136 | Binder.restoreCallingIdentity(identity); |
| 7137 | } |
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7138 | } |
| Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7139 | |
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7140 | @Override |
| Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7141 | public int getSubIdForPhoneAccountHandle( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7142 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
| Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7143 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7144 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
| Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7145 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7146 | } |
| 7147 | final long identity = Binder.clearCallingIdentity(); |
| 7148 | try { |
| 7149 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7150 | } finally { |
| 7151 | Binder.restoreCallingIdentity(identity); |
| 7152 | } |
| 7153 | } |
| 7154 | |
| 7155 | @Override |
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7156 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7157 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7158 | + "subscriptionId: " + subscriptionId); |
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7159 | final long identity = Binder.clearCallingIdentity(); |
| 7160 | try { |
| 7161 | Phone phone = getPhone(subscriptionId); |
| 7162 | if (phone == null) { |
| 7163 | return null; |
| 7164 | } |
| 7165 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7166 | } finally { |
| 7167 | Binder.restoreCallingIdentity(identity); |
| 7168 | } |
| 7169 | } |
| 7170 | |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7171 | /** |
| 7172 | * @return the VoWiFi calling availability. |
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7173 | */ |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7174 | public boolean isWifiCallingAvailable(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7175 | final long identity = Binder.clearCallingIdentity(); |
| 7176 | try { |
| 7177 | Phone phone = getPhone(subId); |
| 7178 | if (phone != null) { |
| 7179 | return phone.isWifiCallingEnabled(); |
| 7180 | } else { |
| 7181 | return false; |
| 7182 | } |
| 7183 | } finally { |
| 7184 | Binder.restoreCallingIdentity(identity); |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7185 | } |
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7186 | } |
| 7187 | |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7188 | /** |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7189 | * @return the VT calling availability. |
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7190 | */ |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7191 | public boolean isVideoTelephonyAvailable(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7192 | final long identity = Binder.clearCallingIdentity(); |
| 7193 | try { |
| 7194 | Phone phone = getPhone(subId); |
| 7195 | if (phone != null) { |
| 7196 | return phone.isVideoEnabled(); |
| 7197 | } else { |
| 7198 | return false; |
| 7199 | } |
| 7200 | } finally { |
| 7201 | Binder.restoreCallingIdentity(identity); |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7202 | } |
| 7203 | } |
| 7204 | |
| 7205 | /** |
| 7206 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7207 | * defined in {@link ImsRegistrationImplBase}. |
| 7208 | */ |
| 7209 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7210 | final long identity = Binder.clearCallingIdentity(); |
| 7211 | try { |
| 7212 | Phone phone = getPhone(subId); |
| 7213 | if (phone != null) { |
| 7214 | return phone.getImsRegistrationTech(); |
| 7215 | } else { |
| 7216 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7217 | } |
| 7218 | } finally { |
| 7219 | Binder.restoreCallingIdentity(identity); |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7220 | } |
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7221 | } |
| 7222 | |
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7223 | @Override |
| 7224 | public void factoryReset(int subId) { |
| paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7225 | enforceSettingsPermission(); |
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7226 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7227 | return; |
| 7228 | } |
| 7229 | |
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7230 | final long identity = Binder.clearCallingIdentity(); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7231 | |
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7232 | try { |
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7233 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7234 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7235 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7236 | getDefaultDataEnabled()); |
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7237 | setNetworkSelectionModeAutomatic(subId); |
| SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7238 | setAllowedNetworkTypesForReason(subId, |
| 7239 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7240 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7241 | setAllowedNetworkTypesForReason(subId, |
| 7242 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER, |
| 7243 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7244 | setAllowedNetworkTypesForReason(subId, |
| 7245 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, |
| 7246 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7247 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7248 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7249 | } |
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7250 | // There has been issues when Sms raw table somehow stores orphan |
| 7251 | // fragments. They lead to garbled message when new fragments come |
| 7252 | // in and combined with those stale ones. In case this happens again, |
| 7253 | // user can reset all network settings which will clean up this table. |
| 7254 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
| Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7255 | // Clean up IMS settings as well here. |
| 7256 | int slotId = getSlotIndex(subId); |
| 7257 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7258 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7259 | } |
| Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7260 | |
| 7261 | // Erase modem config if erase modem on network setting is enabled. |
| 7262 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7263 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7264 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7265 | sendEraseModemConfig(getDefaultPhone()); |
| 7266 | } |
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7267 | } finally { |
| 7268 | Binder.restoreCallingIdentity(identity); |
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7269 | } |
| 7270 | } |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7271 | |
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7272 | private void cleanUpSmsRawTable(Context context) { |
| 7273 | ContentResolver resolver = context.getContentResolver(); |
| 7274 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7275 | resolver.delete(uri, null, null); |
| 7276 | } |
| 7277 | |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7278 | @Override |
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7279 | public String getSimLocaleForSubscriber(int subId) { |
| 7280 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7281 | final Phone phone = getPhone(subId); |
| 7282 | if (phone == null) { |
| 7283 | log("getSimLocaleForSubscriber, invalid subId"); |
| chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7284 | return null; |
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7285 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7286 | final long identity = Binder.clearCallingIdentity(); |
| 7287 | try { |
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7288 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7289 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
| chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7290 | if (info == null) { |
| 7291 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7292 | return null; |
| 7293 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7294 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7295 | // preferences (EF-PL and EF-LI)... |
| 7296 | final int mcc = info.getMcc(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7297 | String simLanguage = null; |
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7298 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7299 | if (localeFromDefaultSim != null) { |
| 7300 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7301 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7302 | + localeFromDefaultSim); |
| 7303 | return localeFromDefaultSim.toLanguageTag(); |
| 7304 | } else { |
| 7305 | simLanguage = localeFromDefaultSim.getLanguage(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7306 | } |
| 7307 | } |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7308 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7309 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7310 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7311 | // the SIM and carrier preferences does not include a country we add the country |
| 7312 | // determined from the SIM MCC to provide an exact locale. |
| zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7313 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7314 | if (mccLocale != null) { |
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7315 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7316 | return mccLocale.toLanguageTag(); |
| 7317 | } |
| 7318 | |
| 7319 | if (DBG) log("No locale found - returning null"); |
| 7320 | return null; |
| 7321 | } finally { |
| 7322 | Binder.restoreCallingIdentity(identity); |
| 7323 | } |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7324 | } |
| 7325 | |
| 7326 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7327 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7328 | mApp.getAttributionTag()); |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7329 | } |
| 7330 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7331 | /** |
| 7332 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7333 | */ |
| 7334 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7335 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7336 | mApp.getAttributionTag()); |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7337 | } |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7338 | |
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7339 | private final ModemActivityInfo mLastModemActivityInfo = |
| Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7340 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7341 | |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7342 | /** |
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7343 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7344 | * representing the state of the modem. |
| 7345 | * |
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7346 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7347 | * caller to it. Everyone should call this class to get cumulative data. |
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7348 | * @hide |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7349 | */ |
| 7350 | @Override |
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7351 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7352 | enforceModifyPermission(); |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7353 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7354 | |
| 7355 | final long identity = Binder.clearCallingIdentity(); |
| 7356 | try { |
| sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7357 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7358 | } finally { |
| 7359 | Binder.restoreCallingIdentity(identity); |
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7360 | } |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7361 | } |
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7362 | |
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7363 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7364 | // less than total activity duration. |
| 7365 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7366 | if (info == null) { |
| 7367 | return false; |
| 7368 | } |
| 7369 | int activityDurationMs = |
| 7370 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7371 | int totalTxTimeMs = 0; |
| Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7372 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7373 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7374 | totalTxTimeMs += txTimeMs[i]; |
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7375 | } |
| 7376 | return (info.isValid() |
| 7377 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7378 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7379 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7380 | && (totalTxTimeMs <= activityDurationMs)); |
| 7381 | } |
| 7382 | |
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7383 | /** |
| 7384 | * {@hide} |
| 7385 | * Returns the service state information on specified subscription. |
| 7386 | */ |
| 7387 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7388 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7389 | String callingFeatureId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7390 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7391 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7392 | return null; |
| 7393 | } |
| 7394 | |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7395 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7396 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7397 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7398 | .setCallingPackage(callingPackage) |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7399 | .setCallingFeatureId(callingFeatureId) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7400 | .setCallingPid(Binder.getCallingPid()) |
| 7401 | .setCallingUid(Binder.getCallingUid()) |
| 7402 | .setMethod("getServiceStateForSubscriber") |
| Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7403 | .setLogAsInfo(true) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7404 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7405 | .build()); |
| 7406 | |
| 7407 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7408 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7409 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7410 | .setCallingPackage(callingPackage) |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7411 | .setCallingFeatureId(callingFeatureId) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7412 | .setCallingPid(Binder.getCallingPid()) |
| 7413 | .setCallingUid(Binder.getCallingUid()) |
| 7414 | .setMethod("getServiceStateForSubscriber") |
| Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7415 | .setLogAsInfo(true) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7416 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7417 | .build()); |
| 7418 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7419 | boolean hasFinePermission = |
| 7420 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7421 | boolean hasCoarsePermission = |
| 7422 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7423 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7424 | final long identity = Binder.clearCallingIdentity(); |
| 7425 | try { |
| Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7426 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7427 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7428 | Rlog.d(LOG_TAG, |
| 7429 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7430 | return null; |
| 7431 | } |
| 7432 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7433 | final Phone phone = getPhone(subId); |
| 7434 | if (phone == null) { |
| 7435 | return null; |
| 7436 | } |
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7437 | |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7438 | ServiceState ss = phone.getServiceState(); |
| 7439 | |
| 7440 | // Scrub out the location info in ServiceState depending on what level of access |
| 7441 | // the caller has. |
| 7442 | if (hasFinePermission) return ss; |
| Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7443 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7444 | return ss.createLocationInfoSanitizedCopy(true); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7445 | } finally { |
| 7446 | Binder.restoreCallingIdentity(identity); |
| 7447 | } |
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7448 | } |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7449 | |
| 7450 | /** |
| 7451 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7452 | * |
| 7453 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7454 | * voicemail ringtone. |
| 7455 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7456 | * PhoneAccount. |
| 7457 | */ |
| 7458 | @Override |
| 7459 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7460 | final long identity = Binder.clearCallingIdentity(); |
| 7461 | try { |
| 7462 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7463 | if (phone == null) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7464 | phone = getDefaultPhone(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7465 | } |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7466 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7467 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7468 | } finally { |
| 7469 | Binder.restoreCallingIdentity(identity); |
| 7470 | } |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7471 | } |
| 7472 | |
| 7473 | /** |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7474 | * Sets the per-account voicemail ringtone. |
| 7475 | * |
| 7476 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7477 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7478 | * |
| 7479 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7480 | * voicemail ringtone. |
| 7481 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7482 | * PhoneAccount. |
| 7483 | */ |
| 7484 | @Override |
| 7485 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7486 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7487 | final Phone defaultPhone = getDefaultPhone(); |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7488 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7489 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7490 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7491 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7492 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7493 | "setVoicemailRingtoneUri"); |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7494 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7495 | |
| 7496 | final long identity = Binder.clearCallingIdentity(); |
| 7497 | try { |
| 7498 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7499 | if (phone == null) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7500 | phone = defaultPhone; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7501 | } |
| 7502 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7503 | } finally { |
| 7504 | Binder.restoreCallingIdentity(identity); |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7505 | } |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7506 | } |
| 7507 | |
| 7508 | /** |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7509 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7510 | * |
| 7511 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7512 | * voicemail vibration setting. |
| 7513 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7514 | */ |
| 7515 | @Override |
| 7516 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7517 | final long identity = Binder.clearCallingIdentity(); |
| 7518 | try { |
| 7519 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7520 | if (phone == null) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7521 | phone = getDefaultPhone(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7522 | } |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7523 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7524 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7525 | } finally { |
| 7526 | Binder.restoreCallingIdentity(identity); |
| 7527 | } |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7528 | } |
| 7529 | |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7530 | /** |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7531 | * Sets the per-account voicemail vibration. |
| 7532 | * |
| 7533 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7534 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7535 | * |
| 7536 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7537 | * voicemail vibration setting. |
| 7538 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7539 | * specific PhoneAccount. |
| 7540 | */ |
| 7541 | @Override |
| 7542 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7543 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7544 | final Phone defaultPhone = getDefaultPhone(); |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7545 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7546 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7547 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7548 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7549 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7550 | "setVoicemailVibrationEnabled"); |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7551 | } |
| 7552 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7553 | final long identity = Binder.clearCallingIdentity(); |
| 7554 | try { |
| 7555 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7556 | if (phone == null) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7557 | phone = defaultPhone; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7558 | } |
| 7559 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7560 | } finally { |
| 7561 | Binder.restoreCallingIdentity(identity); |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7562 | } |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7563 | } |
| 7564 | |
| 7565 | /** |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7566 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7567 | * |
| 7568 | * @throws SecurityException if the caller does not have the required permission |
| 7569 | */ |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7570 | private void enforceReadPrivilegedPermission(String message) { |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7571 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7572 | message); |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7573 | } |
| 7574 | |
| 7575 | /** |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7576 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7577 | * permission. |
| 7578 | * |
| 7579 | * @throws SecurityException if the caller does not have the required permission |
| 7580 | */ |
| 7581 | private void enforceSendSmsPermission() { |
| 7582 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7583 | } |
| 7584 | |
| 7585 | /** |
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7586 | * Make sure called from the package in charge of visual voicemail. |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7587 | * |
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7588 | * @throws SecurityException if the caller is not the visual voicemail package. |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7589 | */ |
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7590 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7591 | final long identity = Binder.clearCallingIdentity(); |
| 7592 | try { |
| 7593 | ComponentName componentName = |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7594 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7595 | if (componentName == null) { |
| 7596 | throw new SecurityException( |
| 7597 | "Caller not current active visual voicemail package[null]"); |
| 7598 | } |
| 7599 | String vvmPackage = componentName.getPackageName(); |
| 7600 | if (!callingPackage.equals(vvmPackage)) { |
| 7601 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7602 | + vvmPackage + "]"); |
| 7603 | } |
| 7604 | } finally { |
| 7605 | Binder.restoreCallingIdentity(identity); |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7606 | } |
| 7607 | } |
| 7608 | |
| 7609 | /** |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7610 | * Return the application ID for the app type. |
| 7611 | * |
| 7612 | * @param subId the subscription ID that this request applies to. |
| 7613 | * @param appType the uicc app type. |
| 7614 | * @return Application ID for specificied app type, or null if no uicc. |
| 7615 | */ |
| 7616 | @Override |
| 7617 | public String getAidForAppType(int subId, int appType) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7618 | enforceReadPrivilegedPermission("getAidForAppType"); |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7619 | Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7620 | |
| 7621 | final long identity = Binder.clearCallingIdentity(); |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7622 | try { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7623 | if (phone == null) { |
| 7624 | return null; |
| 7625 | } |
| 7626 | String aid = null; |
| 7627 | try { |
| 7628 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7629 | .getApplicationByType(appType).getAid(); |
| 7630 | } catch (Exception e) { |
| 7631 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7632 | } |
| 7633 | return aid; |
| 7634 | } finally { |
| 7635 | Binder.restoreCallingIdentity(identity); |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7636 | } |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7637 | } |
| 7638 | |
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7639 | /** |
| 7640 | * Return the Electronic Serial Number. |
| 7641 | * |
| 7642 | * @param subId the subscription ID that this request applies to. |
| 7643 | * @return ESN or null if error. |
| 7644 | */ |
| 7645 | @Override |
| 7646 | public String getEsn(int subId) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7647 | enforceReadPrivilegedPermission("getEsn"); |
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7648 | Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7649 | |
| 7650 | final long identity = Binder.clearCallingIdentity(); |
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7651 | try { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7652 | if (phone == null) { |
| 7653 | return null; |
| 7654 | } |
| 7655 | String esn = null; |
| 7656 | try { |
| 7657 | esn = phone.getEsn(); |
| 7658 | } catch (Exception e) { |
| 7659 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7660 | } |
| 7661 | return esn; |
| 7662 | } finally { |
| 7663 | Binder.restoreCallingIdentity(identity); |
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7664 | } |
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7665 | } |
| 7666 | |
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7667 | /** |
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7668 | * Return the Preferred Roaming List Version. |
| 7669 | * |
| 7670 | * @param subId the subscription ID that this request applies to. |
| 7671 | * @return PRLVersion or null if error. |
| 7672 | */ |
| 7673 | @Override |
| 7674 | public String getCdmaPrlVersion(int subId) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7675 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7676 | Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7677 | |
| 7678 | final long identity = Binder.clearCallingIdentity(); |
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7679 | try { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7680 | if (phone == null) { |
| 7681 | return null; |
| 7682 | } |
| 7683 | String cdmaPrlVersion = null; |
| 7684 | try { |
| 7685 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7686 | } catch (Exception e) { |
| 7687 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7688 | } |
| 7689 | return cdmaPrlVersion; |
| 7690 | } finally { |
| 7691 | Binder.restoreCallingIdentity(identity); |
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7692 | } |
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7693 | } |
| 7694 | |
| 7695 | /** |
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7696 | * Get snapshot of Telephony histograms |
| 7697 | * @return List of Telephony histograms |
| 7698 | * @hide |
| 7699 | */ |
| 7700 | @Override |
| 7701 | public List<TelephonyHistogram> getTelephonyHistograms() { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7702 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7703 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7704 | |
| 7705 | final long identity = Binder.clearCallingIdentity(); |
| 7706 | try { |
| 7707 | return RIL.getTelephonyRILTimingHistograms(); |
| 7708 | } finally { |
| 7709 | Binder.restoreCallingIdentity(identity); |
| 7710 | } |
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7711 | } |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7712 | |
| 7713 | /** |
| 7714 | * {@hide} |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7715 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7716 | * the two lists. |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7717 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7718 | * |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7719 | * @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] | 7720 | */ |
| 7721 | @Override |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7722 | @TelephonyManager.SetCarrierRestrictionResult |
| 7723 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7724 | enforceModifyPermission(); |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7725 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7726 | |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7727 | if (carrierRestrictionRules == null) { |
| 7728 | throw new NullPointerException("carrier restriction cannot be null"); |
| Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7729 | } |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7730 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7731 | final long identity = Binder.clearCallingIdentity(); |
| 7732 | try { |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7733 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7734 | workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7735 | } finally { |
| 7736 | Binder.restoreCallingIdentity(identity); |
| 7737 | } |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7738 | } |
| 7739 | |
| 7740 | /** |
| 7741 | * {@hide} |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7742 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7743 | * the two lists. |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7744 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7745 | * |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7746 | * @return {@link android.telephony.CarrierRestrictionRules} |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7747 | */ |
| 7748 | @Override |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7749 | public CarrierRestrictionRules getAllowedCarriers() { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7750 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7751 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7752 | |
| 7753 | final long identity = Binder.clearCallingIdentity(); |
| 7754 | try { |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7755 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7756 | if (response instanceof CarrierRestrictionRules) { |
| 7757 | return (CarrierRestrictionRules) response; |
| 7758 | } |
| 7759 | // Response is an Exception of some kind, |
| 7760 | // which is signalled to the user as a NULL retval |
| 7761 | return null; |
| 7762 | } catch (Exception e) { |
| 7763 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7764 | return null; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7765 | } finally { |
| 7766 | Binder.restoreCallingIdentity(identity); |
| 7767 | } |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7768 | } |
| 7769 | |
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7770 | /** |
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7771 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7772 | * @param subId the subscription ID that this action applies to. |
| 7773 | * @param enabled control enable or disable radio. |
| 7774 | * {@hide} |
| 7775 | */ |
| 7776 | @Override |
| 7777 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7778 | enforceModifyPermission(); |
| 7779 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7780 | |
| 7781 | final long identity = Binder.clearCallingIdentity(); |
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7782 | if (phone == null) { |
| 7783 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7784 | return; |
| 7785 | } |
| 7786 | try { |
| 7787 | phone.carrierActionSetRadioEnabled(enabled); |
| 7788 | } catch (Exception e) { |
| 7789 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7790 | } finally { |
| 7791 | Binder.restoreCallingIdentity(identity); |
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7792 | } |
| 7793 | } |
| 7794 | |
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7795 | /** |
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7796 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7797 | * network status based on which carrier apps could apply actions accordingly, |
| 7798 | * enable/disable default url handler for example. |
| 7799 | * |
| 7800 | * @param subId the subscription ID that this action applies to. |
| 7801 | * @param report control start/stop reporting the default network status. |
| 7802 | * {@hide} |
| 7803 | */ |
| 7804 | @Override |
| 7805 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7806 | enforceModifyPermission(); |
| 7807 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7808 | |
| 7809 | final long identity = Binder.clearCallingIdentity(); |
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7810 | if (phone == null) { |
| 7811 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7812 | return; |
| 7813 | } |
| 7814 | try { |
| 7815 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7816 | } catch (Exception e) { |
| 7817 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7818 | } finally { |
| 7819 | Binder.restoreCallingIdentity(identity); |
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7820 | } |
| 7821 | } |
| 7822 | |
| 7823 | /** |
| fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7824 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7825 | * @param subId the subscription ID that this action applies to. |
| 7826 | * {@hide} |
| 7827 | */ |
| 7828 | @Override |
| 7829 | public void carrierActionResetAll(int subId) { |
| 7830 | enforceModifyPermission(); |
| 7831 | final Phone phone = getPhone(subId); |
| 7832 | if (phone == null) { |
| 7833 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7834 | return; |
| 7835 | } |
| 7836 | try { |
| 7837 | phone.carrierActionResetAll(); |
| 7838 | } catch (Exception e) { |
| 7839 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7840 | } |
| 7841 | } |
| 7842 | |
| 7843 | /** |
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7844 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7845 | * bug report is being generated. |
| 7846 | */ |
| 7847 | @Override |
| Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7848 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7849 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7850 | != PackageManager.PERMISSION_GRANTED) { |
| dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7851 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7852 | + Binder.getCallingPid() |
| 7853 | + ", uid=" + Binder.getCallingUid() |
| 7854 | + "without permission " |
| 7855 | + android.Manifest.permission.DUMP); |
| 7856 | return; |
| 7857 | } |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7858 | DumpsysHandler.dump(mApp, fd, writer, args); |
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7859 | } |
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7860 | |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7861 | @Override |
| Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7862 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7863 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7864 | @NonNull String[] args) { |
| 7865 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7866 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7867 | err.getFileDescriptor(), args); |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7868 | } |
| 7869 | |
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7870 | /** |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7871 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7872 | * @param subId Subscription index |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7873 | * @param reason the reason the data enable change is taking place |
| 7874 | * @param enabled True if enabling the data, otherwise disabling. |
| 7875 | * @hide |
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7876 | */ |
| 7877 | @Override |
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7878 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7879 | boolean enabled) { |
| 7880 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7881 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7882 | try { |
| 7883 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7884 | mApp, subId, "setDataEnabledForReason"); |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7885 | } catch (SecurityException se) { |
| 7886 | enforceModifyPermission(); |
| 7887 | } |
| 7888 | } else { |
| 7889 | enforceModifyPermission(); |
| 7890 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7891 | |
| 7892 | final long identity = Binder.clearCallingIdentity(); |
| 7893 | try { |
| 7894 | Phone phone = getPhone(subId); |
| 7895 | if (phone != null) { |
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7896 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7897 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7898 | } else { |
| 7899 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7900 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7901 | } |
| 7902 | } finally { |
| 7903 | Binder.restoreCallingIdentity(identity); |
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7904 | } |
| 7905 | } |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7906 | |
| 7907 | /** |
| 7908 | * Get Client request stats |
| 7909 | * @return List of Client Request Stats |
| 7910 | * @hide |
| 7911 | */ |
| 7912 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7913 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7914 | String callingFeatureId, int subId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7915 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7916 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7917 | return null; |
| 7918 | } |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7919 | Phone phone = getPhone(subId); |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7920 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7921 | final long identity = Binder.clearCallingIdentity(); |
| 7922 | try { |
| 7923 | if (phone != null) { |
| 7924 | return phone.getClientRequestStats(); |
| 7925 | } |
| 7926 | |
| 7927 | return null; |
| 7928 | } finally { |
| 7929 | Binder.restoreCallingIdentity(identity); |
| 7930 | } |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7931 | } |
| 7932 | |
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7933 | private WorkSource getWorkSource(int uid) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7934 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7935 | return new WorkSource(uid, packageName); |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7936 | } |
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7937 | |
| 7938 | /** |
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7939 | * Set SIM card power state. |
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7940 | * |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7941 | * @param slotIndex SIM slot id. |
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7942 | * @param state State of SIM (power down, power up, pass through) |
| 7943 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7944 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7945 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7946 | * |
| 7947 | **/ |
| 7948 | @Override |
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7949 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7950 | enforceModifyPermission(); |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7951 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7952 | |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7953 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7954 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7955 | final long identity = Binder.clearCallingIdentity(); |
| 7956 | try { |
| 7957 | if (phone != null) { |
| Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 7958 | phone.setSimPowerState(state, null, workSource); |
| 7959 | } |
| 7960 | } finally { |
| 7961 | Binder.restoreCallingIdentity(identity); |
| 7962 | } |
| 7963 | } |
| 7964 | |
| 7965 | /** |
| 7966 | * Set SIM card power state. |
| 7967 | * |
| 7968 | * @param slotIndex SIM slot id. |
| 7969 | * @param state State of SIM (power down, power up, pass through) |
| 7970 | * @param callback callback to trigger after success or failure |
| 7971 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7972 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7973 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 7974 | * |
| 7975 | **/ |
| 7976 | @Override |
| 7977 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 7978 | IIntegerConsumer callback) { |
| 7979 | enforceModifyPermission(); |
| 7980 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7981 | |
| 7982 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7983 | |
| 7984 | final long identity = Binder.clearCallingIdentity(); |
| 7985 | try { |
| 7986 | if (phone != null) { |
| 7987 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 7988 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7989 | } |
| 7990 | } finally { |
| 7991 | Binder.restoreCallingIdentity(identity); |
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7992 | } |
| 7993 | } |
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7994 | |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7995 | private boolean isUssdApiAllowed(int subId) { |
| 7996 | CarrierConfigManager configManager = |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7997 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7998 | if (configManager == null) { |
| 7999 | return false; |
| 8000 | } |
| 8001 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8002 | if (pb == null) { |
| 8003 | return false; |
| 8004 | } |
| 8005 | return pb.getBoolean( |
| 8006 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8007 | } |
| 8008 | |
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8009 | /** |
| 8010 | * Check if phone is in emergency callback mode |
| 8011 | * @return true if phone is in emergency callback mode |
| 8012 | * @param subId sub id |
| 8013 | */ |
| goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8014 | @Override |
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8015 | public boolean getEmergencyCallbackMode(int subId) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8016 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8017 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8018 | |
| 8019 | final long identity = Binder.clearCallingIdentity(); |
| 8020 | try { |
| 8021 | if (phone != null) { |
| 8022 | return phone.isInEcm(); |
| 8023 | } else { |
| 8024 | return false; |
| 8025 | } |
| 8026 | } finally { |
| 8027 | Binder.restoreCallingIdentity(identity); |
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8028 | } |
| 8029 | } |
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8030 | |
| 8031 | /** |
| 8032 | * Get the current signal strength information for the given subscription. |
| 8033 | * Because this information is not updated when the device is in a low power state |
| 8034 | * it should not be relied-upon to be current. |
| 8035 | * @param subId Subscription index |
| 8036 | * @return the most recent cached signal strength info from the modem |
| 8037 | */ |
| 8038 | @Override |
| 8039 | public SignalStrength getSignalStrength(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8040 | final long identity = Binder.clearCallingIdentity(); |
| 8041 | try { |
| 8042 | Phone p = getPhone(subId); |
| 8043 | if (p == null) { |
| 8044 | return null; |
| 8045 | } |
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8046 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8047 | return p.getSignalStrength(); |
| 8048 | } finally { |
| 8049 | Binder.restoreCallingIdentity(identity); |
| 8050 | } |
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8051 | } |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8052 | |
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8053 | /** |
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8054 | * Get the current modem radio state for the given slot. |
| 8055 | * @param slotIndex slot index. |
| 8056 | * @param callingPackage the name of the package making the call. |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8057 | * @param callingFeatureId The feature in the package. |
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8058 | * @return the current radio power state from the modem |
| 8059 | */ |
| 8060 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8061 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8062 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8063 | if (phone != null) { |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8064 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8065 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8066 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8067 | } |
| 8068 | |
| 8069 | final long identity = Binder.clearCallingIdentity(); |
| 8070 | try { |
| 8071 | return phone.getRadioPowerState(); |
| 8072 | } finally { |
| 8073 | Binder.restoreCallingIdentity(identity); |
| 8074 | } |
| 8075 | } |
| 8076 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8077 | } |
| 8078 | |
| 8079 | /** |
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8080 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8081 | * |
| 8082 | * <p>Requires one of the following permissions: |
| 8083 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8084 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8085 | * privileges. |
| 8086 | * |
| 8087 | * @param subId subscription id |
| 8088 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8089 | * {@code false}. |
| 8090 | */ |
| 8091 | @Override |
| 8092 | public boolean isDataRoamingEnabled(int subId) { |
| Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8093 | try { |
| 8094 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8095 | null); |
| 8096 | } catch (Exception e) { |
| 8097 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8098 | mApp, subId, "isDataRoamingEnabled"); |
| 8099 | } |
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8100 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8101 | boolean isEnabled = false; |
| 8102 | final long identity = Binder.clearCallingIdentity(); |
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8103 | try { |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8104 | Phone phone = getPhone(subId); |
| 8105 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8106 | } finally { |
| 8107 | Binder.restoreCallingIdentity(identity); |
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8108 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8109 | return isEnabled; |
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8110 | } |
| 8111 | |
| 8112 | |
| 8113 | /** |
| 8114 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8115 | * |
| 8116 | * <p> Requires permission: |
| 8117 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8118 | * privileges. |
| 8119 | * |
| 8120 | * @param subId subscription id |
| 8121 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8122 | */ |
| 8123 | @Override |
| 8124 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8125 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8126 | mApp, subId, "setDataRoamingEnabled"); |
| 8127 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8128 | final long identity = Binder.clearCallingIdentity(); |
| 8129 | try { |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8130 | Phone phone = getPhone(subId); |
| 8131 | if (phone != null) { |
| 8132 | phone.setDataRoamingEnabled(isEnabled); |
| 8133 | } |
| 8134 | } finally { |
| 8135 | Binder.restoreCallingIdentity(identity); |
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8136 | } |
| 8137 | } |
| 8138 | |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8139 | @Override |
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8140 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8141 | TelephonyPermissions |
| 8142 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8143 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8144 | |
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8145 | boolean isAllowed = true; |
| 8146 | final long identity = Binder.clearCallingIdentity(); |
| 8147 | try { |
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8148 | Phone phone = getPhone(subId); |
| 8149 | if (phone != null) { |
| 8150 | isAllowed = phone.isCspPlmnEnabled(); |
| 8151 | } |
| 8152 | } finally { |
| 8153 | Binder.restoreCallingIdentity(identity); |
| 8154 | } |
| 8155 | return isAllowed; |
| 8156 | } |
| 8157 | |
| 8158 | @Override |
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8159 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
| Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8160 | // Verify that tha callingPackage belongs to the calling UID |
| 8161 | mApp.getSystemService(AppOpsManager.class) |
| 8162 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8163 | |
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8164 | boolean hasReadPermission = false; |
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8165 | try { |
| 8166 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8167 | hasReadPermission = true; |
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8168 | } catch (SecurityException e) { |
| 8169 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8170 | // has carrier privileges on an active UICC |
| 8171 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8172 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8173 | throw new SecurityException("Caller does not have permission."); |
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8174 | } |
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8175 | } |
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8176 | |
| 8177 | final long identity = Binder.clearCallingIdentity(); |
| 8178 | try { |
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8179 | UiccController uiccController = UiccController.getInstance(); |
| 8180 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8181 | if (hasReadPermission) { |
| 8182 | return cardInfos; |
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8183 | } |
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8184 | |
| 8185 | // Remove private info if the caller doesn't have access |
| 8186 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8187 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8188 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8189 | // is available |
| 8190 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8191 | if (card == null || card.getUiccProfile() == null) { |
| 8192 | // assume no access if the card or profile is unavailable |
| 8193 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8194 | continue; |
| 8195 | } |
| 8196 | UiccProfile profile = card.getUiccProfile(); |
| 8197 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8198 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8199 | filteredInfos.add(cardInfo); |
| 8200 | } else { |
| 8201 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8202 | } |
| 8203 | } |
| 8204 | return filteredInfos; |
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8205 | } finally { |
| 8206 | Binder.restoreCallingIdentity(identity); |
| 8207 | } |
| 8208 | } |
| 8209 | |
| 8210 | @Override |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8211 | public UiccSlotInfo[] getUiccSlotsInfo() { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8212 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8213 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8214 | final long identity = Binder.clearCallingIdentity(); |
| 8215 | try { |
| 8216 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8217 | if (slots == null) { |
| 8218 | Rlog.i(LOG_TAG, "slots is null."); |
| 8219 | return null; |
| 8220 | } |
| 8221 | |
| 8222 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8223 | for (int i = 0; i < slots.length; i++) { |
| 8224 | UiccSlot slot = slots[i]; |
| 8225 | if (slot == null) { |
| 8226 | continue; |
| 8227 | } |
| 8228 | |
| Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8229 | String cardId; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8230 | UiccCard card = slot.getUiccCard(); |
| 8231 | if (card != null) { |
| 8232 | cardId = card.getCardId(); |
| Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8233 | } else { |
| Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8234 | cardId = slot.getEid(); |
| 8235 | if (TextUtils.isEmpty(cardId)) { |
| 8236 | cardId = slot.getIccId(); |
| 8237 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8238 | } |
| 8239 | |
| Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8240 | if (cardId != null) { |
| 8241 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8242 | // if cardId is an EID, it's all digits so this is fine |
| 8243 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8244 | } |
| 8245 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8246 | int cardState = 0; |
| 8247 | switch (slot.getCardState()) { |
| 8248 | case CARDSTATE_ABSENT: |
| 8249 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8250 | break; |
| 8251 | case CARDSTATE_PRESENT: |
| 8252 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8253 | break; |
| 8254 | case CARDSTATE_ERROR: |
| 8255 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8256 | break; |
| 8257 | case CARDSTATE_RESTRICTED: |
| 8258 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8259 | break; |
| 8260 | default: |
| 8261 | break; |
| 8262 | |
| 8263 | } |
| 8264 | |
| 8265 | infos[i] = new UiccSlotInfo( |
| 8266 | slot.isActive(), |
| 8267 | slot.isEuicc(), |
| 8268 | cardId, |
| 8269 | cardState, |
| 8270 | slot.getPhoneId(), |
| Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8271 | slot.isExtendedApduSupported(), |
| 8272 | slot.isRemovable()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8273 | } |
| 8274 | return infos; |
| 8275 | } finally { |
| 8276 | Binder.restoreCallingIdentity(identity); |
| Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8277 | } |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8278 | } |
| 8279 | |
| 8280 | @Override |
| 8281 | public boolean switchSlots(int[] physicalSlots) { |
| 8282 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8283 | |
| 8284 | final long identity = Binder.clearCallingIdentity(); |
| 8285 | try { |
| 8286 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8287 | } finally { |
| 8288 | Binder.restoreCallingIdentity(identity); |
| 8289 | } |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8290 | } |
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8291 | |
| 8292 | @Override |
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8293 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8294 | final long identity = Binder.clearCallingIdentity(); |
| 8295 | try { |
| 8296 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8297 | } finally { |
| 8298 | Binder.restoreCallingIdentity(identity); |
| 8299 | } |
| 8300 | } |
| 8301 | |
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8302 | /** |
| goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8303 | * A test API to reload the UICC profile. |
| 8304 | * |
| 8305 | * <p>Requires that the calling app has permission |
| 8306 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8307 | * @hide |
| 8308 | */ |
| 8309 | @Override |
| 8310 | public void refreshUiccProfile(int subId) { |
| 8311 | enforceModifyPermission(); |
| 8312 | |
| 8313 | final long identity = Binder.clearCallingIdentity(); |
| 8314 | try { |
| 8315 | Phone phone = getPhone(subId); |
| 8316 | if (phone == null) { |
| 8317 | return; |
| 8318 | } |
| 8319 | UiccCard uiccCard = phone.getUiccCard(); |
| 8320 | if (uiccCard == null) { |
| 8321 | return; |
| 8322 | } |
| 8323 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8324 | if (uiccProfile == null) { |
| 8325 | return; |
| 8326 | } |
| 8327 | uiccProfile.refresh(); |
| 8328 | } finally { |
| 8329 | Binder.restoreCallingIdentity(identity); |
| 8330 | } |
| 8331 | } |
| 8332 | |
| 8333 | /** |
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8334 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8335 | */ |
| 8336 | private boolean getDefaultDataEnabled() { |
| Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8337 | return TelephonyProperties.mobile_data().orElse(true); |
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8338 | } |
| 8339 | |
| 8340 | /** |
| 8341 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8342 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8343 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8344 | */ |
| 8345 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8346 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8347 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8348 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8349 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8350 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8351 | return isDataRoamingEnabled; |
| 8352 | } |
| 8353 | |
| 8354 | /** |
| 8355 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8356 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8357 | */ |
| 8358 | private int getDefaultNetworkType(int subId) { |
| Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8359 | List<Integer> list = TelephonyProperties.default_network(); |
| 8360 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8361 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8362 | return list.get(phoneId); |
| 8363 | } |
| 8364 | return Phone.PREFERRED_NT_MODE; |
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8365 | } |
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8366 | |
| 8367 | @Override |
| 8368 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8369 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8370 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8371 | |
| 8372 | final long identity = Binder.clearCallingIdentity(); |
| 8373 | try { |
| 8374 | final Phone phone = getPhone(subId); |
| 8375 | if (phone == null) { |
| 8376 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8377 | return; |
| 8378 | } |
| chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8379 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8380 | carrierPrivilegeRules, apn); |
| Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8381 | if (carrierPrivilegeRules == null) { |
| 8382 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8383 | } else { |
| 8384 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8385 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8386 | } finally { |
| 8387 | Binder.restoreCallingIdentity(identity); |
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8388 | } |
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8389 | } |
| 8390 | |
| 8391 | @Override |
| 8392 | public int getCarrierIdListVersion(int subId) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8393 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8394 | |
| 8395 | final long identity = Binder.clearCallingIdentity(); |
| 8396 | try { |
| 8397 | final Phone phone = getPhone(subId); |
| 8398 | if (phone == null) { |
| 8399 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8400 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8401 | } |
| 8402 | return phone.getCarrierIdListVersion(); |
| 8403 | } finally { |
| 8404 | Binder.restoreCallingIdentity(identity); |
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8405 | } |
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8406 | } |
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8407 | |
| 8408 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8409 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8410 | String callingFeatureId) { |
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8411 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8412 | mApp, subId, callingPackage, callingFeatureId, |
| 8413 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8414 | return -1; |
| 8415 | } |
| 8416 | |
| 8417 | final long identity = Binder.clearCallingIdentity(); |
| 8418 | try { |
| 8419 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8420 | } finally { |
| 8421 | Binder.restoreCallingIdentity(identity); |
| 8422 | } |
| 8423 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8424 | |
| 8425 | @Override |
| 8426 | public int getCdmaRoamingMode(int subId) { |
| zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8427 | TelephonyPermissions |
| 8428 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8429 | mApp, subId, "getCdmaRoamingMode"); |
| 8430 | |
| 8431 | final long identity = Binder.clearCallingIdentity(); |
| 8432 | try { |
| 8433 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8434 | } finally { |
| 8435 | Binder.restoreCallingIdentity(identity); |
| 8436 | } |
| 8437 | } |
| 8438 | |
| 8439 | @Override |
| 8440 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8441 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8442 | mApp, subId, "setCdmaRoamingMode"); |
| 8443 | |
| 8444 | final long identity = Binder.clearCallingIdentity(); |
| 8445 | try { |
| 8446 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8447 | } finally { |
| 8448 | Binder.restoreCallingIdentity(identity); |
| 8449 | } |
| 8450 | } |
| 8451 | |
| 8452 | @Override |
| Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8453 | public int getCdmaSubscriptionMode(int subId) { |
| 8454 | TelephonyPermissions |
| 8455 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8456 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8457 | |
| 8458 | final long identity = Binder.clearCallingIdentity(); |
| 8459 | try { |
| 8460 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8461 | } finally { |
| 8462 | Binder.restoreCallingIdentity(identity); |
| 8463 | } |
| 8464 | } |
| 8465 | |
| 8466 | @Override |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8467 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8468 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8469 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8470 | |
| 8471 | final long identity = Binder.clearCallingIdentity(); |
| 8472 | try { |
| 8473 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8474 | } finally { |
| 8475 | Binder.restoreCallingIdentity(identity); |
| 8476 | } |
| 8477 | } |
| Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8478 | |
| sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8479 | @Override |
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8480 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8481 | String callingPackage, String callingFeatureId) { |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8482 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8483 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8484 | "getEmergencyNumberList")) { |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8485 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8486 | } |
| 8487 | final long identity = Binder.clearCallingIdentity(); |
| 8488 | try { |
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8489 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8490 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8491 | if (phone.getEmergencyNumberTracker() != null |
| 8492 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8493 | emergencyNumberListInternal.put( |
| 8494 | phone.getSubId(), |
| 8495 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8496 | } |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8497 | } |
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8498 | return emergencyNumberListInternal; |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8499 | } finally { |
| 8500 | Binder.restoreCallingIdentity(identity); |
| 8501 | } |
| sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8502 | } |
| 8503 | |
| 8504 | @Override |
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8505 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8506 | final Phone defaultPhone = getDefaultPhone(); |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8507 | if (!exactMatch) { |
| 8508 | TelephonyPermissions |
| 8509 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8510 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8511 | } |
| 8512 | final long identity = Binder.clearCallingIdentity(); |
| 8513 | try { |
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8514 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8515 | if (phone.getEmergencyNumberTracker() != null |
| Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8516 | && phone.getEmergencyNumberTracker() |
| 8517 | .isEmergencyNumber(number, exactMatch)) { |
| 8518 | return true; |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8519 | } |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8520 | } |
| 8521 | return false; |
| 8522 | } finally { |
| 8523 | Binder.restoreCallingIdentity(identity); |
| 8524 | } |
| 8525 | } |
| 8526 | |
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8527 | /** |
| 8528 | * Update emergency number list for test mode. |
| 8529 | */ |
| 8530 | @Override |
| 8531 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8532 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8533 | "updateEmergencyNumberListTestMode"); |
| 8534 | |
| 8535 | final long identity = Binder.clearCallingIdentity(); |
| 8536 | try { |
| 8537 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8538 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8539 | if (tracker != null) { |
| 8540 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8541 | } |
| 8542 | } |
| 8543 | } finally { |
| 8544 | Binder.restoreCallingIdentity(identity); |
| 8545 | } |
| 8546 | } |
| 8547 | |
| 8548 | /** |
| 8549 | * Get the full emergency number list for test mode. |
| 8550 | */ |
| 8551 | @Override |
| 8552 | public List<String> getEmergencyNumberListTestMode() { |
| 8553 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8554 | "getEmergencyNumberListTestMode"); |
| 8555 | |
| 8556 | final long identity = Binder.clearCallingIdentity(); |
| 8557 | try { |
| 8558 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8559 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8560 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8561 | if (tracker != null) { |
| 8562 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8563 | emergencyNumbers.add(num.getNumber()); |
| 8564 | } |
| 8565 | } |
| 8566 | } |
| 8567 | return new ArrayList<>(emergencyNumbers); |
| 8568 | } finally { |
| 8569 | Binder.restoreCallingIdentity(identity); |
| 8570 | } |
| 8571 | } |
| 8572 | |
| chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8573 | @Override |
| Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8574 | public int getEmergencyNumberDbVersion(int subId) { |
| 8575 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8576 | |
| 8577 | final long identity = Binder.clearCallingIdentity(); |
| 8578 | try { |
| 8579 | final Phone phone = getPhone(subId); |
| 8580 | if (phone == null) { |
| 8581 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8582 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8583 | } |
| 8584 | return phone.getEmergencyNumberDbVersion(); |
| 8585 | } finally { |
| 8586 | Binder.restoreCallingIdentity(identity); |
| 8587 | } |
| 8588 | } |
| 8589 | |
| 8590 | @Override |
| 8591 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8592 | enforceModifyPermission(); |
| 8593 | |
| 8594 | final long identity = Binder.clearCallingIdentity(); |
| 8595 | try { |
| 8596 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8597 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8598 | if (tracker != null) { |
| 8599 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8600 | } |
| 8601 | } |
| 8602 | } finally { |
| 8603 | Binder.restoreCallingIdentity(identity); |
| 8604 | } |
| 8605 | } |
| 8606 | |
| 8607 | @Override |
| Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8608 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
| Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8609 | enforceActiveEmergencySessionPermission(); |
| 8610 | |
| 8611 | final long identity = Binder.clearCallingIdentity(); |
| 8612 | try { |
| 8613 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8614 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8615 | if (tracker != null) { |
| Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8616 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8617 | } |
| 8618 | } |
| 8619 | } finally { |
| 8620 | Binder.restoreCallingIdentity(identity); |
| 8621 | } |
| 8622 | } |
| 8623 | |
| 8624 | @Override |
| 8625 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8626 | enforceActiveEmergencySessionPermission(); |
| 8627 | |
| 8628 | final long identity = Binder.clearCallingIdentity(); |
| 8629 | try { |
| 8630 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8631 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8632 | if (tracker != null) { |
| 8633 | tracker.resetOtaEmergencyNumberDbFilePath(); |
| Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8634 | } |
| 8635 | } |
| 8636 | } finally { |
| 8637 | Binder.restoreCallingIdentity(identity); |
| 8638 | } |
| 8639 | } |
| 8640 | |
| 8641 | @Override |
| chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8642 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8643 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8644 | Phone phone = getPhone(subId); |
| 8645 | if (phone == null) { |
| 8646 | return null; |
| 8647 | } |
| 8648 | final long identity = Binder.clearCallingIdentity(); |
| 8649 | try { |
| 8650 | UiccProfile profile = UiccController.getInstance() |
| 8651 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8652 | if (profile != null) { |
| 8653 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8654 | } |
| 8655 | } finally { |
| 8656 | Binder.restoreCallingIdentity(identity); |
| 8657 | } |
| 8658 | return null; |
| 8659 | } |
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8660 | |
| 8661 | /** |
| 8662 | * Enable or disable a modem stack. |
| 8663 | */ |
| 8664 | @Override |
| 8665 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8666 | enforceModifyPermission(); |
| 8667 | |
| 8668 | final long identity = Binder.clearCallingIdentity(); |
| 8669 | try { |
| 8670 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8671 | if (phone == null) { |
| 8672 | return false; |
| 8673 | } else { |
| 8674 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8675 | } |
| 8676 | } finally { |
| 8677 | Binder.restoreCallingIdentity(identity); |
| 8678 | } |
| 8679 | } |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8680 | |
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8681 | /** |
| 8682 | * Whether a modem stack is enabled or not. |
| 8683 | */ |
| 8684 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8685 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8686 | String callingFeatureId) { |
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8687 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8688 | if (phone == null) return false; |
| 8689 | |
| 8690 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8691 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8692 | "isModemEnabledForSlot")) { |
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8693 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8694 | } |
| 8695 | |
| 8696 | final long identity = Binder.clearCallingIdentity(); |
| 8697 | try { |
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8698 | try { |
| 8699 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8700 | } catch (NoSuchElementException ex) { |
| 8701 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8702 | } |
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8703 | } finally { |
| 8704 | Binder.restoreCallingIdentity(identity); |
| 8705 | } |
| 8706 | } |
| 8707 | |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8708 | @Override |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8709 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8710 | enforceModifyPermission(); |
| 8711 | |
| 8712 | final long identity = Binder.clearCallingIdentity(); |
| 8713 | try { |
| 8714 | mTelephonySharedPreferences.edit() |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8715 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8716 | .commit(); |
| 8717 | } finally { |
| 8718 | Binder.restoreCallingIdentity(identity); |
| 8719 | } |
| 8720 | } |
| 8721 | |
| 8722 | @Override |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8723 | @TelephonyManager.IsMultiSimSupportedResult |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8724 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8725 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8726 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8727 | "isMultiSimSupported")) { |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8728 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8729 | } |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8730 | |
| 8731 | final long identity = Binder.clearCallingIdentity(); |
| 8732 | try { |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8733 | return isMultiSimSupportedInternal(); |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8734 | } finally { |
| 8735 | Binder.restoreCallingIdentity(identity); |
| 8736 | } |
| 8737 | } |
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8738 | |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8739 | @TelephonyManager.IsMultiSimSupportedResult |
| 8740 | private int isMultiSimSupportedInternal() { |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8741 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8742 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8743 | if (numPhysicalSlots < 2) { |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8744 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8745 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8746 | } |
| 8747 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8748 | // supported by the modem, indicate that it is restricted. |
| 8749 | PhoneCapability staticCapability = |
| 8750 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8751 | if (staticCapability == null) { |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8752 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8753 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8754 | } |
| Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8755 | if (staticCapability.logicalModemList.size() < 2) { |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8756 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8757 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8758 | } |
| 8759 | // Check if support of multiple SIMs is restricted by carrier |
| 8760 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8761 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8762 | } |
| 8763 | |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8764 | return TelephonyManager.MULTISIM_ALLOWED; |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8765 | } |
| 8766 | |
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8767 | /** |
| 8768 | * Switch configs to enable multi-sim or switch back to single-sim |
| Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8769 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8770 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8771 | * or carrier privileges |
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8772 | * @param numOfSims number of active sims we want to switch to |
| 8773 | */ |
| 8774 | @Override |
| 8775 | public void switchMultiSimConfig(int numOfSims) { |
| Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8776 | if (numOfSims == 1) { |
| 8777 | enforceModifyPermission(); |
| 8778 | } else { |
| 8779 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8780 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8781 | } |
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8782 | final long identity = Binder.clearCallingIdentity(); |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8783 | |
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8784 | try { |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8785 | //only proceed if multi-sim is not restricted |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8786 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8787 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8788 | return; |
| 8789 | } |
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8790 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8791 | } finally { |
| 8792 | Binder.restoreCallingIdentity(identity); |
| 8793 | } |
| 8794 | } |
| 8795 | |
| Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8796 | @Override |
| 8797 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8798 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8799 | Phone phone = getPhone(subId); |
| 8800 | if (phone == null) { |
| 8801 | return false; |
| 8802 | } |
| 8803 | final long identity = Binder.clearCallingIdentity(); |
| 8804 | try { |
| 8805 | UiccCard uiccCard = phone.getUiccCard(); |
| 8806 | if (uiccCard == null) { |
| 8807 | return false; |
| 8808 | } |
| 8809 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8810 | if (uiccProfile == null) { |
| 8811 | return false; |
| 8812 | } |
| 8813 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8814 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8815 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8816 | } |
| 8817 | return false; |
| 8818 | } finally { |
| 8819 | Binder.restoreCallingIdentity(identity); |
| 8820 | } |
| 8821 | } |
| 8822 | |
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8823 | /** |
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8824 | * Get whether making changes to modem configurations will trigger reboot. |
| 8825 | * Return value defaults to true. |
| Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8826 | */ |
| 8827 | @Override |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8828 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8829 | String callingFeatureId) { |
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8830 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8831 | mApp, subId, callingPackage, callingFeatureId, |
| 8832 | "doesSwitchMultiSimConfigTriggerReboot")) { |
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8833 | return false; |
| 8834 | } |
| Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8835 | final long identity = Binder.clearCallingIdentity(); |
| 8836 | try { |
| 8837 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8838 | } finally { |
| 8839 | Binder.restoreCallingIdentity(identity); |
| 8840 | } |
| 8841 | } |
| 8842 | |
| Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8843 | private void updateModemStateMetrics() { |
| 8844 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8845 | // TODO: check the state for each modem if the api is ready. |
| 8846 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8847 | } |
| 8848 | |
| Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8849 | @Override |
| 8850 | public int[] getSlotsMapping() { |
| 8851 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8852 | |
| 8853 | final long identity = Binder.clearCallingIdentity(); |
| 8854 | try { |
| 8855 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8856 | // All logical slots should have a mapping to a physical slot. |
| 8857 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8858 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8859 | for (int i = 0; i < slotInfos.length; i++) { |
| 8860 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8861 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8862 | } |
| 8863 | } |
| 8864 | return logicalSlotsMapping; |
| 8865 | } finally { |
| 8866 | Binder.restoreCallingIdentity(identity); |
| 8867 | } |
| 8868 | } |
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8869 | |
| 8870 | /** |
| 8871 | * Get the IRadio HAL Version |
| 8872 | */ |
| 8873 | @Override |
| 8874 | public int getRadioHalVersion() { |
| 8875 | Phone phone = getDefaultPhone(); |
| 8876 | if (phone == null) return -1; |
| 8877 | HalVersion hv = phone.getHalVersion(); |
| 8878 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8879 | return hv.major * 100 + hv.minor; |
| 8880 | } |
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8881 | |
| 8882 | /** |
| Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8883 | * Get the current calling package name. |
| 8884 | * @return the current calling package name |
| 8885 | */ |
| 8886 | @Override |
| 8887 | public String getCurrentPackageName() { |
| 8888 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8889 | } |
| 8890 | |
| 8891 | /** |
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8892 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8893 | * corresponding network requests on a subId. |
| 8894 | * |
| 8895 | * Data is enabled if: |
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8896 | * 1) user data is turned on, or |
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8897 | * 2) APN is un-metered for this subscription, or |
| 8898 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8899 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8900 | * |
| 8901 | * @return whether data is allowed for a apn type. |
| 8902 | * |
| 8903 | * @hide |
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8904 | */ |
| 8905 | @Override |
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8906 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
| Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8907 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8908 | + "isDataEnabledForApn"); |
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8909 | |
| 8910 | // Now that all security checks passes, perform the operation as ourselves. |
| 8911 | final long identity = Binder.clearCallingIdentity(); |
| 8912 | try { |
| 8913 | Phone phone = getPhone(subId); |
| 8914 | if (phone == null) return false; |
| 8915 | |
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8916 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8917 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8918 | } finally { |
| 8919 | Binder.restoreCallingIdentity(identity); |
| 8920 | } |
| 8921 | } |
| 8922 | |
| 8923 | @Override |
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8924 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8925 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8926 | |
| 8927 | // Now that all security checks passes, perform the operation as ourselves. |
| 8928 | final long identity = Binder.clearCallingIdentity(); |
| 8929 | try { |
| 8930 | Phone phone = getPhone(subId); |
| 8931 | if (phone == null) return true; // By default return true. |
| 8932 | |
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8933 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8934 | } finally { |
| 8935 | Binder.restoreCallingIdentity(identity); |
| 8936 | } |
| 8937 | } |
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8938 | |
| 8939 | @Override |
| Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8940 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8941 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8942 | enforceModifyPermission(); |
| 8943 | long token = Binder.clearCallingIdentity(); |
| 8944 | try { |
| 8945 | Phone phone = getPhone(subscriptionId); |
| 8946 | if (phone == null) { |
| 8947 | try { |
| 8948 | if (resultCallback != null) { |
| 8949 | resultCallback.accept(false); |
| 8950 | } |
| 8951 | } catch (RemoteException e) { |
| 8952 | // ignore |
| 8953 | } |
| 8954 | return; |
| 8955 | } |
| 8956 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8957 | Pair.create(specifiers, (x) -> { |
| 8958 | try { |
| 8959 | if (resultCallback != null) { |
| 8960 | resultCallback.accept(x); |
| 8961 | } |
| 8962 | } catch (RemoteException e) { |
| 8963 | // ignore |
| 8964 | } |
| 8965 | }); |
| 8966 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8967 | } finally { |
| 8968 | Binder.restoreCallingIdentity(token); |
| 8969 | } |
| 8970 | } |
| 8971 | |
| 8972 | @Override |
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8973 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8974 | TelephonyPermissions |
| 8975 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8976 | mApp, subId, "getSystemSelectionChannels"); |
| 8977 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8978 | final long identity = Binder.clearCallingIdentity(); |
| 8979 | try { |
| 8980 | List<RadioAccessSpecifier> specifiers = |
| 8981 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 8982 | null, subId, workSource); |
| 8983 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 8984 | return specifiers; |
| 8985 | } finally { |
| 8986 | Binder.restoreCallingIdentity(identity); |
| 8987 | } |
| 8988 | } |
| 8989 | |
| 8990 | @Override |
| changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8991 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8992 | enforceReadPrivilegedPermission("isMvnoMatched"); |
| changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8993 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8994 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8995 | if (iccRecords == null) { |
| 8996 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8997 | return false; |
| 8998 | } |
| 8999 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9000 | } |
| 9001 | |
| 9002 | @Override |
| Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9003 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9004 | IIntegerConsumer pendingSubIdResult) { |
| Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9005 | if (callingPackage == null) { |
| 9006 | callingPackage = getCurrentPackageName(); |
| 9007 | } |
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9008 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9009 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9010 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9011 | "Sending message")) { |
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9012 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9013 | } |
| 9014 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9015 | Intent intent = new Intent(); |
| 9016 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9017 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9018 | // Bring up choose default SMS subscription dialog right now |
| 9019 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9020 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9021 | mApp.startActivity(intent); |
| 9022 | } |
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9023 | |
| 9024 | @Override |
| 9025 | public String getMmsUAProfUrl(int subId) { |
| 9026 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9027 | final long identity = Binder.clearCallingIdentity(); |
| 9028 | try { |
| Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9029 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9030 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9031 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9032 | return carrierUAProfUrl; |
| 9033 | } |
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9034 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9035 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 9036 | } finally { |
| 9037 | Binder.restoreCallingIdentity(identity); |
| 9038 | } |
| 9039 | } |
| 9040 | |
| 9041 | @Override |
| 9042 | public String getMmsUserAgent(int subId) { |
| 9043 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9044 | final long identity = Binder.clearCallingIdentity(); |
| 9045 | try { |
| Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9046 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9047 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9048 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9049 | return carrierUserAgent; |
| 9050 | } |
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9051 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9052 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 9053 | } finally { |
| 9054 | Binder.restoreCallingIdentity(identity); |
| 9055 | } |
| 9056 | } |
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9057 | |
| 9058 | @Override |
| Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9059 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9060 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 9061 | |
| 9062 | final long identity = Binder.clearCallingIdentity(); |
| 9063 | try { |
| 9064 | Phone phone = getPhone(subscriptionId); |
| 9065 | if (phone == null) return false; |
| 9066 | |
| 9067 | switch (policy) { |
| 9068 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9069 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9070 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9071 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9072 | default: |
| 9073 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9074 | } |
| 9075 | } finally { |
| 9076 | Binder.restoreCallingIdentity(identity); |
| 9077 | } |
| 9078 | } |
| 9079 | |
| 9080 | @Override |
| 9081 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9082 | boolean enabled) { |
| 9083 | enforceModifyPermission(); |
| 9084 | |
| 9085 | final long identity = Binder.clearCallingIdentity(); |
| 9086 | try { |
| 9087 | Phone phone = getPhone(subscriptionId); |
| 9088 | if (phone == null) return; |
| 9089 | |
| 9090 | switch (policy) { |
| 9091 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9092 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9093 | break; |
| 9094 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9095 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9096 | break; |
| 9097 | default: |
| 9098 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9099 | } |
| 9100 | } finally { |
| 9101 | Binder.restoreCallingIdentity(identity); |
| 9102 | } |
| 9103 | } |
| 9104 | |
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9105 | /** |
| Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9106 | * Updates whether conference event package handling is enabled. |
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9107 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9108 | * otherwise. |
| 9109 | */ |
| 9110 | @Override |
| 9111 | public void setCepEnabled(boolean isCepEnabled) { |
| 9112 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9113 | |
| 9114 | final long identity = Binder.clearCallingIdentity(); |
| 9115 | try { |
| 9116 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9117 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9118 | Phone defaultPhone = phone.getImsPhone(); |
| 9119 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9120 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9121 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9122 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9123 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9124 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9125 | + imsPhone.getMsisdn()); |
| 9126 | } |
| 9127 | } |
| 9128 | } finally { |
| 9129 | Binder.restoreCallingIdentity(identity); |
| 9130 | } |
| 9131 | } |
| allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9132 | |
| 9133 | /** |
| 9134 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9135 | * |
| 9136 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9137 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9138 | * before being read. |
| 9139 | */ |
| 9140 | @Override |
| 9141 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9142 | isCompressed) { |
| 9143 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9144 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9145 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9146 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9147 | } |
| 9148 | if (!isImsAvailableOnDevice()) { |
| 9149 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9150 | "IMS not available on device."); |
| 9151 | } |
| 9152 | |
| 9153 | final long identity = Binder.clearCallingIdentity(); |
| allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9154 | try { |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9155 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9156 | } finally { |
| 9157 | Binder.restoreCallingIdentity(identity); |
| allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9158 | } |
| 9159 | } |
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9160 | |
| 9161 | @Override |
| 9162 | public boolean isIccLockEnabled(int subId) { |
| 9163 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9164 | |
| 9165 | // Now that all security checks passes, perform the operation as ourselves. |
| 9166 | final long identity = Binder.clearCallingIdentity(); |
| 9167 | try { |
| 9168 | Phone phone = getPhone(subId); |
| 9169 | if (phone != null && phone.getIccCard() != null) { |
| 9170 | return phone.getIccCard().getIccLockEnabled(); |
| 9171 | } else { |
| 9172 | return false; |
| 9173 | } |
| 9174 | } finally { |
| 9175 | Binder.restoreCallingIdentity(identity); |
| 9176 | } |
| 9177 | } |
| 9178 | |
| 9179 | /** |
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9180 | * Set the ICC pin lock enabled or disabled. |
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9181 | * |
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9182 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9183 | * three cases: |
| 9184 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9185 | * successfully. |
| 9186 | * - Positive number and zero for remaining password attempts. |
| 9187 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9188 | * |
| 9189 | */ |
| 9190 | @Override |
| 9191 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9192 | enforceModifyPermission(); |
| 9193 | |
| 9194 | Phone phone = getPhone(subId); |
| 9195 | if (phone == null) { |
| 9196 | return 0; |
| 9197 | } |
| 9198 | // Now that all security checks passes, perform the operation as ourselves. |
| 9199 | final long identity = Binder.clearCallingIdentity(); |
| 9200 | try { |
| 9201 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9202 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9203 | return attemptsRemaining; |
| 9204 | |
| 9205 | } catch (Exception e) { |
| 9206 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9207 | } finally { |
| 9208 | Binder.restoreCallingIdentity(identity); |
| 9209 | } |
| 9210 | return 0; |
| 9211 | } |
| 9212 | |
| 9213 | /** |
| 9214 | * Change the ICC password used in ICC pin lock. |
| 9215 | * |
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9216 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9217 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9218 | * - Positive number and zero for remaining password attempts. |
| 9219 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9220 | * |
| 9221 | */ |
| 9222 | @Override |
| 9223 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9224 | enforceModifyPermission(); |
| 9225 | |
| 9226 | Phone phone = getPhone(subId); |
| 9227 | if (phone == null) { |
| 9228 | return 0; |
| 9229 | } |
| 9230 | // Now that all security checks passes, perform the operation as ourselves. |
| 9231 | final long identity = Binder.clearCallingIdentity(); |
| 9232 | try { |
| 9233 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9234 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9235 | return attemptsRemaining; |
| 9236 | |
| 9237 | } catch (Exception e) { |
| 9238 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9239 | } finally { |
| 9240 | Binder.restoreCallingIdentity(identity); |
| 9241 | } |
| 9242 | return 0; |
| 9243 | } |
| Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9244 | |
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9245 | /** |
| 9246 | * Request for receiving user activity notification |
| 9247 | */ |
| 9248 | @Override |
| 9249 | public void requestUserActivityNotification() { |
| 9250 | if (!mNotifyUserActivity.get() |
| 9251 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9252 | mNotifyUserActivity.set(true); |
| 9253 | } |
| 9254 | } |
| 9255 | |
| 9256 | /** |
| 9257 | * Called when userActivity is signalled in the power manager. |
| 9258 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9259 | */ |
| 9260 | @Override |
| 9261 | public void userActivity() { |
| 9262 | // *************************************** |
| 9263 | // * Inherited from PhoneWindowManager * |
| 9264 | // *************************************** |
| 9265 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9266 | // WITH ITS LOCKS HELD. |
| 9267 | // |
| 9268 | // This code must be VERY careful about the locks |
| 9269 | // it acquires. |
| 9270 | // In fact, the current code acquires way too many, |
| 9271 | // and probably has lurking deadlocks. |
| 9272 | |
| 9273 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9274 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9275 | } |
| 9276 | |
| 9277 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9278 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9279 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9280 | } |
| 9281 | } |
| Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9282 | |
| Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9283 | @Override |
| 9284 | public boolean canConnectTo5GInDsdsMode() { |
| 9285 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9286 | } |
| Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9287 | |
| 9288 | @Override |
| 9289 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9290 | String callingFeatureId) { |
| 9291 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9292 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9293 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9294 | } |
| 9295 | |
| 9296 | Phone phone = getPhone(subId); |
| 9297 | if (phone == null) { |
| 9298 | throw new RuntimeException("phone is not available"); |
| 9299 | } |
| 9300 | // Now that all security checks passes, perform the operation as ourselves. |
| 9301 | final long identity = Binder.clearCallingIdentity(); |
| 9302 | try { |
| 9303 | return phone.getEquivalentHomePlmns(); |
| 9304 | } finally { |
| 9305 | Binder.restoreCallingIdentity(identity); |
| 9306 | } |
| 9307 | } |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9308 | |
| Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9309 | @Override |
| Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9310 | public boolean isRadioInterfaceCapabilitySupported( |
| 9311 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9312 | Set<String> radioInterfaceCapabilities = |
| Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9313 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9314 | if (radioInterfaceCapabilities == null) { |
| 9315 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9316 | } else { |
| Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9317 | return radioInterfaceCapabilities.contains(capability); |
| Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9318 | } |
| 9319 | } |
| 9320 | |
| 9321 | @Override |
| Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9322 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9323 | UaSecurityProtocolIdentifier securityProtocol, |
| Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9324 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9325 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9326 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9327 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9328 | Manifest.permission.MODIFY_PHONE_STATE); |
| Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9329 | if (DBG) { |
| 9330 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9331 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9332 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9333 | } |
| 9334 | |
| 9335 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9336 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9337 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9338 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9339 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9340 | if (callback != null) { |
| 9341 | try { |
| 9342 | callback.onAuthenticationFailure( |
| 9343 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9344 | } catch (RemoteException exception) { |
| 9345 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9346 | } |
| 9347 | return; |
| 9348 | } |
| 9349 | } |
| 9350 | |
| 9351 | final long token = Binder.clearCallingIdentity(); |
| 9352 | try { |
| 9353 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9354 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9355 | forceBootStrapping, callback)); |
| 9356 | } finally { |
| 9357 | Binder.restoreCallingIdentity(token); |
| 9358 | } |
| 9359 | } |
| 9360 | |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9361 | /** |
| 9362 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9363 | * requested radio power state will actually be set. See {@link |
| 9364 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9365 | * |
| 9366 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9367 | * @param enable {@code true} if trying to turn radio on. |
| 9368 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9369 | * false}. |
| 9370 | */ |
| 9371 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9372 | Phone phone = getPhone(subId); |
| 9373 | if (phone != null) { |
| 9374 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9375 | return true; |
| 9376 | } |
| 9377 | return false; |
| 9378 | } |
| 9379 | |
| 9380 | private int handleDataThrottlingRequest(int subId, |
| 9381 | DataThrottlingRequest dataThrottlingRequest) { |
| 9382 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9383 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9384 | if (!setRadioPowerForThermal(subId, true)) { |
| 9385 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9386 | } |
| 9387 | |
| 9388 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9389 | |
| 9390 | int thermalMitigationResult = |
| 9391 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9392 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9393 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9394 | } |
| 9395 | return thermalMitigationResult; |
| 9396 | } |
| 9397 | |
| 9398 | /** |
| 9399 | * Thermal mitigation request to control functionalities at modem. |
| 9400 | * |
| 9401 | * @param subId the id of the subscription. |
| 9402 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9403 | * |
| 9404 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9405 | */ |
| 9406 | @Override |
| 9407 | @ThermalMitigationResult |
| 9408 | public int sendThermalMitigationRequest( |
| 9409 | int subId, |
| 9410 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9411 | enforceModifyPermission(); |
| 9412 | |
| 9413 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9414 | final long identity = Binder.clearCallingIdentity(); |
| 9415 | |
| 9416 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9417 | try { |
| 9418 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9419 | switch (thermalMitigationAction) { |
| 9420 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9421 | thermalMitigationResult = |
| Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9422 | handleDataThrottlingRequest(subId, |
| 9423 | thermalMitigationRequest.getDataThrottlingRequest()); |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9424 | break; |
| 9425 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9426 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9427 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9428 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9429 | } |
| 9430 | |
| 9431 | // Ensure that radio is on. If not able to power on due to phone being |
| 9432 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9433 | if (!setRadioPowerForThermal(subId, true)) { |
| 9434 | thermalMitigationResult = |
| 9435 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9436 | break; |
| 9437 | } |
| 9438 | |
| 9439 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9440 | false); |
| 9441 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9442 | break; |
| 9443 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9444 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9445 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9446 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9447 | } |
| 9448 | |
| 9449 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9450 | if (registry != null) { |
| 9451 | TelephonyConnectionService service = |
| 9452 | registry.getTelephonyConnectionService(); |
| 9453 | Phone phone = getPhone(subId); |
| 9454 | if (phone == null) { |
| 9455 | thermalMitigationResult = |
| Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9456 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9457 | break; |
| 9458 | } |
| 9459 | |
| 9460 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9461 | != TelephonyManager.CALL_STATE_IDLE |
| 9462 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9463 | || (service != null && service.isEmergencyCallPending())) { |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9464 | String errorMessage = "Phone state is not valid. call state = " |
| 9465 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9466 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9467 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9468 | errorMessage += service == null |
| 9469 | ? " TelephonyConnectionService is null" |
| 9470 | : " isEmergencyCallPending = " |
| 9471 | + service.isEmergencyCallPending(); |
| 9472 | Log.e(LOG_TAG, errorMessage); |
| 9473 | thermalMitigationResult = |
| Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9474 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9475 | break; |
| 9476 | } |
| 9477 | } else { |
| 9478 | thermalMitigationResult = |
| 9479 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9480 | break; |
| 9481 | } |
| 9482 | |
| 9483 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9484 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9485 | if (!setRadioPowerForThermal(subId, false)) { |
| 9486 | thermalMitigationResult = |
| 9487 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9488 | break; |
| 9489 | } |
| 9490 | thermalMitigationResult = |
| Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9491 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9492 | break; |
| 9493 | default: |
| 9494 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9495 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9496 | } |
| 9497 | } catch (IllegalArgumentException e) { |
| 9498 | throw e; |
| 9499 | } catch (Exception e) { |
| 9500 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9501 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9502 | } finally { |
| 9503 | Binder.restoreCallingIdentity(identity); |
| 9504 | } |
| 9505 | |
| 9506 | if (DBG) { |
| 9507 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9508 | + thermalMitigationResult); |
| 9509 | } |
| 9510 | |
| 9511 | return thermalMitigationResult; |
| 9512 | } |
| Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9513 | |
| 9514 | /** |
| 9515 | * Set the GbaService Package Name that Telephony will bind to. |
| 9516 | * |
| 9517 | * @param subId The sim that the GbaService is associated with. |
| 9518 | * @param packageName The name of the package to be replaced with. |
| 9519 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9520 | */ |
| 9521 | @Override |
| 9522 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9523 | enforceModifyPermission(); |
| 9524 | |
| 9525 | final long identity = Binder.clearCallingIdentity(); |
| 9526 | try { |
| 9527 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9528 | } finally { |
| 9529 | Binder.restoreCallingIdentity(identity); |
| 9530 | } |
| 9531 | } |
| 9532 | |
| 9533 | /** |
| 9534 | * Return the package name of the currently bound GbaService. |
| 9535 | * |
| 9536 | * @param subId The sim that the GbaService is associated with. |
| 9537 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9538 | */ |
| 9539 | @Override |
| 9540 | public String getBoundGbaService(int subId) { |
| 9541 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9542 | |
| 9543 | final long identity = Binder.clearCallingIdentity(); |
| 9544 | try { |
| 9545 | return getGbaManager(subId).getServicePackage(); |
| 9546 | } finally { |
| 9547 | Binder.restoreCallingIdentity(identity); |
| 9548 | } |
| 9549 | } |
| 9550 | |
| 9551 | /** |
| 9552 | * Set the release time for telephony to unbind GbaService. |
| 9553 | * |
| 9554 | * @param subId The sim that the GbaService is associated with. |
| 9555 | * @param interval The release time to unbind GbaService by millisecond. |
| 9556 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9557 | */ |
| 9558 | @Override |
| 9559 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9560 | enforceModifyPermission(); |
| 9561 | |
| 9562 | final long identity = Binder.clearCallingIdentity(); |
| 9563 | try { |
| 9564 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9565 | } finally { |
| 9566 | Binder.restoreCallingIdentity(identity); |
| 9567 | } |
| 9568 | } |
| 9569 | |
| 9570 | /** |
| 9571 | * Return the release time for telephony to unbind GbaService. |
| 9572 | * |
| 9573 | * @param subId The sim that the GbaService is associated with. |
| 9574 | * @return The release time to unbind GbaService by millisecond. |
| 9575 | */ |
| 9576 | @Override |
| 9577 | public int getGbaReleaseTime(int subId) { |
| 9578 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9579 | |
| 9580 | final long identity = Binder.clearCallingIdentity(); |
| 9581 | try { |
| 9582 | return getGbaManager(subId).getReleaseTime(); |
| 9583 | } finally { |
| 9584 | Binder.restoreCallingIdentity(identity); |
| 9585 | } |
| 9586 | } |
| 9587 | |
| 9588 | private GbaManager getGbaManager(int subId) { |
| 9589 | GbaManager instance = GbaManager.getInstance(subId); |
| 9590 | if (instance == null) { |
| 9591 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9592 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9593 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9594 | } |
| 9595 | return instance; |
| 9596 | } |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9597 | |
| 9598 | /** |
| 9599 | * indicate whether the device and the carrier can support |
| 9600 | * RCS VoLTE single registration. |
| 9601 | */ |
| 9602 | @Override |
| 9603 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
| Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9604 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9605 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 9606 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9607 | permission.READ_PRIVILEGED_PHONE_STATE); |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9608 | |
| 9609 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9610 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9611 | } |
| 9612 | |
| 9613 | final long identity = Binder.clearCallingIdentity(); |
| 9614 | try { |
| 9615 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9616 | if (rpm != null) { |
| 9617 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9618 | } |
| 9619 | return false; |
| 9620 | } finally { |
| 9621 | Binder.restoreCallingIdentity(identity); |
| 9622 | } |
| 9623 | } |
| 9624 | |
| 9625 | /** |
| 9626 | * Register RCS provisioning callback. |
| 9627 | */ |
| 9628 | @Override |
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9629 | public void registerRcsProvisioningCallback(int subId, |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9630 | IRcsConfigCallback callback) { |
| Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9631 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9632 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
| Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9633 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9634 | permission.READ_PRIVILEGED_PHONE_STATE); |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9635 | |
| 9636 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9637 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9638 | } |
| 9639 | if (!isImsAvailableOnDevice()) { |
| 9640 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9641 | "IMS not available on device."); |
| 9642 | } |
| 9643 | |
| 9644 | final long identity = Binder.clearCallingIdentity(); |
| 9645 | try { |
| Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9646 | if (!RcsProvisioningMonitor.getInstance() |
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9647 | .registerRcsProvisioningCallback(subId, callback)) { |
| Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9648 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9649 | "Service not available for the subscription."); |
| 9650 | } |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9651 | } finally { |
| 9652 | Binder.restoreCallingIdentity(identity); |
| 9653 | } |
| 9654 | } |
| 9655 | |
| 9656 | /** |
| 9657 | * Unregister RCS provisioning callback. |
| 9658 | */ |
| 9659 | @Override |
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9660 | public void unregisterRcsProvisioningCallback(int subId, |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9661 | IRcsConfigCallback callback) { |
| Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9662 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9663 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
| Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9664 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9665 | permission.READ_PRIVILEGED_PHONE_STATE); |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9666 | |
| 9667 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9668 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9669 | } |
| 9670 | if (!isImsAvailableOnDevice()) { |
| 9671 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9672 | "IMS not available on device."); |
| 9673 | } |
| 9674 | |
| 9675 | final long identity = Binder.clearCallingIdentity(); |
| 9676 | try { |
| Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9677 | RcsProvisioningMonitor.getInstance() |
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9678 | .unregisterRcsProvisioningCallback(subId, callback); |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9679 | } finally { |
| 9680 | Binder.restoreCallingIdentity(identity); |
| 9681 | } |
| 9682 | } |
| 9683 | |
| 9684 | /** |
| 9685 | * trigger RCS reconfiguration. |
| 9686 | */ |
| 9687 | public void triggerRcsReconfiguration(int subId) { |
| Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9688 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9689 | "triggerRcsReconfiguration", |
| 9690 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9691 | |
| 9692 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9693 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9694 | } |
| 9695 | if (!isImsAvailableOnDevice()) { |
| 9696 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9697 | "IMS not available on device."); |
| 9698 | } |
| 9699 | |
| 9700 | final long identity = Binder.clearCallingIdentity(); |
| 9701 | try { |
| 9702 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9703 | } finally { |
| 9704 | Binder.restoreCallingIdentity(identity); |
| 9705 | } |
| 9706 | } |
| 9707 | |
| 9708 | /** |
| 9709 | * Provide the client configuration parameters of the RCS application. |
| 9710 | */ |
| 9711 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
| Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9712 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9713 | "setRcsClientConfiguration", |
| 9714 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9715 | |
| 9716 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9717 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9718 | } |
| 9719 | if (!isImsAvailableOnDevice()) { |
| 9720 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9721 | "IMS not available on device."); |
| 9722 | } |
| 9723 | |
| 9724 | final long identity = Binder.clearCallingIdentity(); |
| 9725 | |
| 9726 | try { |
| 9727 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9728 | if (configBinder == null) { |
| 9729 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9730 | } else { |
| 9731 | configBinder.setRcsClientConfiguration(rcc); |
| 9732 | } |
| 9733 | } catch (RemoteException e) { |
| 9734 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9735 | } finally { |
| 9736 | Binder.restoreCallingIdentity(identity); |
| 9737 | } |
| 9738 | } |
| 9739 | |
| 9740 | /** |
| Hui Wang | 19a2187 | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 9741 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 9742 | */ |
| 9743 | @Override |
| 9744 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 9745 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9746 | "setRcsSingleRegistrationTestModeEnabled"); |
| 9747 | |
| 9748 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 9749 | } |
| 9750 | |
| 9751 | /** |
| 9752 | * Gets the test mode for RCS VoLTE single registration. |
| 9753 | */ |
| 9754 | @Override |
| 9755 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 9756 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9757 | "getRcsSingleRegistrationTestModeEnabled"); |
| 9758 | |
| 9759 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 9760 | } |
| 9761 | |
| 9762 | /** |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9763 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9764 | */ |
| 9765 | @Override |
| 9766 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9767 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9768 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9769 | enforceModifyPermission(); |
| 9770 | |
| 9771 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9772 | : Boolean.parseBoolean(enabledStr); |
| 9773 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
| Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9774 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9775 | } |
| 9776 | |
| 9777 | /** |
| Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9778 | * Sends a device to device communication message. Only usable via shell. |
| 9779 | * @param message message to send. |
| 9780 | * @param value message value. |
| 9781 | */ |
| 9782 | @Override |
| 9783 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9784 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9785 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9786 | enforceModifyPermission(); |
| 9787 | |
| 9788 | final long identity = Binder.clearCallingIdentity(); |
| 9789 | try { |
| 9790 | TelephonyConnectionService service = |
| 9791 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9792 | if (service == null) { |
| 9793 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9794 | return; |
| 9795 | } |
| 9796 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9797 | } finally { |
| 9798 | Binder.restoreCallingIdentity(identity); |
| 9799 | } |
| 9800 | } |
| 9801 | |
| 9802 | |
| 9803 | /** |
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9804 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9805 | */ |
| 9806 | @Override |
| 9807 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9808 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9809 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9810 | } |
| 9811 | |
| 9812 | /** |
| 9813 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9814 | */ |
| 9815 | @Override |
| 9816 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9817 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9818 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9819 | enforceModifyPermission(); |
| 9820 | |
| 9821 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9822 | : Boolean.parseBoolean(enabledStr); |
| 9823 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9824 | subId, enabled); |
| 9825 | } |
| 9826 | |
| 9827 | /** |
| 9828 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9829 | */ |
| 9830 | @Override |
| 9831 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9832 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9833 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9834 | } |
| Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9835 | |
| 9836 | /** |
| 9837 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9838 | * their mobile plan. |
| 9839 | */ |
| 9840 | @Override |
| 9841 | public String getMobileProvisioningUrl() { |
| 9842 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9843 | final long identity = Binder.clearCallingIdentity(); |
| 9844 | try { |
| 9845 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9846 | } finally { |
| 9847 | Binder.restoreCallingIdentity(identity); |
| 9848 | } |
| 9849 | } |
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9850 | |
| James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9851 | /** |
| calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 9852 | * Get the EAB contact from the EAB database. |
| 9853 | */ |
| 9854 | @Override |
| 9855 | public String getContactFromEab(String contact) { |
| 9856 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 9857 | enforceModifyPermission(); |
| 9858 | final long identity = Binder.clearCallingIdentity(); |
| 9859 | try { |
| 9860 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 9861 | } finally { |
| 9862 | Binder.restoreCallingIdentity(identity); |
| 9863 | } |
| 9864 | } |
| 9865 | |
| 9866 | /** |
| James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9867 | * Remove the EAB contacts from the EAB database. |
| 9868 | */ |
| 9869 | @Override |
| 9870 | public int removeContactFromEab(int subId, String contacts) { |
| 9871 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 9872 | enforceModifyPermission(); |
| 9873 | final long identity = Binder.clearCallingIdentity(); |
| 9874 | try { |
| 9875 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 9876 | } finally { |
| 9877 | Binder.restoreCallingIdentity(identity); |
| 9878 | } |
| 9879 | } |
| 9880 | |
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9881 | @Override |
| James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 9882 | public boolean getDeviceUceEnabled() { |
| 9883 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 9884 | final long identity = Binder.clearCallingIdentity(); |
| 9885 | try { |
| 9886 | return mApp.getDeviceUceEnabled(); |
| 9887 | } finally { |
| 9888 | Binder.restoreCallingIdentity(identity); |
| 9889 | } |
| 9890 | } |
| 9891 | |
| 9892 | @Override |
| 9893 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 9894 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 9895 | final long identity = Binder.clearCallingIdentity(); |
| 9896 | try { |
| 9897 | mApp.setDeviceUceEnabled(isEnabled); |
| 9898 | } finally { |
| 9899 | Binder.restoreCallingIdentity(identity); |
| 9900 | } |
| 9901 | } |
| 9902 | |
| 9903 | @Override |
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9904 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9905 | String callingPackage) { |
| 9906 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9907 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 9908 | |
| 9909 | final int callingUid = Binder.getCallingUid(); |
| 9910 | // Verify that tha callingPackage belongs to the calling UID |
| 9911 | mApp.getSystemService(AppOpsManager.class) |
| 9912 | .checkPackage(callingUid, callingPackage); |
| 9913 | |
| 9914 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 9915 | |
| 9916 | final long identity = Binder.clearCallingIdentity(); |
| 9917 | try { |
| 9918 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9919 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9920 | |
| 9921 | if (result instanceof IllegalStateException) { |
| 9922 | throw (IllegalStateException) result; |
| 9923 | } |
| 9924 | } finally { |
| 9925 | Binder.restoreCallingIdentity(identity); |
| 9926 | } |
| 9927 | } |
| 9928 | |
| 9929 | @Override |
| 9930 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9931 | String callingPackage) { |
| 9932 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9933 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 9934 | |
| 9935 | final int callingUid = Binder.getCallingUid(); |
| 9936 | // Verify that tha callingPackage belongs to the calling UID |
| 9937 | mApp.getSystemService(AppOpsManager.class) |
| 9938 | .checkPackage(callingUid, callingPackage); |
| 9939 | |
| 9940 | final long identity = Binder.clearCallingIdentity(); |
| 9941 | try { |
| 9942 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9943 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9944 | |
| 9945 | if (result instanceof IllegalStateException) { |
| 9946 | throw (IllegalStateException) result; |
| 9947 | } |
| 9948 | } finally { |
| 9949 | Binder.restoreCallingIdentity(identity); |
| 9950 | } |
| 9951 | } |
| 9952 | |
| 9953 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 9954 | int callingUid) { |
| 9955 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 9956 | // phone/system process do not have further restriction on request |
| 9957 | return; |
| 9958 | } |
| 9959 | |
| 9960 | // Applications has restrictions on how to use the request: |
| 9961 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 9962 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 9963 | // This is not system caller which has been checked above |
| 9964 | throw new IllegalArgumentException( |
| 9965 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 9966 | } |
| 9967 | |
| 9968 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 9969 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 9970 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 9971 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 9972 | || info.isEnabled()) { |
| 9973 | throw new IllegalArgumentException( |
| 9974 | "Only system can set hide fields in SignalThresholdInfo"); |
| 9975 | } |
| 9976 | |
| 9977 | // Thresholds length for each RAN need in range. This has been validated in |
| 9978 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 9979 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 9980 | final int[] thresholds = info.getThresholds(); |
| 9981 | Objects.requireNonNull(thresholds); |
| 9982 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 9983 | || thresholds.length |
| 9984 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 9985 | throw new IllegalArgumentException( |
| 9986 | "thresholds length is out of range: " + thresholds.length); |
| 9987 | } |
| 9988 | } |
| 9989 | } |
| Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 9990 | |
| 9991 | /** |
| 9992 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 9993 | * required to be done shortly after the API is invoked. |
| 9994 | */ |
| 9995 | @Override |
| 9996 | @TelephonyManager.PrepareUnattendedRebootResult |
| 9997 | public int prepareForUnattendedReboot() { |
| 9998 | enforceRebootPermission(); |
| 9999 | |
| 10000 | final long identity = Binder.clearCallingIdentity(); |
| 10001 | try { |
| 10002 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10003 | } finally { |
| 10004 | Binder.restoreCallingIdentity(identity); |
| 10005 | } |
| 10006 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10007 | } |