| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 22 | |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 23 | import android.Manifest.permission; |
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 24 | import android.annotation.Nullable; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.app.AppOpsManager; |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 26 | import android.app.PendingIntent; |
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 27 | import android.content.ComponentName; |
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 28 | import android.content.ContentResolver; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 31 | import android.content.SharedPreferences; |
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 32 | import android.content.pm.ApplicationInfo; |
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 33 | import android.content.pm.ComponentInfo; |
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 34 | import android.content.pm.PackageInfo; |
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
| Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 36 | import android.net.NetworkStats; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.Uri; |
| 38 | import android.os.AsyncResult; |
| 39 | import android.os.Binder; |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 40 | import android.os.Build; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
| 42 | import android.os.Handler; |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.IBinder; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.Looper; |
| 45 | import android.os.Message; |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 46 | import android.os.Messenger; |
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 47 | import android.os.ParcelUuid; |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 48 | import android.os.PersistableBundle; |
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 49 | import android.os.RemoteException; |
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 50 | import android.os.ResultReceiver; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.os.ServiceManager; |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 52 | import android.os.ShellCallback; |
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 53 | import android.os.SystemProperties; |
| 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 | 1264a9f | 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; |
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 61 | import android.telecom.PhoneAccount; |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 62 | import android.telecom.PhoneAccountHandle; |
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 63 | import android.telecom.TelecomManager; |
| Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 64 | import android.telephony.CarrierConfigManager; |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 65 | import android.telephony.CarrierRestrictionRules; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 66 | import android.telephony.CellInfo; |
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 67 | import android.telephony.CellInfoGsm; |
| 68 | import android.telephony.CellInfoWcdma; |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 69 | import android.telephony.CellLocation; |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 70 | import android.telephony.ClientRequestStats; |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 71 | import android.telephony.ICellInfoCallback; |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 72 | import android.telephony.IccOpenLogicalChannelResponse; |
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 73 | import android.telephony.LocationAccessPolicy; |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 74 | import android.telephony.ModemActivityInfo; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 75 | import android.telephony.NeighboringCellInfo; |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 76 | import android.telephony.NetworkScanRequest; |
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 77 | import android.telephony.PhoneCapability; |
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 78 | import android.telephony.PhoneNumberRange; |
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 79 | import android.telephony.RadioAccessFamily; |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 80 | import android.telephony.RadioAccessSpecifier; |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 81 | import android.telephony.Rlog; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 82 | import android.telephony.ServiceState; |
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 83 | import android.telephony.SignalStrength; |
| Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 84 | import android.telephony.SubscriptionInfo; |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 85 | import android.telephony.SubscriptionManager; |
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 86 | import android.telephony.TelephonyHistogram; |
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 87 | import android.telephony.TelephonyManager; |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 88 | import android.telephony.TelephonyScanManager; |
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 89 | import android.telephony.UiccCardInfo; |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 90 | import android.telephony.UiccSlotInfo; |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 91 | import android.telephony.UssdResponse; |
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 92 | import android.telephony.VisualVoicemailSmsFilterSettings; |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 93 | import android.telephony.cdma.CdmaCellLocation; |
| Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 94 | import android.telephony.data.ApnSetting; |
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 95 | import android.telephony.data.ApnSetting.ApnType; |
| Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 96 | import android.telephony.emergency.EmergencyNumber; |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 97 | import android.telephony.gsm.GsmCellLocation; |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 98 | import android.telephony.ims.ProvisioningManager; |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 99 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 100 | import android.telephony.ims.aidl.IImsConfig; |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 101 | import android.telephony.ims.aidl.IImsConfigCallback; |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 102 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 103 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 104 | import android.telephony.ims.aidl.IImsRegistration; |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 106 | import android.telephony.ims.feature.MmTelFeature; |
| 107 | import android.telephony.ims.stub.ImsConfigImplBase; |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 108 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 109 | import android.text.TextUtils; |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 110 | import android.util.ArraySet; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 111 | import android.util.Log; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 112 | import android.util.Pair; |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 113 | import android.util.Slog; |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 114 | |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 115 | import com.android.ims.ImsException; |
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 116 | import com.android.ims.ImsManager; |
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 117 | import com.android.ims.internal.IImsServiceFeatureCallback; |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.CallManager; |
| Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.CallStateException; |
| pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.CarrierInfoManager; |
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 121 | import com.android.internal.telephony.CarrierResolver; |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.CellNetworkScanResult; |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.CommandException; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.DefaultPhoneNotifier; |
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 125 | import com.android.internal.telephony.HalVersion; |
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.IIntegerConsumer; |
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.INumberVerificationCallback; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.ITelephony; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 129 | import com.android.internal.telephony.IccCard; |
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.LocaleTracker; |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 131 | import com.android.internal.telephony.MccTable; |
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.NetworkScanRequestTracker; |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.OperatorInfo; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.Phone; |
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.PhoneConfigurationManager; |
| Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.PhoneConstantConversions; |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.PhoneConstants; |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.PhoneFactory; |
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.ProxyController; |
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.RIL; |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.RILConstants; |
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.ServiceStateTracker; |
| Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.SmsApplication; |
| 144 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.SmsController; |
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.SmsPermissions; |
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.SubscriptionController; |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.TelephonyPermissions; |
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.euicc.EuiccConnector; |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.ims.ImsResolver; |
| Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.uicc.IccIoResult; |
| 155 | import com.android.internal.telephony.uicc.IccUtils; |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.uicc.SIMRecords; |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.uicc.UiccCard; |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.uicc.UiccCardApplication; |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.UiccController; |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.UiccProfile; |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.UiccSlot; |
| fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 163 | import com.android.internal.util.HexDump; |
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 164 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 165 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 166 | import com.android.phone.vvm.RemoteVvmTaskManager; |
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 167 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
| Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 168 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 169 | |
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 170 | import java.io.FileDescriptor; |
| 171 | import java.io.PrintWriter; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 172 | import java.util.ArrayList; |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 173 | import java.util.Arrays; |
| Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 174 | import java.util.Collection; |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 175 | import java.util.HashMap; |
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 176 | import java.util.HashSet; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 177 | import java.util.List; |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 178 | import java.util.Locale; |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 179 | import java.util.Map; |
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 180 | import java.util.NoSuchElementException; |
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 181 | import java.util.Set; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 182 | |
| 183 | /** |
| 184 | * Implementation of the ITelephony interface. |
| 185 | */ |
| Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 186 | public class PhoneInterfaceManager extends ITelephony.Stub { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 187 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 188 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 189 | private static final boolean DBG_LOC = false; |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 190 | private static final boolean DBG_MERGE = false; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 191 | |
| 192 | // Message codes used with mMainThreadHandler |
| 193 | private static final int CMD_HANDLE_PIN_MMI = 1; |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 194 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 195 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 196 | private static final int CMD_OPEN_CHANNEL = 9; |
| 197 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 198 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 199 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 200 | private static final int CMD_NV_READ_ITEM = 13; |
| 201 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 202 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 203 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 204 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 205 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 206 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 207 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 208 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 209 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 210 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 211 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
| Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 212 | private static final int CMD_SEND_ENVELOPE = 25; |
| 213 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 214 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 215 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
| Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 216 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 217 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 218 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 219 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 220 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 221 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 222 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 223 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 224 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 225 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 226 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 227 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 228 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 229 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 230 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 231 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 232 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 233 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 234 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 235 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 236 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 237 | private static final int CMD_SWITCH_SLOTS = 50; |
| 238 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 239 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 240 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 241 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 242 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 243 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 244 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 245 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 246 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 247 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 248 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 249 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 250 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 251 | private static final int CMD_MODEM_REBOOT = 64; |
| 252 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 253 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 254 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 255 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 256 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 257 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 258 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
| Naina Nalluri | 1264a9f | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 259 | private static final int CMD_ERASE_MODEM_CONFIG = 72; |
| 260 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 73; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 261 | |
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 262 | // Parameters of select command. |
| 263 | private static final int SELECT_COMMAND = 0xA4; |
| 264 | private static final int SELECT_P1 = 0x04; |
| 265 | private static final int SELECT_P2 = 0; |
| 266 | private static final int SELECT_P3 = 0x10; |
| 267 | |
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 268 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 269 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 270 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 271 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 272 | /** The singleton instance. */ |
| 273 | private static PhoneInterfaceManager sInstance; |
| 274 | |
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 275 | private PhoneGlobals mApp; |
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 276 | private CallManager mCM; |
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 277 | private UserManager mUserManager; |
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 278 | private AppOpsManager mAppOps; |
| 279 | private MainThreadHandler mMainThreadHandler; |
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 280 | private SubscriptionController mSubscriptionController; |
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 281 | private SharedPreferences mTelephonySharedPreferences; |
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 282 | private PhoneConfigurationManager mPhoneConfigurationManager; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 283 | |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 284 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 285 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 286 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 287 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 288 | |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 289 | // String to store multi SIM allowed |
| 290 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 291 | |
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 292 | // The AID of ISD-R. |
| 293 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 294 | |
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 295 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 296 | |
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 297 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 298 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 299 | |
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 300 | /** |
| Naina Nalluri | 1264a9f | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 301 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 302 | */ |
| 303 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 304 | "reset_network_erase_modem_config_enabled"; |
| 305 | |
| 306 | /** |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 307 | * A request object to use for transmitting data to an ICC. |
| 308 | */ |
| 309 | private static final class IccAPDUArgument { |
| 310 | public int channel, cla, command, p1, p2, p3; |
| 311 | public String data; |
| 312 | |
| 313 | public IccAPDUArgument(int channel, int cla, int command, |
| 314 | int p1, int p2, int p3, String data) { |
| 315 | this.channel = channel; |
| 316 | this.cla = cla; |
| 317 | this.command = command; |
| 318 | this.p1 = p1; |
| 319 | this.p2 = p2; |
| 320 | this.p3 = p3; |
| 321 | this.data = data; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /** |
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 326 | * A request object to use for transmitting data to an ICC. |
| 327 | */ |
| 328 | private static final class ManualNetworkSelectionArgument { |
| 329 | public OperatorInfo operatorInfo; |
| 330 | public boolean persistSelection; |
| 331 | |
| 332 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 333 | this.operatorInfo = operatorInfo; |
| 334 | this.persistSelection = persistSelection; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | /** |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 339 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 340 | * request after sending. The main thread will notify the request when it is complete. |
| 341 | */ |
| 342 | private static final class MainThreadRequest { |
| 343 | /** The argument to use for the request */ |
| 344 | public Object argument; |
| 345 | /** The result of the request that is run on the main thread */ |
| 346 | public Object result; |
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 347 | // The subscriber id that this request applies to. Defaults to |
| 348 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 349 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 350 | |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 351 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 352 | public Phone phone; |
| 353 | |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 354 | public WorkSource workSource; |
| 355 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 356 | public MainThreadRequest(Object argument) { |
| 357 | this.argument = argument; |
| 358 | } |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 359 | |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 360 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 361 | this.argument = argument; |
| 362 | if (phone != null) { |
| 363 | this.phone = phone; |
| 364 | } |
| 365 | this.workSource = workSource; |
| 366 | } |
| 367 | |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 368 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 369 | this.argument = argument; |
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 370 | if (subId != null) { |
| 371 | this.subId = subId; |
| 372 | } |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 373 | this.workSource = workSource; |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 374 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 377 | private static final class IncomingThirdPartyCallArgs { |
| 378 | public final ComponentName component; |
| 379 | public final String callId; |
| 380 | public final String callerDisplayName; |
| 381 | |
| 382 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 383 | String callerDisplayName) { |
| 384 | this.component = component; |
| 385 | this.callId = callId; |
| 386 | this.callerDisplayName = callerDisplayName; |
| 387 | } |
| 388 | } |
| 389 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 390 | /** |
| 391 | * A handler that processes messages on the main thread in the phone process. Since many |
| 392 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 393 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 394 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 395 | * on, which will be notified when the operation completes and will contain the result of the |
| 396 | * request. |
| 397 | * |
| 398 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 399 | * note that request.result must be set to something non-null for the calling thread to |
| 400 | * unblock. |
| 401 | */ |
| 402 | private final class MainThreadHandler extends Handler { |
| 403 | @Override |
| 404 | public void handleMessage(Message msg) { |
| 405 | MainThreadRequest request; |
| 406 | Message onCompleted; |
| 407 | AsyncResult ar; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 408 | UiccCard uiccCard; |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 409 | IccAPDUArgument iccArgument; |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 410 | final Phone defaultPhone = getDefaultPhone(); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 411 | |
| 412 | switch (msg.what) { |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 413 | case CMD_HANDLE_USSD_REQUEST: { |
| 414 | request = (MainThreadRequest) msg.obj; |
| 415 | final Phone phone = getPhoneFromRequest(request); |
| 416 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 417 | String ussdRequest = ussdObject.first; |
| 418 | ResultReceiver wrappedCallback = ussdObject.second; |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 419 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 420 | if (!isUssdApiAllowed(request.subId)) { |
| 421 | // Carrier does not support use of this API, return failure. |
| 422 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 423 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 424 | Bundle returnData = new Bundle(); |
| 425 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 426 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 427 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 428 | request.result = true; |
| 429 | notifyRequester(request); |
| 430 | return; |
| 431 | } |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 432 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 433 | try { |
| 434 | request.result = phone != null |
| 435 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 436 | } catch (CallStateException cse) { |
| 437 | request.result = false; |
| 438 | } |
| 439 | // Wake up the requesting thread |
| 440 | notifyRequester(request); |
| 441 | break; |
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 444 | case CMD_HANDLE_PIN_MMI: { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 445 | request = (MainThreadRequest) msg.obj; |
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 446 | final Phone phone = getPhoneFromRequest(request); |
| 447 | request.result = phone != null ? |
| 448 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 449 | : false; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 450 | // Wake up the requesting thread |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 451 | notifyRequester(request); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 452 | break; |
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 453 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 454 | |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 455 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 456 | request = (MainThreadRequest) msg.obj; |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 457 | iccArgument = (IccAPDUArgument) request.argument; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 458 | uiccCard = getUiccCardFromRequest(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 459 | if (uiccCard == null) { |
| 460 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 461 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 462 | notifyRequester(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 463 | } else { |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 464 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 465 | request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 466 | uiccCard.iccTransmitApduLogicalChannel( |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 467 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 468 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 469 | onCompleted); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 470 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 471 | break; |
| 472 | |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 473 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 474 | ar = (AsyncResult) msg.obj; |
| 475 | request = (MainThreadRequest) ar.userObj; |
| 476 | if (ar.exception == null && ar.result != null) { |
| 477 | request.result = ar.result; |
| 478 | } else { |
| 479 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 480 | if (ar.result == null) { |
| 481 | loge("iccTransmitApduLogicalChannel: Empty response"); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 482 | } else if (ar.exception instanceof CommandException) { |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 483 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 484 | ar.exception); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 485 | } else { |
| 486 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 487 | } |
| 488 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 489 | notifyRequester(request); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 490 | break; |
| 491 | |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 492 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 493 | request = (MainThreadRequest) msg.obj; |
| 494 | iccArgument = (IccAPDUArgument) request.argument; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 495 | uiccCard = getUiccCardFromRequest(request); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 496 | if (uiccCard == null) { |
| 497 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 498 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 499 | notifyRequester(request); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 500 | } else { |
| 501 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 502 | request); |
| 503 | uiccCard.iccTransmitApduBasicChannel( |
| 504 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 505 | iccArgument.p3, iccArgument.data, onCompleted); |
| 506 | } |
| 507 | break; |
| 508 | |
| 509 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 510 | ar = (AsyncResult) msg.obj; |
| 511 | request = (MainThreadRequest) ar.userObj; |
| 512 | if (ar.exception == null && ar.result != null) { |
| 513 | request.result = ar.result; |
| 514 | } else { |
| 515 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 516 | if (ar.result == null) { |
| 517 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 518 | } else if (ar.exception instanceof CommandException) { |
| 519 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 520 | ar.exception); |
| 521 | } else { |
| 522 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 523 | } |
| 524 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 525 | notifyRequester(request); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 526 | break; |
| 527 | |
| 528 | case CMD_EXCHANGE_SIM_IO: |
| 529 | request = (MainThreadRequest) msg.obj; |
| 530 | iccArgument = (IccAPDUArgument) request.argument; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 531 | uiccCard = getUiccCardFromRequest(request); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | if (uiccCard == null) { |
| 533 | loge("iccExchangeSimIO: No UICC"); |
| 534 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 535 | notifyRequester(request); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 536 | } else { |
| 537 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 538 | request); |
| 539 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 540 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 541 | iccArgument.data, onCompleted); |
| 542 | } |
| 543 | break; |
| 544 | |
| 545 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 546 | ar = (AsyncResult) msg.obj; |
| 547 | request = (MainThreadRequest) ar.userObj; |
| 548 | if (ar.exception == null && ar.result != null) { |
| 549 | request.result = ar.result; |
| 550 | } else { |
| 551 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 552 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 553 | notifyRequester(request); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 554 | break; |
| 555 | |
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 556 | case CMD_SEND_ENVELOPE: |
| 557 | request = (MainThreadRequest) msg.obj; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 558 | uiccCard = getUiccCardFromRequest(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 559 | if (uiccCard == null) { |
| 560 | loge("sendEnvelopeWithStatus: No UICC"); |
| 561 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 562 | notifyRequester(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 563 | } else { |
| 564 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 565 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 566 | } |
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 567 | break; |
| 568 | |
| 569 | case EVENT_SEND_ENVELOPE_DONE: |
| 570 | ar = (AsyncResult) msg.obj; |
| 571 | request = (MainThreadRequest) ar.userObj; |
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 572 | if (ar.exception == null && ar.result != null) { |
| 573 | request.result = ar.result; |
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 574 | } else { |
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 575 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 576 | if (ar.result == null) { |
| 577 | loge("sendEnvelopeWithStatus: Empty response"); |
| 578 | } else if (ar.exception instanceof CommandException) { |
| 579 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 580 | ar.exception); |
| 581 | } else { |
| 582 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 583 | } |
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 584 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 585 | notifyRequester(request); |
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 586 | break; |
| 587 | |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 588 | case CMD_OPEN_CHANNEL: |
| 589 | request = (MainThreadRequest) msg.obj; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 590 | uiccCard = getUiccCardFromRequest(request); |
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 591 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 592 | if (uiccCard == null) { |
| 593 | loge("iccOpenLogicalChannel: No UICC"); |
| Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 594 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 595 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 596 | notifyRequester(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 597 | } else { |
| 598 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 599 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 600 | openChannelArgs.second, onCompleted); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 601 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 602 | break; |
| 603 | |
| 604 | case EVENT_OPEN_CHANNEL_DONE: |
| 605 | ar = (AsyncResult) msg.obj; |
| 606 | request = (MainThreadRequest) ar.userObj; |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 607 | IccOpenLogicalChannelResponse openChannelResp; |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 608 | if (ar.exception == null && ar.result != null) { |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 609 | int[] result = (int[]) ar.result; |
| 610 | int channelId = result[0]; |
| 611 | byte[] selectResponse = null; |
| 612 | if (result.length > 1) { |
| 613 | selectResponse = new byte[result.length - 1]; |
| 614 | for (int i = 1; i < result.length; ++i) { |
| 615 | selectResponse[i - 1] = (byte) result[i]; |
| 616 | } |
| 617 | } |
| 618 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 619 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 620 | } else { |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 621 | if (ar.result == null) { |
| 622 | loge("iccOpenLogicalChannel: Empty response"); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 623 | } |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 624 | if (ar.exception != null) { |
| 625 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 626 | } |
| 627 | |
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 628 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 629 | if (ar.exception instanceof CommandException) { |
| 630 | CommandException.Error error = |
| 631 | ((CommandException) (ar.exception)).getCommandError(); |
| 632 | if (error == CommandException.Error.MISSING_RESOURCE) { |
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 633 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 634 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 635 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 639 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 640 | } |
| Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 641 | request.result = openChannelResp; |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 642 | notifyRequester(request); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 643 | break; |
| 644 | |
| 645 | case CMD_CLOSE_CHANNEL: |
| 646 | request = (MainThreadRequest) msg.obj; |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 647 | uiccCard = getUiccCardFromRequest(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 648 | if (uiccCard == null) { |
| 649 | loge("iccCloseLogicalChannel: No UICC"); |
| Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 650 | request.result = false; |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 651 | notifyRequester(request); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 652 | } else { |
| 653 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 654 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 655 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 656 | break; |
| 657 | |
| 658 | case EVENT_CLOSE_CHANNEL_DONE: |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 659 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 660 | break; |
| 661 | |
| 662 | case CMD_NV_READ_ITEM: |
| 663 | request = (MainThreadRequest) msg.obj; |
| 664 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 665 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 666 | request.workSource); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 667 | break; |
| 668 | |
| 669 | case EVENT_NV_READ_ITEM_DONE: |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 670 | ar = (AsyncResult) msg.obj; |
| 671 | request = (MainThreadRequest) ar.userObj; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 672 | if (ar.exception == null && ar.result != null) { |
| 673 | request.result = ar.result; // String |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | } else { |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 675 | request.result = ""; |
| 676 | if (ar.result == null) { |
| 677 | loge("nvReadItem: Empty response"); |
| 678 | } else if (ar.exception instanceof CommandException) { |
| 679 | loge("nvReadItem: CommandException: " + |
| 680 | ar.exception); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 681 | } else { |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 682 | loge("nvReadItem: Unknown exception"); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 683 | } |
| 684 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 685 | notifyRequester(request); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 686 | break; |
| 687 | |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 688 | case CMD_NV_WRITE_ITEM: |
| 689 | request = (MainThreadRequest) msg.obj; |
| 690 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 691 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 692 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 693 | request.workSource); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 694 | break; |
| 695 | |
| 696 | case EVENT_NV_WRITE_ITEM_DONE: |
| 697 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 698 | break; |
| 699 | |
| 700 | case CMD_NV_WRITE_CDMA_PRL: |
| 701 | request = (MainThreadRequest) msg.obj; |
| 702 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 703 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 704 | break; |
| 705 | |
| 706 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 707 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 708 | break; |
| 709 | |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 710 | case CMD_RESET_MODEM_CONFIG: |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 711 | request = (MainThreadRequest) msg.obj; |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 712 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 713 | defaultPhone.resetModemConfig(onCompleted); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | break; |
| 715 | |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 716 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 717 | handleNullReturnEvent(msg, "resetModemConfig"); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 718 | break; |
| 719 | |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 720 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 721 | request = (MainThreadRequest) msg.obj; |
| 722 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 723 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 724 | break; |
| 725 | |
| 726 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 727 | ar = (AsyncResult) msg.obj; |
| 728 | request = (MainThreadRequest) ar.userObj; |
| 729 | if (ar.exception == null && ar.result != null) { |
| 730 | request.result = ar.result; // Integer |
| 731 | } else { |
| Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 732 | request.result = null; |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 733 | if (ar.result == null) { |
| 734 | loge("getPreferredNetworkType: Empty response"); |
| 735 | } else if (ar.exception instanceof CommandException) { |
| 736 | loge("getPreferredNetworkType: CommandException: " + |
| 737 | ar.exception); |
| 738 | } else { |
| 739 | loge("getPreferredNetworkType: Unknown exception"); |
| 740 | } |
| 741 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 742 | notifyRequester(request); |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 743 | break; |
| 744 | |
| 745 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 746 | request = (MainThreadRequest) msg.obj; |
| 747 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 748 | int networkType = (Integer) request.argument; |
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 749 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 750 | break; |
| 751 | |
| 752 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 753 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 754 | break; |
| 755 | |
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 756 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 757 | request = (MainThreadRequest)msg.obj; |
| 758 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 759 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 760 | break; |
| 761 | |
| 762 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 763 | ar = (AsyncResult)msg.obj; |
| 764 | request = (MainThreadRequest)ar.userObj; |
| 765 | request.result = ar; |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 766 | notifyRequester(request); |
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 767 | break; |
| 768 | |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 769 | case CMD_SET_VOICEMAIL_NUMBER: |
| 770 | request = (MainThreadRequest) msg.obj; |
| 771 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 772 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 773 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 774 | onCompleted); |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 778 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 779 | break; |
| 780 | |
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 781 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 782 | request = (MainThreadRequest) msg.obj; |
| 783 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 784 | request); |
| 785 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 786 | break; |
| 787 | |
| 788 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 789 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 790 | break; |
| 791 | |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 792 | case CMD_PERFORM_NETWORK_SCAN: |
| 793 | request = (MainThreadRequest) msg.obj; |
| 794 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 795 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 796 | break; |
| 797 | |
| 798 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 799 | ar = (AsyncResult) msg.obj; |
| 800 | request = (MainThreadRequest) ar.userObj; |
| 801 | CellNetworkScanResult cellScanResult; |
| 802 | if (ar.exception == null && ar.result != null) { |
| 803 | cellScanResult = new CellNetworkScanResult( |
| 804 | CellNetworkScanResult.STATUS_SUCCESS, |
| 805 | (List<OperatorInfo>) ar.result); |
| 806 | } else { |
| 807 | if (ar.result == null) { |
| 808 | loge("getCellNetworkScanResults: Empty response"); |
| 809 | } |
| 810 | if (ar.exception != null) { |
| 811 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 812 | } |
| 813 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 814 | if (ar.exception instanceof CommandException) { |
| 815 | CommandException.Error error = |
| 816 | ((CommandException) (ar.exception)).getCommandError(); |
| 817 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 818 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 819 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 820 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 821 | } |
| 822 | } |
| 823 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 824 | } |
| 825 | request.result = cellScanResult; |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 826 | notifyRequester(request); |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 827 | break; |
| 828 | |
| 829 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 830 | request = (MainThreadRequest) msg.obj; |
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 831 | ManualNetworkSelectionArgument selArg = |
| 832 | (ManualNetworkSelectionArgument) request.argument; |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 833 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 834 | request); |
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 835 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 836 | selArg.persistSelection, onCompleted); |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 837 | break; |
| 838 | |
| 839 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
| Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 840 | ar = (AsyncResult) msg.obj; |
| 841 | request = (MainThreadRequest) ar.userObj; |
| 842 | if (ar.exception == null) { |
| 843 | request.result = true; |
| 844 | } else { |
| 845 | request.result = false; |
| 846 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 847 | } |
| 848 | notifyRequester(request); |
| 849 | mApp.onNetworkSelectionChanged(request.subId); |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 850 | break; |
| 851 | |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 852 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 853 | request = (MainThreadRequest) msg.obj; |
| 854 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
| James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 855 | if (defaultPhone != null) { |
| 856 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 857 | } |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 858 | break; |
| 859 | |
| 860 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 861 | ar = (AsyncResult) msg.obj; |
| 862 | request = (MainThreadRequest) ar.userObj; |
| 863 | if (ar.exception == null && ar.result != null) { |
| 864 | request.result = ar.result; |
| 865 | } else { |
| 866 | if (ar.result == null) { |
| 867 | loge("queryModemActivityInfo: Empty response"); |
| 868 | } else if (ar.exception instanceof CommandException) { |
| 869 | loge("queryModemActivityInfo: CommandException: " + |
| 870 | ar.exception); |
| 871 | } else { |
| 872 | loge("queryModemActivityInfo: Unknown exception"); |
| 873 | } |
| 874 | } |
| Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 875 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 876 | if (request.result == null) { |
| 877 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 878 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 879 | notifyRequester(request); |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 880 | break; |
| 881 | |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 882 | case CMD_SET_ALLOWED_CARRIERS: |
| 883 | request = (MainThreadRequest) msg.obj; |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 884 | CarrierRestrictionRules argument = |
| 885 | (CarrierRestrictionRules) request.argument; |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 886 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 887 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 888 | break; |
| 889 | |
| 890 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 891 | ar = (AsyncResult) msg.obj; |
| 892 | request = (MainThreadRequest) ar.userObj; |
| 893 | if (ar.exception == null && ar.result != null) { |
| 894 | request.result = ar.result; |
| 895 | } else { |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 896 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 897 | if (ar.exception instanceof CommandException) { |
| 898 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 899 | CommandException.Error error = |
| 900 | ((CommandException) (ar.exception)).getCommandError(); |
| 901 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 902 | request.result = |
| 903 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 904 | } |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 905 | } else { |
| 906 | loge("setAllowedCarriers: Unknown exception"); |
| 907 | } |
| 908 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 909 | notifyRequester(request); |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 910 | break; |
| 911 | |
| 912 | case CMD_GET_ALLOWED_CARRIERS: |
| 913 | request = (MainThreadRequest) msg.obj; |
| 914 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 915 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 916 | break; |
| 917 | |
| 918 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 919 | ar = (AsyncResult) msg.obj; |
| 920 | request = (MainThreadRequest) ar.userObj; |
| 921 | if (ar.exception == null && ar.result != null) { |
| 922 | request.result = ar.result; |
| 923 | } else { |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 924 | request.result = new IllegalStateException( |
| 925 | "Failed to get carrier restrictions"); |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 926 | if (ar.result == null) { |
| 927 | loge("getAllowedCarriers: Empty response"); |
| 928 | } else if (ar.exception instanceof CommandException) { |
| 929 | loge("getAllowedCarriers: CommandException: " + |
| 930 | ar.exception); |
| 931 | } else { |
| 932 | loge("getAllowedCarriers: Unknown exception"); |
| 933 | } |
| 934 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 935 | notifyRequester(request); |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 936 | break; |
| 937 | |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 938 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 939 | ar = (AsyncResult) msg.obj; |
| 940 | request = (MainThreadRequest) ar.userObj; |
| 941 | if (ar.exception == null && ar.result != null) { |
| 942 | request.result = ar.result; |
| 943 | } else { |
| 944 | request.result = new IllegalArgumentException( |
| 945 | "Failed to retrieve Forbidden Plmns"); |
| 946 | if (ar.result == null) { |
| 947 | loge("getForbiddenPlmns: Empty response"); |
| 948 | } else { |
| 949 | loge("getForbiddenPlmns: Unknown exception"); |
| 950 | } |
| 951 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 952 | notifyRequester(request); |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 953 | break; |
| 954 | |
| 955 | case CMD_GET_FORBIDDEN_PLMNS: |
| 956 | request = (MainThreadRequest) msg.obj; |
| 957 | uiccCard = getUiccCardFromRequest(request); |
| 958 | if (uiccCard == null) { |
| 959 | loge("getForbiddenPlmns() UiccCard is null"); |
| 960 | request.result = new IllegalArgumentException( |
| 961 | "getForbiddenPlmns() UiccCard is null"); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 962 | notifyRequester(request); |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 963 | break; |
| 964 | } |
| 965 | Integer appType = (Integer) request.argument; |
| 966 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 967 | if (uiccApp == null) { |
| 968 | loge("getForbiddenPlmns() no app with specified type -- " |
| 969 | + appType); |
| 970 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 971 | notifyRequester(request); |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 972 | break; |
| 973 | } else { |
| 974 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 975 | + " specified type -- " + appType); |
| 976 | } |
| 977 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 978 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 979 | onCompleted); |
| 980 | break; |
| 981 | |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 982 | case CMD_SWITCH_SLOTS: |
| 983 | request = (MainThreadRequest) msg.obj; |
| 984 | int[] physicalSlots = (int[]) request.argument; |
| 985 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 986 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 987 | break; |
| 988 | |
| 989 | case EVENT_SWITCH_SLOTS_DONE: |
| 990 | ar = (AsyncResult) msg.obj; |
| 991 | request = (MainThreadRequest) ar.userObj; |
| 992 | request.result = (ar.exception == null); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 993 | notifyRequester(request); |
| 994 | break; |
| 995 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 996 | request = (MainThreadRequest) msg.obj; |
| 997 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 998 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 999 | break; |
| 1000 | |
| 1001 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1002 | ar = (AsyncResult) msg.obj; |
| 1003 | request = (MainThreadRequest) ar.userObj; |
| 1004 | if (ar.exception != null) { |
| 1005 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1006 | } else { |
| 1007 | int mode = ((int[]) ar.result)[0]; |
| 1008 | if (mode == 0) { |
| 1009 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1010 | } else { |
| 1011 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1012 | } |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1013 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1014 | notifyRequester(request); |
| 1015 | break; |
| 1016 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1017 | request = (MainThreadRequest) msg.obj; |
| 1018 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1019 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1020 | break; |
| 1021 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1022 | ar = (AsyncResult) msg.obj; |
| 1023 | request = (MainThreadRequest) ar.userObj; |
| 1024 | if (ar.exception != null) { |
| 1025 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1026 | } else { |
| 1027 | request.result = ((int[]) ar.result)[0]; |
| 1028 | } |
| 1029 | notifyRequester(request); |
| 1030 | break; |
| 1031 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1032 | request = (MainThreadRequest) msg.obj; |
| 1033 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1034 | int mode = (int) request.argument; |
| 1035 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1036 | break; |
| 1037 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1038 | ar = (AsyncResult) msg.obj; |
| 1039 | request = (MainThreadRequest) ar.userObj; |
| 1040 | request.result = ar.exception == null; |
| 1041 | notifyRequester(request); |
| 1042 | break; |
| 1043 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1044 | request = (MainThreadRequest) msg.obj; |
| 1045 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1046 | int subscriptionMode = (int) request.argument; |
| 1047 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1048 | break; |
| 1049 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1050 | ar = (AsyncResult) msg.obj; |
| 1051 | request = (MainThreadRequest) ar.userObj; |
| 1052 | request.result = ar.exception == null; |
| 1053 | notifyRequester(request); |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1054 | break; |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1055 | case CMD_GET_ALL_CELL_INFO: |
| 1056 | request = (MainThreadRequest) msg.obj; |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1057 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1058 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1059 | break; |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1060 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1061 | ar = (AsyncResult) msg.obj; |
| 1062 | request = (MainThreadRequest) ar.userObj; |
| Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1063 | // If a timeout occurs, the response will be null |
| 1064 | request.result = (ar.exception == null && ar.result != null) |
| 1065 | ? ar.result : new ArrayList<CellInfo>(); |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1066 | synchronized (request) { |
| 1067 | request.notifyAll(); |
| 1068 | } |
| 1069 | break; |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1070 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1071 | request = (MainThreadRequest) msg.obj; |
| 1072 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1073 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1074 | break; |
| 1075 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1076 | ar = (AsyncResult) msg.obj; |
| 1077 | request = (MainThreadRequest) ar.userObj; |
| 1078 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1079 | try { |
| 1080 | if (ar.exception != null) { |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1081 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
| Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1082 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1083 | new android.os.ParcelableException(ar.exception)); |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1084 | } else if (ar.result == null) { |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1085 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
| Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1086 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1087 | } else { |
| 1088 | // use the result as returned |
| 1089 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1090 | } |
| 1091 | } catch (RemoteException re) { |
| 1092 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1093 | } |
| 1094 | break; |
| 1095 | case CMD_GET_CELL_LOCATION: |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1096 | request = (MainThreadRequest) msg.obj; |
| 1097 | WorkSource ws = (WorkSource) request.argument; |
| 1098 | Phone phone = getPhoneFromRequest(request); |
| 1099 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1100 | break; |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1101 | case EVENT_GET_CELL_LOCATION_DONE: |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1102 | ar = (AsyncResult) msg.obj; |
| 1103 | request = (MainThreadRequest) ar.userObj; |
| 1104 | if (ar.exception == null) { |
| 1105 | request.result = ar.result; |
| 1106 | } else { |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1107 | phone = getPhoneFromRequest(request); |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1108 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1109 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1110 | } |
| 1111 | |
| 1112 | synchronized (request) { |
| 1113 | request.notifyAll(); |
| 1114 | } |
| 1115 | break; |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1116 | case CMD_MODEM_REBOOT: |
| 1117 | request = (MainThreadRequest) msg.obj; |
| 1118 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1119 | defaultPhone.rebootModem(onCompleted); |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1120 | break; |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1121 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1122 | handleNullReturnEvent(msg, "rebootModem"); |
| 1123 | break; |
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1124 | case CMD_REQUEST_ENABLE_MODEM: |
| 1125 | request = (MainThreadRequest) msg.obj; |
| 1126 | boolean enable = (boolean) request.argument; |
| 1127 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
| Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1128 | onCompleted.arg1 = enable ? 1 : 0; |
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1129 | PhoneConfigurationManager.getInstance() |
| 1130 | .enablePhone(request.phone, enable, onCompleted); |
| 1131 | break; |
| 1132 | case EVENT_ENABLE_MODEM_DONE: |
| 1133 | ar = (AsyncResult) msg.obj; |
| 1134 | request = (MainThreadRequest) ar.userObj; |
| 1135 | request.result = (ar.exception == null); |
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1136 | int phoneId = request.phone.getPhoneId(); |
| Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1137 | //update the cache as modem status has changed |
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1138 | if ((boolean) request.result) { |
| 1139 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1140 | updateModemStateMetrics(); |
| 1141 | } else { |
| 1142 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1143 | + ar.exception); |
| 1144 | } |
| 1145 | notifyRequester(request); |
| 1146 | break; |
| 1147 | case CMD_GET_MODEM_STATUS: |
| 1148 | request = (MainThreadRequest) msg.obj; |
| 1149 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1150 | PhoneConfigurationManager.getInstance() |
| 1151 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1152 | break; |
| 1153 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1154 | ar = (AsyncResult) msg.obj; |
| 1155 | request = (MainThreadRequest) ar.userObj; |
| 1156 | int id = request.phone.getPhoneId(); |
| 1157 | if (ar.exception == null && ar.result != null) { |
| 1158 | request.result = ar.result; |
| 1159 | //update the cache as modem status has changed |
| 1160 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1161 | (boolean) request.result); |
| 1162 | } else { |
| 1163 | // Return true if modem status cannot be retrieved. For most cases, |
| 1164 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1165 | // and disable modem are not supported. Modem is always on. |
| 1166 | // TODO: this should be fixed in R to support a third |
| 1167 | // status UNKNOWN b/131631629 |
| 1168 | request.result = true; |
| 1169 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1170 | + ar.exception); |
| 1171 | } |
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1172 | notifyRequester(request); |
| 1173 | break; |
| Naina Nalluri | 1264a9f | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1174 | case CMD_ERASE_MODEM_CONFIG: |
| 1175 | request = (MainThreadRequest) msg.obj; |
| 1176 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1177 | defaultPhone.eraseModemConfig(onCompleted); |
| 1178 | break; |
| 1179 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1180 | handleNullReturnEvent(msg, "eraseModemConfig"); |
| 1181 | break; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1182 | default: |
| 1183 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1184 | break; |
| 1185 | } |
| 1186 | } |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1187 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1188 | private void notifyRequester(MainThreadRequest request) { |
| 1189 | synchronized (request) { |
| 1190 | request.notifyAll(); |
| 1191 | } |
| 1192 | } |
| 1193 | |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1194 | private void handleNullReturnEvent(Message msg, String command) { |
| 1195 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1196 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1197 | if (ar.exception == null) { |
| 1198 | request.result = true; |
| 1199 | } else { |
| 1200 | request.result = false; |
| 1201 | if (ar.exception instanceof CommandException) { |
| 1202 | loge(command + ": CommandException: " + ar.exception); |
| 1203 | } else { |
| 1204 | loge(command + ": Unknown exception"); |
| 1205 | } |
| 1206 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1207 | notifyRequester(request); |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1208 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | /** |
| 1212 | * Posts the specified command to be executed on the main thread, |
| 1213 | * waits for the request to complete, and returns the result. |
| 1214 | * @see #sendRequestAsync |
| 1215 | */ |
| 1216 | private Object sendRequest(int command, Object argument) { |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1217 | return sendRequest( |
| 1218 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | /** |
| 1222 | * Posts the specified command to be executed on the main thread, |
| 1223 | * waits for the request to complete, and returns the result. |
| 1224 | * @see #sendRequestAsync |
| 1225 | */ |
| 1226 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1227 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1228 | null, workSource); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | /** |
| 1232 | * Posts the specified command to be executed on the main thread, |
| 1233 | * waits for the request to complete, and returns the result. |
| 1234 | * @see #sendRequestAsync |
| 1235 | */ |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1236 | private Object sendRequest(int command, Object argument, Integer subId) { |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1237 | return sendRequest(command, argument, subId, null, null); |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | /** |
| 1241 | * Posts the specified command to be executed on the main thread, |
| 1242 | * waits for the request to complete, and returns the result. |
| 1243 | * @see #sendRequestAsync |
| 1244 | */ |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1245 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1246 | return sendRequest(command, argument, subId, null, workSource); |
| 1247 | } |
| 1248 | |
| 1249 | /** |
| 1250 | * Posts the specified command to be executed on the main thread, |
| 1251 | * waits for the request to complete, and returns the result. |
| 1252 | * @see #sendRequestAsync |
| 1253 | */ |
| 1254 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1255 | return sendRequest( |
| 1256 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1257 | } |
| 1258 | |
| 1259 | /** |
| 1260 | * Posts the specified command to be executed on the main thread, |
| 1261 | * waits for the request to complete, and returns the result. |
| 1262 | * @see #sendRequestAsync |
| 1263 | */ |
| 1264 | private Object sendRequest( |
| 1265 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1266 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1267 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1268 | } |
| 1269 | |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1270 | MainThreadRequest request = null; |
| 1271 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1272 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1273 | } else if (phone != null) { |
| 1274 | request = new MainThreadRequest(argument, phone, workSource); |
| 1275 | } else { |
| 1276 | request = new MainThreadRequest(argument, subId, workSource); |
| 1277 | } |
| 1278 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1279 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1280 | msg.sendToTarget(); |
| 1281 | |
| 1282 | // Wait for the request to complete |
| 1283 | synchronized (request) { |
| 1284 | while (request.result == null) { |
| 1285 | try { |
| 1286 | request.wait(); |
| 1287 | } catch (InterruptedException e) { |
| 1288 | // Do nothing, go back and wait until the request is complete |
| 1289 | } |
| 1290 | } |
| 1291 | } |
| 1292 | return request.result; |
| 1293 | } |
| 1294 | |
| 1295 | /** |
| 1296 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1297 | * Posts the specified command to be executed on the main thread, and |
| 1298 | * returns immediately. |
| 1299 | * @see #sendRequest |
| 1300 | */ |
| 1301 | private void sendRequestAsync(int command) { |
| 1302 | mMainThreadHandler.sendEmptyMessage(command); |
| 1303 | } |
| 1304 | |
| 1305 | /** |
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1306 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1307 | * @see {@link #sendRequest(int)} |
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1308 | */ |
| 1309 | private void sendRequestAsync(int command, Object argument) { |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1310 | sendRequestAsync(command, argument, null, null); |
| 1311 | } |
| 1312 | |
| 1313 | /** |
| 1314 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1315 | * @see {@link #sendRequest(int,Object)} |
| 1316 | */ |
| 1317 | private void sendRequestAsync( |
| 1318 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1319 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1320 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1321 | msg.sendToTarget(); |
| 1322 | } |
| 1323 | |
| 1324 | /** |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1325 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1326 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1327 | */ |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1328 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1329 | synchronized (PhoneInterfaceManager.class) { |
| 1330 | if (sInstance == null) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1331 | sInstance = new PhoneInterfaceManager(app); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1332 | } else { |
| 1333 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1334 | } |
| 1335 | return sInstance; |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | /** Private constructor; @see init() */ |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1340 | private PhoneInterfaceManager(PhoneGlobals app) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1341 | mApp = app; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1342 | mCM = PhoneGlobals.getInstance().mCM; |
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1343 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1344 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1345 | mMainThreadHandler = new MainThreadHandler(); |
| Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1346 | mSubscriptionController = SubscriptionController.getInstance(); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1347 | mTelephonySharedPreferences = |
| 1348 | PreferenceManager.getDefaultSharedPreferences(mApp); |
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1349 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1350 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1351 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1352 | publish(); |
| 1353 | } |
| 1354 | |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1355 | private Phone getDefaultPhone() { |
| 1356 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1357 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1358 | } |
| 1359 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1360 | private void publish() { |
| 1361 | if (DBG) log("publish: " + this); |
| 1362 | |
| 1363 | ServiceManager.addService("phone", this); |
| 1364 | } |
| 1365 | |
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1366 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1367 | if (request.phone != null) { |
| 1368 | return request.phone; |
| 1369 | } else { |
| 1370 | return getPhoneFromSubId(request.subId); |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | private Phone getPhoneFromSubId(int subId) { |
| 1375 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1376 | ? getDefaultPhone() : getPhone(subId); |
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1377 | } |
| 1378 | |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1379 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1380 | Phone phone = getPhoneFromRequest(request); |
| 1381 | return phone == null ? null : |
| 1382 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1383 | } |
| 1384 | |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1385 | // returns phone associated with the subId. |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1386 | private Phone getPhone(int subId) { |
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1387 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1388 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1389 | |
| Naina Nalluri | 1264a9f | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1390 | private void sendEraseModemConfig(Phone phone) { |
| 1391 | if (phone != null) { |
| 1392 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1393 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1394 | final long identity = Binder.clearCallingIdentity(); |
| 1395 | try { |
| 1396 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1397 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1398 | } finally { |
| 1399 | Binder.restoreCallingIdentity(identity); |
| 1400 | } |
| 1401 | } |
| 1402 | } |
| 1403 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1404 | public void dial(String number) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1405 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1408 | public void dialForSubscriber(int subId, String number) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1409 | if (DBG) log("dial: " + number); |
| 1410 | // No permission check needed here: This is just a wrapper around the |
| 1411 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1412 | // the UI before it does anything. |
| 1413 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1414 | final long identity = Binder.clearCallingIdentity(); |
| 1415 | try { |
| 1416 | String url = createTelUrl(number); |
| 1417 | if (url == null) { |
| 1418 | return; |
| 1419 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1420 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1421 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1422 | PhoneConstants.State state = mCM.getState(subId); |
| 1423 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1424 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1425 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1426 | mApp.startActivity(intent); |
| 1427 | } |
| 1428 | } finally { |
| 1429 | Binder.restoreCallingIdentity(identity); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | public void call(String callingPackage, String number) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1434 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1437 | public void callForSubscriber(int subId, String callingPackage, String number) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1438 | if (DBG) log("call: " + number); |
| 1439 | |
| 1440 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1441 | // need to do a permission check since we're calling startActivity() |
| 1442 | // from the context of the phone app. |
| 1443 | enforceCallPermission(); |
| 1444 | |
| 1445 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1446 | != AppOpsManager.MODE_ALLOWED) { |
| 1447 | return; |
| 1448 | } |
| 1449 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1450 | final long identity = Binder.clearCallingIdentity(); |
| 1451 | try { |
| 1452 | String url = createTelUrl(number); |
| 1453 | if (url == null) { |
| 1454 | return; |
| 1455 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1456 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1457 | boolean isValid = false; |
| 1458 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1459 | if (slist != null) { |
| 1460 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1461 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1462 | isValid = true; |
| 1463 | break; |
| 1464 | } |
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1465 | } |
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1466 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1467 | if (!isValid) { |
| 1468 | return; |
| 1469 | } |
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1470 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1471 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1472 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1473 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1474 | mApp.startActivity(intent); |
| 1475 | } finally { |
| 1476 | Binder.restoreCallingIdentity(identity); |
| 1477 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1478 | } |
| 1479 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1480 | public boolean supplyPin(String pin) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1481 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1484 | public boolean supplyPinForSubscriber(int subId, String pin) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1485 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1486 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1487 | } |
| 1488 | |
| 1489 | public boolean supplyPuk(String puk, String pin) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1490 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1493 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1494 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1495 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1496 | } |
| 1497 | |
| 1498 | /** {@hide} */ |
| 1499 | public int[] supplyPinReportResult(String pin) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1500 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1503 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1504 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1505 | |
| 1506 | final long identity = Binder.clearCallingIdentity(); |
| 1507 | try { |
| 1508 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1509 | checkSimPin.start(); |
| 1510 | return checkSimPin.unlockSim(null, pin); |
| 1511 | } finally { |
| 1512 | Binder.restoreCallingIdentity(identity); |
| 1513 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1516 | /** {@hide} */ |
| 1517 | public int[] supplyPukReportResult(String puk, String pin) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1518 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1521 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1522 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1523 | |
| 1524 | final long identity = Binder.clearCallingIdentity(); |
| 1525 | try { |
| 1526 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1527 | checkSimPuk.start(); |
| 1528 | return checkSimPuk.unlockSim(puk, pin); |
| 1529 | } finally { |
| 1530 | Binder.restoreCallingIdentity(identity); |
| 1531 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | /** |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1535 | * Helper thread to turn async call to SimCard#supplyPin into |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1536 | * a synchronous one. |
| 1537 | */ |
| 1538 | private static class UnlockSim extends Thread { |
| 1539 | |
| 1540 | private final IccCard mSimCard; |
| 1541 | |
| 1542 | private boolean mDone = false; |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1543 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1544 | private int mRetryCount = -1; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1545 | |
| 1546 | // For replies from SimCard interface |
| 1547 | private Handler mHandler; |
| 1548 | |
| 1549 | // For async handler to identify request type |
| 1550 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1551 | |
| 1552 | public UnlockSim(IccCard simCard) { |
| 1553 | mSimCard = simCard; |
| 1554 | } |
| 1555 | |
| 1556 | @Override |
| 1557 | public void run() { |
| 1558 | Looper.prepare(); |
| 1559 | synchronized (UnlockSim.this) { |
| 1560 | mHandler = new Handler() { |
| 1561 | @Override |
| 1562 | public void handleMessage(Message msg) { |
| 1563 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1564 | switch (msg.what) { |
| 1565 | case SUPPLY_PIN_COMPLETE: |
| 1566 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1567 | synchronized (UnlockSim.this) { |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1568 | mRetryCount = msg.arg1; |
| 1569 | if (ar.exception != null) { |
| 1570 | if (ar.exception instanceof CommandException && |
| 1571 | ((CommandException)(ar.exception)).getCommandError() |
| 1572 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1573 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1574 | } else { |
| 1575 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1576 | } |
| 1577 | } else { |
| 1578 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1579 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1580 | mDone = true; |
| 1581 | UnlockSim.this.notifyAll(); |
| 1582 | } |
| 1583 | break; |
| 1584 | } |
| 1585 | } |
| 1586 | }; |
| 1587 | UnlockSim.this.notifyAll(); |
| 1588 | } |
| 1589 | Looper.loop(); |
| 1590 | } |
| 1591 | |
| 1592 | /* |
| 1593 | * Use PIN or PUK to unlock SIM card |
| 1594 | * |
| 1595 | * If PUK is null, unlock SIM card with PIN |
| 1596 | * |
| 1597 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1598 | */ |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1599 | synchronized int[] unlockSim(String puk, String pin) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1600 | |
| 1601 | while (mHandler == null) { |
| 1602 | try { |
| 1603 | wait(); |
| 1604 | } catch (InterruptedException e) { |
| 1605 | Thread.currentThread().interrupt(); |
| 1606 | } |
| 1607 | } |
| 1608 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1609 | |
| 1610 | if (puk == null) { |
| 1611 | mSimCard.supplyPin(pin, callback); |
| 1612 | } else { |
| 1613 | mSimCard.supplyPuk(puk, pin, callback); |
| 1614 | } |
| 1615 | |
| 1616 | while (!mDone) { |
| 1617 | try { |
| 1618 | Log.d(LOG_TAG, "wait for done"); |
| 1619 | wait(); |
| 1620 | } catch (InterruptedException e) { |
| 1621 | // Restore the interrupted status |
| 1622 | Thread.currentThread().interrupt(); |
| 1623 | } |
| 1624 | } |
| 1625 | Log.d(LOG_TAG, "done"); |
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1626 | int[] resultArray = new int[2]; |
| 1627 | resultArray[0] = mResult; |
| 1628 | resultArray[1] = mRetryCount; |
| 1629 | return resultArray; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | |
| 1633 | public void updateServiceLocation() { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1634 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1635 | |
| 1636 | } |
| 1637 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1638 | public void updateServiceLocationForSubscriber(int subId) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1639 | // No permission check needed here: this call is harmless, and it's |
| 1640 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1641 | // already intentionally exposed to 3rd parties.) |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1642 | final long identity = Binder.clearCallingIdentity(); |
| 1643 | try { |
| 1644 | final Phone phone = getPhone(subId); |
| 1645 | if (phone != null) { |
| 1646 | phone.updateServiceLocation(); |
| 1647 | } |
| 1648 | } finally { |
| 1649 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1650 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1653 | @Override |
| 1654 | public boolean isRadioOn(String callingPackage) { |
| 1655 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1658 | @Override |
| 1659 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1660 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1661 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1662 | return false; |
| 1663 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1664 | |
| 1665 | final long identity = Binder.clearCallingIdentity(); |
| 1666 | try { |
| 1667 | return isRadioOnForSubscriber(subId); |
| 1668 | } finally { |
| 1669 | Binder.restoreCallingIdentity(identity); |
| 1670 | } |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | private boolean isRadioOnForSubscriber(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1674 | final long identity = Binder.clearCallingIdentity(); |
| 1675 | try { |
| 1676 | final Phone phone = getPhone(subId); |
| 1677 | if (phone != null) { |
| 1678 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1679 | } else { |
| 1680 | return false; |
| 1681 | } |
| 1682 | } finally { |
| 1683 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1684 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | public void toggleRadioOnOff() { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1688 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1689 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1690 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1691 | public void toggleRadioOnOffForSubscriber(int subId) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1692 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1693 | |
| 1694 | final long identity = Binder.clearCallingIdentity(); |
| 1695 | try { |
| 1696 | final Phone phone = getPhone(subId); |
| 1697 | if (phone != null) { |
| 1698 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1699 | } |
| 1700 | } finally { |
| 1701 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1702 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | public boolean setRadio(boolean turnOn) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1706 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1709 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1710 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1711 | |
| 1712 | final long identity = Binder.clearCallingIdentity(); |
| 1713 | try { |
| 1714 | final Phone phone = getPhone(subId); |
| 1715 | if (phone == null) { |
| 1716 | return false; |
| 1717 | } |
| 1718 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1719 | toggleRadioOnOffForSubscriber(subId); |
| 1720 | } |
| 1721 | return true; |
| 1722 | } finally { |
| 1723 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1724 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1725 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1726 | |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1727 | public boolean needMobileRadioShutdown() { |
| 1728 | /* |
| 1729 | * If any of the Radios are available, it will need to be |
| 1730 | * shutdown. So return true if any Radio is available. |
| 1731 | */ |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1732 | final long identity = Binder.clearCallingIdentity(); |
| 1733 | try { |
| 1734 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1735 | Phone phone = PhoneFactory.getPhone(i); |
| 1736 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1737 | } |
| 1738 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1739 | return false; |
| 1740 | } finally { |
| 1741 | Binder.restoreCallingIdentity(identity); |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1742 | } |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1745 | @Override |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1746 | public void shutdownMobileRadios() { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1747 | enforceModifyPermission(); |
| 1748 | |
| 1749 | final long identity = Binder.clearCallingIdentity(); |
| 1750 | try { |
| 1751 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1752 | logv("Shutting down Phone " + i); |
| 1753 | shutdownRadioUsingPhoneId(i); |
| 1754 | } |
| 1755 | } finally { |
| 1756 | Binder.restoreCallingIdentity(identity); |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | private void shutdownRadioUsingPhoneId(int phoneId) { |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1761 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1762 | if (phone != null && phone.isRadioAvailable()) { |
| 1763 | phone.shutdownRadio(); |
| 1764 | } |
| 1765 | } |
| 1766 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1767 | public boolean setRadioPower(boolean turnOn) { |
| Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1768 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1769 | |
| 1770 | final long identity = Binder.clearCallingIdentity(); |
| 1771 | try { |
| 1772 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1773 | if (defaultPhone != null) { |
| 1774 | defaultPhone.setRadioPower(turnOn); |
| 1775 | return true; |
| 1776 | } else { |
| 1777 | loge("There's no default phone."); |
| 1778 | return false; |
| 1779 | } |
| 1780 | } finally { |
| 1781 | Binder.restoreCallingIdentity(identity); |
| Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1782 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1785 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1786 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1787 | |
| 1788 | final long identity = Binder.clearCallingIdentity(); |
| 1789 | try { |
| 1790 | final Phone phone = getPhone(subId); |
| 1791 | if (phone != null) { |
| 1792 | phone.setRadioPower(turnOn); |
| 1793 | return true; |
| 1794 | } else { |
| 1795 | return false; |
| 1796 | } |
| 1797 | } finally { |
| 1798 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1799 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1802 | // FIXME: subId version needed |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1803 | @Override |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1804 | public boolean enableDataConnectivity() { |
| 1805 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1806 | |
| 1807 | final long identity = Binder.clearCallingIdentity(); |
| 1808 | try { |
| 1809 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1810 | final Phone phone = getPhone(subId); |
| 1811 | if (phone != null) { |
| Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1812 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1813 | return true; |
| 1814 | } else { |
| 1815 | return false; |
| 1816 | } |
| 1817 | } finally { |
| 1818 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1819 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1822 | // FIXME: subId version needed |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1823 | @Override |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1824 | public boolean disableDataConnectivity() { |
| 1825 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1826 | |
| 1827 | final long identity = Binder.clearCallingIdentity(); |
| 1828 | try { |
| 1829 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1830 | final Phone phone = getPhone(subId); |
| 1831 | if (phone != null) { |
| Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1832 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1833 | return true; |
| 1834 | } else { |
| 1835 | return false; |
| 1836 | } |
| 1837 | } finally { |
| 1838 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1839 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1842 | @Override |
| Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1843 | public boolean isDataConnectivityPossible(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1844 | final long identity = Binder.clearCallingIdentity(); |
| 1845 | try { |
| 1846 | final Phone phone = getPhone(subId); |
| 1847 | if (phone != null) { |
| Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1848 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1849 | } else { |
| 1850 | return false; |
| 1851 | } |
| 1852 | } finally { |
| 1853 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1854 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | public boolean handlePinMmi(String dialString) { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1858 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
| pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1861 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1862 | enforceCallPermission(); |
| 1863 | |
| 1864 | final long identity = Binder.clearCallingIdentity(); |
| 1865 | try { |
| 1866 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1867 | return; |
| 1868 | } |
| 1869 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1870 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1871 | } finally { |
| 1872 | Binder.restoreCallingIdentity(identity); |
| 1873 | } |
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1874 | }; |
| 1875 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1876 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1877 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1878 | |
| 1879 | final long identity = Binder.clearCallingIdentity(); |
| 1880 | try { |
| 1881 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1882 | return false; |
| 1883 | } |
| 1884 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1885 | } finally { |
| 1886 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1887 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1890 | public int getCallState() { |
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1891 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1894 | public int getCallStateForSlot(int slotIndex) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1895 | final long identity = Binder.clearCallingIdentity(); |
| 1896 | try { |
| 1897 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1898 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1899 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1900 | } finally { |
| 1901 | Binder.restoreCallingIdentity(identity); |
| 1902 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1905 | @Override |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1906 | public int getDataState() { |
| Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1907 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1908 | } |
| 1909 | |
| 1910 | @Override |
| 1911 | public int getDataStateForSubId(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1912 | final long identity = Binder.clearCallingIdentity(); |
| 1913 | try { |
| Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1914 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1915 | if (phone != null) { |
| 1916 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1917 | } else { |
| 1918 | return PhoneConstantConversions.convertDataState( |
| 1919 | PhoneConstants.DataState.DISCONNECTED); |
| 1920 | } |
| 1921 | } finally { |
| 1922 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1923 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1924 | } |
| 1925 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1926 | @Override |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1927 | public int getDataActivity() { |
| Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1928 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1929 | } |
| 1930 | |
| 1931 | @Override |
| 1932 | public int getDataActivityForSubId(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1933 | final long identity = Binder.clearCallingIdentity(); |
| 1934 | try { |
| Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1935 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1936 | if (phone != null) { |
| 1937 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1938 | } else { |
| 1939 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1940 | } |
| 1941 | } finally { |
| 1942 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1943 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | @Override |
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1947 | public Bundle getCellLocation(String callingPackage) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1948 | mApp.getSystemService(AppOpsManager.class) |
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1949 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1950 | |
| 1951 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1952 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1953 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1954 | .setCallingPackage(callingPackage) |
| 1955 | .setCallingPid(Binder.getCallingPid()) |
| 1956 | .setCallingUid(Binder.getCallingUid()) |
| 1957 | .setMethod("getCellLocation") |
| Hall Liu | 460a6de | 2020-01-24 18:07:12 -0800 | [diff] [blame^] | 1958 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1959 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1960 | .build()); |
| 1961 | switch (locationResult) { |
| 1962 | case DENIED_HARD: |
| 1963 | throw new SecurityException("Not allowed to access cell location"); |
| 1964 | case DENIED_SOFT: |
| 1965 | return new Bundle(); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1968 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1969 | final long identity = Binder.clearCallingIdentity(); |
| 1970 | try { |
| 1971 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1972 | Bundle data = new Bundle(); |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1973 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1974 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1975 | cl.fillInNotifierBundle(data); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1976 | return data; |
| 1977 | } finally { |
| 1978 | Binder.restoreCallingIdentity(identity); |
| 1979 | } |
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1982 | @Override |
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1983 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1984 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1985 | // registered cell info, so return a NULL country instead. |
| 1986 | final long identity = Binder.clearCallingIdentity(); |
| 1987 | try { |
| Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1988 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1989 | // Get default phone in this case. |
| 1990 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1991 | } |
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1992 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1993 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1994 | // is on IWLAN. |
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1995 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1996 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1997 | return ""; |
| 1998 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1999 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2000 | if (phone != null) { |
| 2001 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2002 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2003 | if (sst != null) { |
| 2004 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2005 | if (lt != null) { |
| sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2006 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2007 | return lt.getCurrentCountry(); |
| 2008 | } else if (emergencyNumberTracker != null) { |
| 2009 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2010 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2011 | } |
| 2012 | } |
| 2013 | } |
| 2014 | return ""; |
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2015 | } finally { |
| 2016 | Binder.restoreCallingIdentity(identity); |
| 2017 | } |
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | @Override |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2021 | public void enableLocationUpdates() { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2022 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2025 | @Override |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2026 | public void enableLocationUpdatesForSubscriber(int subId) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2027 | mApp.enforceCallingOrSelfPermission( |
| 2028 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2029 | |
| 2030 | final long identity = Binder.clearCallingIdentity(); |
| 2031 | try { |
| 2032 | final Phone phone = getPhone(subId); |
| 2033 | if (phone != null) { |
| 2034 | phone.enableLocationUpdates(); |
| 2035 | } |
| 2036 | } finally { |
| 2037 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2038 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | @Override |
| 2042 | public void disableLocationUpdates() { |
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2043 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2046 | @Override |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2047 | public void disableLocationUpdatesForSubscriber(int subId) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2048 | mApp.enforceCallingOrSelfPermission( |
| 2049 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2050 | |
| 2051 | final long identity = Binder.clearCallingIdentity(); |
| 2052 | try { |
| 2053 | final Phone phone = getPhone(subId); |
| 2054 | if (phone != null) { |
| 2055 | phone.disableLocationUpdates(); |
| 2056 | } |
| 2057 | } finally { |
| 2058 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2059 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2062 | /** |
| 2063 | * Returns the target SDK version number for a given package name. |
| 2064 | * |
| Nathan Harold | ba61eeb | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2065 | * This call MUST be invoked before clearing the calling UID. |
| 2066 | * |
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2067 | * @return target SDK if the package is found or INT_MAX. |
| 2068 | */ |
| 2069 | private int getTargetSdk(String packageName) { |
| 2070 | try { |
| Nathan Harold | ba61eeb | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2071 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
| 2072 | packageName, 0, UserHandle.getUserId(Binder.getCallingUid())); |
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2073 | if (ai != null) return ai.targetSdkVersion; |
| 2074 | } catch (PackageManager.NameNotFoundException unexpected) { |
| Nathan Harold | ba61eeb | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2075 | loge("Failed to get package info for pkg=" |
| 2076 | + packageName + ", uid=" + Binder.getCallingUid()); |
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2077 | } |
| 2078 | return Integer.MAX_VALUE; |
| 2079 | } |
| 2080 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2081 | @Override |
| 2082 | @SuppressWarnings("unchecked") |
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2083 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2084 | final int targetSdk = getTargetSdk(callingPackage); |
| Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2085 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2086 | throw new SecurityException( |
| 2087 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2088 | } |
| Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2089 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2090 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 2091 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2092 | return null; |
| 2093 | } |
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2094 | |
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2095 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2096 | |
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2097 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2098 | if (info == null) return null; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2099 | |
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2100 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2101 | for (CellInfo ci : info) { |
| 2102 | if (ci instanceof CellInfoGsm) { |
| 2103 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2104 | } else if (ci instanceof CellInfoWcdma) { |
| 2105 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2106 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2107 | } |
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2108 | return (neighbors.size()) > 0 ? neighbors : null; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2111 | private List<CellInfo> getCachedCellInfo() { |
| 2112 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2113 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2114 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2115 | if (info != null) cellInfos.addAll(info); |
| 2116 | } |
| 2117 | return cellInfos; |
| 2118 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2119 | |
| 2120 | @Override |
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2121 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2122 | mApp.getSystemService(AppOpsManager.class) |
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2123 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2124 | |
| 2125 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2126 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2127 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2128 | .setCallingPackage(callingPackage) |
| 2129 | .setCallingPid(Binder.getCallingPid()) |
| 2130 | .setCallingUid(Binder.getCallingUid()) |
| 2131 | .setMethod("getAllCellInfo") |
| Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2132 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2133 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2134 | .build()); |
| 2135 | switch (locationResult) { |
| 2136 | case DENIED_HARD: |
| 2137 | throw new SecurityException("Not allowed to access cell info"); |
| 2138 | case DENIED_SOFT: |
| 2139 | return new ArrayList<>(); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2140 | } |
| 2141 | |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2142 | final int targetSdk = getTargetSdk(callingPackage); |
| 2143 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2144 | return getCachedCellInfo(); |
| 2145 | } |
| 2146 | |
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2147 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2148 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2149 | final long identity = Binder.clearCallingIdentity(); |
| 2150 | try { |
| 2151 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2152 | for (Phone phone : PhoneFactory.getPhones()) { |
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2153 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2154 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2155 | if (info != null) cellInfos.addAll(info); |
| 2156 | } |
| 2157 | return cellInfos; |
| 2158 | } finally { |
| 2159 | Binder.restoreCallingIdentity(identity); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2160 | } |
| 2161 | } |
| 2162 | |
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2163 | @Override |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2164 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2165 | requestCellInfoUpdateInternal( |
| 2166 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2167 | } |
| 2168 | |
| 2169 | @Override |
| 2170 | public void requestCellInfoUpdateWithWorkSource( |
| 2171 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2172 | enforceModifyPermission(); |
| 2173 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2174 | } |
| 2175 | |
| 2176 | private void requestCellInfoUpdateInternal( |
| 2177 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2178 | mApp.getSystemService(AppOpsManager.class) |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2179 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2180 | |
| 2181 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2182 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2183 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2184 | .setCallingPackage(callingPackage) |
| 2185 | .setCallingPid(Binder.getCallingPid()) |
| 2186 | .setCallingUid(Binder.getCallingUid()) |
| 2187 | .setMethod("requestCellInfoUpdate") |
| 2188 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2189 | .build()); |
| 2190 | switch (locationResult) { |
| 2191 | case DENIED_HARD: |
| 2192 | throw new SecurityException("Not allowed to access cell info"); |
| 2193 | case DENIED_SOFT: |
| Nathan Harold | b3c5da4 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2194 | try { |
| 2195 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2196 | } catch (RemoteException re) { |
| 2197 | // Drop without consequences |
| 2198 | } |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2199 | return; |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2200 | } |
| 2201 | |
| Nathan Harold | 32e84c4 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2202 | |
| 2203 | final Phone phone = getPhoneFromSubId(subId); |
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2204 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2205 | |
| 2206 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2207 | } |
| 2208 | |
| 2209 | @Override |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2210 | public void setCellInfoListRate(int rateInMillis) { |
| Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2211 | enforceModifyPermission(); |
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2212 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2213 | |
| 2214 | final long identity = Binder.clearCallingIdentity(); |
| 2215 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2216 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2217 | } finally { |
| 2218 | Binder.restoreCallingIdentity(identity); |
| 2219 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2220 | } |
| 2221 | |
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2222 | @Override |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2223 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2224 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2225 | if (phone == null) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2226 | return null; |
| 2227 | } |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2228 | int subId = phone.getSubId(); |
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2229 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2230 | callingPackage, "getImeiForSlot")) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2231 | return null; |
| 2232 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2233 | |
| 2234 | final long identity = Binder.clearCallingIdentity(); |
| 2235 | try { |
| 2236 | return phone.getImei(); |
| 2237 | } finally { |
| 2238 | Binder.restoreCallingIdentity(identity); |
| 2239 | } |
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2240 | } |
| 2241 | |
| 2242 | @Override |
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2243 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2244 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2245 | String tac = null; |
| 2246 | if (phone != null) { |
| 2247 | String imei = phone.getImei(); |
| 2248 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2249 | } |
| 2250 | return tac; |
| 2251 | } |
| 2252 | |
| 2253 | @Override |
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2254 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2255 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2256 | if (phone == null) { |
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2257 | return null; |
| 2258 | } |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2259 | |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2260 | int subId = phone.getSubId(); |
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2261 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2262 | callingPackage, "getMeidForSlot")) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2263 | return null; |
| 2264 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2265 | |
| 2266 | final long identity = Binder.clearCallingIdentity(); |
| 2267 | try { |
| 2268 | return phone.getMeid(); |
| 2269 | } finally { |
| 2270 | Binder.restoreCallingIdentity(identity); |
| 2271 | } |
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | @Override |
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2275 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2276 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2277 | String manufacturerCode = null; |
| 2278 | if (phone != null) { |
| 2279 | String meid = phone.getMeid(); |
| 2280 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2281 | } |
| 2282 | return manufacturerCode; |
| 2283 | } |
| 2284 | |
| 2285 | @Override |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2286 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2287 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2288 | if (phone == null) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2289 | return null; |
| 2290 | } |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2291 | int subId = phone.getSubId(); |
| 2292 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2293 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2294 | return null; |
| 2295 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2296 | |
| 2297 | final long identity = Binder.clearCallingIdentity(); |
| 2298 | try { |
| 2299 | return phone.getDeviceSvn(); |
| 2300 | } finally { |
| 2301 | Binder.restoreCallingIdentity(identity); |
| 2302 | } |
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2303 | } |
| 2304 | |
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2305 | @Override |
| 2306 | public int getSubscriptionCarrierId(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2307 | final long identity = Binder.clearCallingIdentity(); |
| 2308 | try { |
| 2309 | final Phone phone = getPhone(subId); |
| 2310 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2311 | } finally { |
| 2312 | Binder.restoreCallingIdentity(identity); |
| 2313 | } |
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | @Override |
| 2317 | public String getSubscriptionCarrierName(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2318 | final long identity = Binder.clearCallingIdentity(); |
| 2319 | try { |
| 2320 | final Phone phone = getPhone(subId); |
| 2321 | return phone == null ? null : phone.getCarrierName(); |
| 2322 | } finally { |
| 2323 | Binder.restoreCallingIdentity(identity); |
| 2324 | } |
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2325 | } |
| 2326 | |
| calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2327 | @Override |
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2328 | public int getSubscriptionSpecificCarrierId(int subId) { |
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2329 | final long identity = Binder.clearCallingIdentity(); |
| 2330 | try { |
| 2331 | final Phone phone = getPhone(subId); |
| 2332 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2333 | : phone.getSpecificCarrierId(); |
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2334 | } finally { |
| 2335 | Binder.restoreCallingIdentity(identity); |
| 2336 | } |
| 2337 | } |
| 2338 | |
| 2339 | @Override |
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2340 | public String getSubscriptionSpecificCarrierName(int subId) { |
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2341 | final long identity = Binder.clearCallingIdentity(); |
| 2342 | try { |
| 2343 | final Phone phone = getPhone(subId); |
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2344 | return phone == null ? null : phone.getSpecificCarrierName(); |
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2345 | } finally { |
| 2346 | Binder.restoreCallingIdentity(identity); |
| 2347 | } |
| 2348 | } |
| 2349 | |
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2350 | @Override |
| chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2351 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2352 | if (!isSubscriptionMccMnc) { |
| 2353 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2354 | } |
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2355 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2356 | if (phone == null) { |
| 2357 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2358 | } |
| 2359 | final long identity = Binder.clearCallingIdentity(); |
| 2360 | try { |
| 2361 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2362 | } finally { |
| 2363 | Binder.restoreCallingIdentity(identity); |
| 2364 | } |
| 2365 | } |
| 2366 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2367 | // |
| 2368 | // Internal helper methods. |
| 2369 | // |
| 2370 | |
| Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2371 | /** |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2372 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2373 | * |
| 2374 | * @throws SecurityException if the caller does not have the required permission |
| 2375 | */ |
| 2376 | private void enforceModifyPermission() { |
| 2377 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2378 | } |
| 2379 | |
| 2380 | /** |
| 2381 | * Make sure the caller has the CALL_PHONE permission. |
| 2382 | * |
| 2383 | * @throws SecurityException if the caller does not have the required permission |
| 2384 | */ |
| 2385 | private void enforceCallPermission() { |
| 2386 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2387 | } |
| 2388 | |
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2389 | private void enforceConnectivityInternalPermission() { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2390 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2391 | "ConnectivityService"); |
| 2392 | } |
| 2393 | |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2394 | private String createTelUrl(String number) { |
| 2395 | if (TextUtils.isEmpty(number)) { |
| 2396 | return null; |
| 2397 | } |
| 2398 | |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2399 | return "tel:" + number; |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2400 | } |
| 2401 | |
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2402 | private static void log(String msg) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2403 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2404 | } |
| 2405 | |
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2406 | private static void logv(String msg) { |
| 2407 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2408 | } |
| 2409 | |
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2410 | private static void loge(String msg) { |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2411 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2412 | } |
| 2413 | |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2414 | @Override |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2415 | public int getActivePhoneType() { |
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2416 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2417 | } |
| 2418 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2419 | @Override |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2420 | public int getActivePhoneTypeForSlot(int slotIndex) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2421 | final long identity = Binder.clearCallingIdentity(); |
| 2422 | try { |
| 2423 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2424 | if (phone == null) { |
| 2425 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2426 | } else { |
| 2427 | return phone.getPhoneType(); |
| 2428 | } |
| 2429 | } finally { |
| 2430 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2431 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | /** |
| 2435 | * Returns the CDMA ERI icon index to display |
| 2436 | */ |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2437 | @Override |
| 2438 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2439 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2442 | @Override |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2443 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2444 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2445 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2446 | return -1; |
| 2447 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2448 | |
| 2449 | final long identity = Binder.clearCallingIdentity(); |
| 2450 | try { |
| 2451 | final Phone phone = getPhone(subId); |
| 2452 | if (phone != null) { |
| 2453 | return phone.getCdmaEriIconIndex(); |
| 2454 | } else { |
| 2455 | return -1; |
| 2456 | } |
| 2457 | } finally { |
| 2458 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2459 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | /** |
| 2463 | * Returns the CDMA ERI icon mode, |
| 2464 | * 0 - ON |
| 2465 | * 1 - FLASHING |
| 2466 | */ |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2467 | @Override |
| 2468 | public int getCdmaEriIconMode(String callingPackage) { |
| 2469 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2472 | @Override |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2473 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2474 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2475 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2476 | return -1; |
| 2477 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2478 | |
| 2479 | final long identity = Binder.clearCallingIdentity(); |
| 2480 | try { |
| 2481 | final Phone phone = getPhone(subId); |
| 2482 | if (phone != null) { |
| 2483 | return phone.getCdmaEriIconMode(); |
| 2484 | } else { |
| 2485 | return -1; |
| 2486 | } |
| 2487 | } finally { |
| 2488 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2489 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | /** |
| 2493 | * Returns the CDMA ERI text, |
| 2494 | */ |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2495 | @Override |
| 2496 | public String getCdmaEriText(String callingPackage) { |
| 2497 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2500 | @Override |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2501 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2502 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2503 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2504 | return null; |
| 2505 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2506 | |
| 2507 | final long identity = Binder.clearCallingIdentity(); |
| 2508 | try { |
| 2509 | final Phone phone = getPhone(subId); |
| 2510 | if (phone != null) { |
| 2511 | return phone.getCdmaEriText(); |
| 2512 | } else { |
| 2513 | return null; |
| 2514 | } |
| 2515 | } finally { |
| 2516 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2517 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | /** |
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2521 | * Returns the CDMA MDN. |
| 2522 | */ |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2523 | @Override |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2524 | public String getCdmaMdn(int subId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2525 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2526 | mApp, subId, "getCdmaMdn"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2527 | |
| 2528 | final long identity = Binder.clearCallingIdentity(); |
| 2529 | try { |
| 2530 | final Phone phone = getPhone(subId); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2531 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2532 | return phone.getLine1Number(); |
| 2533 | } else { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2534 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2535 | return null; |
| 2536 | } |
| 2537 | } finally { |
| 2538 | Binder.restoreCallingIdentity(identity); |
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2539 | } |
| 2540 | } |
| 2541 | |
| 2542 | /** |
| 2543 | * Returns the CDMA MIN. |
| 2544 | */ |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2545 | @Override |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2546 | public String getCdmaMin(int subId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2547 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2548 | mApp, subId, "getCdmaMin"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2549 | |
| 2550 | final long identity = Binder.clearCallingIdentity(); |
| 2551 | try { |
| 2552 | final Phone phone = getPhone(subId); |
| 2553 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2554 | return phone.getCdmaMin(); |
| 2555 | } else { |
| 2556 | return null; |
| 2557 | } |
| 2558 | } finally { |
| 2559 | Binder.restoreCallingIdentity(identity); |
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2560 | } |
| 2561 | } |
| 2562 | |
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2563 | @Override |
| 2564 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2565 | INumberVerificationCallback callback, String callingPackage) { |
| 2566 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2567 | != PERMISSION_GRANTED) { |
| 2568 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2569 | } |
| 2570 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2571 | |
| 2572 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2573 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2574 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2575 | } |
| 2576 | |
| 2577 | if (range == null) { |
| 2578 | throw new NullPointerException("Range must be non-null"); |
| 2579 | } |
| 2580 | |
| 2581 | timeoutMillis = Math.min(timeoutMillis, |
| Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2582 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2583 | |
| 2584 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2585 | } |
| 2586 | |
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2587 | /** |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2588 | * Returns true if CDMA provisioning needs to run. |
| 2589 | */ |
| 2590 | public boolean needsOtaServiceProvisioning() { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2591 | final long identity = Binder.clearCallingIdentity(); |
| 2592 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2593 | return getDefaultPhone().needsOtaServiceProvisioning(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2594 | } finally { |
| 2595 | Binder.restoreCallingIdentity(identity); |
| 2596 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2597 | } |
| 2598 | |
| 2599 | /** |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2600 | * Sets the voice mail number of a given subId. |
| 2601 | */ |
| 2602 | @Override |
| 2603 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2604 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2605 | |
| 2606 | final long identity = Binder.clearCallingIdentity(); |
| 2607 | try { |
| 2608 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2609 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2610 | return success; |
| 2611 | } finally { |
| 2612 | Binder.restoreCallingIdentity(identity); |
| 2613 | } |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2614 | } |
| 2615 | |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2616 | @Override |
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2617 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2618 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2619 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2620 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2621 | throw new SecurityException("caller must be system dialer"); |
| 2622 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2623 | |
| 2624 | final long identity = Binder.clearCallingIdentity(); |
| 2625 | try { |
| 2626 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2627 | if (phoneAccountHandle == null) { |
| 2628 | return null; |
| 2629 | } |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2630 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2631 | } finally { |
| 2632 | Binder.restoreCallingIdentity(identity); |
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2633 | } |
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | @Override |
| Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2637 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2638 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2639 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2640 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2641 | return null; |
| 2642 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2643 | |
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2644 | final long identity = Binder.clearCallingIdentity(); |
| 2645 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2646 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2647 | } finally { |
| 2648 | Binder.restoreCallingIdentity(identity); |
| 2649 | } |
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | @Override |
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2653 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2654 | VisualVoicemailSmsFilterSettings settings) { |
| 2655 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2656 | |
| 2657 | final long identity = Binder.clearCallingIdentity(); |
| 2658 | try { |
| 2659 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2660 | mApp, callingPackage, subId, settings); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2661 | } finally { |
| 2662 | Binder.restoreCallingIdentity(identity); |
| 2663 | } |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | @Override |
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2667 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2668 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2669 | |
| 2670 | final long identity = Binder.clearCallingIdentity(); |
| 2671 | try { |
| 2672 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2673 | mApp, callingPackage, subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2674 | } finally { |
| 2675 | Binder.restoreCallingIdentity(identity); |
| 2676 | } |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | @Override |
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2680 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2681 | String callingPackage, int subId) { |
| 2682 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2683 | |
| 2684 | final long identity = Binder.clearCallingIdentity(); |
| 2685 | try { |
| 2686 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2687 | mApp, callingPackage, subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2688 | } finally { |
| 2689 | Binder.restoreCallingIdentity(identity); |
| 2690 | } |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | @Override |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2694 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2695 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2696 | |
| 2697 | final long identity = Binder.clearCallingIdentity(); |
| 2698 | try { |
| 2699 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2700 | mApp, subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2701 | } finally { |
| 2702 | Binder.restoreCallingIdentity(identity); |
| 2703 | } |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | @Override |
| 2707 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2708 | String number, int port, String text, PendingIntent sentIntent) { |
| 2709 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2710 | enforceVisualVoicemailPackage(callingPackage, subId); |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2711 | enforceSendSmsPermission(); |
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2712 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2713 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2714 | sentIntent); |
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2715 | } |
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2716 | |
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2717 | /** |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2718 | * Sets the voice activation state of a given subId. |
| 2719 | */ |
| 2720 | @Override |
| 2721 | public void setVoiceActivationState(int subId, int activationState) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2722 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2723 | mApp, subId, "setVoiceActivationState"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2724 | |
| 2725 | final long identity = Binder.clearCallingIdentity(); |
| 2726 | try { |
| 2727 | final Phone phone = getPhone(subId); |
| 2728 | if (phone != null) { |
| 2729 | phone.setVoiceActivationState(activationState); |
| 2730 | } else { |
| 2731 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2732 | } |
| 2733 | } finally { |
| 2734 | Binder.restoreCallingIdentity(identity); |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2735 | } |
| 2736 | } |
| 2737 | |
| 2738 | /** |
| 2739 | * Sets the data activation state of a given subId. |
| 2740 | */ |
| 2741 | @Override |
| 2742 | public void setDataActivationState(int subId, int activationState) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2743 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2744 | mApp, subId, "setDataActivationState"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2745 | |
| 2746 | final long identity = Binder.clearCallingIdentity(); |
| 2747 | try { |
| 2748 | final Phone phone = getPhone(subId); |
| 2749 | if (phone != null) { |
| 2750 | phone.setDataActivationState(activationState); |
| 2751 | } else { |
| 2752 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2753 | } |
| 2754 | } finally { |
| 2755 | Binder.restoreCallingIdentity(identity); |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2756 | } |
| 2757 | } |
| 2758 | |
| 2759 | /** |
| 2760 | * Returns the voice activation state of a given subId. |
| 2761 | */ |
| 2762 | @Override |
| 2763 | public int getVoiceActivationState(int subId, String callingPackage) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2764 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2765 | |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2766 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2767 | final long identity = Binder.clearCallingIdentity(); |
| 2768 | try { |
| 2769 | if (phone != null) { |
| 2770 | return phone.getVoiceActivationState(); |
| 2771 | } else { |
| 2772 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2773 | } |
| 2774 | } finally { |
| 2775 | Binder.restoreCallingIdentity(identity); |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2776 | } |
| 2777 | } |
| 2778 | |
| 2779 | /** |
| 2780 | * Returns the data activation state of a given subId. |
| 2781 | */ |
| 2782 | @Override |
| 2783 | public int getDataActivationState(int subId, String callingPackage) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2784 | enforceReadPrivilegedPermission("getDataActivationState"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2785 | |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2786 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2787 | final long identity = Binder.clearCallingIdentity(); |
| 2788 | try { |
| 2789 | if (phone != null) { |
| 2790 | return phone.getDataActivationState(); |
| 2791 | } else { |
| 2792 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2793 | } |
| 2794 | } finally { |
| 2795 | Binder.restoreCallingIdentity(identity); |
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2796 | } |
| 2797 | } |
| 2798 | |
| 2799 | /** |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2800 | * Returns the unread count of voicemails for a subId |
| 2801 | */ |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2802 | @Override |
| Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2803 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2804 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2805 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2806 | return 0; |
| 2807 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2808 | final long identity = Binder.clearCallingIdentity(); |
| 2809 | try { |
| 2810 | final Phone phone = getPhone(subId); |
| 2811 | if (phone != null) { |
| 2812 | return phone.getVoiceMessageCount(); |
| 2813 | } else { |
| 2814 | return 0; |
| 2815 | } |
| 2816 | } finally { |
| 2817 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2818 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | /** |
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2822 | * returns true, if the device is in a state where both voice and data |
| 2823 | * are supported simultaneously. This can change based on location or network condition. |
| 2824 | */ |
| 2825 | @Override |
| 2826 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2827 | final long identity = Binder.clearCallingIdentity(); |
| 2828 | try { |
| 2829 | final Phone phone = getPhone(subId); |
| 2830 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2831 | } finally { |
| 2832 | Binder.restoreCallingIdentity(identity); |
| 2833 | } |
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | /** |
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2837 | * Send the dialer code if called from the current default dialer or the caller has |
| 2838 | * carrier privilege. |
| 2839 | * @param inputCode The dialer code to send |
| 2840 | */ |
| 2841 | @Override |
| 2842 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2843 | final Phone defaultPhone = getDefaultPhone(); |
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2844 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2845 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2846 | .getDefaultDialerPackage(); |
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2847 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2848 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2849 | getDefaultSubscription(), "sendDialerSpecialCode"); |
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2850 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2851 | |
| 2852 | final long identity = Binder.clearCallingIdentity(); |
| 2853 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2854 | defaultPhone.sendDialerSpecialCode(inputCode); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2855 | } finally { |
| 2856 | Binder.restoreCallingIdentity(identity); |
| 2857 | } |
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2858 | } |
| 2859 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2860 | @Override |
| 2861 | public int getNetworkSelectionMode(int subId) { |
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2862 | if (!isActiveSubscription(subId)) { |
| 2863 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2864 | } |
| 2865 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2866 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2867 | } |
| 2868 | |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2869 | @Override |
| Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2870 | public boolean isInEmergencySmsMode() { |
| 2871 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2872 | final long identity = Binder.clearCallingIdentity(); |
| 2873 | try { |
| 2874 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2875 | if (phone.isInEmergencySmsMode()) { |
| 2876 | return true; |
| 2877 | } |
| 2878 | } |
| 2879 | } finally { |
| 2880 | Binder.restoreCallingIdentity(identity); |
| 2881 | } |
| 2882 | return false; |
| 2883 | } |
| 2884 | |
| 2885 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2886 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2887 | throws RemoteException { |
| 2888 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2889 | final long token = Binder.clearCallingIdentity(); |
| 2890 | try { |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2891 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2892 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2893 | .addRegistrationCallbackForSubscription(c, subId); |
| 2894 | } finally { |
| 2895 | Binder.restoreCallingIdentity(token); |
| 2896 | } |
| 2897 | } |
| 2898 | |
| 2899 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2900 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2901 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2902 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2903 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2904 | } |
| 2905 | Binder.withCleanCallingIdentity(() -> { |
| 2906 | try { |
| 2907 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2908 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2909 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2910 | } catch (IllegalArgumentException e) { |
| 2911 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2912 | + "is inactive, ignoring unregister."); |
| 2913 | // If the subscription is no longer active, just return, since the callback |
| 2914 | // will already have been removed internally. |
| 2915 | } |
| 2916 | }); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2920 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2921 | throws RemoteException { |
| 2922 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2923 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2924 | final long token = Binder.clearCallingIdentity(); |
| 2925 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2926 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2927 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2928 | } finally { |
| 2929 | Binder.restoreCallingIdentity(token); |
| 2930 | } |
| 2931 | } |
| 2932 | |
| 2933 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2934 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2935 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2936 | |
| 2937 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2938 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2939 | } |
| 2940 | Binder.withCleanCallingIdentity(() -> { |
| 2941 | try { |
| 2942 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2943 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2944 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2945 | } catch (IllegalArgumentException e) { |
| 2946 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2947 | + "is inactive, ignoring unregister."); |
| 2948 | // If the subscription is no longer active, just return, since the callback |
| 2949 | // will already have been removed internally. |
| 2950 | } |
| 2951 | }); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2955 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2956 | enforceReadPrivilegedPermission("isCapable"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2957 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2958 | final long token = Binder.clearCallingIdentity(); |
| 2959 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2960 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2961 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2962 | } catch (ImsException e) { |
| 2963 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2964 | return false; |
| Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2965 | } catch (IllegalArgumentException e) { |
| 2966 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2967 | return false; |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2968 | } finally { |
| 2969 | Binder.restoreCallingIdentity(token); |
| 2970 | } |
| 2971 | } |
| 2972 | |
| 2973 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2974 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2975 | enforceReadPrivilegedPermission("isAvailable"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2976 | final long token = Binder.clearCallingIdentity(); |
| 2977 | try { |
| 2978 | Phone phone = getPhone(subId); |
| 2979 | if (phone == null) return false; |
| 2980 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2981 | } finally { |
| 2982 | Binder.restoreCallingIdentity(token); |
| 2983 | } |
| 2984 | } |
| 2985 | |
| 2986 | @Override |
| 2987 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2988 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2989 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2990 | final long token = Binder.clearCallingIdentity(); |
| 2991 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2992 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2993 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2994 | } finally { |
| 2995 | Binder.restoreCallingIdentity(token); |
| 2996 | } |
| 2997 | } |
| 2998 | |
| 2999 | @Override |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3000 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3001 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3002 | "setAdvancedCallingSettingEnabled"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3003 | final long identity = Binder.clearCallingIdentity(); |
| 3004 | try { |
| 3005 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3006 | ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3007 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 3008 | } finally { |
| 3009 | Binder.restoreCallingIdentity(identity); |
| 3010 | } |
| 3011 | } |
| 3012 | |
| 3013 | @Override |
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3014 | public boolean isVtSettingEnabled(int subId) { |
| 3015 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3016 | final long identity = Binder.clearCallingIdentity(); |
| 3017 | try { |
| 3018 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3019 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3020 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3021 | } finally { |
| 3022 | Binder.restoreCallingIdentity(identity); |
| 3023 | } |
| 3024 | } |
| 3025 | |
| 3026 | @Override |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3027 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3028 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3029 | "setVtSettingEnabled"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3030 | final long identity = Binder.clearCallingIdentity(); |
| 3031 | try { |
| 3032 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3033 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3034 | } finally { |
| 3035 | Binder.restoreCallingIdentity(identity); |
| 3036 | } |
| 3037 | } |
| 3038 | |
| 3039 | @Override |
| 3040 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3041 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3042 | final long identity = Binder.clearCallingIdentity(); |
| 3043 | try { |
| 3044 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3045 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3046 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 3047 | } finally { |
| 3048 | Binder.restoreCallingIdentity(identity); |
| 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | @Override |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3053 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3054 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3055 | "setVoWiFiSettingEnabled"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3056 | final long identity = Binder.clearCallingIdentity(); |
| 3057 | try { |
| 3058 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3059 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3060 | } finally { |
| 3061 | Binder.restoreCallingIdentity(identity); |
| 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | @Override |
| 3066 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3067 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3068 | final long identity = Binder.clearCallingIdentity(); |
| 3069 | try { |
| 3070 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3071 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3072 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 3073 | } finally { |
| 3074 | Binder.restoreCallingIdentity(identity); |
| 3075 | } |
| 3076 | } |
| 3077 | |
| 3078 | @Override |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3079 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3080 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3081 | "setVoWiFiRoamingSettingEnabled"); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3082 | final long identity = Binder.clearCallingIdentity(); |
| 3083 | try { |
| 3084 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3085 | ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3086 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 3087 | } finally { |
| 3088 | Binder.restoreCallingIdentity(identity); |
| 3089 | } |
| 3090 | } |
| 3091 | |
| 3092 | @Override |
| 3093 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3095 | "setVoWiFiNonPersistent"); |
| 3096 | final long identity = Binder.clearCallingIdentity(); |
| 3097 | try { |
| 3098 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3099 | ImsManager.getInstance(mApp, |
| Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3100 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3101 | } finally { |
| 3102 | Binder.restoreCallingIdentity(identity); |
| 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | @Override |
| 3107 | public int getVoWiFiModeSetting(int subId) { |
| 3108 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3109 | final long identity = Binder.clearCallingIdentity(); |
| 3110 | try { |
| 3111 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3112 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3113 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3114 | } finally { |
| 3115 | Binder.restoreCallingIdentity(identity); |
| 3116 | } |
| 3117 | } |
| 3118 | |
| 3119 | @Override |
| 3120 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3121 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3122 | "setVoWiFiModeSetting"); |
| 3123 | final long identity = Binder.clearCallingIdentity(); |
| 3124 | try { |
| 3125 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3126 | ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3127 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3128 | } finally { |
| 3129 | Binder.restoreCallingIdentity(identity); |
| 3130 | } |
| 3131 | } |
| 3132 | |
| 3133 | @Override |
| 3134 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3135 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3136 | final long identity = Binder.clearCallingIdentity(); |
| 3137 | try { |
| 3138 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3139 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3140 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3141 | } finally { |
| 3142 | Binder.restoreCallingIdentity(identity); |
| 3143 | } |
| 3144 | } |
| 3145 | |
| 3146 | @Override |
| 3147 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3148 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3149 | "setVoWiFiRoamingModeSetting"); |
| 3150 | final long identity = Binder.clearCallingIdentity(); |
| 3151 | try { |
| 3152 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3153 | ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3154 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3155 | } finally { |
| 3156 | Binder.restoreCallingIdentity(identity); |
| 3157 | } |
| 3158 | } |
| 3159 | |
| 3160 | @Override |
| 3161 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3162 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3163 | "setRttCapabilityEnabled"); |
| 3164 | final long identity = Binder.clearCallingIdentity(); |
| 3165 | try { |
| 3166 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3167 | ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3168 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3169 | } finally { |
| 3170 | Binder.restoreCallingIdentity(identity); |
| 3171 | } |
| 3172 | } |
| 3173 | |
| 3174 | @Override |
| 3175 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3176 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3177 | final long identity = Binder.clearCallingIdentity(); |
| 3178 | try { |
| 3179 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3180 | return ImsManager.getInstance(mApp, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3181 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3182 | } finally { |
| 3183 | Binder.restoreCallingIdentity(identity); |
| 3184 | } |
| 3185 | } |
| 3186 | |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3187 | @Override |
| 3188 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3189 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3190 | final long identity = Binder.clearCallingIdentity(); |
| 3191 | try { |
| 3192 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3193 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3194 | .addProvisioningCallbackForSubscription(callback, subId); |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3195 | } finally { |
| 3196 | Binder.restoreCallingIdentity(identity); |
| 3197 | } |
| 3198 | } |
| 3199 | |
| 3200 | @Override |
| 3201 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3202 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3203 | final long identity = Binder.clearCallingIdentity(); |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3204 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3205 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3206 | } |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3207 | try { |
| 3208 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3209 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3210 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3211 | } catch (IllegalArgumentException e) { |
| 3212 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3213 | + "is inactive, ignoring unregister."); |
| 3214 | // If the subscription is no longer active, just return, since the callback will already |
| 3215 | // have been removed internally. |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3216 | } finally { |
| 3217 | Binder.restoreCallingIdentity(identity); |
| 3218 | } |
| 3219 | } |
| 3220 | |
| 3221 | @Override |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3222 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3223 | boolean isProvisioned) { |
| 3224 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3225 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3226 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3227 | } |
| 3228 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3229 | "setProvisioningStatusForCapability"); |
| 3230 | final long identity = Binder.clearCallingIdentity(); |
| 3231 | try { |
| 3232 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3233 | Phone phone = getPhone(subId); |
| 3234 | if (phone == null) { |
| 3235 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3236 | + subId); |
| 3237 | return; |
| 3238 | } |
| 3239 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3240 | return; |
| 3241 | } |
| 3242 | |
| 3243 | // this capability requires provisioning, route to the correct API. |
| 3244 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3245 | switch (capability) { |
| 3246 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3247 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3248 | ims.setVolteProvisioned(isProvisioned); |
| 3249 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3250 | ims.setWfcProvisioned(isProvisioned); |
| 3251 | } |
| 3252 | break; |
| 3253 | } |
| 3254 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3255 | // There is currently no difference in VT provisioning type. |
| 3256 | ims.setVtProvisioned(isProvisioned); |
| 3257 | break; |
| 3258 | } |
| 3259 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3260 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3261 | // change the capability of the feature instead if needed. |
| 3262 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3263 | == isProvisioned) { |
| 3264 | // No change in provisioning. |
| 3265 | return; |
| 3266 | } |
| 3267 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3268 | try { |
| 3269 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3270 | } catch (ImsException e) { |
| 3271 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3272 | + ", Exception" + e.getMessage()); |
| 3273 | } |
| 3274 | break; |
| 3275 | } |
| 3276 | default: { |
| 3277 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3278 | + capability + "', which does not require provisioning."); |
| 3279 | } |
| 3280 | } |
| 3281 | |
| 3282 | } finally { |
| 3283 | Binder.restoreCallingIdentity(identity); |
| 3284 | } |
| 3285 | } |
| 3286 | |
| 3287 | @Override |
| 3288 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3289 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3290 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3291 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3292 | } |
| 3293 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3294 | final long identity = Binder.clearCallingIdentity(); |
| 3295 | try { |
| 3296 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3297 | Phone phone = getPhone(subId); |
| 3298 | if (phone == null) { |
| 3299 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3300 | + subId); |
| 3301 | // We will fail with "true" as the provisioning status because this is the default |
| 3302 | // if we do not require provisioning. |
| 3303 | return true; |
| 3304 | } |
| 3305 | |
| 3306 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3307 | return true; |
| 3308 | } |
| 3309 | |
| 3310 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3311 | switch (capability) { |
| 3312 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3313 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3314 | return ims.isVolteProvisionedOnDevice(); |
| 3315 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3316 | return ims.isWfcProvisionedOnDevice(); |
| 3317 | } |
| 3318 | // This should never happen, since we are checking tech above to make sure it |
| 3319 | // is either LTE or IWLAN. |
| 3320 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3321 | + "capability."); |
| 3322 | } |
| 3323 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3324 | // There is currently no difference in VT provisioning type. |
| 3325 | return ims.isVtProvisionedOnDevice(); |
| 3326 | } |
| 3327 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3328 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3329 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3330 | } |
| 3331 | default: { |
| 3332 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3333 | + capability + "', which does not require provisioning."); |
| 3334 | } |
| 3335 | } |
| 3336 | |
| 3337 | } finally { |
| 3338 | Binder.restoreCallingIdentity(identity); |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | @Override |
| 3343 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3344 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3345 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3346 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3347 | } |
| 3348 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3349 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3350 | return (provisionedBits & capability) > 0; |
| 3351 | } |
| 3352 | |
| 3353 | @Override |
| 3354 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3355 | boolean isProvisioned) { |
| 3356 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3357 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3358 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3359 | } |
| 3360 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3361 | "setProvisioningStatusForCapability"); |
| 3362 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3363 | // If the current provisioning status for capability already matches isProvisioned, |
| 3364 | // do nothing. |
| 3365 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3366 | return; |
| 3367 | } |
| 3368 | if (isProvisioned) { |
| 3369 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3370 | } else { |
| 3371 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3372 | } |
| 3373 | } |
| 3374 | |
| 3375 | /** |
| 3376 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3377 | * technology. The bitfield should mirror the bitfield defined by |
| 3378 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3379 | */ |
| 3380 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3381 | String key = getMmTelProvisioningKey(subId, tech); |
| 3382 | // Default is no capabilities are provisioned. |
| 3383 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3384 | } |
| 3385 | |
| 3386 | /** |
| 3387 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3388 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3389 | * technology specified. |
| 3390 | * |
| 3391 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3392 | */ |
| 3393 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3394 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3395 | String key = getMmTelProvisioningKey(subId, tech); |
| 3396 | editor.putInt(key, newField); |
| 3397 | editor.commit(); |
| 3398 | } |
| 3399 | |
| 3400 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3401 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3402 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3403 | } |
| 3404 | |
| 3405 | /** |
| 3406 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3407 | * carrier associated with the subscription id. |
| 3408 | */ |
| 3409 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3410 | int capability) { |
| 3411 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3412 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3413 | boolean requireUtProvisioning = c.getBoolean( |
| 3414 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3415 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3416 | // the no-SIM case, where we would normally shortcut this to false. |
| 3417 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3418 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3419 | false); |
| 3420 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3421 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3422 | |
| 3423 | // First check to make sure that the capability requires provisioning. |
| 3424 | switch (capability) { |
| 3425 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3426 | // intentional fallthrough |
| 3427 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3428 | if (requireVoiceVtProvisioning) { |
| 3429 | // Voice and Video requires provisioning |
| 3430 | return true; |
| 3431 | } |
| 3432 | break; |
| 3433 | } |
| 3434 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3435 | if (requireUtProvisioning) { |
| 3436 | // UT requires provisioning |
| 3437 | return true; |
| 3438 | } |
| 3439 | break; |
| 3440 | } |
| 3441 | } |
| 3442 | return false; |
| 3443 | } |
| 3444 | |
| 3445 | @Override |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3446 | public int getImsProvisioningInt(int subId, int key) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3447 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3448 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3449 | } |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3450 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3451 | final long identity = Binder.clearCallingIdentity(); |
| 3452 | try { |
| 3453 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3454 | int slotId = getSlotIndex(subId); |
| 3455 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3456 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3457 | + subId + "' for key:" + key); |
| 3458 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3459 | } |
| 3460 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3461 | } catch (ImsException e) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3462 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3463 | + subId + "' for key:" + key); |
| 3464 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3465 | } finally { |
| 3466 | Binder.restoreCallingIdentity(identity); |
| 3467 | } |
| 3468 | } |
| 3469 | |
| 3470 | @Override |
| 3471 | public String getImsProvisioningString(int subId, int key) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3472 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3473 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3474 | } |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3475 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3476 | final long identity = Binder.clearCallingIdentity(); |
| 3477 | try { |
| 3478 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3479 | int slotId = getSlotIndex(subId); |
| 3480 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3481 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3482 | + subId + "' for key:" + key); |
| 3483 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3484 | } |
| 3485 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3486 | } catch (ImsException e) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3487 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3488 | + subId + "' for key:" + key); |
| 3489 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3490 | } finally { |
| 3491 | Binder.restoreCallingIdentity(identity); |
| 3492 | } |
| 3493 | } |
| 3494 | |
| 3495 | @Override |
| 3496 | public int setImsProvisioningInt(int subId, int key, int value) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3497 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3498 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3499 | } |
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3500 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3501 | "setImsProvisioningInt"); |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3502 | final long identity = Binder.clearCallingIdentity(); |
| 3503 | try { |
| 3504 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3505 | int slotId = getSlotIndex(subId); |
| 3506 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3507 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3508 | + subId + "' for key:" + key); |
| 3509 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3510 | } |
| 3511 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3512 | } catch (ImsException e) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3513 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3514 | + "' for key:" + key); |
| 3515 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3516 | } finally { |
| 3517 | Binder.restoreCallingIdentity(identity); |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | @Override |
| 3522 | public int setImsProvisioningString(int subId, int key, String value) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3523 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3524 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3525 | } |
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3526 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3527 | "setImsProvisioningString"); |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3528 | final long identity = Binder.clearCallingIdentity(); |
| 3529 | try { |
| 3530 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3531 | int slotId = getSlotIndex(subId); |
| 3532 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3533 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3534 | + subId + "' for key:" + key); |
| 3535 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3536 | } |
| 3537 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3538 | } catch (ImsException e) { |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3539 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3540 | + "' for key:" + key); |
| 3541 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3542 | } finally { |
| 3543 | Binder.restoreCallingIdentity(identity); |
| 3544 | } |
| 3545 | } |
| 3546 | |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3547 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3548 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3549 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3550 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3551 | } |
| 3552 | return slotId; |
| 3553 | } |
| 3554 | |
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3555 | private int getSlotIndex(int subId) { |
| 3556 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3557 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3558 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3559 | } |
| 3560 | return slotId; |
| 3561 | } |
| 3562 | |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3563 | /** |
| Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3564 | * Returns the data network type for a subId; does not throw SecurityException. |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3565 | */ |
| 3566 | @Override |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3567 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
| Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3568 | if (getTargetSdk(callingPackage) >= android.os.Build.VERSION_CODES.Q |
| 3569 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
| 3570 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3571 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3572 | } |
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3573 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3574 | final long identity = Binder.clearCallingIdentity(); |
| 3575 | try { |
| 3576 | final Phone phone = getPhone(subId); |
| 3577 | if (phone != null) { |
| 3578 | return phone.getServiceState().getDataNetworkType(); |
| 3579 | } else { |
| 3580 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3581 | } |
| 3582 | } finally { |
| 3583 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3584 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
| 3587 | /** |
| 3588 | * Returns the data network type |
| 3589 | */ |
| 3590 | @Override |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3591 | public int getDataNetworkType(String callingPackage) { |
| 3592 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | /** |
| 3596 | * Returns the data network type for a subId |
| 3597 | */ |
| 3598 | @Override |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3599 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3600 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3601 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3602 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3603 | } |
| 3604 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3605 | final long identity = Binder.clearCallingIdentity(); |
| 3606 | try { |
| 3607 | final Phone phone = getPhone(subId); |
| 3608 | if (phone != null) { |
| 3609 | return phone.getServiceState().getDataNetworkType(); |
| 3610 | } else { |
| 3611 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3612 | } |
| 3613 | } finally { |
| 3614 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3615 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | /** |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3619 | * Returns the Voice network type for a subId |
| 3620 | */ |
| 3621 | @Override |
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3622 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3623 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3624 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3625 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3626 | } |
| 3627 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3628 | final long identity = Binder.clearCallingIdentity(); |
| 3629 | try { |
| 3630 | final Phone phone = getPhone(subId); |
| 3631 | if (phone != null) { |
| 3632 | return phone.getServiceState().getVoiceNetworkType(); |
| 3633 | } else { |
| 3634 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3635 | } |
| 3636 | } finally { |
| 3637 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3638 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | /** |
| 3642 | * @return true if a ICC card is present |
| 3643 | */ |
| 3644 | public boolean hasIccCard() { |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3645 | // FIXME Make changes to pass defaultSimId of type int |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3646 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3647 | getDefaultSubscription())); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | /** |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3651 | * @return true if a ICC card is present for a slotIndex |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3652 | */ |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3653 | @Override |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3654 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3655 | final long identity = Binder.clearCallingIdentity(); |
| 3656 | try { |
| 3657 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3658 | if (phone != null) { |
| 3659 | return phone.getIccCard().hasIccCard(); |
| 3660 | } else { |
| 3661 | return false; |
| 3662 | } |
| 3663 | } finally { |
| 3664 | Binder.restoreCallingIdentity(identity); |
| Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3665 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | /** |
| 3669 | * Return if the current radio is LTE on CDMA. This |
| 3670 | * is a tri-state return value as for a period of time |
| 3671 | * the mode may be unknown. |
| 3672 | * |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3673 | * @param callingPackage the name of the package making the call. |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3674 | * @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] | 3675 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3676 | */ |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3677 | @Override |
| 3678 | public int getLteOnCdmaMode(String callingPackage) { |
| 3679 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3680 | } |
| 3681 | |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3682 | @Override |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3683 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3684 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3685 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3686 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3687 | } |
| 3688 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3689 | final long identity = Binder.clearCallingIdentity(); |
| 3690 | try { |
| 3691 | final Phone phone = getPhone(subId); |
| 3692 | if (phone == null) { |
| 3693 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3694 | } else { |
| 3695 | return phone.getLteOnCdmaMode(); |
| 3696 | } |
| 3697 | } finally { |
| 3698 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3699 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3700 | } |
| 3701 | |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3702 | /** |
| 3703 | * {@hide} |
| 3704 | * Returns Default subId, 0 in the case of single standby. |
| 3705 | */ |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3706 | private int getDefaultSubscription() { |
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3707 | return mSubscriptionController.getDefaultSubId(); |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3708 | } |
| 3709 | |
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3710 | private int getSlotForDefaultSubscription() { |
| 3711 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3712 | } |
| 3713 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3714 | private int getPreferredVoiceSubscription() { |
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3715 | return mSubscriptionController.getDefaultVoiceSubId(); |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3716 | } |
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3717 | |
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3718 | private boolean isActiveSubscription(int subId) { |
| 3719 | return mSubscriptionController.isActiveSubId(subId); |
| 3720 | } |
| 3721 | |
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3722 | /** |
| 3723 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3724 | */ |
| 3725 | public int getWhenToMakeWifiCalls() { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3726 | final long identity = Binder.clearCallingIdentity(); |
| 3727 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3728 | return Settings.System.getInt(mApp.getContentResolver(), |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3729 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3730 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3731 | } finally { |
| 3732 | Binder.restoreCallingIdentity(identity); |
| 3733 | } |
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3734 | } |
| 3735 | |
| 3736 | /** |
| 3737 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3738 | */ |
| 3739 | public void setWhenToMakeWifiCalls(int preference) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3740 | final long identity = Binder.clearCallingIdentity(); |
| 3741 | try { |
| 3742 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3743 | Settings.System.putInt(mApp.getContentResolver(), |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3744 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3745 | } finally { |
| 3746 | Binder.restoreCallingIdentity(identity); |
| 3747 | } |
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3748 | } |
| 3749 | |
| Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3750 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
| Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3751 | // TODO: Use a build property to choose this value. |
| Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3752 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3753 | } |
| Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3754 | |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3755 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3756 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3757 | if (phoneId == -1) { |
| 3758 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3759 | + " does not correspond to an active phone"); |
| 3760 | } |
| 3761 | return PhoneFactory.getPhone(phoneId); |
| 3762 | } |
| 3763 | |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3764 | @Override |
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3765 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3766 | int subId, String callingPackage, String aid, int p2) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3767 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3768 | mApp, subId, "iccOpenLogicalChannel"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3769 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3770 | if (DBG) { |
| 3771 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3772 | } |
| 3773 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3774 | p2); |
| 3775 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3776 | |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3777 | |
| 3778 | @Override |
| 3779 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3780 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3781 | enforceModifyPermission(); |
| 3782 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3783 | if (DBG) { |
| 3784 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3785 | } |
| 3786 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3787 | callingPackage, aid, p2); |
| 3788 | } |
| 3789 | |
| 3790 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3791 | String callingPackage, String aid, int p2) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3792 | final long identity = Binder.clearCallingIdentity(); |
| 3793 | try { |
| 3794 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3795 | // Only allows LPA to open logical channel to ISD-R. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3796 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3797 | .getContext().getPackageManager()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3798 | if (bestComponent == null |
| 3799 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3800 | loge("The calling package is not allowed to access ISD-R."); |
| 3801 | throw new SecurityException( |
| 3802 | "The calling package is not allowed to access ISD-R."); |
| 3803 | } |
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3804 | } |
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3805 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3806 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3807 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3808 | null /* workSource */); |
| 3809 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3810 | return response; |
| 3811 | } finally { |
| 3812 | Binder.restoreCallingIdentity(identity); |
| 3813 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3817 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3818 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3819 | mApp, subId, "iccCloseLogicalChannel"); |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3820 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3821 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3822 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3823 | |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3824 | @Override |
| 3825 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3826 | enforceModifyPermission(); |
| 3827 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3828 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3829 | channel); |
| 3830 | } |
| 3831 | |
| 3832 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3833 | final long identity = Binder.clearCallingIdentity(); |
| 3834 | try { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3835 | if (channel < 0) { |
| 3836 | return false; |
| 3837 | } |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3838 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3839 | null /* workSource */); |
| 3840 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3841 | return success; |
| 3842 | } finally { |
| 3843 | Binder.restoreCallingIdentity(identity); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3844 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3848 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3849 | int command, int p1, int p2, int p3, String data) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3850 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3851 | mApp, subId, "iccTransmitApduLogicalChannel"); |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3852 | if (DBG) { |
| 3853 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3854 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3855 | + p3 + " data=" + data); |
| 3856 | } |
| 3857 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3858 | command, p1, p2, p3, data); |
| 3859 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3860 | |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3861 | @Override |
| 3862 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3863 | int command, int p1, int p2, int p3, String data) { |
| 3864 | enforceModifyPermission(); |
| 3865 | if (DBG) { |
| 3866 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3867 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3868 | + p3 + " data=" + data); |
| 3869 | } |
| 3870 | return iccTransmitApduLogicalChannelWithPermission( |
| 3871 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3872 | data); |
| 3873 | } |
| 3874 | |
| 3875 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3876 | int command, int p1, int p2, int p3, String data) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3877 | final long identity = Binder.clearCallingIdentity(); |
| 3878 | try { |
| Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 3879 | if (channel <= 0) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3880 | return ""; |
| 3881 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3882 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3883 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3884 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3885 | null /* workSource */); |
| 3886 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3887 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3888 | // Append the returned status code to the end of the response payload. |
| 3889 | String s = Integer.toHexString( |
| 3890 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3891 | if (response.payload != null) { |
| 3892 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3893 | } |
| 3894 | return s; |
| 3895 | } finally { |
| 3896 | Binder.restoreCallingIdentity(identity); |
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3897 | } |
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3898 | } |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3899 | |
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3900 | @Override |
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3901 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3902 | int command, int p1, int p2, int p3, String data) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3903 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3904 | mApp, subId, "iccTransmitApduBasicChannel"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3905 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3906 | if (DBG) { |
| 3907 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3908 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3909 | } |
| 3910 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3911 | cla, command, p1, p2, p3, data); |
| 3912 | } |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3913 | |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3914 | @Override |
| 3915 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3916 | int command, int p1, int p2, int p3, String data) { |
| 3917 | enforceModifyPermission(); |
| 3918 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3919 | if (DBG) { |
| 3920 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3921 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3922 | + " data=" + data); |
| 3923 | } |
| 3924 | |
| 3925 | return iccTransmitApduBasicChannelWithPermission( |
| 3926 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3927 | p2, p3, data); |
| 3928 | } |
| 3929 | |
| 3930 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3931 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3932 | int cla, int command, int p1, int p2, int p3, String data) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3933 | final long identity = Binder.clearCallingIdentity(); |
| 3934 | try { |
| 3935 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3936 | && TextUtils.equals(ISDR_AID, data)) { |
| 3937 | // Only allows LPA to select ISD-R. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3938 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3939 | .getContext().getPackageManager()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3940 | if (bestComponent == null |
| 3941 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3942 | loge("The calling package is not allowed to select ISD-R."); |
| 3943 | throw new SecurityException( |
| 3944 | "The calling package is not allowed to select ISD-R."); |
| 3945 | } |
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3946 | } |
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3947 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3948 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3949 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 3950 | null /* workSource */); |
| 3951 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3952 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3953 | // Append the returned status code to the end of the response payload. |
| 3954 | String s = Integer.toHexString( |
| 3955 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3956 | if (response.payload != null) { |
| 3957 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3958 | } |
| 3959 | return s; |
| 3960 | } finally { |
| 3961 | Binder.restoreCallingIdentity(identity); |
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3962 | } |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3966 | 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] | 3967 | String filePath) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3968 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3969 | mApp, subId, "iccExchangeSimIO"); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3970 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3971 | final long identity = Binder.clearCallingIdentity(); |
| 3972 | try { |
| 3973 | if (DBG) { |
| 3974 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3975 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3976 | } |
| 3977 | |
| 3978 | IccIoResult response = |
| 3979 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3980 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3981 | subId); |
| 3982 | |
| 3983 | if (DBG) { |
| 3984 | log("Exchange SIM_IO [R]" + response); |
| 3985 | } |
| 3986 | |
| 3987 | byte[] result = null; |
| 3988 | int length = 2; |
| 3989 | if (response.payload != null) { |
| 3990 | length = 2 + response.payload.length; |
| 3991 | result = new byte[length]; |
| 3992 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3993 | } else { |
| 3994 | result = new byte[length]; |
| 3995 | } |
| 3996 | |
| 3997 | result[length - 1] = (byte) response.sw2; |
| 3998 | result[length - 2] = (byte) response.sw1; |
| 3999 | return result; |
| 4000 | } finally { |
| 4001 | Binder.restoreCallingIdentity(identity); |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4002 | } |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4003 | } |
| 4004 | |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4005 | /** |
| 4006 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4007 | * on a particular subscription |
| 4008 | */ |
| sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4009 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 4010 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4011 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 4012 | return null; |
| 4013 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4014 | |
| 4015 | final long identity = Binder.clearCallingIdentity(); |
| 4016 | try { |
| 4017 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4018 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4019 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4020 | return null; |
| 4021 | } |
| 4022 | Object response = sendRequest( |
| 4023 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4024 | if (response instanceof String[]) { |
| 4025 | return (String[]) response; |
| 4026 | } |
| 4027 | // Response is an Exception of some kind, |
| 4028 | // which is signalled to the user as a NULL retval |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4029 | return null; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4030 | } finally { |
| 4031 | Binder.restoreCallingIdentity(identity); |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4032 | } |
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4033 | } |
| 4034 | |
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4035 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4036 | public String sendEnvelopeWithStatus(int subId, String content) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4037 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4038 | mApp, subId, "sendEnvelopeWithStatus"); |
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4039 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4040 | final long identity = Binder.clearCallingIdentity(); |
| 4041 | try { |
| 4042 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4043 | if (response.payload == null) { |
| 4044 | return ""; |
| 4045 | } |
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4046 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4047 | // Append the returned status code to the end of the response payload. |
| 4048 | String s = Integer.toHexString( |
| 4049 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4050 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4051 | return s; |
| 4052 | } finally { |
| 4053 | Binder.restoreCallingIdentity(identity); |
| 4054 | } |
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4055 | } |
| 4056 | |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4057 | /** |
| 4058 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4059 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4060 | * |
| 4061 | * @param itemID the ID of the item to read |
| 4062 | * @return the NV item as a String, or null on error. |
| 4063 | */ |
| 4064 | @Override |
| 4065 | public String nvReadItem(int itemID) { |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4066 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4067 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4068 | mApp, getDefaultSubscription(), "nvReadItem"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4069 | |
| 4070 | final long identity = Binder.clearCallingIdentity(); |
| 4071 | try { |
| 4072 | if (DBG) log("nvReadItem: item " + itemID); |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4073 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4074 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4075 | return value; |
| 4076 | } finally { |
| 4077 | Binder.restoreCallingIdentity(identity); |
| 4078 | } |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | /** |
| 4082 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4083 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4084 | * |
| 4085 | * @param itemID the ID of the item to read |
| 4086 | * @param itemValue the value to write, as a String |
| 4087 | * @return true on success; false on any failure |
| 4088 | */ |
| 4089 | @Override |
| 4090 | public boolean nvWriteItem(int itemID, String itemValue) { |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4091 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4092 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4093 | mApp, getDefaultSubscription(), "nvWriteItem"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4094 | |
| 4095 | final long identity = Binder.clearCallingIdentity(); |
| 4096 | try { |
| 4097 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4098 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4099 | new Pair<Integer, String>(itemID, itemValue), workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4100 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4101 | return success; |
| 4102 | } finally { |
| 4103 | Binder.restoreCallingIdentity(identity); |
| 4104 | } |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4105 | } |
| 4106 | |
| 4107 | /** |
| 4108 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4109 | * Used for device configuration by some CDMA operators. |
| 4110 | * |
| 4111 | * @param preferredRoamingList byte array containing the new PRL |
| 4112 | * @return true on success; false on any failure |
| 4113 | */ |
| 4114 | @Override |
| 4115 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4116 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4117 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4118 | |
| 4119 | final long identity = Binder.clearCallingIdentity(); |
| 4120 | try { |
| 4121 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4122 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4123 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4124 | return success; |
| 4125 | } finally { |
| 4126 | Binder.restoreCallingIdentity(identity); |
| 4127 | } |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4128 | } |
| 4129 | |
| 4130 | /** |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4131 | * 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] | 4132 | * Used for device configuration by some CDMA operators. |
| 4133 | * |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4134 | * @param slotIndex - device slot. |
| 4135 | * |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4136 | * @return true on success; false on any failure |
| 4137 | */ |
| 4138 | @Override |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4139 | public boolean resetModemConfig(int slotIndex) { |
| 4140 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4141 | if (phone != null) { |
| 4142 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4143 | mApp, phone.getSubId(), "resetModemConfig"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4144 | |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4145 | final long identity = Binder.clearCallingIdentity(); |
| 4146 | try { |
| 4147 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4148 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4149 | return success; |
| 4150 | } finally { |
| 4151 | Binder.restoreCallingIdentity(identity); |
| 4152 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4153 | } |
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4154 | return false; |
| 4155 | } |
| 4156 | |
| 4157 | /** |
| 4158 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4159 | * |
| 4160 | * @param slotIndex - device slot. |
| 4161 | * |
| 4162 | * @return true on success; false on any failure |
| 4163 | */ |
| 4164 | @Override |
| 4165 | public boolean rebootModem(int slotIndex) { |
| 4166 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4167 | if (phone != null) { |
| 4168 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4169 | mApp, phone.getSubId(), "rebootModem"); |
| 4170 | |
| 4171 | final long identity = Binder.clearCallingIdentity(); |
| 4172 | try { |
| 4173 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4174 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4175 | return success; |
| 4176 | } finally { |
| 4177 | Binder.restoreCallingIdentity(identity); |
| 4178 | } |
| 4179 | } |
| 4180 | return false; |
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4181 | } |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4182 | |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4183 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4184 | final Phone defaultPhone = getDefaultPhone(); |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4185 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4186 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4187 | return new String[0]; |
| 4188 | } |
| 4189 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4190 | final long identity = Binder.clearCallingIdentity(); |
| 4191 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4192 | return defaultPhone.getPcscfAddress(apnType); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4193 | } finally { |
| 4194 | Binder.restoreCallingIdentity(identity); |
| 4195 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4196 | } |
| 4197 | |
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4198 | /** |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4199 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4200 | * status updates, if not already enabled. |
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4201 | */ |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4202 | public void enableIms(int slotId) { |
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4203 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4204 | |
| 4205 | final long identity = Binder.clearCallingIdentity(); |
| 4206 | try { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4207 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4208 | if (resolver == null) { |
| 4209 | // may happen if the device does not support IMS. |
| 4210 | return; |
| 4211 | } |
| 4212 | resolver.enableIms(slotId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4213 | } finally { |
| 4214 | Binder.restoreCallingIdentity(identity); |
| 4215 | } |
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | /** |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4219 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4220 | * status updates to disabled. |
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4221 | */ |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4222 | public void disableIms(int slotId) { |
| 4223 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4224 | |
| 4225 | final long identity = Binder.clearCallingIdentity(); |
| 4226 | try { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4227 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4228 | if (resolver == null) { |
| 4229 | // may happen if the device does not support IMS. |
| 4230 | return; |
| 4231 | } |
| 4232 | resolver.disableIms(slotId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4233 | } finally { |
| 4234 | Binder.restoreCallingIdentity(identity); |
| 4235 | } |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4236 | } |
| 4237 | |
| 4238 | /** |
| 4239 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4240 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4241 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4242 | */ |
| 4243 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4244 | IImsServiceFeatureCallback callback) { |
| 4245 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4246 | |
| 4247 | final long identity = Binder.clearCallingIdentity(); |
| 4248 | try { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4249 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4250 | if (resolver == null) { |
| 4251 | // may happen if the device does not support IMS. |
| 4252 | return null; |
| 4253 | } |
| 4254 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4255 | } finally { |
| 4256 | Binder.restoreCallingIdentity(identity); |
| 4257 | } |
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | /** |
| 4261 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4262 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4263 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4264 | * listener for feature updates. |
| 4265 | */ |
| 4266 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4267 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4268 | |
| 4269 | final long identity = Binder.clearCallingIdentity(); |
| 4270 | try { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4271 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4272 | if (resolver == null) { |
| 4273 | // may happen if the device does not support IMS. |
| 4274 | return null; |
| 4275 | } |
| 4276 | return resolver.getRcsFeatureAndListen(slotId, callback); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4277 | } finally { |
| 4278 | Binder.restoreCallingIdentity(identity); |
| 4279 | } |
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4280 | } |
| 4281 | |
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4282 | /** |
| 4283 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4284 | * specified or null if IMS is not supported on the slot specified. |
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4285 | */ |
| 4286 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4287 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4288 | |
| 4289 | final long identity = Binder.clearCallingIdentity(); |
| 4290 | try { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4291 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4292 | if (resolver == null) { |
| 4293 | // may happen if the device does not support IMS. |
| 4294 | return null; |
| 4295 | } |
| 4296 | return resolver.getImsRegistration(slotId, feature); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4297 | } finally { |
| 4298 | Binder.restoreCallingIdentity(identity); |
| 4299 | } |
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4300 | } |
| 4301 | |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4302 | /** |
| 4303 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4304 | * specified or null if IMS is not supported on the slot specified. |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4305 | */ |
| 4306 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4307 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4308 | |
| 4309 | final long identity = Binder.clearCallingIdentity(); |
| 4310 | try { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4311 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4312 | if (resolver == null) { |
| 4313 | // may happen if the device does not support IMS. |
| 4314 | return null; |
| 4315 | } |
| 4316 | return resolver.getImsConfig(slotId, feature); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4317 | } finally { |
| 4318 | Binder.restoreCallingIdentity(identity); |
| 4319 | } |
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4320 | } |
| 4321 | |
| Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4322 | /** |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4323 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4324 | * |
| 4325 | * @param slotId the slot ID that the ImsService should bind for. |
| 4326 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4327 | * ImsService is the device default ImsService. |
| 4328 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4329 | * to. |
| 4330 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4331 | * @hide |
| 4332 | */ |
| 4333 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4334 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4335 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4336 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4337 | "setImsService"); |
| 4338 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4339 | final long identity = Binder.clearCallingIdentity(); |
| 4340 | try { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4341 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4342 | if (resolver == null) { |
| 4343 | // may happen if the device does not support IMS. |
| 4344 | return false; |
| 4345 | } |
| 4346 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4347 | packageName); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4348 | } finally { |
| 4349 | Binder.restoreCallingIdentity(identity); |
| 4350 | } |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | /** |
| 4354 | * Return the ImsService configuration. |
| 4355 | * |
| 4356 | * @param slotId The slot that the ImsService is associated with. |
| 4357 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4358 | * the device default. |
| 4359 | * @return the package name of the ImsService configuration. |
| 4360 | */ |
| 4361 | public String getImsService(int slotId, boolean isCarrierImsService) { |
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4362 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4363 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4364 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4365 | "getImsService"); |
| 4366 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4367 | final long identity = Binder.clearCallingIdentity(); |
| 4368 | try { |
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4369 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4370 | if (resolver == null) { |
| 4371 | // may happen if the device does not support IMS. |
| 4372 | return ""; |
| 4373 | } |
| 4374 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4375 | } finally { |
| 4376 | Binder.restoreCallingIdentity(identity); |
| 4377 | } |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4378 | } |
| 4379 | |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4380 | public void setImsRegistrationState(boolean registered) { |
| 4381 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4382 | |
| 4383 | final long identity = Binder.clearCallingIdentity(); |
| 4384 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4385 | getDefaultPhone().setImsRegistrationState(registered); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4386 | } finally { |
| 4387 | Binder.restoreCallingIdentity(identity); |
| 4388 | } |
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | /** |
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4392 | * Set the network selection mode to automatic. |
| 4393 | * |
| 4394 | */ |
| 4395 | @Override |
| 4396 | public void setNetworkSelectionModeAutomatic(int subId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4397 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4398 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4399 | |
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4400 | if (!isActiveSubscription(subId)) { |
| 4401 | return; |
| 4402 | } |
| 4403 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4404 | final long identity = Binder.clearCallingIdentity(); |
| 4405 | try { |
| 4406 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4407 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4408 | } finally { |
| 4409 | Binder.restoreCallingIdentity(identity); |
| 4410 | } |
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4411 | } |
| 4412 | |
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4413 | /** |
| 4414 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4415 | * |
| 4416 | * @param subId the id of the subscription. |
| 4417 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4418 | * the operator to attach to. |
| 4419 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4420 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4421 | * normal network selection next time. |
| 4422 | * @return {@code true} on success; {@code true} on any failure. |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4423 | */ |
| 4424 | @Override |
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4425 | public boolean setNetworkSelectionModeManual( |
| 4426 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4427 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4428 | mApp, subId, "setNetworkSelectionModeManual"); |
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4429 | |
| 4430 | if (!isActiveSubscription(subId)) { |
| 4431 | return false; |
| 4432 | } |
| 4433 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4434 | final long identity = Binder.clearCallingIdentity(); |
| 4435 | try { |
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4436 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4437 | persistSelection); |
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4438 | if (DBG) { |
| 4439 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4440 | + " operator: " + operatorInfo); |
| 4441 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4442 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4443 | } finally { |
| 4444 | Binder.restoreCallingIdentity(identity); |
| 4445 | } |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4446 | } |
| 4447 | |
| 4448 | /** |
| 4449 | * Scans for available networks. |
| 4450 | */ |
| 4451 | @Override |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4452 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4453 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4454 | mApp, subId, "getCellNetworkScanResults"); |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4455 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4456 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4457 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4458 | .setCallingPackage(callingPackage) |
| 4459 | .setCallingPid(Binder.getCallingPid()) |
| 4460 | .setCallingUid(Binder.getCallingUid()) |
| 4461 | .setMethod("getCellNetworkScanResults") |
| 4462 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4463 | .build()); |
| 4464 | switch (locationResult) { |
| 4465 | case DENIED_HARD: |
| 4466 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4467 | case DENIED_SOFT: |
| 4468 | return null; |
| 4469 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4470 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4471 | long identity = Binder.clearCallingIdentity(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4472 | try { |
| 4473 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4474 | return (CellNetworkScanResult) sendRequest( |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4475 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4476 | } finally { |
| 4477 | Binder.restoreCallingIdentity(identity); |
| 4478 | } |
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | /** |
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4482 | * Starts a new network scan and returns the id of this scan. |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4483 | * |
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4484 | * @param subId id of the subscription |
| 4485 | * @param request contains the radio access networks with bands/channels to scan |
| 4486 | * @param messenger callback messenger for scan results or errors |
| 4487 | * @param binder for the purpose of auto clean when the user thread crashes |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4488 | * @return the id of the requested scan which can be used to stop the scan. |
| 4489 | */ |
| 4490 | @Override |
| 4491 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4492 | IBinder binder, String callingPackage) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4493 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4494 | mApp, subId, "requestNetworkScan"); |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4495 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4496 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4497 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4498 | .setCallingPackage(callingPackage) |
| 4499 | .setCallingPid(Binder.getCallingPid()) |
| 4500 | .setCallingUid(Binder.getCallingUid()) |
| 4501 | .setMethod("requestNetworkScan") |
| 4502 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4503 | .build()); |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4504 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
| Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4505 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4506 | if (e != null) { |
| 4507 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4508 | throw e; |
| 4509 | } else { |
| Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4510 | loge(e.getMessage()); |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4511 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4512 | } |
| 4513 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4514 | } |
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4515 | int callingUid = Binder.getCallingUid(); |
| 4516 | int callingPid = Binder.getCallingPid(); |
| Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4517 | final long identity = Binder.clearCallingIdentity(); |
| 4518 | try { |
| 4519 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4520 | request, messenger, binder, getPhone(subId), |
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4521 | callingUid, callingPid, callingPackage); |
| Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4522 | } finally { |
| 4523 | Binder.restoreCallingIdentity(identity); |
| 4524 | } |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4525 | } |
| 4526 | |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4527 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
| Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4528 | NetworkScanRequest request, int subId) { |
| 4529 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4530 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4531 | boolean hasNetworkScanPermission = |
| 4532 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4533 | == PERMISSION_GRANTED; |
| 4534 | |
| 4535 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4536 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4537 | + " for network scans without location access."); |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4541 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4542 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4543 | return new SecurityException("Specific channels must not be" |
| 4544 | + " scanned without location access."); |
| 4545 | } |
| 4546 | } |
| 4547 | } |
| 4548 | |
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4549 | return null; |
| 4550 | } |
| 4551 | |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4552 | /** |
| 4553 | * Stops an existing network scan with the given scanId. |
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4554 | * |
| 4555 | * @param subId id of the subscription |
| 4556 | * @param scanId id of the scan that needs to be stopped |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4557 | */ |
| 4558 | @Override |
| 4559 | public void stopNetworkScan(int subId, int scanId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4560 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4561 | mApp, subId, "stopNetworkScan"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4562 | |
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4563 | int callingUid = Binder.getCallingUid(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4564 | final long identity = Binder.clearCallingIdentity(); |
| 4565 | try { |
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4566 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4567 | } finally { |
| 4568 | Binder.restoreCallingIdentity(identity); |
| 4569 | } |
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4570 | } |
| 4571 | |
| 4572 | /** |
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4573 | * Get the calculated preferred network type. |
| 4574 | * Used for debugging incorrect network type. |
| 4575 | * |
| 4576 | * @return the preferred network type, defined in RILConstants.java. |
| 4577 | */ |
| 4578 | @Override |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4579 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4580 | final Phone defaultPhone = getDefaultPhone(); |
| 4581 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4582 | callingPackage, "getCalculatedPreferredNetworkType")) { |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4583 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4584 | } |
| 4585 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4586 | final long identity = Binder.clearCallingIdentity(); |
| 4587 | try { |
| 4588 | // FIXME: need to get SubId from somewhere. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4589 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4590 | } finally { |
| 4591 | Binder.restoreCallingIdentity(identity); |
| 4592 | } |
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | /** |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4596 | * Get the preferred network type. |
| 4597 | * Used for device configuration by some CDMA operators. |
| 4598 | * |
| 4599 | * @return the preferred network type, defined in RILConstants.java. |
| 4600 | */ |
| 4601 | @Override |
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4602 | public int getPreferredNetworkType(int subId) { |
| Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4603 | TelephonyPermissions |
| 4604 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4605 | mApp, subId, "getPreferredNetworkType"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4606 | |
| 4607 | final long identity = Binder.clearCallingIdentity(); |
| 4608 | try { |
| 4609 | if (DBG) log("getPreferredNetworkType"); |
| 4610 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4611 | int networkType = (result != null ? result[0] : -1); |
| 4612 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4613 | return networkType; |
| 4614 | } finally { |
| 4615 | Binder.restoreCallingIdentity(identity); |
| 4616 | } |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4617 | } |
| 4618 | |
| 4619 | /** |
| 4620 | * Set the preferred network type. |
| 4621 | * Used for device configuration by some CDMA operators. |
| 4622 | * |
| 4623 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4624 | * @return true on success; false on any failure. |
| 4625 | */ |
| 4626 | @Override |
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4627 | public boolean setPreferredNetworkType(int subId, int networkType) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4628 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4629 | mApp, subId, "setPreferredNetworkType"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4630 | |
| 4631 | final long identity = Binder.clearCallingIdentity(); |
| 4632 | try { |
| 4633 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4634 | Boolean success = (Boolean) sendRequest( |
| 4635 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4636 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4637 | if (success) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4638 | Settings.Global.putInt(mApp.getContentResolver(), |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4639 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4640 | } |
| 4641 | return success; |
| 4642 | } finally { |
| 4643 | Binder.restoreCallingIdentity(identity); |
| Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4644 | } |
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4645 | } |
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4646 | |
| 4647 | /** |
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4648 | * Check whether DUN APN is required for tethering with subId. |
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4649 | * |
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4650 | * @param subId the id of the subscription to require tethering. |
| Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4651 | * @return {@code true} if DUN APN is required for tethering. |
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4652 | * @hide |
| 4653 | */ |
| 4654 | @Override |
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4655 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4656 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4657 | final long identity = Binder.clearCallingIdentity(); |
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4658 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4659 | try { |
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4660 | if (phone != null) { |
| 4661 | return phone.hasMatchedTetherApnSetting(); |
| 4662 | } else { |
| 4663 | return false; |
| 4664 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4665 | } finally { |
| 4666 | Binder.restoreCallingIdentity(identity); |
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4667 | } |
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | /** |
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4671 | * Set mobile data enabled |
| 4672 | * Used by the user through settings etc to turn on/off mobile data |
| 4673 | * |
| 4674 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4675 | */ |
| 4676 | @Override |
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4677 | public void setUserDataEnabled(int subId, boolean enable) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4678 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4679 | mApp, subId, "setUserDataEnabled"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4680 | |
| 4681 | final long identity = Binder.clearCallingIdentity(); |
| 4682 | try { |
| 4683 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4684 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4685 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4686 | if (phone != null) { |
| 4687 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
| Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4688 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4689 | } else { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4690 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4691 | } |
| 4692 | } finally { |
| 4693 | Binder.restoreCallingIdentity(identity); |
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4694 | } |
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4695 | } |
| 4696 | |
| 4697 | /** |
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4698 | * Get the user enabled state of Mobile Data. |
| 4699 | * |
| 4700 | * TODO: remove and use isUserDataEnabled. |
| 4701 | * This can't be removed now because some vendor codes |
| 4702 | * calls through ITelephony directly while they should |
| 4703 | * use TelephonyManager. |
| 4704 | * |
| 4705 | * @return true on enabled |
| 4706 | */ |
| 4707 | @Override |
| 4708 | public boolean getDataEnabled(int subId) { |
| 4709 | return isUserDataEnabled(subId); |
| 4710 | } |
| 4711 | |
| 4712 | /** |
| 4713 | * Get whether mobile data is enabled per user setting. |
| 4714 | * |
| 4715 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4716 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4717 | * |
| Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4718 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4719 | * |
| 4720 | * @return {@code true} if data is enabled else {@code false} |
| 4721 | */ |
| 4722 | @Override |
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4723 | public boolean isUserDataEnabled(int subId) { |
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4724 | try { |
| 4725 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4726 | null); |
| 4727 | } catch (Exception e) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4728 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4729 | mApp, subId, "isUserDataEnabled"); |
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4730 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4731 | |
| 4732 | final long identity = Binder.clearCallingIdentity(); |
| 4733 | try { |
| 4734 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4735 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4736 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4737 | if (phone != null) { |
| 4738 | boolean retVal = phone.isUserDataEnabled(); |
| 4739 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4740 | return retVal; |
| 4741 | } else { |
| 4742 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4743 | return false; |
| 4744 | } |
| 4745 | } finally { |
| 4746 | Binder.restoreCallingIdentity(identity); |
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4747 | } |
| 4748 | } |
| 4749 | |
| 4750 | /** |
| 4751 | * Get whether mobile data is enabled. |
| 4752 | * |
| 4753 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4754 | * whether mobile data is actually enabled. |
| 4755 | * |
| 4756 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4757 | * |
| 4758 | * @return {@code true} if data is enabled else {@code false} |
| 4759 | */ |
| 4760 | @Override |
| 4761 | public boolean isDataEnabled(int subId) { |
| 4762 | try { |
| 4763 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4764 | null); |
| 4765 | } catch (Exception e) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4766 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4767 | mApp, subId, "isDataEnabled"); |
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4768 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4769 | |
| 4770 | final long identity = Binder.clearCallingIdentity(); |
| 4771 | try { |
| 4772 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4773 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4774 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4775 | if (phone != null) { |
| Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4776 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4777 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4778 | return retVal; |
| 4779 | } else { |
| 4780 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4781 | return false; |
| 4782 | } |
| 4783 | } finally { |
| 4784 | Binder.restoreCallingIdentity(identity); |
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4785 | } |
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4786 | } |
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4787 | |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4788 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 4789 | Phone phone) { |
| 4790 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 4791 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 4792 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 4793 | || subController == null) return privilegeFromSim; |
| 4794 | |
| 4795 | int uid = Binder.getCallingUid(); |
| 4796 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 4797 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 4798 | |
| 4799 | final long identity = Binder.clearCallingIdentity(); |
| 4800 | try { |
| 4801 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 4802 | SubscriptionManager subManager = (SubscriptionManager) |
| 4803 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 4804 | for (String pkg : packages) { |
| 4805 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 4806 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4807 | } |
| 4808 | } |
| 4809 | return privilegeFromSim; |
| 4810 | } finally { |
| 4811 | Binder.restoreCallingIdentity(identity); |
| 4812 | } |
| 4813 | } |
| 4814 | |
| 4815 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 4816 | String pkgName) { |
| 4817 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 4818 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 4819 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 4820 | || subController == null) return privilegeFromSim; |
| 4821 | |
| 4822 | final long identity = Binder.clearCallingIdentity(); |
| 4823 | try { |
| 4824 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 4825 | SubscriptionManager subManager = (SubscriptionManager) |
| 4826 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 4827 | return subManager.canManageSubscription(subInfo, pkgName) |
| 4828 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 4829 | } finally { |
| 4830 | Binder.restoreCallingIdentity(identity); |
| 4831 | } |
| 4832 | } |
| 4833 | |
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4834 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4835 | public int getCarrierPrivilegeStatus(int subId) { |
| 4836 | final Phone phone = getPhone(subId); |
| 4837 | if (phone == null) { |
| 4838 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4839 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4840 | } |
| 4841 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4842 | if (card == null) { |
| Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4843 | loge("getCarrierPrivilegeStatus: No UICC"); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4844 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4845 | } |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4846 | |
| 4847 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4848 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 4849 | phone.getContext().getPackageManager()), phone); |
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4850 | } |
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4851 | |
| 4852 | @Override |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4853 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4854 | final Phone phone = getPhone(subId); |
| 4855 | if (phone == null) { |
| 4856 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4857 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4858 | } |
| 4859 | UiccProfile profile = |
| 4860 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4861 | if (profile == null) { |
| 4862 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4863 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4864 | } |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4865 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4866 | profile.getCarrierPrivilegeStatusForUid( |
| 4867 | phone.getContext().getPackageManager(), uid), phone); |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4868 | } |
| 4869 | |
| 4870 | @Override |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4871 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 4872 | if (TextUtils.isEmpty(pkgName)) { |
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4873 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 4877 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4878 | if (card == null) { |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4879 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4880 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4881 | } |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4882 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4883 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 4884 | getPhone(phoneId), pkgName); |
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4885 | } |
| 4886 | |
| 4887 | @Override |
| 4888 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4889 | if (TextUtils.isEmpty(pkgName)) |
| 4890 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4891 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4892 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4893 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4894 | if (card == null) { |
| Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4895 | // No UICC in that slot. |
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4896 | continue; |
| 4897 | } |
| 4898 | |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4899 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4900 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 4901 | getPhone(i), pkgName); |
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4902 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4903 | break; |
| 4904 | } |
| 4905 | } |
| 4906 | |
| 4907 | return result; |
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4908 | } |
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4909 | |
| 4910 | @Override |
| Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4911 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4912 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4913 | loge("phoneId " + phoneId + " is not valid."); |
| 4914 | return null; |
| 4915 | } |
| 4916 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4917 | if (card == null) { |
| Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4918 | loge("getCarrierPackageNamesForIntent: No UICC"); |
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4919 | return null ; |
| 4920 | } |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4921 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4922 | } |
| 4923 | |
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4924 | @Override |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4925 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4926 | PackageManager pm = mApp.getPackageManager(); |
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4927 | List<String> privilegedPackages = new ArrayList<>(); |
| 4928 | List<PackageInfo> packages = null; |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4929 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 4930 | // has UICC in that slot. |
| 4931 | if (card != null) { |
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4932 | if (card.hasCarrierPrivilegeRules()) { |
| 4933 | if (packages == null) { |
| 4934 | // Only check packages in user 0 for now |
| 4935 | packages = pm.getInstalledPackagesAsUser( |
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4936 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4937 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 4938 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 4939 | UserHandle.USER_SYSTEM); |
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4940 | } |
| 4941 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4942 | PackageInfo pkgInfo = packages.get(p); |
| 4943 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4944 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4945 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4946 | privilegedPackages.add(pkgInfo.packageName); |
| 4947 | } |
| 4948 | } |
| 4949 | } |
| 4950 | } |
| 4951 | return privilegedPackages; |
| 4952 | } |
| 4953 | |
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4954 | @Override |
| 4955 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
| 4956 | List<String> privilegedPackages = new ArrayList<>(); |
| 4957 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4958 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 4959 | } |
| 4960 | return privilegedPackages; |
| 4961 | } |
| 4962 | |
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4963 | private String getIccId(int subId) { |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4964 | final Phone phone = getPhone(subId); |
| 4965 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4966 | if (card == null) { |
| 4967 | loge("getIccId: No UICC"); |
| 4968 | return null; |
| 4969 | } |
| 4970 | String iccId = card.getIccId(); |
| 4971 | if (TextUtils.isEmpty(iccId)) { |
| 4972 | loge("getIccId: ICC ID is null or empty."); |
| 4973 | return null; |
| 4974 | } |
| 4975 | return iccId; |
| 4976 | } |
| 4977 | |
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4978 | @Override |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4979 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4980 | String number) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4981 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4982 | subId, "setLine1NumberForDisplayForSubscriber"); |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4983 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4984 | final long identity = Binder.clearCallingIdentity(); |
| 4985 | try { |
| 4986 | final String iccId = getIccId(subId); |
| 4987 | final Phone phone = getPhone(subId); |
| 4988 | if (phone == null) { |
| 4989 | return false; |
| 4990 | } |
| 4991 | final String subscriberId = phone.getSubscriberId(); |
| 4992 | |
| 4993 | if (DBG_MERGE) { |
| 4994 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4995 | + subscriberId + " to " + number); |
| 4996 | } |
| 4997 | |
| 4998 | if (TextUtils.isEmpty(iccId)) { |
| 4999 | return false; |
| 5000 | } |
| 5001 | |
| 5002 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5003 | |
| 5004 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5005 | if (alphaTag == null) { |
| 5006 | editor.remove(alphaTagPrefKey); |
| 5007 | } else { |
| 5008 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5009 | } |
| 5010 | |
| 5011 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5012 | // track all merged IMSIs based on line number |
| 5013 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5014 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5015 | if (number == null) { |
| 5016 | editor.remove(numberPrefKey); |
| 5017 | editor.remove(subscriberPrefKey); |
| 5018 | } else { |
| 5019 | editor.putString(numberPrefKey, number); |
| 5020 | editor.putString(subscriberPrefKey, subscriberId); |
| 5021 | } |
| 5022 | |
| 5023 | editor.commit(); |
| 5024 | return true; |
| 5025 | } finally { |
| 5026 | Binder.restoreCallingIdentity(identity); |
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5027 | } |
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5028 | } |
| 5029 | |
| 5030 | @Override |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5031 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
| Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5032 | // This is open to apps with WRITE_SMS. |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5033 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5034 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5035 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5036 | return null; |
| 5037 | } |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5038 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5039 | final long identity = Binder.clearCallingIdentity(); |
| 5040 | try { |
| 5041 | String iccId = getIccId(subId); |
| 5042 | if (iccId != null) { |
| 5043 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5044 | if (DBG_MERGE) { |
| 5045 | log("getLine1NumberForDisplay returning " |
| 5046 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5047 | } |
| 5048 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5049 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5050 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5051 | return null; |
| 5052 | } finally { |
| 5053 | Binder.restoreCallingIdentity(identity); |
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5054 | } |
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5055 | } |
| 5056 | |
| 5057 | @Override |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5058 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5059 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5060 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5061 | return null; |
| 5062 | } |
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5063 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5064 | final long identity = Binder.clearCallingIdentity(); |
| 5065 | try { |
| 5066 | String iccId = getIccId(subId); |
| 5067 | if (iccId != null) { |
| 5068 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5069 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5070 | } |
| 5071 | return null; |
| 5072 | } finally { |
| 5073 | Binder.restoreCallingIdentity(identity); |
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5074 | } |
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5075 | } |
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5076 | |
| 5077 | @Override |
| Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5078 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5079 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5080 | // about carrier-privileged callers not having access. |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5081 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5082 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 5083 | "getMergedSubscriberIds")) { |
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5084 | return null; |
| 5085 | } |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5086 | |
| Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5087 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5088 | // the process, where TelephonyManager was instantiated. |
| 5089 | // Otherwise AppOps check will fail. |
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5090 | final long identity = Binder.clearCallingIdentity(); |
| 5091 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5092 | final Context context = mApp; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5093 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5094 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5095 | |
| 5096 | // Figure out what subscribers are currently active |
| 5097 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5098 | |
| Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5099 | // Only consider subs which match the current subId |
| 5100 | // This logic can be simplified. See b/131189269 for progress. |
| 5101 | if (isActiveSubscription(subId)) { |
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5102 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5103 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5104 | |
| 5105 | // First pass, find a number override for an active subscriber |
| 5106 | String mergeNumber = null; |
| 5107 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5108 | for (String key : prefs.keySet()) { |
| 5109 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5110 | final String subscriberId = (String) prefs.get(key); |
| 5111 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5112 | final String iccId = key.substring( |
| 5113 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5114 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5115 | mergeNumber = (String) prefs.get(numberKey); |
| 5116 | if (DBG_MERGE) { |
| 5117 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5118 | + " for active subscriber " + subscriberId); |
| 5119 | } |
| 5120 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5121 | break; |
| 5122 | } |
| 5123 | } |
| 5124 | } |
| 5125 | } |
| 5126 | |
| 5127 | // Shortcut when no active merged subscribers |
| 5128 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5129 | return null; |
| 5130 | } |
| 5131 | |
| 5132 | // Second pass, find all subscribers under that line override |
| 5133 | final ArraySet<String> result = new ArraySet<>(); |
| 5134 | for (String key : prefs.keySet()) { |
| 5135 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5136 | final String number = (String) prefs.get(key); |
| 5137 | if (mergeNumber.equals(number)) { |
| 5138 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5139 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5140 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5141 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5142 | result.add(subscriberId); |
| 5143 | } |
| 5144 | } |
| 5145 | } |
| 5146 | } |
| 5147 | |
| 5148 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5149 | Arrays.sort(resultArray); |
| 5150 | if (DBG_MERGE) { |
| 5151 | Slog.d(LOG_TAG, |
| 5152 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5153 | } |
| 5154 | return resultArray; |
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5155 | } finally { |
| 5156 | Binder.restoreCallingIdentity(identity); |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5157 | } |
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | @Override |
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5161 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 5162 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 5163 | |
| 5164 | final long identity = Binder.clearCallingIdentity(); |
| 5165 | try { |
| 5166 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5167 | TelephonyManager.class); |
| 5168 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5169 | if (subscriberId == null) { |
| 5170 | if (DBG) { |
| 5171 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 5172 | + subId); |
| 5173 | } |
| 5174 | return null; |
| 5175 | } |
| 5176 | |
| 5177 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5178 | .getSubscriptionInfo(subId); |
| 5179 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5180 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5181 | if (groupUuid == null) { |
| 5182 | return new String[]{subscriberId}; |
| 5183 | } |
| 5184 | |
| 5185 | // Get all subscriberIds from the group. |
| 5186 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5187 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
| 5188 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName()); |
| 5189 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5190 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5191 | if (subscriberId != null) { |
| 5192 | mergedSubscriberIds.add(subscriberId); |
| 5193 | } |
| 5194 | } |
| 5195 | |
| 5196 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5197 | } finally { |
| 5198 | Binder.restoreCallingIdentity(identity); |
| 5199 | |
| 5200 | } |
| 5201 | } |
| 5202 | |
| 5203 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5204 | public boolean setOperatorBrandOverride(int subId, String brand) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5205 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5206 | subId, "setOperatorBrandOverride"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5207 | |
| 5208 | final long identity = Binder.clearCallingIdentity(); |
| 5209 | try { |
| 5210 | final Phone phone = getPhone(subId); |
| 5211 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5212 | } finally { |
| 5213 | Binder.restoreCallingIdentity(identity); |
| 5214 | } |
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5215 | } |
| Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5216 | |
| 5217 | @Override |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5218 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5219 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5220 | List<String> cdmaNonRoamingList) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5221 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5222 | |
| 5223 | final long identity = Binder.clearCallingIdentity(); |
| 5224 | try { |
| 5225 | final Phone phone = getPhone(subId); |
| 5226 | if (phone == null) { |
| 5227 | return false; |
| 5228 | } |
| 5229 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5230 | cdmaNonRoamingList); |
| 5231 | } finally { |
| 5232 | Binder.restoreCallingIdentity(identity); |
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5233 | } |
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | @Override |
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5237 | @Deprecated |
| 5238 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5239 | enforceModifyPermission(); |
| 5240 | |
| 5241 | int returnValue = 0; |
| 5242 | try { |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5243 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5244 | if(result.exception == null) { |
| 5245 | if (result.result != null) { |
| 5246 | byte[] responseData = (byte[])(result.result); |
| 5247 | if(responseData.length > oemResp.length) { |
| 5248 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5249 | responseData.length + "bytes. Buffer Size is " + |
| 5250 | oemResp.length + "bytes."); |
| 5251 | } |
| 5252 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5253 | returnValue = responseData.length; |
| 5254 | } |
| 5255 | } else { |
| 5256 | CommandException ex = (CommandException) result.exception; |
| 5257 | returnValue = ex.getCommandError().ordinal(); |
| 5258 | if(returnValue > 0) returnValue *= -1; |
| 5259 | } |
| 5260 | } catch (RuntimeException e) { |
| 5261 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5262 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5263 | if(returnValue > 0) returnValue *= -1; |
| 5264 | } |
| 5265 | |
| 5266 | return returnValue; |
| 5267 | } |
| 5268 | |
| 5269 | @Override |
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5270 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5271 | try { |
| 5272 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5273 | } catch (RuntimeException e) { |
| 5274 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5275 | } |
| 5276 | } |
| 5277 | |
| 5278 | @Override |
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5279 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5280 | Phone phone = PhoneFactory.getPhone(phoneId); |
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5281 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5282 | if (phone == null) { |
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5283 | return raf; |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5284 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5285 | final long identity = Binder.clearCallingIdentity(); |
| 5286 | try { |
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5287 | TelephonyPermissions |
| 5288 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5289 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5290 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5291 | } finally { |
| 5292 | Binder.restoreCallingIdentity(identity); |
| 5293 | } |
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5294 | return raf; |
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5295 | } |
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5296 | |
| 5297 | @Override |
| 5298 | public void enableVideoCalling(boolean enable) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5299 | final Phone defaultPhone = getDefaultPhone(); |
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5300 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5301 | |
| 5302 | final long identity = Binder.clearCallingIdentity(); |
| 5303 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5304 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5305 | defaultPhone.getPhoneId()).setVtSetting(enable); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5306 | } finally { |
| 5307 | Binder.restoreCallingIdentity(identity); |
| 5308 | } |
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5309 | } |
| 5310 | |
| 5311 | @Override |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5312 | public boolean isVideoCallingEnabled(String callingPackage) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5313 | final Phone defaultPhone = getDefaultPhone(); |
| Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5314 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5315 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
| Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5316 | return false; |
| 5317 | } |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5318 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5319 | final long identity = Binder.clearCallingIdentity(); |
| 5320 | try { |
| 5321 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5322 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5323 | // In the long run, we may instead need to check if there exists a connection service |
| 5324 | // which can support video calling. |
| 5325 | ImsManager imsManager = |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5326 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5327 | return imsManager.isVtEnabledByPlatform() |
| 5328 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5329 | && imsManager.isVtEnabledByUser(); |
| 5330 | } finally { |
| 5331 | Binder.restoreCallingIdentity(identity); |
| 5332 | } |
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5333 | } |
| Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5334 | |
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5335 | @Override |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5336 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5337 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5338 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5339 | return false; |
| 5340 | } |
| 5341 | |
| 5342 | final long identity = Binder.clearCallingIdentity(); |
| 5343 | try { |
| 5344 | CarrierConfigManager configManager = |
| 5345 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5346 | return configManager.getConfigForSubId(subId) |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5347 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5348 | } finally { |
| 5349 | Binder.restoreCallingIdentity(identity); |
| 5350 | } |
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5351 | } |
| 5352 | |
| 5353 | @Override |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5354 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5355 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5356 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5357 | return false; |
| 5358 | } |
| 5359 | |
| 5360 | final long identity = Binder.clearCallingIdentity(); |
| 5361 | try { |
| 5362 | CarrierConfigManager configManager = |
| 5363 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5364 | return configManager.getConfigForSubId(subId) |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5365 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5366 | } finally { |
| 5367 | Binder.restoreCallingIdentity(identity); |
| 5368 | } |
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5369 | } |
| 5370 | |
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5371 | @Override |
| 5372 | public boolean isTtyModeSupported() { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5373 | TelecomManager telecomManager = TelecomManager.from(mApp); |
| Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5374 | return telecomManager.isTtySupported(); |
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5375 | } |
| 5376 | |
| 5377 | @Override |
| 5378 | public boolean isHearingAidCompatibilitySupported() { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5379 | final long identity = Binder.clearCallingIdentity(); |
| 5380 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5381 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5382 | } finally { |
| 5383 | Binder.restoreCallingIdentity(identity); |
| 5384 | } |
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5385 | } |
| 5386 | |
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5387 | /** |
| 5388 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5389 | * support for the feature and device firmware support. |
| 5390 | * |
| 5391 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5392 | */ |
| 5393 | @Override |
| 5394 | public boolean isRttSupported(int subscriptionId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5395 | final long identity = Binder.clearCallingIdentity(); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5396 | final Phone phone = getPhone(subscriptionId); |
| 5397 | if (phone == null) { |
| 5398 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5399 | return false; |
| 5400 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5401 | try { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5402 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5403 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5404 | boolean isDeviceSupported = |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5405 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5406 | return isCarrierSupported && isDeviceSupported; |
| 5407 | } finally { |
| 5408 | Binder.restoreCallingIdentity(identity); |
| 5409 | } |
| Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5410 | } |
| 5411 | |
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5412 | /** |
| Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5413 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 5414 | * RTT setting, will return true if the device and carrier both support RTT. |
| 5415 | * 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] | 5416 | */ |
| 5417 | public boolean isRttEnabled(int subscriptionId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5418 | final long identity = Binder.clearCallingIdentity(); |
| 5419 | try { |
| Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5420 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 5421 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5422 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5423 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 5424 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 5425 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5426 | } finally { |
| 5427 | Binder.restoreCallingIdentity(identity); |
| 5428 | } |
| Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5429 | } |
| 5430 | |
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5431 | /** |
| 5432 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5433 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5434 | * |
| 5435 | * <p>Requires Permission: |
| 5436 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5437 | */ |
| 5438 | @Override |
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5439 | public String getDeviceId(String callingPackage) { |
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5440 | final Phone phone = PhoneFactory.getPhone(0); |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5441 | if (phone == null) { |
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5442 | return null; |
| 5443 | } |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5444 | int subId = phone.getSubId(); |
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5445 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5446 | callingPackage, "getDeviceId")) { |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5447 | return null; |
| 5448 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5449 | |
| 5450 | final long identity = Binder.clearCallingIdentity(); |
| 5451 | try { |
| 5452 | return phone.getDeviceId(); |
| 5453 | } finally { |
| 5454 | Binder.restoreCallingIdentity(identity); |
| 5455 | } |
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5456 | } |
| 5457 | |
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5458 | /** |
| 5459 | * {@hide} |
| 5460 | * Returns the IMS Registration Status on a particular subid |
| 5461 | * |
| 5462 | * @param subId |
| 5463 | */ |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5464 | public boolean isImsRegistered(int subId) { |
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5465 | Phone phone = getPhone(subId); |
| 5466 | if (phone != null) { |
| 5467 | return phone.isImsRegistered(); |
| 5468 | } else { |
| 5469 | return false; |
| 5470 | } |
| 5471 | } |
| 5472 | |
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5473 | @Override |
| 5474 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5475 | final long identity = Binder.clearCallingIdentity(); |
| 5476 | try { |
| 5477 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5478 | } finally { |
| 5479 | Binder.restoreCallingIdentity(identity); |
| 5480 | } |
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5481 | } |
| Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5482 | |
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5483 | @Override |
| 5484 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5485 | final long identity = Binder.clearCallingIdentity(); |
| 5486 | try { |
| 5487 | Phone phone = getPhone(subscriptionId); |
| 5488 | if (phone == null) { |
| 5489 | return null; |
| 5490 | } |
| 5491 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5492 | } finally { |
| 5493 | Binder.restoreCallingIdentity(identity); |
| 5494 | } |
| 5495 | } |
| 5496 | |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5497 | /** |
| 5498 | * @return the VoWiFi calling availability. |
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5499 | */ |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5500 | public boolean isWifiCallingAvailable(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5501 | final long identity = Binder.clearCallingIdentity(); |
| 5502 | try { |
| 5503 | Phone phone = getPhone(subId); |
| 5504 | if (phone != null) { |
| 5505 | return phone.isWifiCallingEnabled(); |
| 5506 | } else { |
| 5507 | return false; |
| 5508 | } |
| 5509 | } finally { |
| 5510 | Binder.restoreCallingIdentity(identity); |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5511 | } |
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5512 | } |
| 5513 | |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5514 | /** |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5515 | * @return the VT calling availability. |
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5516 | */ |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5517 | public boolean isVideoTelephonyAvailable(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5518 | final long identity = Binder.clearCallingIdentity(); |
| 5519 | try { |
| 5520 | Phone phone = getPhone(subId); |
| 5521 | if (phone != null) { |
| 5522 | return phone.isVideoEnabled(); |
| 5523 | } else { |
| 5524 | return false; |
| 5525 | } |
| 5526 | } finally { |
| 5527 | Binder.restoreCallingIdentity(identity); |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5528 | } |
| 5529 | } |
| 5530 | |
| 5531 | /** |
| 5532 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5533 | * defined in {@link ImsRegistrationImplBase}. |
| 5534 | */ |
| 5535 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5536 | final long identity = Binder.clearCallingIdentity(); |
| 5537 | try { |
| 5538 | Phone phone = getPhone(subId); |
| 5539 | if (phone != null) { |
| 5540 | return phone.getImsRegistrationTech(); |
| 5541 | } else { |
| 5542 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5543 | } |
| 5544 | } finally { |
| 5545 | Binder.restoreCallingIdentity(identity); |
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5546 | } |
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5547 | } |
| 5548 | |
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5549 | @Override |
| 5550 | public void factoryReset(int subId) { |
| 5551 | enforceConnectivityInternalPermission(); |
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5552 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5553 | return; |
| 5554 | } |
| 5555 | |
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5556 | final long identity = Binder.clearCallingIdentity(); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5557 | |
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5558 | try { |
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5559 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5560 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5561 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5562 | setNetworkSelectionModeAutomatic(subId); |
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5563 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5564 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5565 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5566 | } |
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5567 | // There has been issues when Sms raw table somehow stores orphan |
| 5568 | // fragments. They lead to garbled message when new fragments come |
| 5569 | // in and combined with those stale ones. In case this happens again, |
| 5570 | // user can reset all network settings which will clean up this table. |
| 5571 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
| Naina Nalluri | 1264a9f | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 5572 | |
| 5573 | // Erase modem config if erase modem on network setting is enabled. |
| 5574 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 5575 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 5576 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 5577 | sendEraseModemConfig(getDefaultPhone()); |
| 5578 | } |
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5579 | } finally { |
| 5580 | Binder.restoreCallingIdentity(identity); |
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5581 | } |
| 5582 | } |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5583 | |
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5584 | private void cleanUpSmsRawTable(Context context) { |
| 5585 | ContentResolver resolver = context.getContentResolver(); |
| 5586 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5587 | resolver.delete(uri, null, null); |
| 5588 | } |
| 5589 | |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5590 | @Override |
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5591 | public String getSimLocaleForSubscriber(int subId) { |
| 5592 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5593 | final Phone phone = getPhone(subId); |
| 5594 | if (phone == null) { |
| 5595 | log("getSimLocaleForSubscriber, invalid subId"); |
| chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5596 | return null; |
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5597 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5598 | final long identity = Binder.clearCallingIdentity(); |
| 5599 | try { |
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5600 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5601 | phone.getContext().getOpPackageName()); |
| chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5602 | if (info == null) { |
| 5603 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5604 | return null; |
| 5605 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5606 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5607 | // preferences (EF-PL and EF-LI)... |
| 5608 | final int mcc = info.getMcc(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5609 | String simLanguage = null; |
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5610 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5611 | if (localeFromDefaultSim != null) { |
| 5612 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5613 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5614 | + localeFromDefaultSim); |
| 5615 | return localeFromDefaultSim.toLanguageTag(); |
| 5616 | } else { |
| 5617 | simLanguage = localeFromDefaultSim.getLanguage(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5618 | } |
| 5619 | } |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5620 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5621 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5622 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5623 | // the SIM and carrier preferences does not include a country we add the country |
| 5624 | // determined from the SIM MCC to provide an exact locale. |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5625 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5626 | if (mccLocale != null) { |
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5627 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5628 | return mccLocale.toLanguageTag(); |
| 5629 | } |
| 5630 | |
| 5631 | if (DBG) log("No locale found - returning null"); |
| 5632 | return null; |
| 5633 | } finally { |
| 5634 | Binder.restoreCallingIdentity(identity); |
| 5635 | } |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5636 | } |
| 5637 | |
| 5638 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5639 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5640 | } |
| 5641 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5642 | /** |
| 5643 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5644 | */ |
| 5645 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5646 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5647 | } |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5648 | |
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5649 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5650 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5651 | |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5652 | /** |
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5653 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5654 | * representing the state of the modem. |
| 5655 | * |
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5656 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5657 | * caller to it. Everyone should call this class to get cumulative data. |
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5658 | * @hide |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5659 | */ |
| 5660 | @Override |
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5661 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5662 | enforceModifyPermission(); |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5663 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5664 | |
| 5665 | final long identity = Binder.clearCallingIdentity(); |
| 5666 | try { |
| 5667 | ModemActivityInfo ret = null; |
| 5668 | synchronized (mLastModemActivityInfo) { |
| 5669 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5670 | CMD_GET_MODEM_ACTIVITY_INFO, |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5671 | null, workSource); |
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5672 | if (isModemActivityInfoValid(info)) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5673 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5674 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5675 | mergedTxTimeMs[i] = info.getTxTimeMillis()[i] |
| 5676 | + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5677 | } |
| 5678 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5679 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 5680 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5681 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5682 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5683 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5684 | mLastModemActivityInfo.setRxTimeMillis( |
| 5685 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5686 | mLastModemActivityInfo.setEnergyUsed( |
| 5687 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5688 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5689 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5690 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5691 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5692 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5693 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5694 | mLastModemActivityInfo.getEnergyUsed()); |
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5695 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5696 | Bundle bundle = new Bundle(); |
| 5697 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5698 | result.send(0, bundle); |
| 5699 | } finally { |
| 5700 | Binder.restoreCallingIdentity(identity); |
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5701 | } |
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5702 | } |
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5703 | |
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5704 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5705 | // less than total activity duration. |
| 5706 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5707 | if (info == null) { |
| 5708 | return false; |
| 5709 | } |
| 5710 | int activityDurationMs = |
| 5711 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5712 | int totalTxTimeMs = 0; |
| 5713 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5714 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5715 | } |
| 5716 | return (info.isValid() |
| 5717 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5718 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5719 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5720 | && (totalTxTimeMs <= activityDurationMs)); |
| 5721 | } |
| 5722 | |
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5723 | /** |
| 5724 | * {@hide} |
| 5725 | * Returns the service state information on specified subscription. |
| 5726 | */ |
| 5727 | @Override |
| 5728 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5729 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5730 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5731 | return null; |
| 5732 | } |
| 5733 | |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5734 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5735 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5736 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5737 | .setCallingPackage(callingPackage) |
| 5738 | .setCallingPid(Binder.getCallingPid()) |
| 5739 | .setCallingUid(Binder.getCallingUid()) |
| 5740 | .setMethod("getServiceStateForSubscriber") |
| Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5741 | .setLogAsInfo(true) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5742 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5743 | .build()); |
| 5744 | |
| 5745 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5746 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5747 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5748 | .setCallingPackage(callingPackage) |
| 5749 | .setCallingPid(Binder.getCallingPid()) |
| 5750 | .setCallingUid(Binder.getCallingUid()) |
| 5751 | .setMethod("getServiceStateForSubscriber") |
| Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5752 | .setLogAsInfo(true) |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5753 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5754 | .build()); |
| 5755 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5756 | boolean hasFinePermission = |
| 5757 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5758 | boolean hasCoarsePermission = |
| 5759 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5760 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5761 | final long identity = Binder.clearCallingIdentity(); |
| 5762 | try { |
| 5763 | final Phone phone = getPhone(subId); |
| 5764 | if (phone == null) { |
| 5765 | return null; |
| 5766 | } |
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5767 | |
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5768 | ServiceState ss = phone.getServiceState(); |
| 5769 | |
| 5770 | // Scrub out the location info in ServiceState depending on what level of access |
| 5771 | // the caller has. |
| 5772 | if (hasFinePermission) return ss; |
| 5773 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5774 | return ss.sanitizeLocationInfo(true); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5775 | } finally { |
| 5776 | Binder.restoreCallingIdentity(identity); |
| 5777 | } |
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5778 | } |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5779 | |
| 5780 | /** |
| 5781 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5782 | * |
| 5783 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5784 | * voicemail ringtone. |
| 5785 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5786 | * PhoneAccount. |
| 5787 | */ |
| 5788 | @Override |
| 5789 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5790 | final long identity = Binder.clearCallingIdentity(); |
| 5791 | try { |
| 5792 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5793 | if (phone == null) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5794 | phone = getDefaultPhone(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5795 | } |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5796 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5797 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5798 | } finally { |
| 5799 | Binder.restoreCallingIdentity(identity); |
| 5800 | } |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5801 | } |
| 5802 | |
| 5803 | /** |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5804 | * Sets the per-account voicemail ringtone. |
| 5805 | * |
| 5806 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5807 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5808 | * |
| 5809 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5810 | * voicemail ringtone. |
| 5811 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5812 | * PhoneAccount. |
| 5813 | */ |
| 5814 | @Override |
| 5815 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5816 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5817 | final Phone defaultPhone = getDefaultPhone(); |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5818 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5819 | if (!TextUtils.equals(callingPackage, |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5820 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5821 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5822 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5823 | "setVoicemailRingtoneUri"); |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5824 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5825 | |
| 5826 | final long identity = Binder.clearCallingIdentity(); |
| 5827 | try { |
| 5828 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5829 | if (phone == null) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5830 | phone = defaultPhone; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5831 | } |
| 5832 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5833 | } finally { |
| 5834 | Binder.restoreCallingIdentity(identity); |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5835 | } |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5836 | } |
| 5837 | |
| 5838 | /** |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5839 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5840 | * |
| 5841 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5842 | * voicemail vibration setting. |
| 5843 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5844 | */ |
| 5845 | @Override |
| 5846 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5847 | final long identity = Binder.clearCallingIdentity(); |
| 5848 | try { |
| 5849 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5850 | if (phone == null) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5851 | phone = getDefaultPhone(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5852 | } |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5853 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5854 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5855 | } finally { |
| 5856 | Binder.restoreCallingIdentity(identity); |
| 5857 | } |
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5858 | } |
| 5859 | |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5860 | /** |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5861 | * Sets the per-account voicemail vibration. |
| 5862 | * |
| 5863 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5864 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5865 | * |
| 5866 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5867 | * voicemail vibration setting. |
| 5868 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5869 | * specific PhoneAccount. |
| 5870 | */ |
| 5871 | @Override |
| 5872 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5873 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5874 | final Phone defaultPhone = getDefaultPhone(); |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5875 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5876 | if (!TextUtils.equals(callingPackage, |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5877 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5878 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5879 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5880 | "setVoicemailVibrationEnabled"); |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5881 | } |
| 5882 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5883 | final long identity = Binder.clearCallingIdentity(); |
| 5884 | try { |
| 5885 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5886 | if (phone == null) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5887 | phone = defaultPhone; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5888 | } |
| 5889 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5890 | } finally { |
| 5891 | Binder.restoreCallingIdentity(identity); |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5892 | } |
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5893 | } |
| 5894 | |
| 5895 | /** |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5896 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5897 | * |
| 5898 | * @throws SecurityException if the caller does not have the required permission |
| 5899 | */ |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5900 | private void enforceReadPrivilegedPermission(String message) { |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5901 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5902 | message); |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | /** |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5906 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5907 | * permission. |
| 5908 | * |
| 5909 | * @throws SecurityException if the caller does not have the required permission |
| 5910 | */ |
| 5911 | private void enforceSendSmsPermission() { |
| 5912 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5913 | } |
| 5914 | |
| 5915 | /** |
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5916 | * Make sure called from the package in charge of visual voicemail. |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5917 | * |
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5918 | * @throws SecurityException if the caller is not the visual voicemail package. |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5919 | */ |
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5920 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5921 | final long identity = Binder.clearCallingIdentity(); |
| 5922 | try { |
| 5923 | ComponentName componentName = |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5924 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5925 | if (componentName == null) { |
| 5926 | throw new SecurityException( |
| 5927 | "Caller not current active visual voicemail package[null]"); |
| 5928 | } |
| 5929 | String vvmPackage = componentName.getPackageName(); |
| 5930 | if (!callingPackage.equals(vvmPackage)) { |
| 5931 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5932 | + vvmPackage + "]"); |
| 5933 | } |
| 5934 | } finally { |
| 5935 | Binder.restoreCallingIdentity(identity); |
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5936 | } |
| 5937 | } |
| 5938 | |
| 5939 | /** |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5940 | * Return the application ID for the app type. |
| 5941 | * |
| 5942 | * @param subId the subscription ID that this request applies to. |
| 5943 | * @param appType the uicc app type. |
| 5944 | * @return Application ID for specificied app type, or null if no uicc. |
| 5945 | */ |
| 5946 | @Override |
| 5947 | public String getAidForAppType(int subId, int appType) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5948 | enforceReadPrivilegedPermission("getAidForAppType"); |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5949 | Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5950 | |
| 5951 | final long identity = Binder.clearCallingIdentity(); |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5952 | try { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5953 | if (phone == null) { |
| 5954 | return null; |
| 5955 | } |
| 5956 | String aid = null; |
| 5957 | try { |
| 5958 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5959 | .getApplicationByType(appType).getAid(); |
| 5960 | } catch (Exception e) { |
| 5961 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5962 | } |
| 5963 | return aid; |
| 5964 | } finally { |
| 5965 | Binder.restoreCallingIdentity(identity); |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5966 | } |
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5967 | } |
| 5968 | |
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5969 | /** |
| 5970 | * Return the Electronic Serial Number. |
| 5971 | * |
| 5972 | * @param subId the subscription ID that this request applies to. |
| 5973 | * @return ESN or null if error. |
| 5974 | */ |
| 5975 | @Override |
| 5976 | public String getEsn(int subId) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5977 | enforceReadPrivilegedPermission("getEsn"); |
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5978 | Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5979 | |
| 5980 | final long identity = Binder.clearCallingIdentity(); |
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5981 | try { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5982 | if (phone == null) { |
| 5983 | return null; |
| 5984 | } |
| 5985 | String esn = null; |
| 5986 | try { |
| 5987 | esn = phone.getEsn(); |
| 5988 | } catch (Exception e) { |
| 5989 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5990 | } |
| 5991 | return esn; |
| 5992 | } finally { |
| 5993 | Binder.restoreCallingIdentity(identity); |
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5994 | } |
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5995 | } |
| 5996 | |
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5997 | /** |
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5998 | * Return the Preferred Roaming List Version. |
| 5999 | * |
| 6000 | * @param subId the subscription ID that this request applies to. |
| 6001 | * @return PRLVersion or null if error. |
| 6002 | */ |
| 6003 | @Override |
| 6004 | public String getCdmaPrlVersion(int subId) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6005 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6006 | Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6007 | |
| 6008 | final long identity = Binder.clearCallingIdentity(); |
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6009 | try { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6010 | if (phone == null) { |
| 6011 | return null; |
| 6012 | } |
| 6013 | String cdmaPrlVersion = null; |
| 6014 | try { |
| 6015 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6016 | } catch (Exception e) { |
| 6017 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6018 | } |
| 6019 | return cdmaPrlVersion; |
| 6020 | } finally { |
| 6021 | Binder.restoreCallingIdentity(identity); |
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6022 | } |
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6023 | } |
| 6024 | |
| 6025 | /** |
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6026 | * Get snapshot of Telephony histograms |
| 6027 | * @return List of Telephony histograms |
| 6028 | * @hide |
| 6029 | */ |
| 6030 | @Override |
| 6031 | public List<TelephonyHistogram> getTelephonyHistograms() { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6032 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6033 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6034 | |
| 6035 | final long identity = Binder.clearCallingIdentity(); |
| 6036 | try { |
| 6037 | return RIL.getTelephonyRILTimingHistograms(); |
| 6038 | } finally { |
| 6039 | Binder.restoreCallingIdentity(identity); |
| 6040 | } |
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6041 | } |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6042 | |
| 6043 | /** |
| 6044 | * {@hide} |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6045 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6046 | * the two lists. |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6047 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6048 | * |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6049 | * @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] | 6050 | */ |
| 6051 | @Override |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6052 | @TelephonyManager.SetCarrierRestrictionResult |
| 6053 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6054 | enforceModifyPermission(); |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6055 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6056 | |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6057 | if (carrierRestrictionRules == null) { |
| 6058 | throw new NullPointerException("carrier restriction cannot be null"); |
| Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6059 | } |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6060 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6061 | final long identity = Binder.clearCallingIdentity(); |
| 6062 | try { |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6063 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6064 | workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6065 | } finally { |
| 6066 | Binder.restoreCallingIdentity(identity); |
| 6067 | } |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6068 | } |
| 6069 | |
| 6070 | /** |
| 6071 | * {@hide} |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6072 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6073 | * the two lists. |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6074 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6075 | * |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6076 | * @return {@link android.telephony.CarrierRestrictionRules} |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6077 | */ |
| 6078 | @Override |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6079 | public CarrierRestrictionRules getAllowedCarriers() { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6080 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6081 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6082 | |
| 6083 | final long identity = Binder.clearCallingIdentity(); |
| 6084 | try { |
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6085 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6086 | if (response instanceof CarrierRestrictionRules) { |
| 6087 | return (CarrierRestrictionRules) response; |
| 6088 | } |
| 6089 | // Response is an Exception of some kind, |
| 6090 | // which is signalled to the user as a NULL retval |
| 6091 | return null; |
| 6092 | } catch (Exception e) { |
| 6093 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6094 | return null; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6095 | } finally { |
| 6096 | Binder.restoreCallingIdentity(identity); |
| 6097 | } |
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6098 | } |
| 6099 | |
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6100 | /** |
| 6101 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6102 | * @param subId the subscription ID that this action applies to. |
| 6103 | * @param enabled control enable or disable metered apns. |
| 6104 | * {@hide} |
| 6105 | */ |
| 6106 | @Override |
| 6107 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6108 | enforceModifyPermission(); |
| 6109 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6110 | |
| 6111 | final long identity = Binder.clearCallingIdentity(); |
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6112 | if (phone == null) { |
| 6113 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6114 | return; |
| 6115 | } |
| 6116 | try { |
| 6117 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6118 | } catch (Exception e) { |
| 6119 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6120 | } finally { |
| 6121 | Binder.restoreCallingIdentity(identity); |
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | /** |
| 6126 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6127 | * @param subId the subscription ID that this action applies to. |
| 6128 | * @param enabled control enable or disable radio. |
| 6129 | * {@hide} |
| 6130 | */ |
| 6131 | @Override |
| 6132 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6133 | enforceModifyPermission(); |
| 6134 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6135 | |
| 6136 | final long identity = Binder.clearCallingIdentity(); |
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6137 | if (phone == null) { |
| 6138 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6139 | return; |
| 6140 | } |
| 6141 | try { |
| 6142 | phone.carrierActionSetRadioEnabled(enabled); |
| 6143 | } catch (Exception e) { |
| 6144 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6145 | } finally { |
| 6146 | Binder.restoreCallingIdentity(identity); |
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6147 | } |
| 6148 | } |
| 6149 | |
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6150 | /** |
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6151 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6152 | * network status based on which carrier apps could apply actions accordingly, |
| 6153 | * enable/disable default url handler for example. |
| 6154 | * |
| 6155 | * @param subId the subscription ID that this action applies to. |
| 6156 | * @param report control start/stop reporting the default network status. |
| 6157 | * {@hide} |
| 6158 | */ |
| 6159 | @Override |
| 6160 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6161 | enforceModifyPermission(); |
| 6162 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6163 | |
| 6164 | final long identity = Binder.clearCallingIdentity(); |
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6165 | if (phone == null) { |
| 6166 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6167 | return; |
| 6168 | } |
| 6169 | try { |
| 6170 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6171 | } catch (Exception e) { |
| 6172 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6173 | } finally { |
| 6174 | Binder.restoreCallingIdentity(identity); |
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6175 | } |
| 6176 | } |
| 6177 | |
| 6178 | /** |
| fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6179 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6180 | * @param subId the subscription ID that this action applies to. |
| 6181 | * {@hide} |
| 6182 | */ |
| 6183 | @Override |
| 6184 | public void carrierActionResetAll(int subId) { |
| 6185 | enforceModifyPermission(); |
| 6186 | final Phone phone = getPhone(subId); |
| 6187 | if (phone == null) { |
| 6188 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6189 | return; |
| 6190 | } |
| 6191 | try { |
| 6192 | phone.carrierActionResetAll(); |
| 6193 | } catch (Exception e) { |
| 6194 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6195 | } |
| 6196 | } |
| 6197 | |
| 6198 | /** |
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6199 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6200 | * bug report is being generated. |
| 6201 | */ |
| 6202 | @Override |
| Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6203 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6204 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6205 | != PackageManager.PERMISSION_GRANTED) { |
| dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6206 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6207 | + Binder.getCallingPid() |
| 6208 | + ", uid=" + Binder.getCallingUid() |
| 6209 | + "without permission " |
| 6210 | + android.Manifest.permission.DUMP); |
| 6211 | return; |
| 6212 | } |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6213 | DumpsysHandler.dump(mApp, fd, writer, args); |
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6214 | } |
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6215 | |
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6216 | @Override |
| 6217 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6218 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6219 | throws RemoteException { |
| 6220 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 6221 | } |
| 6222 | |
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6223 | /** |
| Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6224 | * Get aggregated video call data usage since boot. |
| 6225 | * |
| 6226 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6227 | * @return Snapshot of video call data usage |
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6228 | * {@hide} |
| 6229 | */ |
| 6230 | @Override |
| Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6231 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6232 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6233 | null); |
| 6234 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6235 | final long identity = Binder.clearCallingIdentity(); |
| 6236 | try { |
| 6237 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6238 | // records the delta with the corresponding network identity. |
| 6239 | // We just return the total video call data usage snapshot since boot. |
| 6240 | Phone phone = getPhone(subId); |
| 6241 | if (phone != null) { |
| 6242 | return phone.getVtDataUsage(perUidStats); |
| 6243 | } |
| 6244 | return null; |
| 6245 | } finally { |
| 6246 | Binder.restoreCallingIdentity(identity); |
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6247 | } |
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6248 | } |
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6249 | |
| 6250 | /** |
| 6251 | * Policy control of data connection. Usually used when data limit is passed. |
| 6252 | * @param enabled True if enabling the data, otherwise disabling. |
| 6253 | * @param subId Subscription index |
| 6254 | * {@hide} |
| 6255 | */ |
| 6256 | @Override |
| 6257 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6258 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6259 | |
| 6260 | final long identity = Binder.clearCallingIdentity(); |
| 6261 | try { |
| 6262 | Phone phone = getPhone(subId); |
| 6263 | if (phone != null) { |
| Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6264 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6265 | } |
| 6266 | } finally { |
| 6267 | Binder.restoreCallingIdentity(identity); |
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6268 | } |
| 6269 | } |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6270 | |
| 6271 | /** |
| 6272 | * Get Client request stats |
| 6273 | * @return List of Client Request Stats |
| 6274 | * @hide |
| 6275 | */ |
| 6276 | @Override |
| 6277 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6278 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6279 | mApp, subId, callingPackage, "getClientRequestStats")) { |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6280 | return null; |
| 6281 | } |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6282 | Phone phone = getPhone(subId); |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6283 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6284 | final long identity = Binder.clearCallingIdentity(); |
| 6285 | try { |
| 6286 | if (phone != null) { |
| 6287 | return phone.getClientRequestStats(); |
| 6288 | } |
| 6289 | |
| 6290 | return null; |
| 6291 | } finally { |
| 6292 | Binder.restoreCallingIdentity(identity); |
| 6293 | } |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6294 | } |
| 6295 | |
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6296 | private WorkSource getWorkSource(int uid) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6297 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6298 | return new WorkSource(uid, packageName); |
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6299 | } |
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6300 | |
| 6301 | /** |
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6302 | * Set SIM card power state. |
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6303 | * |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6304 | * @param slotIndex SIM slot id. |
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6305 | * @param state State of SIM (power down, power up, pass through) |
| 6306 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6307 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6308 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6309 | * |
| 6310 | **/ |
| 6311 | @Override |
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6312 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6313 | enforceModifyPermission(); |
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6314 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6315 | |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6316 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6317 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6318 | final long identity = Binder.clearCallingIdentity(); |
| 6319 | try { |
| 6320 | if (phone != null) { |
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6321 | phone.setSimPowerState(state, workSource); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6322 | } |
| 6323 | } finally { |
| 6324 | Binder.restoreCallingIdentity(identity); |
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6325 | } |
| 6326 | } |
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6327 | |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6328 | private boolean isUssdApiAllowed(int subId) { |
| 6329 | CarrierConfigManager configManager = |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6330 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6331 | if (configManager == null) { |
| 6332 | return false; |
| 6333 | } |
| 6334 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6335 | if (pb == null) { |
| 6336 | return false; |
| 6337 | } |
| 6338 | return pb.getBoolean( |
| 6339 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6340 | } |
| 6341 | |
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6342 | /** |
| 6343 | * Check if phone is in emergency callback mode |
| 6344 | * @return true if phone is in emergency callback mode |
| 6345 | * @param subId sub id |
| 6346 | */ |
| goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6347 | @Override |
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6348 | public boolean getEmergencyCallbackMode(int subId) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6349 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6350 | final Phone phone = getPhone(subId); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6351 | |
| 6352 | final long identity = Binder.clearCallingIdentity(); |
| 6353 | try { |
| 6354 | if (phone != null) { |
| 6355 | return phone.isInEcm(); |
| 6356 | } else { |
| 6357 | return false; |
| 6358 | } |
| 6359 | } finally { |
| 6360 | Binder.restoreCallingIdentity(identity); |
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6361 | } |
| 6362 | } |
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6363 | |
| 6364 | /** |
| 6365 | * Get the current signal strength information for the given subscription. |
| 6366 | * Because this information is not updated when the device is in a low power state |
| 6367 | * it should not be relied-upon to be current. |
| 6368 | * @param subId Subscription index |
| 6369 | * @return the most recent cached signal strength info from the modem |
| 6370 | */ |
| 6371 | @Override |
| 6372 | public SignalStrength getSignalStrength(int subId) { |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6373 | final long identity = Binder.clearCallingIdentity(); |
| 6374 | try { |
| 6375 | Phone p = getPhone(subId); |
| 6376 | if (p == null) { |
| 6377 | return null; |
| 6378 | } |
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6379 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6380 | return p.getSignalStrength(); |
| 6381 | } finally { |
| 6382 | Binder.restoreCallingIdentity(identity); |
| 6383 | } |
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6384 | } |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6385 | |
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6386 | /** |
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6387 | * Get the current modem radio state for the given slot. |
| 6388 | * @param slotIndex slot index. |
| 6389 | * @param callingPackage the name of the package making the call. |
| 6390 | * @return the current radio power state from the modem |
| 6391 | */ |
| 6392 | @Override |
| 6393 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6394 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6395 | if (phone != null) { |
| 6396 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6397 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6398 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6399 | } |
| 6400 | |
| 6401 | final long identity = Binder.clearCallingIdentity(); |
| 6402 | try { |
| 6403 | return phone.getRadioPowerState(); |
| 6404 | } finally { |
| 6405 | Binder.restoreCallingIdentity(identity); |
| 6406 | } |
| 6407 | } |
| 6408 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6409 | } |
| 6410 | |
| 6411 | /** |
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6412 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6413 | * |
| 6414 | * <p>Requires one of the following permissions: |
| 6415 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6416 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6417 | * privileges. |
| 6418 | * |
| 6419 | * @param subId subscription id |
| 6420 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6421 | * {@code false}. |
| 6422 | */ |
| 6423 | @Override |
| 6424 | public boolean isDataRoamingEnabled(int subId) { |
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6425 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6426 | null /* message */); |
| 6427 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6428 | boolean isEnabled = false; |
| 6429 | final long identity = Binder.clearCallingIdentity(); |
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6430 | try { |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6431 | Phone phone = getPhone(subId); |
| 6432 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6433 | } catch (Exception e) { |
| 6434 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6435 | mApp, subId, "isDataRoamingEnabled"); |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6436 | } finally { |
| 6437 | Binder.restoreCallingIdentity(identity); |
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6438 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6439 | return isEnabled; |
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6440 | } |
| 6441 | |
| 6442 | |
| 6443 | /** |
| 6444 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6445 | * |
| 6446 | * <p> Requires permission: |
| 6447 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6448 | * privileges. |
| 6449 | * |
| 6450 | * @param subId subscription id |
| 6451 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6452 | */ |
| 6453 | @Override |
| 6454 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6456 | mApp, subId, "setDataRoamingEnabled"); |
| 6457 | |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6458 | final long identity = Binder.clearCallingIdentity(); |
| 6459 | try { |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6460 | Phone phone = getPhone(subId); |
| 6461 | if (phone != null) { |
| 6462 | phone.setDataRoamingEnabled(isEnabled); |
| 6463 | } |
| 6464 | } finally { |
| 6465 | Binder.restoreCallingIdentity(identity); |
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6466 | } |
| 6467 | } |
| 6468 | |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6469 | @Override |
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6470 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6471 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6472 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6473 | |
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6474 | boolean isAllowed = true; |
| 6475 | final long identity = Binder.clearCallingIdentity(); |
| 6476 | try { |
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6477 | Phone phone = getPhone(subId); |
| 6478 | if (phone != null) { |
| 6479 | isAllowed = phone.isCspPlmnEnabled(); |
| 6480 | } |
| 6481 | } finally { |
| 6482 | Binder.restoreCallingIdentity(identity); |
| 6483 | } |
| 6484 | return isAllowed; |
| 6485 | } |
| 6486 | |
| 6487 | @Override |
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6488 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6489 | boolean hasReadPermission = false; |
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6490 | try { |
| 6491 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6492 | hasReadPermission = true; |
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6493 | } catch (SecurityException e) { |
| 6494 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6495 | // has carrier privileges on an active UICC |
| 6496 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6497 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6498 | throw new SecurityException("Caller does not have permission."); |
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6499 | } |
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6500 | } |
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6501 | |
| 6502 | final long identity = Binder.clearCallingIdentity(); |
| 6503 | try { |
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6504 | UiccController uiccController = UiccController.getInstance(); |
| 6505 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6506 | if (hasReadPermission) { |
| 6507 | return cardInfos; |
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6508 | } |
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6509 | |
| 6510 | // Remove private info if the caller doesn't have access |
| 6511 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6512 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6513 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6514 | // is available |
| 6515 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6516 | if (card == null || card.getUiccProfile() == null) { |
| 6517 | // assume no access if the card or profile is unavailable |
| 6518 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6519 | continue; |
| 6520 | } |
| 6521 | UiccProfile profile = card.getUiccProfile(); |
| 6522 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6523 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6524 | filteredInfos.add(cardInfo); |
| 6525 | } else { |
| 6526 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6527 | } |
| 6528 | } |
| 6529 | return filteredInfos; |
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6530 | } finally { |
| 6531 | Binder.restoreCallingIdentity(identity); |
| 6532 | } |
| 6533 | } |
| 6534 | |
| 6535 | @Override |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6536 | public UiccSlotInfo[] getUiccSlotsInfo() { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6537 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6538 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6539 | final long identity = Binder.clearCallingIdentity(); |
| 6540 | try { |
| 6541 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6542 | if (slots == null) { |
| 6543 | Rlog.i(LOG_TAG, "slots is null."); |
| 6544 | return null; |
| 6545 | } |
| 6546 | |
| 6547 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6548 | for (int i = 0; i < slots.length; i++) { |
| 6549 | UiccSlot slot = slots[i]; |
| 6550 | if (slot == null) { |
| 6551 | continue; |
| 6552 | } |
| 6553 | |
| Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6554 | String cardId; |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6555 | UiccCard card = slot.getUiccCard(); |
| 6556 | if (card != null) { |
| 6557 | cardId = card.getCardId(); |
| Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6558 | } else { |
| Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 6559 | cardId = slot.getEid(); |
| 6560 | if (TextUtils.isEmpty(cardId)) { |
| 6561 | cardId = slot.getIccId(); |
| 6562 | } |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6563 | } |
| 6564 | |
| 6565 | int cardState = 0; |
| 6566 | switch (slot.getCardState()) { |
| 6567 | case CARDSTATE_ABSENT: |
| 6568 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6569 | break; |
| 6570 | case CARDSTATE_PRESENT: |
| 6571 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6572 | break; |
| 6573 | case CARDSTATE_ERROR: |
| 6574 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6575 | break; |
| 6576 | case CARDSTATE_RESTRICTED: |
| 6577 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6578 | break; |
| 6579 | default: |
| 6580 | break; |
| 6581 | |
| 6582 | } |
| 6583 | |
| 6584 | infos[i] = new UiccSlotInfo( |
| 6585 | slot.isActive(), |
| 6586 | slot.isEuicc(), |
| 6587 | cardId, |
| 6588 | cardState, |
| 6589 | slot.getPhoneId(), |
| Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6590 | slot.isExtendedApduSupported(), |
| 6591 | slot.isRemovable()); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6592 | } |
| 6593 | return infos; |
| 6594 | } finally { |
| 6595 | Binder.restoreCallingIdentity(identity); |
| Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6596 | } |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6597 | } |
| 6598 | |
| 6599 | @Override |
| 6600 | public boolean switchSlots(int[] physicalSlots) { |
| 6601 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6602 | |
| 6603 | final long identity = Binder.clearCallingIdentity(); |
| 6604 | try { |
| 6605 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6606 | } finally { |
| 6607 | Binder.restoreCallingIdentity(identity); |
| 6608 | } |
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6609 | } |
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6610 | |
| 6611 | @Override |
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6612 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6613 | final long identity = Binder.clearCallingIdentity(); |
| 6614 | try { |
| 6615 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6616 | } finally { |
| 6617 | Binder.restoreCallingIdentity(identity); |
| 6618 | } |
| 6619 | } |
| 6620 | |
| 6621 | @Override |
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6622 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6623 | enforceModifyPermission(); |
| 6624 | final Phone phone = getPhone(subId); |
| 6625 | if (phone == null) { |
| 6626 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6627 | return; |
| 6628 | } |
| 6629 | |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6630 | final long identity = Binder.clearCallingIdentity(); |
| 6631 | try { |
| 6632 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6633 | } finally { |
| 6634 | Binder.restoreCallingIdentity(identity); |
| 6635 | } |
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6636 | } |
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6637 | |
| 6638 | /** |
| goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6639 | * A test API to reload the UICC profile. |
| 6640 | * |
| 6641 | * <p>Requires that the calling app has permission |
| 6642 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6643 | * @hide |
| 6644 | */ |
| 6645 | @Override |
| 6646 | public void refreshUiccProfile(int subId) { |
| 6647 | enforceModifyPermission(); |
| 6648 | |
| 6649 | final long identity = Binder.clearCallingIdentity(); |
| 6650 | try { |
| 6651 | Phone phone = getPhone(subId); |
| 6652 | if (phone == null) { |
| 6653 | return; |
| 6654 | } |
| 6655 | UiccCard uiccCard = phone.getUiccCard(); |
| 6656 | if (uiccCard == null) { |
| 6657 | return; |
| 6658 | } |
| 6659 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6660 | if (uiccProfile == null) { |
| 6661 | return; |
| 6662 | } |
| 6663 | uiccProfile.refresh(); |
| 6664 | } finally { |
| 6665 | Binder.restoreCallingIdentity(identity); |
| 6666 | } |
| 6667 | } |
| 6668 | |
| 6669 | /** |
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6670 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6671 | */ |
| 6672 | private boolean getDefaultDataEnabled() { |
| 6673 | return "true".equalsIgnoreCase( |
| 6674 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6675 | } |
| 6676 | |
| 6677 | /** |
| 6678 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6679 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6680 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6681 | */ |
| 6682 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6683 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6684 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6685 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6686 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6687 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6688 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6689 | return isDataRoamingEnabled; |
| 6690 | } |
| 6691 | |
| 6692 | /** |
| 6693 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6694 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6695 | */ |
| 6696 | private int getDefaultNetworkType(int subId) { |
| 6697 | return Integer.parseInt( |
| 6698 | TelephonyManager.getTelephonyProperty( |
| 6699 | mSubscriptionController.getPhoneId(subId), |
| 6700 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6701 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6702 | } |
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6703 | |
| 6704 | @Override |
| 6705 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6706 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6707 | enforceModifyPermission(); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6708 | |
| 6709 | final long identity = Binder.clearCallingIdentity(); |
| 6710 | try { |
| 6711 | final Phone phone = getPhone(subId); |
| 6712 | if (phone == null) { |
| 6713 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6714 | return; |
| 6715 | } |
| chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6716 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 6717 | carrierPrivilegeRules, apn); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6718 | } finally { |
| 6719 | Binder.restoreCallingIdentity(identity); |
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6720 | } |
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | @Override |
| 6724 | public int getCarrierIdListVersion(int subId) { |
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6725 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6726 | |
| 6727 | final long identity = Binder.clearCallingIdentity(); |
| 6728 | try { |
| 6729 | final Phone phone = getPhone(subId); |
| 6730 | if (phone == null) { |
| 6731 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6732 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6733 | } |
| 6734 | return phone.getCarrierIdListVersion(); |
| 6735 | } finally { |
| 6736 | Binder.restoreCallingIdentity(identity); |
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6737 | } |
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6738 | } |
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6739 | |
| 6740 | @Override |
| 6741 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6742 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6743 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6744 | return -1; |
| 6745 | } |
| 6746 | |
| 6747 | final long identity = Binder.clearCallingIdentity(); |
| 6748 | try { |
| 6749 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6750 | } finally { |
| 6751 | Binder.restoreCallingIdentity(identity); |
| 6752 | } |
| 6753 | } |
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6754 | |
| 6755 | @Override |
| 6756 | public int getCdmaRoamingMode(int subId) { |
| 6757 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6758 | mApp, subId, "getCdmaRoamingMode"); |
| 6759 | |
| 6760 | final long identity = Binder.clearCallingIdentity(); |
| 6761 | try { |
| 6762 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6763 | } finally { |
| 6764 | Binder.restoreCallingIdentity(identity); |
| 6765 | } |
| 6766 | } |
| 6767 | |
| 6768 | @Override |
| 6769 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6770 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6771 | mApp, subId, "setCdmaRoamingMode"); |
| 6772 | |
| 6773 | final long identity = Binder.clearCallingIdentity(); |
| 6774 | try { |
| 6775 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6776 | } finally { |
| 6777 | Binder.restoreCallingIdentity(identity); |
| 6778 | } |
| 6779 | } |
| 6780 | |
| 6781 | @Override |
| 6782 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6783 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6784 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6785 | |
| 6786 | final long identity = Binder.clearCallingIdentity(); |
| 6787 | try { |
| 6788 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6789 | } finally { |
| 6790 | Binder.restoreCallingIdentity(identity); |
| 6791 | } |
| 6792 | } |
| Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 6793 | |
| 6794 | private void ensureUserRunning(int userId) { |
| 6795 | if (!mUserManager.isUserRunning(userId)) { |
| 6796 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6797 | } |
| 6798 | } |
| 6799 | |
| 6800 | /** |
| 6801 | * Returns a list of SMS apps on a given user. |
| 6802 | * |
| 6803 | * Only the shell user (UID 2000 or 0) can call it. |
| 6804 | * Target user must be running. |
| 6805 | */ |
| 6806 | @Override |
| 6807 | public String[] getSmsApps(int userId) { |
| 6808 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6809 | ensureUserRunning(userId); |
| 6810 | |
| 6811 | final Collection<SmsApplicationData> apps = |
| 6812 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6813 | |
| 6814 | String[] ret = new String[apps.size()]; |
| 6815 | int i = 0; |
| 6816 | for (SmsApplicationData app : apps) { |
| 6817 | ret[i++] = app.mPackageName; |
| 6818 | } |
| 6819 | return ret; |
| 6820 | } |
| 6821 | |
| 6822 | /** |
| 6823 | * Returns the default SMS app package name on a given user. |
| 6824 | * |
| 6825 | * Only the shell user (UID 2000 or 0) can call it. |
| 6826 | * Target user must be running. |
| 6827 | */ |
| 6828 | @Override |
| 6829 | public String getDefaultSmsApp(int userId) { |
| 6830 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6831 | ensureUserRunning(userId); |
| 6832 | |
| 6833 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6834 | /* updateIfNeeded= */ true, userId); |
| 6835 | return cn == null ? null : cn.getPackageName(); |
| 6836 | } |
| 6837 | |
| 6838 | /** |
| 6839 | * Set a package as the default SMS app on a given user. |
| 6840 | * |
| 6841 | * Only the shell user (UID 2000 or 0) can call it. |
| 6842 | * Target user must be running. |
| 6843 | */ |
| 6844 | @Override |
| 6845 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6846 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6847 | ensureUserRunning(userId); |
| 6848 | |
| 6849 | boolean found = false; |
| 6850 | for (String pkg : getSmsApps(userId)) { |
| 6851 | if (TextUtils.equals(packageName, pkg)) { |
| 6852 | found = true; |
| 6853 | break; |
| 6854 | } |
| 6855 | } |
| 6856 | if (!found) { |
| 6857 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6858 | } |
| 6859 | |
| 6860 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6861 | } |
| sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6862 | |
| 6863 | @Override |
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6864 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
| sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6865 | String callingPackage) { |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6866 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6867 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6868 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6869 | } |
| 6870 | final long identity = Binder.clearCallingIdentity(); |
| 6871 | try { |
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6872 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6873 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6874 | if (phone.getEmergencyNumberTracker() != null |
| 6875 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6876 | emergencyNumberListInternal.put( |
| 6877 | phone.getSubId(), |
| 6878 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6879 | } |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6880 | } |
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6881 | return emergencyNumberListInternal; |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6882 | } finally { |
| 6883 | Binder.restoreCallingIdentity(identity); |
| 6884 | } |
| sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6885 | } |
| 6886 | |
| 6887 | @Override |
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6888 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6889 | final Phone defaultPhone = getDefaultPhone(); |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6890 | if (!exactMatch) { |
| 6891 | TelephonyPermissions |
| 6892 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6893 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6894 | } |
| 6895 | final long identity = Binder.clearCallingIdentity(); |
| 6896 | try { |
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6897 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6898 | if (phone.getEmergencyNumberTracker() != null |
| 6899 | && phone.getEmergencyNumberTracker() != null) { |
| 6900 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6901 | number, exactMatch)) { |
| 6902 | return true; |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6903 | } |
| 6904 | } |
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6905 | } |
| 6906 | return false; |
| 6907 | } finally { |
| 6908 | Binder.restoreCallingIdentity(identity); |
| 6909 | } |
| 6910 | } |
| 6911 | |
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6912 | /** |
| 6913 | * Update emergency number list for test mode. |
| 6914 | */ |
| 6915 | @Override |
| 6916 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6917 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6918 | "updateEmergencyNumberListTestMode"); |
| 6919 | |
| 6920 | final long identity = Binder.clearCallingIdentity(); |
| 6921 | try { |
| 6922 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6923 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6924 | if (tracker != null) { |
| 6925 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6926 | } |
| 6927 | } |
| 6928 | } finally { |
| 6929 | Binder.restoreCallingIdentity(identity); |
| 6930 | } |
| 6931 | } |
| 6932 | |
| 6933 | /** |
| 6934 | * Get the full emergency number list for test mode. |
| 6935 | */ |
| 6936 | @Override |
| 6937 | public List<String> getEmergencyNumberListTestMode() { |
| 6938 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6939 | "getEmergencyNumberListTestMode"); |
| 6940 | |
| 6941 | final long identity = Binder.clearCallingIdentity(); |
| 6942 | try { |
| 6943 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6944 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6945 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6946 | if (tracker != null) { |
| 6947 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6948 | emergencyNumbers.add(num.getNumber()); |
| 6949 | } |
| 6950 | } |
| 6951 | } |
| 6952 | return new ArrayList<>(emergencyNumbers); |
| 6953 | } finally { |
| 6954 | Binder.restoreCallingIdentity(identity); |
| 6955 | } |
| 6956 | } |
| 6957 | |
| chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6958 | @Override |
| 6959 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6960 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6961 | Phone phone = getPhone(subId); |
| 6962 | if (phone == null) { |
| 6963 | return null; |
| 6964 | } |
| 6965 | final long identity = Binder.clearCallingIdentity(); |
| 6966 | try { |
| 6967 | UiccProfile profile = UiccController.getInstance() |
| 6968 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6969 | if (profile != null) { |
| 6970 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6971 | } |
| 6972 | } finally { |
| 6973 | Binder.restoreCallingIdentity(identity); |
| 6974 | } |
| 6975 | return null; |
| 6976 | } |
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6977 | |
| 6978 | /** |
| 6979 | * Enable or disable a modem stack. |
| 6980 | */ |
| 6981 | @Override |
| 6982 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6983 | enforceModifyPermission(); |
| 6984 | |
| 6985 | final long identity = Binder.clearCallingIdentity(); |
| 6986 | try { |
| 6987 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6988 | if (phone == null) { |
| 6989 | return false; |
| 6990 | } else { |
| 6991 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6992 | } |
| 6993 | } finally { |
| 6994 | Binder.restoreCallingIdentity(identity); |
| 6995 | } |
| 6996 | } |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6997 | |
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6998 | /** |
| 6999 | * Whether a modem stack is enabled or not. |
| 7000 | */ |
| 7001 | @Override |
| 7002 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 7003 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7004 | if (phone == null) return false; |
| 7005 | |
| 7006 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7007 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 7008 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7009 | } |
| 7010 | |
| 7011 | final long identity = Binder.clearCallingIdentity(); |
| 7012 | try { |
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7013 | try { |
| 7014 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7015 | } catch (NoSuchElementException ex) { |
| 7016 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7017 | } |
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7018 | } finally { |
| 7019 | Binder.restoreCallingIdentity(identity); |
| 7020 | } |
| 7021 | } |
| 7022 | |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7023 | @Override |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7024 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7025 | enforceModifyPermission(); |
| 7026 | |
| 7027 | final long identity = Binder.clearCallingIdentity(); |
| 7028 | try { |
| 7029 | mTelephonySharedPreferences.edit() |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7030 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7031 | .commit(); |
| 7032 | } finally { |
| 7033 | Binder.restoreCallingIdentity(identity); |
| 7034 | } |
| 7035 | } |
| 7036 | |
| 7037 | @Override |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7038 | @TelephonyManager.IsMultiSimSupportedResult |
| 7039 | public int isMultiSimSupported(String callingPackage) { |
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7040 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7041 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 7042 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7043 | } |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7044 | |
| 7045 | final long identity = Binder.clearCallingIdentity(); |
| 7046 | try { |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7047 | return isMultiSimSupportedInternal(); |
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7048 | } finally { |
| 7049 | Binder.restoreCallingIdentity(identity); |
| 7050 | } |
| 7051 | } |
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7052 | |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7053 | @TelephonyManager.IsMultiSimSupportedResult |
| 7054 | private int isMultiSimSupportedInternal() { |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7055 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7056 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7057 | if (numPhysicalSlots < 2) { |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7058 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7059 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7060 | } |
| 7061 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7062 | // supported by the modem, indicate that it is restricted. |
| 7063 | PhoneCapability staticCapability = |
| 7064 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7065 | if (staticCapability == null) { |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7066 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7067 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7068 | } |
| 7069 | if (staticCapability.logicalModemList.size() < 2) { |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7070 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7071 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7072 | } |
| 7073 | // Check if support of multiple SIMs is restricted by carrier |
| 7074 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7075 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7076 | } |
| 7077 | |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7078 | return TelephonyManager.MULTISIM_ALLOWED; |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7079 | } |
| 7080 | |
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7081 | /** |
| 7082 | * Switch configs to enable multi-sim or switch back to single-sim |
| Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7083 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7084 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7085 | * or carrier privileges |
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7086 | * @param numOfSims number of active sims we want to switch to |
| 7087 | */ |
| 7088 | @Override |
| 7089 | public void switchMultiSimConfig(int numOfSims) { |
| Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7090 | if (numOfSims == 1) { |
| 7091 | enforceModifyPermission(); |
| 7092 | } else { |
| 7093 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7094 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7095 | } |
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7096 | final long identity = Binder.clearCallingIdentity(); |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7097 | |
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7098 | try { |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7099 | //only proceed if multi-sim is not restricted |
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7100 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7101 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7102 | return; |
| 7103 | } |
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7104 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7105 | } finally { |
| 7106 | Binder.restoreCallingIdentity(identity); |
| 7107 | } |
| 7108 | } |
| 7109 | |
| 7110 | /** |
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7111 | * Get whether making changes to modem configurations will trigger reboot. |
| 7112 | * Return value defaults to true. |
| Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7113 | */ |
| 7114 | @Override |
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7115 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) { |
| 7116 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7117 | mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) { |
| 7118 | return false; |
| 7119 | } |
| Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7120 | final long identity = Binder.clearCallingIdentity(); |
| 7121 | try { |
| 7122 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7123 | } finally { |
| 7124 | Binder.restoreCallingIdentity(identity); |
| 7125 | } |
| 7126 | } |
| 7127 | |
| Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7128 | private void updateModemStateMetrics() { |
| 7129 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7130 | // TODO: check the state for each modem if the api is ready. |
| 7131 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7132 | } |
| 7133 | |
| Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7134 | @Override |
| 7135 | public int[] getSlotsMapping() { |
| 7136 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7137 | |
| 7138 | final long identity = Binder.clearCallingIdentity(); |
| 7139 | try { |
| 7140 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7141 | // All logical slots should have a mapping to a physical slot. |
| 7142 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7143 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7144 | for (int i = 0; i < slotInfos.length; i++) { |
| 7145 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7146 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7147 | } |
| 7148 | } |
| 7149 | return logicalSlotsMapping; |
| 7150 | } finally { |
| 7151 | Binder.restoreCallingIdentity(identity); |
| 7152 | } |
| 7153 | } |
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7154 | |
| 7155 | /** |
| 7156 | * Get the IRadio HAL Version |
| 7157 | */ |
| 7158 | @Override |
| 7159 | public int getRadioHalVersion() { |
| 7160 | Phone phone = getDefaultPhone(); |
| 7161 | if (phone == null) return -1; |
| 7162 | HalVersion hv = phone.getHalVersion(); |
| 7163 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7164 | return hv.major * 100 + hv.minor; |
| 7165 | } |
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7166 | |
| 7167 | /** |
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7168 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7169 | * corresponding network requests on a subId. |
| 7170 | * |
| 7171 | * Data is enabled if: |
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7172 | * 1) user data is turned on, or |
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7173 | * 2) APN is un-metered for this subscription, or |
| 7174 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7175 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7176 | * |
| 7177 | * @return whether data is allowed for a apn type. |
| 7178 | * |
| 7179 | * @hide |
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7180 | */ |
| 7181 | @Override |
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7182 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7183 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7184 | mApp, subId, callingPackage, "isDataEnabledForApn")) { |
| 7185 | throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn"); |
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7186 | } |
| 7187 | |
| 7188 | // Now that all security checks passes, perform the operation as ourselves. |
| 7189 | final long identity = Binder.clearCallingIdentity(); |
| 7190 | try { |
| 7191 | Phone phone = getPhone(subId); |
| 7192 | if (phone == null) return false; |
| 7193 | |
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7194 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7195 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7196 | } finally { |
| 7197 | Binder.restoreCallingIdentity(identity); |
| 7198 | } |
| 7199 | } |
| 7200 | |
| 7201 | @Override |
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7202 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7203 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7204 | |
| 7205 | // Now that all security checks passes, perform the operation as ourselves. |
| 7206 | final long identity = Binder.clearCallingIdentity(); |
| 7207 | try { |
| 7208 | Phone phone = getPhone(subId); |
| 7209 | if (phone == null) return true; // By default return true. |
| 7210 | |
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7211 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7212 | } finally { |
| 7213 | Binder.restoreCallingIdentity(identity); |
| 7214 | } |
| 7215 | } |
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7216 | |
| 7217 | @Override |
| 7218 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7219 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7220 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7221 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7222 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7223 | } |
| 7224 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7225 | Intent intent = new Intent(); |
| 7226 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7227 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7228 | // Bring up choose default SMS subscription dialog right now |
| 7229 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7230 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7231 | mApp.startActivity(intent); |
| 7232 | } |
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7233 | |
| 7234 | @Override |
| 7235 | public String getMmsUAProfUrl(int subId) { |
| 7236 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7237 | final long identity = Binder.clearCallingIdentity(); |
| 7238 | try { |
| 7239 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7240 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7241 | } finally { |
| 7242 | Binder.restoreCallingIdentity(identity); |
| 7243 | } |
| 7244 | } |
| 7245 | |
| 7246 | @Override |
| 7247 | public String getMmsUserAgent(int subId) { |
| 7248 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7249 | final long identity = Binder.clearCallingIdentity(); |
| 7250 | try { |
| 7251 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7252 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7253 | } finally { |
| 7254 | Binder.restoreCallingIdentity(identity); |
| 7255 | } |
| 7256 | } |
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7257 | |
| 7258 | @Override |
| 7259 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7260 | enforceModifyPermission(); |
| 7261 | |
| 7262 | // Now that all security checks passes, perform the operation as ourselves. |
| 7263 | final long identity = Binder.clearCallingIdentity(); |
| 7264 | try { |
| 7265 | Phone phone = getPhone(subId); |
| 7266 | if (phone == null) return false; |
| 7267 | |
| 7268 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7269 | } finally { |
| 7270 | Binder.restoreCallingIdentity(identity); |
| 7271 | } |
| 7272 | } |
| 7273 | |
| 7274 | @Override |
| 7275 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7276 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7277 | |
| 7278 | // Now that all security checks passes, perform the operation as ourselves. |
| 7279 | final long identity = Binder.clearCallingIdentity(); |
| 7280 | try { |
| 7281 | Phone phone = getPhone(subId); |
| 7282 | if (phone == null) return false; |
| 7283 | |
| 7284 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7285 | } finally { |
| 7286 | Binder.restoreCallingIdentity(identity); |
| 7287 | } |
| 7288 | } |
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7289 | } |