| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2006 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | package com.android.phone; | 
|  | 18 |  | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; | 
|  | 20 |  | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; | 
|  | 23 |  | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; | 
| changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 25 | import android.annotation.NonNull; | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; | 
|  | 32 | import android.content.Intent; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 34 | import android.content.pm.ComponentInfo; | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 35 | import android.content.pm.PackageInfo; | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.Uri; | 
|  | 38 | import android.os.AsyncResult; | 
|  | 39 | import android.os.Binder; | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 40 | import android.os.Build; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; | 
|  | 42 | import android.os.Handler; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.IBinder; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.Looper; | 
|  | 45 | import android.os.Message; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 46 | import android.os.Messenger; | 
| Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 47 | import android.os.ParcelFileDescriptor; | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 48 | import android.os.ParcelUuid; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 49 | import android.os.PersistableBundle; | 
| Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 50 | import android.os.Process; | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 52 | import android.os.ResultReceiver; | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 53 | import android.os.ServiceSpecificException; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.os.UserHandle; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 55 | import android.os.UserManager; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 56 | import android.os.WorkSource; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 57 | import android.preference.PreferenceManager; | 
| Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 58 | import android.provider.DeviceConfig; | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 59 | import android.provider.Settings; | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 60 | import android.provider.Telephony; | 
| Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 61 | import android.sysprop.TelephonyProperties; | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 62 | import android.telecom.PhoneAccount; | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccountHandle; | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 64 | import android.telecom.TelecomManager; | 
| Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 65 | import android.telephony.Annotation.ApnType; | 
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 66 | import android.telephony.Annotation.ThermalMitigationResult; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 67 | import android.telephony.CallForwardingInfo; | 
| Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 68 | import android.telephony.CarrierBandwidth; | 
| Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierConfigManager; | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 70 | import android.telephony.CarrierRestrictionRules; | 
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 71 | import android.telephony.CellIdentity; | 
| Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 72 | import android.telephony.CellIdentityCdma; | 
|  | 73 | import android.telephony.CellIdentityGsm; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfo; | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfoGsm; | 
|  | 76 | import android.telephony.CellInfoWcdma; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 77 | import android.telephony.ClientRequestStats; | 
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 78 | import android.telephony.DataThrottlingRequest; | 
| Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 79 | import android.telephony.IBootstrapAuthenticationCallback; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 80 | import android.telephony.ICellInfoCallback; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 81 | import android.telephony.IccOpenLogicalChannelResponse; | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 82 | import android.telephony.LocationAccessPolicy; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 83 | import android.telephony.ModemActivityInfo; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 84 | import android.telephony.NeighboringCellInfo; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 85 | import android.telephony.NetworkScanRequest; | 
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 86 | import android.telephony.PhoneCapability; | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 87 | import android.telephony.PhoneNumberRange; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 88 | import android.telephony.RadioAccessFamily; | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 89 | import android.telephony.RadioAccessSpecifier; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 90 | import android.telephony.ServiceState; | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 91 | import android.telephony.SignalStrength; | 
| Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 92 | import android.telephony.SubscriptionInfo; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 93 | import android.telephony.SubscriptionManager; | 
| Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyFrameworkInitializer; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 95 | import android.telephony.TelephonyHistogram; | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 96 | import android.telephony.TelephonyManager; | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 97 | import android.telephony.TelephonyScanManager; | 
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 98 | import android.telephony.ThermalMitigationRequest; | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 99 | import android.telephony.UiccCardInfo; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 100 | import android.telephony.UiccSlotInfo; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 101 | import android.telephony.UssdResponse; | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 102 | import android.telephony.VisualVoicemailSmsFilterSettings; | 
| Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 103 | import android.telephony.data.ApnSetting; | 
|  | 104 | import android.telephony.emergency.EmergencyNumber; | 
| Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 105 | import android.telephony.gba.GbaAuthRequest; | 
|  | 106 | import android.telephony.gba.UaSecurityProtocolIdentifier; | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 107 | import android.telephony.ims.ImsException; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 108 | import android.telephony.ims.ProvisioningManager; | 
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 109 | import android.telephony.ims.RcsClientConfiguration; | 
| Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 110 | import android.telephony.ims.RegistrationManager; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 111 | import android.telephony.ims.aidl.IImsCapabilityCallback; | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 112 | import android.telephony.ims.aidl.IImsConfig; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 113 | import android.telephony.ims.aidl.IImsConfigCallback; | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 114 | import android.telephony.ims.aidl.IImsRegistration; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsRegistrationCallback; | 
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IRcsConfigCallback; | 
| Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 117 | import android.telephony.ims.feature.ImsFeature; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 118 | import android.telephony.ims.feature.MmTelFeature; | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 119 | import android.telephony.ims.feature.RcsFeature; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 120 | import android.telephony.ims.stub.ImsConfigImplBase; | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 121 | import android.telephony.ims.stub.ImsRegistrationImplBase; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 122 | import android.text.TextUtils; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 123 | import android.util.ArraySet; | 
| Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 124 | import android.util.EventLog; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | import android.util.Log; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 126 | import android.util.Pair; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 127 |  | 
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 128 | import com.android.ims.ImsManager; | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 129 | import com.android.ims.internal.IImsServiceFeatureCallback; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.CallForwardInfo; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.CallManager; | 
| Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.CallStateException; | 
| pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.CarrierInfoManager; | 
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.CarrierResolver; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.CellNetworkScanResult; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.CommandException; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.CommandsInterface; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.DefaultPhoneNotifier; | 
| Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.GbaManager; | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.HalVersion; | 
| Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.IBooleanConsumer; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.ICallForwardingInfoCallback; | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.IIntegerConsumer; | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.INumberVerificationCallback; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.ITelephony; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.IccCard; | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.LocaleTracker; | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.NetworkScanRequestTracker; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.OperatorInfo; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.Phone; | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.PhoneConfigurationManager; | 
| Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.PhoneConstantConversions; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.PhoneConstants; | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.PhoneFactory; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.ProxyController; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.RIL; | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.RILConstants; | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.ServiceStateTracker; | 
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.SmsController; | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.SmsPermissions; | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.SubscriptionController; | 
| Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 162 | import com.android.internal.telephony.TelephonyIntents; | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.TelephonyPermissions; | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.euicc.EuiccConnector; | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.ims.ImsResolver; | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.imsphone.ImsPhone; | 
|  | 169 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; | 
| Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.metrics.TelephonyMetrics; | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.uicc.IccIoResult; | 
| changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 173 | import com.android.internal.telephony.uicc.IccRecords; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.uicc.IccUtils; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.SIMRecords; | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.UiccCard; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.UiccCardApplication; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.UiccController; | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.UiccProfile; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccSlot; | 
| zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 181 | import com.android.internal.telephony.util.LocaleUtils; | 
| fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 183 | import com.android.internal.util.FunctionalUtils; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 184 | import com.android.internal.util.HexDump; | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 185 | import com.android.phone.settings.PickSmsSubscriptionActivity; | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 186 | import com.android.phone.vvm.PhoneAccountHandleConverter; | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 187 | import com.android.phone.vvm.RemoteVvmTaskManager; | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 188 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; | 
| Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 189 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; | 
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 190 | import com.android.services.telephony.TelecomAccountRegistry; | 
|  | 191 | import com.android.services.telephony.TelephonyConnectionService; | 
| Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 192 | import com.android.telephony.Rlog; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 193 |  | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 194 | import java.io.FileDescriptor; | 
|  | 195 | import java.io.PrintWriter; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | import java.util.ArrayList; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 197 | import java.util.Arrays; | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 198 | import java.util.HashMap; | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 199 | import java.util.HashSet; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 200 | import java.util.List; | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 201 | import java.util.Locale; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 202 | import java.util.Map; | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 203 | import java.util.NoSuchElementException; | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 204 | import java.util.Set; | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 205 | import java.util.concurrent.atomic.AtomicBoolean; | 
| Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 206 | import java.util.function.Consumer; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 207 |  | 
|  | 208 | /** | 
|  | 209 | * Implementation of the ITelephony interface. | 
|  | 210 | */ | 
| Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 211 | public class PhoneInterfaceManager extends ITelephony.Stub { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 212 | private static final String LOG_TAG = "PhoneInterfaceManager"; | 
|  | 213 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); | 
|  | 214 | private static final boolean DBG_LOC = false; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 215 | private static final boolean DBG_MERGE = false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 216 |  | 
|  | 217 | // Message codes used with mMainThreadHandler | 
|  | 218 | private static final int CMD_HANDLE_PIN_MMI = 1; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 219 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; | 
|  | 220 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 221 | private static final int CMD_OPEN_CHANNEL = 9; | 
|  | 222 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; | 
|  | 223 | private static final int CMD_CLOSE_CHANNEL = 11; | 
|  | 224 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 225 | private static final int CMD_NV_READ_ITEM = 13; | 
|  | 226 | private static final int EVENT_NV_READ_ITEM_DONE = 14; | 
|  | 227 | private static final int CMD_NV_WRITE_ITEM = 15; | 
|  | 228 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; | 
|  | 229 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; | 
|  | 230 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 231 | private static final int CMD_RESET_MODEM_CONFIG = 19; | 
|  | 232 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 233 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; | 
|  | 234 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; | 
|  | 235 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; | 
|  | 236 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; | 
| Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 237 | private static final int CMD_SEND_ENVELOPE = 25; | 
|  | 238 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 239 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; | 
|  | 240 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; | 
| Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 241 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; | 
|  | 242 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; | 
|  | 243 | private static final int CMD_EXCHANGE_SIM_IO = 31; | 
|  | 244 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 245 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; | 
|  | 246 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 247 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; | 
|  | 248 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 249 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; | 
|  | 250 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 251 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; | 
|  | 252 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; | 
|  | 253 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; | 
|  | 254 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 255 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; | 
|  | 256 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; | 
|  | 257 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; | 
|  | 258 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 259 | private static final int CMD_HANDLE_USSD_REQUEST = 47; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 260 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; | 
|  | 261 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 262 | private static final int CMD_SWITCH_SLOTS = 50; | 
|  | 263 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 264 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; | 
|  | 265 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; | 
|  | 266 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; | 
|  | 267 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; | 
|  | 268 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; | 
|  | 269 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; | 
|  | 270 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; | 
|  | 271 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 272 | private static final int CMD_GET_ALL_CELL_INFO = 60; | 
|  | 273 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; | 
|  | 274 | private static final int CMD_GET_CELL_LOCATION = 62; | 
|  | 275 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 276 | private static final int CMD_MODEM_REBOOT = 64; | 
|  | 277 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 278 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; | 
|  | 279 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 280 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; | 
|  | 281 | private static final int EVENT_ENABLE_MODEM_DONE = 69; | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 282 | private static final int CMD_GET_MODEM_STATUS = 70; | 
|  | 283 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; | 
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 284 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; | 
|  | 285 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; | 
| Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 286 | private static final int CMD_ERASE_MODEM_CONFIG = 74; | 
|  | 287 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; | 
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 288 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; | 
|  | 289 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; | 
|  | 290 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; | 
|  | 291 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; | 
| Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 292 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; | 
|  | 293 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 294 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 295 | private static final int CMD_GET_CALL_FORWARDING = 83; | 
|  | 296 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; | 
|  | 297 | private static final int CMD_SET_CALL_FORWARDING = 85; | 
|  | 298 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; | 
|  | 299 | private static final int CMD_GET_CALL_WAITING = 87; | 
|  | 300 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; | 
|  | 301 | private static final int CMD_SET_CALL_WAITING = 89; | 
|  | 302 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; | 
| Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 303 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; | 
|  | 304 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; | 
|  | 305 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; | 
|  | 306 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; | 
| Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 307 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; | 
|  | 308 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; | 
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 309 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; | 
|  | 310 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; | 
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 311 | private static final int CMD_SET_DATA_THROTTLING = 99; | 
|  | 312 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; | 
| Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 313 | private static final int CMD_SET_SIM_POWER = 101; | 
|  | 314 | private static final int EVENT_SET_SIM_POWER_DONE = 102; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 315 |  | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 316 | // Parameters of select command. | 
|  | 317 | private static final int SELECT_COMMAND = 0xA4; | 
|  | 318 | private static final int SELECT_P1 = 0x04; | 
|  | 319 | private static final int SELECT_P2 = 0; | 
|  | 320 | private static final int SELECT_P3 = 0x10; | 
|  | 321 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 322 | /** The singleton instance. */ | 
|  | 323 | private static PhoneInterfaceManager sInstance; | 
|  | 324 |  | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 325 | private PhoneGlobals mApp; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 326 | private CallManager mCM; | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 327 | private ImsResolver mImsResolver; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 328 | private UserManager mUserManager; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 329 | private AppOpsManager mAppOps; | 
|  | 330 | private MainThreadHandler mMainThreadHandler; | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 331 | private SubscriptionController mSubscriptionController; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 332 | private SharedPreferences mTelephonySharedPreferences; | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 333 | private PhoneConfigurationManager mPhoneConfigurationManager; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 334 |  | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 335 | /** User Activity */ | 
|  | 336 | private AtomicBoolean mNotifyUserActivity; | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 337 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; | 
|  | 338 |  | 
| Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 339 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); | 
|  | 340 |  | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 341 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; | 
|  | 342 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 343 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 344 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 345 |  | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 346 | // String to store multi SIM allowed | 
|  | 347 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; | 
|  | 348 |  | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 349 | // The AID of ISD-R. | 
|  | 350 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; | 
|  | 351 |  | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 352 | private NetworkScanRequestTracker mNetworkScanRequestTracker; | 
|  | 353 |  | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 354 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; | 
|  | 355 | private static final int MANUFACTURER_CODE_LENGTH = 8; | 
|  | 356 |  | 
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 357 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; | 
|  | 358 |  | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 359 | /** | 
| Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 360 | * Experiment flag to enable erase modem config on reset network, default value is false | 
|  | 361 | */ | 
|  | 362 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = | 
|  | 363 | "reset_network_erase_modem_config_enabled"; | 
|  | 364 |  | 
|  | 365 | /** | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 366 | * A request object to use for transmitting data to an ICC. | 
|  | 367 | */ | 
|  | 368 | private static final class IccAPDUArgument { | 
|  | 369 | public int channel, cla, command, p1, p2, p3; | 
|  | 370 | public String data; | 
|  | 371 |  | 
|  | 372 | public IccAPDUArgument(int channel, int cla, int command, | 
|  | 373 | int p1, int p2, int p3, String data) { | 
|  | 374 | this.channel = channel; | 
|  | 375 | this.cla = cla; | 
|  | 376 | this.command = command; | 
|  | 377 | this.p1 = p1; | 
|  | 378 | this.p2 = p2; | 
|  | 379 | this.p3 = p3; | 
|  | 380 | this.data = data; | 
|  | 381 | } | 
|  | 382 | } | 
|  | 383 |  | 
|  | 384 | /** | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 385 | * A request object to use for transmitting data to an ICC. | 
|  | 386 | */ | 
|  | 387 | private static final class ManualNetworkSelectionArgument { | 
|  | 388 | public OperatorInfo operatorInfo; | 
|  | 389 | public boolean persistSelection; | 
|  | 390 |  | 
|  | 391 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { | 
|  | 392 | this.operatorInfo = operatorInfo; | 
|  | 393 | this.persistSelection = persistSelection; | 
|  | 394 | } | 
|  | 395 | } | 
|  | 396 |  | 
|  | 397 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 398 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the | 
|  | 399 | * request after sending. The main thread will notify the request when it is complete. | 
|  | 400 | */ | 
|  | 401 | private static final class MainThreadRequest { | 
|  | 402 | /** The argument to use for the request */ | 
|  | 403 | public Object argument; | 
|  | 404 | /** The result of the request that is run on the main thread */ | 
|  | 405 | public Object result; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 406 | // The subscriber id that this request applies to. Defaults to | 
|  | 407 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID | 
|  | 408 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 409 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 410 | // In cases where subId is unavailable, the caller needs to specify the phone. | 
|  | 411 | public Phone phone; | 
|  | 412 |  | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 413 | public WorkSource workSource; | 
|  | 414 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 415 | public MainThreadRequest(Object argument) { | 
|  | 416 | this.argument = argument; | 
|  | 417 | } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 418 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 419 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { | 
|  | 420 | this.argument = argument; | 
|  | 421 | if (phone != null) { | 
|  | 422 | this.phone = phone; | 
|  | 423 | } | 
|  | 424 | this.workSource = workSource; | 
|  | 425 | } | 
|  | 426 |  | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 427 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 428 | this.argument = argument; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 429 | if (subId != null) { | 
|  | 430 | this.subId = subId; | 
|  | 431 | } | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 432 | this.workSource = workSource; | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 433 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 434 | } | 
|  | 435 |  | 
| Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 436 | private static final class IncomingThirdPartyCallArgs { | 
|  | 437 | public final ComponentName component; | 
|  | 438 | public final String callId; | 
|  | 439 | public final String callerDisplayName; | 
|  | 440 |  | 
|  | 441 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, | 
|  | 442 | String callerDisplayName) { | 
|  | 443 | this.component = component; | 
|  | 444 | this.callId = callId; | 
|  | 445 | this.callerDisplayName = callerDisplayName; | 
|  | 446 | } | 
|  | 447 | } | 
|  | 448 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 449 | /** | 
|  | 450 | * A handler that processes messages on the main thread in the phone process. Since many | 
|  | 451 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the | 
|  | 452 | * inbound binder threads to the main thread in the phone process.  The Binder thread | 
|  | 453 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting | 
|  | 454 | * on, which will be notified when the operation completes and will contain the result of the | 
|  | 455 | * request. | 
|  | 456 | * | 
|  | 457 | * <p>If a MainThreadRequest object is provided in the msg.obj field, | 
|  | 458 | * note that request.result must be set to something non-null for the calling thread to | 
|  | 459 | * unblock. | 
|  | 460 | */ | 
|  | 461 | private final class MainThreadHandler extends Handler { | 
|  | 462 | @Override | 
|  | 463 | public void handleMessage(Message msg) { | 
|  | 464 | MainThreadRequest request; | 
|  | 465 | Message onCompleted; | 
|  | 466 | AsyncResult ar; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 467 | UiccCard uiccCard; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 468 | IccAPDUArgument iccArgument; | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 469 | final Phone defaultPhone = getDefaultPhone(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 470 |  | 
|  | 471 | switch (msg.what) { | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 472 | case CMD_HANDLE_USSD_REQUEST: { | 
|  | 473 | request = (MainThreadRequest) msg.obj; | 
|  | 474 | final Phone phone = getPhoneFromRequest(request); | 
|  | 475 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; | 
|  | 476 | String ussdRequest =  ussdObject.first; | 
|  | 477 | ResultReceiver wrappedCallback = ussdObject.second; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 478 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 479 | if (!isUssdApiAllowed(request.subId)) { | 
|  | 480 | // Carrier does not support use of this API, return failure. | 
|  | 481 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); | 
|  | 482 | UssdResponse response = new UssdResponse(ussdRequest, null); | 
|  | 483 | Bundle returnData = new Bundle(); | 
|  | 484 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); | 
|  | 485 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 486 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 487 | request.result = true; | 
|  | 488 | notifyRequester(request); | 
|  | 489 | return; | 
|  | 490 | } | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 491 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 492 | try { | 
|  | 493 | request.result = phone != null | 
|  | 494 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; | 
|  | 495 | } catch (CallStateException cse) { | 
|  | 496 | request.result = false; | 
|  | 497 | } | 
|  | 498 | // Wake up the requesting thread | 
|  | 499 | notifyRequester(request); | 
|  | 500 | break; | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 501 | } | 
|  | 502 |  | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 503 | case CMD_HANDLE_PIN_MMI: { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 504 | request = (MainThreadRequest) msg.obj; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 505 | final Phone phone = getPhoneFromRequest(request); | 
|  | 506 | request.result = phone != null ? | 
|  | 507 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) | 
|  | 508 | : false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 509 | // Wake up the requesting thread | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 510 | notifyRequester(request); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 511 | break; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 512 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 513 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 514 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 515 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 516 | iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 517 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 518 | if (uiccCard == null) { | 
|  | 519 | loge("iccTransmitApduLogicalChannel: No UICC"); | 
|  | 520 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 521 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 522 | } else { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 523 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, | 
|  | 524 | request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 525 | uiccCard.iccTransmitApduLogicalChannel( | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 526 | iccArgument.channel, iccArgument.cla, iccArgument.command, | 
|  | 527 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 528 | onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 529 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 530 | break; | 
|  | 531 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 533 | ar = (AsyncResult) msg.obj; | 
|  | 534 | request = (MainThreadRequest) ar.userObj; | 
|  | 535 | if (ar.exception == null && ar.result != null) { | 
|  | 536 | request.result = ar.result; | 
|  | 537 | } else { | 
|  | 538 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
|  | 539 | if (ar.result == null) { | 
|  | 540 | loge("iccTransmitApduLogicalChannel: Empty response"); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 541 | } else if (ar.exception instanceof CommandException) { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 542 | loge("iccTransmitApduLogicalChannel: CommandException: " + | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 543 | ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 544 | } else { | 
|  | 545 | loge("iccTransmitApduLogicalChannel: Unknown exception"); | 
|  | 546 | } | 
|  | 547 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 548 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 549 | break; | 
|  | 550 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 551 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: | 
|  | 552 | request = (MainThreadRequest) msg.obj; | 
|  | 553 | iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 554 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 555 | if (uiccCard == null) { | 
|  | 556 | loge("iccTransmitApduBasicChannel: No UICC"); | 
|  | 557 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 558 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 559 | } else { | 
|  | 560 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, | 
|  | 561 | request); | 
|  | 562 | uiccCard.iccTransmitApduBasicChannel( | 
|  | 563 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, | 
|  | 564 | iccArgument.p3, iccArgument.data, onCompleted); | 
|  | 565 | } | 
|  | 566 | break; | 
|  | 567 |  | 
|  | 568 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: | 
|  | 569 | ar = (AsyncResult) msg.obj; | 
|  | 570 | request = (MainThreadRequest) ar.userObj; | 
|  | 571 | if (ar.exception == null && ar.result != null) { | 
|  | 572 | request.result = ar.result; | 
|  | 573 | } else { | 
|  | 574 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
|  | 575 | if (ar.result == null) { | 
|  | 576 | loge("iccTransmitApduBasicChannel: Empty response"); | 
|  | 577 | } else if (ar.exception instanceof CommandException) { | 
|  | 578 | loge("iccTransmitApduBasicChannel: CommandException: " + | 
|  | 579 | ar.exception); | 
|  | 580 | } else { | 
|  | 581 | loge("iccTransmitApduBasicChannel: Unknown exception"); | 
|  | 582 | } | 
|  | 583 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 584 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 585 | break; | 
|  | 586 |  | 
|  | 587 | case CMD_EXCHANGE_SIM_IO: | 
|  | 588 | request = (MainThreadRequest) msg.obj; | 
|  | 589 | iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 590 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 591 | if (uiccCard == null) { | 
|  | 592 | loge("iccExchangeSimIO: No UICC"); | 
|  | 593 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 594 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 595 | } else { | 
|  | 596 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, | 
|  | 597 | request); | 
|  | 598 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ | 
|  | 599 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, | 
|  | 600 | iccArgument.data, onCompleted); | 
|  | 601 | } | 
|  | 602 | break; | 
|  | 603 |  | 
|  | 604 | case EVENT_EXCHANGE_SIM_IO_DONE: | 
|  | 605 | ar = (AsyncResult) msg.obj; | 
|  | 606 | request = (MainThreadRequest) ar.userObj; | 
|  | 607 | if (ar.exception == null && ar.result != null) { | 
|  | 608 | request.result = ar.result; | 
|  | 609 | } else { | 
|  | 610 | request.result = new IccIoResult(0x6f, 0, (byte[])null); | 
|  | 611 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 612 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 613 | break; | 
|  | 614 |  | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 615 | case CMD_SEND_ENVELOPE: | 
|  | 616 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 617 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 618 | if (uiccCard == null) { | 
|  | 619 | loge("sendEnvelopeWithStatus: No UICC"); | 
|  | 620 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 621 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 622 | } else { | 
|  | 623 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); | 
|  | 624 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); | 
|  | 625 | } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 626 | break; | 
|  | 627 |  | 
|  | 628 | case EVENT_SEND_ENVELOPE_DONE: | 
|  | 629 | ar = (AsyncResult) msg.obj; | 
|  | 630 | request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 631 | if (ar.exception == null && ar.result != null) { | 
|  | 632 | request.result = ar.result; | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 633 | } else { | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 634 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
|  | 635 | if (ar.result == null) { | 
|  | 636 | loge("sendEnvelopeWithStatus: Empty response"); | 
|  | 637 | } else if (ar.exception instanceof CommandException) { | 
|  | 638 | loge("sendEnvelopeWithStatus: CommandException: " + | 
|  | 639 | ar.exception); | 
|  | 640 | } else { | 
|  | 641 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); | 
|  | 642 | } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 643 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 644 | notifyRequester(request); | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 645 | break; | 
|  | 646 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | case CMD_OPEN_CHANNEL: | 
|  | 648 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 649 | uiccCard = getUiccCardFromRequest(request); | 
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 650 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 651 | if (uiccCard == null) { | 
|  | 652 | loge("iccOpenLogicalChannel: No UICC"); | 
| Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 653 | request.result = new IccOpenLogicalChannelResponse(-1, | 
|  | 654 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 655 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 656 | } else { | 
|  | 657 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); | 
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 658 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, | 
|  | 659 | openChannelArgs.second, onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 660 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 661 | break; | 
|  | 662 |  | 
|  | 663 | case EVENT_OPEN_CHANNEL_DONE: | 
|  | 664 | ar = (AsyncResult) msg.obj; | 
|  | 665 | request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 666 | IccOpenLogicalChannelResponse openChannelResp; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 667 | if (ar.exception == null && ar.result != null) { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 668 | int[] result = (int[]) ar.result; | 
|  | 669 | int channelId = result[0]; | 
|  | 670 | byte[] selectResponse = null; | 
|  | 671 | if (result.length > 1) { | 
|  | 672 | selectResponse = new byte[result.length - 1]; | 
|  | 673 | for (int i = 1; i < result.length; ++i) { | 
|  | 674 | selectResponse[i - 1] = (byte) result[i]; | 
|  | 675 | } | 
|  | 676 | } | 
|  | 677 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 678 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | } else { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | if (ar.result == null) { | 
|  | 681 | loge("iccOpenLogicalChannel: Empty response"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 683 | if (ar.exception != null) { | 
|  | 684 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); | 
|  | 685 | } | 
|  | 686 |  | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 687 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 688 | if (ar.exception instanceof CommandException) { | 
|  | 689 | CommandException.Error error = | 
|  | 690 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 691 | if (error == CommandException.Error.MISSING_RESOURCE) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 692 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 693 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 694 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 695 | } | 
|  | 696 | } | 
|  | 697 | openChannelResp = new IccOpenLogicalChannelResponse( | 
|  | 698 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 699 | } | 
| Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 700 | request.result = openChannelResp; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 701 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 702 | break; | 
|  | 703 |  | 
|  | 704 | case CMD_CLOSE_CHANNEL: | 
|  | 705 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 706 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 707 | if (uiccCard == null) { | 
|  | 708 | loge("iccCloseLogicalChannel: No UICC"); | 
| Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 709 | request.result = false; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 710 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 711 | } else { | 
|  | 712 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); | 
|  | 713 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); | 
|  | 714 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 715 | break; | 
|  | 716 |  | 
|  | 717 | case EVENT_CLOSE_CHANNEL_DONE: | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 718 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); | 
|  | 719 | break; | 
|  | 720 |  | 
|  | 721 | case CMD_NV_READ_ITEM: | 
|  | 722 | request = (MainThreadRequest) msg.obj; | 
|  | 723 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 724 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, | 
|  | 725 | request.workSource); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 726 | break; | 
|  | 727 |  | 
|  | 728 | case EVENT_NV_READ_ITEM_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 729 | ar = (AsyncResult) msg.obj; | 
|  | 730 | request = (MainThreadRequest) ar.userObj; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 731 | if (ar.exception == null && ar.result != null) { | 
|  | 732 | request.result = ar.result;     // String | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 733 | } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 734 | request.result = ""; | 
|  | 735 | if (ar.result == null) { | 
|  | 736 | loge("nvReadItem: Empty response"); | 
|  | 737 | } else if (ar.exception instanceof CommandException) { | 
|  | 738 | loge("nvReadItem: CommandException: " + | 
|  | 739 | ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 740 | } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 741 | loge("nvReadItem: Unknown exception"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 742 | } | 
|  | 743 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 744 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 745 | break; | 
|  | 746 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 747 | case CMD_NV_WRITE_ITEM: | 
|  | 748 | request = (MainThreadRequest) msg.obj; | 
|  | 749 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); | 
|  | 750 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 751 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 752 | request.workSource); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 753 | break; | 
|  | 754 |  | 
|  | 755 | case EVENT_NV_WRITE_ITEM_DONE: | 
|  | 756 | handleNullReturnEvent(msg, "nvWriteItem"); | 
|  | 757 | break; | 
|  | 758 |  | 
|  | 759 | case CMD_NV_WRITE_CDMA_PRL: | 
|  | 760 | request = (MainThreadRequest) msg.obj; | 
|  | 761 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 762 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 763 | break; | 
|  | 764 |  | 
|  | 765 | case EVENT_NV_WRITE_CDMA_PRL_DONE: | 
|  | 766 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); | 
|  | 767 | break; | 
|  | 768 |  | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 769 | case CMD_RESET_MODEM_CONFIG: | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 770 | request = (MainThreadRequest) msg.obj; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 771 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 772 | defaultPhone.resetModemConfig(onCompleted); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 773 | break; | 
|  | 774 |  | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 775 | case EVENT_RESET_MODEM_CONFIG_DONE: | 
|  | 776 | handleNullReturnEvent(msg, "resetModemConfig"); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 777 | break; | 
|  | 778 |  | 
| Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 779 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { | 
|  | 780 | request = (MainThreadRequest) msg.obj; | 
|  | 781 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, | 
|  | 782 | request); | 
|  | 783 | Phone phone = getPhoneFromRequest(request); | 
|  | 784 | if (phone != null) { | 
|  | 785 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); | 
|  | 786 | } else { | 
|  | 787 | loge("isNRDualConnectivityEnabled: No phone object"); | 
|  | 788 | request.result = false; | 
|  | 789 | notifyRequester(request); | 
|  | 790 | } | 
|  | 791 | break; | 
|  | 792 | } | 
|  | 793 |  | 
|  | 794 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: | 
|  | 795 | ar = (AsyncResult) msg.obj; | 
|  | 796 | request = (MainThreadRequest) ar.userObj; | 
|  | 797 | if (ar.exception == null && ar.result != null) { | 
|  | 798 | request.result = ar.result; | 
|  | 799 | } else { | 
|  | 800 | // request.result must be set to something non-null | 
|  | 801 | // for the calling thread to unblock | 
|  | 802 | if (request.result != null) { | 
|  | 803 | request.result = ar.result; | 
|  | 804 | } else { | 
|  | 805 | request.result = false; | 
|  | 806 | } | 
|  | 807 | if (ar.result == null) { | 
|  | 808 | loge("isNRDualConnectivityEnabled: Empty response"); | 
|  | 809 | } else if (ar.exception instanceof CommandException) { | 
|  | 810 | loge("isNRDualConnectivityEnabled: CommandException: " | 
|  | 811 | + ar.exception); | 
|  | 812 | } else { | 
|  | 813 | loge("isNRDualConnectivityEnabled: Unknown exception"); | 
|  | 814 | } | 
|  | 815 | } | 
|  | 816 | notifyRequester(request); | 
|  | 817 | break; | 
|  | 818 |  | 
|  | 819 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { | 
|  | 820 | request = (MainThreadRequest) msg.obj; | 
|  | 821 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); | 
|  | 822 | Phone phone = getPhoneFromRequest(request); | 
|  | 823 | if (phone != null) { | 
|  | 824 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, | 
|  | 825 | request.workSource); | 
|  | 826 | } else { | 
|  | 827 | loge("enableNrDualConnectivity: No phone object"); | 
|  | 828 | request.result = | 
|  | 829 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; | 
|  | 830 | notifyRequester(request); | 
|  | 831 | } | 
|  | 832 | break; | 
|  | 833 | } | 
|  | 834 |  | 
|  | 835 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { | 
|  | 836 | ar = (AsyncResult) msg.obj; | 
|  | 837 | request = (MainThreadRequest) ar.userObj; | 
|  | 838 | if (ar.exception == null) { | 
|  | 839 | request.result = | 
|  | 840 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; | 
|  | 841 | } else { | 
|  | 842 | request.result = | 
|  | 843 | TelephonyManager | 
|  | 844 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; | 
|  | 845 | if (ar.exception instanceof CommandException) { | 
|  | 846 | CommandException.Error error = | 
|  | 847 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 848 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
|  | 849 | request.result = | 
|  | 850 | TelephonyManager | 
|  | 851 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; | 
|  | 852 | } | 
|  | 853 | loge("enableNrDualConnectivity" + ": CommandException: " | 
|  | 854 | + ar.exception); | 
|  | 855 | } else { | 
|  | 856 | loge("enableNrDualConnectivity" + ": Unknown exception"); | 
|  | 857 | } | 
|  | 858 | } | 
|  | 859 | notifyRequester(request); | 
|  | 860 | break; | 
|  | 861 | } | 
|  | 862 |  | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 863 | case CMD_GET_PREFERRED_NETWORK_TYPE: | 
|  | 864 | request = (MainThreadRequest) msg.obj; | 
|  | 865 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 866 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 867 | break; | 
|  | 868 |  | 
|  | 869 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: | 
|  | 870 | ar = (AsyncResult) msg.obj; | 
|  | 871 | request = (MainThreadRequest) ar.userObj; | 
|  | 872 | if (ar.exception == null && ar.result != null) { | 
|  | 873 | request.result = ar.result;     // Integer | 
|  | 874 | } else { | 
| Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 875 | // request.result must be set to something non-null | 
|  | 876 | // for the calling thread to unblock | 
|  | 877 | request.result = new int[]{-1}; | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 878 | if (ar.result == null) { | 
|  | 879 | loge("getPreferredNetworkType: Empty response"); | 
|  | 880 | } else if (ar.exception instanceof CommandException) { | 
|  | 881 | loge("getPreferredNetworkType: CommandException: " + | 
|  | 882 | ar.exception); | 
|  | 883 | } else { | 
|  | 884 | loge("getPreferredNetworkType: Unknown exception"); | 
|  | 885 | } | 
|  | 886 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 887 | notifyRequester(request); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 888 | break; | 
|  | 889 |  | 
|  | 890 | case CMD_SET_PREFERRED_NETWORK_TYPE: | 
|  | 891 | request = (MainThreadRequest) msg.obj; | 
|  | 892 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); | 
|  | 893 | int networkType = (Integer) request.argument; | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 894 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 895 | break; | 
|  | 896 |  | 
|  | 897 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: | 
|  | 898 | handleNullReturnEvent(msg, "setPreferredNetworkType"); | 
|  | 899 | break; | 
|  | 900 |  | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 901 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: | 
|  | 902 | request = (MainThreadRequest)msg.obj; | 
|  | 903 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 904 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 905 | break; | 
|  | 906 |  | 
|  | 907 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: | 
|  | 908 | ar = (AsyncResult)msg.obj; | 
|  | 909 | request = (MainThreadRequest)ar.userObj; | 
|  | 910 | request.result = ar; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 911 | notifyRequester(request); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 912 | break; | 
|  | 913 |  | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 914 | case CMD_SET_VOICEMAIL_NUMBER: | 
|  | 915 | request = (MainThreadRequest) msg.obj; | 
|  | 916 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); | 
|  | 917 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 918 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, | 
|  | 919 | onCompleted); | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 920 | break; | 
|  | 921 |  | 
|  | 922 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: | 
|  | 923 | handleNullReturnEvent(msg, "setVoicemailNumber"); | 
|  | 924 | break; | 
|  | 925 |  | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 926 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: | 
|  | 927 | request = (MainThreadRequest) msg.obj; | 
|  | 928 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, | 
|  | 929 | request); | 
|  | 930 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); | 
|  | 931 | break; | 
|  | 932 |  | 
|  | 933 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: | 
|  | 934 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); | 
|  | 935 | break; | 
|  | 936 |  | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 937 | case CMD_PERFORM_NETWORK_SCAN: | 
|  | 938 | request = (MainThreadRequest) msg.obj; | 
|  | 939 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); | 
|  | 940 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); | 
|  | 941 | break; | 
|  | 942 |  | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 943 | case CMD_GET_CALL_FORWARDING: { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 944 | request = (MainThreadRequest) msg.obj; | 
|  | 945 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 946 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = | 
|  | 947 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) | 
|  | 948 | request.argument; | 
|  | 949 | int callForwardingReason = args.first; | 
|  | 950 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 951 | break; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 952 | } | 
|  | 953 | case EVENT_GET_CALL_FORWARDING_DONE: { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 954 | ar = (AsyncResult) msg.obj; | 
|  | 955 | request = (MainThreadRequest) ar.userObj; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 956 | TelephonyManager.CallForwardingInfoCallback callback = | 
|  | 957 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) | 
|  | 958 | request.argument).second; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 959 | if (ar.exception == null && ar.result != null) { | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 960 | CallForwardingInfo callForwardingInfo = null; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 961 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; | 
|  | 962 | for (CallForwardInfo callForwardInfo : callForwardInfos) { | 
|  | 963 | // Service Class is a bit mask per 3gpp 27.007. Search for | 
|  | 964 | // any service for voice call. | 
|  | 965 | if ((callForwardInfo.serviceClass | 
|  | 966 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 967 | callForwardingInfo = new CallForwardingInfo(true, | 
|  | 968 | callForwardInfo.reason, | 
|  | 969 | callForwardInfo.number, | 
|  | 970 | callForwardInfo.timeSeconds); | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 971 | break; | 
|  | 972 | } | 
|  | 973 | } | 
|  | 974 | // Didn't find a call forward info for voice call. | 
|  | 975 | if (callForwardingInfo == null) { | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 976 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, | 
|  | 977 | 0 /* reason */, null /* number */, 0 /* timeout */); | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 978 | } | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 979 | callback.onCallForwardingInfoAvailable(callForwardingInfo); | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 980 | } else { | 
|  | 981 | if (ar.result == null) { | 
|  | 982 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); | 
|  | 983 | } | 
|  | 984 | if (ar.exception != null) { | 
|  | 985 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); | 
|  | 986 | } | 
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 987 | int errorCode = TelephonyManager | 
|  | 988 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 989 | if (ar.exception instanceof CommandException) { | 
|  | 990 | CommandException.Error error = | 
|  | 991 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 992 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { | 
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 993 | errorCode = TelephonyManager | 
|  | 994 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 995 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 996 | errorCode = TelephonyManager | 
|  | 997 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 998 | } | 
|  | 999 | } | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1000 | callback.onError(errorCode); | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1001 | } | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1002 | break; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1003 | } | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1004 |  | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1005 | case CMD_SET_CALL_FORWARDING: { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1006 | request = (MainThreadRequest) msg.obj; | 
|  | 1007 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1008 | request = (MainThreadRequest) msg.obj; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1009 | CallForwardingInfo callForwardingInfoToSet = | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1010 | ((Pair<CallForwardingInfo, Consumer<Integer>>) | 
|  | 1011 | request.argument).first; | 
|  | 1012 | request.phone.setCallForwardingOption( | 
|  | 1013 | callForwardingInfoToSet.isEnabled() | 
|  | 1014 | ? CommandsInterface.CF_ACTION_ENABLE | 
|  | 1015 | : CommandsInterface.CF_ACTION_DISABLE, | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1016 | callForwardingInfoToSet.getReason(), | 
|  | 1017 | callForwardingInfoToSet.getNumber(), | 
|  | 1018 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); | 
|  | 1019 | break; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1020 | } | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1021 |  | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1022 | case EVENT_SET_CALL_FORWARDING_DONE: { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1023 | ar = (AsyncResult) msg.obj; | 
|  | 1024 | request = (MainThreadRequest) ar.userObj; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1025 | Consumer<Integer> callback = | 
|  | 1026 | ((Pair<CallForwardingInfo, Consumer<Integer>>) | 
|  | 1027 | request.argument).second; | 
|  | 1028 | if (ar.exception != null) { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1029 | loge("setCallForwarding exception: " + ar.exception); | 
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1030 | int errorCode = TelephonyManager.CallForwardingInfoCallback | 
|  | 1031 | .RESULT_ERROR_UNKNOWN; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1032 | if (ar.exception instanceof CommandException) { | 
|  | 1033 | CommandException.Error error = | 
|  | 1034 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1035 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { | 
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1036 | errorCode = TelephonyManager.CallForwardingInfoCallback | 
|  | 1037 | .RESULT_ERROR_FDN_CHECK_FAILURE; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1038 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1039 | errorCode = TelephonyManager.CallForwardingInfoCallback | 
|  | 1040 | .RESULT_ERROR_NOT_SUPPORTED; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1041 | } | 
|  | 1042 | } | 
|  | 1043 | callback.accept(errorCode); | 
|  | 1044 | } else { | 
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1045 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1046 | } | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1047 | break; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1048 | } | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1049 |  | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1050 | case CMD_GET_CALL_WAITING: { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1051 | request = (MainThreadRequest) msg.obj; | 
|  | 1052 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); | 
|  | 1053 | getPhoneFromRequest(request).getCallWaiting(onCompleted); | 
|  | 1054 | break; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1055 | } | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1056 |  | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1057 | case EVENT_GET_CALL_WAITING_DONE: { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1058 | ar = (AsyncResult) msg.obj; | 
|  | 1059 | request = (MainThreadRequest) ar.userObj; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1060 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1061 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; | 
|  | 1062 | if (ar.exception == null && ar.result != null) { | 
| Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1063 | int[] callForwardResults = (int[]) ar.result; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1064 | // Service Class is a bit mask per 3gpp 27.007. | 
|  | 1065 | // Search for any service for voice call. | 
| Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1066 | if (callForwardResults.length > 1 | 
|  | 1067 | && ((callForwardResults[1] | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1068 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { | 
| Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1069 | callForwardingStatus = callForwardResults[0] == 0 | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1070 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED | 
|  | 1071 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1072 | } else { | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1073 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1074 | } | 
|  | 1075 | } else { | 
|  | 1076 | if (ar.result == null) { | 
|  | 1077 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); | 
|  | 1078 | } | 
|  | 1079 | if (ar.exception != null) { | 
|  | 1080 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); | 
|  | 1081 | } | 
|  | 1082 | if (ar.exception instanceof CommandException) { | 
|  | 1083 | CommandException.Error error = | 
|  | 1084 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1085 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 1086 | callForwardingStatus = | 
|  | 1087 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; | 
|  | 1088 | } | 
|  | 1089 | } | 
|  | 1090 | } | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1091 | callback.accept(callForwardingStatus); | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1092 | break; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1093 | } | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1094 |  | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1095 | case CMD_SET_CALL_WAITING: { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1096 | request = (MainThreadRequest) msg.obj; | 
|  | 1097 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1098 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; | 
|  | 1099 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1100 | break; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1101 | } | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1102 |  | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1103 | case EVENT_SET_CALL_WAITING_DONE: { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1104 | ar = (AsyncResult) msg.obj; | 
|  | 1105 | request = (MainThreadRequest) ar.userObj; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1106 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; | 
|  | 1107 | Consumer<Integer> callback = | 
|  | 1108 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; | 
|  | 1109 | if (ar.exception != null) { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1110 | loge("setCallWaiting exception: " + ar.exception); | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1111 | if (ar.exception instanceof CommandException) { | 
|  | 1112 | CommandException.Error error = | 
|  | 1113 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1114 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 1115 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); | 
|  | 1116 | } else { | 
|  | 1117 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); | 
|  | 1118 | } | 
|  | 1119 | } else { | 
|  | 1120 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); | 
|  | 1121 | } | 
|  | 1122 | } else { | 
|  | 1123 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED | 
|  | 1124 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1125 | } | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1126 | break; | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1127 | } | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1128 |  | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1129 | case EVENT_PERFORM_NETWORK_SCAN_DONE: | 
|  | 1130 | ar = (AsyncResult) msg.obj; | 
|  | 1131 | request = (MainThreadRequest) ar.userObj; | 
|  | 1132 | CellNetworkScanResult cellScanResult; | 
|  | 1133 | if (ar.exception == null && ar.result != null) { | 
|  | 1134 | cellScanResult = new CellNetworkScanResult( | 
|  | 1135 | CellNetworkScanResult.STATUS_SUCCESS, | 
|  | 1136 | (List<OperatorInfo>) ar.result); | 
|  | 1137 | } else { | 
|  | 1138 | if (ar.result == null) { | 
|  | 1139 | loge("getCellNetworkScanResults: Empty response"); | 
|  | 1140 | } | 
|  | 1141 | if (ar.exception != null) { | 
|  | 1142 | loge("getCellNetworkScanResults: Exception: " + ar.exception); | 
|  | 1143 | } | 
|  | 1144 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; | 
|  | 1145 | if (ar.exception instanceof CommandException) { | 
|  | 1146 | CommandException.Error error = | 
|  | 1147 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1148 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
|  | 1149 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; | 
|  | 1150 | } else if (error == CommandException.Error.GENERIC_FAILURE) { | 
|  | 1151 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; | 
|  | 1152 | } | 
|  | 1153 | } | 
|  | 1154 | cellScanResult = new CellNetworkScanResult(errorCode, null); | 
|  | 1155 | } | 
|  | 1156 | request.result = cellScanResult; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1157 | notifyRequester(request); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1158 | break; | 
|  | 1159 |  | 
|  | 1160 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: | 
|  | 1161 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1162 | ManualNetworkSelectionArgument selArg = | 
|  | 1163 | (ManualNetworkSelectionArgument) request.argument; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1164 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, | 
|  | 1165 | request); | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1166 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, | 
|  | 1167 | selArg.persistSelection, onCompleted); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1168 | break; | 
|  | 1169 |  | 
|  | 1170 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: | 
| Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1171 | ar = (AsyncResult) msg.obj; | 
|  | 1172 | request = (MainThreadRequest) ar.userObj; | 
|  | 1173 | if (ar.exception == null) { | 
|  | 1174 | request.result = true; | 
|  | 1175 | } else { | 
|  | 1176 | request.result = false; | 
|  | 1177 | loge("setNetworkSelectionModeManual " + ar.exception); | 
|  | 1178 | } | 
|  | 1179 | notifyRequester(request); | 
|  | 1180 | mApp.onNetworkSelectionChanged(request.subId); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1181 | break; | 
|  | 1182 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1183 | case CMD_GET_MODEM_ACTIVITY_INFO: | 
|  | 1184 | request = (MainThreadRequest) msg.obj; | 
|  | 1185 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); | 
| James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1186 | if (defaultPhone != null) { | 
|  | 1187 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); | 
| sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1188 | } else { | 
|  | 1189 | ResultReceiver result = (ResultReceiver) request.argument; | 
|  | 1190 | Bundle bundle = new Bundle(); | 
|  | 1191 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, | 
|  | 1192 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); | 
|  | 1193 | result.send(0, bundle); | 
| James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1194 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1195 | break; | 
|  | 1196 |  | 
|  | 1197 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: | 
|  | 1198 | ar = (AsyncResult) msg.obj; | 
|  | 1199 | request = (MainThreadRequest) ar.userObj; | 
| sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1200 | ResultReceiver result = (ResultReceiver) request.argument; | 
|  | 1201 |  | 
|  | 1202 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1203 | if (ar.exception == null && ar.result != null) { | 
| sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1204 | // Update the last modem activity info and the result of the request. | 
|  | 1205 | ModemActivityInfo info = (ModemActivityInfo) ar.result; | 
|  | 1206 | if (isModemActivityInfoValid(info)) { | 
|  | 1207 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; | 
|  | 1208 | int[] txTimeMs = info.getTransmitTimeMillis(); | 
|  | 1209 | int[] lastModemTxTimeMs = mLastModemActivityInfo | 
|  | 1210 | .getTransmitTimeMillis(); | 
|  | 1211 | for (int i = 0; i < mergedTxTimeMs.length; i++) { | 
|  | 1212 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; | 
|  | 1213 | } | 
|  | 1214 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); | 
|  | 1215 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() | 
|  | 1216 | + mLastModemActivityInfo.getSleepTimeMillis()); | 
|  | 1217 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() | 
|  | 1218 | + mLastModemActivityInfo.getIdleTimeMillis()); | 
|  | 1219 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); | 
|  | 1220 | mLastModemActivityInfo.setReceiveTimeMillis( | 
|  | 1221 | info.getReceiveTimeMillis() | 
|  | 1222 | + mLastModemActivityInfo.getReceiveTimeMillis()); | 
|  | 1223 | } | 
|  | 1224 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), | 
|  | 1225 | mLastModemActivityInfo.getSleepTimeMillis(), | 
|  | 1226 | mLastModemActivityInfo.getIdleTimeMillis(), | 
|  | 1227 | mLastModemActivityInfo.getTransmitTimeMillis(), | 
|  | 1228 | mLastModemActivityInfo.getReceiveTimeMillis()); | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1229 | } else { | 
|  | 1230 | if (ar.result == null) { | 
|  | 1231 | loge("queryModemActivityInfo: Empty response"); | 
|  | 1232 | } else if (ar.exception instanceof CommandException) { | 
|  | 1233 | loge("queryModemActivityInfo: CommandException: " + | 
|  | 1234 | ar.exception); | 
|  | 1235 | } else { | 
|  | 1236 | loge("queryModemActivityInfo: Unknown exception"); | 
|  | 1237 | } | 
|  | 1238 | } | 
| sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1239 | Bundle bundle = new Bundle(); | 
|  | 1240 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); | 
|  | 1241 | result.send(0, bundle); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1242 | notifyRequester(request); | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1243 | break; | 
|  | 1244 |  | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1245 | case CMD_SET_ALLOWED_CARRIERS: | 
|  | 1246 | request = (MainThreadRequest) msg.obj; | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1247 | CarrierRestrictionRules argument = | 
|  | 1248 | (CarrierRestrictionRules) request.argument; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1249 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1250 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1251 | break; | 
|  | 1252 |  | 
|  | 1253 | case EVENT_SET_ALLOWED_CARRIERS_DONE: | 
|  | 1254 | ar = (AsyncResult) msg.obj; | 
|  | 1255 | request = (MainThreadRequest) ar.userObj; | 
|  | 1256 | if (ar.exception == null && ar.result != null) { | 
|  | 1257 | request.result = ar.result; | 
|  | 1258 | } else { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1259 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; | 
|  | 1260 | if (ar.exception instanceof CommandException) { | 
|  | 1261 | loge("setAllowedCarriers: CommandException: " + ar.exception); | 
|  | 1262 | CommandException.Error error = | 
|  | 1263 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1264 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 1265 | request.result = | 
|  | 1266 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; | 
|  | 1267 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1268 | } else { | 
|  | 1269 | loge("setAllowedCarriers: Unknown exception"); | 
|  | 1270 | } | 
|  | 1271 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1272 | notifyRequester(request); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1273 | break; | 
|  | 1274 |  | 
|  | 1275 | case CMD_GET_ALLOWED_CARRIERS: | 
|  | 1276 | request = (MainThreadRequest) msg.obj; | 
|  | 1277 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1278 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1279 | break; | 
|  | 1280 |  | 
|  | 1281 | case EVENT_GET_ALLOWED_CARRIERS_DONE: | 
|  | 1282 | ar = (AsyncResult) msg.obj; | 
|  | 1283 | request = (MainThreadRequest) ar.userObj; | 
|  | 1284 | if (ar.exception == null && ar.result != null) { | 
|  | 1285 | request.result = ar.result; | 
|  | 1286 | } else { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1287 | request.result = new IllegalStateException( | 
|  | 1288 | "Failed to get carrier restrictions"); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1289 | if (ar.result == null) { | 
|  | 1290 | loge("getAllowedCarriers: Empty response"); | 
|  | 1291 | } else if (ar.exception instanceof CommandException) { | 
|  | 1292 | loge("getAllowedCarriers: CommandException: " + | 
|  | 1293 | ar.exception); | 
|  | 1294 | } else { | 
|  | 1295 | loge("getAllowedCarriers: Unknown exception"); | 
|  | 1296 | } | 
|  | 1297 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1298 | notifyRequester(request); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1299 | break; | 
|  | 1300 |  | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1301 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: | 
|  | 1302 | ar = (AsyncResult) msg.obj; | 
|  | 1303 | request = (MainThreadRequest) ar.userObj; | 
|  | 1304 | if (ar.exception == null && ar.result != null) { | 
|  | 1305 | request.result = ar.result; | 
|  | 1306 | } else { | 
|  | 1307 | request.result = new IllegalArgumentException( | 
|  | 1308 | "Failed to retrieve Forbidden Plmns"); | 
|  | 1309 | if (ar.result == null) { | 
|  | 1310 | loge("getForbiddenPlmns: Empty response"); | 
|  | 1311 | } else { | 
|  | 1312 | loge("getForbiddenPlmns: Unknown exception"); | 
|  | 1313 | } | 
|  | 1314 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1315 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1316 | break; | 
|  | 1317 |  | 
|  | 1318 | case CMD_GET_FORBIDDEN_PLMNS: | 
|  | 1319 | request = (MainThreadRequest) msg.obj; | 
|  | 1320 | uiccCard = getUiccCardFromRequest(request); | 
|  | 1321 | if (uiccCard == null) { | 
|  | 1322 | loge("getForbiddenPlmns() UiccCard is null"); | 
|  | 1323 | request.result = new IllegalArgumentException( | 
|  | 1324 | "getForbiddenPlmns() UiccCard is null"); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1325 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1326 | break; | 
|  | 1327 | } | 
|  | 1328 | Integer appType = (Integer) request.argument; | 
|  | 1329 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); | 
|  | 1330 | if (uiccApp == null) { | 
|  | 1331 | loge("getForbiddenPlmns() no app with specified type -- " | 
|  | 1332 | + appType); | 
|  | 1333 | request.result = new IllegalArgumentException("Failed to get UICC App"); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1334 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1335 | break; | 
|  | 1336 | } else { | 
|  | 1337 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() | 
|  | 1338 | + " specified type -- " + appType); | 
|  | 1339 | } | 
|  | 1340 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); | 
|  | 1341 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( | 
|  | 1342 | onCompleted); | 
|  | 1343 | break; | 
|  | 1344 |  | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1345 | case CMD_SWITCH_SLOTS: | 
|  | 1346 | request = (MainThreadRequest) msg.obj; | 
|  | 1347 | int[] physicalSlots = (int[]) request.argument; | 
|  | 1348 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); | 
|  | 1349 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); | 
|  | 1350 | break; | 
|  | 1351 |  | 
|  | 1352 | case EVENT_SWITCH_SLOTS_DONE: | 
|  | 1353 | ar = (AsyncResult) msg.obj; | 
|  | 1354 | request = (MainThreadRequest) ar.userObj; | 
|  | 1355 | request.result = (ar.exception == null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1356 | notifyRequester(request); | 
|  | 1357 | break; | 
|  | 1358 | case CMD_GET_NETWORK_SELECTION_MODE: | 
|  | 1359 | request = (MainThreadRequest) msg.obj; | 
|  | 1360 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); | 
|  | 1361 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); | 
|  | 1362 | break; | 
|  | 1363 |  | 
|  | 1364 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: | 
|  | 1365 | ar = (AsyncResult) msg.obj; | 
|  | 1366 | request = (MainThreadRequest) ar.userObj; | 
|  | 1367 | if (ar.exception != null) { | 
|  | 1368 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; | 
|  | 1369 | } else { | 
|  | 1370 | int mode = ((int[]) ar.result)[0]; | 
|  | 1371 | if (mode == 0) { | 
|  | 1372 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; | 
|  | 1373 | } else { | 
|  | 1374 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; | 
|  | 1375 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1376 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1377 | notifyRequester(request); | 
|  | 1378 | break; | 
|  | 1379 | case CMD_GET_CDMA_ROAMING_MODE: | 
|  | 1380 | request = (MainThreadRequest) msg.obj; | 
|  | 1381 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); | 
|  | 1382 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); | 
|  | 1383 | break; | 
|  | 1384 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: | 
|  | 1385 | ar = (AsyncResult) msg.obj; | 
|  | 1386 | request = (MainThreadRequest) ar.userObj; | 
|  | 1387 | if (ar.exception != null) { | 
|  | 1388 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; | 
|  | 1389 | } else { | 
|  | 1390 | request.result = ((int[]) ar.result)[0]; | 
|  | 1391 | } | 
|  | 1392 | notifyRequester(request); | 
|  | 1393 | break; | 
|  | 1394 | case CMD_SET_CDMA_ROAMING_MODE: | 
|  | 1395 | request = (MainThreadRequest) msg.obj; | 
|  | 1396 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); | 
|  | 1397 | int mode = (int) request.argument; | 
|  | 1398 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); | 
|  | 1399 | break; | 
|  | 1400 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: | 
|  | 1401 | ar = (AsyncResult) msg.obj; | 
|  | 1402 | request = (MainThreadRequest) ar.userObj; | 
|  | 1403 | request.result = ar.exception == null; | 
|  | 1404 | notifyRequester(request); | 
|  | 1405 | break; | 
| Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1406 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: | 
|  | 1407 | request = (MainThreadRequest) msg.obj; | 
|  | 1408 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); | 
|  | 1409 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); | 
|  | 1410 | break; | 
|  | 1411 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: | 
|  | 1412 | ar = (AsyncResult) msg.obj; | 
|  | 1413 | request = (MainThreadRequest) ar.userObj; | 
|  | 1414 | if (ar.exception != null) { | 
|  | 1415 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; | 
|  | 1416 | } else { | 
|  | 1417 | request.result = ((int[]) ar.result)[0]; | 
|  | 1418 | } | 
|  | 1419 | notifyRequester(request); | 
|  | 1420 | break; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1421 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: | 
|  | 1422 | request = (MainThreadRequest) msg.obj; | 
|  | 1423 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); | 
|  | 1424 | int subscriptionMode = (int) request.argument; | 
| Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1425 | getPhoneFromRequest(request).setCdmaSubscriptionMode( | 
|  | 1426 | subscriptionMode, onCompleted); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1427 | break; | 
|  | 1428 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: | 
|  | 1429 | ar = (AsyncResult) msg.obj; | 
|  | 1430 | request = (MainThreadRequest) ar.userObj; | 
|  | 1431 | request.result = ar.exception == null; | 
|  | 1432 | notifyRequester(request); | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1433 | break; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1434 | case CMD_GET_ALL_CELL_INFO: | 
|  | 1435 | request = (MainThreadRequest) msg.obj; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1436 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1437 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1438 | break; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1439 | case EVENT_GET_ALL_CELL_INFO_DONE: | 
|  | 1440 | ar = (AsyncResult) msg.obj; | 
|  | 1441 | request = (MainThreadRequest) ar.userObj; | 
| Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1442 | // If a timeout occurs, the response will be null | 
|  | 1443 | request.result = (ar.exception == null && ar.result != null) | 
|  | 1444 | ? ar.result : new ArrayList<CellInfo>(); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1445 | synchronized (request) { | 
|  | 1446 | request.notifyAll(); | 
|  | 1447 | } | 
|  | 1448 | break; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1449 | case CMD_REQUEST_CELL_INFO_UPDATE: | 
|  | 1450 | request = (MainThreadRequest) msg.obj; | 
|  | 1451 | request.phone.requestCellInfoUpdate(request.workSource, | 
|  | 1452 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); | 
|  | 1453 | break; | 
|  | 1454 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: | 
|  | 1455 | ar = (AsyncResult) msg.obj; | 
|  | 1456 | request = (MainThreadRequest) ar.userObj; | 
|  | 1457 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; | 
|  | 1458 | try { | 
|  | 1459 | if (ar.exception != null) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1460 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); | 
| Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1461 | cb.onError( | 
|  | 1462 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, | 
|  | 1463 | ar.exception.getClass().getName(), | 
|  | 1464 | ar.exception.toString()); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1465 | } else if (ar.result == null) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1466 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); | 
| Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1467 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1468 | } else { | 
|  | 1469 | // use the result as returned | 
|  | 1470 | cb.onCellInfo((List<CellInfo>) ar.result); | 
|  | 1471 | } | 
|  | 1472 | } catch (RemoteException re) { | 
|  | 1473 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); | 
|  | 1474 | } | 
|  | 1475 | break; | 
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1476 | case CMD_GET_CELL_LOCATION: { | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1477 | request = (MainThreadRequest) msg.obj; | 
|  | 1478 | WorkSource ws = (WorkSource) request.argument; | 
|  | 1479 | Phone phone = getPhoneFromRequest(request); | 
| Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1480 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1481 | break; | 
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1482 | } | 
|  | 1483 | case EVENT_GET_CELL_LOCATION_DONE: { | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1484 | ar = (AsyncResult) msg.obj; | 
|  | 1485 | request = (MainThreadRequest) ar.userObj; | 
|  | 1486 | if (ar.exception == null) { | 
|  | 1487 | request.result = ar.result; | 
|  | 1488 | } else { | 
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1489 | Phone phone = getPhoneFromRequest(request); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1490 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) | 
| Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1491 | ? new CellIdentityCdma() : new CellIdentityGsm(); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1492 | } | 
|  | 1493 |  | 
|  | 1494 | synchronized (request) { | 
|  | 1495 | request.notifyAll(); | 
|  | 1496 | } | 
|  | 1497 | break; | 
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1498 | } | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1499 | case CMD_MODEM_REBOOT: | 
|  | 1500 | request = (MainThreadRequest) msg.obj; | 
|  | 1501 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1502 | defaultPhone.rebootModem(onCompleted); | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1503 | break; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1504 | case EVENT_CMD_MODEM_REBOOT_DONE: | 
|  | 1505 | handleNullReturnEvent(msg, "rebootModem"); | 
|  | 1506 | break; | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1507 | case CMD_REQUEST_ENABLE_MODEM: | 
|  | 1508 | request = (MainThreadRequest) msg.obj; | 
|  | 1509 | boolean enable = (boolean) request.argument; | 
|  | 1510 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); | 
| Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1511 | onCompleted.arg1 = enable ? 1 : 0; | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1512 | PhoneConfigurationManager.getInstance() | 
|  | 1513 | .enablePhone(request.phone, enable, onCompleted); | 
|  | 1514 | break; | 
|  | 1515 | case EVENT_ENABLE_MODEM_DONE: | 
|  | 1516 | ar = (AsyncResult) msg.obj; | 
|  | 1517 | request = (MainThreadRequest) ar.userObj; | 
|  | 1518 | request.result = (ar.exception == null); | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1519 | int phoneId = request.phone.getPhoneId(); | 
| Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1520 | //update the cache as modem status has changed | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1521 | if ((boolean) request.result) { | 
|  | 1522 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); | 
|  | 1523 | updateModemStateMetrics(); | 
|  | 1524 | } else { | 
|  | 1525 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." | 
|  | 1526 | + ar.exception); | 
|  | 1527 | } | 
|  | 1528 | notifyRequester(request); | 
|  | 1529 | break; | 
|  | 1530 | case CMD_GET_MODEM_STATUS: | 
|  | 1531 | request = (MainThreadRequest) msg.obj; | 
|  | 1532 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); | 
|  | 1533 | PhoneConfigurationManager.getInstance() | 
|  | 1534 | .getPhoneStatusFromModem(request.phone, onCompleted); | 
|  | 1535 | break; | 
|  | 1536 | case EVENT_GET_MODEM_STATUS_DONE: | 
|  | 1537 | ar = (AsyncResult) msg.obj; | 
|  | 1538 | request = (MainThreadRequest) ar.userObj; | 
|  | 1539 | int id = request.phone.getPhoneId(); | 
|  | 1540 | if (ar.exception == null && ar.result != null) { | 
|  | 1541 | request.result = ar.result; | 
|  | 1542 | //update the cache as modem status has changed | 
|  | 1543 | mPhoneConfigurationManager.addToPhoneStatusCache(id, | 
|  | 1544 | (boolean) request.result); | 
|  | 1545 | } else { | 
|  | 1546 | // Return true if modem status cannot be retrieved. For most cases, | 
|  | 1547 | // modem status is on. And for older version modems, GET_MODEM_STATUS | 
|  | 1548 | // and disable modem are not supported. Modem is always on. | 
|  | 1549 | // TODO: this should be fixed in R to support a third | 
|  | 1550 | // status UNKNOWN b/131631629 | 
|  | 1551 | request.result = true; | 
|  | 1552 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." | 
|  | 1553 | + ar.exception); | 
|  | 1554 | } | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1555 | notifyRequester(request); | 
|  | 1556 | break; | 
| Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1557 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { | 
|  | 1558 | request = (MainThreadRequest) msg.obj; | 
|  | 1559 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); | 
|  | 1560 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = | 
|  | 1561 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; | 
|  | 1562 | request.phone.setSystemSelectionChannels(args.first, onCompleted); | 
|  | 1563 | break; | 
|  | 1564 | } | 
|  | 1565 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { | 
|  | 1566 | ar = (AsyncResult) msg.obj; | 
|  | 1567 | request = (MainThreadRequest) ar.userObj; | 
|  | 1568 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = | 
|  | 1569 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; | 
|  | 1570 | args.second.accept(ar.exception == null); | 
|  | 1571 | notifyRequester(request); | 
|  | 1572 | break; | 
|  | 1573 | } | 
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1574 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { | 
|  | 1575 | request = (MainThreadRequest) msg.obj; | 
|  | 1576 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); | 
|  | 1577 | Phone phone = getPhoneFromRequest(request); | 
|  | 1578 | if (phone != null) { | 
|  | 1579 | phone.getSystemSelectionChannels(onCompleted); | 
|  | 1580 | } else { | 
|  | 1581 | loge("getSystemSelectionChannels: No phone object"); | 
|  | 1582 | request.result = new ArrayList<RadioAccessSpecifier>(); | 
|  | 1583 | notifyRequester(request); | 
|  | 1584 | } | 
|  | 1585 | break; | 
|  | 1586 | } | 
|  | 1587 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: | 
|  | 1588 | ar = (AsyncResult) msg.obj; | 
|  | 1589 | request = (MainThreadRequest) ar.userObj; | 
|  | 1590 | if (ar.exception == null && ar.result != null) { | 
|  | 1591 | request.result = ar.result; | 
|  | 1592 | } else { | 
|  | 1593 | request.result = new IllegalArgumentException( | 
|  | 1594 | "Failed to retrieve system selection channels"); | 
|  | 1595 | if (ar.result == null) { | 
|  | 1596 | loge("getSystemSelectionChannels: Empty response"); | 
|  | 1597 | } else { | 
|  | 1598 | loge("getSystemSelectionChannels: Unknown exception"); | 
|  | 1599 | } | 
|  | 1600 | } | 
|  | 1601 | notifyRequester(request); | 
|  | 1602 | break; | 
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1603 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: | 
|  | 1604 | ar = (AsyncResult) msg.obj; | 
|  | 1605 | request = (MainThreadRequest) ar.userObj; | 
|  | 1606 | if (ar.exception == null && ar.result != null) { | 
|  | 1607 | request.result = ar.result; | 
|  | 1608 | } else { | 
|  | 1609 | request.result = -1; | 
|  | 1610 | loge("Failed to set Forbidden Plmns"); | 
|  | 1611 | if (ar.result == null) { | 
|  | 1612 | loge("setForbidenPlmns: Empty response"); | 
|  | 1613 | } else if (ar.exception != null) { | 
|  | 1614 | loge("setForbiddenPlmns: Exception: " + ar.exception); | 
|  | 1615 | request.result = -1; | 
|  | 1616 | } else { | 
|  | 1617 | loge("setForbiddenPlmns: Unknown exception"); | 
|  | 1618 | } | 
|  | 1619 | } | 
|  | 1620 | notifyRequester(request); | 
|  | 1621 | break; | 
|  | 1622 | case CMD_SET_FORBIDDEN_PLMNS: | 
|  | 1623 | request = (MainThreadRequest) msg.obj; | 
|  | 1624 | uiccCard = getUiccCardFromRequest(request); | 
|  | 1625 | if (uiccCard == null) { | 
|  | 1626 | loge("setForbiddenPlmns: UiccCard is null"); | 
|  | 1627 | request.result = -1; | 
|  | 1628 | notifyRequester(request); | 
|  | 1629 | break; | 
|  | 1630 | } | 
|  | 1631 | Pair<Integer, List<String>> setFplmnsArgs = | 
|  | 1632 | (Pair<Integer, List<String>>) request.argument; | 
|  | 1633 | appType = setFplmnsArgs.first; | 
|  | 1634 | List<String> fplmns = setFplmnsArgs.second; | 
|  | 1635 | uiccApp = uiccCard.getApplicationByType(appType); | 
|  | 1636 | if (uiccApp == null) { | 
|  | 1637 | loge("setForbiddenPlmns: no app with specified type -- " + appType); | 
|  | 1638 | request.result = -1; | 
|  | 1639 | loge("Failed to get UICC App"); | 
|  | 1640 | notifyRequester(request); | 
|  | 1641 | } else { | 
|  | 1642 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); | 
|  | 1643 | ((SIMRecords) uiccApp.getIccRecords()) | 
|  | 1644 | .setForbiddenPlmns(onCompleted, fplmns); | 
|  | 1645 | } | 
| yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1646 | break; | 
| Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1647 | case CMD_ERASE_MODEM_CONFIG: | 
|  | 1648 | request = (MainThreadRequest) msg.obj; | 
|  | 1649 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); | 
|  | 1650 | defaultPhone.eraseModemConfig(onCompleted); | 
|  | 1651 | break; | 
|  | 1652 | case EVENT_ERASE_MODEM_CONFIG_DONE: | 
|  | 1653 | handleNullReturnEvent(msg, "eraseModemConfig"); | 
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1654 | break; | 
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1655 |  | 
|  | 1656 | case CMD_CHANGE_ICC_LOCK_PASSWORD: | 
|  | 1657 | request = (MainThreadRequest) msg.obj; | 
|  | 1658 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); | 
|  | 1659 | Pair<String, String> changed = (Pair<String, String>) request.argument; | 
|  | 1660 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( | 
|  | 1661 | changed.first, changed.second, onCompleted); | 
|  | 1662 | break; | 
|  | 1663 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: | 
|  | 1664 | ar = (AsyncResult) msg.obj; | 
|  | 1665 | request = (MainThreadRequest) ar.userObj; | 
|  | 1666 | if (ar.exception == null) { | 
|  | 1667 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; | 
|  | 1668 | } else { | 
|  | 1669 | request.result = msg.arg1; | 
|  | 1670 | } | 
|  | 1671 | notifyRequester(request); | 
|  | 1672 | break; | 
|  | 1673 |  | 
|  | 1674 | case CMD_SET_ICC_LOCK_ENABLED: | 
|  | 1675 | request = (MainThreadRequest) msg.obj; | 
|  | 1676 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); | 
|  | 1677 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; | 
|  | 1678 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( | 
|  | 1679 | enabled.first, enabled.second, onCompleted); | 
|  | 1680 | break; | 
|  | 1681 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: | 
|  | 1682 | ar = (AsyncResult) msg.obj; | 
|  | 1683 | request = (MainThreadRequest) ar.userObj; | 
|  | 1684 | if (ar.exception == null) { | 
|  | 1685 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; | 
|  | 1686 | } else { | 
|  | 1687 | request.result = msg.arg1; | 
|  | 1688 | } | 
|  | 1689 | notifyRequester(request); | 
|  | 1690 | break; | 
|  | 1691 |  | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1692 | case MSG_NOTIFY_USER_ACTIVITY: | 
|  | 1693 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); | 
| Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1694 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1695 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); | 
|  | 1696 | getDefaultPhone().getContext().sendBroadcastAsUser( | 
|  | 1697 | intent, UserHandle.ALL, permission.USER_ACTIVITY); | 
|  | 1698 | break; | 
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1699 |  | 
|  | 1700 | case CMD_SET_DATA_THROTTLING: { | 
|  | 1701 | request = (MainThreadRequest) msg.obj; | 
|  | 1702 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); | 
|  | 1703 | DataThrottlingRequest dataThrottlingRequest = | 
|  | 1704 | (DataThrottlingRequest) request.argument; | 
|  | 1705 | Phone phone = getPhoneFromRequest(request); | 
|  | 1706 | if (phone != null) { | 
|  | 1707 | phone.setDataThrottling(onCompleted, | 
|  | 1708 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), | 
|  | 1709 | dataThrottlingRequest.getCompletionDurationMillis()); | 
|  | 1710 | } else { | 
|  | 1711 | loge("setDataThrottling: No phone object"); | 
|  | 1712 | request.result = | 
|  | 1713 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 1714 | notifyRequester(request); | 
|  | 1715 | } | 
|  | 1716 |  | 
|  | 1717 | break; | 
|  | 1718 | } | 
|  | 1719 | case EVENT_SET_DATA_THROTTLING_DONE: | 
|  | 1720 | ar = (AsyncResult) msg.obj; | 
|  | 1721 | request = (MainThreadRequest) ar.userObj; | 
|  | 1722 |  | 
|  | 1723 | if (ar.exception == null) { | 
|  | 1724 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; | 
|  | 1725 | } else if (ar.exception instanceof CommandException) { | 
|  | 1726 | loge("setDataThrottling: CommandException: " + ar.exception); | 
|  | 1727 | CommandException.Error error = | 
|  | 1728 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1729 |  | 
|  | 1730 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
|  | 1731 | request.result = TelephonyManager | 
|  | 1732 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 1733 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { | 
|  | 1734 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; | 
|  | 1735 | } else { | 
|  | 1736 | request.result = | 
|  | 1737 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; | 
|  | 1738 | } | 
|  | 1739 | } else { | 
|  | 1740 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; | 
|  | 1741 | } | 
|  | 1742 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); | 
|  | 1743 | notifyRequester(request); | 
|  | 1744 | break; | 
| Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1745 |  | 
|  | 1746 | case CMD_SET_SIM_POWER: { | 
|  | 1747 | request = (MainThreadRequest) msg.obj; | 
|  | 1748 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); | 
|  | 1749 | request = (MainThreadRequest) msg.obj; | 
|  | 1750 | int stateToSet = | 
|  | 1751 | ((Pair<Integer, IIntegerConsumer>) | 
|  | 1752 | request.argument).first; | 
|  | 1753 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); | 
|  | 1754 | break; | 
|  | 1755 | } | 
|  | 1756 | case EVENT_SET_SIM_POWER_DONE: { | 
|  | 1757 | ar = (AsyncResult) msg.obj; | 
|  | 1758 | request = (MainThreadRequest) ar.userObj; | 
|  | 1759 | IIntegerConsumer callback = | 
|  | 1760 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; | 
|  | 1761 | if (ar.exception != null) { | 
|  | 1762 | loge("setSimPower exception: " + ar.exception); | 
|  | 1763 | int errorCode = TelephonyManager.CallForwardingInfoCallback | 
|  | 1764 | .RESULT_ERROR_UNKNOWN; | 
|  | 1765 | if (ar.exception instanceof CommandException) { | 
|  | 1766 | CommandException.Error error = | 
|  | 1767 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1768 | if (error == CommandException.Error.SIM_ERR) { | 
|  | 1769 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; | 
|  | 1770 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { | 
|  | 1771 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; | 
|  | 1772 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 1773 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; | 
|  | 1774 | } else { | 
|  | 1775 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; | 
|  | 1776 | } | 
|  | 1777 | } | 
|  | 1778 | try { | 
|  | 1779 | callback.accept(errorCode); | 
|  | 1780 | } catch (RemoteException e) { | 
|  | 1781 | // Ignore if the remote process is no longer available to call back. | 
|  | 1782 | Log.w(LOG_TAG, "setSimPower: callback not available."); | 
|  | 1783 | } | 
|  | 1784 | } else { | 
|  | 1785 | try { | 
|  | 1786 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); | 
|  | 1787 | } catch (RemoteException e) { | 
|  | 1788 | // Ignore if the remote process is no longer available to call back. | 
|  | 1789 | Log.w(LOG_TAG, "setSimPower: callback not available."); | 
|  | 1790 | } | 
|  | 1791 | } | 
|  | 1792 | break; | 
|  | 1793 | } | 
|  | 1794 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1795 | default: | 
|  | 1796 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); | 
|  | 1797 | break; | 
|  | 1798 | } | 
|  | 1799 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1800 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1801 | private void notifyRequester(MainThreadRequest request) { | 
|  | 1802 | synchronized (request) { | 
|  | 1803 | request.notifyAll(); | 
|  | 1804 | } | 
|  | 1805 | } | 
|  | 1806 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1807 | private void handleNullReturnEvent(Message msg, String command) { | 
|  | 1808 | AsyncResult ar = (AsyncResult) msg.obj; | 
|  | 1809 | MainThreadRequest request = (MainThreadRequest) ar.userObj; | 
|  | 1810 | if (ar.exception == null) { | 
|  | 1811 | request.result = true; | 
|  | 1812 | } else { | 
|  | 1813 | request.result = false; | 
|  | 1814 | if (ar.exception instanceof CommandException) { | 
|  | 1815 | loge(command + ": CommandException: " + ar.exception); | 
|  | 1816 | } else { | 
|  | 1817 | loge(command + ": Unknown exception"); | 
|  | 1818 | } | 
|  | 1819 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1820 | notifyRequester(request); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1821 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1822 | } | 
|  | 1823 |  | 
|  | 1824 | /** | 
|  | 1825 | * Posts the specified command to be executed on the main thread, | 
|  | 1826 | * waits for the request to complete, and returns the result. | 
|  | 1827 | * @see #sendRequestAsync | 
|  | 1828 | */ | 
|  | 1829 | private Object sendRequest(int command, Object argument) { | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1830 | return sendRequest( | 
|  | 1831 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1832 | } | 
|  | 1833 |  | 
|  | 1834 | /** | 
|  | 1835 | * Posts the specified command to be executed on the main thread, | 
|  | 1836 | * waits for the request to complete, and returns the result. | 
|  | 1837 | * @see #sendRequestAsync | 
|  | 1838 | */ | 
|  | 1839 | private Object sendRequest(int command, Object argument, WorkSource workSource) { | 
|  | 1840 | return sendRequest(command, argument,  SubscriptionManager.INVALID_SUBSCRIPTION_ID, | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1841 | null, workSource); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1842 | } | 
|  | 1843 |  | 
|  | 1844 | /** | 
|  | 1845 | * Posts the specified command to be executed on the main thread, | 
|  | 1846 | * waits for the request to complete, and returns the result. | 
|  | 1847 | * @see #sendRequestAsync | 
|  | 1848 | */ | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1849 | private Object sendRequest(int command, Object argument, Integer subId) { | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1850 | return sendRequest(command, argument, subId, null, null); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1851 | } | 
|  | 1852 |  | 
|  | 1853 | /** | 
|  | 1854 | * Posts the specified command to be executed on the main thread, | 
|  | 1855 | * waits for the request to complete, and returns the result. | 
|  | 1856 | * @see #sendRequestAsync | 
|  | 1857 | */ | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1858 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { | 
|  | 1859 | return sendRequest(command, argument, subId, null, workSource); | 
|  | 1860 | } | 
|  | 1861 |  | 
|  | 1862 | /** | 
|  | 1863 | * Posts the specified command to be executed on the main thread, | 
|  | 1864 | * waits for the request to complete, and returns the result. | 
|  | 1865 | * @see #sendRequestAsync | 
|  | 1866 | */ | 
|  | 1867 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { | 
|  | 1868 | return sendRequest( | 
|  | 1869 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); | 
|  | 1870 | } | 
|  | 1871 |  | 
|  | 1872 | /** | 
|  | 1873 | * Posts the specified command to be executed on the main thread, | 
|  | 1874 | * waits for the request to complete, and returns the result. | 
|  | 1875 | * @see #sendRequestAsync | 
|  | 1876 | */ | 
|  | 1877 | private Object sendRequest( | 
|  | 1878 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1879 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { | 
|  | 1880 | throw new RuntimeException("This method will deadlock if called from the main thread."); | 
|  | 1881 | } | 
|  | 1882 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1883 | MainThreadRequest request = null; | 
|  | 1884 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { | 
|  | 1885 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); | 
|  | 1886 | } else if (phone != null) { | 
|  | 1887 | request = new MainThreadRequest(argument, phone, workSource); | 
|  | 1888 | } else { | 
|  | 1889 | request = new MainThreadRequest(argument, subId, workSource); | 
|  | 1890 | } | 
|  | 1891 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1892 | Message msg = mMainThreadHandler.obtainMessage(command, request); | 
|  | 1893 | msg.sendToTarget(); | 
|  | 1894 |  | 
|  | 1895 | // Wait for the request to complete | 
|  | 1896 | synchronized (request) { | 
|  | 1897 | while (request.result == null) { | 
|  | 1898 | try { | 
|  | 1899 | request.wait(); | 
|  | 1900 | } catch (InterruptedException e) { | 
|  | 1901 | // Do nothing, go back and wait until the request is complete | 
|  | 1902 | } | 
|  | 1903 | } | 
|  | 1904 | } | 
|  | 1905 | return request.result; | 
|  | 1906 | } | 
|  | 1907 |  | 
|  | 1908 | /** | 
|  | 1909 | * Asynchronous ("fire and forget") version of sendRequest(): | 
|  | 1910 | * Posts the specified command to be executed on the main thread, and | 
|  | 1911 | * returns immediately. | 
|  | 1912 | * @see #sendRequest | 
|  | 1913 | */ | 
|  | 1914 | private void sendRequestAsync(int command) { | 
|  | 1915 | mMainThreadHandler.sendEmptyMessage(command); | 
|  | 1916 | } | 
|  | 1917 |  | 
|  | 1918 | /** | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1919 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1920 | * @see {@link #sendRequest(int)} | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1921 | */ | 
|  | 1922 | private void sendRequestAsync(int command, Object argument) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1923 | sendRequestAsync(command, argument, null, null); | 
|  | 1924 | } | 
|  | 1925 |  | 
|  | 1926 | /** | 
|  | 1927 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. | 
|  | 1928 | * @see {@link #sendRequest(int,Object)} | 
|  | 1929 | */ | 
|  | 1930 | private void sendRequestAsync( | 
|  | 1931 | int command, Object argument, Phone phone, WorkSource workSource) { | 
|  | 1932 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1933 | Message msg = mMainThreadHandler.obtainMessage(command, request); | 
|  | 1934 | msg.sendToTarget(); | 
|  | 1935 | } | 
|  | 1936 |  | 
|  | 1937 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1938 | * Initialize the singleton PhoneInterfaceManager instance. | 
|  | 1939 | * This is only done once, at startup, from PhoneApp.onCreate(). | 
|  | 1940 | */ | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1941 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1942 | synchronized (PhoneInterfaceManager.class) { | 
|  | 1943 | if (sInstance == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1944 | sInstance = new PhoneInterfaceManager(app); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1945 | } else { | 
|  | 1946 | Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance); | 
|  | 1947 | } | 
|  | 1948 | return sInstance; | 
|  | 1949 | } | 
|  | 1950 | } | 
|  | 1951 |  | 
|  | 1952 | /** Private constructor; @see init() */ | 
| Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1953 | private PhoneInterfaceManager(PhoneGlobals app) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1954 | mApp = app; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1955 | mCM = PhoneGlobals.getInstance().mCM; | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1956 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1957 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1958 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); | 
|  | 1959 | mMainThreadHandler = new MainThreadHandler(); | 
| Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1960 | mSubscriptionController = SubscriptionController.getInstance(); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1961 | mTelephonySharedPreferences = | 
|  | 1962 | PreferenceManager.getDefaultSharedPreferences(mApp); | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1963 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1964 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); | 
| Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1965 | mNotifyUserActivity = new AtomicBoolean(false); | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1966 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1967 | publish(); | 
|  | 1968 | } | 
|  | 1969 |  | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1970 | private Phone getDefaultPhone() { | 
|  | 1971 | Phone thePhone = getPhone(getDefaultSubscription()); | 
|  | 1972 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); | 
|  | 1973 | } | 
|  | 1974 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1975 | private void publish() { | 
|  | 1976 | if (DBG) log("publish: " + this); | 
|  | 1977 |  | 
| Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1978 | TelephonyFrameworkInitializer | 
|  | 1979 | .getTelephonyServiceManager() | 
|  | 1980 | .getTelephonyServiceRegisterer() | 
|  | 1981 | .register(this); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1982 | } | 
|  | 1983 |  | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1984 | private Phone getPhoneFromRequest(MainThreadRequest request) { | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1985 | if (request.phone != null) { | 
|  | 1986 | return request.phone; | 
|  | 1987 | } else { | 
|  | 1988 | return getPhoneFromSubId(request.subId); | 
|  | 1989 | } | 
|  | 1990 | } | 
|  | 1991 |  | 
|  | 1992 | private Phone getPhoneFromSubId(int subId) { | 
|  | 1993 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) | 
|  | 1994 | ? getDefaultPhone() : getPhone(subId); | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1995 | } | 
|  | 1996 |  | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1997 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { | 
|  | 1998 | Phone phone = getPhoneFromRequest(request); | 
|  | 1999 | return phone == null ? null : | 
|  | 2000 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); | 
|  | 2001 | } | 
|  | 2002 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2003 | // returns phone associated with the subId. | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2004 | private Phone getPhone(int subId) { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2005 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2006 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2007 |  | 
| Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2008 | private void sendEraseModemConfig(Phone phone) { | 
|  | 2009 | if (phone != null) { | 
|  | 2010 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 2011 | mApp, phone.getSubId(), "eraseModemConfig"); | 
|  | 2012 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2013 | try { | 
|  | 2014 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); | 
|  | 2015 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); | 
|  | 2016 | } finally { | 
|  | 2017 | Binder.restoreCallingIdentity(identity); | 
|  | 2018 | } | 
|  | 2019 | } | 
|  | 2020 | } | 
|  | 2021 |  | 
| Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2022 | private boolean isImsAvailableOnDevice() { | 
|  | 2023 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); | 
|  | 2024 | if (pm == null) { | 
|  | 2025 | // For some reason package manger is not available.. This will fail internally anyway, | 
|  | 2026 | // so do not throw error and allow. | 
|  | 2027 | return true; | 
|  | 2028 | } | 
|  | 2029 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); | 
|  | 2030 | } | 
|  | 2031 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2032 | public void dial(String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2033 | dialForSubscriber(getPreferredVoiceSubscription(), number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2034 | } | 
|  | 2035 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2036 | public void dialForSubscriber(int subId, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2037 | if (DBG) log("dial: " + number); | 
|  | 2038 | // No permission check needed here: This is just a wrapper around the | 
|  | 2039 | // ACTION_DIAL intent, which is available to any app since it puts up | 
|  | 2040 | // the UI before it does anything. | 
|  | 2041 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2042 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2043 | try { | 
|  | 2044 | String url = createTelUrl(number); | 
|  | 2045 | if (url == null) { | 
|  | 2046 | return; | 
|  | 2047 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2048 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2049 | // PENDING: should we just silently fail if phone is offhook or ringing? | 
|  | 2050 | PhoneConstants.State state = mCM.getState(subId); | 
|  | 2051 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { | 
|  | 2052 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); | 
|  | 2053 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 2054 | mApp.startActivity(intent); | 
|  | 2055 | } | 
|  | 2056 | } finally { | 
|  | 2057 | Binder.restoreCallingIdentity(identity); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2058 | } | 
|  | 2059 | } | 
|  | 2060 |  | 
|  | 2061 | public void call(String callingPackage, String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2062 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2063 | } | 
|  | 2064 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2065 | public void callForSubscriber(int subId, String callingPackage, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2066 | if (DBG) log("call: " + number); | 
|  | 2067 |  | 
|  | 2068 | // This is just a wrapper around the ACTION_CALL intent, but we still | 
|  | 2069 | // need to do a permission check since we're calling startActivity() | 
|  | 2070 | // from the context of the phone app. | 
|  | 2071 | enforceCallPermission(); | 
|  | 2072 |  | 
| Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2073 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2074 | != AppOpsManager.MODE_ALLOWED) { | 
|  | 2075 | return; | 
|  | 2076 | } | 
|  | 2077 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2078 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2079 | try { | 
|  | 2080 | String url = createTelUrl(number); | 
|  | 2081 | if (url == null) { | 
|  | 2082 | return; | 
|  | 2083 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2084 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2085 | boolean isValid = false; | 
|  | 2086 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); | 
|  | 2087 | if (slist != null) { | 
|  | 2088 | for (SubscriptionInfo subInfoRecord : slist) { | 
|  | 2089 | if (subInfoRecord.getSubscriptionId() == subId) { | 
|  | 2090 | isValid = true; | 
|  | 2091 | break; | 
|  | 2092 | } | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2093 | } | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2094 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2095 | if (!isValid) { | 
|  | 2096 | return; | 
|  | 2097 | } | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2098 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2099 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); | 
|  | 2100 | intent.putExtra(SUBSCRIPTION_KEY, subId); | 
|  | 2101 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 2102 | mApp.startActivity(intent); | 
|  | 2103 | } finally { | 
|  | 2104 | Binder.restoreCallingIdentity(identity); | 
|  | 2105 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2106 | } | 
|  | 2107 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2108 | public boolean supplyPinForSubscriber(int subId, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2109 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2110 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
|  | 2111 | } | 
|  | 2112 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2113 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2114 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2115 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
|  | 2116 | } | 
|  | 2117 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2118 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2119 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2120 |  | 
|  | 2121 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2122 | try { | 
|  | 2123 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); | 
|  | 2124 | checkSimPin.start(); | 
|  | 2125 | return checkSimPin.unlockSim(null, pin); | 
|  | 2126 | } finally { | 
|  | 2127 | Binder.restoreCallingIdentity(identity); | 
|  | 2128 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2129 | } | 
|  | 2130 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2131 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2132 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2133 |  | 
|  | 2134 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2135 | try { | 
|  | 2136 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); | 
|  | 2137 | checkSimPuk.start(); | 
|  | 2138 | return checkSimPuk.unlockSim(puk, pin); | 
|  | 2139 | } finally { | 
|  | 2140 | Binder.restoreCallingIdentity(identity); | 
|  | 2141 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2142 | } | 
|  | 2143 |  | 
|  | 2144 | /** | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2145 | * Helper thread to turn async call to SimCard#supplyPin into | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2146 | * a synchronous one. | 
|  | 2147 | */ | 
|  | 2148 | private static class UnlockSim extends Thread { | 
|  | 2149 |  | 
|  | 2150 | private final IccCard mSimCard; | 
|  | 2151 |  | 
|  | 2152 | private boolean mDone = false; | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2153 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
|  | 2154 | private int mRetryCount = -1; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2155 |  | 
|  | 2156 | // For replies from SimCard interface | 
|  | 2157 | private Handler mHandler; | 
|  | 2158 |  | 
|  | 2159 | // For async handler to identify request type | 
|  | 2160 | private static final int SUPPLY_PIN_COMPLETE = 100; | 
|  | 2161 |  | 
|  | 2162 | public UnlockSim(IccCard simCard) { | 
|  | 2163 | mSimCard = simCard; | 
|  | 2164 | } | 
|  | 2165 |  | 
|  | 2166 | @Override | 
|  | 2167 | public void run() { | 
|  | 2168 | Looper.prepare(); | 
|  | 2169 | synchronized (UnlockSim.this) { | 
|  | 2170 | mHandler = new Handler() { | 
|  | 2171 | @Override | 
|  | 2172 | public void handleMessage(Message msg) { | 
|  | 2173 | AsyncResult ar = (AsyncResult) msg.obj; | 
|  | 2174 | switch (msg.what) { | 
|  | 2175 | case SUPPLY_PIN_COMPLETE: | 
|  | 2176 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); | 
|  | 2177 | synchronized (UnlockSim.this) { | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2178 | mRetryCount = msg.arg1; | 
|  | 2179 | if (ar.exception != null) { | 
|  | 2180 | if (ar.exception instanceof CommandException && | 
|  | 2181 | ((CommandException)(ar.exception)).getCommandError() | 
|  | 2182 | == CommandException.Error.PASSWORD_INCORRECT) { | 
|  | 2183 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; | 
| vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2184 | } //When UiccCardApp dispose,handle message and return exception | 
|  | 2185 | else if (ar.exception instanceof CommandException && | 
|  | 2186 | ((CommandException) (ar.exception)).getCommandError() | 
|  | 2187 | == CommandException.Error.ABORTED) { | 
|  | 2188 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2189 | } else { | 
|  | 2190 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
|  | 2191 | } | 
|  | 2192 | } else { | 
|  | 2193 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; | 
|  | 2194 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2195 | mDone = true; | 
|  | 2196 | UnlockSim.this.notifyAll(); | 
|  | 2197 | } | 
|  | 2198 | break; | 
|  | 2199 | } | 
|  | 2200 | } | 
|  | 2201 | }; | 
|  | 2202 | UnlockSim.this.notifyAll(); | 
|  | 2203 | } | 
|  | 2204 | Looper.loop(); | 
|  | 2205 | } | 
|  | 2206 |  | 
|  | 2207 | /* | 
|  | 2208 | * Use PIN or PUK to unlock SIM card | 
|  | 2209 | * | 
|  | 2210 | * If PUK is null, unlock SIM card with PIN | 
|  | 2211 | * | 
|  | 2212 | * If PUK is not null, unlock SIM card with PUK and set PIN code | 
|  | 2213 | */ | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2214 | synchronized int[] unlockSim(String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2215 |  | 
|  | 2216 | while (mHandler == null) { | 
|  | 2217 | try { | 
|  | 2218 | wait(); | 
|  | 2219 | } catch (InterruptedException e) { | 
|  | 2220 | Thread.currentThread().interrupt(); | 
|  | 2221 | } | 
|  | 2222 | } | 
|  | 2223 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); | 
|  | 2224 |  | 
|  | 2225 | if (puk == null) { | 
|  | 2226 | mSimCard.supplyPin(pin, callback); | 
|  | 2227 | } else { | 
|  | 2228 | mSimCard.supplyPuk(puk, pin, callback); | 
|  | 2229 | } | 
|  | 2230 |  | 
|  | 2231 | while (!mDone) { | 
|  | 2232 | try { | 
|  | 2233 | Log.d(LOG_TAG, "wait for done"); | 
|  | 2234 | wait(); | 
|  | 2235 | } catch (InterruptedException e) { | 
|  | 2236 | // Restore the interrupted status | 
|  | 2237 | Thread.currentThread().interrupt(); | 
|  | 2238 | } | 
|  | 2239 | } | 
|  | 2240 | Log.d(LOG_TAG, "done"); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2241 | int[] resultArray = new int[2]; | 
|  | 2242 | resultArray[0] = mResult; | 
|  | 2243 | resultArray[1] = mRetryCount; | 
|  | 2244 | return resultArray; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2245 | } | 
|  | 2246 | } | 
|  | 2247 |  | 
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2248 | /** | 
|  | 2249 | * This method has been removed due to privacy and stability concerns. | 
|  | 2250 | */ | 
|  | 2251 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2252 | public void updateServiceLocation() { | 
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2253 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); | 
|  | 2254 | return; | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2255 | } | 
|  | 2256 |  | 
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2257 | @Override | 
|  | 2258 | public void updateServiceLocationWithPackageName(String callingPackage) { | 
|  | 2259 | mApp.getSystemService(AppOpsManager.class) | 
|  | 2260 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 2261 |  | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2262 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); | 
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2263 | if (targetSdk > android.os.Build.VERSION_CODES.R) { | 
|  | 2264 | // Callers targeting S have no business invoking this method. | 
|  | 2265 | return; | 
|  | 2266 | } | 
|  | 2267 |  | 
|  | 2268 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 2269 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 2270 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 2271 | .setCallingPackage(callingPackage) | 
|  | 2272 | .setCallingFeatureId(null) | 
|  | 2273 | .setCallingPid(Binder.getCallingPid()) | 
|  | 2274 | .setCallingUid(Binder.getCallingUid()) | 
|  | 2275 | .setMethod("updateServiceLocation") | 
|  | 2276 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
|  | 2277 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 2278 | .build()); | 
|  | 2279 | // Apps that lack location permission have no business calling this method; | 
|  | 2280 | // however, because no permission was declared in the public API, denials must | 
|  | 2281 | // all be "soft". | 
|  | 2282 | switch (locationResult) { | 
|  | 2283 | case DENIED_HARD: /* fall through */ | 
|  | 2284 | case DENIED_SOFT: | 
|  | 2285 | return; | 
|  | 2286 | } | 
|  | 2287 |  | 
|  | 2288 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2289 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2290 | try { | 
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2291 | final Phone phone = getPhone(getDefaultSubscription()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2292 | if (phone != null) { | 
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2293 | phone.updateServiceLocation(workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2294 | } | 
|  | 2295 | } finally { | 
|  | 2296 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2297 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2298 | } | 
|  | 2299 |  | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2300 | @Deprecated | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2301 | @Override | 
|  | 2302 | public boolean isRadioOn(String callingPackage) { | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2303 | return isRadioOnWithFeature(callingPackage, null); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2304 | } | 
|  | 2305 |  | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2306 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2307 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2308 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { | 
|  | 2309 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, | 
|  | 2310 | callingFeatureId); | 
|  | 2311 | } | 
|  | 2312 |  | 
|  | 2313 | @Deprecated | 
|  | 2314 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2315 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2316 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); | 
|  | 2317 | } | 
|  | 2318 |  | 
|  | 2319 | @Override | 
|  | 2320 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, | 
|  | 2321 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2322 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2323 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2324 | return false; | 
|  | 2325 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2326 |  | 
|  | 2327 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2328 | try { | 
|  | 2329 | return isRadioOnForSubscriber(subId); | 
|  | 2330 | } finally { | 
|  | 2331 | Binder.restoreCallingIdentity(identity); | 
|  | 2332 | } | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2333 | } | 
|  | 2334 |  | 
|  | 2335 | private boolean isRadioOnForSubscriber(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2336 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2337 | try { | 
|  | 2338 | final Phone phone = getPhone(subId); | 
|  | 2339 | if (phone != null) { | 
|  | 2340 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; | 
|  | 2341 | } else { | 
|  | 2342 | return false; | 
|  | 2343 | } | 
|  | 2344 | } finally { | 
|  | 2345 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2346 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2347 | } | 
|  | 2348 |  | 
|  | 2349 | public void toggleRadioOnOff() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2350 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2351 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2352 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2353 | public void toggleRadioOnOffForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2354 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2355 |  | 
|  | 2356 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2357 | try { | 
|  | 2358 | final Phone phone = getPhone(subId); | 
|  | 2359 | if (phone != null) { | 
|  | 2360 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); | 
|  | 2361 | } | 
|  | 2362 | } finally { | 
|  | 2363 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2364 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2365 | } | 
|  | 2366 |  | 
|  | 2367 | public boolean setRadio(boolean turnOn) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2368 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2369 | } | 
|  | 2370 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2371 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2372 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2373 |  | 
|  | 2374 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2375 | try { | 
|  | 2376 | final Phone phone = getPhone(subId); | 
|  | 2377 | if (phone == null) { | 
|  | 2378 | return false; | 
|  | 2379 | } | 
|  | 2380 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { | 
|  | 2381 | toggleRadioOnOffForSubscriber(subId); | 
|  | 2382 | } | 
|  | 2383 | return true; | 
|  | 2384 | } finally { | 
|  | 2385 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2386 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2387 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2388 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2389 | public boolean needMobileRadioShutdown() { | 
| Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2390 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2391 | /* | 
|  | 2392 | * If any of the Radios are available, it will need to be | 
|  | 2393 | * shutdown. So return true if any Radio is available. | 
|  | 2394 | */ | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2395 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2396 | try { | 
|  | 2397 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 2398 | Phone phone = PhoneFactory.getPhone(i); | 
|  | 2399 | if (phone != null && phone.isRadioAvailable()) return true; | 
|  | 2400 | } | 
|  | 2401 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); | 
|  | 2402 | return false; | 
|  | 2403 | } finally { | 
|  | 2404 | Binder.restoreCallingIdentity(identity); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2405 | } | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2406 | } | 
|  | 2407 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2408 | @Override | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2409 | public void shutdownMobileRadios() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2410 | enforceModifyPermission(); | 
|  | 2411 |  | 
|  | 2412 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2413 | try { | 
|  | 2414 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 2415 | logv("Shutting down Phone " + i); | 
|  | 2416 | shutdownRadioUsingPhoneId(i); | 
|  | 2417 | } | 
|  | 2418 | } finally { | 
|  | 2419 | Binder.restoreCallingIdentity(identity); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2420 | } | 
|  | 2421 | } | 
|  | 2422 |  | 
|  | 2423 | private void shutdownRadioUsingPhoneId(int phoneId) { | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2424 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 2425 | if (phone != null && phone.isRadioAvailable()) { | 
|  | 2426 | phone.shutdownRadio(); | 
|  | 2427 | } | 
|  | 2428 | } | 
|  | 2429 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2430 | public boolean setRadioPower(boolean turnOn) { | 
| Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2431 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2432 |  | 
|  | 2433 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2434 | try { | 
|  | 2435 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); | 
|  | 2436 | if (defaultPhone != null) { | 
|  | 2437 | defaultPhone.setRadioPower(turnOn); | 
|  | 2438 | return true; | 
|  | 2439 | } else { | 
|  | 2440 | loge("There's no default phone."); | 
|  | 2441 | return false; | 
|  | 2442 | } | 
|  | 2443 | } finally { | 
|  | 2444 | Binder.restoreCallingIdentity(identity); | 
| Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2445 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2446 | } | 
|  | 2447 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2448 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2449 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2450 |  | 
|  | 2451 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2452 | try { | 
|  | 2453 | final Phone phone = getPhone(subId); | 
|  | 2454 | if (phone != null) { | 
|  | 2455 | phone.setRadioPower(turnOn); | 
|  | 2456 | return true; | 
|  | 2457 | } else { | 
|  | 2458 | return false; | 
|  | 2459 | } | 
|  | 2460 | } finally { | 
|  | 2461 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2462 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | } | 
|  | 2464 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2465 | // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2466 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2467 | public boolean enableDataConnectivity() { | 
|  | 2468 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2469 |  | 
|  | 2470 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2471 | try { | 
|  | 2472 | int subId = mSubscriptionController.getDefaultDataSubId(); | 
|  | 2473 | final Phone phone = getPhone(subId); | 
|  | 2474 | if (phone != null) { | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2475 | phone.getDataEnabledSettings().setDataEnabled( | 
|  | 2476 | TelephonyManager.DATA_ENABLED_REASON_USER, true); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2477 | return true; | 
|  | 2478 | } else { | 
|  | 2479 | return false; | 
|  | 2480 | } | 
|  | 2481 | } finally { | 
|  | 2482 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2483 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2484 | } | 
|  | 2485 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2486 | // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2487 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2488 | public boolean disableDataConnectivity() { | 
|  | 2489 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2490 |  | 
|  | 2491 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2492 | try { | 
|  | 2493 | int subId = mSubscriptionController.getDefaultDataSubId(); | 
|  | 2494 | final Phone phone = getPhone(subId); | 
|  | 2495 | if (phone != null) { | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2496 | phone.getDataEnabledSettings().setDataEnabled( | 
|  | 2497 | TelephonyManager.DATA_ENABLED_REASON_USER, false); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2498 | return true; | 
|  | 2499 | } else { | 
|  | 2500 | return false; | 
|  | 2501 | } | 
|  | 2502 | } finally { | 
|  | 2503 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2504 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2505 | } | 
|  | 2506 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2507 | @Override | 
| Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2508 | public boolean isDataConnectivityPossible(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2509 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2510 | try { | 
|  | 2511 | final Phone phone = getPhone(subId); | 
|  | 2512 | if (phone != null) { | 
| Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2513 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2514 | } else { | 
|  | 2515 | return false; | 
|  | 2516 | } | 
|  | 2517 | } finally { | 
|  | 2518 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2519 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2520 | } | 
|  | 2521 |  | 
|  | 2522 | public boolean handlePinMmi(String dialString) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2523 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2524 | } | 
|  | 2525 |  | 
| pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2526 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2527 | enforceCallPermission(); | 
|  | 2528 |  | 
|  | 2529 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2530 | try { | 
|  | 2531 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 2532 | return; | 
|  | 2533 | } | 
|  | 2534 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); | 
|  | 2535 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); | 
|  | 2536 | } finally { | 
|  | 2537 | Binder.restoreCallingIdentity(identity); | 
|  | 2538 | } | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2539 | }; | 
|  | 2540 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2541 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2542 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2543 |  | 
|  | 2544 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2545 | try { | 
|  | 2546 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 2547 | return false; | 
|  | 2548 | } | 
|  | 2549 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); | 
|  | 2550 | } finally { | 
|  | 2551 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2552 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2553 | } | 
|  | 2554 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2555 | public int getCallState() { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2556 | return getCallStateForSlot(getSlotForDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2557 | } | 
|  | 2558 |  | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2559 | public int getCallStateForSlot(int slotIndex) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2560 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2561 | try { | 
|  | 2562 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2563 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : | 
|  | 2564 | PhoneConstantConversions.convertCallState(phone.getState()); | 
|  | 2565 | } finally { | 
|  | 2566 | Binder.restoreCallingIdentity(identity); | 
|  | 2567 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | } | 
|  | 2569 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2570 | @Override | 
| Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2571 | public int getDataState() { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2572 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); | 
|  | 2573 | } | 
|  | 2574 |  | 
|  | 2575 | @Override | 
|  | 2576 | public int getDataStateForSubId(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2577 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2578 | try { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2579 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2580 | if (phone != null) { | 
|  | 2581 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); | 
|  | 2582 | } else { | 
|  | 2583 | return PhoneConstantConversions.convertDataState( | 
|  | 2584 | PhoneConstants.DataState.DISCONNECTED); | 
|  | 2585 | } | 
|  | 2586 | } finally { | 
|  | 2587 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2588 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2589 | } | 
|  | 2590 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2591 | @Override | 
| Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2592 | public int getDataActivity() { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2593 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); | 
|  | 2594 | } | 
|  | 2595 |  | 
|  | 2596 | @Override | 
|  | 2597 | public int getDataActivityForSubId(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2598 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2599 | try { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2600 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2601 | if (phone != null) { | 
|  | 2602 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); | 
|  | 2603 | } else { | 
|  | 2604 | return TelephonyManager.DATA_ACTIVITY_NONE; | 
|  | 2605 | } | 
|  | 2606 | } finally { | 
|  | 2607 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2608 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2609 | } | 
|  | 2610 |  | 
|  | 2611 | @Override | 
| Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2612 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2613 | mApp.getSystemService(AppOpsManager.class) | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2614 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2615 |  | 
|  | 2616 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 2617 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 2618 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 2619 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2620 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2621 | .setCallingPid(Binder.getCallingPid()) | 
|  | 2622 | .setCallingUid(Binder.getCallingUid()) | 
|  | 2623 | .setMethod("getCellLocation") | 
| Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2624 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2625 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 2626 | .build()); | 
|  | 2627 | switch (locationResult) { | 
|  | 2628 | case DENIED_HARD: | 
|  | 2629 | throw new SecurityException("Not allowed to access cell location"); | 
|  | 2630 | case DENIED_SOFT: | 
| Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2631 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) | 
|  | 2632 | ? new CellIdentityCdma() : new CellIdentityGsm(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2633 | } | 
|  | 2634 |  | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2635 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2636 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2637 | try { | 
|  | 2638 | if (DBG_LOC) log("getCellLocation: is active user"); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2639 | int subId = mSubscriptionController.getDefaultDataSubId(); | 
| Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2640 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2641 | } finally { | 
|  | 2642 | Binder.restoreCallingIdentity(identity); | 
|  | 2643 | } | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2644 | } | 
|  | 2645 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2646 | @Override | 
| Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2647 | public String getNetworkCountryIsoForPhone(int phoneId) { | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2648 | // Reporting the correct network country is ambiguous when IWLAN could conflict with | 
|  | 2649 | // registered cell info, so return a NULL country instead. | 
|  | 2650 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2651 | try { | 
| Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2652 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { | 
|  | 2653 | // Get default phone in this case. | 
|  | 2654 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; | 
|  | 2655 | } | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2656 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2657 | Phone phone = PhoneFactory.getPhone(phoneId); | 
| Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2658 | if (phone == null) return ""; | 
|  | 2659 | ServiceStateTracker sst = phone.getServiceStateTracker(); | 
|  | 2660 | if (sst == null) return ""; | 
|  | 2661 | LocaleTracker lt = sst.getLocaleTracker(); | 
|  | 2662 | if (lt == null) return ""; | 
|  | 2663 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); | 
|  | 2664 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); | 
|  | 2665 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2666 | } finally { | 
|  | 2667 | Binder.restoreCallingIdentity(identity); | 
|  | 2668 | } | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2669 | } | 
|  | 2670 |  | 
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2671 | /** | 
|  | 2672 | * This method was removed due to potential issues caused by performing partial | 
|  | 2673 | * updates of service state, and lack of a credible use case. | 
|  | 2674 | * | 
|  | 2675 | * This has the ability to break the telephony implementation by disabling notification of | 
|  | 2676 | * changes in device connectivity. DO NOT USE THIS! | 
|  | 2677 | */ | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2678 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2679 | public void enableLocationUpdates() { | 
|  | 2680 | mApp.enforceCallingOrSelfPermission( | 
|  | 2681 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2682 | } | 
|  | 2683 |  | 
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2684 | /** | 
|  | 2685 | * This method was removed due to potential issues caused by performing partial | 
|  | 2686 | * updates of service state, and lack of a credible use case. | 
|  | 2687 | * | 
|  | 2688 | * This has the ability to break the telephony implementation by disabling notification of | 
|  | 2689 | * changes in device connectivity. DO NOT USE THIS! | 
|  | 2690 | */ | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2691 | @Override | 
|  | 2692 | public void disableLocationUpdates() { | 
|  | 2693 | mApp.enforceCallingOrSelfPermission( | 
|  | 2694 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2695 | } | 
|  | 2696 |  | 
|  | 2697 | @Override | 
|  | 2698 | @SuppressWarnings("unchecked") | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2699 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, | 
|  | 2700 | String callingFeatureId) { | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2701 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); | 
| Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2702 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { | 
|  | 2703 | throw new SecurityException( | 
|  | 2704 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); | 
|  | 2705 | } | 
| Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2706 |  | 
| Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2707 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2708 | callingPackage) != AppOpsManager.MODE_ALLOWED) { | 
|  | 2709 | return null; | 
|  | 2710 | } | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2711 |  | 
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2712 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2713 |  | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2714 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2715 | if (info == null) return null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2716 |  | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2717 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); | 
|  | 2718 | for (CellInfo ci : info) { | 
|  | 2719 | if (ci instanceof CellInfoGsm) { | 
|  | 2720 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); | 
|  | 2721 | } else if (ci instanceof CellInfoWcdma) { | 
|  | 2722 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); | 
|  | 2723 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | } | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2725 | return (neighbors.size()) > 0 ? neighbors : null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2726 | } | 
|  | 2727 |  | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2728 | private List<CellInfo> getCachedCellInfo() { | 
|  | 2729 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); | 
|  | 2730 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 2731 | List<CellInfo> info = phone.getAllCellInfo(); | 
|  | 2732 | if (info != null) cellInfos.addAll(info); | 
|  | 2733 | } | 
|  | 2734 | return cellInfos; | 
|  | 2735 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2736 |  | 
|  | 2737 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2738 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2739 | mApp.getSystemService(AppOpsManager.class) | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2740 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2741 |  | 
|  | 2742 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 2743 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 2744 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 2745 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2746 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2747 | .setCallingPid(Binder.getCallingPid()) | 
|  | 2748 | .setCallingUid(Binder.getCallingUid()) | 
|  | 2749 | .setMethod("getAllCellInfo") | 
| Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2750 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2751 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 2752 | .build()); | 
|  | 2753 | switch (locationResult) { | 
|  | 2754 | case DENIED_HARD: | 
|  | 2755 | throw new SecurityException("Not allowed to access cell info"); | 
|  | 2756 | case DENIED_SOFT: | 
|  | 2757 | return new ArrayList<>(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2758 | } | 
|  | 2759 |  | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2760 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2761 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { | 
|  | 2762 | return getCachedCellInfo(); | 
|  | 2763 | } | 
|  | 2764 |  | 
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2765 | if (DBG_LOC) log("getAllCellInfo: is active user"); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2766 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2767 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2768 | try { | 
|  | 2769 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); | 
|  | 2770 | for (Phone phone : PhoneFactory.getPhones()) { | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2771 | final List<CellInfo> info = (List<CellInfo>) sendRequest( | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2772 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2773 | if (info != null) cellInfos.addAll(info); | 
|  | 2774 | } | 
|  | 2775 | return cellInfos; | 
|  | 2776 | } finally { | 
|  | 2777 | Binder.restoreCallingIdentity(identity); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2778 | } | 
|  | 2779 | } | 
|  | 2780 |  | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2781 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2782 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, | 
|  | 2783 | String callingFeatureId) { | 
|  | 2784 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, | 
|  | 2785 | getWorkSource(Binder.getCallingUid())); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2786 | } | 
|  | 2787 |  | 
|  | 2788 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2789 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, | 
|  | 2790 | String callingPackage, String callingFeatureId, WorkSource workSource) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2791 | enforceModifyPermission(); | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2792 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2793 | } | 
|  | 2794 |  | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2795 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, | 
|  | 2796 | String callingPackage, String callingFeatureId, WorkSource workSource) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2797 | mApp.getSystemService(AppOpsManager.class) | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2798 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2799 |  | 
|  | 2800 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 2801 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 2802 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 2803 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2804 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2805 | .setCallingPid(Binder.getCallingPid()) | 
|  | 2806 | .setCallingUid(Binder.getCallingUid()) | 
|  | 2807 | .setMethod("requestCellInfoUpdate") | 
| Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2808 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
|  | 2809 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2810 | .build()); | 
|  | 2811 | switch (locationResult) { | 
|  | 2812 | case DENIED_HARD: | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2813 | if (TelephonyPermissions | 
|  | 2814 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { | 
| Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2815 | // Safetynet logging for b/154934934 | 
|  | 2816 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); | 
|  | 2817 | } | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2818 | throw new SecurityException("Not allowed to access cell info"); | 
|  | 2819 | case DENIED_SOFT: | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2820 | if (TelephonyPermissions | 
|  | 2821 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { | 
| Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2822 | // Safetynet logging for b/154934934 | 
|  | 2823 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); | 
|  | 2824 | } | 
| Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2825 | try { | 
|  | 2826 | cb.onCellInfo(new ArrayList<CellInfo>()); | 
|  | 2827 | } catch (RemoteException re) { | 
|  | 2828 | // Drop without consequences | 
|  | 2829 | } | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2830 | return; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2831 | } | 
|  | 2832 |  | 
| Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2833 |  | 
|  | 2834 | final Phone phone = getPhoneFromSubId(subId); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2835 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); | 
|  | 2836 |  | 
|  | 2837 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); | 
|  | 2838 | } | 
|  | 2839 |  | 
|  | 2840 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2841 | public void setCellInfoListRate(int rateInMillis) { | 
| Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2842 | enforceModifyPermission(); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2843 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2844 |  | 
|  | 2845 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2846 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2847 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2848 | } finally { | 
|  | 2849 | Binder.restoreCallingIdentity(identity); | 
|  | 2850 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2851 | } | 
|  | 2852 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2853 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2854 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2855 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2856 | if (phone == null) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2857 | return null; | 
|  | 2858 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2859 | int subId = phone.getSubId(); | 
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2860 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2861 | callingPackage, callingFeatureId, "getImeiForSlot")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2862 | return null; | 
|  | 2863 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2864 |  | 
|  | 2865 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2866 | try { | 
|  | 2867 | return phone.getImei(); | 
|  | 2868 | } finally { | 
|  | 2869 | Binder.restoreCallingIdentity(identity); | 
|  | 2870 | } | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2871 | } | 
|  | 2872 |  | 
|  | 2873 | @Override | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2874 | public String getTypeAllocationCodeForSlot(int slotIndex) { | 
|  | 2875 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2876 | String tac = null; | 
|  | 2877 | if (phone != null) { | 
|  | 2878 | String imei = phone.getImei(); | 
|  | 2879 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); | 
|  | 2880 | } | 
|  | 2881 | return tac; | 
|  | 2882 | } | 
|  | 2883 |  | 
|  | 2884 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2885 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2886 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2887 | if (phone == null) { | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2888 | return null; | 
|  | 2889 | } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2890 |  | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2891 | int subId = phone.getSubId(); | 
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2892 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2893 | callingPackage, callingFeatureId, "getMeidForSlot")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2894 | return null; | 
|  | 2895 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2896 |  | 
|  | 2897 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2898 | try { | 
|  | 2899 | return phone.getMeid(); | 
|  | 2900 | } finally { | 
|  | 2901 | Binder.restoreCallingIdentity(identity); | 
|  | 2902 | } | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2903 | } | 
|  | 2904 |  | 
|  | 2905 | @Override | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2906 | public String getManufacturerCodeForSlot(int slotIndex) { | 
|  | 2907 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2908 | String manufacturerCode = null; | 
|  | 2909 | if (phone != null) { | 
|  | 2910 | String meid = phone.getMeid(); | 
|  | 2911 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); | 
|  | 2912 | } | 
|  | 2913 | return manufacturerCode; | 
|  | 2914 | } | 
|  | 2915 |  | 
|  | 2916 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2917 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, | 
|  | 2918 | String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2919 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2920 | if (phone == null) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2921 | return null; | 
|  | 2922 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2923 | int subId = phone.getSubId(); | 
|  | 2924 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2925 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 2926 | "getDeviceSoftwareVersionForSlot")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2927 | return null; | 
|  | 2928 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2929 |  | 
|  | 2930 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2931 | try { | 
|  | 2932 | return phone.getDeviceSvn(); | 
|  | 2933 | } finally { | 
|  | 2934 | Binder.restoreCallingIdentity(identity); | 
|  | 2935 | } | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2936 | } | 
|  | 2937 |  | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2938 | @Override | 
|  | 2939 | public int getSubscriptionCarrierId(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2940 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2941 | try { | 
|  | 2942 | final Phone phone = getPhone(subId); | 
|  | 2943 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); | 
|  | 2944 | } finally { | 
|  | 2945 | Binder.restoreCallingIdentity(identity); | 
|  | 2946 | } | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2947 | } | 
|  | 2948 |  | 
|  | 2949 | @Override | 
|  | 2950 | public String getSubscriptionCarrierName(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2951 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2952 | try { | 
|  | 2953 | final Phone phone = getPhone(subId); | 
|  | 2954 | return phone == null ? null : phone.getCarrierName(); | 
|  | 2955 | } finally { | 
|  | 2956 | Binder.restoreCallingIdentity(identity); | 
|  | 2957 | } | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2958 | } | 
|  | 2959 |  | 
| calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2960 | @Override | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2961 | public int getSubscriptionSpecificCarrierId(int subId) { | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2962 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2963 | try { | 
|  | 2964 | final Phone phone = getPhone(subId); | 
|  | 2965 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2966 | : phone.getSpecificCarrierId(); | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2967 | } finally { | 
|  | 2968 | Binder.restoreCallingIdentity(identity); | 
|  | 2969 | } | 
|  | 2970 | } | 
|  | 2971 |  | 
|  | 2972 | @Override | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2973 | public String getSubscriptionSpecificCarrierName(int subId) { | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2974 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2975 | try { | 
|  | 2976 | final Phone phone = getPhone(subId); | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2977 | return phone == null ? null : phone.getSpecificCarrierName(); | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2978 | } finally { | 
|  | 2979 | Binder.restoreCallingIdentity(identity); | 
|  | 2980 | } | 
|  | 2981 | } | 
|  | 2982 |  | 
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2983 | @Override | 
| chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2984 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { | 
|  | 2985 | if (!isSubscriptionMccMnc) { | 
|  | 2986 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); | 
|  | 2987 | } | 
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2988 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2989 | if (phone == null) { | 
|  | 2990 | return TelephonyManager.UNKNOWN_CARRIER_ID; | 
|  | 2991 | } | 
|  | 2992 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2993 | try { | 
|  | 2994 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); | 
|  | 2995 | } finally { | 
|  | 2996 | Binder.restoreCallingIdentity(identity); | 
|  | 2997 | } | 
|  | 2998 | } | 
|  | 2999 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3000 | // | 
|  | 3001 | // Internal helper methods. | 
|  | 3002 | // | 
|  | 3003 |  | 
| Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3004 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3005 | * Make sure the caller has the MODIFY_PHONE_STATE permission. | 
|  | 3006 | * | 
|  | 3007 | * @throws SecurityException if the caller does not have the required permission | 
|  | 3008 | */ | 
|  | 3009 | private void enforceModifyPermission() { | 
|  | 3010 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); | 
|  | 3011 | } | 
|  | 3012 |  | 
| Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3013 | /** | 
|  | 3014 | * Make sure the caller is system. | 
|  | 3015 | * | 
|  | 3016 | * @throws SecurityException if the caller is not system. | 
|  | 3017 | */ | 
|  | 3018 | private void enforceSystemCaller() { | 
|  | 3019 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { | 
|  | 3020 | throw new SecurityException("Caller must be system"); | 
|  | 3021 | } | 
|  | 3022 | } | 
|  | 3023 |  | 
| Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3024 | private void enforceActiveEmergencySessionPermission() { | 
|  | 3025 | mApp.enforceCallingOrSelfPermission( | 
|  | 3026 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); | 
|  | 3027 | } | 
|  | 3028 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3029 | /** | 
|  | 3030 | * Make sure the caller has the CALL_PHONE permission. | 
|  | 3031 | * | 
|  | 3032 | * @throws SecurityException if the caller does not have the required permission | 
|  | 3033 | */ | 
|  | 3034 | private void enforceCallPermission() { | 
|  | 3035 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); | 
|  | 3036 | } | 
|  | 3037 |  | 
| paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3038 | private void enforceSettingsPermission() { | 
|  | 3039 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3040 | } | 
|  | 3041 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3042 | private String createTelUrl(String number) { | 
|  | 3043 | if (TextUtils.isEmpty(number)) { | 
|  | 3044 | return null; | 
|  | 3045 | } | 
|  | 3046 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3047 | return "tel:" + number; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3048 | } | 
|  | 3049 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3050 | private static void log(String msg) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3051 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
|  | 3052 | } | 
|  | 3053 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3054 | private static void logv(String msg) { | 
|  | 3055 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
|  | 3056 | } | 
|  | 3057 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3058 | private static void loge(String msg) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3059 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
|  | 3060 | } | 
|  | 3061 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3062 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3063 | public int getActivePhoneType() { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3064 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3065 | } | 
|  | 3066 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3067 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3068 | public int getActivePhoneTypeForSlot(int slotIndex) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3069 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3070 | try { | 
|  | 3071 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3072 | if (phone == null) { | 
|  | 3073 | return PhoneConstants.PHONE_TYPE_NONE; | 
|  | 3074 | } else { | 
|  | 3075 | return phone.getPhoneType(); | 
|  | 3076 | } | 
|  | 3077 | } finally { | 
|  | 3078 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3079 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3080 | } | 
|  | 3081 |  | 
|  | 3082 | /** | 
|  | 3083 | * Returns the CDMA ERI icon index to display | 
|  | 3084 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3085 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3086 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { | 
|  | 3087 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 3088 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3089 | } | 
|  | 3090 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3091 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3092 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, | 
|  | 3093 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3094 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3095 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3096 | "getCdmaEriIconIndexForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3097 | return -1; | 
|  | 3098 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3099 |  | 
|  | 3100 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3101 | try { | 
|  | 3102 | final Phone phone = getPhone(subId); | 
|  | 3103 | if (phone != null) { | 
|  | 3104 | return phone.getCdmaEriIconIndex(); | 
|  | 3105 | } else { | 
|  | 3106 | return -1; | 
|  | 3107 | } | 
|  | 3108 | } finally { | 
|  | 3109 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3110 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3111 | } | 
|  | 3112 |  | 
|  | 3113 | /** | 
|  | 3114 | * Returns the CDMA ERI icon mode, | 
|  | 3115 | * 0 - ON | 
|  | 3116 | * 1 - FLASHING | 
|  | 3117 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3118 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3119 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { | 
|  | 3120 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 3121 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3122 | } | 
|  | 3123 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3124 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3125 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, | 
|  | 3126 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3127 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3128 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3129 | "getCdmaEriIconModeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3130 | return -1; | 
|  | 3131 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3132 |  | 
|  | 3133 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3134 | try { | 
|  | 3135 | final Phone phone = getPhone(subId); | 
|  | 3136 | if (phone != null) { | 
|  | 3137 | return phone.getCdmaEriIconMode(); | 
|  | 3138 | } else { | 
|  | 3139 | return -1; | 
|  | 3140 | } | 
|  | 3141 | } finally { | 
|  | 3142 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3143 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3144 | } | 
|  | 3145 |  | 
|  | 3146 | /** | 
|  | 3147 | * Returns the CDMA ERI text, | 
|  | 3148 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3149 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3150 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { | 
|  | 3151 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 3152 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3153 | } | 
|  | 3154 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3155 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3156 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, | 
|  | 3157 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3158 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3159 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3160 | "getCdmaEriIconTextForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3161 | return null; | 
|  | 3162 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3163 |  | 
|  | 3164 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3165 | try { | 
|  | 3166 | final Phone phone = getPhone(subId); | 
|  | 3167 | if (phone != null) { | 
|  | 3168 | return phone.getCdmaEriText(); | 
|  | 3169 | } else { | 
|  | 3170 | return null; | 
|  | 3171 | } | 
|  | 3172 | } finally { | 
|  | 3173 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3174 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3175 | } | 
|  | 3176 |  | 
|  | 3177 | /** | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3178 | * Returns the CDMA MDN. | 
|  | 3179 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3180 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3181 | public String getCdmaMdn(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3182 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3183 | mApp, subId, "getCdmaMdn"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3184 |  | 
|  | 3185 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3186 | try { | 
|  | 3187 | final Phone phone = getPhone(subId); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3188 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3189 | return phone.getLine1Number(); | 
|  | 3190 | } else { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3191 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3192 | return null; | 
|  | 3193 | } | 
|  | 3194 | } finally { | 
|  | 3195 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3196 | } | 
|  | 3197 | } | 
|  | 3198 |  | 
|  | 3199 | /** | 
|  | 3200 | * Returns the CDMA MIN. | 
|  | 3201 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3202 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3203 | public String getCdmaMin(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3204 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3205 | mApp, subId, "getCdmaMin"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3206 |  | 
|  | 3207 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3208 | try { | 
|  | 3209 | final Phone phone = getPhone(subId); | 
|  | 3210 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
|  | 3211 | return phone.getCdmaMin(); | 
|  | 3212 | } else { | 
|  | 3213 | return null; | 
|  | 3214 | } | 
|  | 3215 | } finally { | 
|  | 3216 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3217 | } | 
|  | 3218 | } | 
|  | 3219 |  | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3220 | @Override | 
|  | 3221 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, | 
|  | 3222 | INumberVerificationCallback callback, String callingPackage) { | 
|  | 3223 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) | 
|  | 3224 | != PERMISSION_GRANTED) { | 
|  | 3225 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); | 
|  | 3226 | } | 
|  | 3227 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 3228 |  | 
|  | 3229 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); | 
|  | 3230 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { | 
|  | 3231 | throw new SecurityException("Calling package must be configured in the device config"); | 
|  | 3232 | } | 
|  | 3233 |  | 
|  | 3234 | if (range == null) { | 
|  | 3235 | throw new NullPointerException("Range must be non-null"); | 
|  | 3236 | } | 
|  | 3237 |  | 
|  | 3238 | timeoutMillis = Math.min(timeoutMillis, | 
| Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3239 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3240 |  | 
|  | 3241 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); | 
|  | 3242 | } | 
|  | 3243 |  | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3244 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3245 | * Returns true if CDMA provisioning needs to run. | 
|  | 3246 | */ | 
|  | 3247 | public boolean needsOtaServiceProvisioning() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3248 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3249 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3250 | return getDefaultPhone().needsOtaServiceProvisioning(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3251 | } finally { | 
|  | 3252 | Binder.restoreCallingIdentity(identity); | 
|  | 3253 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3254 | } | 
|  | 3255 |  | 
|  | 3256 | /** | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3257 | * Sets the voice mail number of a given subId. | 
|  | 3258 | */ | 
|  | 3259 | @Override | 
|  | 3260 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { | 
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3261 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
|  | 3262 | mApp, subId, "setVoiceMailNumber"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3263 |  | 
|  | 3264 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3265 | try { | 
|  | 3266 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, | 
|  | 3267 | new Pair<String, String>(alphaTag, number), new Integer(subId)); | 
|  | 3268 | return success; | 
|  | 3269 | } finally { | 
|  | 3270 | Binder.restoreCallingIdentity(identity); | 
|  | 3271 | } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3272 | } | 
|  | 3273 |  | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3274 | @Override | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3275 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { | 
|  | 3276 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3277 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); | 
|  | 3278 | String systemDialer = tm.getSystemDialerPackage(); | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3279 | if (!TextUtils.equals(callingPackage, systemDialer)) { | 
|  | 3280 | throw new SecurityException("caller must be system dialer"); | 
|  | 3281 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3282 |  | 
|  | 3283 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3284 | try { | 
|  | 3285 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); | 
|  | 3286 | if (phoneAccountHandle == null) { | 
|  | 3287 | return null; | 
|  | 3288 | } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3289 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3290 | } finally { | 
|  | 3291 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3292 | } | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3293 | } | 
|  | 3294 |  | 
|  | 3295 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3296 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, | 
|  | 3297 | int subId) { | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3298 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3299 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3300 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3301 | "getVisualVoicemailPackageName")) { | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3302 | return null; | 
|  | 3303 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3304 |  | 
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3305 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3306 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3307 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); | 
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3308 | } finally { | 
|  | 3309 | Binder.restoreCallingIdentity(identity); | 
|  | 3310 | } | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3311 | } | 
|  | 3312 |  | 
|  | 3313 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3314 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, | 
|  | 3315 | VisualVoicemailSmsFilterSettings settings) { | 
|  | 3316 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3317 |  | 
|  | 3318 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3319 | try { | 
|  | 3320 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3321 | mApp, callingPackage, subId, settings); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3322 | } finally { | 
|  | 3323 | Binder.restoreCallingIdentity(identity); | 
|  | 3324 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3325 | } | 
|  | 3326 |  | 
|  | 3327 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3328 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { | 
|  | 3329 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3330 |  | 
|  | 3331 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3332 | try { | 
|  | 3333 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3334 | mApp, callingPackage, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3335 | } finally { | 
|  | 3336 | Binder.restoreCallingIdentity(identity); | 
|  | 3337 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3338 | } | 
|  | 3339 |  | 
|  | 3340 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3341 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( | 
|  | 3342 | String callingPackage, int subId) { | 
|  | 3343 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3344 |  | 
|  | 3345 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3346 | try { | 
|  | 3347 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3348 | mApp, callingPackage, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3349 | } finally { | 
|  | 3350 | Binder.restoreCallingIdentity(identity); | 
|  | 3351 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3352 | } | 
|  | 3353 |  | 
|  | 3354 | @Override | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3355 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3356 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3357 |  | 
|  | 3358 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3359 | try { | 
|  | 3360 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3361 | mApp, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3362 | } finally { | 
|  | 3363 | Binder.restoreCallingIdentity(identity); | 
|  | 3364 | } | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3365 | } | 
|  | 3366 |  | 
|  | 3367 | @Override | 
| Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3368 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, | 
|  | 3369 | String callingAttributionTag, int subId, String number, int port, String text, | 
|  | 3370 | PendingIntent sentIntent) { | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3371 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3372 | enforceVisualVoicemailPackage(callingPackage, subId); | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3373 | enforceSendSmsPermission(); | 
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3374 | SmsController smsController = PhoneFactory.getSmsController(); | 
| Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3375 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, | 
|  | 3376 | subId, number, port, text, sentIntent); | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3377 | } | 
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3378 |  | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3379 | /** | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3380 | * Sets the voice activation state of a given subId. | 
|  | 3381 | */ | 
|  | 3382 | @Override | 
|  | 3383 | public void setVoiceActivationState(int subId, int activationState) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3384 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3385 | mApp, subId, "setVoiceActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3386 |  | 
|  | 3387 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3388 | try { | 
|  | 3389 | final Phone phone = getPhone(subId); | 
|  | 3390 | if (phone != null) { | 
|  | 3391 | phone.setVoiceActivationState(activationState); | 
|  | 3392 | } else { | 
|  | 3393 | loge("setVoiceActivationState fails with invalid subId: " + subId); | 
|  | 3394 | } | 
|  | 3395 | } finally { | 
|  | 3396 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3397 | } | 
|  | 3398 | } | 
|  | 3399 |  | 
|  | 3400 | /** | 
|  | 3401 | * Sets the data activation state of a given subId. | 
|  | 3402 | */ | 
|  | 3403 | @Override | 
|  | 3404 | public void setDataActivationState(int subId, int activationState) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3405 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3406 | mApp, subId, "setDataActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3407 |  | 
|  | 3408 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3409 | try { | 
|  | 3410 | final Phone phone = getPhone(subId); | 
|  | 3411 | if (phone != null) { | 
|  | 3412 | phone.setDataActivationState(activationState); | 
|  | 3413 | } else { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3414 | loge("setDataActivationState fails with invalid subId: " + subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3415 | } | 
|  | 3416 | } finally { | 
|  | 3417 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3418 | } | 
|  | 3419 | } | 
|  | 3420 |  | 
|  | 3421 | /** | 
|  | 3422 | * Returns the voice activation state of a given subId. | 
|  | 3423 | */ | 
|  | 3424 | @Override | 
|  | 3425 | public int getVoiceActivationState(int subId, String callingPackage) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3426 | enforceReadPrivilegedPermission("getVoiceActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3427 |  | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3428 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3429 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3430 | try { | 
|  | 3431 | if (phone != null) { | 
|  | 3432 | return phone.getVoiceActivationState(); | 
|  | 3433 | } else { | 
|  | 3434 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; | 
|  | 3435 | } | 
|  | 3436 | } finally { | 
|  | 3437 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3438 | } | 
|  | 3439 | } | 
|  | 3440 |  | 
|  | 3441 | /** | 
|  | 3442 | * Returns the data activation state of a given subId. | 
|  | 3443 | */ | 
|  | 3444 | @Override | 
|  | 3445 | public int getDataActivationState(int subId, String callingPackage) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3446 | enforceReadPrivilegedPermission("getDataActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3447 |  | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3448 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3449 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3450 | try { | 
|  | 3451 | if (phone != null) { | 
|  | 3452 | return phone.getDataActivationState(); | 
|  | 3453 | } else { | 
|  | 3454 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; | 
|  | 3455 | } | 
|  | 3456 | } finally { | 
|  | 3457 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3458 | } | 
|  | 3459 | } | 
|  | 3460 |  | 
|  | 3461 | /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3462 | * Returns the unread count of voicemails for a subId | 
|  | 3463 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3464 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3465 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, | 
|  | 3466 | String callingFeatureId) { | 
| Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3467 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3468 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3469 | "getVoiceMessageCountForSubscriber")) { | 
| Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3470 | return 0; | 
|  | 3471 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3472 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3473 | try { | 
|  | 3474 | final Phone phone = getPhone(subId); | 
|  | 3475 | if (phone != null) { | 
|  | 3476 | return phone.getVoiceMessageCount(); | 
|  | 3477 | } else { | 
|  | 3478 | return 0; | 
|  | 3479 | } | 
|  | 3480 | } finally { | 
|  | 3481 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3482 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3483 | } | 
|  | 3484 |  | 
|  | 3485 | /** | 
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3486 | * returns true, if the device is in a state where both voice and data | 
|  | 3487 | * are supported simultaneously. This can change based on location or network condition. | 
|  | 3488 | */ | 
|  | 3489 | @Override | 
|  | 3490 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3491 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3492 | try { | 
|  | 3493 | final Phone phone = getPhone(subId); | 
|  | 3494 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); | 
|  | 3495 | } finally { | 
|  | 3496 | Binder.restoreCallingIdentity(identity); | 
|  | 3497 | } | 
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3498 | } | 
|  | 3499 |  | 
|  | 3500 | /** | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3501 | * Send the dialer code if called from the current default dialer or the caller has | 
|  | 3502 | * carrier privilege. | 
|  | 3503 | * @param inputCode The dialer code to send | 
|  | 3504 | */ | 
|  | 3505 | @Override | 
|  | 3506 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3507 | final Phone defaultPhone = getDefaultPhone(); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3508 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3509 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); | 
|  | 3510 | String defaultDialer = tm.getDefaultDialerPackage(); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3511 | if (!TextUtils.equals(callingPackage, defaultDialer)) { | 
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3512 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3513 | getDefaultSubscription(), "sendDialerSpecialCode"); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3514 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3515 |  | 
|  | 3516 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3517 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3518 | defaultPhone.sendDialerSpecialCode(inputCode); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3519 | } finally { | 
|  | 3520 | Binder.restoreCallingIdentity(identity); | 
|  | 3521 | } | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3522 | } | 
|  | 3523 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3524 | @Override | 
|  | 3525 | public int getNetworkSelectionMode(int subId) { | 
| shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3526 | TelephonyPermissions | 
|  | 3527 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3528 | mApp, subId, "getNetworkSelectionMode"); | 
|  | 3529 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3530 | try { | 
|  | 3531 | if (!isActiveSubscription(subId)) { | 
|  | 3532 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; | 
|  | 3533 | } | 
|  | 3534 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); | 
|  | 3535 | } finally { | 
|  | 3536 | Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3537 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3538 | } | 
|  | 3539 |  | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3540 | @Override | 
| Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3541 | public boolean isInEmergencySmsMode() { | 
|  | 3542 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); | 
|  | 3543 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3544 | try { | 
|  | 3545 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 3546 | if (phone.isInEmergencySmsMode()) { | 
|  | 3547 | return true; | 
|  | 3548 | } | 
|  | 3549 | } | 
|  | 3550 | } finally { | 
|  | 3551 | Binder.restoreCallingIdentity(identity); | 
|  | 3552 | } | 
|  | 3553 | return false; | 
|  | 3554 | } | 
|  | 3555 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3556 | /** | 
|  | 3557 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3558 | * @param subId The subscription to use to check the configuration. | 
|  | 3559 | * @param c The callback that will be used to send the result. | 
|  | 3560 | */ | 
| Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3561 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3562 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) | 
|  | 3563 | throws RemoteException { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3564 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3565 | mApp, subId, "registerImsRegistrationCallback"); | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3566 |  | 
| Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3567 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 3568 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 3569 | "IMS not available on device."); | 
|  | 3570 | } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3571 | final long token = Binder.clearCallingIdentity(); | 
|  | 3572 | try { | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3573 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3574 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3575 | .addRegistrationCallbackForSubscription(c, subId); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3576 | } catch (ImsException e) { | 
|  | 3577 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3578 | } finally { | 
|  | 3579 | Binder.restoreCallingIdentity(token); | 
|  | 3580 | } | 
|  | 3581 | } | 
|  | 3582 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3583 | /** | 
|  | 3584 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3585 | * @param subId The subscription to use to check the configuration. | 
|  | 3586 | * @param c The callback that will be used to send the result. | 
|  | 3587 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3588 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3589 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3590 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3591 | mApp, subId, "unregisterImsRegistrationCallback"); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3592 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3593 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 3594 | } | 
| Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3595 | final long token = Binder.clearCallingIdentity(); | 
|  | 3596 | try { | 
|  | 3597 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. | 
|  | 3598 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
|  | 3599 | .removeRegistrationCallbackForSubscription(c, subId); | 
|  | 3600 | } catch (ImsException e) { | 
|  | 3601 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId | 
|  | 3602 | + "is inactive, ignoring unregister."); | 
|  | 3603 | // If the subscription is no longer active, just return, since the callback | 
|  | 3604 | // will already have been removed internally. | 
|  | 3605 | } finally { | 
|  | 3606 | Binder.restoreCallingIdentity(token); | 
|  | 3607 | } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3608 | } | 
|  | 3609 |  | 
| Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3610 | /** | 
|  | 3611 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. | 
|  | 3612 | */ | 
|  | 3613 | @Override | 
|  | 3614 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { | 
|  | 3615 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); | 
|  | 3616 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 3617 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 3618 | "IMS not available on device."); | 
|  | 3619 | } | 
|  | 3620 | final long token = Binder.clearCallingIdentity(); | 
|  | 3621 | try { | 
|  | 3622 | Phone phone = getPhone(subId); | 
|  | 3623 | if (phone == null) { | 
|  | 3624 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" | 
|  | 3625 | + subId + "'"); | 
|  | 3626 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
|  | 3627 | } | 
|  | 3628 | phone.getImsRegistrationState(regState -> { | 
|  | 3629 | try { | 
|  | 3630 | consumer.accept((regState == null) | 
|  | 3631 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); | 
|  | 3632 | } catch (RemoteException e) { | 
|  | 3633 | // Ignore if the remote process is no longer available to call back. | 
|  | 3634 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); | 
|  | 3635 | } | 
|  | 3636 | }); | 
|  | 3637 | } finally { | 
|  | 3638 | Binder.restoreCallingIdentity(token); | 
|  | 3639 | } | 
|  | 3640 | } | 
|  | 3641 |  | 
|  | 3642 | /** | 
|  | 3643 | * Get the transport type for the IMS service registration state. | 
|  | 3644 | */ | 
|  | 3645 | @Override | 
|  | 3646 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3647 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3648 | mApp, subId, "getImsMmTelRegistrationTransportType"); | 
| Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3649 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 3650 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 3651 | "IMS not available on device."); | 
|  | 3652 | } | 
|  | 3653 | final long token = Binder.clearCallingIdentity(); | 
|  | 3654 | try { | 
|  | 3655 | Phone phone = getPhone(subId); | 
|  | 3656 | if (phone == null) { | 
|  | 3657 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" | 
|  | 3658 | + subId + "'"); | 
|  | 3659 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
|  | 3660 | } | 
|  | 3661 | phone.getImsRegistrationTech(regTech -> { | 
|  | 3662 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager | 
|  | 3663 | int regTechConverted = (regTech == null) | 
|  | 3664 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; | 
|  | 3665 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( | 
|  | 3666 | regTechConverted); | 
|  | 3667 | try { | 
|  | 3668 | consumer.accept(regTechConverted); | 
|  | 3669 | } catch (RemoteException e) { | 
|  | 3670 | // Ignore if the remote process is no longer available to call back. | 
|  | 3671 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); | 
|  | 3672 | } | 
|  | 3673 | }); | 
|  | 3674 | } finally { | 
|  | 3675 | Binder.restoreCallingIdentity(token); | 
|  | 3676 | } | 
|  | 3677 | } | 
|  | 3678 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3679 | /** | 
|  | 3680 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3681 | * @param subId The subscription to use to check the configuration. | 
|  | 3682 | * @param c The callback that will be used to send the result. | 
|  | 3683 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3684 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3685 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) | 
|  | 3686 | throws RemoteException { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3687 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3688 | mApp, subId, "registerMmTelCapabilityCallback"); | 
| Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3689 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 3690 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 3691 | "IMS not available on device."); | 
|  | 3692 | } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3693 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 3694 | final long token = Binder.clearCallingIdentity(); | 
|  | 3695 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3696 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3697 | .addCapabilitiesCallbackForSubscription(c, subId); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3698 | } catch (ImsException e) { | 
|  | 3699 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3700 | } finally { | 
|  | 3701 | Binder.restoreCallingIdentity(token); | 
|  | 3702 | } | 
|  | 3703 | } | 
|  | 3704 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3705 | /** | 
|  | 3706 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3707 | * @param subId The subscription to use to check the configuration. | 
|  | 3708 | * @param c The callback that will be used to send the result. | 
|  | 3709 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3710 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3711 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3712 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3713 | mApp, subId, "unregisterMmTelCapabilityCallback"); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3714 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3715 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 3716 | } | 
| Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3717 |  | 
|  | 3718 | final long token = Binder.clearCallingIdentity(); | 
|  | 3719 | try { | 
|  | 3720 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. | 
|  | 3721 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3722 | .removeCapabilitiesCallbackForSubscription(c, subId); | 
| Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3723 | } catch (ImsException e) { | 
|  | 3724 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId | 
|  | 3725 | + "is inactive, ignoring unregister."); | 
|  | 3726 | // If the subscription is no longer active, just return, since the callback | 
|  | 3727 | // will already have been removed internally. | 
|  | 3728 | } finally { | 
|  | 3729 | Binder.restoreCallingIdentity(token); | 
|  | 3730 | } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3731 | } | 
|  | 3732 |  | 
|  | 3733 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3734 | public boolean isCapable(int subId, int capability, int regTech) { | 
|  | 3735 | enforceReadPrivilegedPermission("isCapable"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3736 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 3737 | final long token = Binder.clearCallingIdentity(); | 
|  | 3738 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3739 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3740 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3741 | } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3742 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); | 
|  | 3743 | return false; | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3744 | } catch (ImsException e) { | 
| Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3745 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); | 
|  | 3746 | return false; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3747 | } finally { | 
|  | 3748 | Binder.restoreCallingIdentity(token); | 
|  | 3749 | } | 
|  | 3750 | } | 
|  | 3751 |  | 
|  | 3752 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3753 | public boolean isAvailable(int subId, int capability, int regTech) { | 
|  | 3754 | enforceReadPrivilegedPermission("isAvailable"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3755 | final long token = Binder.clearCallingIdentity(); | 
|  | 3756 | try { | 
|  | 3757 | Phone phone = getPhone(subId); | 
|  | 3758 | if (phone == null) return false; | 
|  | 3759 | return phone.isImsCapabilityAvailable(capability, regTech); | 
| Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3760 | } catch (com.android.ims.ImsException e) { | 
|  | 3761 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); | 
|  | 3762 | return false; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3763 | } finally { | 
|  | 3764 | Binder.restoreCallingIdentity(token); | 
|  | 3765 | } | 
|  | 3766 | } | 
|  | 3767 |  | 
| Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3768 | /** | 
|  | 3769 | * Determines if the MmTel feature capability is supported by the carrier configuration for this | 
|  | 3770 | * subscription. | 
|  | 3771 | * @param subId The subscription to use to check the configuration. | 
|  | 3772 | * @param callback The callback that will be used to send the result. | 
|  | 3773 | * @param capability The MmTelFeature capability that will be used to send the result. | 
|  | 3774 | * @param transportType The transport type of the MmTelFeature capability. | 
|  | 3775 | */ | 
|  | 3776 | @Override | 
|  | 3777 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, | 
|  | 3778 | int transportType) { | 
|  | 3779 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); | 
|  | 3780 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 3781 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 3782 | "IMS not available on device."); | 
|  | 3783 | } | 
|  | 3784 | final long token = Binder.clearCallingIdentity(); | 
|  | 3785 | try { | 
|  | 3786 | int slotId = getSlotIndex(subId); | 
|  | 3787 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 3788 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" | 
|  | 3789 | + subId + "'"); | 
|  | 3790 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
|  | 3791 | } | 
|  | 3792 | ImsManager.getInstance(mApp, slotId).isSupported(capability, | 
|  | 3793 | transportType, aBoolean -> { | 
|  | 3794 | try { | 
|  | 3795 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); | 
|  | 3796 | } catch (RemoteException e) { | 
|  | 3797 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " | 
|  | 3798 | + "running. Ignore"); | 
|  | 3799 | } | 
|  | 3800 | }); | 
|  | 3801 | } finally { | 
|  | 3802 | Binder.restoreCallingIdentity(token); | 
|  | 3803 | } | 
|  | 3804 | } | 
|  | 3805 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3806 | /** | 
|  | 3807 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3808 | * @param subId The subscription to use to check the configuration. | 
|  | 3809 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3810 | @Override | 
|  | 3811 | public boolean isAdvancedCallingSettingEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3812 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3813 | mApp, subId, "isAdvancedCallingSettingEnabled"); | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3814 |  | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3815 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 3816 | final long token = Binder.clearCallingIdentity(); | 
|  | 3817 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3818 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3819 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3820 | } catch (ImsException e) { | 
|  | 3821 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3822 | } finally { | 
|  | 3823 | Binder.restoreCallingIdentity(token); | 
|  | 3824 | } | 
|  | 3825 | } | 
|  | 3826 |  | 
|  | 3827 | @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3828 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3829 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3830 | "setAdvancedCallingSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3831 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3832 | try { | 
|  | 3833 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3834 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3835 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3836 | } catch (ImsException e) { | 
|  | 3837 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3838 | } finally { | 
|  | 3839 | Binder.restoreCallingIdentity(identity); | 
|  | 3840 | } | 
|  | 3841 | } | 
|  | 3842 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3843 | /** | 
|  | 3844 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3845 | * @param subId The subscription to use to check the configuration. | 
|  | 3846 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3847 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3848 | public boolean isVtSettingEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3849 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3850 | mApp, subId, "isVtSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3851 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3852 | try { | 
|  | 3853 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3854 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); | 
|  | 3855 | } catch (ImsException e) { | 
|  | 3856 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3857 | } finally { | 
|  | 3858 | Binder.restoreCallingIdentity(identity); | 
|  | 3859 | } | 
|  | 3860 | } | 
|  | 3861 |  | 
|  | 3862 | @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3863 | public void setVtSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3864 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3865 | "setVtSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3866 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3867 | try { | 
|  | 3868 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3869 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3870 | } catch (ImsException e) { | 
|  | 3871 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3872 | } finally { | 
|  | 3873 | Binder.restoreCallingIdentity(identity); | 
|  | 3874 | } | 
|  | 3875 | } | 
|  | 3876 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3877 | /** | 
|  | 3878 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3879 | * @param subId The subscription to use to check the configuration. | 
|  | 3880 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3881 | @Override | 
|  | 3882 | public boolean isVoWiFiSettingEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3883 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3884 | mApp, subId, "isVoWiFiSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3885 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3886 | try { | 
|  | 3887 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3888 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3889 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3890 | } catch (ImsException e) { | 
|  | 3891 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3892 | } finally { | 
|  | 3893 | Binder.restoreCallingIdentity(identity); | 
|  | 3894 | } | 
|  | 3895 | } | 
|  | 3896 |  | 
|  | 3897 | @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3898 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3899 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3900 | "setVoWiFiSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3901 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3902 | try { | 
|  | 3903 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3904 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3905 | } catch (ImsException e) { | 
|  | 3906 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3907 | } finally { | 
|  | 3908 | Binder.restoreCallingIdentity(identity); | 
|  | 3909 | } | 
|  | 3910 | } | 
|  | 3911 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3912 | /** | 
|  | 3913 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3914 | * @param subId The subscription to use to check the configuration. | 
|  | 3915 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3916 | @Override | 
|  | 3917 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3918 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3919 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3920 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3921 | try { | 
|  | 3922 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3923 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3924 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3925 | } catch (ImsException e) { | 
|  | 3926 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3927 | } finally { | 
|  | 3928 | Binder.restoreCallingIdentity(identity); | 
|  | 3929 | } | 
|  | 3930 | } | 
|  | 3931 |  | 
|  | 3932 | @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3933 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3934 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3935 | "setVoWiFiRoamingSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3936 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3937 | try { | 
|  | 3938 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3939 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3940 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3941 | } catch (ImsException e) { | 
|  | 3942 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3943 | } finally { | 
|  | 3944 | Binder.restoreCallingIdentity(identity); | 
|  | 3945 | } | 
|  | 3946 | } | 
|  | 3947 |  | 
|  | 3948 | @Override | 
|  | 3949 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { | 
|  | 3950 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3951 | "setVoWiFiNonPersistent"); | 
|  | 3952 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3953 | try { | 
|  | 3954 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3955 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3956 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3957 | } catch (ImsException e) { | 
|  | 3958 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3959 | } finally { | 
|  | 3960 | Binder.restoreCallingIdentity(identity); | 
|  | 3961 | } | 
|  | 3962 | } | 
|  | 3963 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3964 | /** | 
|  | 3965 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 3966 | * @param subId The subscription to use to check the configuration. | 
|  | 3967 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3968 | @Override | 
|  | 3969 | public int getVoWiFiModeSetting(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3970 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 3971 | mApp, subId, "getVoWiFiModeSetting"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3972 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3973 | try { | 
|  | 3974 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3975 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3976 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3977 | } catch (ImsException e) { | 
|  | 3978 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3979 | } finally { | 
|  | 3980 | Binder.restoreCallingIdentity(identity); | 
|  | 3981 | } | 
|  | 3982 | } | 
|  | 3983 |  | 
|  | 3984 | @Override | 
|  | 3985 | public void setVoWiFiModeSetting(int subId, int mode) { | 
|  | 3986 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3987 | "setVoWiFiModeSetting"); | 
|  | 3988 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3989 | try { | 
|  | 3990 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3991 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3992 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3993 | } catch (ImsException e) { | 
|  | 3994 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3995 | } finally { | 
|  | 3996 | Binder.restoreCallingIdentity(identity); | 
|  | 3997 | } | 
|  | 3998 | } | 
|  | 3999 |  | 
|  | 4000 | @Override | 
|  | 4001 | public int getVoWiFiRoamingModeSetting(int subId) { | 
|  | 4002 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); | 
|  | 4003 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4004 | try { | 
|  | 4005 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4006 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4007 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4008 | } catch (ImsException e) { | 
|  | 4009 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4010 | } finally { | 
|  | 4011 | Binder.restoreCallingIdentity(identity); | 
|  | 4012 | } | 
|  | 4013 | } | 
|  | 4014 |  | 
|  | 4015 | @Override | 
|  | 4016 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { | 
|  | 4017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4018 | "setVoWiFiRoamingModeSetting"); | 
|  | 4019 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4020 | try { | 
|  | 4021 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4022 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4023 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4024 | } catch (ImsException e) { | 
|  | 4025 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4026 | } finally { | 
|  | 4027 | Binder.restoreCallingIdentity(identity); | 
|  | 4028 | } | 
|  | 4029 | } | 
|  | 4030 |  | 
|  | 4031 | @Override | 
|  | 4032 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { | 
|  | 4033 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4034 | "setRttCapabilityEnabled"); | 
|  | 4035 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4036 | try { | 
|  | 4037 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4038 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); | 
|  | 4039 | } catch (ImsException e) { | 
|  | 4040 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4041 | } finally { | 
|  | 4042 | Binder.restoreCallingIdentity(identity); | 
|  | 4043 | } | 
|  | 4044 | } | 
|  | 4045 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4046 | /** | 
|  | 4047 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4048 | * @param subId The subscription to use to check the configuration. | 
|  | 4049 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4050 | @Override | 
|  | 4051 | public boolean isTtyOverVolteEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4052 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 4053 | mApp, subId, "isTtyOverVolteEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4054 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4055 | try { | 
|  | 4056 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4057 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4058 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4059 | } catch (ImsException e) { | 
|  | 4060 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4061 | } finally { | 
|  | 4062 | Binder.restoreCallingIdentity(identity); | 
|  | 4063 | } | 
|  | 4064 | } | 
|  | 4065 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4066 | @Override | 
|  | 4067 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { | 
|  | 4068 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); | 
|  | 4069 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4070 | try { | 
| Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4071 | if (!isImsAvailableOnDevice()) { | 
|  | 4072 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 4073 | "IMS not available on device."); | 
| Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4074 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4075 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4076 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4077 | .addProvisioningCallbackForSubscription(callback, subId); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4078 | } catch (ImsException e) { | 
|  | 4079 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4080 | } finally { | 
|  | 4081 | Binder.restoreCallingIdentity(identity); | 
|  | 4082 | } | 
|  | 4083 | } | 
|  | 4084 |  | 
|  | 4085 | @Override | 
|  | 4086 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { | 
|  | 4087 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); | 
|  | 4088 | final long identity = Binder.clearCallingIdentity(); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4089 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4090 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 4091 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4092 | try { | 
|  | 4093 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4094 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4095 | .removeProvisioningCallbackForSubscription(callback, subId); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4096 | } catch (ImsException e) { | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4097 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId | 
|  | 4098 | + "is inactive, ignoring unregister."); | 
|  | 4099 | // If the subscription is no longer active, just return, since the callback will already | 
|  | 4100 | // have been removed internally. | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4101 | } finally { | 
|  | 4102 | Binder.restoreCallingIdentity(identity); | 
|  | 4103 | } | 
|  | 4104 | } | 
|  | 4105 |  | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4106 |  | 
|  | 4107 | private void checkModifyPhoneStatePermission(int subId, String message) { | 
|  | 4108 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4109 | message); | 
|  | 4110 | } | 
|  | 4111 |  | 
|  | 4112 | private boolean isImsProvisioningRequired(int subId, int capability, | 
|  | 4113 | boolean isMmtelCapability) { | 
|  | 4114 | Phone phone = getPhone(subId); | 
|  | 4115 | if (phone == null) { | 
|  | 4116 | loge("phone instance null for subid " + subId); | 
|  | 4117 | return false; | 
|  | 4118 | } | 
|  | 4119 | if (isMmtelCapability) { | 
|  | 4120 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { | 
|  | 4121 | return false; | 
|  | 4122 | } | 
|  | 4123 | } else { | 
|  | 4124 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { | 
|  | 4125 | return false; | 
|  | 4126 | } | 
|  | 4127 | } | 
|  | 4128 | return true; | 
|  | 4129 | } | 
|  | 4130 |  | 
|  | 4131 | @Override | 
|  | 4132 | public void setRcsProvisioningStatusForCapability(int subId, int capability, | 
|  | 4133 | boolean isProvisioned) { | 
|  | 4134 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); | 
|  | 4135 |  | 
|  | 4136 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4137 | try { | 
|  | 4138 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 4139 | if (!isImsProvisioningRequired(subId, capability, false)) { | 
|  | 4140 | return; | 
|  | 4141 | } | 
|  | 4142 |  | 
|  | 4143 | // this capability requires provisioning, route to the correct API. | 
|  | 4144 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
|  | 4145 | switch (capability) { | 
|  | 4146 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: | 
|  | 4147 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: | 
|  | 4148 | ims.setEabProvisioned(isProvisioned); | 
|  | 4149 | break; | 
|  | 4150 | default: { | 
|  | 4151 | throw new IllegalArgumentException("Tried to set provisioning for " | 
|  | 4152 | + "rcs capability '" + capability + "', which does not require " | 
|  | 4153 | + "provisioning."); | 
|  | 4154 | } | 
|  | 4155 | } | 
|  | 4156 | } finally { | 
|  | 4157 | Binder.restoreCallingIdentity(identity); | 
|  | 4158 | } | 
|  | 4159 |  | 
|  | 4160 | } | 
|  | 4161 |  | 
|  | 4162 |  | 
|  | 4163 | @Override | 
|  | 4164 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { | 
|  | 4165 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); | 
|  | 4166 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4167 | try { | 
|  | 4168 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 4169 | if (!isImsProvisioningRequired(subId, capability, false)) { | 
|  | 4170 | return true; | 
|  | 4171 | } | 
|  | 4172 |  | 
|  | 4173 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
|  | 4174 | switch (capability) { | 
|  | 4175 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: | 
|  | 4176 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: | 
|  | 4177 | return ims.isEabProvisionedOnDevice(); | 
|  | 4178 |  | 
|  | 4179 | default: { | 
|  | 4180 | throw new IllegalArgumentException("Tried to get rcs provisioning for " | 
|  | 4181 | + "capability '" + capability + "', which does not require " | 
|  | 4182 | + "provisioning."); | 
|  | 4183 | } | 
|  | 4184 | } | 
|  | 4185 |  | 
|  | 4186 | } finally { | 
|  | 4187 | Binder.restoreCallingIdentity(identity); | 
|  | 4188 | } | 
|  | 4189 | } | 
|  | 4190 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4191 | @Override | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4192 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, | 
|  | 4193 | boolean isProvisioned) { | 
|  | 4194 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 4195 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 4196 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 4197 | } | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4198 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4199 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4200 | try { | 
|  | 4201 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4202 | if (!isImsProvisioningRequired(subId, capability, true)) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4203 | return; | 
|  | 4204 | } | 
|  | 4205 |  | 
|  | 4206 | // this capability requires provisioning, route to the correct API. | 
|  | 4207 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
|  | 4208 | switch (capability) { | 
|  | 4209 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { | 
|  | 4210 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 4211 | ims.setVolteProvisioned(isProvisioned); | 
|  | 4212 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { | 
|  | 4213 | ims.setWfcProvisioned(isProvisioned); | 
|  | 4214 | } | 
|  | 4215 | break; | 
|  | 4216 | } | 
|  | 4217 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
|  | 4218 | // There is currently no difference in VT provisioning type. | 
|  | 4219 | ims.setVtProvisioned(isProvisioned); | 
|  | 4220 | break; | 
|  | 4221 | } | 
|  | 4222 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
|  | 4223 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so | 
|  | 4224 | // change the capability of the feature instead if needed. | 
|  | 4225 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) | 
|  | 4226 | == isProvisioned) { | 
|  | 4227 | // No change in provisioning. | 
|  | 4228 | return; | 
|  | 4229 | } | 
|  | 4230 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); | 
|  | 4231 | try { | 
|  | 4232 | ims.changeMmTelCapability(capability, tech, isProvisioned); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4233 | } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4234 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" | 
|  | 4235 | + ", Exception" + e.getMessage()); | 
|  | 4236 | } | 
|  | 4237 | break; | 
|  | 4238 | } | 
|  | 4239 | default: { | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4240 | throw new IllegalArgumentException("Tried to set provisioning for " | 
|  | 4241 | + "MmTel capability '" + capability + "', which does not require " | 
|  | 4242 | + "provisioning. "); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4243 | } | 
|  | 4244 | } | 
|  | 4245 |  | 
|  | 4246 | } finally { | 
|  | 4247 | Binder.restoreCallingIdentity(identity); | 
|  | 4248 | } | 
|  | 4249 | } | 
|  | 4250 |  | 
|  | 4251 | @Override | 
|  | 4252 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { | 
|  | 4253 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 4254 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 4255 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 4256 | } | 
|  | 4257 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); | 
|  | 4258 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4259 | try { | 
|  | 4260 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4261 | if (!isImsProvisioningRequired(subId, capability, true)) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4262 | return true; | 
|  | 4263 | } | 
|  | 4264 |  | 
|  | 4265 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
|  | 4266 | switch (capability) { | 
|  | 4267 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { | 
|  | 4268 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 4269 | return ims.isVolteProvisionedOnDevice(); | 
|  | 4270 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { | 
|  | 4271 | return ims.isWfcProvisionedOnDevice(); | 
|  | 4272 | } | 
|  | 4273 | // This should never happen, since we are checking tech above to make sure it | 
|  | 4274 | // is either LTE or IWLAN. | 
|  | 4275 | throw new IllegalArgumentException("Invalid radio technology for voice " | 
|  | 4276 | + "capability."); | 
|  | 4277 | } | 
|  | 4278 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
|  | 4279 | // There is currently no difference in VT provisioning type. | 
|  | 4280 | return ims.isVtProvisionedOnDevice(); | 
|  | 4281 | } | 
|  | 4282 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
|  | 4283 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. | 
|  | 4284 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); | 
|  | 4285 | } | 
|  | 4286 | default: { | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4287 | throw new IllegalArgumentException( | 
|  | 4288 | "Tried to get provisioning for MmTel capability '" + capability | 
|  | 4289 | + "', which does not require provisioning."); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4290 | } | 
|  | 4291 | } | 
|  | 4292 |  | 
|  | 4293 | } finally { | 
|  | 4294 | Binder.restoreCallingIdentity(identity); | 
|  | 4295 | } | 
|  | 4296 | } | 
|  | 4297 |  | 
|  | 4298 | @Override | 
|  | 4299 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { | 
|  | 4300 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 4301 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 4302 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 4303 | } | 
|  | 4304 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); | 
|  | 4305 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); | 
|  | 4306 | return (provisionedBits & capability) > 0; | 
|  | 4307 | } | 
|  | 4308 |  | 
|  | 4309 | @Override | 
|  | 4310 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, | 
|  | 4311 | boolean isProvisioned) { | 
|  | 4312 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 4313 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 4314 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 4315 | } | 
|  | 4316 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4317 | "setProvisioningStatusForCapability"); | 
|  | 4318 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); | 
|  | 4319 | // If the current provisioning status for capability already matches isProvisioned, | 
|  | 4320 | // do nothing. | 
|  | 4321 | if (((provisionedBits & capability) > 0) == isProvisioned) { | 
|  | 4322 | return; | 
|  | 4323 | } | 
|  | 4324 | if (isProvisioned) { | 
|  | 4325 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); | 
|  | 4326 | } else { | 
|  | 4327 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); | 
|  | 4328 | } | 
|  | 4329 | } | 
|  | 4330 |  | 
|  | 4331 | /** | 
|  | 4332 | * @return the bitfield containing the MmTel provisioning for the provided subscription and | 
|  | 4333 | * technology. The bitfield should mirror the bitfield defined by | 
|  | 4334 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. | 
|  | 4335 | */ | 
|  | 4336 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { | 
|  | 4337 | String key = getMmTelProvisioningKey(subId, tech); | 
|  | 4338 | // Default is no capabilities are provisioned. | 
|  | 4339 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); | 
|  | 4340 | } | 
|  | 4341 |  | 
|  | 4342 | /** | 
|  | 4343 | * Sets the MmTel capability provisioning bitfield (defined by | 
|  | 4344 | *     {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and | 
|  | 4345 | *     technology specified. | 
|  | 4346 | * | 
|  | 4347 | * Note: This is a synchronous command and should not be called on UI thread. | 
|  | 4348 | */ | 
|  | 4349 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { | 
|  | 4350 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); | 
|  | 4351 | String key = getMmTelProvisioningKey(subId, tech); | 
|  | 4352 | editor.putInt(key, newField); | 
|  | 4353 | editor.commit(); | 
|  | 4354 | } | 
|  | 4355 |  | 
|  | 4356 | private static String getMmTelProvisioningKey(int subId, int tech) { | 
|  | 4357 | // resulting key is provision_ims_mmtel_{subId}_{tech} | 
|  | 4358 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; | 
|  | 4359 | } | 
|  | 4360 |  | 
|  | 4361 | /** | 
|  | 4362 | * Query CarrierConfig to see if the specified capability requires provisioning for the | 
|  | 4363 | * carrier associated with the subscription id. | 
|  | 4364 | */ | 
|  | 4365 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, | 
|  | 4366 | int capability) { | 
|  | 4367 | CarrierConfigManager configManager = new CarrierConfigManager(context); | 
|  | 4368 | PersistableBundle c = configManager.getConfigForSubId(subId); | 
|  | 4369 | boolean requireUtProvisioning = c.getBoolean( | 
| Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4370 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4371 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, | 
|  | 4372 | false); | 
|  | 4373 | boolean requireVoiceVtProvisioning = c.getBoolean( | 
|  | 4374 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); | 
|  | 4375 |  | 
|  | 4376 | // First check to make sure that the capability requires provisioning. | 
|  | 4377 | switch (capability) { | 
|  | 4378 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: | 
|  | 4379 | // intentional fallthrough | 
|  | 4380 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
|  | 4381 | if (requireVoiceVtProvisioning) { | 
|  | 4382 | // Voice and Video requires provisioning | 
|  | 4383 | return true; | 
|  | 4384 | } | 
|  | 4385 | break; | 
|  | 4386 | } | 
|  | 4387 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
|  | 4388 | if (requireUtProvisioning) { | 
|  | 4389 | // UT requires provisioning | 
|  | 4390 | return true; | 
|  | 4391 | } | 
|  | 4392 | break; | 
|  | 4393 | } | 
|  | 4394 | } | 
|  | 4395 | return false; | 
|  | 4396 | } | 
|  | 4397 |  | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4398 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, | 
|  | 4399 | int capability) { | 
|  | 4400 | CarrierConfigManager configManager = new CarrierConfigManager(context); | 
|  | 4401 | PersistableBundle c = configManager.getConfigForSubId(subId); | 
|  | 4402 |  | 
|  | 4403 | boolean requireRcsProvisioning = c.getBoolean( | 
|  | 4404 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); | 
|  | 4405 |  | 
|  | 4406 | // First check to make sure that the capability requires provisioning. | 
|  | 4407 | switch (capability) { | 
|  | 4408 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: | 
|  | 4409 | // intentional fallthrough | 
|  | 4410 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { | 
|  | 4411 | if (requireRcsProvisioning) { | 
|  | 4412 | // OPTION or PRESENCE requires provisioning | 
|  | 4413 | return true; | 
|  | 4414 | } | 
|  | 4415 | break; | 
|  | 4416 | } | 
|  | 4417 | } | 
|  | 4418 | return false; | 
|  | 4419 | } | 
|  | 4420 |  | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4421 | @Override | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4422 | public int getImsProvisioningInt(int subId, int key) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4423 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4424 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 4425 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4426 | enforceReadPrivilegedPermission("getImsProvisioningInt"); | 
|  | 4427 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4428 | try { | 
|  | 4429 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4430 | int slotId = getSlotIndex(subId); | 
|  | 4431 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 4432 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" | 
|  | 4433 | + subId + "' for key:" + key); | 
|  | 4434 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; | 
|  | 4435 | } | 
|  | 4436 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4437 | } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4438 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" | 
|  | 4439 | + subId + "' for key:" + key); | 
|  | 4440 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4441 | } finally { | 
|  | 4442 | Binder.restoreCallingIdentity(identity); | 
|  | 4443 | } | 
|  | 4444 | } | 
|  | 4445 |  | 
|  | 4446 | @Override | 
|  | 4447 | public String getImsProvisioningString(int subId, int key) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4448 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4449 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 4450 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4451 | enforceReadPrivilegedPermission("getImsProvisioningString"); | 
|  | 4452 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4453 | try { | 
|  | 4454 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4455 | int slotId = getSlotIndex(subId); | 
|  | 4456 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 4457 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" | 
|  | 4458 | + subId + "' for key:" + key); | 
|  | 4459 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; | 
|  | 4460 | } | 
|  | 4461 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4462 | } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4463 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" | 
|  | 4464 | + subId + "' for key:" + key); | 
|  | 4465 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4466 | } finally { | 
|  | 4467 | Binder.restoreCallingIdentity(identity); | 
|  | 4468 | } | 
|  | 4469 | } | 
|  | 4470 |  | 
|  | 4471 | @Override | 
|  | 4472 | public int setImsProvisioningInt(int subId, int key, int value) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4473 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4474 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 4475 | } | 
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4476 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4477 | "setImsProvisioningInt"); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4478 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4479 | try { | 
|  | 4480 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4481 | int slotId = getSlotIndex(subId); | 
|  | 4482 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 4483 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" | 
|  | 4484 | + subId + "' for key:" + key); | 
|  | 4485 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
|  | 4486 | } | 
|  | 4487 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4488 | } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4489 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId | 
|  | 4490 | + "' for key:" + key); | 
|  | 4491 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4492 | } finally { | 
|  | 4493 | Binder.restoreCallingIdentity(identity); | 
|  | 4494 | } | 
|  | 4495 | } | 
|  | 4496 |  | 
|  | 4497 | @Override | 
|  | 4498 | public int setImsProvisioningString(int subId, int key, String value) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4499 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4500 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 4501 | } | 
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4503 | "setImsProvisioningString"); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4504 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4505 | try { | 
|  | 4506 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4507 | int slotId = getSlotIndex(subId); | 
|  | 4508 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 4509 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" | 
|  | 4510 | + subId + "' for key:" + key); | 
|  | 4511 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
|  | 4512 | } | 
|  | 4513 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4514 | } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4515 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId | 
|  | 4516 | + "' for key:" + key); | 
|  | 4517 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4518 | } finally { | 
|  | 4519 | Binder.restoreCallingIdentity(identity); | 
|  | 4520 | } | 
|  | 4521 | } | 
|  | 4522 |  | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4523 | private int getSlotIndexOrException(int subId) throws ImsException { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4524 | int slotId = SubscriptionManager.getSlotIndex(subId); | 
|  | 4525 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4526 | throw new ImsException("Invalid Subscription Id, subId=" + subId, | 
|  | 4527 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4528 | } | 
|  | 4529 | return slotId; | 
|  | 4530 | } | 
|  | 4531 |  | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4532 | private int getSlotIndex(int subId) { | 
|  | 4533 | int slotId = SubscriptionManager.getSlotIndex(subId); | 
|  | 4534 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { | 
|  | 4535 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; | 
|  | 4536 | } | 
|  | 4537 | return slotId; | 
|  | 4538 | } | 
|  | 4539 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4540 | /** | 
| Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4541 | * Returns the data network type for a subId; does not throw SecurityException. | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4542 | */ | 
|  | 4543 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4544 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, | 
|  | 4545 | String callingFeatureId) { | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4546 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); | 
| Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4547 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4548 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); | 
| Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4549 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q | 
| Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4550 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4551 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 4552 | "getNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4553 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 4554 | } | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4555 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4556 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4557 | try { | 
|  | 4558 | final Phone phone = getPhone(subId); | 
|  | 4559 | if (phone != null) { | 
|  | 4560 | return phone.getServiceState().getDataNetworkType(); | 
|  | 4561 | } else { | 
|  | 4562 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 4563 | } | 
|  | 4564 | } finally { | 
|  | 4565 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4566 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4567 | } | 
|  | 4568 |  | 
|  | 4569 | /** | 
|  | 4570 | * Returns the data network type | 
|  | 4571 | */ | 
|  | 4572 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4573 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { | 
|  | 4574 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 4575 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4576 | } | 
|  | 4577 |  | 
|  | 4578 | /** | 
|  | 4579 | * Returns the data network type for a subId | 
|  | 4580 | */ | 
|  | 4581 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4582 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, | 
|  | 4583 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4584 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4585 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 4586 | "getDataNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4587 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 4588 | } | 
|  | 4589 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4590 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4591 | try { | 
|  | 4592 | final Phone phone = getPhone(subId); | 
|  | 4593 | if (phone != null) { | 
|  | 4594 | return phone.getServiceState().getDataNetworkType(); | 
|  | 4595 | } else { | 
|  | 4596 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 4597 | } | 
|  | 4598 | } finally { | 
|  | 4599 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4600 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4601 | } | 
|  | 4602 |  | 
|  | 4603 | /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4604 | * Returns the Voice network type for a subId | 
|  | 4605 | */ | 
|  | 4606 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4607 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, | 
|  | 4608 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4609 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4610 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 4611 | "getDataNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4612 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 4613 | } | 
|  | 4614 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4615 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4616 | try { | 
|  | 4617 | final Phone phone = getPhone(subId); | 
|  | 4618 | if (phone != null) { | 
|  | 4619 | return phone.getServiceState().getVoiceNetworkType(); | 
|  | 4620 | } else { | 
|  | 4621 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 4622 | } | 
|  | 4623 | } finally { | 
|  | 4624 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4625 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4626 | } | 
|  | 4627 |  | 
|  | 4628 | /** | 
|  | 4629 | * @return true if a ICC card is present | 
|  | 4630 | */ | 
|  | 4631 | public boolean hasIccCard() { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4632 | // FIXME Make changes to pass defaultSimId of type int | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4633 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( | 
|  | 4634 | getDefaultSubscription())); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4635 | } | 
|  | 4636 |  | 
|  | 4637 | /** | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4638 | * @return true if a ICC card is present for a slotIndex | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4639 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4640 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4641 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4642 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4643 | try { | 
|  | 4644 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 4645 | if (phone != null) { | 
|  | 4646 | return phone.getIccCard().hasIccCard(); | 
|  | 4647 | } else { | 
|  | 4648 | return false; | 
|  | 4649 | } | 
|  | 4650 | } finally { | 
|  | 4651 | Binder.restoreCallingIdentity(identity); | 
| Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4652 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4653 | } | 
|  | 4654 |  | 
|  | 4655 | /** | 
|  | 4656 | * Return if the current radio is LTE on CDMA. This | 
|  | 4657 | * is a tri-state return value as for a period of time | 
|  | 4658 | * the mode may be unknown. | 
|  | 4659 | * | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4660 | * @param callingPackage the name of the package making the call. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4661 | * @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] | 4662 | * or {@link Phone#LTE_ON_CDMA_TRUE} | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4663 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4664 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4665 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { | 
|  | 4666 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 4667 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4668 | } | 
|  | 4669 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4670 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4671 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, | 
|  | 4672 | String callingFeatureId) { | 
| Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4673 | try { | 
|  | 4674 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); | 
|  | 4675 | } catch (SecurityException e) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4676 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
|  | 4677 | } | 
|  | 4678 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4679 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4680 | try { | 
|  | 4681 | final Phone phone = getPhone(subId); | 
|  | 4682 | if (phone == null) { | 
|  | 4683 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
|  | 4684 | } else { | 
| Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4685 | return TelephonyProperties.lte_on_cdma_device() | 
|  | 4686 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4687 | } | 
|  | 4688 | } finally { | 
|  | 4689 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4690 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4691 | } | 
|  | 4692 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4693 | /** | 
|  | 4694 | * {@hide} | 
|  | 4695 | * Returns Default subId, 0 in the case of single standby. | 
|  | 4696 | */ | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4697 | private int getDefaultSubscription() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4698 | return mSubscriptionController.getDefaultSubId(); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4699 | } | 
|  | 4700 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4701 | private int getSlotForDefaultSubscription() { | 
|  | 4702 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); | 
|  | 4703 | } | 
|  | 4704 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4705 | private int getPreferredVoiceSubscription() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4706 | return mSubscriptionController.getDefaultVoiceSubId(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4707 | } | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4708 |  | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4709 | private boolean isActiveSubscription(int subId) { | 
|  | 4710 | return mSubscriptionController.isActiveSubId(subId); | 
|  | 4711 | } | 
|  | 4712 |  | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4713 | /** | 
|  | 4714 | * @see android.telephony.TelephonyManager.WifiCallingChoices | 
|  | 4715 | */ | 
|  | 4716 | public int getWhenToMakeWifiCalls() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4717 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4718 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4719 | return Settings.System.getInt(mApp.getContentResolver(), | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4720 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, | 
|  | 4721 | getWhenToMakeWifiCallsDefaultPreference()); | 
|  | 4722 | } finally { | 
|  | 4723 | Binder.restoreCallingIdentity(identity); | 
|  | 4724 | } | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4725 | } | 
|  | 4726 |  | 
|  | 4727 | /** | 
|  | 4728 | * @see android.telephony.TelephonyManager.WifiCallingChoices | 
|  | 4729 | */ | 
|  | 4730 | public void setWhenToMakeWifiCalls(int preference) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4731 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4732 | try { | 
|  | 4733 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4734 | Settings.System.putInt(mApp.getContentResolver(), | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4735 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); | 
|  | 4736 | } finally { | 
|  | 4737 | Binder.restoreCallingIdentity(identity); | 
|  | 4738 | } | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4739 | } | 
|  | 4740 |  | 
| Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4741 | private static int getWhenToMakeWifiCallsDefaultPreference() { | 
| Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4742 | // TODO: Use a build property to choose this value. | 
| Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4743 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4744 | } | 
| Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4745 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4746 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { | 
|  | 4747 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); | 
|  | 4748 | if (phoneId == -1) { | 
|  | 4749 | throw new IllegalArgumentException("Given slot index: " + slotIndex | 
|  | 4750 | + " does not correspond to an active phone"); | 
|  | 4751 | } | 
|  | 4752 | return PhoneFactory.getPhone(phoneId); | 
|  | 4753 | } | 
|  | 4754 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4755 | @Override | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4756 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( | 
|  | 4757 | int subId, String callingPackage, String aid, int p2) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4758 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4759 | mApp, subId, "iccOpenLogicalChannel"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4760 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4761 | if (DBG) { | 
|  | 4762 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); | 
|  | 4763 | } | 
|  | 4764 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, | 
|  | 4765 | p2); | 
|  | 4766 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4767 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4768 |  | 
|  | 4769 | @Override | 
|  | 4770 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( | 
|  | 4771 | int slotIndex, String callingPackage, String aid, int p2) { | 
|  | 4772 | enforceModifyPermission(); | 
|  | 4773 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 4774 | if (DBG) { | 
|  | 4775 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); | 
|  | 4776 | } | 
|  | 4777 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), | 
|  | 4778 | callingPackage, aid, p2); | 
|  | 4779 | } | 
|  | 4780 |  | 
|  | 4781 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, | 
|  | 4782 | String callingPackage, String aid, int p2) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4783 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4784 | try { | 
|  | 4785 | if (TextUtils.equals(ISDR_AID, aid)) { | 
|  | 4786 | // Only allows LPA to open logical channel to ISD-R. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4787 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() | 
|  | 4788 | .getContext().getPackageManager()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4789 | if (bestComponent == null | 
|  | 4790 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { | 
|  | 4791 | loge("The calling package is not allowed to access ISD-R."); | 
|  | 4792 | throw new SecurityException( | 
|  | 4793 | "The calling package is not allowed to access ISD-R."); | 
|  | 4794 | } | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4795 | } | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4796 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4797 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4798 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, | 
|  | 4799 | null /* workSource */); | 
|  | 4800 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4801 | return response; | 
|  | 4802 | } finally { | 
|  | 4803 | Binder.restoreCallingIdentity(identity); | 
|  | 4804 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4805 | } | 
|  | 4806 |  | 
|  | 4807 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4808 | public boolean iccCloseLogicalChannel(int subId, int channel) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4809 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4810 | mApp, subId, "iccCloseLogicalChannel"); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4811 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); | 
|  | 4812 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); | 
|  | 4813 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4814 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4815 | @Override | 
|  | 4816 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { | 
|  | 4817 | enforceModifyPermission(); | 
|  | 4818 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); | 
|  | 4819 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), | 
|  | 4820 | channel); | 
|  | 4821 | } | 
|  | 4822 |  | 
|  | 4823 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4824 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4825 | try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4826 | if (channel < 0) { | 
|  | 4827 | return false; | 
|  | 4828 | } | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4829 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, | 
|  | 4830 | null /* workSource */); | 
|  | 4831 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4832 | return success; | 
|  | 4833 | } finally { | 
|  | 4834 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4835 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4836 | } | 
|  | 4837 |  | 
|  | 4838 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4839 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4840 | int command, int p1, int p2, int p3, String data) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4841 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4842 | mApp, subId, "iccTransmitApduLogicalChannel"); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4843 | if (DBG) { | 
|  | 4844 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel | 
|  | 4845 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" | 
|  | 4846 | + p3 + " data=" + data); | 
|  | 4847 | } | 
|  | 4848 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, | 
|  | 4849 | command, p1, p2, p3, data); | 
|  | 4850 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4851 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4852 | @Override | 
|  | 4853 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, | 
|  | 4854 | int command, int p1, int p2, int p3, String data) { | 
|  | 4855 | enforceModifyPermission(); | 
|  | 4856 | if (DBG) { | 
|  | 4857 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel | 
|  | 4858 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" | 
|  | 4859 | + p3 + " data=" + data); | 
|  | 4860 | } | 
|  | 4861 | return iccTransmitApduLogicalChannelWithPermission( | 
|  | 4862 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, | 
|  | 4863 | data); | 
|  | 4864 | } | 
|  | 4865 |  | 
|  | 4866 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, | 
|  | 4867 | int command, int p1, int p2, int p3, String data) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4868 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4869 | try { | 
| Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4870 | if (channel <= 0) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4871 | return ""; | 
|  | 4872 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4873 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4874 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4875 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, | 
|  | 4876 | null /* workSource */); | 
|  | 4877 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4878 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4879 | // Append the returned status code to the end of the response payload. | 
|  | 4880 | String s = Integer.toHexString( | 
|  | 4881 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 4882 | if (response.payload != null) { | 
|  | 4883 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 4884 | } | 
|  | 4885 | return s; | 
|  | 4886 | } finally { | 
|  | 4887 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4888 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4889 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4890 |  | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4891 | @Override | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4892 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, | 
|  | 4893 | int command, int p1, int p2, int p3, String data) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4894 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4895 | mApp, subId, "iccTransmitApduBasicChannel"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4896 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4897 | if (DBG) { | 
|  | 4898 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" | 
|  | 4899 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); | 
|  | 4900 | } | 
|  | 4901 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, | 
|  | 4902 | cla, command, p1, p2, p3, data); | 
|  | 4903 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4904 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4905 | @Override | 
|  | 4906 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, | 
|  | 4907 | int command, int p1, int p2, int p3, String data) { | 
|  | 4908 | enforceModifyPermission(); | 
|  | 4909 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 4910 | if (DBG) { | 
|  | 4911 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla | 
|  | 4912 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 | 
|  | 4913 | + " data=" + data); | 
|  | 4914 | } | 
|  | 4915 |  | 
|  | 4916 | return iccTransmitApduBasicChannelWithPermission( | 
|  | 4917 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, | 
|  | 4918 | p2, p3, data); | 
|  | 4919 | } | 
|  | 4920 |  | 
|  | 4921 | // open APDU basic channel assuming the caller has sufficient permissions | 
|  | 4922 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, | 
|  | 4923 | int cla, int command, int p1, int p2, int p3, String data) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4924 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4925 | try { | 
|  | 4926 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 | 
|  | 4927 | && TextUtils.equals(ISDR_AID, data)) { | 
|  | 4928 | // Only allows LPA to select ISD-R. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4929 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() | 
|  | 4930 | .getContext().getPackageManager()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4931 | if (bestComponent == null | 
|  | 4932 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { | 
|  | 4933 | loge("The calling package is not allowed to select ISD-R."); | 
|  | 4934 | throw new SecurityException( | 
|  | 4935 | "The calling package is not allowed to select ISD-R."); | 
|  | 4936 | } | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4937 | } | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4938 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4939 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4940 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, | 
|  | 4941 | null /* workSource */); | 
|  | 4942 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4943 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4944 | // Append the returned status code to the end of the response payload. | 
|  | 4945 | String s = Integer.toHexString( | 
|  | 4946 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 4947 | if (response.payload != null) { | 
|  | 4948 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 4949 | } | 
|  | 4950 | return s; | 
|  | 4951 | } finally { | 
|  | 4952 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4953 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4954 | } | 
|  | 4955 |  | 
|  | 4956 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4957 | 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] | 4958 | String filePath) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4959 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4960 | mApp, subId, "iccExchangeSimIO"); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4961 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4962 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4963 | try { | 
|  | 4964 | if (DBG) { | 
|  | 4965 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " | 
|  | 4966 | + p1 + " " + p2 + " " + p3 + ":" + filePath); | 
|  | 4967 | } | 
|  | 4968 |  | 
|  | 4969 | IccIoResult response = | 
|  | 4970 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, | 
|  | 4971 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), | 
|  | 4972 | subId); | 
|  | 4973 |  | 
|  | 4974 | if (DBG) { | 
|  | 4975 | log("Exchange SIM_IO [R]" + response); | 
|  | 4976 | } | 
|  | 4977 |  | 
|  | 4978 | byte[] result = null; | 
|  | 4979 | int length = 2; | 
|  | 4980 | if (response.payload != null) { | 
|  | 4981 | length = 2 + response.payload.length; | 
|  | 4982 | result = new byte[length]; | 
|  | 4983 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); | 
|  | 4984 | } else { | 
|  | 4985 | result = new byte[length]; | 
|  | 4986 | } | 
|  | 4987 |  | 
|  | 4988 | result[length - 1] = (byte) response.sw2; | 
|  | 4989 | result[length - 2] = (byte) response.sw1; | 
|  | 4990 | return result; | 
|  | 4991 | } finally { | 
|  | 4992 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4993 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4994 | } | 
|  | 4995 |  | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4996 | /** | 
|  | 4997 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) | 
|  | 4998 | * on a particular subscription | 
|  | 4999 | */ | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5000 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, | 
|  | 5001 | String callingFeatureId) { | 
| sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5002 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5003 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { | 
| sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5004 | return null; | 
|  | 5005 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5006 |  | 
|  | 5007 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5008 | try { | 
|  | 5009 | if (appType != TelephonyManager.APPTYPE_USIM | 
|  | 5010 | && appType != TelephonyManager.APPTYPE_SIM) { | 
|  | 5011 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); | 
|  | 5012 | return null; | 
|  | 5013 | } | 
|  | 5014 | Object response = sendRequest( | 
|  | 5015 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); | 
|  | 5016 | if (response instanceof String[]) { | 
|  | 5017 | return (String[]) response; | 
|  | 5018 | } | 
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5019 | // Response is an Exception of some kind | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5020 | // which is signalled to the user as a NULL retval | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5021 | return null; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5022 | } finally { | 
|  | 5023 | Binder.restoreCallingIdentity(identity); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5024 | } | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5025 | } | 
|  | 5026 |  | 
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5027 | /** | 
|  | 5028 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular | 
|  | 5029 | * subscription. | 
|  | 5030 | * | 
|  | 5031 | * @param subId the id of the subscription. | 
|  | 5032 | * @param appType the uicc app type, must be USIM or SIM. | 
|  | 5033 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. | 
|  | 5034 | * @param callingPackage the op Package name. | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5035 | * @param callingFeatureId the feature in the package. | 
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5036 | * @return number of fplmns that is successfully written to the SIM. | 
|  | 5037 | */ | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5038 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, | 
|  | 5039 | String callingFeatureId) { | 
|  | 5040 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, | 
|  | 5041 | callingFeatureId, "setForbiddenPlmns")) { | 
| yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5042 | if (DBG) logv("no permissions for setForbiddenplmns"); | 
|  | 5043 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); | 
|  | 5044 | } | 
|  | 5045 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { | 
|  | 5046 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); | 
|  | 5047 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); | 
|  | 5048 | } | 
|  | 5049 | if (fplmns == null) { | 
|  | 5050 | throw new IllegalArgumentException("Fplmn List provided is null"); | 
|  | 5051 | } | 
|  | 5052 | for (String fplmn : fplmns) { | 
|  | 5053 | if (!CellIdentity.isValidPlmn(fplmn)) { | 
|  | 5054 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); | 
|  | 5055 | } | 
|  | 5056 | } | 
|  | 5057 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5058 | try { | 
|  | 5059 | Object response = sendRequest( | 
|  | 5060 | CMD_SET_FORBIDDEN_PLMNS, | 
|  | 5061 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), | 
|  | 5062 | subId); | 
|  | 5063 | return (int) response; | 
|  | 5064 | } finally { | 
|  | 5065 | Binder.restoreCallingIdentity(identity); | 
|  | 5066 | } | 
|  | 5067 | } | 
|  | 5068 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5069 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5070 | public String sendEnvelopeWithStatus(int subId, String content) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5071 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5072 | mApp, subId, "sendEnvelopeWithStatus"); | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5073 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5074 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5075 | try { | 
|  | 5076 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); | 
|  | 5077 | if (response.payload == null) { | 
|  | 5078 | return ""; | 
|  | 5079 | } | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5080 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5081 | // Append the returned status code to the end of the response payload. | 
|  | 5082 | String s = Integer.toHexString( | 
|  | 5083 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 5084 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 5085 | return s; | 
|  | 5086 | } finally { | 
|  | 5087 | Binder.restoreCallingIdentity(identity); | 
|  | 5088 | } | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5089 | } | 
|  | 5090 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5091 | /** | 
|  | 5092 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
|  | 5093 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
|  | 5094 | * | 
|  | 5095 | * @param itemID the ID of the item to read | 
|  | 5096 | * @return the NV item as a String, or null on error. | 
|  | 5097 | */ | 
|  | 5098 | @Override | 
|  | 5099 | public String nvReadItem(int itemID) { | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5100 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5101 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5102 | mApp, getDefaultSubscription(), "nvReadItem"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5103 |  | 
|  | 5104 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5105 | try { | 
|  | 5106 | if (DBG) log("nvReadItem: item " + itemID); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5107 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5108 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); | 
|  | 5109 | return value; | 
|  | 5110 | } finally { | 
|  | 5111 | Binder.restoreCallingIdentity(identity); | 
|  | 5112 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5113 | } | 
|  | 5114 |  | 
|  | 5115 | /** | 
|  | 5116 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
|  | 5117 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
|  | 5118 | * | 
|  | 5119 | * @param itemID the ID of the item to read | 
|  | 5120 | * @param itemValue the value to write, as a String | 
|  | 5121 | * @return true on success; false on any failure | 
|  | 5122 | */ | 
|  | 5123 | @Override | 
|  | 5124 | public boolean nvWriteItem(int itemID, String itemValue) { | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5125 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5126 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5127 | mApp, getDefaultSubscription(), "nvWriteItem"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5128 |  | 
|  | 5129 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5130 | try { | 
|  | 5131 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); | 
|  | 5132 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5133 | new Pair<Integer, String>(itemID, itemValue), workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5134 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); | 
|  | 5135 | return success; | 
|  | 5136 | } finally { | 
|  | 5137 | Binder.restoreCallingIdentity(identity); | 
|  | 5138 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5139 | } | 
|  | 5140 |  | 
|  | 5141 | /** | 
|  | 5142 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. | 
|  | 5143 | * Used for device configuration by some CDMA operators. | 
|  | 5144 | * | 
|  | 5145 | * @param preferredRoamingList byte array containing the new PRL | 
|  | 5146 | * @return true on success; false on any failure | 
|  | 5147 | */ | 
|  | 5148 | @Override | 
|  | 5149 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5150 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5151 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5152 |  | 
|  | 5153 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5154 | try { | 
|  | 5155 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); | 
|  | 5156 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); | 
|  | 5157 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); | 
|  | 5158 | return success; | 
|  | 5159 | } finally { | 
|  | 5160 | Binder.restoreCallingIdentity(identity); | 
|  | 5161 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5162 | } | 
|  | 5163 |  | 
|  | 5164 | /** | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5165 | * 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] | 5166 | * Used for device configuration by some CDMA operators. | 
|  | 5167 | * | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5168 | * @param slotIndex - device slot. | 
|  | 5169 | * | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5170 | * @return true on success; false on any failure | 
|  | 5171 | */ | 
|  | 5172 | @Override | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5173 | public boolean resetModemConfig(int slotIndex) { | 
|  | 5174 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 5175 | if (phone != null) { | 
|  | 5176 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5177 | mApp, phone.getSubId(), "resetModemConfig"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5178 |  | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5179 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5180 | try { | 
|  | 5181 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); | 
|  | 5182 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); | 
|  | 5183 | return success; | 
|  | 5184 | } finally { | 
|  | 5185 | Binder.restoreCallingIdentity(identity); | 
|  | 5186 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5187 | } | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5188 | return false; | 
|  | 5189 | } | 
|  | 5190 |  | 
|  | 5191 | /** | 
|  | 5192 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. | 
|  | 5193 | * | 
|  | 5194 | * @param slotIndex - device slot. | 
|  | 5195 | * | 
|  | 5196 | * @return true on success; false on any failure | 
|  | 5197 | */ | 
|  | 5198 | @Override | 
|  | 5199 | public boolean rebootModem(int slotIndex) { | 
|  | 5200 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 5201 | if (phone != null) { | 
|  | 5202 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5203 | mApp, phone.getSubId(), "rebootModem"); | 
|  | 5204 |  | 
|  | 5205 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5206 | try { | 
|  | 5207 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); | 
|  | 5208 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); | 
|  | 5209 | return success; | 
|  | 5210 | } finally { | 
|  | 5211 | Binder.restoreCallingIdentity(identity); | 
|  | 5212 | } | 
|  | 5213 | } | 
|  | 5214 | return false; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5215 | } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5216 |  | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5217 | public String[] getPcscfAddress(String apnType, String callingPackage, | 
|  | 5218 | String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5219 | final Phone defaultPhone = getDefaultPhone(); | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5220 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), | 
|  | 5221 | callingPackage, callingFeatureId, "getPcscfAddress")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5222 | return new String[0]; | 
|  | 5223 | } | 
|  | 5224 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5225 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5226 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5227 | return defaultPhone.getPcscfAddress(apnType); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5228 | } finally { | 
|  | 5229 | Binder.restoreCallingIdentity(identity); | 
|  | 5230 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5231 | } | 
|  | 5232 |  | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5233 | /** | 
| Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5234 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and | 
|  | 5235 | * {@link #disableIms(int)}. | 
|  | 5236 | * @param slotIndex device slot. | 
|  | 5237 | */ | 
|  | 5238 | public void resetIms(int slotIndex) { | 
|  | 5239 | enforceModifyPermission(); | 
|  | 5240 |  | 
|  | 5241 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5242 | try { | 
|  | 5243 | if (mImsResolver == null) { | 
|  | 5244 | // may happen if the does not support IMS. | 
|  | 5245 | return; | 
|  | 5246 | } | 
|  | 5247 | mImsResolver.disableIms(slotIndex); | 
|  | 5248 | mImsResolver.enableIms(slotIndex); | 
|  | 5249 | } finally { | 
|  | 5250 | Binder.restoreCallingIdentity(identity); | 
|  | 5251 | } | 
|  | 5252 | } | 
|  | 5253 |  | 
|  | 5254 | /** | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5255 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability | 
|  | 5256 | * status updates, if not already enabled. | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5257 | */ | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5258 | public void enableIms(int slotId) { | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5259 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5260 |  | 
|  | 5261 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5262 | try { | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5263 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5264 | // may happen if the device does not support IMS. | 
|  | 5265 | return; | 
|  | 5266 | } | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5267 | mImsResolver.enableIms(slotId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5268 | } finally { | 
|  | 5269 | Binder.restoreCallingIdentity(identity); | 
|  | 5270 | } | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5271 | } | 
|  | 5272 |  | 
|  | 5273 | /** | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5274 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature | 
|  | 5275 | * status updates to disabled. | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5276 | */ | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5277 | public void disableIms(int slotId) { | 
|  | 5278 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5279 |  | 
|  | 5280 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5281 | try { | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5282 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5283 | // may happen if the device does not support IMS. | 
|  | 5284 | return; | 
|  | 5285 | } | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5286 | mImsResolver.disableIms(slotId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5287 | } finally { | 
|  | 5288 | Binder.restoreCallingIdentity(identity); | 
|  | 5289 | } | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5290 | } | 
|  | 5291 |  | 
|  | 5292 | /** | 
| Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5293 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback | 
|  | 5294 | * callback. | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5295 | */ | 
| Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5296 | @Override | 
| Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5297 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5298 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5299 |  | 
|  | 5300 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5301 | try { | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5302 | if (mImsResolver == null) { | 
| Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5303 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 5304 | "Device does not support IMS"); | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5305 | } | 
| Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5306 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5307 | } finally { | 
|  | 5308 | Binder.restoreCallingIdentity(identity); | 
|  | 5309 | } | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5310 | } | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5311 | /** | 
| Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5312 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. | 
|  | 5313 | */ | 
| Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5314 | @Override | 
|  | 5315 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { | 
| Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5316 | enforceModifyPermission(); | 
|  | 5317 |  | 
|  | 5318 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5319 | try { | 
|  | 5320 | if (mImsResolver == null) return; | 
| Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5321 | mImsResolver.unregisterImsFeatureCallback(callback); | 
| Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5322 | } finally { | 
|  | 5323 | Binder.restoreCallingIdentity(identity); | 
|  | 5324 | } | 
|  | 5325 | } | 
|  | 5326 |  | 
|  | 5327 | /** | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5328 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5329 | * specified or null if IMS is not supported on the slot specified. | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5330 | */ | 
|  | 5331 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { | 
|  | 5332 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5333 |  | 
|  | 5334 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5335 | try { | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5336 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5337 | // may happen if the device does not support IMS. | 
|  | 5338 | return null; | 
|  | 5339 | } | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5340 | return mImsResolver.getImsRegistration(slotId, feature); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5341 | } finally { | 
|  | 5342 | Binder.restoreCallingIdentity(identity); | 
|  | 5343 | } | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5344 | } | 
|  | 5345 |  | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5346 | /** | 
|  | 5347 | * Returns the {@link IImsConfig} structure associated with the slotId and feature | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5348 | * specified or null if IMS is not supported on the slot specified. | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5349 | */ | 
|  | 5350 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { | 
|  | 5351 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5352 |  | 
|  | 5353 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5354 | try { | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5355 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5356 | // may happen if the device does not support IMS. | 
|  | 5357 | return null; | 
|  | 5358 | } | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5359 | return mImsResolver.getImsConfig(slotId, feature); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5360 | } finally { | 
|  | 5361 | Binder.restoreCallingIdentity(identity); | 
|  | 5362 | } | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5363 | } | 
|  | 5364 |  | 
| Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5365 | /** | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5366 | * Sets the ImsService Package Name that Telephony will bind to. | 
|  | 5367 | * | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5368 | * @param slotIndex the slot ID that the ImsService should bind for. | 
|  | 5369 | * @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] | 5370 | *         ImsService is the device default ImsService. | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5371 | * @param featureTypes An integer array of feature types associated with a packageName. | 
|  | 5372 | * @param packageName The name of the package that the current configuration will be replaced | 
|  | 5373 | *                    with. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5374 | * @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] | 5375 | */ | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5376 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, | 
|  | 5377 | int[] featureTypes, String packageName) { | 
|  | 5378 | int[] subIds = SubscriptionManager.getSubId(slotIndex); | 
|  | 5379 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5380 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, | 
|  | 5381 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5382 | "setBoundImsServiceOverride"); | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5383 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5384 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5385 | try { | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5386 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5387 | // may happen if the device does not support IMS. | 
|  | 5388 | return false; | 
|  | 5389 | } | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5390 | Map<Integer, String> featureConfig = new HashMap<>(); | 
|  | 5391 | for (int featureType : featureTypes) { | 
|  | 5392 | featureConfig.put(featureType, packageName); | 
|  | 5393 | } | 
|  | 5394 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, | 
|  | 5395 | featureConfig); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5396 | } finally { | 
|  | 5397 | Binder.restoreCallingIdentity(identity); | 
|  | 5398 | } | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5399 | } | 
|  | 5400 |  | 
|  | 5401 | /** | 
| Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5402 | * Clears any carrier ImsService overrides for the slot index specified that were previously | 
|  | 5403 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. | 
|  | 5404 | * | 
|  | 5405 | * This should only be used for testing. | 
|  | 5406 | * | 
|  | 5407 | * @param slotIndex the slot ID that the ImsService should bind for. | 
|  | 5408 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. | 
|  | 5409 | */ | 
|  | 5410 | @Override | 
|  | 5411 | public boolean clearCarrierImsServiceOverride(int slotIndex) { | 
|  | 5412 | int[] subIds = SubscriptionManager.getSubId(slotIndex); | 
|  | 5413 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 5414 | "clearCarrierImsServiceOverride"); | 
|  | 5415 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, | 
|  | 5416 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), | 
|  | 5417 | "clearCarrierImsServiceOverride"); | 
|  | 5418 |  | 
|  | 5419 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5420 | try { | 
|  | 5421 | if (mImsResolver == null) { | 
|  | 5422 | // may happen if the device does not support IMS. | 
|  | 5423 | return false; | 
|  | 5424 | } | 
|  | 5425 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); | 
|  | 5426 | } finally { | 
|  | 5427 | Binder.restoreCallingIdentity(identity); | 
|  | 5428 | } | 
|  | 5429 | } | 
|  | 5430 |  | 
|  | 5431 | /** | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5432 | * Return the package name of the currently bound ImsService. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5433 | * | 
|  | 5434 | * @param slotId The slot that the ImsService is associated with. | 
|  | 5435 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is | 
|  | 5436 | *         the device default. | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5437 | * @param featureType The feature associated with the queried configuration. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5438 | * @return the package name of the ImsService configuration. | 
|  | 5439 | */ | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5440 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, | 
|  | 5441 | @ImsFeature.FeatureType int featureType) { | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5442 | int[] subIds = SubscriptionManager.getSubId(slotId); | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5443 | TelephonyPermissions | 
|  | 5444 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 5445 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), | 
|  | 5446 | "getBoundImsServicePackage"); | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5447 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 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 | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5451 | // may happen if the device does not support IMS. | 
|  | 5452 | return ""; | 
|  | 5453 | } | 
| Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5454 | // TODO: change API to query RCS separately. | 
| Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5455 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, | 
|  | 5456 | featureType); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5457 | } finally { | 
|  | 5458 | Binder.restoreCallingIdentity(identity); | 
|  | 5459 | } | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5460 | } | 
|  | 5461 |  | 
| Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5462 | /** | 
|  | 5463 | * Get the MmTelFeature state associated with the requested subscription id. | 
|  | 5464 | * @param subId The subscription that the MmTelFeature is associated with. | 
|  | 5465 | * @param callback A callback with an integer containing the | 
|  | 5466 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. | 
|  | 5467 | */ | 
|  | 5468 | @Override | 
|  | 5469 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { | 
|  | 5470 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); | 
|  | 5471 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 5472 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 5473 | "IMS not available on device."); | 
|  | 5474 | } | 
|  | 5475 | final long token = Binder.clearCallingIdentity(); | 
|  | 5476 | try { | 
|  | 5477 | int slotId = getSlotIndex(subId); | 
|  | 5478 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 5479 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" | 
|  | 5480 | + subId + "'"); | 
|  | 5481 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
|  | 5482 | } | 
|  | 5483 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { | 
|  | 5484 | try { | 
|  | 5485 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); | 
|  | 5486 | } catch (RemoteException e) { | 
|  | 5487 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " | 
|  | 5488 | + "Ignore"); | 
|  | 5489 | } | 
|  | 5490 | }); | 
|  | 5491 | } finally { | 
|  | 5492 | Binder.restoreCallingIdentity(token); | 
|  | 5493 | } | 
|  | 5494 | } | 
|  | 5495 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5496 | public void setImsRegistrationState(boolean registered) { | 
|  | 5497 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5498 |  | 
|  | 5499 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5500 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5501 | getDefaultPhone().setImsRegistrationState(registered); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5502 | } finally { | 
|  | 5503 | Binder.restoreCallingIdentity(identity); | 
|  | 5504 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5505 | } | 
|  | 5506 |  | 
|  | 5507 | /** | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5508 | * Set the network selection mode to automatic. | 
|  | 5509 | * | 
|  | 5510 | */ | 
|  | 5511 | @Override | 
|  | 5512 | public void setNetworkSelectionModeAutomatic(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5513 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5514 | mApp, subId, "setNetworkSelectionModeAutomatic"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5515 |  | 
|  | 5516 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5517 | try { | 
| shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5518 | if (!isActiveSubscription(subId)) { | 
|  | 5519 | return; | 
|  | 5520 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5521 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); | 
|  | 5522 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); | 
|  | 5523 | } finally { | 
|  | 5524 | Binder.restoreCallingIdentity(identity); | 
|  | 5525 | } | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5526 | } | 
|  | 5527 |  | 
| Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5528 | /** | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5529 | * Ask the radio to connect to the input network and change selection mode to manual. | 
|  | 5530 | * | 
|  | 5531 | * @param subId the id of the subscription. | 
|  | 5532 | * @param operatorInfo the operator information, included the PLMN, long name and short name of | 
|  | 5533 | * the operator to attach to. | 
|  | 5534 | * @param persistSelection whether the selection will persist until reboot. If true, only allows | 
|  | 5535 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume | 
|  | 5536 | * normal network selection next time. | 
|  | 5537 | * @return {@code true} on success; {@code true} on any failure. | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5538 | */ | 
|  | 5539 | @Override | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5540 | public boolean setNetworkSelectionModeManual( | 
|  | 5541 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5542 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5543 | mApp, subId, "setNetworkSelectionModeManual"); | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5544 |  | 
|  | 5545 | if (!isActiveSubscription(subId)) { | 
|  | 5546 | return false; | 
|  | 5547 | } | 
|  | 5548 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5549 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5550 | try { | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5551 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5552 | persistSelection); | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5553 | if (DBG) { | 
|  | 5554 | log("setNetworkSelectionModeManual: subId: " + subId | 
|  | 5555 | + " operator: " + operatorInfo); | 
|  | 5556 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5557 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); | 
|  | 5558 | } finally { | 
|  | 5559 | Binder.restoreCallingIdentity(identity); | 
|  | 5560 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5561 | } | 
| shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5562 | /** | 
|  | 5563 | * Get the manual network selection | 
|  | 5564 | * | 
|  | 5565 | * @param subId the id of the subscription. | 
|  | 5566 | * | 
|  | 5567 | * @return the previously saved user selected PLMN | 
|  | 5568 | */ | 
|  | 5569 | @Override | 
|  | 5570 | public String getManualNetworkSelectionPlmn(int subId) { | 
|  | 5571 | TelephonyPermissions | 
|  | 5572 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 5573 | mApp, subId, "getManualNetworkSelectionPlmn"); | 
|  | 5574 |  | 
|  | 5575 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5576 | try { | 
|  | 5577 | if (!isActiveSubscription(subId)) { | 
|  | 5578 | return ""; | 
|  | 5579 | } | 
|  | 5580 |  | 
|  | 5581 | final Phone phone = getPhone(subId); | 
|  | 5582 | if (phone == null) { | 
|  | 5583 | return ""; | 
|  | 5584 | } | 
|  | 5585 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); | 
|  | 5586 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) | 
|  | 5587 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); | 
|  | 5588 | } finally { | 
|  | 5589 | Binder.restoreCallingIdentity(identity); | 
|  | 5590 | } | 
|  | 5591 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5592 |  | 
|  | 5593 | /** | 
|  | 5594 | * Scans for available networks. | 
|  | 5595 | */ | 
|  | 5596 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5597 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, | 
|  | 5598 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5599 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5600 | mApp, subId, "getCellNetworkScanResults"); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5601 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 5602 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 5603 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 5604 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5605 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5606 | .setCallingPid(Binder.getCallingPid()) | 
|  | 5607 | .setCallingUid(Binder.getCallingUid()) | 
|  | 5608 | .setMethod("getCellNetworkScanResults") | 
|  | 5609 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 5610 | .build()); | 
|  | 5611 | switch (locationResult) { | 
|  | 5612 | case DENIED_HARD: | 
|  | 5613 | throw new SecurityException("Not allowed to access scan results -- location"); | 
|  | 5614 | case DENIED_SOFT: | 
|  | 5615 | return null; | 
|  | 5616 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5617 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5618 | long identity = Binder.clearCallingIdentity(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5619 | try { | 
|  | 5620 | if (DBG) log("getCellNetworkScanResults: subId " + subId); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5621 | return (CellNetworkScanResult) sendRequest( | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5622 | CMD_PERFORM_NETWORK_SCAN, null, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5623 | } finally { | 
|  | 5624 | Binder.restoreCallingIdentity(identity); | 
|  | 5625 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5626 | } | 
|  | 5627 |  | 
|  | 5628 | /** | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5629 | * Get the call forwarding info, given the call forwarding reason. | 
|  | 5630 | */ | 
|  | 5631 | @Override | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5632 | public void getCallForwarding(int subId, int callForwardingReason, | 
|  | 5633 | ICallForwardingInfoCallback callback) { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5634 | enforceReadPrivilegedPermission("getCallForwarding"); | 
|  | 5635 | long identity = Binder.clearCallingIdentity(); | 
|  | 5636 | try { | 
|  | 5637 | if (DBG) { | 
|  | 5638 | log("getCallForwarding: subId " + subId | 
|  | 5639 | + " callForwardingReason" + callForwardingReason); | 
|  | 5640 | } | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5641 |  | 
|  | 5642 | Phone phone = getPhone(subId); | 
|  | 5643 | if (phone == null) { | 
|  | 5644 | try { | 
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5645 | callback.onError( | 
|  | 5646 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5647 | } catch (RemoteException e) { | 
|  | 5648 | // ignore | 
|  | 5649 | } | 
|  | 5650 | return; | 
|  | 5651 | } | 
|  | 5652 |  | 
|  | 5653 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( | 
|  | 5654 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { | 
|  | 5655 | @Override | 
|  | 5656 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { | 
|  | 5657 | try { | 
|  | 5658 | callback.onCallForwardingInfoAvailable(info); | 
|  | 5659 | } catch (RemoteException e) { | 
|  | 5660 | // ignore | 
|  | 5661 | } | 
|  | 5662 | } | 
|  | 5663 |  | 
|  | 5664 | @Override | 
|  | 5665 | public void onError(int error) { | 
|  | 5666 | try { | 
|  | 5667 | callback.onError(error); | 
|  | 5668 | } catch (RemoteException e) { | 
|  | 5669 | // ignore | 
|  | 5670 | } | 
|  | 5671 | } | 
|  | 5672 | }); | 
|  | 5673 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5674 | } finally { | 
|  | 5675 | Binder.restoreCallingIdentity(identity); | 
|  | 5676 | } | 
|  | 5677 | } | 
|  | 5678 |  | 
|  | 5679 | /** | 
|  | 5680 | * Sets the voice call forwarding info including status (enable/disable), call forwarding | 
|  | 5681 | * reason, the number to forward, and the timeout before the forwarding is attempted. | 
|  | 5682 | */ | 
|  | 5683 | @Override | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5684 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, | 
|  | 5685 | IIntegerConsumer callback) { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5686 | enforceModifyPermission(); | 
|  | 5687 | long identity = Binder.clearCallingIdentity(); | 
|  | 5688 | try { | 
|  | 5689 | if (DBG) { | 
|  | 5690 | log("setCallForwarding: subId " + subId | 
|  | 5691 | + " callForwardingInfo" + callForwardingInfo); | 
|  | 5692 | } | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5693 |  | 
|  | 5694 | Phone phone = getPhone(subId); | 
|  | 5695 | if (phone == null) { | 
|  | 5696 | try { | 
| Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5697 | callback.accept( | 
|  | 5698 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5699 | } catch (RemoteException e) { | 
|  | 5700 | // ignore | 
|  | 5701 | } | 
|  | 5702 | return; | 
|  | 5703 | } | 
|  | 5704 |  | 
|  | 5705 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, | 
|  | 5706 | FunctionalUtils.ignoreRemoteException(callback::accept)); | 
|  | 5707 |  | 
|  | 5708 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5709 | } finally { | 
|  | 5710 | Binder.restoreCallingIdentity(identity); | 
|  | 5711 | } | 
|  | 5712 | } | 
|  | 5713 |  | 
|  | 5714 | /** | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5715 | * Get the call waiting status for a subId. | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5716 | */ | 
|  | 5717 | @Override | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5718 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5719 | enforceReadPrivilegedPermission("getCallForwarding"); | 
|  | 5720 | long identity = Binder.clearCallingIdentity(); | 
|  | 5721 | try { | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5722 |  | 
|  | 5723 | Phone phone = getPhone(subId); | 
|  | 5724 | if (phone == null) { | 
|  | 5725 | try { | 
|  | 5726 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); | 
|  | 5727 | } catch (RemoteException e) { | 
|  | 5728 | // ignore | 
|  | 5729 | } | 
|  | 5730 | return; | 
|  | 5731 | } | 
|  | 5732 |  | 
|  | 5733 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); | 
|  | 5734 |  | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5735 | if (DBG) log("getCallWaitingStatus: subId " + subId); | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5736 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5737 | } finally { | 
|  | 5738 | Binder.restoreCallingIdentity(identity); | 
|  | 5739 | } | 
|  | 5740 | } | 
|  | 5741 |  | 
|  | 5742 | /** | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5743 | * Sets whether call waiting is enabled for a given subId. | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5744 | */ | 
|  | 5745 | @Override | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5746 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5747 | enforceModifyPermission(); | 
|  | 5748 | long identity = Binder.clearCallingIdentity(); | 
|  | 5749 | try { | 
| Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5750 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); | 
|  | 5751 |  | 
|  | 5752 | Phone phone = getPhone(subId); | 
|  | 5753 | if (phone == null) { | 
|  | 5754 | try { | 
|  | 5755 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); | 
|  | 5756 | } catch (RemoteException e) { | 
|  | 5757 | // ignore | 
|  | 5758 | } | 
|  | 5759 | return; | 
|  | 5760 | } | 
|  | 5761 |  | 
|  | 5762 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, | 
|  | 5763 | FunctionalUtils.ignoreRemoteException(callback::accept)); | 
|  | 5764 |  | 
|  | 5765 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); | 
| sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5766 | } finally { | 
|  | 5767 | Binder.restoreCallingIdentity(identity); | 
|  | 5768 | } | 
|  | 5769 | } | 
|  | 5770 |  | 
|  | 5771 | /** | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5772 | * Starts a new network scan and returns the id of this scan. | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5773 | * | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5774 | * @param subId id of the subscription | 
|  | 5775 | * @param request contains the radio access networks with bands/channels to scan | 
|  | 5776 | * @param messenger callback messenger for scan results or errors | 
|  | 5777 | * @param binder for the purpose of auto clean when the user thread crashes | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5778 | * @return the id of the requested scan which can be used to stop the scan. | 
|  | 5779 | */ | 
|  | 5780 | @Override | 
|  | 5781 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5782 | IBinder binder, String callingPackage, String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5783 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5784 | mApp, subId, "requestNetworkScan"); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5785 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 5786 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 5787 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 5788 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5789 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5790 | .setCallingPid(Binder.getCallingPid()) | 
|  | 5791 | .setCallingUid(Binder.getCallingUid()) | 
|  | 5792 | .setMethod("requestNetworkScan") | 
|  | 5793 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 5794 | .build()); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5795 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { | 
| Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5796 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( | 
|  | 5797 | request, subId, callingPackage); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5798 | if (e != null) { | 
|  | 5799 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { | 
|  | 5800 | throw e; | 
|  | 5801 | } else { | 
| Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5802 | loge(e.getMessage()); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5803 | return TelephonyScanManager.INVALID_SCAN_ID; | 
|  | 5804 | } | 
|  | 5805 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5806 | } | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5807 | int callingUid = Binder.getCallingUid(); | 
|  | 5808 | int callingPid = Binder.getCallingPid(); | 
| Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5809 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5810 | try { | 
|  | 5811 | return mNetworkScanRequestTracker.startNetworkScan( | 
|  | 5812 | request, messenger, binder, getPhone(subId), | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5813 | callingUid, callingPid, callingPackage); | 
| Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5814 | } finally { | 
|  | 5815 | Binder.restoreCallingIdentity(identity); | 
|  | 5816 | } | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5817 | } | 
|  | 5818 |  | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5819 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( | 
| Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5820 | NetworkScanRequest request, int subId, String callingPackage) { | 
|  | 5821 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) | 
| Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5822 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; | 
|  | 5823 | boolean hasNetworkScanPermission = | 
|  | 5824 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) | 
|  | 5825 | == PERMISSION_GRANTED; | 
|  | 5826 |  | 
|  | 5827 | if (!hasCarrierPriv && !hasNetworkScanPermission) { | 
|  | 5828 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" | 
|  | 5829 | + " for network scans without location access."); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5830 | } | 
|  | 5831 |  | 
|  | 5832 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { | 
|  | 5833 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5834 | if (ras.getChannels() != null && ras.getChannels().length > 0) { | 
|  | 5835 | return new SecurityException("Specific channels must not be" | 
|  | 5836 | + " scanned without location access."); | 
|  | 5837 | } | 
|  | 5838 | } | 
|  | 5839 | } | 
|  | 5840 |  | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5841 | return null; | 
|  | 5842 | } | 
|  | 5843 |  | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5844 | /** | 
|  | 5845 | * Stops an existing network scan with the given scanId. | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5846 | * | 
|  | 5847 | * @param subId id of the subscription | 
|  | 5848 | * @param scanId id of the scan that needs to be stopped | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5849 | */ | 
|  | 5850 | @Override | 
|  | 5851 | public void stopNetworkScan(int subId, int scanId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5852 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5853 | mApp, subId, "stopNetworkScan"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5854 |  | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5855 | int callingUid = Binder.getCallingUid(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5856 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5857 | try { | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5858 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5859 | } finally { | 
|  | 5860 | Binder.restoreCallingIdentity(identity); | 
|  | 5861 | } | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5862 | } | 
|  | 5863 |  | 
|  | 5864 | /** | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5865 | * Get the calculated preferred network type. | 
|  | 5866 | * Used for debugging incorrect network type. | 
|  | 5867 | * | 
|  | 5868 | * @return the preferred network type, defined in RILConstants.java. | 
|  | 5869 | */ | 
|  | 5870 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5871 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5872 | final Phone defaultPhone = getDefaultPhone(); | 
|  | 5873 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5874 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5875 | return RILConstants.PREFERRED_NETWORK_MODE; | 
|  | 5876 | } | 
|  | 5877 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5878 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5879 | try { | 
|  | 5880 | // FIXME: need to get SubId from somewhere. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5881 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5882 | } finally { | 
|  | 5883 | Binder.restoreCallingIdentity(identity); | 
|  | 5884 | } | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5885 | } | 
|  | 5886 |  | 
|  | 5887 | /** | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5888 | * Get the preferred network type. | 
|  | 5889 | * Used for device configuration by some CDMA operators. | 
|  | 5890 | * | 
|  | 5891 | * @return the preferred network type, defined in RILConstants.java. | 
|  | 5892 | */ | 
|  | 5893 | @Override | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5894 | public int getPreferredNetworkType(int subId) { | 
| Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5895 | TelephonyPermissions | 
|  | 5896 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 5897 | mApp, subId, "getPreferredNetworkType"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5898 |  | 
|  | 5899 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5900 | try { | 
|  | 5901 | if (DBG) log("getPreferredNetworkType"); | 
|  | 5902 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); | 
|  | 5903 | int networkType = (result != null ? result[0] : -1); | 
|  | 5904 | if (DBG) log("getPreferredNetworkType: " + networkType); | 
|  | 5905 | return networkType; | 
|  | 5906 | } finally { | 
|  | 5907 | Binder.restoreCallingIdentity(identity); | 
|  | 5908 | } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5909 | } | 
|  | 5910 |  | 
|  | 5911 | /** | 
|  | 5912 | * Set the preferred network type. | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5913 | * | 
|  | 5914 | * @param networkType the preferred network type, defined in RILConstants.java. | 
|  | 5915 | * @return true on success; false on any failure. | 
|  | 5916 | */ | 
|  | 5917 | @Override | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5918 | public boolean setPreferredNetworkType(int subId, int networkType) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5919 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5920 | mApp, subId, "setPreferredNetworkType"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5921 |  | 
|  | 5922 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5923 | try { | 
| calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5924 | Boolean success = (Boolean) sendRequest( | 
|  | 5925 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); | 
| calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5926 |  | 
|  | 5927 | if (success) { | 
|  | 5928 | Settings.Global.putInt(mApp.getContentResolver(), | 
|  | 5929 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); | 
|  | 5930 | } | 
| calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5931 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); | 
|  | 5932 | return success; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5933 | } finally { | 
|  | 5934 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5935 | } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5936 | } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5937 |  | 
|  | 5938 | /** | 
| calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5939 | * Get the allowed network types that store in the telephony provider. | 
|  | 5940 | * | 
|  | 5941 | * @param subId the id of the subscription. | 
|  | 5942 | * @return allowedNetworkTypes the allowed network types. | 
|  | 5943 | */ | 
|  | 5944 | @Override | 
|  | 5945 | public long getAllowedNetworkTypes(int subId) { | 
|  | 5946 | TelephonyPermissions | 
|  | 5947 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 5948 | mApp, subId, "getAllowedNetworkTypes"); | 
|  | 5949 |  | 
|  | 5950 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5951 | try { | 
|  | 5952 | return SubscriptionManager.getLongSubscriptionProperty( | 
|  | 5953 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); | 
|  | 5954 | } finally { | 
|  | 5955 | Binder.restoreCallingIdentity(identity); | 
|  | 5956 | } | 
|  | 5957 | } | 
|  | 5958 |  | 
|  | 5959 | /** | 
|  | 5960 | * Set the allowed network types. | 
|  | 5961 | * | 
|  | 5962 | * @param subId the id of the subscription. | 
|  | 5963 | * @param allowedNetworkTypes the allowed network types. | 
|  | 5964 | * @return true on success; false on any failure. | 
|  | 5965 | */ | 
|  | 5966 | @Override | 
|  | 5967 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { | 
|  | 5968 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5969 | mApp, subId, "setAllowedNetworkTypes"); | 
| calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5970 |  | 
| calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5971 | SubscriptionManager.setSubscriptionProperty(subId, | 
|  | 5972 | SubscriptionManager.ALLOWED_NETWORK_TYPES, | 
|  | 5973 | String.valueOf(allowedNetworkTypes)); | 
| calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5974 |  | 
| calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5975 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), | 
|  | 5976 | Settings.Global.PREFERRED_NETWORK_MODE + subId, | 
|  | 5977 | RILConstants.PREFERRED_NETWORK_MODE); | 
|  | 5978 | return setPreferredNetworkType(subId, preferredNetworkMode); | 
| calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5979 | } | 
|  | 5980 |  | 
|  | 5981 | /** | 
| Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5982 | * Get the allowed network types for certain reason. | 
|  | 5983 | * | 
|  | 5984 | * @param subId the id of the subscription. | 
|  | 5985 | * @param reason the reason the allowed network type change is taking place | 
|  | 5986 | * @return the allowed network types. | 
|  | 5987 | */ | 
|  | 5988 | @Override | 
|  | 5989 | public long getAllowedNetworkTypesForReason(int subId, | 
|  | 5990 | @TelephonyManager.AllowedNetworkTypesReason int reason) { | 
|  | 5991 | TelephonyPermissions | 
|  | 5992 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 5993 | mApp, subId, "getAllowedNetworkTypesForReason"); | 
|  | 5994 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5995 | try { | 
|  | 5996 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); | 
|  | 5997 | } finally { | 
|  | 5998 | Binder.restoreCallingIdentity(identity); | 
|  | 5999 | } | 
|  | 6000 | } | 
|  | 6001 |  | 
|  | 6002 | /** | 
| Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6003 | * Enable/Disable E-UTRA-NR Dual Connectivity | 
|  | 6004 | * @param subId subscription id of the sim card | 
|  | 6005 | * @param nrDualConnectivityState expected NR dual connectivity state | 
|  | 6006 | * This can be passed following states | 
|  | 6007 | * <ol> | 
|  | 6008 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} | 
|  | 6009 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} | 
|  | 6010 | * <li>Disable NR dual connectivity and force secondary cell to be released | 
|  | 6011 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} | 
|  | 6012 | * </ol> | 
|  | 6013 | * @return operation result. | 
|  | 6014 | */ | 
|  | 6015 | @Override | 
|  | 6016 | public int setNrDualConnectivityState(int subId, | 
|  | 6017 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { | 
|  | 6018 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6019 | mApp, subId, "enableNRDualConnectivity"); | 
|  | 6020 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 6021 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6022 | try { | 
|  | 6023 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, | 
|  | 6024 | nrDualConnectivityState, subId, | 
|  | 6025 | workSource); | 
|  | 6026 | if (DBG) log("enableNRDualConnectivity result: " + result); | 
|  | 6027 | return result; | 
|  | 6028 | } finally { | 
|  | 6029 | Binder.restoreCallingIdentity(identity); | 
|  | 6030 | } | 
|  | 6031 | } | 
|  | 6032 |  | 
|  | 6033 | /** | 
|  | 6034 | * Is E-UTRA-NR Dual Connectivity enabled | 
|  | 6035 | * @return true if dual connectivity is enabled else false | 
|  | 6036 | */ | 
|  | 6037 | @Override | 
|  | 6038 | public boolean isNrDualConnectivityEnabled(int subId) { | 
|  | 6039 | TelephonyPermissions | 
|  | 6040 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 6041 | mApp, subId, "isNRDualConnectivityEnabled"); | 
|  | 6042 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 6043 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6044 | try { | 
|  | 6045 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, | 
|  | 6046 | null, subId, workSource); | 
|  | 6047 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); | 
|  | 6048 | return isEnabled; | 
|  | 6049 | } finally { | 
|  | 6050 | Binder.restoreCallingIdentity(identity); | 
|  | 6051 | } | 
|  | 6052 | } | 
|  | 6053 |  | 
|  | 6054 | /** | 
| Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6055 | * get carrier bandwidth per primary and secondary carrier | 
|  | 6056 | * @param subId subscription id of the sim card | 
|  | 6057 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. | 
|  | 6058 | */ | 
|  | 6059 | @Override | 
|  | 6060 | public CarrierBandwidth getCarrierBandwidth(int subId) { | 
|  | 6061 | TelephonyPermissions | 
|  | 6062 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 6063 | mApp, subId, "isNRDualConnectivityEnabled"); | 
|  | 6064 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 6065 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6066 | try { | 
|  | 6067 | CarrierBandwidth carrierBandwidth = | 
|  | 6068 | getPhoneFromSubId(subId).getCarrierBandwidth(); | 
|  | 6069 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); | 
|  | 6070 | return carrierBandwidth; | 
|  | 6071 | } finally { | 
|  | 6072 | Binder.restoreCallingIdentity(identity); | 
|  | 6073 | } | 
|  | 6074 | } | 
|  | 6075 |  | 
|  | 6076 | /** | 
| Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6077 | * Get the effective allowed network types on the device. | 
|  | 6078 | * This API will return an intersection of allowed network types for all reasons, | 
|  | 6079 | * including the configuration done through setAllowedNetworkTypes | 
|  | 6080 | * | 
|  | 6081 | * @param subId the id of the subscription. | 
|  | 6082 | * @return the allowed network types | 
|  | 6083 | */ | 
|  | 6084 | @Override | 
|  | 6085 | public long getEffectiveAllowedNetworkTypes(int subId) { | 
|  | 6086 | TelephonyPermissions | 
|  | 6087 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 6088 | mApp, subId, "getEffectiveAllowedNetworkTypes"); | 
|  | 6089 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6090 | try { | 
|  | 6091 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); | 
|  | 6092 | } finally { | 
|  | 6093 | Binder.restoreCallingIdentity(identity); | 
|  | 6094 | } | 
|  | 6095 | } | 
|  | 6096 |  | 
|  | 6097 | /** | 
|  | 6098 | * Set the allowed network types of the device and | 
|  | 6099 | * provide the reason triggering the allowed network change. | 
|  | 6100 | * | 
|  | 6101 | * @param subId the id of the subscription. | 
|  | 6102 | * @param reason the reason the allowed network type change is taking place | 
|  | 6103 | * @param allowedNetworkTypes the allowed network types. | 
|  | 6104 | * @return true on success; false on any failure. | 
|  | 6105 | */ | 
|  | 6106 | @Override | 
|  | 6107 | public boolean setAllowedNetworkTypesForReason(int subId, | 
|  | 6108 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { | 
|  | 6109 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6110 | mApp, subId, "setAllowedNetworkTypesForReason"); | 
|  | 6111 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6112 | try { | 
|  | 6113 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); | 
|  | 6114 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), | 
|  | 6115 | Settings.Global.PREFERRED_NETWORK_MODE + subId, | 
|  | 6116 | RILConstants.PREFERRED_NETWORK_MODE); | 
|  | 6117 | return setPreferredNetworkType(subId, preferredNetworkMode); | 
|  | 6118 | } finally { | 
|  | 6119 | Binder.restoreCallingIdentity(identity); | 
|  | 6120 | } | 
|  | 6121 | } | 
|  | 6122 |  | 
|  | 6123 | /** | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6124 | * Check whether DUN APN is required for tethering with subId. | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6125 | * | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6126 | * @param subId the id of the subscription to require tethering. | 
| Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6127 | * @return {@code true} if DUN APN is required for tethering. | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6128 | * @hide | 
|  | 6129 | */ | 
|  | 6130 | @Override | 
| SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6131 | public boolean isTetheringApnRequiredForSubscriber(int subId) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6132 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6133 | final long identity = Binder.clearCallingIdentity(); | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6134 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6135 | try { | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6136 | if (phone != null) { | 
|  | 6137 | return phone.hasMatchedTetherApnSetting(); | 
|  | 6138 | } else { | 
|  | 6139 | return false; | 
|  | 6140 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6141 | } finally { | 
|  | 6142 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6143 | } | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6144 | } | 
|  | 6145 |  | 
|  | 6146 | /** | 
| Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6147 | * Enable or disable always reporting signal strength changes from radio. | 
|  | 6148 | * | 
|  | 6149 | * @param isEnable {@code true} for enabling; {@code false} for disabling. | 
|  | 6150 | */ | 
|  | 6151 | @Override | 
|  | 6152 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { | 
|  | 6153 | enforceModifyPermission(); | 
|  | 6154 | enforceSystemCaller(); | 
|  | 6155 |  | 
|  | 6156 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6157 | final Phone phone = getPhone(subId); | 
|  | 6158 | try { | 
|  | 6159 | if (phone != null) { | 
|  | 6160 | if (DBG) { | 
|  | 6161 | log("setAlwaysReportSignalStrength: subId=" + subId | 
|  | 6162 | + " isEnable=" + isEnable); | 
|  | 6163 | } | 
|  | 6164 | phone.setAlwaysReportSignalStrength(isEnable); | 
|  | 6165 | } else { | 
|  | 6166 | loge("setAlwaysReportSignalStrength: no phone found for subId=" | 
|  | 6167 | + subId); | 
|  | 6168 | } | 
|  | 6169 | } finally { | 
|  | 6170 | Binder.restoreCallingIdentity(identity); | 
|  | 6171 | } | 
|  | 6172 | } | 
|  | 6173 |  | 
|  | 6174 | /** | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6175 | * Get the user enabled state of Mobile Data. | 
|  | 6176 | * | 
|  | 6177 | * TODO: remove and use isUserDataEnabled. | 
|  | 6178 | * This can't be removed now because some vendor codes | 
|  | 6179 | * calls through ITelephony directly while they should | 
|  | 6180 | * use TelephonyManager. | 
|  | 6181 | * | 
|  | 6182 | * @return true on enabled | 
|  | 6183 | */ | 
|  | 6184 | @Override | 
|  | 6185 | public boolean getDataEnabled(int subId) { | 
|  | 6186 | return isUserDataEnabled(subId); | 
|  | 6187 | } | 
|  | 6188 |  | 
|  | 6189 | /** | 
|  | 6190 | * Get whether mobile data is enabled per user setting. | 
|  | 6191 | * | 
|  | 6192 | * There are other factors deciding whether mobile data is actually enabled, but they are | 
|  | 6193 | * not considered here. See {@link #isDataEnabled(int)} for more details. | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6194 | * | 
| Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6195 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6196 | * | 
|  | 6197 | * @return {@code true} if data is enabled else {@code false} | 
|  | 6198 | */ | 
|  | 6199 | @Override | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6200 | public boolean isUserDataEnabled(int subId) { | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6201 | try { | 
|  | 6202 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 6203 | null); | 
|  | 6204 | } catch (Exception e) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6205 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6206 | mApp, subId, "isUserDataEnabled"); | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6207 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6208 |  | 
|  | 6209 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6210 | try { | 
|  | 6211 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 6212 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
|  | 6213 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 6214 | if (phone != null) { | 
|  | 6215 | boolean retVal = phone.isUserDataEnabled(); | 
|  | 6216 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); | 
|  | 6217 | return retVal; | 
|  | 6218 | } else { | 
|  | 6219 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); | 
|  | 6220 | return false; | 
|  | 6221 | } | 
|  | 6222 | } finally { | 
|  | 6223 | Binder.restoreCallingIdentity(identity); | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6224 | } | 
|  | 6225 | } | 
|  | 6226 |  | 
|  | 6227 | /** | 
| Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6228 | * Checks if the device is capable of mobile data by considering whether whether the | 
|  | 6229 | * user has enabled mobile data, whether the carrier has enabled mobile data, and | 
|  | 6230 | * whether the network policy allows data connections. | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6231 | * | 
| Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6232 | * @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] | 6233 | */ | 
|  | 6234 | @Override | 
|  | 6235 | public boolean isDataEnabled(int subId) { | 
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6236 | try { | 
|  | 6237 | try { | 
|  | 6238 | mApp.enforceCallingOrSelfPermission( | 
|  | 6239 | android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 6240 | null); | 
|  | 6241 | } catch (Exception e) { | 
|  | 6242 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, | 
|  | 6243 | "isDataEnabled"); | 
|  | 6244 | } | 
|  | 6245 | } catch (Exception e) { | 
|  | 6246 | enforceReadPrivilegedPermission("isDataEnabled"); | 
|  | 6247 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6248 |  | 
|  | 6249 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6250 | try { | 
|  | 6251 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 6252 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
|  | 6253 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 6254 | if (phone != null) { | 
| Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6255 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6256 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); | 
|  | 6257 | return retVal; | 
|  | 6258 | } else { | 
|  | 6259 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); | 
|  | 6260 | return false; | 
|  | 6261 | } | 
|  | 6262 | } finally { | 
|  | 6263 | Binder.restoreCallingIdentity(identity); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6264 | } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6265 | } | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6266 |  | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6267 | /** | 
|  | 6268 | * Check if data is enabled for a specific reason | 
|  | 6269 | * @param subId Subscription index | 
|  | 6270 | * @param reason the reason the data enable change is taking place | 
|  | 6271 | * @return {@code true} if the overall data is enabled; {@code false} if not. | 
|  | 6272 | */ | 
|  | 6273 | @Override | 
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6274 | public boolean isDataEnabledForReason(int subId, | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6275 | @TelephonyManager.DataEnabledReason int reason) { | 
|  | 6276 | try { | 
|  | 6277 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 6278 | null); | 
|  | 6279 | } catch (Exception e) { | 
|  | 6280 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, | 
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6281 | "isDataEnabledForReason"); | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6282 | } | 
|  | 6283 |  | 
|  | 6284 |  | 
|  | 6285 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6286 | try { | 
|  | 6287 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 6288 | if (DBG) { | 
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6289 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6290 | + " reason=" + reason); | 
|  | 6291 | } | 
|  | 6292 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 6293 | if (phone != null) { | 
|  | 6294 | boolean retVal; | 
|  | 6295 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { | 
|  | 6296 | retVal = phone.isUserDataEnabled(); | 
|  | 6297 | } else { | 
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6298 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6299 | } | 
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6300 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6301 | return retVal; | 
|  | 6302 | } else { | 
|  | 6303 | if (DBG) { | 
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6304 | loge("isDataEnabledForReason: no phone subId=" | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6305 | + subId + " retVal=false"); | 
|  | 6306 | } | 
|  | 6307 | return false; | 
|  | 6308 | } | 
|  | 6309 | } finally { | 
|  | 6310 | Binder.restoreCallingIdentity(identity); | 
|  | 6311 | } | 
|  | 6312 | } | 
|  | 6313 |  | 
| Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6314 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6315 | Phone phone) { | 
| Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6316 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { | 
|  | 6317 | // Skip the check if it's one of these special uids | 
|  | 6318 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; | 
|  | 6319 | } | 
|  | 6320 |  | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6321 | //load access rules from carrier configs, and check those as well: b/139133814 | 
|  | 6322 | SubscriptionController subController = SubscriptionController.getInstance(); | 
|  | 6323 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS | 
|  | 6324 | || subController == null) return privilegeFromSim; | 
|  | 6325 |  | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6326 | PackageManager pkgMgr = phone.getContext().getPackageManager(); | 
|  | 6327 | String[] packages = pkgMgr.getPackagesForUid(uid); | 
|  | 6328 |  | 
|  | 6329 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6330 | try { | 
| Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6331 | int subId = phone.getSubId(); | 
|  | 6332 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { | 
|  | 6333 | // A test override is in place for the privileges for this subId, so don't try to | 
|  | 6334 | // read the subscription privileges. | 
|  | 6335 | return privilegeFromSim; | 
|  | 6336 | } | 
|  | 6337 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6338 | SubscriptionManager subManager = (SubscriptionManager) | 
|  | 6339 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); | 
|  | 6340 | for (String pkg : packages) { | 
|  | 6341 | if (subManager.canManageSubscription(subInfo, pkg)) { | 
|  | 6342 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; | 
|  | 6343 | } | 
|  | 6344 | } | 
|  | 6345 | return privilegeFromSim; | 
|  | 6346 | } finally { | 
|  | 6347 | Binder.restoreCallingIdentity(identity); | 
|  | 6348 | } | 
|  | 6349 | } | 
|  | 6350 |  | 
|  | 6351 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, | 
|  | 6352 | String pkgName) { | 
|  | 6353 | //load access rules from carrier configs, and check those as well: b/139133814 | 
|  | 6354 | SubscriptionController subController = SubscriptionController.getInstance(); | 
|  | 6355 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS | 
|  | 6356 | || subController == null) return privilegeFromSim; | 
|  | 6357 |  | 
|  | 6358 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6359 | try { | 
| Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6360 | int subId = phone.getSubId(); | 
|  | 6361 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { | 
|  | 6362 | // A test override is in place for the privileges for this subId, so don't try to | 
|  | 6363 | // read the subscription privileges. | 
|  | 6364 | return privilegeFromSim; | 
|  | 6365 | } | 
|  | 6366 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6367 | SubscriptionManager subManager = (SubscriptionManager) | 
|  | 6368 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); | 
|  | 6369 | return subManager.canManageSubscription(subInfo, pkgName) | 
|  | 6370 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; | 
|  | 6371 | } finally { | 
|  | 6372 | Binder.restoreCallingIdentity(identity); | 
|  | 6373 | } | 
|  | 6374 | } | 
|  | 6375 |  | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6376 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6377 | public int getCarrierPrivilegeStatus(int subId) { | 
|  | 6378 | final Phone phone = getPhone(subId); | 
|  | 6379 | if (phone == null) { | 
|  | 6380 | loge("getCarrierPrivilegeStatus: Invalid subId"); | 
|  | 6381 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
|  | 6382 | } | 
|  | 6383 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6384 | if (card == null) { | 
| Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6385 | loge("getCarrierPrivilegeStatus: No UICC"); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6386 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 6387 | } | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6388 |  | 
|  | 6389 | return getCarrierPrivilegeStatusFromCarrierConfigRules( | 
|  | 6390 | card.getCarrierPrivilegeStatusForCurrentTransaction( | 
| Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6391 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6392 | } | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6393 |  | 
|  | 6394 | @Override | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6395 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { | 
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6396 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6397 | final Phone phone = getPhone(subId); | 
|  | 6398 | if (phone == null) { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6399 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6400 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
|  | 6401 | } | 
|  | 6402 | UiccProfile profile = | 
|  | 6403 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); | 
|  | 6404 | if (profile == null) { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6405 | loge("getCarrierPrivilegeStatusForUid: No UICC"); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6406 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 6407 | } | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6408 | return getCarrierPrivilegeStatusFromCarrierConfigRules( | 
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6409 | profile.getCarrierPrivilegeStatusForUid( | 
| Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6410 | phone.getContext().getPackageManager(), uid), uid, phone); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6411 | } | 
|  | 6412 |  | 
|  | 6413 | @Override | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6414 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { | 
|  | 6415 | if (TextUtils.isEmpty(pkgName)) { | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6416 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6417 | } | 
|  | 6418 |  | 
|  | 6419 | int phoneId = SubscriptionManager.getPhoneId(subId); | 
|  | 6420 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6421 | if (card == null) { | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6422 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6423 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 6424 | } | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6425 | return getCarrierPrivilegeStatusFromCarrierConfigRules( | 
|  | 6426 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), | 
|  | 6427 | getPhone(phoneId), pkgName); | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6428 | } | 
|  | 6429 |  | 
|  | 6430 | @Override | 
|  | 6431 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6432 | if (TextUtils.isEmpty(pkgName)) | 
|  | 6433 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6434 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 6435 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 6436 | UiccCard card = UiccController.getInstance().getUiccCard(i); | 
|  | 6437 | if (card == null) { | 
| Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6438 | // No UICC in that slot. | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6439 | continue; | 
|  | 6440 | } | 
|  | 6441 |  | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6442 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( | 
|  | 6443 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), | 
|  | 6444 | getPhone(i), pkgName); | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6445 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
|  | 6446 | break; | 
|  | 6447 | } | 
|  | 6448 | } | 
|  | 6449 |  | 
|  | 6450 | return result; | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6451 | } | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6452 |  | 
|  | 6453 | @Override | 
| Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6454 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { | 
|  | 6455 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { | 
|  | 6456 | loge("phoneId " + phoneId + " is not valid."); | 
|  | 6457 | return null; | 
|  | 6458 | } | 
|  | 6459 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6460 | if (card == null) { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6461 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6462 | return null ; | 
|  | 6463 | } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6464 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6465 | } | 
|  | 6466 |  | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6467 | @Override | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6468 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6469 | PackageManager pm = mApp.getPackageManager(); | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6470 | List<String> privilegedPackages = new ArrayList<>(); | 
|  | 6471 | List<PackageInfo> packages = null; | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6472 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); | 
|  | 6473 | // has UICC in that slot. | 
|  | 6474 | if (card != null) { | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6475 | if (card.hasCarrierPrivilegeRules()) { | 
|  | 6476 | if (packages == null) { | 
|  | 6477 | // Only check packages in user 0 for now | 
|  | 6478 | packages = pm.getInstalledPackagesAsUser( | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6479 | PackageManager.MATCH_DISABLED_COMPONENTS | 
|  | 6480 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS | 
| Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6481 | | PackageManager.GET_SIGNING_CERTIFICATES, | 
| Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6482 | UserHandle.SYSTEM.getIdentifier()); | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6483 | } | 
|  | 6484 | for (int p = packages.size() - 1; p >= 0; p--) { | 
|  | 6485 | PackageInfo pkgInfo = packages.get(p); | 
|  | 6486 | if (pkgInfo != null && pkgInfo.packageName != null | 
|  | 6487 | && card.getCarrierPrivilegeStatus(pkgInfo) | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6488 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6489 | privilegedPackages.add(pkgInfo.packageName); | 
|  | 6490 | } | 
|  | 6491 | } | 
|  | 6492 | } | 
|  | 6493 | } | 
|  | 6494 | return privilegedPackages; | 
|  | 6495 | } | 
|  | 6496 |  | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6497 | @Override | 
|  | 6498 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { | 
| Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6499 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); | 
|  | 6500 |  | 
|  | 6501 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6502 |  | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6503 | List<String> privilegedPackages = new ArrayList<>(); | 
| Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6504 | try { | 
|  | 6505 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 6506 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); | 
|  | 6507 | } | 
|  | 6508 | } finally { | 
|  | 6509 | Binder.restoreCallingIdentity(identity); | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6510 | } | 
|  | 6511 | return privilegedPackages; | 
|  | 6512 | } | 
|  | 6513 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6514 | private String getIccId(int subId) { | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6515 | final Phone phone = getPhone(subId); | 
|  | 6516 | UiccCard card = phone == null ? null : phone.getUiccCard(); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6517 | if (card == null) { | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6518 | return null; | 
|  | 6519 | } | 
|  | 6520 | String iccId = card.getIccId(); | 
|  | 6521 | if (TextUtils.isEmpty(iccId)) { | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6522 | return null; | 
|  | 6523 | } | 
|  | 6524 | return iccId; | 
|  | 6525 | } | 
|  | 6526 |  | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6527 | @Override | 
| Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6528 | public void setCallComposerStatus(int subId, int status) { | 
|  | 6529 | enforceModifyPermission(); | 
|  | 6530 |  | 
|  | 6531 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6532 | try { | 
|  | 6533 | Phone phone = getPhone(subId); | 
|  | 6534 | if (phone != null) { | 
|  | 6535 | Phone defaultPhone = phone.getImsPhone(); | 
|  | 6536 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { | 
|  | 6537 | ImsPhone imsPhone = (ImsPhone) defaultPhone; | 
|  | 6538 | imsPhone.setCallComposerStatus(status); | 
|  | 6539 | } | 
|  | 6540 | } | 
|  | 6541 | } finally { | 
|  | 6542 | Binder.restoreCallingIdentity(identity); | 
|  | 6543 | } | 
|  | 6544 | } | 
|  | 6545 |  | 
|  | 6546 | @Override | 
|  | 6547 | public int getCallComposerStatus(int subId) { | 
|  | 6548 | enforceReadPrivilegedPermission("getCallComposerStatus"); | 
|  | 6549 |  | 
|  | 6550 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6551 | try { | 
|  | 6552 | Phone phone = getPhone(subId); | 
|  | 6553 | if (phone != null) { | 
|  | 6554 | Phone defaultPhone = phone.getImsPhone(); | 
|  | 6555 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { | 
|  | 6556 | ImsPhone imsPhone = (ImsPhone) defaultPhone; | 
|  | 6557 | return imsPhone.getCallComposerStatus(); | 
|  | 6558 | } | 
|  | 6559 | } | 
|  | 6560 | } finally { | 
|  | 6561 | Binder.restoreCallingIdentity(identity); | 
|  | 6562 | } | 
|  | 6563 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; | 
|  | 6564 | } | 
|  | 6565 |  | 
|  | 6566 | @Override | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6567 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, | 
|  | 6568 | String number) { | 
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6569 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6570 | subId, "setLine1NumberForDisplayForSubscriber"); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6571 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6572 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6573 | try { | 
|  | 6574 | final String iccId = getIccId(subId); | 
|  | 6575 | final Phone phone = getPhone(subId); | 
|  | 6576 | if (phone == null) { | 
|  | 6577 | return false; | 
|  | 6578 | } | 
|  | 6579 | final String subscriberId = phone.getSubscriberId(); | 
|  | 6580 |  | 
|  | 6581 | if (DBG_MERGE) { | 
| Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6582 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6583 | + subscriberId + " to " + number); | 
|  | 6584 | } | 
|  | 6585 |  | 
|  | 6586 | if (TextUtils.isEmpty(iccId)) { | 
|  | 6587 | return false; | 
|  | 6588 | } | 
|  | 6589 |  | 
|  | 6590 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); | 
|  | 6591 |  | 
|  | 6592 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
|  | 6593 | if (alphaTag == null) { | 
|  | 6594 | editor.remove(alphaTagPrefKey); | 
|  | 6595 | } else { | 
|  | 6596 | editor.putString(alphaTagPrefKey, alphaTag); | 
|  | 6597 | } | 
|  | 6598 |  | 
|  | 6599 | // Record both the line number and IMSI for this ICCID, since we need to | 
|  | 6600 | // track all merged IMSIs based on line number | 
|  | 6601 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 6602 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
|  | 6603 | if (number == null) { | 
|  | 6604 | editor.remove(numberPrefKey); | 
|  | 6605 | editor.remove(subscriberPrefKey); | 
|  | 6606 | } else { | 
|  | 6607 | editor.putString(numberPrefKey, number); | 
|  | 6608 | editor.putString(subscriberPrefKey, subscriberId); | 
|  | 6609 | } | 
|  | 6610 |  | 
|  | 6611 | editor.commit(); | 
|  | 6612 | return true; | 
|  | 6613 | } finally { | 
|  | 6614 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6615 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6616 | } | 
|  | 6617 |  | 
|  | 6618 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6619 | public String getLine1NumberForDisplay(int subId, String callingPackage, | 
|  | 6620 | String callingFeatureId) { | 
| Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6621 | // This is open to apps with WRITE_SMS. | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6622 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6623 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6624 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6625 | return null; | 
|  | 6626 | } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6627 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6628 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6629 | try { | 
|  | 6630 | String iccId = getIccId(subId); | 
|  | 6631 | if (iccId != null) { | 
|  | 6632 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 6633 | if (DBG_MERGE) { | 
|  | 6634 | log("getLine1NumberForDisplay returning " | 
|  | 6635 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); | 
|  | 6636 | } | 
|  | 6637 | return mTelephonySharedPreferences.getString(numberPrefKey, null); | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6638 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6639 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); | 
|  | 6640 | return null; | 
|  | 6641 | } finally { | 
|  | 6642 | Binder.restoreCallingIdentity(identity); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6643 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6644 | } | 
|  | 6645 |  | 
|  | 6646 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6647 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, | 
|  | 6648 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6649 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6650 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6651 | return null; | 
|  | 6652 | } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6653 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6654 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6655 | try { | 
|  | 6656 | String iccId = getIccId(subId); | 
|  | 6657 | if (iccId != null) { | 
|  | 6658 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
|  | 6659 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); | 
|  | 6660 | } | 
|  | 6661 | return null; | 
|  | 6662 | } finally { | 
|  | 6663 | Binder.restoreCallingIdentity(identity); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6664 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6665 | } | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6666 |  | 
|  | 6667 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6668 | public String[] getMergedSubscriberIds(int subId, String callingPackage, | 
|  | 6669 | String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6670 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried | 
|  | 6671 | // about carrier-privileged callers not having access. | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6672 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6673 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6674 | callingFeatureId, "getMergedSubscriberIds")) { | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6675 | return null; | 
|  | 6676 | } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6677 |  | 
| Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6678 | // Clear calling identity, when calling TelephonyManager, because callerUid must be | 
|  | 6679 | // the process, where TelephonyManager was instantiated. | 
|  | 6680 | // Otherwise AppOps check will fail. | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6681 | final long identity  = Binder.clearCallingIdentity(); | 
|  | 6682 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6683 | final Context context = mApp; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6684 | final TelephonyManager tele = TelephonyManager.from(context); | 
|  | 6685 | final SubscriptionManager sub = SubscriptionManager.from(context); | 
|  | 6686 |  | 
|  | 6687 | // Figure out what subscribers are currently active | 
|  | 6688 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6689 |  | 
| Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6690 | // Only consider subs which match the current subId | 
|  | 6691 | // This logic can be simplified. See b/131189269 for progress. | 
|  | 6692 | if (isActiveSubscription(subId)) { | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6693 | activeSubscriberIds.add(tele.getSubscriberId(subId)); | 
|  | 6694 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6695 |  | 
|  | 6696 | // First pass, find a number override for an active subscriber | 
|  | 6697 | String mergeNumber = null; | 
|  | 6698 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); | 
|  | 6699 | for (String key : prefs.keySet()) { | 
|  | 6700 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { | 
|  | 6701 | final String subscriberId = (String) prefs.get(key); | 
|  | 6702 | if (activeSubscriberIds.contains(subscriberId)) { | 
|  | 6703 | final String iccId = key.substring( | 
|  | 6704 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); | 
|  | 6705 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 6706 | mergeNumber = (String) prefs.get(numberKey); | 
|  | 6707 | if (DBG_MERGE) { | 
| Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6708 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6709 | + " for active subscriber " + subscriberId); | 
|  | 6710 | } | 
|  | 6711 | if (!TextUtils.isEmpty(mergeNumber)) { | 
|  | 6712 | break; | 
|  | 6713 | } | 
|  | 6714 | } | 
|  | 6715 | } | 
|  | 6716 | } | 
|  | 6717 |  | 
|  | 6718 | // Shortcut when no active merged subscribers | 
|  | 6719 | if (TextUtils.isEmpty(mergeNumber)) { | 
|  | 6720 | return null; | 
|  | 6721 | } | 
|  | 6722 |  | 
|  | 6723 | // Second pass, find all subscribers under that line override | 
|  | 6724 | final ArraySet<String> result = new ArraySet<>(); | 
|  | 6725 | for (String key : prefs.keySet()) { | 
|  | 6726 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { | 
|  | 6727 | final String number = (String) prefs.get(key); | 
|  | 6728 | if (mergeNumber.equals(number)) { | 
|  | 6729 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); | 
|  | 6730 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
|  | 6731 | final String subscriberId = (String) prefs.get(subscriberKey); | 
|  | 6732 | if (!TextUtils.isEmpty(subscriberId)) { | 
|  | 6733 | result.add(subscriberId); | 
|  | 6734 | } | 
|  | 6735 | } | 
|  | 6736 | } | 
|  | 6737 | } | 
|  | 6738 |  | 
|  | 6739 | final String[] resultArray = result.toArray(new String[result.size()]); | 
|  | 6740 | Arrays.sort(resultArray); | 
|  | 6741 | if (DBG_MERGE) { | 
| Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6742 | Rlog.d(LOG_TAG, | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6743 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); | 
|  | 6744 | } | 
|  | 6745 | return resultArray; | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6746 | } finally { | 
|  | 6747 | Binder.restoreCallingIdentity(identity); | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6748 | } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6749 | } | 
|  | 6750 |  | 
|  | 6751 | @Override | 
| zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6752 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { | 
|  | 6753 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6754 |  | 
|  | 6755 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6756 | try { | 
|  | 6757 | final TelephonyManager telephonyManager = mApp.getSystemService( | 
|  | 6758 | TelephonyManager.class); | 
|  | 6759 | String subscriberId = telephonyManager.getSubscriberId(subId); | 
|  | 6760 | if (subscriberId == null) { | 
|  | 6761 | if (DBG) { | 
| zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6762 | log("getMergedImsisFromGroup can't find subscriberId for subId " | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6763 | + subId); | 
|  | 6764 | } | 
|  | 6765 | return null; | 
|  | 6766 | } | 
|  | 6767 |  | 
|  | 6768 | final SubscriptionInfo info = SubscriptionController.getInstance() | 
|  | 6769 | .getSubscriptionInfo(subId); | 
|  | 6770 | final ParcelUuid groupUuid = info.getGroupUuid(); | 
|  | 6771 | // If it doesn't belong to any group, return just subscriberId of itself. | 
|  | 6772 | if (groupUuid == null) { | 
|  | 6773 | return new String[]{subscriberId}; | 
|  | 6774 | } | 
|  | 6775 |  | 
|  | 6776 | // Get all subscriberIds from the group. | 
|  | 6777 | final List<String> mergedSubscriberIds = new ArrayList<>(); | 
|  | 6778 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6779 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), | 
| Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6780 | mApp.getAttributionTag()); | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6781 | for (SubscriptionInfo subInfo : groupInfos) { | 
|  | 6782 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); | 
|  | 6783 | if (subscriberId != null) { | 
|  | 6784 | mergedSubscriberIds.add(subscriberId); | 
|  | 6785 | } | 
|  | 6786 | } | 
|  | 6787 |  | 
|  | 6788 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); | 
|  | 6789 | } finally { | 
|  | 6790 | Binder.restoreCallingIdentity(identity); | 
|  | 6791 |  | 
|  | 6792 | } | 
|  | 6793 | } | 
|  | 6794 |  | 
|  | 6795 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6796 | public boolean setOperatorBrandOverride(int subId, String brand) { | 
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6797 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6798 | subId, "setOperatorBrandOverride"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6799 |  | 
|  | 6800 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6801 | try { | 
|  | 6802 | final Phone phone = getPhone(subId); | 
|  | 6803 | return phone == null ? false : phone.setOperatorBrandOverride(brand); | 
|  | 6804 | } finally { | 
|  | 6805 | Binder.restoreCallingIdentity(identity); | 
|  | 6806 | } | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6807 | } | 
| Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6808 |  | 
|  | 6809 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6810 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6811 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, | 
|  | 6812 | List<String> cdmaNonRoamingList) { | 
| Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6813 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
|  | 6814 | mApp, subId, "setRoamingOverride"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6815 |  | 
|  | 6816 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6817 | try { | 
|  | 6818 | final Phone phone = getPhone(subId); | 
|  | 6819 | if (phone == null) { | 
|  | 6820 | return false; | 
|  | 6821 | } | 
|  | 6822 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, | 
|  | 6823 | cdmaNonRoamingList); | 
|  | 6824 | } finally { | 
|  | 6825 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6826 | } | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6827 | } | 
|  | 6828 |  | 
|  | 6829 | @Override | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6830 | @Deprecated | 
|  | 6831 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { | 
|  | 6832 | enforceModifyPermission(); | 
|  | 6833 |  | 
|  | 6834 | int returnValue = 0; | 
|  | 6835 | try { | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6836 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6837 | if(result.exception == null) { | 
|  | 6838 | if (result.result != null) { | 
|  | 6839 | byte[] responseData = (byte[])(result.result); | 
|  | 6840 | if(responseData.length > oemResp.length) { | 
|  | 6841 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + | 
|  | 6842 | responseData.length +  "bytes. Buffer Size is " + | 
|  | 6843 | oemResp.length + "bytes."); | 
|  | 6844 | } | 
|  | 6845 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); | 
|  | 6846 | returnValue = responseData.length; | 
|  | 6847 | } | 
|  | 6848 | } else { | 
|  | 6849 | CommandException ex = (CommandException) result.exception; | 
|  | 6850 | returnValue = ex.getCommandError().ordinal(); | 
|  | 6851 | if(returnValue > 0) returnValue *= -1; | 
|  | 6852 | } | 
|  | 6853 | } catch (RuntimeException e) { | 
|  | 6854 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); | 
|  | 6855 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); | 
|  | 6856 | if(returnValue > 0) returnValue *= -1; | 
|  | 6857 | } | 
|  | 6858 |  | 
|  | 6859 | return returnValue; | 
|  | 6860 | } | 
|  | 6861 |  | 
|  | 6862 | @Override | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6863 | public void setRadioCapability(RadioAccessFamily[] rafs) { | 
|  | 6864 | try { | 
|  | 6865 | ProxyController.getInstance().setRadioCapability(rafs); | 
|  | 6866 | } catch (RuntimeException e) { | 
|  | 6867 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); | 
|  | 6868 | } | 
|  | 6869 | } | 
|  | 6870 |  | 
|  | 6871 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6872 | public int getRadioAccessFamily(int phoneId, String callingPackage) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6873 | Phone phone = PhoneFactory.getPhone(phoneId); | 
| Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6874 | try { | 
|  | 6875 | TelephonyPermissions | 
|  | 6876 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 6877 | mApp, phone.getSubId(), "getRadioAccessFamily"); | 
|  | 6878 | } catch (SecurityException e) { | 
|  | 6879 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); | 
|  | 6880 | throw e; | 
|  | 6881 | } | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6882 | int raf = RadioAccessFamily.RAF_UNKNOWN; | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6883 | if (phone == null) { | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6884 | return raf; | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6885 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6886 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6887 | try { | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6888 | TelephonyPermissions | 
|  | 6889 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 6890 | mApp, phone.getSubId(), "getRadioAccessFamily"); | 
|  | 6891 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6892 | } finally { | 
|  | 6893 | Binder.restoreCallingIdentity(identity); | 
|  | 6894 | } | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6895 | return raf; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6896 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6897 |  | 
|  | 6898 | @Override | 
|  | 6899 | public void enableVideoCalling(boolean enable) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6900 | final Phone defaultPhone = getDefaultPhone(); | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6901 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6902 |  | 
|  | 6903 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6904 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6905 | ImsManager.getInstance(defaultPhone.getContext(), | 
|  | 6906 | defaultPhone.getPhoneId()).setVtSetting(enable); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6907 | } finally { | 
|  | 6908 | Binder.restoreCallingIdentity(identity); | 
|  | 6909 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6910 | } | 
|  | 6911 |  | 
|  | 6912 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6913 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6914 | final Phone defaultPhone = getDefaultPhone(); | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6915 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), | 
|  | 6916 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { | 
| Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6917 | return false; | 
|  | 6918 | } | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6919 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6920 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6921 | try { | 
|  | 6922 | // Check the user preference and the  system-level IMS setting. Even if the user has | 
|  | 6923 | // enabled video calling, if IMS is disabled we aren't able to support video calling. | 
|  | 6924 | // In the long run, we may instead need to check if there exists a connection service | 
|  | 6925 | // which can support video calling. | 
|  | 6926 | ImsManager imsManager = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6927 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6928 | return imsManager.isVtEnabledByPlatform() | 
|  | 6929 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() | 
|  | 6930 | && imsManager.isVtEnabledByUser(); | 
|  | 6931 | } finally { | 
|  | 6932 | Binder.restoreCallingIdentity(identity); | 
|  | 6933 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6934 | } | 
| Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6935 |  | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6936 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6937 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, | 
|  | 6938 | String callingFeatureId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6939 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6940 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 6941 | "isVideoCallingEnabled")) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6942 | return false; | 
|  | 6943 | } | 
|  | 6944 |  | 
|  | 6945 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6946 | try { | 
|  | 6947 | CarrierConfigManager configManager = | 
|  | 6948 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6949 | return configManager.getConfigForSubId(subId) | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6950 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); | 
|  | 6951 | } finally { | 
|  | 6952 | Binder.restoreCallingIdentity(identity); | 
|  | 6953 | } | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6954 | } | 
|  | 6955 |  | 
|  | 6956 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6957 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6958 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6959 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6960 | return false; | 
|  | 6961 | } | 
|  | 6962 |  | 
|  | 6963 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6964 | try { | 
|  | 6965 | CarrierConfigManager configManager = | 
|  | 6966 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6967 | return configManager.getConfigForSubId(subId) | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6968 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); | 
|  | 6969 | } finally { | 
|  | 6970 | Binder.restoreCallingIdentity(identity); | 
|  | 6971 | } | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6972 | } | 
|  | 6973 |  | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6974 | @Override | 
|  | 6975 | public boolean isTtyModeSupported() { | 
| Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6976 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); | 
| Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6977 | return telecomManager.isTtySupported(); | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6978 | } | 
|  | 6979 |  | 
|  | 6980 | @Override | 
|  | 6981 | public boolean isHearingAidCompatibilitySupported() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6982 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6983 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6984 | return mApp.getResources().getBoolean(R.bool.hac_enabled); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6985 | } finally { | 
|  | 6986 | Binder.restoreCallingIdentity(identity); | 
|  | 6987 | } | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6988 | } | 
|  | 6989 |  | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6990 | /** | 
|  | 6991 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier | 
|  | 6992 | * support for the feature and device firmware support. | 
|  | 6993 | * | 
|  | 6994 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. | 
|  | 6995 | */ | 
|  | 6996 | @Override | 
|  | 6997 | public boolean isRttSupported(int subscriptionId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6998 | final long identity = Binder.clearCallingIdentity(); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6999 | final Phone phone = getPhone(subscriptionId); | 
|  | 7000 | if (phone == null) { | 
|  | 7001 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); | 
|  | 7002 | return false; | 
|  | 7003 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7004 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7005 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7006 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); | 
|  | 7007 | boolean isDeviceSupported = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7008 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7009 | return isCarrierSupported && isDeviceSupported; | 
|  | 7010 | } finally { | 
|  | 7011 | Binder.restoreCallingIdentity(identity); | 
|  | 7012 | } | 
| Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7013 | } | 
|  | 7014 |  | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7015 | /** | 
| Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7016 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set | 
|  | 7017 | * RTT setting, will return true if the device and carrier both support RTT. | 
|  | 7018 | * 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] | 7019 | */ | 
|  | 7020 | public boolean isRttEnabled(int subscriptionId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7021 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7022 | try { | 
| Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7023 | boolean isRttSupported = isRttSupported(subscriptionId); | 
|  | 7024 | boolean isUserRttSettingOn = Settings.Secure.getInt( | 
|  | 7025 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; | 
|  | 7026 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) | 
|  | 7027 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); | 
|  | 7028 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7029 | } finally { | 
|  | 7030 | Binder.restoreCallingIdentity(identity); | 
|  | 7031 | } | 
| Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7032 | } | 
|  | 7033 |  | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7034 | @Deprecated | 
|  | 7035 | @Override | 
|  | 7036 | public String getDeviceId(String callingPackage) { | 
|  | 7037 | return getDeviceIdWithFeature(callingPackage, null); | 
|  | 7038 | } | 
|  | 7039 |  | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7040 | /** | 
|  | 7041 | * Returns the unique device ID of phone, for example, the IMEI for | 
|  | 7042 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. | 
|  | 7043 | * | 
|  | 7044 | * <p>Requires Permission: | 
|  | 7045 | *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} | 
|  | 7046 | */ | 
|  | 7047 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7048 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7049 | final Phone phone = PhoneFactory.getPhone(0); | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7050 | if (phone == null) { | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7051 | return null; | 
|  | 7052 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7053 | int subId = phone.getSubId(); | 
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7054 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7055 | callingPackage, callingFeatureId, "getDeviceId")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7056 | return null; | 
|  | 7057 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7058 |  | 
|  | 7059 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7060 | try { | 
|  | 7061 | return phone.getDeviceId(); | 
|  | 7062 | } finally { | 
|  | 7063 | Binder.restoreCallingIdentity(identity); | 
|  | 7064 | } | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7065 | } | 
|  | 7066 |  | 
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7067 | /** | 
|  | 7068 | * {@hide} | 
|  | 7069 | * Returns the IMS Registration Status on a particular subid | 
|  | 7070 | * | 
|  | 7071 | * @param subId | 
|  | 7072 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7073 | public boolean isImsRegistered(int subId) { | 
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7074 | Phone phone = getPhone(subId); | 
|  | 7075 | if (phone != null) { | 
|  | 7076 | return phone.isImsRegistered(); | 
|  | 7077 | } else { | 
|  | 7078 | return false; | 
|  | 7079 | } | 
|  | 7080 | } | 
|  | 7081 |  | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7082 | @Override | 
|  | 7083 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7084 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7085 | try { | 
|  | 7086 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); | 
|  | 7087 | } finally { | 
|  | 7088 | Binder.restoreCallingIdentity(identity); | 
|  | 7089 | } | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7090 | } | 
| Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7091 |  | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7092 | @Override | 
| Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7093 | public int getSubIdForPhoneAccountHandle( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7094 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { | 
| Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7095 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7096 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { | 
| Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7097 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 7098 | } | 
|  | 7099 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7100 | try { | 
|  | 7101 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); | 
|  | 7102 | } finally { | 
|  | 7103 | Binder.restoreCallingIdentity(identity); | 
|  | 7104 | } | 
|  | 7105 | } | 
|  | 7106 |  | 
|  | 7107 | @Override | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7108 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { | 
| duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7109 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " | 
|  | 7110 | + "subscriptionId: " + subscriptionId); | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7111 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7112 | try { | 
|  | 7113 | Phone phone = getPhone(subscriptionId); | 
|  | 7114 | if (phone == null) { | 
|  | 7115 | return null; | 
|  | 7116 | } | 
|  | 7117 | return PhoneUtils.makePstnPhoneAccountHandle(phone); | 
|  | 7118 | } finally { | 
|  | 7119 | Binder.restoreCallingIdentity(identity); | 
|  | 7120 | } | 
|  | 7121 | } | 
|  | 7122 |  | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7123 | /** | 
|  | 7124 | * @return the VoWiFi calling availability. | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7125 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7126 | public boolean isWifiCallingAvailable(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7127 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7128 | try { | 
|  | 7129 | Phone phone = getPhone(subId); | 
|  | 7130 | if (phone != null) { | 
|  | 7131 | return phone.isWifiCallingEnabled(); | 
|  | 7132 | } else { | 
|  | 7133 | return false; | 
|  | 7134 | } | 
|  | 7135 | } finally { | 
|  | 7136 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7137 | } | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7138 | } | 
|  | 7139 |  | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7140 | /** | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7141 | * @return the VT calling availability. | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7142 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7143 | public boolean isVideoTelephonyAvailable(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7144 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7145 | try { | 
|  | 7146 | Phone phone = getPhone(subId); | 
|  | 7147 | if (phone != null) { | 
|  | 7148 | return phone.isVideoEnabled(); | 
|  | 7149 | } else { | 
|  | 7150 | return false; | 
|  | 7151 | } | 
|  | 7152 | } finally { | 
|  | 7153 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7154 | } | 
|  | 7155 | } | 
|  | 7156 |  | 
|  | 7157 | /** | 
|  | 7158 | * @return the IMS registration technology for the MMTEL feature. Valid return values are | 
|  | 7159 | * defined in {@link ImsRegistrationImplBase}. | 
|  | 7160 | */ | 
|  | 7161 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7162 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7163 | try { | 
|  | 7164 | Phone phone = getPhone(subId); | 
|  | 7165 | if (phone != null) { | 
|  | 7166 | return phone.getImsRegistrationTech(); | 
|  | 7167 | } else { | 
|  | 7168 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; | 
|  | 7169 | } | 
|  | 7170 | } finally { | 
|  | 7171 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7172 | } | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7173 | } | 
|  | 7174 |  | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7175 | @Override | 
|  | 7176 | public void factoryReset(int subId) { | 
| paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7177 | enforceSettingsPermission(); | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7178 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { | 
|  | 7179 | return; | 
|  | 7180 | } | 
|  | 7181 |  | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7182 | final long identity = Binder.clearCallingIdentity(); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7183 |  | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7184 | try { | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7185 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( | 
|  | 7186 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { | 
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7187 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7188 | getDefaultDataEnabled()); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7189 | setNetworkSelectionModeAutomatic(subId); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7190 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7191 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); | 
|  | 7192 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7193 | } | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7194 | // There has been issues when Sms raw table somehow stores orphan | 
|  | 7195 | // fragments. They lead to garbled message when new fragments come | 
|  | 7196 | // in and combined with those stale ones. In case this happens again, | 
|  | 7197 | // user can reset all network settings which will clean up this table. | 
|  | 7198 | cleanUpSmsRawTable(getDefaultPhone().getContext()); | 
| Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7199 | // Clean up IMS settings as well here. | 
|  | 7200 | int slotId = getSlotIndex(subId); | 
|  | 7201 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 7202 | ImsManager.getInstance(mApp, slotId).factoryReset(); | 
|  | 7203 | } | 
| Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7204 |  | 
|  | 7205 | // Erase modem config if erase modem on network setting is enabled. | 
|  | 7206 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, | 
|  | 7207 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); | 
|  | 7208 | if (configValue != null && Boolean.parseBoolean(configValue)) { | 
|  | 7209 | sendEraseModemConfig(getDefaultPhone()); | 
|  | 7210 | } | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7211 | } finally { | 
|  | 7212 | Binder.restoreCallingIdentity(identity); | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7213 | } | 
|  | 7214 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7215 |  | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7216 | private void cleanUpSmsRawTable(Context context) { | 
|  | 7217 | ContentResolver resolver = context.getContentResolver(); | 
|  | 7218 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); | 
|  | 7219 | resolver.delete(uri, null, null); | 
|  | 7220 | } | 
|  | 7221 |  | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7222 | @Override | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7223 | public String getSimLocaleForSubscriber(int subId) { | 
|  | 7224 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); | 
|  | 7225 | final Phone phone = getPhone(subId); | 
|  | 7226 | if (phone == null) { | 
|  | 7227 | log("getSimLocaleForSubscriber, invalid subId"); | 
| chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7228 | return null; | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7229 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7230 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7231 | try { | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7232 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, | 
| Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7233 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); | 
| chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7234 | if (info == null) { | 
|  | 7235 | log("getSimLocaleForSubscriber, inactive subId: " + subId); | 
|  | 7236 | return null; | 
|  | 7237 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7238 | // Try and fetch the locale from the carrier properties or from the SIM language | 
|  | 7239 | // preferences (EF-PL and EF-LI)... | 
|  | 7240 | final int mcc = info.getMcc(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7241 | String simLanguage = null; | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7242 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); | 
|  | 7243 | if (localeFromDefaultSim != null) { | 
|  | 7244 | if (!localeFromDefaultSim.getCountry().isEmpty()) { | 
|  | 7245 | if (DBG) log("Using locale from subId: " + subId + " locale: " | 
|  | 7246 | + localeFromDefaultSim); | 
|  | 7247 | return localeFromDefaultSim.toLanguageTag(); | 
|  | 7248 | } else { | 
|  | 7249 | simLanguage = localeFromDefaultSim.getLanguage(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7250 | } | 
|  | 7251 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7252 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7253 | // The SIM language preferences only store a language (e.g. fr = French), not an | 
|  | 7254 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from | 
|  | 7255 | // the SIM and carrier preferences does not include a country we add the country | 
|  | 7256 | // determined from the SIM MCC to provide an exact locale. | 
| zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7257 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7258 | if (mccLocale != null) { | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7259 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7260 | return mccLocale.toLanguageTag(); | 
|  | 7261 | } | 
|  | 7262 |  | 
|  | 7263 | if (DBG) log("No locale found - returning null"); | 
|  | 7264 | return null; | 
|  | 7265 | } finally { | 
|  | 7266 | Binder.restoreCallingIdentity(identity); | 
|  | 7267 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7268 | } | 
|  | 7269 |  | 
|  | 7270 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7271 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), | 
| Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7272 | mApp.getAttributionTag()); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7273 | } | 
|  | 7274 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7275 | /** | 
|  | 7276 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. | 
|  | 7277 | */ | 
|  | 7278 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7279 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), | 
| Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7280 | mApp.getAttributionTag()); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7281 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7282 |  | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7283 | private final ModemActivityInfo mLastModemActivityInfo = | 
| Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7284 | new ModemActivityInfo(0, 0, 0, new int[0], 0); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7285 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7286 | /** | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7287 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object | 
|  | 7288 | * representing the state of the modem. | 
|  | 7289 | * | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7290 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one | 
|  | 7291 | * caller to it. Everyone should call this class to get cumulative data. | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7292 | * @hide | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7293 | */ | 
|  | 7294 | @Override | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7295 | public void requestModemActivityInfo(ResultReceiver result) { | 
|  | 7296 | enforceModifyPermission(); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7297 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7298 |  | 
|  | 7299 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7300 | try { | 
| sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7301 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7302 | } finally { | 
|  | 7303 | Binder.restoreCallingIdentity(identity); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7304 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7305 | } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7306 |  | 
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7307 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be | 
|  | 7308 | // less than total activity duration. | 
|  | 7309 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { | 
|  | 7310 | if (info == null) { | 
|  | 7311 | return false; | 
|  | 7312 | } | 
|  | 7313 | int activityDurationMs = | 
|  | 7314 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); | 
|  | 7315 | int totalTxTimeMs = 0; | 
| Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7316 | int[] txTimeMs = info.getTransmitTimeMillis(); | 
|  | 7317 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { | 
|  | 7318 | totalTxTimeMs += txTimeMs[i]; | 
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7319 | } | 
|  | 7320 | return (info.isValid() | 
|  | 7321 | && (info.getSleepTimeMillis() <= activityDurationMs) | 
|  | 7322 | && (info.getIdleTimeMillis() <= activityDurationMs) | 
| Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7323 | && (info.getReceiveTimeMillis() <= activityDurationMs) | 
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7324 | && (totalTxTimeMs <= activityDurationMs)); | 
|  | 7325 | } | 
|  | 7326 |  | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7327 | /** | 
|  | 7328 | * {@hide} | 
|  | 7329 | * Returns the service state information on specified subscription. | 
|  | 7330 | */ | 
|  | 7331 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7332 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, | 
|  | 7333 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7334 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7335 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7336 | return null; | 
|  | 7337 | } | 
|  | 7338 |  | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7339 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = | 
|  | 7340 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 7341 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 7342 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7343 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7344 | .setCallingPid(Binder.getCallingPid()) | 
|  | 7345 | .setCallingUid(Binder.getCallingUid()) | 
|  | 7346 | .setMethod("getServiceStateForSubscriber") | 
| Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7347 | .setLogAsInfo(true) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7348 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 7349 | .build()); | 
|  | 7350 |  | 
|  | 7351 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = | 
|  | 7352 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 7353 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 7354 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7355 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7356 | .setCallingPid(Binder.getCallingPid()) | 
|  | 7357 | .setCallingUid(Binder.getCallingUid()) | 
|  | 7358 | .setMethod("getServiceStateForSubscriber") | 
| Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7359 | .setLogAsInfo(true) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7360 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) | 
|  | 7361 | .build()); | 
|  | 7362 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. | 
|  | 7363 | boolean hasFinePermission = | 
|  | 7364 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; | 
|  | 7365 | boolean hasCoarsePermission = | 
|  | 7366 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; | 
|  | 7367 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7368 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7369 | try { | 
| Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7370 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above | 
|  | 7371 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { | 
|  | 7372 | Rlog.d(LOG_TAG, | 
|  | 7373 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); | 
|  | 7374 | return null; | 
|  | 7375 | } | 
|  | 7376 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7377 | final Phone phone = getPhone(subId); | 
|  | 7378 | if (phone == null) { | 
|  | 7379 | return null; | 
|  | 7380 | } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7381 |  | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7382 | ServiceState ss = phone.getServiceState(); | 
|  | 7383 |  | 
|  | 7384 | // Scrub out the location info in ServiceState depending on what level of access | 
|  | 7385 | // the caller has. | 
|  | 7386 | if (hasFinePermission) return ss; | 
| Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7387 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); | 
|  | 7388 | return ss.createLocationInfoSanitizedCopy(true); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7389 | } finally { | 
|  | 7390 | Binder.restoreCallingIdentity(identity); | 
|  | 7391 | } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7392 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7393 |  | 
|  | 7394 | /** | 
|  | 7395 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. | 
|  | 7396 | * | 
|  | 7397 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
|  | 7398 | * voicemail ringtone. | 
|  | 7399 | * @return The URI for the ringtone to play when receiving a voicemail from a specific | 
|  | 7400 | * PhoneAccount. | 
|  | 7401 | */ | 
|  | 7402 | @Override | 
|  | 7403 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7404 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7405 | try { | 
|  | 7406 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
|  | 7407 | if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7408 | phone = getDefaultPhone(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7409 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7410 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7411 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); | 
|  | 7412 | } finally { | 
|  | 7413 | Binder.restoreCallingIdentity(identity); | 
|  | 7414 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7415 | } | 
|  | 7416 |  | 
|  | 7417 | /** | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7418 | * Sets the per-account voicemail ringtone. | 
|  | 7419 | * | 
|  | 7420 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or | 
|  | 7421 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 7422 | * | 
|  | 7423 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the | 
|  | 7424 | * voicemail ringtone. | 
|  | 7425 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific | 
|  | 7426 | * PhoneAccount. | 
|  | 7427 | */ | 
|  | 7428 | @Override | 
|  | 7429 | public void setVoicemailRingtoneUri(String callingPackage, | 
|  | 7430 | PhoneAccountHandle phoneAccountHandle, Uri uri) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7431 | final Phone defaultPhone = getDefaultPhone(); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7432 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7433 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); | 
|  | 7434 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7435 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 7436 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), | 
|  | 7437 | "setVoicemailRingtoneUri"); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7438 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7439 |  | 
|  | 7440 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7441 | try { | 
|  | 7442 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); | 
|  | 7443 | if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7444 | phone = defaultPhone; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7445 | } | 
|  | 7446 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); | 
|  | 7447 | } finally { | 
|  | 7448 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7449 | } | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7450 | } | 
|  | 7451 |  | 
|  | 7452 | /** | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7453 | * Returns whether vibration is set for voicemail notification in Phone settings. | 
|  | 7454 | * | 
|  | 7455 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
|  | 7456 | * voicemail vibration setting. | 
|  | 7457 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. | 
|  | 7458 | */ | 
|  | 7459 | @Override | 
|  | 7460 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7461 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7462 | try { | 
|  | 7463 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
|  | 7464 | if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7465 | phone = getDefaultPhone(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7466 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7467 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7468 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); | 
|  | 7469 | } finally { | 
|  | 7470 | Binder.restoreCallingIdentity(identity); | 
|  | 7471 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7472 | } | 
|  | 7473 |  | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7474 | /** | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7475 | * Sets the per-account voicemail vibration. | 
|  | 7476 | * | 
|  | 7477 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or | 
|  | 7478 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 7479 | * | 
|  | 7480 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the | 
|  | 7481 | * voicemail vibration setting. | 
|  | 7482 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a | 
|  | 7483 | * specific PhoneAccount. | 
|  | 7484 | */ | 
|  | 7485 | @Override | 
|  | 7486 | public void setVoicemailVibrationEnabled(String callingPackage, | 
|  | 7487 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7488 | final Phone defaultPhone = getDefaultPhone(); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7489 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7490 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); | 
|  | 7491 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7492 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 7493 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), | 
|  | 7494 | "setVoicemailVibrationEnabled"); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7495 | } | 
|  | 7496 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7497 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7498 | try { | 
|  | 7499 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); | 
|  | 7500 | if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7501 | phone = defaultPhone; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7502 | } | 
|  | 7503 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); | 
|  | 7504 | } finally { | 
|  | 7505 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7506 | } | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7507 | } | 
|  | 7508 |  | 
|  | 7509 | /** | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7510 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. | 
|  | 7511 | * | 
|  | 7512 | * @throws SecurityException if the caller does not have the required permission | 
|  | 7513 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7514 | private void enforceReadPrivilegedPermission(String message) { | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7515 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7516 | message); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7517 | } | 
|  | 7518 |  | 
|  | 7519 | /** | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7520 | * Make sure either called from same process as self (phone) or IPC caller has send SMS | 
|  | 7521 | * permission. | 
|  | 7522 | * | 
|  | 7523 | * @throws SecurityException if the caller does not have the required permission | 
|  | 7524 | */ | 
|  | 7525 | private void enforceSendSmsPermission() { | 
|  | 7526 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); | 
|  | 7527 | } | 
|  | 7528 |  | 
|  | 7529 | /** | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7530 | * Make sure called from the package in charge of visual voicemail. | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7531 | * | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7532 | * @throws SecurityException if the caller is not the visual voicemail package. | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7533 | */ | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7534 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7535 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7536 | try { | 
|  | 7537 | ComponentName componentName = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7538 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7539 | if (componentName == null) { | 
|  | 7540 | throw new SecurityException( | 
|  | 7541 | "Caller not current active visual voicemail package[null]"); | 
|  | 7542 | } | 
|  | 7543 | String vvmPackage = componentName.getPackageName(); | 
|  | 7544 | if (!callingPackage.equals(vvmPackage)) { | 
|  | 7545 | throw new SecurityException("Caller not current active visual voicemail package[" | 
|  | 7546 | + vvmPackage + "]"); | 
|  | 7547 | } | 
|  | 7548 | } finally { | 
|  | 7549 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7550 | } | 
|  | 7551 | } | 
|  | 7552 |  | 
|  | 7553 | /** | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7554 | * Return the application ID for the app type. | 
|  | 7555 | * | 
|  | 7556 | * @param subId the subscription ID that this request applies to. | 
|  | 7557 | * @param appType the uicc app type. | 
|  | 7558 | * @return Application ID for specificied app type, or null if no uicc. | 
|  | 7559 | */ | 
|  | 7560 | @Override | 
|  | 7561 | public String getAidForAppType(int subId, int appType) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7562 | enforceReadPrivilegedPermission("getAidForAppType"); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7563 | Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7564 |  | 
|  | 7565 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7566 | try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7567 | if (phone == null) { | 
|  | 7568 | return null; | 
|  | 7569 | } | 
|  | 7570 | String aid = null; | 
|  | 7571 | try { | 
|  | 7572 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) | 
|  | 7573 | .getApplicationByType(appType).getAid(); | 
|  | 7574 | } catch (Exception e) { | 
|  | 7575 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); | 
|  | 7576 | } | 
|  | 7577 | return aid; | 
|  | 7578 | } finally { | 
|  | 7579 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7580 | } | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7581 | } | 
|  | 7582 |  | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7583 | /** | 
|  | 7584 | * Return the Electronic Serial Number. | 
|  | 7585 | * | 
|  | 7586 | * @param subId the subscription ID that this request applies to. | 
|  | 7587 | * @return ESN or null if error. | 
|  | 7588 | */ | 
|  | 7589 | @Override | 
|  | 7590 | public String getEsn(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7591 | enforceReadPrivilegedPermission("getEsn"); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7592 | Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7593 |  | 
|  | 7594 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7595 | try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7596 | if (phone == null) { | 
|  | 7597 | return null; | 
|  | 7598 | } | 
|  | 7599 | String esn = null; | 
|  | 7600 | try { | 
|  | 7601 | esn = phone.getEsn(); | 
|  | 7602 | } catch (Exception e) { | 
|  | 7603 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); | 
|  | 7604 | } | 
|  | 7605 | return esn; | 
|  | 7606 | } finally { | 
|  | 7607 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7608 | } | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7609 | } | 
|  | 7610 |  | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7611 | /** | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7612 | * Return the Preferred Roaming List Version. | 
|  | 7613 | * | 
|  | 7614 | * @param subId the subscription ID that this request applies to. | 
|  | 7615 | * @return PRLVersion or null if error. | 
|  | 7616 | */ | 
|  | 7617 | @Override | 
|  | 7618 | public String getCdmaPrlVersion(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7619 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7620 | Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7621 |  | 
|  | 7622 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7623 | try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7624 | if (phone == null) { | 
|  | 7625 | return null; | 
|  | 7626 | } | 
|  | 7627 | String cdmaPrlVersion = null; | 
|  | 7628 | try { | 
|  | 7629 | cdmaPrlVersion = phone.getCdmaPrlVersion(); | 
|  | 7630 | } catch (Exception e) { | 
|  | 7631 | Log.e(LOG_TAG, "Not getting PRLVersion", e); | 
|  | 7632 | } | 
|  | 7633 | return cdmaPrlVersion; | 
|  | 7634 | } finally { | 
|  | 7635 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7636 | } | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7637 | } | 
|  | 7638 |  | 
|  | 7639 | /** | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7640 | * Get snapshot of Telephony histograms | 
|  | 7641 | * @return List of Telephony histograms | 
|  | 7642 | * @hide | 
|  | 7643 | */ | 
|  | 7644 | @Override | 
|  | 7645 | public List<TelephonyHistogram> getTelephonyHistograms() { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7646 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 7647 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7648 |  | 
|  | 7649 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7650 | try { | 
|  | 7651 | return RIL.getTelephonyRILTimingHistograms(); | 
|  | 7652 | } finally { | 
|  | 7653 | Binder.restoreCallingIdentity(identity); | 
|  | 7654 | } | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7655 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7656 |  | 
|  | 7657 | /** | 
|  | 7658 | * {@hide} | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7659 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between | 
|  | 7660 | * the two lists. | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7661 | * Require system privileges. In the future we may add this to carrier APIs. | 
|  | 7662 | * | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7663 | * @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] | 7664 | */ | 
|  | 7665 | @Override | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7666 | @TelephonyManager.SetCarrierRestrictionResult | 
|  | 7667 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7668 | enforceModifyPermission(); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7669 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7670 |  | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7671 | if (carrierRestrictionRules == null) { | 
|  | 7672 | throw new NullPointerException("carrier restriction cannot be null"); | 
| Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7673 | } | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7674 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7675 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7676 | try { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7677 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7678 | workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7679 | } finally { | 
|  | 7680 | Binder.restoreCallingIdentity(identity); | 
|  | 7681 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7682 | } | 
|  | 7683 |  | 
|  | 7684 | /** | 
|  | 7685 | * {@hide} | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7686 | * Get the allowed carrier list and the excluded carrier list, including the priority between | 
|  | 7687 | * the two lists. | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7688 | * Require system privileges. In the future we may add this to carrier APIs. | 
|  | 7689 | * | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7690 | * @return {@link android.telephony.CarrierRestrictionRules} | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7691 | */ | 
|  | 7692 | @Override | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7693 | public CarrierRestrictionRules getAllowedCarriers() { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7694 | enforceReadPrivilegedPermission("getAllowedCarriers"); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7695 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7696 |  | 
|  | 7697 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7698 | try { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7699 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); | 
|  | 7700 | if (response instanceof CarrierRestrictionRules) { | 
|  | 7701 | return (CarrierRestrictionRules) response; | 
|  | 7702 | } | 
|  | 7703 | // Response is an Exception of some kind, | 
|  | 7704 | // which is signalled to the user as a NULL retval | 
|  | 7705 | return null; | 
|  | 7706 | } catch (Exception e) { | 
|  | 7707 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); | 
|  | 7708 | return null; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7709 | } finally { | 
|  | 7710 | Binder.restoreCallingIdentity(identity); | 
|  | 7711 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7712 | } | 
|  | 7713 |  | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7714 | /** | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7715 | * Action set from carrier signalling broadcast receivers to enable/disable radio | 
|  | 7716 | * @param subId the subscription ID that this action applies to. | 
|  | 7717 | * @param enabled control enable or disable radio. | 
|  | 7718 | * {@hide} | 
|  | 7719 | */ | 
|  | 7720 | @Override | 
|  | 7721 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { | 
|  | 7722 | enforceModifyPermission(); | 
|  | 7723 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7724 |  | 
|  | 7725 | final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7726 | if (phone == null) { | 
|  | 7727 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); | 
|  | 7728 | return; | 
|  | 7729 | } | 
|  | 7730 | try { | 
|  | 7731 | phone.carrierActionSetRadioEnabled(enabled); | 
|  | 7732 | } catch (Exception e) { | 
|  | 7733 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7734 | } finally { | 
|  | 7735 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7736 | } | 
|  | 7737 | } | 
|  | 7738 |  | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7739 | /** | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7740 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default | 
|  | 7741 | * network status based on which carrier apps could apply actions accordingly, | 
|  | 7742 | * enable/disable default url handler for example. | 
|  | 7743 | * | 
|  | 7744 | * @param subId the subscription ID that this action applies to. | 
|  | 7745 | * @param report control start/stop reporting the default network status. | 
|  | 7746 | * {@hide} | 
|  | 7747 | */ | 
|  | 7748 | @Override | 
|  | 7749 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { | 
|  | 7750 | enforceModifyPermission(); | 
|  | 7751 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7752 |  | 
|  | 7753 | final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7754 | if (phone == null) { | 
|  | 7755 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); | 
|  | 7756 | return; | 
|  | 7757 | } | 
|  | 7758 | try { | 
|  | 7759 | phone.carrierActionReportDefaultNetworkStatus(report); | 
|  | 7760 | } catch (Exception e) { | 
|  | 7761 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7762 | } finally { | 
|  | 7763 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7764 | } | 
|  | 7765 | } | 
|  | 7766 |  | 
|  | 7767 | /** | 
| fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7768 | * Action set from carrier signalling broadcast receivers to reset all carrier actions | 
|  | 7769 | * @param subId the subscription ID that this action applies to. | 
|  | 7770 | * {@hide} | 
|  | 7771 | */ | 
|  | 7772 | @Override | 
|  | 7773 | public void carrierActionResetAll(int subId) { | 
|  | 7774 | enforceModifyPermission(); | 
|  | 7775 | final Phone phone = getPhone(subId); | 
|  | 7776 | if (phone == null) { | 
|  | 7777 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); | 
|  | 7778 | return; | 
|  | 7779 | } | 
|  | 7780 | try { | 
|  | 7781 | phone.carrierActionResetAll(); | 
|  | 7782 | } catch (Exception e) { | 
|  | 7783 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); | 
|  | 7784 | } | 
|  | 7785 | } | 
|  | 7786 |  | 
|  | 7787 | /** | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7788 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a | 
|  | 7789 | * bug report is being generated. | 
|  | 7790 | */ | 
|  | 7791 | @Override | 
| Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7792 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7793 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) | 
|  | 7794 | != PackageManager.PERMISSION_GRANTED) { | 
| dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7795 | writer.println("Permission Denial: can't dump Phone from pid=" | 
|  | 7796 | + Binder.getCallingPid() | 
|  | 7797 | + ", uid=" + Binder.getCallingUid() | 
|  | 7798 | + "without permission " | 
|  | 7799 | + android.Manifest.permission.DUMP); | 
|  | 7800 | return; | 
|  | 7801 | } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7802 | DumpsysHandler.dump(mApp, fd, writer, args); | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7803 | } | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7804 |  | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7805 | @Override | 
| Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7806 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, | 
|  | 7807 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, | 
|  | 7808 | @NonNull String[] args) { | 
|  | 7809 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( | 
|  | 7810 | this, in.getFileDescriptor(), out.getFileDescriptor(), | 
|  | 7811 | err.getFileDescriptor(), args); | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7812 | } | 
|  | 7813 |  | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7814 | /** | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7815 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7816 | * @param subId Subscription index | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7817 | * @param reason the reason the data enable change is taking place | 
|  | 7818 | * @param enabled True if enabling the data, otherwise disabling. | 
|  | 7819 | * @hide | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7820 | */ | 
|  | 7821 | @Override | 
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7822 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7823 | boolean enabled) { | 
|  | 7824 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER | 
|  | 7825 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { | 
|  | 7826 | try { | 
|  | 7827 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
| Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7828 | mApp, subId, "setDataEnabledForReason"); | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7829 | } catch (SecurityException se) { | 
|  | 7830 | enforceModifyPermission(); | 
|  | 7831 | } | 
|  | 7832 | } else { | 
|  | 7833 | enforceModifyPermission(); | 
|  | 7834 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7835 |  | 
|  | 7836 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7837 | try { | 
|  | 7838 | Phone phone = getPhone(subId); | 
|  | 7839 | if (phone != null) { | 
| Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7840 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { | 
|  | 7841 | phone.carrierActionSetMeteredApnsEnabled(enabled); | 
|  | 7842 | } else { | 
|  | 7843 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); | 
|  | 7844 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7845 | } | 
|  | 7846 | } finally { | 
|  | 7847 | Binder.restoreCallingIdentity(identity); | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7848 | } | 
|  | 7849 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7850 |  | 
|  | 7851 | /** | 
|  | 7852 | * Get Client request stats | 
|  | 7853 | * @return List of Client Request Stats | 
|  | 7854 | * @hide | 
|  | 7855 | */ | 
|  | 7856 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7857 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, | 
|  | 7858 | String callingFeatureId, int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7859 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7860 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7861 | return null; | 
|  | 7862 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7863 | Phone phone = getPhone(subId); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7864 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7865 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7866 | try { | 
|  | 7867 | if (phone != null) { | 
|  | 7868 | return phone.getClientRequestStats(); | 
|  | 7869 | } | 
|  | 7870 |  | 
|  | 7871 | return null; | 
|  | 7872 | } finally { | 
|  | 7873 | Binder.restoreCallingIdentity(identity); | 
|  | 7874 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7875 | } | 
|  | 7876 |  | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7877 | private WorkSource getWorkSource(int uid) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7878 | String packageName = mApp.getPackageManager().getNameForUid(uid); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7879 | return new WorkSource(uid, packageName); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7880 | } | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7881 |  | 
|  | 7882 | /** | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7883 | * Set SIM card power state. | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7884 | * | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7885 | * @param slotIndex SIM slot id. | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7886 | * @param state  State of SIM (power down, power up, pass through) | 
|  | 7887 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} | 
|  | 7888 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} | 
|  | 7889 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7890 | * | 
|  | 7891 | **/ | 
|  | 7892 | @Override | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7893 | public void setSimPowerStateForSlot(int slotIndex, int state) { | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7894 | enforceModifyPermission(); | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7895 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 7896 |  | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7897 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 7898 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7899 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7900 | try { | 
|  | 7901 | if (phone != null) { | 
| Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 7902 | phone.setSimPowerState(state, null, workSource); | 
|  | 7903 | } | 
|  | 7904 | } finally { | 
|  | 7905 | Binder.restoreCallingIdentity(identity); | 
|  | 7906 | } | 
|  | 7907 | } | 
|  | 7908 |  | 
|  | 7909 | /** | 
|  | 7910 | * Set SIM card power state. | 
|  | 7911 | * | 
|  | 7912 | * @param slotIndex SIM slot id. | 
|  | 7913 | * @param state  State of SIM (power down, power up, pass through) | 
|  | 7914 | * @param callback  callback to trigger after success or failure | 
|  | 7915 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} | 
|  | 7916 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} | 
|  | 7917 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} | 
|  | 7918 | * | 
|  | 7919 | **/ | 
|  | 7920 | @Override | 
|  | 7921 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, | 
|  | 7922 | IIntegerConsumer callback) { | 
|  | 7923 | enforceModifyPermission(); | 
|  | 7924 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 7925 |  | 
|  | 7926 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 7927 |  | 
|  | 7928 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7929 | try { | 
|  | 7930 | if (phone != null) { | 
|  | 7931 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); | 
|  | 7932 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7933 | } | 
|  | 7934 | } finally { | 
|  | 7935 | Binder.restoreCallingIdentity(identity); | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7936 | } | 
|  | 7937 | } | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7938 |  | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7939 | private boolean isUssdApiAllowed(int subId) { | 
|  | 7940 | CarrierConfigManager configManager = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7941 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7942 | if (configManager == null) { | 
|  | 7943 | return false; | 
|  | 7944 | } | 
|  | 7945 | PersistableBundle pb = configManager.getConfigForSubId(subId); | 
|  | 7946 | if (pb == null) { | 
|  | 7947 | return false; | 
|  | 7948 | } | 
|  | 7949 | return pb.getBoolean( | 
|  | 7950 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); | 
|  | 7951 | } | 
|  | 7952 |  | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7953 | /** | 
|  | 7954 | * Check if phone is in emergency callback mode | 
|  | 7955 | * @return true if phone is in emergency callback mode | 
|  | 7956 | * @param subId sub id | 
|  | 7957 | */ | 
| goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7958 | @Override | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7959 | public boolean getEmergencyCallbackMode(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7960 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7961 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7962 |  | 
|  | 7963 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7964 | try { | 
|  | 7965 | if (phone != null) { | 
|  | 7966 | return phone.isInEcm(); | 
|  | 7967 | } else { | 
|  | 7968 | return false; | 
|  | 7969 | } | 
|  | 7970 | } finally { | 
|  | 7971 | Binder.restoreCallingIdentity(identity); | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7972 | } | 
|  | 7973 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7974 |  | 
|  | 7975 | /** | 
|  | 7976 | * Get the current signal strength information for the given subscription. | 
|  | 7977 | * Because this information is not updated when the device is in a low power state | 
|  | 7978 | * it should not be relied-upon to be current. | 
|  | 7979 | * @param subId Subscription index | 
|  | 7980 | * @return the most recent cached signal strength info from the modem | 
|  | 7981 | */ | 
|  | 7982 | @Override | 
|  | 7983 | public SignalStrength getSignalStrength(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7984 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7985 | try { | 
|  | 7986 | Phone p = getPhone(subId); | 
|  | 7987 | if (p == null) { | 
|  | 7988 | return null; | 
|  | 7989 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7990 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7991 | return p.getSignalStrength(); | 
|  | 7992 | } finally { | 
|  | 7993 | Binder.restoreCallingIdentity(identity); | 
|  | 7994 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7995 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7996 |  | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7997 | /** | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7998 | * Get the current modem radio state for the given slot. | 
|  | 7999 | * @param slotIndex slot index. | 
|  | 8000 | * @param callingPackage the name of the package making the call. | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8001 | * @param callingFeatureId The feature in the package. | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8002 | * @return the current radio power state from the modem | 
|  | 8003 | */ | 
|  | 8004 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8005 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8006 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 8007 | if (phone != null) { | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8008 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), | 
|  | 8009 | callingPackage, callingFeatureId, "getRadioPowerState")) { | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8010 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; | 
|  | 8011 | } | 
|  | 8012 |  | 
|  | 8013 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8014 | try { | 
|  | 8015 | return phone.getRadioPowerState(); | 
|  | 8016 | } finally { | 
|  | 8017 | Binder.restoreCallingIdentity(identity); | 
|  | 8018 | } | 
|  | 8019 | } | 
|  | 8020 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; | 
|  | 8021 | } | 
|  | 8022 |  | 
|  | 8023 | /** | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8024 | * Checks if data roaming is enabled on the subscription with id {@code subId}. | 
|  | 8025 | * | 
|  | 8026 | * <p>Requires one of the following permissions: | 
|  | 8027 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, | 
|  | 8028 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier | 
|  | 8029 | * privileges. | 
|  | 8030 | * | 
|  | 8031 | * @param subId subscription id | 
|  | 8032 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return | 
|  | 8033 | * {@code false}. | 
|  | 8034 | */ | 
|  | 8035 | @Override | 
|  | 8036 | public boolean isDataRoamingEnabled(int subId) { | 
| Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8037 | try { | 
|  | 8038 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 8039 | null); | 
|  | 8040 | } catch (Exception e) { | 
|  | 8041 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( | 
|  | 8042 | mApp, subId, "isDataRoamingEnabled"); | 
|  | 8043 | } | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8044 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8045 | boolean isEnabled = false; | 
|  | 8046 | final long identity = Binder.clearCallingIdentity(); | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8047 | try { | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8048 | Phone phone = getPhone(subId); | 
|  | 8049 | isEnabled =  phone != null ? phone.getDataRoamingEnabled() : false; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8050 | } finally { | 
|  | 8051 | Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8052 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8053 | return isEnabled; | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8054 | } | 
|  | 8055 |  | 
|  | 8056 |  | 
|  | 8057 | /** | 
|  | 8058 | * Enables/Disables the data roaming on the subscription with id {@code subId}. | 
|  | 8059 | * | 
|  | 8060 | * <p> Requires permission: | 
|  | 8061 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier | 
|  | 8062 | * privileges. | 
|  | 8063 | * | 
|  | 8064 | * @param subId subscription id | 
|  | 8065 | * @param isEnabled {@code true} means enable, {@code false} means disable. | 
|  | 8066 | */ | 
|  | 8067 | @Override | 
|  | 8068 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8069 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 8070 | mApp, subId, "setDataRoamingEnabled"); | 
|  | 8071 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8072 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8073 | try { | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8074 | Phone phone = getPhone(subId); | 
|  | 8075 | if (phone != null) { | 
|  | 8076 | phone.setDataRoamingEnabled(isEnabled); | 
|  | 8077 | } | 
|  | 8078 | } finally { | 
|  | 8079 | Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8080 | } | 
|  | 8081 | } | 
|  | 8082 |  | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8083 | @Override | 
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8084 | public boolean isManualNetworkSelectionAllowed(int subId) { | 
| tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8085 | TelephonyPermissions | 
|  | 8086 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8087 | mApp, subId, "isManualNetworkSelectionAllowed"); | 
|  | 8088 |  | 
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8089 | boolean isAllowed = true; | 
|  | 8090 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8091 | try { | 
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8092 | Phone phone = getPhone(subId); | 
|  | 8093 | if (phone != null) { | 
|  | 8094 | isAllowed = phone.isCspPlmnEnabled(); | 
|  | 8095 | } | 
|  | 8096 | } finally { | 
|  | 8097 | Binder.restoreCallingIdentity(identity); | 
|  | 8098 | } | 
|  | 8099 | return isAllowed; | 
|  | 8100 | } | 
|  | 8101 |  | 
|  | 8102 | @Override | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8103 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { | 
| Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8104 | // Verify that tha callingPackage belongs to the calling UID | 
|  | 8105 | mApp.getSystemService(AppOpsManager.class) | 
|  | 8106 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 8107 |  | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8108 | boolean hasReadPermission = false; | 
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8109 | try { | 
|  | 8110 | enforceReadPrivilegedPermission("getUiccCardsInfo"); | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8111 | hasReadPermission = true; | 
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8112 | } catch (SecurityException e) { | 
|  | 8113 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller | 
|  | 8114 | // has carrier privileges on an active UICC | 
|  | 8115 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) | 
|  | 8116 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8117 | throw new SecurityException("Caller does not have permission."); | 
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8118 | } | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8119 | } | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8120 |  | 
|  | 8121 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8122 | try { | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8123 | UiccController uiccController = UiccController.getInstance(); | 
|  | 8124 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8125 | if (hasReadPermission) { | 
|  | 8126 | return cardInfos; | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8127 | } | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8128 |  | 
|  | 8129 | // Remove private info if the caller doesn't have access | 
|  | 8130 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); | 
|  | 8131 | for (UiccCardInfo cardInfo : cardInfos) { | 
|  | 8132 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo | 
|  | 8133 | // is available | 
|  | 8134 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); | 
|  | 8135 | if (card == null || card.getUiccProfile() == null) { | 
|  | 8136 | // assume no access if the card or profile is unavailable | 
|  | 8137 | filteredInfos.add(cardInfo.getUnprivileged()); | 
|  | 8138 | continue; | 
|  | 8139 | } | 
|  | 8140 | UiccProfile profile = card.getUiccProfile(); | 
|  | 8141 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) | 
|  | 8142 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
|  | 8143 | filteredInfos.add(cardInfo); | 
|  | 8144 | } else { | 
|  | 8145 | filteredInfos.add(cardInfo.getUnprivileged()); | 
|  | 8146 | } | 
|  | 8147 | } | 
|  | 8148 | return filteredInfos; | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8149 | } finally { | 
|  | 8150 | Binder.restoreCallingIdentity(identity); | 
|  | 8151 | } | 
|  | 8152 | } | 
|  | 8153 |  | 
|  | 8154 | @Override | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8155 | public UiccSlotInfo[] getUiccSlotsInfo() { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8156 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8157 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8158 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8159 | try { | 
|  | 8160 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); | 
|  | 8161 | if (slots == null) { | 
|  | 8162 | Rlog.i(LOG_TAG, "slots is null."); | 
|  | 8163 | return null; | 
|  | 8164 | } | 
|  | 8165 |  | 
|  | 8166 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; | 
|  | 8167 | for (int i = 0; i < slots.length; i++) { | 
|  | 8168 | UiccSlot slot = slots[i]; | 
|  | 8169 | if (slot == null) { | 
|  | 8170 | continue; | 
|  | 8171 | } | 
|  | 8172 |  | 
| Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8173 | String cardId; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8174 | UiccCard card = slot.getUiccCard(); | 
|  | 8175 | if (card != null) { | 
|  | 8176 | cardId = card.getCardId(); | 
| Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8177 | } else { | 
| Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8178 | cardId = slot.getEid(); | 
|  | 8179 | if (TextUtils.isEmpty(cardId)) { | 
|  | 8180 | cardId = slot.getIccId(); | 
|  | 8181 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8182 | } | 
|  | 8183 |  | 
| Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8184 | if (cardId != null) { | 
|  | 8185 | // if cardId is an ICCID, strip off trailing Fs before exposing to user | 
|  | 8186 | // if cardId is an EID, it's all digits so this is fine | 
|  | 8187 | cardId = IccUtils.stripTrailingFs(cardId); | 
|  | 8188 | } | 
|  | 8189 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8190 | int cardState = 0; | 
|  | 8191 | switch (slot.getCardState()) { | 
|  | 8192 | case CARDSTATE_ABSENT: | 
|  | 8193 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; | 
|  | 8194 | break; | 
|  | 8195 | case CARDSTATE_PRESENT: | 
|  | 8196 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; | 
|  | 8197 | break; | 
|  | 8198 | case CARDSTATE_ERROR: | 
|  | 8199 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; | 
|  | 8200 | break; | 
|  | 8201 | case CARDSTATE_RESTRICTED: | 
|  | 8202 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; | 
|  | 8203 | break; | 
|  | 8204 | default: | 
|  | 8205 | break; | 
|  | 8206 |  | 
|  | 8207 | } | 
|  | 8208 |  | 
|  | 8209 | infos[i] = new UiccSlotInfo( | 
|  | 8210 | slot.isActive(), | 
|  | 8211 | slot.isEuicc(), | 
|  | 8212 | cardId, | 
|  | 8213 | cardState, | 
|  | 8214 | slot.getPhoneId(), | 
| Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8215 | slot.isExtendedApduSupported(), | 
|  | 8216 | slot.isRemovable()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8217 | } | 
|  | 8218 | return infos; | 
|  | 8219 | } finally { | 
|  | 8220 | Binder.restoreCallingIdentity(identity); | 
| Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8221 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8222 | } | 
|  | 8223 |  | 
|  | 8224 | @Override | 
|  | 8225 | public boolean switchSlots(int[] physicalSlots) { | 
|  | 8226 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8227 |  | 
|  | 8228 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8229 | try { | 
|  | 8230 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); | 
|  | 8231 | } finally { | 
|  | 8232 | Binder.restoreCallingIdentity(identity); | 
|  | 8233 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8234 | } | 
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8235 |  | 
|  | 8236 | @Override | 
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8237 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { | 
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8238 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8239 | try { | 
|  | 8240 | return UiccController.getInstance().getCardIdForDefaultEuicc(); | 
|  | 8241 | } finally { | 
|  | 8242 | Binder.restoreCallingIdentity(identity); | 
|  | 8243 | } | 
|  | 8244 | } | 
|  | 8245 |  | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8246 | /** | 
| goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8247 | * A test API to reload the UICC profile. | 
|  | 8248 | * | 
|  | 8249 | * <p>Requires that the calling app has permission | 
|  | 8250 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 8251 | * @hide | 
|  | 8252 | */ | 
|  | 8253 | @Override | 
|  | 8254 | public void refreshUiccProfile(int subId) { | 
|  | 8255 | enforceModifyPermission(); | 
|  | 8256 |  | 
|  | 8257 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8258 | try { | 
|  | 8259 | Phone phone = getPhone(subId); | 
|  | 8260 | if (phone == null) { | 
|  | 8261 | return; | 
|  | 8262 | } | 
|  | 8263 | UiccCard uiccCard = phone.getUiccCard(); | 
|  | 8264 | if (uiccCard == null) { | 
|  | 8265 | return; | 
|  | 8266 | } | 
|  | 8267 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); | 
|  | 8268 | if (uiccProfile == null) { | 
|  | 8269 | return; | 
|  | 8270 | } | 
|  | 8271 | uiccProfile.refresh(); | 
|  | 8272 | } finally { | 
|  | 8273 | Binder.restoreCallingIdentity(identity); | 
|  | 8274 | } | 
|  | 8275 | } | 
|  | 8276 |  | 
|  | 8277 | /** | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8278 | * Returns false if the mobile data is disabled by default, otherwise return true. | 
|  | 8279 | */ | 
|  | 8280 | private boolean getDefaultDataEnabled() { | 
| Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8281 | return TelephonyProperties.mobile_data().orElse(true); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8282 | } | 
|  | 8283 |  | 
|  | 8284 | /** | 
|  | 8285 | * Returns true if the data roaming is enabled by default, i.e the system property | 
|  | 8286 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of | 
|  | 8287 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. | 
|  | 8288 | */ | 
|  | 8289 | private boolean getDefaultDataRoamingEnabled(int subId) { | 
|  | 8290 | final CarrierConfigManager configMgr = (CarrierConfigManager) | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8291 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8292 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8293 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( | 
|  | 8294 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); | 
|  | 8295 | return isDataRoamingEnabled; | 
|  | 8296 | } | 
|  | 8297 |  | 
|  | 8298 | /** | 
|  | 8299 | * Returns the default network type for the given {@code subId}, if the default network type is | 
|  | 8300 | * not set, return {@link Phone#PREFERRED_NT_MODE}. | 
|  | 8301 | */ | 
|  | 8302 | private int getDefaultNetworkType(int subId) { | 
| Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8303 | List<Integer> list = TelephonyProperties.default_network(); | 
|  | 8304 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 8305 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { | 
|  | 8306 | return list.get(phoneId); | 
|  | 8307 | } | 
|  | 8308 | return Phone.PREFERRED_NT_MODE; | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8309 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8310 |  | 
|  | 8311 | @Override | 
|  | 8312 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String | 
| chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8313 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8314 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8315 |  | 
|  | 8316 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8317 | try { | 
|  | 8318 | final Phone phone = getPhone(subId); | 
|  | 8319 | if (phone == null) { | 
|  | 8320 | loge("setCarrierTestOverride fails with invalid subId: " + subId); | 
|  | 8321 | return; | 
|  | 8322 | } | 
| chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8323 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, | 
|  | 8324 | carrierPrivilegeRules, apn); | 
| Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8325 | if (carrierPrivilegeRules == null) { | 
|  | 8326 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); | 
|  | 8327 | } else { | 
|  | 8328 | mCarrierPrivilegeTestOverrideSubIds.add(subId); | 
|  | 8329 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8330 | } finally { | 
|  | 8331 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8332 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8333 | } | 
|  | 8334 |  | 
|  | 8335 | @Override | 
|  | 8336 | public int getCarrierIdListVersion(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8337 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8338 |  | 
|  | 8339 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8340 | try { | 
|  | 8341 | final Phone phone = getPhone(subId); | 
|  | 8342 | if (phone == null) { | 
|  | 8343 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); | 
|  | 8344 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; | 
|  | 8345 | } | 
|  | 8346 | return phone.getCarrierIdListVersion(); | 
|  | 8347 | } finally { | 
|  | 8348 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8349 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8350 | } | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8351 |  | 
|  | 8352 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8353 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, | 
|  | 8354 | String callingFeatureId) { | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8355 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8356 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 8357 | "getNumberOfModemsWithSimultaneousDataConnections")) { | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8358 | return -1; | 
|  | 8359 | } | 
|  | 8360 |  | 
|  | 8361 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8362 | try { | 
|  | 8363 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); | 
|  | 8364 | } finally { | 
|  | 8365 | Binder.restoreCallingIdentity(identity); | 
|  | 8366 | } | 
|  | 8367 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8368 |  | 
|  | 8369 | @Override | 
|  | 8370 | public int getCdmaRoamingMode(int subId) { | 
| zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8371 | TelephonyPermissions | 
|  | 8372 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8373 | mApp, subId, "getCdmaRoamingMode"); | 
|  | 8374 |  | 
|  | 8375 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8376 | try { | 
|  | 8377 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); | 
|  | 8378 | } finally { | 
|  | 8379 | Binder.restoreCallingIdentity(identity); | 
|  | 8380 | } | 
|  | 8381 | } | 
|  | 8382 |  | 
|  | 8383 | @Override | 
|  | 8384 | public boolean setCdmaRoamingMode(int subId, int mode) { | 
|  | 8385 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 8386 | mApp, subId, "setCdmaRoamingMode"); | 
|  | 8387 |  | 
|  | 8388 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8389 | try { | 
|  | 8390 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); | 
|  | 8391 | } finally { | 
|  | 8392 | Binder.restoreCallingIdentity(identity); | 
|  | 8393 | } | 
|  | 8394 | } | 
|  | 8395 |  | 
|  | 8396 | @Override | 
| Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8397 | public int getCdmaSubscriptionMode(int subId) { | 
|  | 8398 | TelephonyPermissions | 
|  | 8399 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 8400 | mApp, subId, "getCdmaSubscriptionMode"); | 
|  | 8401 |  | 
|  | 8402 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8403 | try { | 
|  | 8404 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); | 
|  | 8405 | } finally { | 
|  | 8406 | Binder.restoreCallingIdentity(identity); | 
|  | 8407 | } | 
|  | 8408 | } | 
|  | 8409 |  | 
|  | 8410 | @Override | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8411 | public boolean setCdmaSubscriptionMode(int subId, int mode) { | 
|  | 8412 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 8413 | mApp, subId, "setCdmaSubscriptionMode"); | 
|  | 8414 |  | 
|  | 8415 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8416 | try { | 
|  | 8417 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); | 
|  | 8418 | } finally { | 
|  | 8419 | Binder.restoreCallingIdentity(identity); | 
|  | 8420 | } | 
|  | 8421 | } | 
| Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8422 |  | 
| sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8423 | @Override | 
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8424 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8425 | String callingPackage, String callingFeatureId) { | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8426 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8427 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, | 
|  | 8428 | "getEmergencyNumberList")) { | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8429 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 8430 | } | 
|  | 8431 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8432 | try { | 
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8433 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); | 
|  | 8434 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8435 | if (phone.getEmergencyNumberTracker() != null | 
|  | 8436 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { | 
|  | 8437 | emergencyNumberListInternal.put( | 
|  | 8438 | phone.getSubId(), | 
|  | 8439 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); | 
|  | 8440 | } | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8441 | } | 
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8442 | return emergencyNumberListInternal; | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8443 | } finally { | 
|  | 8444 | Binder.restoreCallingIdentity(identity); | 
|  | 8445 | } | 
| sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8446 | } | 
|  | 8447 |  | 
|  | 8448 | @Override | 
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8449 | public boolean isEmergencyNumber(String number, boolean exactMatch) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8450 | final Phone defaultPhone = getDefaultPhone(); | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8451 | if (!exactMatch) { | 
|  | 8452 | TelephonyPermissions | 
|  | 8453 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8454 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8455 | } | 
|  | 8456 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8457 | try { | 
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8458 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8459 | if (phone.getEmergencyNumberTracker() != null | 
| Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8460 | && phone.getEmergencyNumberTracker() | 
|  | 8461 | .isEmergencyNumber(number, exactMatch)) { | 
|  | 8462 | return true; | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8463 | } | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8464 | } | 
|  | 8465 | return false; | 
|  | 8466 | } finally { | 
|  | 8467 | Binder.restoreCallingIdentity(identity); | 
|  | 8468 | } | 
|  | 8469 | } | 
|  | 8470 |  | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8471 | /** | 
|  | 8472 | * Update emergency number list for test mode. | 
|  | 8473 | */ | 
|  | 8474 | @Override | 
|  | 8475 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { | 
|  | 8476 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 8477 | "updateEmergencyNumberListTestMode"); | 
|  | 8478 |  | 
|  | 8479 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8480 | try { | 
|  | 8481 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8482 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 8483 | if (tracker != null) { | 
|  | 8484 | tracker.executeEmergencyNumberTestModeCommand(action, num); | 
|  | 8485 | } | 
|  | 8486 | } | 
|  | 8487 | } finally { | 
|  | 8488 | Binder.restoreCallingIdentity(identity); | 
|  | 8489 | } | 
|  | 8490 | } | 
|  | 8491 |  | 
|  | 8492 | /** | 
|  | 8493 | * Get the full emergency number list for test mode. | 
|  | 8494 | */ | 
|  | 8495 | @Override | 
|  | 8496 | public List<String> getEmergencyNumberListTestMode() { | 
|  | 8497 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 8498 | "getEmergencyNumberListTestMode"); | 
|  | 8499 |  | 
|  | 8500 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8501 | try { | 
|  | 8502 | Set<String> emergencyNumbers = new HashSet<>(); | 
|  | 8503 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8504 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 8505 | if (tracker != null) { | 
|  | 8506 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { | 
|  | 8507 | emergencyNumbers.add(num.getNumber()); | 
|  | 8508 | } | 
|  | 8509 | } | 
|  | 8510 | } | 
|  | 8511 | return new ArrayList<>(emergencyNumbers); | 
|  | 8512 | } finally { | 
|  | 8513 | Binder.restoreCallingIdentity(identity); | 
|  | 8514 | } | 
|  | 8515 | } | 
|  | 8516 |  | 
| chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8517 | @Override | 
| Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8518 | public int getEmergencyNumberDbVersion(int subId) { | 
|  | 8519 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); | 
|  | 8520 |  | 
|  | 8521 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8522 | try { | 
|  | 8523 | final Phone phone = getPhone(subId); | 
|  | 8524 | if (phone == null) { | 
|  | 8525 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); | 
|  | 8526 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; | 
|  | 8527 | } | 
|  | 8528 | return phone.getEmergencyNumberDbVersion(); | 
|  | 8529 | } finally { | 
|  | 8530 | Binder.restoreCallingIdentity(identity); | 
|  | 8531 | } | 
|  | 8532 | } | 
|  | 8533 |  | 
|  | 8534 | @Override | 
|  | 8535 | public void notifyOtaEmergencyNumberDbInstalled() { | 
|  | 8536 | enforceModifyPermission(); | 
|  | 8537 |  | 
|  | 8538 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8539 | try { | 
|  | 8540 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8541 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 8542 | if (tracker != null) { | 
|  | 8543 | tracker.updateOtaEmergencyNumberDatabase(); | 
|  | 8544 | } | 
|  | 8545 | } | 
|  | 8546 | } finally { | 
|  | 8547 | Binder.restoreCallingIdentity(identity); | 
|  | 8548 | } | 
|  | 8549 | } | 
|  | 8550 |  | 
|  | 8551 | @Override | 
| Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8552 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { | 
| Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8553 | enforceActiveEmergencySessionPermission(); | 
|  | 8554 |  | 
|  | 8555 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8556 | try { | 
|  | 8557 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8558 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 8559 | if (tracker != null) { | 
| Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8560 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); | 
|  | 8561 | } | 
|  | 8562 | } | 
|  | 8563 | } finally { | 
|  | 8564 | Binder.restoreCallingIdentity(identity); | 
|  | 8565 | } | 
|  | 8566 | } | 
|  | 8567 |  | 
|  | 8568 | @Override | 
|  | 8569 | public void resetOtaEmergencyNumberDbFilePath() { | 
|  | 8570 | enforceActiveEmergencySessionPermission(); | 
|  | 8571 |  | 
|  | 8572 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8573 | try { | 
|  | 8574 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 8575 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 8576 | if (tracker != null) { | 
|  | 8577 | tracker.resetOtaEmergencyNumberDbFilePath(); | 
| Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8578 | } | 
|  | 8579 | } | 
|  | 8580 | } finally { | 
|  | 8581 | Binder.restoreCallingIdentity(identity); | 
|  | 8582 | } | 
|  | 8583 | } | 
|  | 8584 |  | 
|  | 8585 | @Override | 
| chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8586 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { | 
|  | 8587 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); | 
|  | 8588 | Phone phone = getPhone(subId); | 
|  | 8589 | if (phone == null) { | 
|  | 8590 | return null; | 
|  | 8591 | } | 
|  | 8592 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8593 | try { | 
|  | 8594 | UiccProfile profile = UiccController.getInstance() | 
|  | 8595 | .getUiccProfileForPhone(phone.getPhoneId()); | 
|  | 8596 | if (profile != null) { | 
|  | 8597 | return profile.getCertsFromCarrierPrivilegeAccessRules(); | 
|  | 8598 | } | 
|  | 8599 | } finally { | 
|  | 8600 | Binder.restoreCallingIdentity(identity); | 
|  | 8601 | } | 
|  | 8602 | return null; | 
|  | 8603 | } | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8604 |  | 
|  | 8605 | /** | 
|  | 8606 | * Enable or disable a modem stack. | 
|  | 8607 | */ | 
|  | 8608 | @Override | 
|  | 8609 | public boolean enableModemForSlot(int slotIndex, boolean enable) { | 
|  | 8610 | enforceModifyPermission(); | 
|  | 8611 |  | 
|  | 8612 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8613 | try { | 
|  | 8614 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 8615 | if (phone == null) { | 
|  | 8616 | return false; | 
|  | 8617 | } else { | 
|  | 8618 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); | 
|  | 8619 | } | 
|  | 8620 | } finally { | 
|  | 8621 | Binder.restoreCallingIdentity(identity); | 
|  | 8622 | } | 
|  | 8623 | } | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8624 |  | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8625 | /** | 
|  | 8626 | * Whether a modem stack is enabled or not. | 
|  | 8627 | */ | 
|  | 8628 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8629 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, | 
|  | 8630 | String callingFeatureId) { | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8631 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 8632 | if (phone == null) return false; | 
|  | 8633 |  | 
|  | 8634 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8635 | mApp, phone.getSubId(), callingPackage, callingFeatureId, | 
|  | 8636 | "isModemEnabledForSlot")) { | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8637 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 8638 | } | 
|  | 8639 |  | 
|  | 8640 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8641 | try { | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8642 | try { | 
|  | 8643 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); | 
|  | 8644 | } catch (NoSuchElementException ex) { | 
|  | 8645 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); | 
|  | 8646 | } | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8647 | } finally { | 
|  | 8648 | Binder.restoreCallingIdentity(identity); | 
|  | 8649 | } | 
|  | 8650 | } | 
|  | 8651 |  | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8652 | @Override | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8653 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8654 | enforceModifyPermission(); | 
|  | 8655 |  | 
|  | 8656 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8657 | try { | 
|  | 8658 | mTelephonySharedPreferences.edit() | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8659 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8660 | .commit(); | 
|  | 8661 | } finally { | 
|  | 8662 | Binder.restoreCallingIdentity(identity); | 
|  | 8663 | } | 
|  | 8664 | } | 
|  | 8665 |  | 
|  | 8666 | @Override | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8667 | @TelephonyManager.IsMultiSimSupportedResult | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8668 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { | 
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8669 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8670 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, | 
|  | 8671 | "isMultiSimSupported")) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8672 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8673 | } | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8674 |  | 
|  | 8675 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8676 | try { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8677 | return isMultiSimSupportedInternal(); | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8678 | } finally { | 
|  | 8679 | Binder.restoreCallingIdentity(identity); | 
|  | 8680 | } | 
|  | 8681 | } | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8682 |  | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8683 | @TelephonyManager.IsMultiSimSupportedResult | 
|  | 8684 | private int isMultiSimSupportedInternal() { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8685 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. | 
|  | 8686 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; | 
|  | 8687 | if (numPhysicalSlots < 2) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8688 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); | 
|  | 8689 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8690 | } | 
|  | 8691 | // Check if the hardware supports multisim functionality. If usage of multisim is not | 
|  | 8692 | // supported by the modem, indicate that it is restricted. | 
|  | 8693 | PhoneCapability staticCapability = | 
|  | 8694 | mPhoneConfigurationManager.getStaticPhoneCapability(); | 
|  | 8695 | if (staticCapability == null) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8696 | loge("isMultiSimSupportedInternal: no static configuration available"); | 
|  | 8697 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8698 | } | 
| Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8699 | if (staticCapability.logicalModemList.size() < 2) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8700 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); | 
|  | 8701 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8702 | } | 
|  | 8703 | // Check if support of multiple SIMs is restricted by carrier | 
|  | 8704 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8705 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8706 | } | 
|  | 8707 |  | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8708 | return TelephonyManager.MULTISIM_ALLOWED; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8709 | } | 
|  | 8710 |  | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8711 | /** | 
|  | 8712 | * Switch configs to enable multi-sim or switch back to single-sim | 
| Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8713 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE | 
|  | 8714 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE | 
|  | 8715 | * or carrier privileges | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8716 | * @param numOfSims number of active sims we want to switch to | 
|  | 8717 | */ | 
|  | 8718 | @Override | 
|  | 8719 | public void switchMultiSimConfig(int numOfSims) { | 
| Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8720 | if (numOfSims == 1) { | 
|  | 8721 | enforceModifyPermission(); | 
|  | 8722 | } else { | 
|  | 8723 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 8724 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); | 
|  | 8725 | } | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8726 | final long identity = Binder.clearCallingIdentity(); | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8727 |  | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8728 | try { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8729 | //only proceed if multi-sim is not restricted | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8730 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8731 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); | 
|  | 8732 | return; | 
|  | 8733 | } | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8734 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); | 
|  | 8735 | } finally { | 
|  | 8736 | Binder.restoreCallingIdentity(identity); | 
|  | 8737 | } | 
|  | 8738 | } | 
|  | 8739 |  | 
| Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8740 | @Override | 
|  | 8741 | public boolean isApplicationOnUicc(int subId, int appType) { | 
|  | 8742 | enforceReadPrivilegedPermission("isApplicationOnUicc"); | 
|  | 8743 | Phone phone = getPhone(subId); | 
|  | 8744 | if (phone == null) { | 
|  | 8745 | return false; | 
|  | 8746 | } | 
|  | 8747 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8748 | try { | 
|  | 8749 | UiccCard uiccCard = phone.getUiccCard(); | 
|  | 8750 | if (uiccCard == null) { | 
|  | 8751 | return false; | 
|  | 8752 | } | 
|  | 8753 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); | 
|  | 8754 | if (uiccProfile == null) { | 
|  | 8755 | return false; | 
|  | 8756 | } | 
|  | 8757 | if (TelephonyManager.APPTYPE_SIM <= appType | 
|  | 8758 | && appType <= TelephonyManager.APPTYPE_ISIM) { | 
|  | 8759 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); | 
|  | 8760 | } | 
|  | 8761 | return false; | 
|  | 8762 | } finally { | 
|  | 8763 | Binder.restoreCallingIdentity(identity); | 
|  | 8764 | } | 
|  | 8765 | } | 
|  | 8766 |  | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8767 | /** | 
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8768 | * Get whether making changes to modem configurations will trigger reboot. | 
|  | 8769 | * Return value defaults to true. | 
| Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8770 | */ | 
|  | 8771 | @Override | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8772 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, | 
|  | 8773 | String callingFeatureId) { | 
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8774 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8775 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 8776 | "doesSwitchMultiSimConfigTriggerReboot")) { | 
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8777 | return false; | 
|  | 8778 | } | 
| Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8779 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8780 | try { | 
|  | 8781 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); | 
|  | 8782 | } finally { | 
|  | 8783 | Binder.restoreCallingIdentity(identity); | 
|  | 8784 | } | 
|  | 8785 | } | 
|  | 8786 |  | 
| Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8787 | private void updateModemStateMetrics() { | 
|  | 8788 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); | 
|  | 8789 | // TODO: check the state for each modem if the api is ready. | 
|  | 8790 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); | 
|  | 8791 | } | 
|  | 8792 |  | 
| Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8793 | @Override | 
|  | 8794 | public int[] getSlotsMapping() { | 
|  | 8795 | enforceReadPrivilegedPermission("getSlotsMapping"); | 
|  | 8796 |  | 
|  | 8797 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8798 | try { | 
|  | 8799 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); | 
|  | 8800 | // All logical slots should have a mapping to a physical slot. | 
|  | 8801 | int[] logicalSlotsMapping = new int[phoneCount]; | 
|  | 8802 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); | 
|  | 8803 | for (int i = 0; i < slotInfos.length; i++) { | 
|  | 8804 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { | 
|  | 8805 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; | 
|  | 8806 | } | 
|  | 8807 | } | 
|  | 8808 | return logicalSlotsMapping; | 
|  | 8809 | } finally { | 
|  | 8810 | Binder.restoreCallingIdentity(identity); | 
|  | 8811 | } | 
|  | 8812 | } | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8813 |  | 
|  | 8814 | /** | 
|  | 8815 | * Get the IRadio HAL Version | 
|  | 8816 | */ | 
|  | 8817 | @Override | 
|  | 8818 | public int getRadioHalVersion() { | 
|  | 8819 | Phone phone = getDefaultPhone(); | 
|  | 8820 | if (phone == null) return -1; | 
|  | 8821 | HalVersion hv = phone.getHalVersion(); | 
|  | 8822 | if (hv.equals(HalVersion.UNKNOWN)) return -1; | 
|  | 8823 | return hv.major * 100 + hv.minor; | 
|  | 8824 | } | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8825 |  | 
|  | 8826 | /** | 
| Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8827 | * Get the current calling package name. | 
|  | 8828 | * @return the current calling package name | 
|  | 8829 | */ | 
|  | 8830 | @Override | 
|  | 8831 | public String getCurrentPackageName() { | 
|  | 8832 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; | 
|  | 8833 | } | 
|  | 8834 |  | 
|  | 8835 | /** | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8836 | * Return whether data is enabled for certain APN type. This will tell if framework will accept | 
|  | 8837 | * corresponding network requests on a subId. | 
|  | 8838 | * | 
|  | 8839 | *  Data is enabled if: | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8840 | *  1) user data is turned on, or | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8841 | *  2) APN is un-metered for this subscription, or | 
|  | 8842 | *  3) APN type is whitelisted. E.g. MMS is whitelisted if | 
| Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8843 | *  {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8844 | * | 
|  | 8845 | * @return whether data is allowed for a apn type. | 
|  | 8846 | * | 
|  | 8847 | * @hide | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8848 | */ | 
|  | 8849 | @Override | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8850 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { | 
| Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8851 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " | 
|  | 8852 | + "isDataEnabledForApn"); | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8853 |  | 
|  | 8854 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 8855 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8856 | try { | 
|  | 8857 | Phone phone = getPhone(subId); | 
|  | 8858 | if (phone == null) return false; | 
|  | 8859 |  | 
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8860 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8861 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); | 
|  | 8862 | } finally { | 
|  | 8863 | Binder.restoreCallingIdentity(identity); | 
|  | 8864 | } | 
|  | 8865 | } | 
|  | 8866 |  | 
|  | 8867 | @Override | 
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8868 | public boolean isApnMetered(@ApnType int apnType, int subId) { | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8869 | enforceReadPrivilegedPermission("isApnMetered"); | 
|  | 8870 |  | 
|  | 8871 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 8872 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8873 | try { | 
|  | 8874 | Phone phone = getPhone(subId); | 
|  | 8875 | if (phone == null) return true; // By default return true. | 
|  | 8876 |  | 
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8877 | return ApnSettingUtils.isMeteredApnType(apnType, phone); | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8878 | } finally { | 
|  | 8879 | Binder.restoreCallingIdentity(identity); | 
|  | 8880 | } | 
|  | 8881 | } | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8882 |  | 
|  | 8883 | @Override | 
| Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8884 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, | 
|  | 8885 | int subscriptionId, IBooleanConsumer resultCallback) { | 
|  | 8886 | enforceModifyPermission(); | 
|  | 8887 | long token = Binder.clearCallingIdentity(); | 
|  | 8888 | try { | 
|  | 8889 | Phone phone = getPhone(subscriptionId); | 
|  | 8890 | if (phone == null) { | 
|  | 8891 | try { | 
|  | 8892 | if (resultCallback != null) { | 
|  | 8893 | resultCallback.accept(false); | 
|  | 8894 | } | 
|  | 8895 | } catch (RemoteException e) { | 
|  | 8896 | // ignore | 
|  | 8897 | } | 
|  | 8898 | return; | 
|  | 8899 | } | 
|  | 8900 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = | 
|  | 8901 | Pair.create(specifiers, (x) -> { | 
|  | 8902 | try { | 
|  | 8903 | if (resultCallback != null) { | 
|  | 8904 | resultCallback.accept(x); | 
|  | 8905 | } | 
|  | 8906 | } catch (RemoteException e) { | 
|  | 8907 | // ignore | 
|  | 8908 | } | 
|  | 8909 | }); | 
|  | 8910 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); | 
|  | 8911 | } finally { | 
|  | 8912 | Binder.restoreCallingIdentity(token); | 
|  | 8913 | } | 
|  | 8914 | } | 
|  | 8915 |  | 
|  | 8916 | @Override | 
| Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8917 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { | 
|  | 8918 | TelephonyPermissions | 
|  | 8919 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 8920 | mApp, subId, "getSystemSelectionChannels"); | 
|  | 8921 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 8922 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8923 | try { | 
|  | 8924 | List<RadioAccessSpecifier> specifiers = | 
|  | 8925 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, | 
|  | 8926 | null, subId, workSource); | 
|  | 8927 | if (DBG) log("getSystemSelectionChannels: " + specifiers); | 
|  | 8928 | return specifiers; | 
|  | 8929 | } finally { | 
|  | 8930 | Binder.restoreCallingIdentity(identity); | 
|  | 8931 | } | 
|  | 8932 | } | 
|  | 8933 |  | 
|  | 8934 | @Override | 
| changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8935 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { | 
| changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8936 | enforceReadPrivilegedPermission("isMvnoMatched"); | 
| changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8937 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( | 
|  | 8938 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); | 
|  | 8939 | if (iccRecords == null) { | 
|  | 8940 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); | 
|  | 8941 | return false; | 
|  | 8942 | } | 
|  | 8943 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); | 
|  | 8944 | } | 
|  | 8945 |  | 
|  | 8946 | @Override | 
| Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8947 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, | 
|  | 8948 | IIntegerConsumer pendingSubIdResult) { | 
| Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8949 | if (callingPackage == null) { | 
|  | 8950 | callingPackage = getCurrentPackageName(); | 
|  | 8951 | } | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8952 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, | 
|  | 8953 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); | 
| Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8954 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, | 
|  | 8955 | "Sending message")) { | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8956 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); | 
|  | 8957 | } | 
|  | 8958 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); | 
|  | 8959 | Intent intent = new Intent(); | 
|  | 8960 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); | 
|  | 8961 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 8962 | // Bring up choose default SMS subscription dialog right now | 
|  | 8963 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, | 
|  | 8964 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); | 
|  | 8965 | mApp.startActivity(intent); | 
|  | 8966 | } | 
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8967 |  | 
|  | 8968 | @Override | 
|  | 8969 | public String getMmsUAProfUrl(int subId) { | 
|  | 8970 | //TODO investigate if this API should require proper permission check in R b/133791609 | 
|  | 8971 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8972 | try { | 
| Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8973 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( | 
|  | 8974 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); | 
|  | 8975 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { | 
|  | 8976 | return carrierUAProfUrl; | 
|  | 8977 | } | 
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8978 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) | 
|  | 8979 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); | 
|  | 8980 | } finally { | 
|  | 8981 | Binder.restoreCallingIdentity(identity); | 
|  | 8982 | } | 
|  | 8983 | } | 
|  | 8984 |  | 
|  | 8985 | @Override | 
|  | 8986 | public String getMmsUserAgent(int subId) { | 
|  | 8987 | //TODO investigate if this API should require proper permission check in R b/133791609 | 
|  | 8988 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8989 | try { | 
| Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8990 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( | 
|  | 8991 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); | 
|  | 8992 | if (!TextUtils.isEmpty(carrierUserAgent)) { | 
|  | 8993 | return carrierUserAgent; | 
|  | 8994 | } | 
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8995 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) | 
|  | 8996 | .getString(com.android.internal.R.string.config_mms_user_agent); | 
|  | 8997 | } finally { | 
|  | 8998 | Binder.restoreCallingIdentity(identity); | 
|  | 8999 | } | 
|  | 9000 | } | 
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9001 |  | 
|  | 9002 | @Override | 
| Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9003 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { | 
|  | 9004 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); | 
|  | 9005 |  | 
|  | 9006 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9007 | try { | 
|  | 9008 | Phone phone = getPhone(subscriptionId); | 
|  | 9009 | if (phone == null) return false; | 
|  | 9010 |  | 
|  | 9011 | switch (policy) { | 
|  | 9012 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: | 
|  | 9013 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); | 
|  | 9014 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: | 
|  | 9015 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); | 
|  | 9016 | default: | 
|  | 9017 | throw new IllegalArgumentException(policy + " is not a valid policy"); | 
|  | 9018 | } | 
|  | 9019 | } finally { | 
|  | 9020 | Binder.restoreCallingIdentity(identity); | 
|  | 9021 | } | 
|  | 9022 | } | 
|  | 9023 |  | 
|  | 9024 | @Override | 
|  | 9025 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, | 
|  | 9026 | boolean enabled) { | 
|  | 9027 | enforceModifyPermission(); | 
|  | 9028 |  | 
|  | 9029 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9030 | try { | 
|  | 9031 | Phone phone = getPhone(subscriptionId); | 
|  | 9032 | if (phone == null) return; | 
|  | 9033 |  | 
|  | 9034 | switch (policy) { | 
|  | 9035 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: | 
|  | 9036 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); | 
|  | 9037 | break; | 
|  | 9038 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: | 
|  | 9039 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); | 
|  | 9040 | break; | 
|  | 9041 | default: | 
|  | 9042 | throw new IllegalArgumentException(policy + " is not a valid policy"); | 
|  | 9043 | } | 
|  | 9044 | } finally { | 
|  | 9045 | Binder.restoreCallingIdentity(identity); | 
|  | 9046 | } | 
|  | 9047 | } | 
|  | 9048 |  | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9049 | /** | 
| Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9050 | * Updates whether conference event package handling is enabled. | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9051 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} | 
|  | 9052 | *                                 otherwise. | 
|  | 9053 | */ | 
|  | 9054 | @Override | 
|  | 9055 | public void setCepEnabled(boolean isCepEnabled) { | 
|  | 9056 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); | 
|  | 9057 |  | 
|  | 9058 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9059 | try { | 
|  | 9060 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); | 
|  | 9061 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 9062 | Phone defaultPhone = phone.getImsPhone(); | 
|  | 9063 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { | 
|  | 9064 | ImsPhone imsPhone = (ImsPhone) defaultPhone; | 
|  | 9065 | ImsPhoneCallTracker imsPhoneCallTracker = | 
|  | 9066 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); | 
|  | 9067 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); | 
|  | 9068 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " | 
|  | 9069 | + imsPhone.getMsisdn()); | 
|  | 9070 | } | 
|  | 9071 | } | 
|  | 9072 | } finally { | 
|  | 9073 | Binder.restoreCallingIdentity(identity); | 
|  | 9074 | } | 
|  | 9075 | } | 
| allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9076 |  | 
|  | 9077 | /** | 
|  | 9078 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. | 
|  | 9079 | * | 
|  | 9080 | * @param config       The XML file to be read. ASCII/UTF8 encoded text if not compressed. | 
|  | 9081 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed | 
|  | 9082 | *                     before being read. | 
|  | 9083 | */ | 
|  | 9084 | @Override | 
|  | 9085 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean | 
|  | 9086 | isCompressed) { | 
|  | 9087 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 9088 | mApp, subId, "notifyRcsAutoConfigurationReceived"); | 
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9089 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 9090 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 9091 | } | 
|  | 9092 | if (!isImsAvailableOnDevice()) { | 
|  | 9093 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 9094 | "IMS not available on device."); | 
|  | 9095 | } | 
|  | 9096 |  | 
|  | 9097 | final long identity = Binder.clearCallingIdentity(); | 
| allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9098 | try { | 
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9099 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); | 
|  | 9100 | } finally { | 
|  | 9101 | Binder.restoreCallingIdentity(identity); | 
| allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9102 | } | 
|  | 9103 | } | 
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9104 |  | 
|  | 9105 | @Override | 
|  | 9106 | public boolean isIccLockEnabled(int subId) { | 
|  | 9107 | enforceReadPrivilegedPermission("isIccLockEnabled"); | 
|  | 9108 |  | 
|  | 9109 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 9110 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9111 | try { | 
|  | 9112 | Phone phone = getPhone(subId); | 
|  | 9113 | if (phone != null && phone.getIccCard() != null) { | 
|  | 9114 | return phone.getIccCard().getIccLockEnabled(); | 
|  | 9115 | } else { | 
|  | 9116 | return false; | 
|  | 9117 | } | 
|  | 9118 | } finally { | 
|  | 9119 | Binder.restoreCallingIdentity(identity); | 
|  | 9120 | } | 
|  | 9121 | } | 
|  | 9122 |  | 
|  | 9123 | /** | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9124 | * Set the ICC pin lock enabled or disabled. | 
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9125 | * | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9126 | * @return an integer representing the status of IccLock enabled or disabled in the following | 
|  | 9127 | * three cases: | 
|  | 9128 | *   - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock | 
|  | 9129 | *   successfully. | 
|  | 9130 | *   - Positive number and zero for remaining password attempts. | 
|  | 9131 | *   - Negative number for other failure cases (such like enabling/disabling PIN failed). | 
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9132 | * | 
|  | 9133 | */ | 
|  | 9134 | @Override | 
|  | 9135 | public int setIccLockEnabled(int subId, boolean enabled, String password) { | 
|  | 9136 | enforceModifyPermission(); | 
|  | 9137 |  | 
|  | 9138 | Phone phone = getPhone(subId); | 
|  | 9139 | if (phone == null) { | 
|  | 9140 | return 0; | 
|  | 9141 | } | 
|  | 9142 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 9143 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9144 | try { | 
|  | 9145 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, | 
|  | 9146 | new Pair<Boolean, String>(enabled, password), phone, null); | 
|  | 9147 | return attemptsRemaining; | 
|  | 9148 |  | 
|  | 9149 | } catch (Exception e) { | 
|  | 9150 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); | 
|  | 9151 | } finally { | 
|  | 9152 | Binder.restoreCallingIdentity(identity); | 
|  | 9153 | } | 
|  | 9154 | return 0; | 
|  | 9155 | } | 
|  | 9156 |  | 
|  | 9157 | /** | 
|  | 9158 | * Change the ICC password used in ICC pin lock. | 
|  | 9159 | * | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9160 | * @return an integer representing the status of IccLock changed in the following three cases: | 
|  | 9161 | *   - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. | 
|  | 9162 | *   - Positive number and zero for remaining password attempts. | 
|  | 9163 | *   - Negative number for other failure cases (such like enabling/disabling PIN failed). | 
| zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9164 | * | 
|  | 9165 | */ | 
|  | 9166 | @Override | 
|  | 9167 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { | 
|  | 9168 | enforceModifyPermission(); | 
|  | 9169 |  | 
|  | 9170 | Phone phone = getPhone(subId); | 
|  | 9171 | if (phone == null) { | 
|  | 9172 | return 0; | 
|  | 9173 | } | 
|  | 9174 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 9175 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9176 | try { | 
|  | 9177 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, | 
|  | 9178 | new Pair<String, String>(oldPassword, newPassword), phone, null); | 
|  | 9179 | return attemptsRemaining; | 
|  | 9180 |  | 
|  | 9181 | } catch (Exception e) { | 
|  | 9182 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); | 
|  | 9183 | } finally { | 
|  | 9184 | Binder.restoreCallingIdentity(identity); | 
|  | 9185 | } | 
|  | 9186 | return 0; | 
|  | 9187 | } | 
| Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9188 |  | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9189 | /** | 
|  | 9190 | * Request for receiving user activity notification | 
|  | 9191 | */ | 
|  | 9192 | @Override | 
|  | 9193 | public void requestUserActivityNotification() { | 
|  | 9194 | if (!mNotifyUserActivity.get() | 
|  | 9195 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { | 
|  | 9196 | mNotifyUserActivity.set(true); | 
|  | 9197 | } | 
|  | 9198 | } | 
|  | 9199 |  | 
|  | 9200 | /** | 
|  | 9201 | * Called when userActivity is signalled in the power manager. | 
|  | 9202 | * This is safe to call from any thread, with any window manager locks held or not. | 
|  | 9203 | */ | 
|  | 9204 | @Override | 
|  | 9205 | public void userActivity() { | 
|  | 9206 | // *************************************** | 
|  | 9207 | // *  Inherited from PhoneWindowManager  * | 
|  | 9208 | // *************************************** | 
|  | 9209 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER | 
|  | 9210 | // WITH ITS LOCKS HELD. | 
|  | 9211 | // | 
|  | 9212 | // This code must be VERY careful about the locks | 
|  | 9213 | // it acquires. | 
|  | 9214 | // In fact, the current code acquires way too many, | 
|  | 9215 | // and probably has lurking deadlocks. | 
|  | 9216 |  | 
|  | 9217 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { | 
|  | 9218 | throw new SecurityException("Only the OS may call notifyUserActivity()"); | 
|  | 9219 | } | 
|  | 9220 |  | 
|  | 9221 | if (mNotifyUserActivity.getAndSet(false)) { | 
|  | 9222 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, | 
|  | 9223 | USER_ACTIVITY_NOTIFICATION_DELAY); | 
|  | 9224 | } | 
|  | 9225 | } | 
| Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9226 |  | 
| Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9227 | @Override | 
|  | 9228 | public boolean canConnectTo5GInDsdsMode() { | 
|  | 9229 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); | 
|  | 9230 | } | 
| Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9231 |  | 
|  | 9232 | @Override | 
|  | 9233 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, | 
|  | 9234 | String callingFeatureId) { | 
|  | 9235 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 9236 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { | 
|  | 9237 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 9238 | } | 
|  | 9239 |  | 
|  | 9240 | Phone phone = getPhone(subId); | 
|  | 9241 | if (phone == null) { | 
|  | 9242 | throw new RuntimeException("phone is not available"); | 
|  | 9243 | } | 
|  | 9244 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 9245 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9246 | try { | 
|  | 9247 | return phone.getEquivalentHomePlmns(); | 
|  | 9248 | } finally { | 
|  | 9249 | Binder.restoreCallingIdentity(identity); | 
|  | 9250 | } | 
|  | 9251 | } | 
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9252 |  | 
| Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9253 | @Override | 
|  | 9254 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, | 
|  | 9255 | UaSecurityProtocolIdentifier securityProtocol, | 
|  | 9256 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) | 
|  | 9257 | throws RemoteException { | 
|  | 9258 | enforceModifyPermission(); | 
|  | 9259 | if (DBG) { | 
|  | 9260 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" | 
|  | 9261 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol | 
|  | 9262 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); | 
|  | 9263 | } | 
|  | 9264 |  | 
|  | 9265 | if (!SubscriptionManager.isValidSubscriptionId(subId) | 
|  | 9266 | || appType < TelephonyManager.APPTYPE_UNKNOWN | 
|  | 9267 | || appType > TelephonyManager.APPTYPE_ISIM | 
|  | 9268 | || nafUrl == null || securityProtocol == null || callback == null) { | 
|  | 9269 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); | 
|  | 9270 | if (callback != null) { | 
|  | 9271 | try { | 
|  | 9272 | callback.onAuthenticationFailure( | 
|  | 9273 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); | 
|  | 9274 | } catch (RemoteException exception) { | 
|  | 9275 | log("Fail to notify onAuthenticationFailure due to " + exception); | 
|  | 9276 | } | 
|  | 9277 | return; | 
|  | 9278 | } | 
|  | 9279 | } | 
|  | 9280 |  | 
|  | 9281 | final long token = Binder.clearCallingIdentity(); | 
|  | 9282 | try { | 
|  | 9283 | getGbaManager(subId).bootstrapAuthenticationRequest( | 
|  | 9284 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), | 
|  | 9285 | forceBootStrapping, callback)); | 
|  | 9286 | } finally { | 
|  | 9287 | Binder.restoreCallingIdentity(token); | 
|  | 9288 | } | 
|  | 9289 | } | 
|  | 9290 |  | 
| Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9291 | /** | 
|  | 9292 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the | 
|  | 9293 | * requested radio power state will actually be set. See {@link | 
|  | 9294 | * PhoneInternalInterface#setRadioPowerForReason} for more details. | 
|  | 9295 | * | 
|  | 9296 | * @param subId the subscription ID of the phone requesting to set the radio power state. | 
|  | 9297 | * @param enable {@code true} if trying to turn radio on. | 
|  | 9298 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code | 
|  | 9299 | * false}. | 
|  | 9300 | */ | 
|  | 9301 | private boolean setRadioPowerForThermal(int subId, boolean enable) { | 
|  | 9302 | Phone phone = getPhone(subId); | 
|  | 9303 | if (phone != null) { | 
|  | 9304 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); | 
|  | 9305 | return true; | 
|  | 9306 | } | 
|  | 9307 | return false; | 
|  | 9308 | } | 
|  | 9309 |  | 
|  | 9310 | private int handleDataThrottlingRequest(int subId, | 
|  | 9311 | DataThrottlingRequest dataThrottlingRequest) { | 
|  | 9312 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return | 
|  | 9313 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. | 
|  | 9314 | if (!setRadioPowerForThermal(subId, true)) { | 
|  | 9315 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 9316 | } | 
|  | 9317 |  | 
|  | 9318 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); | 
|  | 9319 |  | 
|  | 9320 | int thermalMitigationResult = | 
|  | 9321 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); | 
|  | 9322 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { | 
|  | 9323 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); | 
|  | 9324 | } | 
|  | 9325 | return thermalMitigationResult; | 
|  | 9326 | } | 
|  | 9327 |  | 
|  | 9328 | /** | 
|  | 9329 | * Thermal mitigation request to control functionalities at modem. | 
|  | 9330 | * | 
|  | 9331 | * @param subId the id of the subscription. | 
|  | 9332 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. | 
|  | 9333 | * | 
|  | 9334 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. | 
|  | 9335 | */ | 
|  | 9336 | @Override | 
|  | 9337 | @ThermalMitigationResult | 
|  | 9338 | public int sendThermalMitigationRequest( | 
|  | 9339 | int subId, | 
|  | 9340 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { | 
|  | 9341 | enforceModifyPermission(); | 
|  | 9342 |  | 
|  | 9343 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 9344 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9345 |  | 
|  | 9346 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; | 
|  | 9347 | try { | 
|  | 9348 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); | 
|  | 9349 | switch (thermalMitigationAction) { | 
|  | 9350 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: | 
|  | 9351 | thermalMitigationResult = | 
|  | 9352 | handleDataThrottlingRequest(subId, | 
|  | 9353 | thermalMitigationRequest.getDataThrottlingRequest()); | 
|  | 9354 | break; | 
|  | 9355 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: | 
|  | 9356 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { | 
|  | 9357 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " | 
|  | 9358 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); | 
|  | 9359 | } | 
|  | 9360 |  | 
|  | 9361 | // Ensure that radio is on. If not able to power on due to phone being | 
|  | 9362 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. | 
|  | 9363 | if (!setRadioPowerForThermal(subId, true)) { | 
|  | 9364 | thermalMitigationResult = | 
|  | 9365 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 9366 | break; | 
|  | 9367 | } | 
|  | 9368 |  | 
|  | 9369 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, | 
|  | 9370 | false); | 
|  | 9371 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; | 
|  | 9372 | break; | 
|  | 9373 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: | 
|  | 9374 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { | 
|  | 9375 | throw new IllegalArgumentException("dataThrottlingRequest  must be null for" | 
|  | 9376 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); | 
|  | 9377 | } | 
|  | 9378 |  | 
|  | 9379 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); | 
|  | 9380 | if (registry != null) { | 
|  | 9381 | TelephonyConnectionService service = | 
|  | 9382 | registry.getTelephonyConnectionService(); | 
|  | 9383 | Phone phone = getPhone(subId); | 
|  | 9384 | if (phone == null) { | 
|  | 9385 | thermalMitigationResult = | 
|  | 9386 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 9387 | break; | 
|  | 9388 | } | 
|  | 9389 |  | 
|  | 9390 | if (PhoneConstantConversions.convertCallState(phone.getState()) | 
|  | 9391 | != TelephonyManager.CALL_STATE_IDLE | 
|  | 9392 | || phone.isInEmergencySmsMode() || phone.isInEcm() | 
|  | 9393 | || (service != null && service.isEmergencyCallPending())) { | 
|  | 9394 | String errorMessage = "Phone state is not valid. call state = " | 
|  | 9395 | + PhoneConstantConversions.convertCallState(phone.getState()) | 
|  | 9396 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() | 
|  | 9397 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); | 
|  | 9398 | errorMessage += service == null | 
|  | 9399 | ? " TelephonyConnectionService is null" | 
|  | 9400 | : " isEmergencyCallPending = " | 
|  | 9401 | + service.isEmergencyCallPending(); | 
|  | 9402 | Log.e(LOG_TAG, errorMessage); | 
|  | 9403 | thermalMitigationResult = | 
|  | 9404 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; | 
|  | 9405 | break; | 
|  | 9406 | } | 
|  | 9407 | } else { | 
|  | 9408 | thermalMitigationResult = | 
|  | 9409 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 9410 | break; | 
|  | 9411 | } | 
|  | 9412 |  | 
|  | 9413 | // Turn radio off. If not able to power off due to phone being unavailable, | 
|  | 9414 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. | 
|  | 9415 | if (!setRadioPowerForThermal(subId, false)) { | 
|  | 9416 | thermalMitigationResult = | 
|  | 9417 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 9418 | break; | 
|  | 9419 | } | 
|  | 9420 | thermalMitigationResult = | 
|  | 9421 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; | 
|  | 9422 | break; | 
|  | 9423 | default: | 
|  | 9424 | throw new IllegalArgumentException("the requested thermalMitigationAction does " | 
|  | 9425 | + "not exist. Requested action: " + thermalMitigationAction); | 
|  | 9426 | } | 
|  | 9427 | } catch (IllegalArgumentException e) { | 
|  | 9428 | throw e; | 
|  | 9429 | } catch (Exception e) { | 
|  | 9430 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); | 
|  | 9431 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; | 
|  | 9432 | } finally { | 
|  | 9433 | Binder.restoreCallingIdentity(identity); | 
|  | 9434 | } | 
|  | 9435 |  | 
|  | 9436 | if (DBG) { | 
|  | 9437 | log("thermalMitigationRequest returning with thermalMitigationResult: " | 
|  | 9438 | + thermalMitigationResult); | 
|  | 9439 | } | 
|  | 9440 |  | 
|  | 9441 | return thermalMitigationResult; | 
|  | 9442 | } | 
| Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9443 |  | 
|  | 9444 | /** | 
|  | 9445 | * Set the GbaService Package Name that Telephony will bind to. | 
|  | 9446 | * | 
|  | 9447 | * @param subId The sim that the GbaService is associated with. | 
|  | 9448 | * @param packageName The name of the package to be replaced with. | 
|  | 9449 | * @return true if setting the GbaService to bind to succeeded, false if it did not. | 
|  | 9450 | */ | 
|  | 9451 | @Override | 
|  | 9452 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { | 
|  | 9453 | enforceModifyPermission(); | 
|  | 9454 |  | 
|  | 9455 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9456 | try { | 
|  | 9457 | return getGbaManager(subId).overrideServicePackage(packageName); | 
|  | 9458 | } finally { | 
|  | 9459 | Binder.restoreCallingIdentity(identity); | 
|  | 9460 | } | 
|  | 9461 | } | 
|  | 9462 |  | 
|  | 9463 | /** | 
|  | 9464 | * Return the package name of the currently bound GbaService. | 
|  | 9465 | * | 
|  | 9466 | * @param subId The sim that the GbaService is associated with. | 
|  | 9467 | * @return the package name of the GbaService configuration, null if GBA is not supported. | 
|  | 9468 | */ | 
|  | 9469 | @Override | 
|  | 9470 | public String getBoundGbaService(int subId) { | 
|  | 9471 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); | 
|  | 9472 |  | 
|  | 9473 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9474 | try { | 
|  | 9475 | return getGbaManager(subId).getServicePackage(); | 
|  | 9476 | } finally { | 
|  | 9477 | Binder.restoreCallingIdentity(identity); | 
|  | 9478 | } | 
|  | 9479 | } | 
|  | 9480 |  | 
|  | 9481 | /** | 
|  | 9482 | * Set the release time for telephony to unbind GbaService. | 
|  | 9483 | * | 
|  | 9484 | * @param subId The sim that the GbaService is associated with. | 
|  | 9485 | * @param interval The release time to unbind GbaService by millisecond. | 
|  | 9486 | * @return true if setting the GbaService to bind to succeeded, false if it did not. | 
|  | 9487 | */ | 
|  | 9488 | @Override | 
|  | 9489 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { | 
|  | 9490 | enforceModifyPermission(); | 
|  | 9491 |  | 
|  | 9492 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9493 | try { | 
|  | 9494 | return getGbaManager(subId).overrideReleaseTime(interval); | 
|  | 9495 | } finally { | 
|  | 9496 | Binder.restoreCallingIdentity(identity); | 
|  | 9497 | } | 
|  | 9498 | } | 
|  | 9499 |  | 
|  | 9500 | /** | 
|  | 9501 | * Return the release time for telephony to unbind GbaService. | 
|  | 9502 | * | 
|  | 9503 | * @param subId The sim that the GbaService is associated with. | 
|  | 9504 | * @return The release time to unbind GbaService by millisecond. | 
|  | 9505 | */ | 
|  | 9506 | @Override | 
|  | 9507 | public int getGbaReleaseTime(int subId) { | 
|  | 9508 | enforceReadPrivilegedPermission("getGbaReleaseTime"); | 
|  | 9509 |  | 
|  | 9510 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9511 | try { | 
|  | 9512 | return getGbaManager(subId).getReleaseTime(); | 
|  | 9513 | } finally { | 
|  | 9514 | Binder.restoreCallingIdentity(identity); | 
|  | 9515 | } | 
|  | 9516 | } | 
|  | 9517 |  | 
|  | 9518 | private GbaManager getGbaManager(int subId) { | 
|  | 9519 | GbaManager instance = GbaManager.getInstance(subId); | 
|  | 9520 | if (instance == null) { | 
|  | 9521 | String packageName = mApp.getResources().getString(R.string.config_gba_package); | 
|  | 9522 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); | 
|  | 9523 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); | 
|  | 9524 | } | 
|  | 9525 | return instance; | 
|  | 9526 | } | 
| Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9527 |  | 
|  | 9528 | /** | 
|  | 9529 | * indicate whether the device and the carrier can support | 
|  | 9530 | * RCS VoLTE single registration. | 
|  | 9531 | */ | 
|  | 9532 | @Override | 
|  | 9533 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { | 
|  | 9534 | enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable"); | 
|  | 9535 |  | 
|  | 9536 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 9537 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 9538 | } | 
|  | 9539 |  | 
|  | 9540 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9541 | try { | 
|  | 9542 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); | 
|  | 9543 | if (rpm != null) { | 
|  | 9544 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); | 
|  | 9545 | } | 
|  | 9546 | return false; | 
|  | 9547 | } finally { | 
|  | 9548 | Binder.restoreCallingIdentity(identity); | 
|  | 9549 | } | 
|  | 9550 | } | 
|  | 9551 |  | 
|  | 9552 | /** | 
|  | 9553 | * Register RCS provisioning callback. | 
|  | 9554 | */ | 
|  | 9555 | @Override | 
|  | 9556 | public void registerRcsProvisioningChangedCallback(int subId, | 
|  | 9557 | IRcsConfigCallback callback) { | 
|  | 9558 | enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback"); | 
|  | 9559 |  | 
|  | 9560 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 9561 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 9562 | } | 
|  | 9563 | if (!isImsAvailableOnDevice()) { | 
|  | 9564 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 9565 | "IMS not available on device."); | 
|  | 9566 | } | 
|  | 9567 |  | 
|  | 9568 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9569 | try { | 
|  | 9570 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
|  | 9571 | .addRcsProvisioningCallbackForSubscription(callback, subId); | 
|  | 9572 | } catch (ImsException e) { | 
|  | 9573 | throw new ServiceSpecificException(e.getCode()); | 
|  | 9574 | } finally { | 
|  | 9575 | Binder.restoreCallingIdentity(identity); | 
|  | 9576 | } | 
|  | 9577 | } | 
|  | 9578 |  | 
|  | 9579 | /** | 
|  | 9580 | * Unregister RCS provisioning callback. | 
|  | 9581 | */ | 
|  | 9582 | @Override | 
|  | 9583 | public void unregisterRcsProvisioningChangedCallback(int subId, | 
|  | 9584 | IRcsConfigCallback callback) { | 
|  | 9585 | enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback"); | 
|  | 9586 |  | 
|  | 9587 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 9588 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 9589 | } | 
|  | 9590 | if (!isImsAvailableOnDevice()) { | 
|  | 9591 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 9592 | "IMS not available on device."); | 
|  | 9593 | } | 
|  | 9594 |  | 
|  | 9595 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9596 | try { | 
|  | 9597 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
|  | 9598 | .removeRcsProvisioningCallbackForSubscription(callback, subId); | 
|  | 9599 | } catch (ImsException e) { | 
|  | 9600 | Log.i(LOG_TAG, "unregisterRcsProvisioningChangedCallback: " + subId | 
|  | 9601 | + "is inactive, ignoring unregister."); | 
|  | 9602 | } finally { | 
|  | 9603 | Binder.restoreCallingIdentity(identity); | 
|  | 9604 | } | 
|  | 9605 | } | 
|  | 9606 |  | 
|  | 9607 | /** | 
|  | 9608 | * trigger RCS reconfiguration. | 
|  | 9609 | */ | 
|  | 9610 | public void triggerRcsReconfiguration(int subId) { | 
|  | 9611 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 9612 | mApp, subId, "triggerRcsReconfiguration"); | 
|  | 9613 |  | 
|  | 9614 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 9615 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 9616 | } | 
|  | 9617 | if (!isImsAvailableOnDevice()) { | 
|  | 9618 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 9619 | "IMS not available on device."); | 
|  | 9620 | } | 
|  | 9621 |  | 
|  | 9622 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9623 | try { | 
|  | 9624 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); | 
|  | 9625 | } finally { | 
|  | 9626 | Binder.restoreCallingIdentity(identity); | 
|  | 9627 | } | 
|  | 9628 | } | 
|  | 9629 |  | 
|  | 9630 | /** | 
|  | 9631 | * Provide the client configuration parameters of the RCS application. | 
|  | 9632 | */ | 
|  | 9633 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { | 
|  | 9634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 9635 | mApp, subId, "setRcsClientConfiguration"); | 
|  | 9636 |  | 
|  | 9637 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 9638 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 9639 | } | 
|  | 9640 | if (!isImsAvailableOnDevice()) { | 
|  | 9641 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 9642 | "IMS not available on device."); | 
|  | 9643 | } | 
|  | 9644 |  | 
|  | 9645 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9646 |  | 
|  | 9647 | try { | 
|  | 9648 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); | 
|  | 9649 | if (configBinder == null) { | 
|  | 9650 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); | 
|  | 9651 | } else { | 
|  | 9652 | configBinder.setRcsClientConfiguration(rcc); | 
|  | 9653 | } | 
|  | 9654 | } catch (RemoteException e) { | 
|  | 9655 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); | 
|  | 9656 | } finally { | 
|  | 9657 | Binder.restoreCallingIdentity(identity); | 
|  | 9658 | } | 
|  | 9659 | } | 
|  | 9660 |  | 
|  | 9661 | /** | 
|  | 9662 | * Overrides the config of RCS VoLTE single registration enabled for the device. | 
|  | 9663 | */ | 
|  | 9664 | @Override | 
|  | 9665 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { | 
|  | 9666 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 9667 | "setDeviceSingleRegistrationEnabledOverride"); | 
|  | 9668 | enforceModifyPermission(); | 
|  | 9669 |  | 
|  | 9670 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null | 
|  | 9671 | : Boolean.parseBoolean(enabledStr); | 
|  | 9672 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); | 
|  | 9673 | } | 
|  | 9674 |  | 
|  | 9675 | /** | 
|  | 9676 | * Gets the config of RCS VoLTE single registration enabled for the device. | 
|  | 9677 | */ | 
|  | 9678 | @Override | 
|  | 9679 | public boolean getDeviceSingleRegistrationEnabled() { | 
|  | 9680 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); | 
|  | 9681 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); | 
|  | 9682 | } | 
|  | 9683 |  | 
|  | 9684 | /** | 
|  | 9685 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. | 
|  | 9686 | */ | 
|  | 9687 | @Override | 
|  | 9688 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { | 
|  | 9689 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 9690 | "setCarrierSingleRegistrationEnabledOverride"); | 
|  | 9691 | enforceModifyPermission(); | 
|  | 9692 |  | 
|  | 9693 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null | 
|  | 9694 | : Boolean.parseBoolean(enabledStr); | 
|  | 9695 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( | 
|  | 9696 | subId, enabled); | 
|  | 9697 | } | 
|  | 9698 |  | 
|  | 9699 | /** | 
|  | 9700 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. | 
|  | 9701 | */ | 
|  | 9702 | @Override | 
|  | 9703 | public boolean getCarrierSingleRegistrationEnabled(int subId) { | 
|  | 9704 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); | 
|  | 9705 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); | 
|  | 9706 | } | 
| Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9707 |  | 
|  | 9708 | /** | 
|  | 9709 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage | 
|  | 9710 | * their mobile plan. | 
|  | 9711 | */ | 
|  | 9712 | @Override | 
|  | 9713 | public String getMobileProvisioningUrl() { | 
|  | 9714 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); | 
|  | 9715 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9716 | try { | 
|  | 9717 | return getDefaultPhone().getMobileProvisioningUrl(); | 
|  | 9718 | } finally { | 
|  | 9719 | Binder.restoreCallingIdentity(identity); | 
|  | 9720 | } | 
|  | 9721 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9722 | } |