Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.server.telecom; |
| 18 | |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 19 | import static android.Manifest.permission.CALL_PHONE; |
Tyler Gunn | b652dad | 2018-03-27 18:49:49 +0000 | [diff] [blame] | 20 | import static android.Manifest.permission.CALL_PRIVILEGED; |
Hall Liu | ecd74a5 | 2016-01-12 15:26:36 -0800 | [diff] [blame] | 21 | import static android.Manifest.permission.DUMP; |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 22 | import static android.Manifest.permission.MODIFY_PHONE_STATE; |
| 23 | import static android.Manifest.permission.READ_PHONE_STATE; |
Amit Mahajan | 3c29693 | 2015-07-14 10:23:15 -0700 | [diff] [blame] | 24 | import static android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE; |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 25 | import static android.Manifest.permission.REGISTER_SIM_SUBSCRIPTION; |
Yorke Lee | 71734c2 | 2015-06-02 14:22:56 -0700 | [diff] [blame] | 26 | import static android.Manifest.permission.WRITE_SECURE_SETTINGS; |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 27 | |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 28 | import android.Manifest; |
Yorke Lee | b398430 | 2015-06-15 12:06:35 -0700 | [diff] [blame] | 29 | import android.app.ActivityManager; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 30 | import android.app.AppOpsManager; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 31 | import android.content.ComponentName; |
| 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
| 34 | import android.content.pm.ApplicationInfo; |
| 35 | import android.content.pm.PackageManager; |
| 36 | import android.content.res.Resources; |
| 37 | import android.net.Uri; |
| 38 | import android.os.Binder; |
| 39 | import android.os.Bundle; |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 40 | import android.os.Process; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 41 | import android.os.UserHandle; |
Brad Ebinger | a3eccfe | 2016-10-05 15:45:22 -0700 | [diff] [blame] | 42 | import android.telecom.Log; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 43 | import android.telecom.PhoneAccount; |
| 44 | import android.telecom.PhoneAccountHandle; |
Hall Liu | 874c0f8 | 2016-04-29 18:13:18 -0700 | [diff] [blame] | 45 | import android.telecom.TelecomAnalytics; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 46 | import android.telecom.TelecomManager; |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 47 | import android.telecom.VideoProfile; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 48 | import android.telephony.SubscriptionManager; |
| 49 | import android.telephony.TelephonyManager; |
Tyler Gunn | 0edfc66 | 2017-04-14 13:46:21 -0700 | [diff] [blame] | 50 | import android.text.TextUtils; |
Brad Ebinger | 62da8e1 | 2016-01-28 19:16:08 -0800 | [diff] [blame] | 51 | import android.util.EventLog; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 52 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 53 | import com.android.internal.telecom.ITelecomService; |
| 54 | import com.android.internal.util.IndentingPrintWriter; |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 55 | import com.android.server.telecom.components.UserCallIntentProcessorFactory; |
Mohamed | c926185 | 2016-02-05 14:10:17 -0800 | [diff] [blame] | 56 | import com.android.server.telecom.settings.BlockedNumbersActivity; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 57 | |
| 58 | import java.io.FileDescriptor; |
| 59 | import java.io.PrintWriter; |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 60 | import java.util.Collections; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 61 | import java.util.List; |
| 62 | |
Eugene Susla | ccba720 | 2017-02-10 10:56:53 -0800 | [diff] [blame] | 63 | // TODO: Needed for move to system service: import com.android.internal.R; |
| 64 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 65 | /** |
| 66 | * Implementation of the ITelecom interface. |
| 67 | */ |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 68 | public class TelecomServiceImpl { |
Hall Liu | 0a6dd30 | 2015-12-16 15:06:49 -0800 | [diff] [blame] | 69 | |
| 70 | public interface SubscriptionManagerAdapter { |
| 71 | int getDefaultVoiceSubId(); |
| 72 | } |
| 73 | |
| 74 | static class SubscriptionManagerAdapterImpl implements SubscriptionManagerAdapter { |
| 75 | @Override |
| 76 | public int getDefaultVoiceSubId() { |
Shishir Agrawal | ce68874 | 2016-01-25 15:02:21 -0800 | [diff] [blame] | 77 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Hall Liu | 0a6dd30 | 2015-12-16 15:06:49 -0800 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
Tyler Gunn | 897e851 | 2017-05-18 15:46:51 -0700 | [diff] [blame] | 81 | private static final String TIME_LINE_ARG = "timeline"; |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 82 | private static final int DEFAULT_VIDEO_STATE = -1; |
Santos Cordon | 7385396 | 2015-02-27 15:13:35 -0800 | [diff] [blame] | 83 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 84 | private final ITelecomService.Stub mBinderImpl = new ITelecomService.Stub() { |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 85 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 86 | public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme, |
| 87 | String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 88 | try { |
| 89 | Log.startSession("TSI.gDOPA"); |
| 90 | synchronized (mLock) { |
| 91 | if (!canReadPhoneState(callingPackage, "getDefaultOutgoingPhoneAccount")) { |
| 92 | return null; |
| 93 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 94 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 95 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 96 | long token = Binder.clearCallingIdentity(); |
| 97 | try { |
| 98 | return mPhoneAccountRegistrar |
| 99 | .getOutgoingPhoneAccountForScheme(uriScheme, callingUserHandle); |
| 100 | } catch (Exception e) { |
| 101 | Log.e(this, e, "getDefaultOutgoingPhoneAccount"); |
| 102 | throw e; |
| 103 | } finally { |
| 104 | Binder.restoreCallingIdentity(token); |
| 105 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 106 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 107 | } finally { |
| 108 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 114 | synchronized (mLock) { |
| 115 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 116 | Log.startSession("TSI.gUSOPA"); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 117 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 118 | return mPhoneAccountRegistrar.getUserSelectedOutgoingPhoneAccount( |
| 119 | callingUserHandle); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 120 | } catch (Exception e) { |
| 121 | Log.e(this, e, "getUserSelectedOutgoingPhoneAccount"); |
| 122 | throw e; |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 123 | } finally { |
| 124 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 125 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 131 | try { |
| 132 | Log.startSession("TSI.sUSOPA"); |
| 133 | synchronized (mLock) { |
| 134 | enforceModifyPermission(); |
| 135 | UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 136 | long token = Binder.clearCallingIdentity(); |
| 137 | try { |
| 138 | mPhoneAccountRegistrar.setUserSelectedOutgoingPhoneAccount( |
| 139 | accountHandle, callingUserHandle); |
| 140 | } catch (Exception e) { |
| 141 | Log.e(this, e, "setUserSelectedOutgoingPhoneAccount"); |
| 142 | throw e; |
| 143 | } finally { |
| 144 | Binder.restoreCallingIdentity(token); |
| 145 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 146 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 147 | } finally { |
| 148 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
| 152 | @Override |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 153 | public List<PhoneAccountHandle> getCallCapablePhoneAccounts( |
| 154 | boolean includeDisabledAccounts, String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 155 | try { |
| 156 | Log.startSession("TSI.gCCPA"); |
| 157 | if (!canReadPhoneState(callingPackage, "getDefaultOutgoingPhoneAccount")) { |
| 158 | return Collections.emptyList(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 159 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 160 | synchronized (mLock) { |
| 161 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 162 | long token = Binder.clearCallingIdentity(); |
| 163 | try { |
| 164 | return mPhoneAccountRegistrar.getCallCapablePhoneAccounts(null, |
| 165 | includeDisabledAccounts, callingUserHandle); |
| 166 | } catch (Exception e) { |
| 167 | Log.e(this, e, "getCallCapablePhoneAccounts"); |
| 168 | throw e; |
| 169 | } finally { |
| 170 | Binder.restoreCallingIdentity(token); |
| 171 | } |
| 172 | } |
| 173 | } finally { |
| 174 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
| 178 | @Override |
Tyler Gunn | ebfc916 | 2017-04-07 15:00:49 -0700 | [diff] [blame] | 179 | public List<PhoneAccountHandle> getSelfManagedPhoneAccounts(String callingPackage) { |
| 180 | try { |
| 181 | Log.startSession("TSI.gSMPA"); |
| 182 | if (!canReadPhoneState(callingPackage, "Requires READ_PHONE_STATE permission.")) { |
| 183 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 184 | } |
| 185 | synchronized (mLock) { |
| 186 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 187 | long token = Binder.clearCallingIdentity(); |
| 188 | try { |
| 189 | return mPhoneAccountRegistrar.getSelfManagedPhoneAccounts( |
| 190 | callingUserHandle); |
| 191 | } catch (Exception e) { |
| 192 | Log.e(this, e, "getSelfManagedPhoneAccounts"); |
| 193 | throw e; |
| 194 | } finally { |
| 195 | Binder.restoreCallingIdentity(token); |
| 196 | } |
| 197 | } |
| 198 | } finally { |
| 199 | Log.endSession(); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 204 | public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme, |
| 205 | String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 206 | try { |
| 207 | Log.startSession("TSI.gPASS"); |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 208 | try { |
| 209 | enforceModifyPermission( |
| 210 | "getPhoneAccountsSupportingScheme requires MODIFY_PHONE_STATE"); |
| 211 | } catch (SecurityException e) { |
| 212 | EventLog.writeEvent(0x534e4554, "62347125", Binder.getCallingUid(), |
| 213 | "getPhoneAccountsSupportingScheme: " + callingPackage); |
| 214 | return Collections.emptyList(); |
| 215 | } |
| 216 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 217 | synchronized (mLock) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 218 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 219 | long token = Binder.clearCallingIdentity(); |
| 220 | try { |
| 221 | return mPhoneAccountRegistrar.getCallCapablePhoneAccounts(uriScheme, false, |
| 222 | callingUserHandle); |
| 223 | } catch (Exception e) { |
| 224 | Log.e(this, e, "getPhoneAccountsSupportingScheme %s", uriScheme); |
| 225 | throw e; |
| 226 | } finally { |
| 227 | Binder.restoreCallingIdentity(token); |
| 228 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 229 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 230 | } finally { |
| 231 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public List<PhoneAccountHandle> getPhoneAccountsForPackage(String packageName) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 237 | synchronized (mLock) { |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 238 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 239 | long token = Binder.clearCallingIdentity(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 240 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 241 | Log.startSession("TSI.gPAFP"); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 242 | return mPhoneAccountRegistrar.getPhoneAccountsForPackage(packageName, |
| 243 | callingUserHandle); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 244 | } catch (Exception e) { |
| 245 | Log.e(this, e, "getPhoneAccountsForPackage %s", packageName); |
| 246 | throw e; |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 247 | } finally { |
| 248 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 249 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 250 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
| 254 | @Override |
| 255 | public PhoneAccount getPhoneAccount(PhoneAccountHandle accountHandle) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 256 | synchronized (mLock) { |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 257 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 258 | long token = Binder.clearCallingIdentity(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 259 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 260 | Log.startSession("TSI.gPA"); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 261 | // In ideal case, we should not resolve the handle across profiles. But given |
| 262 | // the fact that profile's call is handled by its parent user's in-call UI, |
| 263 | // parent user's in call UI need to be able to get phone account from the |
| 264 | // profile's phone account handle. |
| 265 | return mPhoneAccountRegistrar |
| 266 | .getPhoneAccount(accountHandle, callingUserHandle, |
| 267 | /* acrossProfiles */ true); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 268 | } catch (Exception e) { |
| 269 | Log.e(this, e, "getPhoneAccount %s", accountHandle); |
| 270 | throw e; |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 271 | } finally { |
| 272 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 273 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 274 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
| 278 | @Override |
| 279 | public int getAllPhoneAccountsCount() { |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 280 | try { |
| 281 | Log.startSession("TSI.gAPAC"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 282 | try { |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 283 | enforceModifyPermission( |
| 284 | "getAllPhoneAccountsCount requires MODIFY_PHONE_STATE permission."); |
| 285 | } catch (SecurityException e) { |
| 286 | EventLog.writeEvent(0x534e4554, "62347125", Binder.getCallingUid(), |
| 287 | "getAllPhoneAccountsCount"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 288 | throw e; |
| 289 | } |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 290 | |
| 291 | synchronized (mLock) { |
| 292 | try { |
| 293 | // This list is pre-filtered for the calling user. |
| 294 | return getAllPhoneAccounts().size(); |
| 295 | } catch (Exception e) { |
| 296 | Log.e(this, e, "getAllPhoneAccountsCount"); |
| 297 | throw e; |
| 298 | |
| 299 | } |
| 300 | } |
| 301 | } finally { |
| 302 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
| 306 | @Override |
| 307 | public List<PhoneAccount> getAllPhoneAccounts() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 308 | synchronized (mLock) { |
| 309 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 310 | Log.startSession("TSI.gAPA"); |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 311 | try { |
| 312 | enforceModifyPermission( |
| 313 | "getAllPhoneAccounts requires MODIFY_PHONE_STATE permission."); |
| 314 | } catch (SecurityException e) { |
| 315 | EventLog.writeEvent(0x534e4554, "62347125", Binder.getCallingUid(), |
| 316 | "getAllPhoneAccounts"); |
| 317 | throw e; |
| 318 | } |
| 319 | |
| 320 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 321 | long token = Binder.clearCallingIdentity(); |
| 322 | try { |
| 323 | return mPhoneAccountRegistrar.getAllPhoneAccounts(callingUserHandle); |
| 324 | } catch (Exception e) { |
| 325 | Log.e(this, e, "getAllPhoneAccounts"); |
| 326 | throw e; |
| 327 | } finally { |
| 328 | Binder.restoreCallingIdentity(token); |
| 329 | } |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 330 | } finally { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 331 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 332 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public List<PhoneAccountHandle> getAllPhoneAccountHandles() { |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 338 | try { |
| 339 | Log.startSession("TSI.gAPAH"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 340 | try { |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 341 | enforceModifyPermission( |
| 342 | "getAllPhoneAccountHandles requires MODIFY_PHONE_STATE permission."); |
| 343 | } catch (SecurityException e) { |
| 344 | EventLog.writeEvent(0x534e4554, "62347125", Binder.getCallingUid(), |
| 345 | "getAllPhoneAccountHandles"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 346 | throw e; |
| 347 | } |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 348 | |
| 349 | synchronized (mLock) { |
| 350 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 351 | long token = Binder.clearCallingIdentity(); |
| 352 | try { |
| 353 | return mPhoneAccountRegistrar.getAllPhoneAccountHandles(callingUserHandle); |
| 354 | } catch (Exception e) { |
| 355 | Log.e(this, e, "getAllPhoneAccounts"); |
| 356 | throw e; |
| 357 | } finally { |
| 358 | Binder.restoreCallingIdentity(token); |
| 359 | } |
| 360 | } |
| 361 | } finally { |
| 362 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | @Override |
| 367 | public PhoneAccountHandle getSimCallManager() { |
Sailesh Nepal | fc43ea8 | 2015-07-28 19:30:28 -0700 | [diff] [blame] | 368 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 369 | Log.startSession("TSI.gSCM"); |
| 370 | long token = Binder.clearCallingIdentity(); |
| 371 | int user; |
| 372 | try { |
| 373 | user = ActivityManager.getCurrentUser(); |
| 374 | return getSimCallManagerForUser(user); |
| 375 | } finally { |
| 376 | Binder.restoreCallingIdentity(token); |
| 377 | } |
Sailesh Nepal | fc43ea8 | 2015-07-28 19:30:28 -0700 | [diff] [blame] | 378 | } finally { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 379 | Log.endSession(); |
Sailesh Nepal | fc43ea8 | 2015-07-28 19:30:28 -0700 | [diff] [blame] | 380 | } |
Sailesh Nepal | fc43ea8 | 2015-07-28 19:30:28 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public PhoneAccountHandle getSimCallManagerForUser(int user) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 385 | synchronized (mLock) { |
| 386 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 387 | Log.startSession("TSI.gSCMFU"); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 388 | final int callingUid = Binder.getCallingUid(); |
Santos Cordon | 59c21a7 | 2015-06-11 10:11:21 -0700 | [diff] [blame] | 389 | long token = Binder.clearCallingIdentity(); |
| 390 | try { |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 391 | if (user != ActivityManager.getCurrentUser()) { |
| 392 | enforceCrossUserPermission(callingUid); |
| 393 | } |
| 394 | return mPhoneAccountRegistrar.getSimCallManager(UserHandle.of(user)); |
Santos Cordon | 59c21a7 | 2015-06-11 10:11:21 -0700 | [diff] [blame] | 395 | } finally { |
Santos Cordon | 59c21a7 | 2015-06-11 10:11:21 -0700 | [diff] [blame] | 396 | Binder.restoreCallingIdentity(token); |
| 397 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 398 | } catch (Exception e) { |
| 399 | Log.e(this, e, "getSimCallManager"); |
| 400 | throw e; |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 401 | } finally { |
| 402 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 403 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
| 407 | @Override |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 408 | public void registerPhoneAccount(PhoneAccount account) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 409 | try { |
| 410 | Log.startSession("TSI.rPA"); |
| 411 | synchronized (mLock) { |
| 412 | if (!mContext.getApplicationContext().getResources().getBoolean( |
| 413 | com.android.internal.R.bool.config_voice_capable)) { |
| 414 | Log.w(this, |
| 415 | "registerPhoneAccount not allowed on non-voice capable device."); |
| 416 | return; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 417 | } |
Yorke Lee | 5806175 | 2015-05-04 11:06:26 -0700 | [diff] [blame] | 418 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 419 | enforcePhoneAccountModificationForPackage( |
| 420 | account.getAccountHandle().getComponentName().getPackageName()); |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 421 | if (account.hasCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)) { |
| 422 | enforceRegisterSelfManaged(); |
Tyler Gunn | 9e806ee | 2017-02-06 20:49:24 -0800 | [diff] [blame] | 423 | if (account.hasCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER) || |
| 424 | account.hasCapabilities( |
| 425 | PhoneAccount.CAPABILITY_CONNECTION_MANAGER) || |
| 426 | account.hasCapabilities( |
| 427 | PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) { |
| 428 | throw new SecurityException("Self-managed ConnectionServices " + |
| 429 | "cannot also be call capable, connection managers, or " + |
| 430 | "SIM accounts."); |
| 431 | } |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 432 | |
| 433 | // For self-managed CS, the phone account registrar will override the |
| 434 | // label the user has set for the phone account. This ensures the |
| 435 | // self-managed cs implementation can't spoof their app name. |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 436 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 437 | if (account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) { |
| 438 | enforceRegisterSimSubscriptionPermission(); |
| 439 | } |
| 440 | if (account.hasCapabilities(PhoneAccount.CAPABILITY_MULTI_USER)) { |
| 441 | enforceRegisterMultiUser(); |
| 442 | } |
| 443 | enforceUserHandleMatchesCaller(account.getAccountHandle()); |
Tyler Gunn | cbc9be2 | 2017-04-19 10:52:36 -0700 | [diff] [blame] | 444 | final long token = Binder.clearCallingIdentity(); |
| 445 | try { |
| 446 | mPhoneAccountRegistrar.registerPhoneAccount(account); |
| 447 | } finally { |
| 448 | Binder.restoreCallingIdentity(token); |
| 449 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 450 | } catch (Exception e) { |
| 451 | Log.e(this, e, "registerPhoneAccount %s", account); |
| 452 | throw e; |
Yorke Lee | 5806175 | 2015-05-04 11:06:26 -0700 | [diff] [blame] | 453 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 454 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 455 | } finally { |
| 456 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
| 460 | @Override |
| 461 | public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 462 | synchronized (mLock) { |
| 463 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 464 | Log.startSession("TSI.uPA"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 465 | enforcePhoneAccountModificationForPackage( |
| 466 | accountHandle.getComponentName().getPackageName()); |
| 467 | enforceUserHandleMatchesCaller(accountHandle); |
Tyler Gunn | cbc9be2 | 2017-04-19 10:52:36 -0700 | [diff] [blame] | 468 | final long token = Binder.clearCallingIdentity(); |
| 469 | try { |
| 470 | mPhoneAccountRegistrar.unregisterPhoneAccount(accountHandle); |
| 471 | } finally { |
| 472 | Binder.restoreCallingIdentity(token); |
| 473 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 474 | } catch (Exception e) { |
| 475 | Log.e(this, e, "unregisterPhoneAccount %s", accountHandle); |
| 476 | throw e; |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 477 | } finally { |
| 478 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 479 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | |
| 483 | @Override |
| 484 | public void clearAccounts(String packageName) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 485 | synchronized (mLock) { |
| 486 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 487 | Log.startSession("TSI.cA"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 488 | enforcePhoneAccountModificationForPackage(packageName); |
| 489 | mPhoneAccountRegistrar |
| 490 | .clearAccounts(packageName, Binder.getCallingUserHandle()); |
| 491 | } catch (Exception e) { |
| 492 | Log.e(this, e, "clearAccounts %s", packageName); |
| 493 | throw e; |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 494 | } finally { |
| 495 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 496 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * @see android.telecom.TelecomManager#isVoiceMailNumber |
| 502 | */ |
| 503 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 504 | public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number, |
| 505 | String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 506 | try { |
| 507 | Log.startSession("TSI.iVMN"); |
| 508 | synchronized (mLock) { |
| 509 | if (!canReadPhoneState(callingPackage, "isVoiceMailNumber")) { |
| 510 | return false; |
| 511 | } |
| 512 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 513 | if (!isPhoneAccountHandleVisibleToCallingUser(accountHandle, |
| 514 | callingUserHandle)) { |
| 515 | Log.d(this, "%s is not visible for the calling user [iVMN]", accountHandle); |
| 516 | return false; |
| 517 | } |
| 518 | long token = Binder.clearCallingIdentity(); |
| 519 | try { |
| 520 | return mPhoneAccountRegistrar.isVoiceMailNumber(accountHandle, number); |
| 521 | } catch (Exception e) { |
| 522 | Log.e(this, e, "getSubscriptionIdForPhoneAccount"); |
| 523 | throw e; |
| 524 | } finally { |
| 525 | Binder.restoreCallingIdentity(token); |
| 526 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 527 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 528 | } finally { |
| 529 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | /** |
Yorke Lee | fb5ec30 | 2015-04-15 16:15:55 -0700 | [diff] [blame] | 534 | * @see android.telecom.TelecomManager#getVoiceMailNumber |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 535 | */ |
| 536 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 537 | public String getVoiceMailNumber(PhoneAccountHandle accountHandle, String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 538 | try { |
| 539 | Log.startSession("TSI.gVMN"); |
| 540 | synchronized (mLock) { |
| 541 | if (!canReadPhoneState(callingPackage, "getVoiceMailNumber")) { |
Yorke Lee | fb5ec30 | 2015-04-15 16:15:55 -0700 | [diff] [blame] | 542 | return null; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 543 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 544 | try { |
| 545 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 546 | if (!isPhoneAccountHandleVisibleToCallingUser(accountHandle, |
| 547 | callingUserHandle)) { |
| 548 | Log.d(this, "%s is not visible for the calling user [gVMN]", |
| 549 | accountHandle); |
| 550 | return null; |
| 551 | } |
Hall Liu | 0a6dd30 | 2015-12-16 15:06:49 -0800 | [diff] [blame] | 552 | int subId = mSubscriptionManagerAdapter.getDefaultVoiceSubId(); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 553 | if (accountHandle != null) { |
| 554 | subId = mPhoneAccountRegistrar |
| 555 | .getSubscriptionIdForPhoneAccount(accountHandle); |
| 556 | } |
| 557 | return getTelephonyManager().getVoiceMailNumber(subId); |
| 558 | } catch (Exception e) { |
| 559 | Log.e(this, e, "getSubscriptionIdForPhoneAccount"); |
| 560 | throw e; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 561 | } |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 562 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 563 | } finally { |
| 564 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
| 568 | /** |
Nancy Chen | ba30475 | 2015-01-24 23:29:22 -0800 | [diff] [blame] | 569 | * @see android.telecom.TelecomManager#getLine1Number |
| 570 | */ |
| 571 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 572 | public String getLine1Number(PhoneAccountHandle accountHandle, String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 573 | try { |
| 574 | Log.startSession("getL1N"); |
| 575 | if (!canReadPhoneState(callingPackage, "getLine1Number")) { |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 576 | return null; |
| 577 | } |
| 578 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 579 | synchronized (mLock) { |
| 580 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 581 | if (!isPhoneAccountHandleVisibleToCallingUser(accountHandle, |
| 582 | callingUserHandle)) { |
| 583 | Log.d(this, "%s is not visible for the calling user [gL1N]", accountHandle); |
| 584 | return null; |
| 585 | } |
| 586 | |
| 587 | long token = Binder.clearCallingIdentity(); |
| 588 | try { |
| 589 | int subId = mPhoneAccountRegistrar.getSubscriptionIdForPhoneAccount( |
| 590 | accountHandle); |
Shishir Agrawal | ce68874 | 2016-01-25 15:02:21 -0800 | [diff] [blame] | 591 | return getTelephonyManager().getLine1Number(subId); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 592 | } catch (Exception e) { |
| 593 | Log.e(this, e, "getSubscriptionIdForPhoneAccount"); |
| 594 | throw e; |
| 595 | } finally { |
| 596 | Binder.restoreCallingIdentity(token); |
| 597 | } |
Nancy Chen | ba30475 | 2015-01-24 23:29:22 -0800 | [diff] [blame] | 598 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 599 | } finally { |
| 600 | Log.endSession(); |
Nancy Chen | ba30475 | 2015-01-24 23:29:22 -0800 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | |
| 604 | /** |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 605 | * @see android.telecom.TelecomManager#silenceRinger |
| 606 | */ |
| 607 | @Override |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 608 | public void silenceRinger(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 609 | try { |
| 610 | Log.startSession("TSI.sR"); |
| 611 | synchronized (mLock) { |
| 612 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 613 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 614 | long token = Binder.clearCallingIdentity(); |
| 615 | try { |
| 616 | Log.i(this, "Silence Ringer requested by %s", callingPackage); |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 617 | mCallsManager.getCallAudioManager().silenceRingers(); |
Sailesh Nepal | c07b8e1 | 2016-01-23 16:43:10 -0800 | [diff] [blame] | 618 | mCallsManager.getInCallController().silenceRinger(); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 619 | } finally { |
| 620 | Binder.restoreCallingIdentity(token); |
| 621 | } |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 622 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 623 | } finally { |
| 624 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 625 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | /** |
| 629 | * @see android.telecom.TelecomManager#getDefaultPhoneApp |
Yorke Lee | 5b3fc0a | 2015-04-23 17:42:57 -0700 | [diff] [blame] | 630 | * @deprecated - Use {@link android.telecom.TelecomManager#getDefaultDialerPackage()} |
| 631 | * instead. |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 632 | */ |
| 633 | @Override |
| 634 | public ComponentName getDefaultPhoneApp() { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 635 | try { |
| 636 | Log.startSession("TSI.gDPA"); |
| 637 | // No need to synchronize |
| 638 | Resources resources = mContext.getResources(); |
| 639 | return new ComponentName( |
| 640 | resources.getString(R.string.ui_default_package), |
| 641 | resources.getString(R.string.dialer_default_class)); |
| 642 | } finally { |
| 643 | Log.endSession(); |
| 644 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | /** |
Yorke Lee | 5291d4a | 2015-04-24 16:42:36 -0700 | [diff] [blame] | 648 | * @return the package name of the current user-selected default dialer. If no default |
| 649 | * has been selected, the package name of the system dialer is returned. If |
| 650 | * neither exists, then {@code null} is returned. |
Yorke Lee | 5b3fc0a | 2015-04-23 17:42:57 -0700 | [diff] [blame] | 651 | * @see android.telecom.TelecomManager#getDefaultDialerPackage |
| 652 | */ |
| 653 | @Override |
| 654 | public String getDefaultDialerPackage() { |
Yorke Lee | 29c003e | 2015-05-04 17:09:27 -0700 | [diff] [blame] | 655 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 656 | Log.startSession("TSI.gDDP"); |
| 657 | final long token = Binder.clearCallingIdentity(); |
| 658 | try { |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 659 | return mDefaultDialerCache.getDefaultDialerApplication( |
| 660 | ActivityManager.getCurrentUser()); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 661 | } finally { |
| 662 | Binder.restoreCallingIdentity(token); |
| 663 | } |
Yorke Lee | 29c003e | 2015-05-04 17:09:27 -0700 | [diff] [blame] | 664 | } finally { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 665 | Log.endSession(); |
Yorke Lee | 29c003e | 2015-05-04 17:09:27 -0700 | [diff] [blame] | 666 | } |
Yorke Lee | 5b3fc0a | 2015-04-23 17:42:57 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | /** |
| 670 | * @see android.telecom.TelecomManager#getSystemDialerPackage |
| 671 | */ |
| 672 | @Override |
| 673 | public String getSystemDialerPackage() { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 674 | try { |
| 675 | Log.startSession("TSI.gSDP"); |
| 676 | return mContext.getResources().getString(R.string.ui_default_package); |
| 677 | } finally { |
| 678 | Log.endSession(); |
| 679 | } |
Yorke Lee | 5b3fc0a | 2015-04-23 17:42:57 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | /** |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 683 | * @see android.telecom.TelecomManager#isInCall |
| 684 | */ |
| 685 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 686 | public boolean isInCall(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 687 | try { |
| 688 | Log.startSession("TSI.iIC"); |
| 689 | if (!canReadPhoneState(callingPackage, "isInCall")) { |
| 690 | return false; |
| 691 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 692 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 693 | synchronized (mLock) { |
Tyler Gunn | baf105b | 2017-04-11 15:21:03 -0700 | [diff] [blame] | 694 | return mCallsManager.hasOngoingCalls(); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 695 | } |
| 696 | } finally { |
| 697 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 698 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | /** |
Tyler Gunn | 37e782b | 2017-02-10 09:42:03 -0800 | [diff] [blame] | 702 | * @see android.telecom.TelecomManager#isInManagedCall |
| 703 | */ |
| 704 | @Override |
| 705 | public boolean isInManagedCall(String callingPackage) { |
| 706 | try { |
| 707 | Log.startSession("TSI.iIMC"); |
| 708 | if (!canReadPhoneState(callingPackage, "isInManagedCall")) { |
| 709 | throw new SecurityException("Only the default dialer or caller with " + |
| 710 | "READ_PHONE_STATE permission can use this method."); |
| 711 | } |
| 712 | |
| 713 | synchronized (mLock) { |
| 714 | return mCallsManager.hasOngoingManagedCalls(); |
| 715 | } |
| 716 | } finally { |
| 717 | Log.endSession(); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | /** |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 722 | * @see android.telecom.TelecomManager#isRinging |
| 723 | */ |
| 724 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 725 | public boolean isRinging(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 726 | try { |
| 727 | Log.startSession("TSI.iR"); |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 728 | if (!isPrivilegedDialerCalling(callingPackage)) { |
| 729 | try { |
| 730 | enforceModifyPermission( |
| 731 | "isRinging requires MODIFY_PHONE_STATE permission."); |
| 732 | } catch (SecurityException e) { |
| 733 | EventLog.writeEvent(0x534e4554, "62347125", "isRinging: " + callingPackage); |
| 734 | throw e; |
| 735 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 736 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 737 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 738 | synchronized (mLock) { |
| 739 | // Note: We are explicitly checking the calls telecom is tracking rather than |
| 740 | // relying on mCallsManager#getCallState(). Since getCallState() relies on the |
| 741 | // current state as tracked by PhoneStateBroadcaster, any failure to properly |
| 742 | // track the current call state there could result in the wrong ringing state |
| 743 | // being reported by this API. |
| 744 | return mCallsManager.hasRingingCall(); |
| 745 | } |
| 746 | } finally { |
| 747 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 748 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | /** |
| 752 | * @see TelecomManager#getCallState |
| 753 | */ |
| 754 | @Override |
| 755 | public int getCallState() { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 756 | try { |
| 757 | Log.startSession("TSI.getCallState"); |
| 758 | synchronized (mLock) { |
| 759 | return mCallsManager.getCallState(); |
| 760 | } |
| 761 | } finally { |
| 762 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 763 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /** |
| 767 | * @see android.telecom.TelecomManager#endCall |
| 768 | */ |
| 769 | @Override |
Tyler Gunn | 587fc27 | 2018-02-07 16:07:29 -0800 | [diff] [blame] | 770 | public boolean endCall(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 771 | try { |
| 772 | Log.startSession("TSI.eC"); |
| 773 | synchronized (mLock) { |
Tyler Gunn | e27a531 | 2018-05-02 13:41:44 -0700 | [diff] [blame] | 774 | if (!enforceAnswerCallPermission(callingPackage, Binder.getCallingUid())) { |
| 775 | throw new SecurityException("requires ANSWER_PHONE_CALLS permission"); |
| 776 | } |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 777 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 778 | long token = Binder.clearCallingIdentity(); |
| 779 | try { |
Tyler Gunn | 587fc27 | 2018-02-07 16:07:29 -0800 | [diff] [blame] | 780 | return endCallInternal(callingPackage); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 781 | } finally { |
| 782 | Binder.restoreCallingIdentity(token); |
| 783 | } |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 784 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 785 | } finally { |
| 786 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 787 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | /** |
| 791 | * @see android.telecom.TelecomManager#acceptRingingCall |
| 792 | */ |
| 793 | @Override |
Eugene Susla | ccba720 | 2017-02-10 10:56:53 -0800 | [diff] [blame] | 794 | public void acceptRingingCall(String packageName) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 795 | try { |
| 796 | Log.startSession("TSI.aRC"); |
| 797 | synchronized (mLock) { |
Eugene Susla | ccba720 | 2017-02-10 10:56:53 -0800 | [diff] [blame] | 798 | if (!enforceAnswerCallPermission(packageName, Binder.getCallingUid())) return; |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 799 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 800 | long token = Binder.clearCallingIdentity(); |
| 801 | try { |
| 802 | acceptRingingCallInternal(DEFAULT_VIDEO_STATE); |
| 803 | } finally { |
| 804 | Binder.restoreCallingIdentity(token); |
| 805 | } |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 806 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 807 | } finally { |
| 808 | Log.endSession(); |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 809 | } |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * @see android.telecom.TelecomManager#acceptRingingCall(int) |
| 814 | * |
| 815 | */ |
| 816 | @Override |
Eugene Susla | ccba720 | 2017-02-10 10:56:53 -0800 | [diff] [blame] | 817 | public void acceptRingingCallWithVideoState(String packageName, int videoState) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 818 | try { |
| 819 | Log.startSession("TSI.aRCWVS"); |
| 820 | synchronized (mLock) { |
Eugene Susla | ccba720 | 2017-02-10 10:56:53 -0800 | [diff] [blame] | 821 | if (!enforceAnswerCallPermission(packageName, Binder.getCallingUid())) return; |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 822 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 823 | long token = Binder.clearCallingIdentity(); |
| 824 | try { |
| 825 | acceptRingingCallInternal(videoState); |
| 826 | } finally { |
| 827 | Binder.restoreCallingIdentity(token); |
| 828 | } |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 829 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 830 | } finally { |
| 831 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 832 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | /** |
| 836 | * @see android.telecom.TelecomManager#showInCallScreen |
| 837 | */ |
| 838 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 839 | public void showInCallScreen(boolean showDialpad, String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 840 | try { |
| 841 | Log.startSession("TSI.sICS"); |
| 842 | if (!canReadPhoneState(callingPackage, "showInCallScreen")) { |
| 843 | return; |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 844 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 845 | |
| 846 | synchronized (mLock) { |
| 847 | |
| 848 | long token = Binder.clearCallingIdentity(); |
| 849 | try { |
| 850 | mCallsManager.getInCallController().bringToForeground(showDialpad); |
| 851 | } finally { |
| 852 | Binder.restoreCallingIdentity(token); |
| 853 | } |
| 854 | } |
| 855 | } finally { |
| 856 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 857 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | /** |
| 861 | * @see android.telecom.TelecomManager#cancelMissedCallsNotification |
| 862 | */ |
| 863 | @Override |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 864 | public void cancelMissedCallsNotification(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 865 | try { |
| 866 | Log.startSession("TSI.cMCN"); |
| 867 | synchronized (mLock) { |
| 868 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
Tony Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 869 | UserHandle userHandle = Binder.getCallingUserHandle(); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 870 | long token = Binder.clearCallingIdentity(); |
| 871 | try { |
Tony Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 872 | mCallsManager.getMissedCallNotifier().clearMissedCalls(userHandle); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 873 | } finally { |
| 874 | Binder.restoreCallingIdentity(token); |
| 875 | } |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 876 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 877 | } finally { |
| 878 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 879 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 880 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 881 | /** |
| 882 | * @see android.telecom.TelecomManager#handleMmi |
| 883 | */ |
| 884 | @Override |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 885 | public boolean handlePinMmi(String dialString, String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 886 | try { |
| 887 | Log.startSession("TSI.hPM"); |
| 888 | synchronized (mLock) { |
| 889 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 890 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 891 | // Switch identity so that TelephonyManager checks Telecom's permissions |
| 892 | // instead. |
| 893 | long token = Binder.clearCallingIdentity(); |
| 894 | boolean retval = false; |
| 895 | try { |
| 896 | retval = getTelephonyManager().handlePinMmi(dialString); |
| 897 | } finally { |
| 898 | Binder.restoreCallingIdentity(token); |
| 899 | } |
| 900 | |
| 901 | return retval; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 902 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 903 | }finally { |
| 904 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 905 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | /** |
| 909 | * @see android.telecom.TelecomManager#handleMmi |
| 910 | */ |
| 911 | @Override |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 912 | public boolean handlePinMmiForPhoneAccount(PhoneAccountHandle accountHandle, |
| 913 | String dialString, String callingPackage) { |
| 914 | try { |
| 915 | Log.startSession("TSI.hPMFPA"); |
| 916 | synchronized (mLock) { |
| 917 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 918 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 919 | UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 920 | if (!isPhoneAccountHandleVisibleToCallingUser(accountHandle, |
| 921 | callingUserHandle)) { |
| 922 | Log.d(this, "%s is not visible for the calling user [hMMI]", accountHandle); |
| 923 | return false; |
| 924 | } |
| 925 | |
| 926 | // Switch identity so that TelephonyManager checks Telecom's permissions |
| 927 | // instead. |
| 928 | long token = Binder.clearCallingIdentity(); |
| 929 | boolean retval = false; |
| 930 | try { |
| 931 | int subId = mPhoneAccountRegistrar.getSubscriptionIdForPhoneAccount( |
| 932 | accountHandle); |
| 933 | retval = getTelephonyManager().handlePinMmiForSubscriber(subId, dialString); |
| 934 | } finally { |
| 935 | Binder.restoreCallingIdentity(token); |
| 936 | } |
| 937 | return retval; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 938 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 939 | }finally { |
| 940 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 941 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | /** |
| 945 | * @see android.telecom.TelecomManager#getAdnUriForPhoneAccount |
| 946 | */ |
| 947 | @Override |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 948 | public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle, |
| 949 | String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 950 | try { |
| 951 | Log.startSession("TSI.aAUFPA"); |
| 952 | synchronized (mLock) { |
| 953 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
| 954 | if (!isPhoneAccountHandleVisibleToCallingUser(accountHandle, |
| 955 | Binder.getCallingUserHandle())) { |
| 956 | Log.d(this, "%s is not visible for the calling user [gA4PA]", |
| 957 | accountHandle); |
| 958 | return null; |
| 959 | } |
| 960 | // Switch identity so that TelephonyManager checks Telecom's permissions |
| 961 | // instead. |
| 962 | long token = Binder.clearCallingIdentity(); |
| 963 | String retval = "content://icc/adn/"; |
| 964 | try { |
| 965 | long subId = mPhoneAccountRegistrar |
| 966 | .getSubscriptionIdForPhoneAccount(accountHandle); |
| 967 | retval = retval + "subId/" + subId; |
| 968 | } finally { |
| 969 | Binder.restoreCallingIdentity(token); |
| 970 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 971 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 972 | return Uri.parse(retval); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 973 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 974 | } finally { |
| 975 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 976 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | /** |
| 980 | * @see android.telecom.TelecomManager#isTtySupported |
| 981 | */ |
| 982 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 983 | public boolean isTtySupported(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 984 | try { |
| 985 | Log.startSession("TSI.iTS"); |
Sanket Padawe | 88efa0c | 2017-09-08 11:46:34 -0700 | [diff] [blame] | 986 | if (!canReadPhoneState(callingPackage, "isTtySupported")) { |
| 987 | throw new SecurityException("Only default dialer or an app with" + |
| 988 | "READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE can call this api"); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 989 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 990 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 991 | synchronized (mLock) { |
| 992 | return mCallsManager.isTtySupported(); |
| 993 | } |
| 994 | } finally { |
| 995 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 996 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | /** |
| 1000 | * @see android.telecom.TelecomManager#getCurrentTtyMode |
| 1001 | */ |
| 1002 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 1003 | public int getCurrentTtyMode(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1004 | try { |
| 1005 | Log.startSession("TSI.gCTM"); |
| 1006 | if (!canReadPhoneState(callingPackage, "getCurrentTtyMode")) { |
| 1007 | return TelecomManager.TTY_MODE_OFF; |
| 1008 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 1009 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1010 | synchronized (mLock) { |
| 1011 | return mCallsManager.getCurrentTtyMode(); |
| 1012 | } |
| 1013 | } finally { |
| 1014 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1015 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | /** |
| 1019 | * @see android.telecom.TelecomManager#addNewIncomingCall |
| 1020 | */ |
| 1021 | @Override |
| 1022 | public void addNewIncomingCall(PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1023 | try { |
| 1024 | Log.startSession("TSI.aNIC"); |
| 1025 | synchronized (mLock) { |
| 1026 | Log.i(this, "Adding new incoming call with phoneAccountHandle %s", |
Sharvil Nanavati | 6d3efb4 | 2015-05-14 11:36:40 -0700 | [diff] [blame] | 1027 | phoneAccountHandle); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1028 | if (phoneAccountHandle != null && |
| 1029 | phoneAccountHandle.getComponentName() != null) { |
| 1030 | // TODO(sail): Add unit tests for adding incoming calls from a SIM call |
| 1031 | // manager. |
| 1032 | if (isCallerSimCallManager() && TelephonyUtil.isPstnComponentName( |
| 1033 | phoneAccountHandle.getComponentName())) { |
| 1034 | Log.v(this, "Allowing call manager to add incoming call with PSTN" + |
| 1035 | " handle"); |
| 1036 | } else { |
| 1037 | mAppOpsManager.checkPackage( |
| 1038 | Binder.getCallingUid(), |
| 1039 | phoneAccountHandle.getComponentName().getPackageName()); |
| 1040 | // Make sure it doesn't cross the UserHandle boundary |
| 1041 | enforceUserHandleMatchesCaller(phoneAccountHandle); |
Tony Mak | 5851fa0 | 2016-02-23 19:41:52 +0000 | [diff] [blame] | 1042 | enforcePhoneAccountIsRegisteredEnabled(phoneAccountHandle, |
| 1043 | Binder.getCallingUserHandle()); |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1044 | if (isSelfManagedConnectionService(phoneAccountHandle)) { |
| 1045 | // Self-managed phone account, ensure it has MANAGE_OWN_CALLS. |
| 1046 | mContext.enforceCallingOrSelfPermission( |
| 1047 | android.Manifest.permission.MANAGE_OWN_CALLS, |
| 1048 | "Self-managed phone accounts must have MANAGE_OWN_CALLS " + |
| 1049 | "permission."); |
Tyler Gunn | 0c7cf9a | 2017-05-17 11:15:57 -0700 | [diff] [blame] | 1050 | |
| 1051 | // Self-managed ConnectionServices can ONLY add new incoming calls |
| 1052 | // using their own PhoneAccounts. The checkPackage(..) app opps |
| 1053 | // check above ensures this. |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1054 | } |
Sharvil Nanavati | 6d3efb4 | 2015-05-14 11:36:40 -0700 | [diff] [blame] | 1055 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1056 | long token = Binder.clearCallingIdentity(); |
| 1057 | try { |
| 1058 | Intent intent = new Intent(TelecomManager.ACTION_INCOMING_CALL); |
| 1059 | intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, |
| 1060 | phoneAccountHandle); |
| 1061 | intent.putExtra(CallIntentProcessor.KEY_IS_INCOMING_CALL, true); |
| 1062 | if (extras != null) { |
Jeff Sharkey | e2e4cdf | 2016-03-18 12:19:02 -0600 | [diff] [blame] | 1063 | extras.setDefusable(true); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1064 | intent.putExtra(TelecomManager.EXTRA_INCOMING_CALL_EXTRAS, extras); |
| 1065 | } |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1066 | mCallIntentProcessorAdapter.processIncomingCallIntent( |
| 1067 | mCallsManager, intent); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1068 | } finally { |
| 1069 | Binder.restoreCallingIdentity(token); |
| 1070 | } |
| 1071 | } else { |
| 1072 | Log.w(this, "Null phoneAccountHandle. Ignoring request to add new" + |
| 1073 | " incoming call"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1074 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1075 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1076 | } finally { |
| 1077 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | /** |
Sanket Padawe | ccdf364 | 2017-11-10 14:49:05 -0800 | [diff] [blame] | 1082 | * @see android.telecom.TelecomManager#acceptHandover |
| 1083 | */ |
| 1084 | @Override |
| 1085 | public void acceptHandover(Uri srcAddr, int videoState, PhoneAccountHandle destAcct) { |
| 1086 | try { |
| 1087 | Log.startSession("TSI.aHO"); |
| 1088 | synchronized (mLock) { |
Tyler Gunn | 37a4dca | 2018-01-18 15:00:41 -0800 | [diff] [blame] | 1089 | Log.i(this, "acceptHandover; srcAddr=%s, videoState=%s, dest=%s", |
| 1090 | Log.pii(srcAddr), VideoProfile.videoStateToString(videoState), |
Sanket Padawe | ccdf364 | 2017-11-10 14:49:05 -0800 | [diff] [blame] | 1091 | destAcct); |
Tyler Gunn | 37a4dca | 2018-01-18 15:00:41 -0800 | [diff] [blame] | 1092 | |
Sanket Padawe | ccdf364 | 2017-11-10 14:49:05 -0800 | [diff] [blame] | 1093 | if (destAcct != null && destAcct.getComponentName() != null) { |
| 1094 | mAppOpsManager.checkPackage( |
| 1095 | Binder.getCallingUid(), |
| 1096 | destAcct.getComponentName().getPackageName()); |
| 1097 | enforceUserHandleMatchesCaller(destAcct); |
| 1098 | enforcePhoneAccountIsRegisteredEnabled(destAcct, |
| 1099 | Binder.getCallingUserHandle()); |
| 1100 | if (isSelfManagedConnectionService(destAcct)) { |
| 1101 | // Self-managed phone account, ensure it has MANAGE_OWN_CALLS. |
| 1102 | mContext.enforceCallingOrSelfPermission( |
| 1103 | android.Manifest.permission.MANAGE_OWN_CALLS, |
| 1104 | "Self-managed phone accounts must have MANAGE_OWN_CALLS " + |
| 1105 | "permission."); |
| 1106 | } |
Tyler Gunn | 37a4dca | 2018-01-18 15:00:41 -0800 | [diff] [blame] | 1107 | if (!enforceAcceptHandoverPermission( |
| 1108 | destAcct.getComponentName().getPackageName(), |
| 1109 | Binder.getCallingUid())) { |
| 1110 | throw new SecurityException("App must be granted runtime " |
| 1111 | + "ACCEPT_HANDOVER permission."); |
| 1112 | } |
Sanket Padawe | ccdf364 | 2017-11-10 14:49:05 -0800 | [diff] [blame] | 1113 | |
Tyler Gunn | 37a4dca | 2018-01-18 15:00:41 -0800 | [diff] [blame] | 1114 | long token = Binder.clearCallingIdentity(); |
| 1115 | try { |
| 1116 | mCallsManager.acceptHandover(srcAddr, videoState, destAcct); |
| 1117 | } finally { |
| 1118 | Binder.restoreCallingIdentity(token); |
| 1119 | } |
Sanket Padawe | ccdf364 | 2017-11-10 14:49:05 -0800 | [diff] [blame] | 1120 | } else { |
| 1121 | Log.w(this, "Null phoneAccountHandle. Ignoring request " + |
| 1122 | "to handover the call"); |
| 1123 | } |
| 1124 | } |
| 1125 | } finally { |
| 1126 | Log.endSession(); |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | /** |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1131 | * @see android.telecom.TelecomManager#addNewUnknownCall |
| 1132 | */ |
| 1133 | @Override |
| 1134 | public void addNewUnknownCall(PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1135 | try { |
| 1136 | Log.startSession("TSI.aNUC"); |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 1137 | try { |
| 1138 | enforceModifyPermission( |
| 1139 | "addNewUnknownCall requires MODIFY_PHONE_STATE permission."); |
| 1140 | } catch (SecurityException e) { |
| 1141 | EventLog.writeEvent(0x534e4554, "62347125", Binder.getCallingUid(), |
| 1142 | "addNewUnknownCall"); |
| 1143 | throw e; |
| 1144 | } |
| 1145 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1146 | synchronized (mLock) { |
| 1147 | if (phoneAccountHandle != null && |
| 1148 | phoneAccountHandle.getComponentName() != null) { |
| 1149 | mAppOpsManager.checkPackage( |
| 1150 | Binder.getCallingUid(), |
| 1151 | phoneAccountHandle.getComponentName().getPackageName()); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1152 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1153 | // Make sure it doesn't cross the UserHandle boundary |
| 1154 | enforceUserHandleMatchesCaller(phoneAccountHandle); |
Tony Mak | 5851fa0 | 2016-02-23 19:41:52 +0000 | [diff] [blame] | 1155 | enforcePhoneAccountIsRegisteredEnabled(phoneAccountHandle, |
| 1156 | Binder.getCallingUserHandle()); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1157 | long token = Binder.clearCallingIdentity(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1158 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1159 | try { |
| 1160 | Intent intent = new Intent(TelecomManager.ACTION_NEW_UNKNOWN_CALL); |
Jeff Sharkey | e2e4cdf | 2016-03-18 12:19:02 -0600 | [diff] [blame] | 1161 | if (extras != null) { |
| 1162 | extras.setDefusable(true); |
| 1163 | intent.putExtras(extras); |
| 1164 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1165 | intent.putExtra(CallIntentProcessor.KEY_IS_UNKNOWN_CALL, true); |
| 1166 | intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, |
| 1167 | phoneAccountHandle); |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1168 | mCallIntentProcessorAdapter.processUnknownCallIntent(mCallsManager, intent); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1169 | } finally { |
| 1170 | Binder.restoreCallingIdentity(token); |
| 1171 | } |
| 1172 | } else { |
| 1173 | Log.i(this, |
| 1174 | "Null phoneAccountHandle or not initiated by Telephony. " + |
| 1175 | "Ignoring request to add new unknown call."); |
Sharvil Nanavati | 6d3efb4 | 2015-05-14 11:36:40 -0700 | [diff] [blame] | 1176 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1177 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1178 | } finally { |
| 1179 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1180 | } |
| 1181 | } |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1182 | |
| 1183 | /** |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 1184 | * @see android.telecom.TelecomManager#placeCall |
| 1185 | */ |
| 1186 | @Override |
| 1187 | public void placeCall(Uri handle, Bundle extras, String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1188 | try { |
| 1189 | Log.startSession("TSI.pC"); |
| 1190 | enforceCallingPackage(callingPackage); |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1191 | |
| 1192 | PhoneAccountHandle phoneAccountHandle = null; |
| 1193 | if (extras != null) { |
| 1194 | phoneAccountHandle = extras.getParcelable( |
| 1195 | TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE); |
Tyler Gunn | 141ef58 | 2017-05-26 13:38:13 -0700 | [diff] [blame] | 1196 | if (extras.containsKey(TelecomManager.EXTRA_IS_HANDOVER)) { |
| 1197 | // This extra is for Telecom use only so should never be passed in. |
| 1198 | extras.remove(TelecomManager.EXTRA_IS_HANDOVER); |
| 1199 | } |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1200 | } |
| 1201 | boolean isSelfManaged = phoneAccountHandle != null && |
| 1202 | isSelfManagedConnectionService(phoneAccountHandle); |
| 1203 | if (isSelfManaged) { |
| 1204 | mContext.enforceCallingOrSelfPermission(Manifest.permission.MANAGE_OWN_CALLS, |
| 1205 | "Self-managed ConnectionServices require MANAGE_OWN_CALLS permission."); |
Tyler Gunn | 0c7cf9a | 2017-05-17 11:15:57 -0700 | [diff] [blame] | 1206 | |
| 1207 | if (!callingPackage.equals( |
| 1208 | phoneAccountHandle.getComponentName().getPackageName()) |
| 1209 | && !canCallPhone(callingPackage, |
| 1210 | "CALL_PHONE permission required to place calls.")) { |
| 1211 | // The caller is not allowed to place calls, so we want to ensure that it |
| 1212 | // can only place calls through itself. |
| 1213 | throw new SecurityException("Self-managed ConnectionServices can only " |
| 1214 | + "place calls through their own ConnectionService."); |
| 1215 | } |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1216 | } else if (!canCallPhone(callingPackage, "placeCall")) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1217 | throw new SecurityException("Package " + callingPackage |
| 1218 | + " is not allowed to place phone calls"); |
Yorke Lee | 5806175 | 2015-05-04 11:06:26 -0700 | [diff] [blame] | 1219 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1220 | |
| 1221 | // Note: we can still get here for the default/system dialer, even if the Phone |
| 1222 | // permission is turned off. This is because the default/system dialer is always |
| 1223 | // allowed to attempt to place a call (regardless of permission state), in case |
| 1224 | // it turns out to be an emergency call. If the permission is denied and the |
| 1225 | // call is being made to a non-emergency number, the call will be denied later on |
| 1226 | // by {@link UserCallIntentProcessor}. |
| 1227 | |
| 1228 | final boolean hasCallAppOp = mAppOpsManager.noteOp(AppOpsManager.OP_CALL_PHONE, |
| 1229 | Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED; |
| 1230 | |
| 1231 | final boolean hasCallPermission = mContext.checkCallingPermission(CALL_PHONE) == |
| 1232 | PackageManager.PERMISSION_GRANTED; |
Tyler Gunn | b652dad | 2018-03-27 18:49:49 +0000 | [diff] [blame] | 1233 | // The Emergency Dialer has call privileged permission and uses this to place |
| 1234 | // emergency calls. We ensure permission checks in |
| 1235 | // NewOutgoingCallIntentBroadcaster#process pass by sending this to |
| 1236 | // Telecom as an ACTION_CALL_PRIVILEGED intent (which makes sense since the |
| 1237 | // com.android.phone process has that permission). |
| 1238 | final boolean hasCallPrivilegedPermission = mContext.checkCallingPermission( |
| 1239 | CALL_PRIVILEGED) == PackageManager.PERMISSION_GRANTED; |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1240 | |
| 1241 | synchronized (mLock) { |
| 1242 | final UserHandle userHandle = Binder.getCallingUserHandle(); |
| 1243 | long token = Binder.clearCallingIdentity(); |
| 1244 | try { |
Tyler Gunn | b652dad | 2018-03-27 18:49:49 +0000 | [diff] [blame] | 1245 | final Intent intent = new Intent(hasCallPrivilegedPermission ? |
| 1246 | Intent.ACTION_CALL_PRIVILEGED : Intent.ACTION_CALL, handle); |
Jeff Sharkey | e2e4cdf | 2016-03-18 12:19:02 -0600 | [diff] [blame] | 1247 | if (extras != null) { |
| 1248 | extras.setDefusable(true); |
| 1249 | intent.putExtras(extras); |
| 1250 | } |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1251 | mUserCallIntentProcessorFactory.create(mContext, userHandle) |
| 1252 | .processIntent( |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1253 | intent, callingPackage, isSelfManaged || |
Tyler Gunn | b652dad | 2018-03-27 18:49:49 +0000 | [diff] [blame] | 1254 | (hasCallAppOp && hasCallPermission), |
| 1255 | true /* isLocalInvocation */); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1256 | } finally { |
| 1257 | Binder.restoreCallingIdentity(token); |
| 1258 | } |
| 1259 | } |
| 1260 | } finally { |
| 1261 | Log.endSession(); |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | /** |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 1266 | * @see android.telecom.TelecomManager#enablePhoneAccount |
| 1267 | */ |
| 1268 | @Override |
Yorke Lee | 71734c2 | 2015-06-02 14:22:56 -0700 | [diff] [blame] | 1269 | public boolean enablePhoneAccount(PhoneAccountHandle accountHandle, boolean isEnabled) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1270 | try { |
| 1271 | Log.startSession("TSI.ePA"); |
| 1272 | enforceModifyPermission(); |
| 1273 | synchronized (mLock) { |
| 1274 | long token = Binder.clearCallingIdentity(); |
| 1275 | try { |
| 1276 | // enable/disable phone account |
| 1277 | return mPhoneAccountRegistrar.enablePhoneAccount(accountHandle, isEnabled); |
| 1278 | } finally { |
| 1279 | Binder.restoreCallingIdentity(token); |
| 1280 | } |
Yorke Lee | 71734c2 | 2015-06-02 14:22:56 -0700 | [diff] [blame] | 1281 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1282 | } finally { |
| 1283 | Log.endSession(); |
Yorke Lee | 71734c2 | 2015-06-02 14:22:56 -0700 | [diff] [blame] | 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | @Override |
| 1288 | public boolean setDefaultDialer(String packageName) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1289 | try { |
| 1290 | Log.startSession("TSI.sDD"); |
| 1291 | enforcePermission(MODIFY_PHONE_STATE); |
| 1292 | enforcePermission(WRITE_SECURE_SETTINGS); |
| 1293 | synchronized (mLock) { |
| 1294 | long token = Binder.clearCallingIdentity(); |
| 1295 | try { |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 1296 | final boolean result = mDefaultDialerCache.setDefaultDialer( |
| 1297 | packageName, ActivityManager.getCurrentUser()); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1298 | if (result) { |
| 1299 | final Intent intent = |
| 1300 | new Intent(TelecomManager.ACTION_DEFAULT_DIALER_CHANGED); |
| 1301 | intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, |
| 1302 | packageName); |
| 1303 | mContext.sendBroadcastAsUser(intent, |
| 1304 | new UserHandle(ActivityManager.getCurrentUser())); |
| 1305 | } |
| 1306 | return result; |
| 1307 | } finally { |
| 1308 | Binder.restoreCallingIdentity(token); |
Yorke Lee | b398430 | 2015-06-15 12:06:35 -0700 | [diff] [blame] | 1309 | } |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 1310 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1311 | } finally { |
| 1312 | Log.endSession(); |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 1313 | } |
| 1314 | } |
| 1315 | |
Hall Liu | ecd74a5 | 2016-01-12 15:26:36 -0800 | [diff] [blame] | 1316 | @Override |
Hall Liu | 874c0f8 | 2016-04-29 18:13:18 -0700 | [diff] [blame] | 1317 | public TelecomAnalytics dumpCallAnalytics() { |
Hall Liu | ecd74a5 | 2016-01-12 15:26:36 -0800 | [diff] [blame] | 1318 | try { |
| 1319 | Log.startSession("TSI.dCA"); |
| 1320 | enforcePermission(DUMP); |
Hall Liu | 874c0f8 | 2016-04-29 18:13:18 -0700 | [diff] [blame] | 1321 | return Analytics.dumpToParcelableAnalytics(); |
Hall Liu | ecd74a5 | 2016-01-12 15:26:36 -0800 | [diff] [blame] | 1322 | } finally { |
| 1323 | Log.endSession(); |
| 1324 | } |
| 1325 | } |
| 1326 | |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 1327 | /** |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1328 | * Dumps the current state of the TelecomService. Used when generating problem reports. |
| 1329 | * |
| 1330 | * @param fd The file descriptor. |
| 1331 | * @param writer The print writer to dump the state to. |
| 1332 | * @param args Optional dump arguments. |
| 1333 | */ |
| 1334 | @Override |
| 1335 | protected void dump(FileDescriptor fd, final PrintWriter writer, String[] args) { |
| 1336 | if (mContext.checkCallingOrSelfPermission( |
| 1337 | android.Manifest.permission.DUMP) |
| 1338 | != PackageManager.PERMISSION_GRANTED) { |
| 1339 | writer.println("Permission Denial: can't dump TelecomService " + |
| 1340 | "from from pid=" + Binder.getCallingPid() + ", uid=" + |
| 1341 | Binder.getCallingUid()); |
| 1342 | return; |
| 1343 | } |
| 1344 | |
Hall Liu | 5bbbcf7 | 2016-08-08 17:23:20 -0700 | [diff] [blame] | 1345 | if (args.length > 0 && Analytics.ANALYTICS_DUMPSYS_ARG.equals(args[0])) { |
| 1346 | Analytics.dumpToEncodedProto(writer, args); |
| 1347 | return; |
| 1348 | } |
Tyler Gunn | 897e851 | 2017-05-18 15:46:51 -0700 | [diff] [blame] | 1349 | boolean isTimeLineView = (args.length > 0 && TIME_LINE_ARG.equalsIgnoreCase(args[0])); |
Hall Liu | 5bbbcf7 | 2016-08-08 17:23:20 -0700 | [diff] [blame] | 1350 | |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1351 | final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1352 | if (mCallsManager != null) { |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 1353 | pw.println("CallsManager: "); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1354 | pw.increaseIndent(); |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1355 | mCallsManager.dump(pw); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1356 | pw.decreaseIndent(); |
| 1357 | |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 1358 | pw.println("PhoneAccountRegistrar: "); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1359 | pw.increaseIndent(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1360 | mPhoneAccountRegistrar.dump(pw); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1361 | pw.decreaseIndent(); |
Hall Liu | 3258720 | 2015-11-18 11:10:08 -0800 | [diff] [blame] | 1362 | |
| 1363 | pw.println("Analytics:"); |
| 1364 | pw.increaseIndent(); |
| 1365 | Analytics.dump(pw); |
| 1366 | pw.decreaseIndent(); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1367 | } |
Tyler Gunn | 897e851 | 2017-05-18 15:46:51 -0700 | [diff] [blame] | 1368 | if (isTimeLineView) { |
| 1369 | Log.dumpEventsTimeline(pw); |
| 1370 | } else { |
| 1371 | Log.dumpEvents(pw); |
| 1372 | } |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1373 | } |
Abhijith Shastry | 7a846f5 | 2016-02-01 16:49:27 -0800 | [diff] [blame] | 1374 | |
Mohamed | c926185 | 2016-02-05 14:10:17 -0800 | [diff] [blame] | 1375 | /** |
Abhijith Shastry | b1308ec | 2016-02-29 16:26:09 -0800 | [diff] [blame] | 1376 | * @see android.telecom.TelecomManager#createManageBlockedNumbersIntent |
| 1377 | */ |
Abhijith Shastry | ebe7bbe | 2016-02-29 11:16:30 -0800 | [diff] [blame] | 1378 | @Override |
| 1379 | public Intent createManageBlockedNumbersIntent() { |
Abhijith Shastry | b1308ec | 2016-02-29 16:26:09 -0800 | [diff] [blame] | 1380 | return BlockedNumbersActivity.getIntentForStartingActivity(); |
Abhijith Shastry | ebe7bbe | 2016-02-29 11:16:30 -0800 | [diff] [blame] | 1381 | } |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 1382 | |
| 1383 | /** |
| 1384 | * @see android.telecom.TelecomManager#isIncomingCallPermitted(PhoneAccountHandle) |
| 1385 | */ |
| 1386 | @Override |
| 1387 | public boolean isIncomingCallPermitted(PhoneAccountHandle phoneAccountHandle) { |
| 1388 | try { |
| 1389 | Log.startSession("TSI.iICP"); |
| 1390 | enforcePermission(android.Manifest.permission.MANAGE_OWN_CALLS); |
| 1391 | synchronized (mLock) { |
| 1392 | long token = Binder.clearCallingIdentity(); |
| 1393 | try { |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1394 | return mCallsManager.isIncomingCallPermitted(phoneAccountHandle); |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 1395 | } finally { |
| 1396 | Binder.restoreCallingIdentity(token); |
| 1397 | } |
| 1398 | } |
| 1399 | } finally { |
| 1400 | Log.endSession(); |
| 1401 | } |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | /** |
| 1405 | * @see android.telecom.TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle) |
| 1406 | */ |
| 1407 | @Override |
| 1408 | public boolean isOutgoingCallPermitted(PhoneAccountHandle phoneAccountHandle) { |
| 1409 | try { |
| 1410 | Log.startSession("TSI.iOCP"); |
| 1411 | enforcePermission(android.Manifest.permission.MANAGE_OWN_CALLS); |
| 1412 | synchronized (mLock) { |
| 1413 | long token = Binder.clearCallingIdentity(); |
| 1414 | try { |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1415 | return mCallsManager.isOutgoingCallPermitted(phoneAccountHandle); |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 1416 | } finally { |
| 1417 | Binder.restoreCallingIdentity(token); |
| 1418 | } |
| 1419 | } |
| 1420 | } finally { |
| 1421 | Log.endSession(); |
| 1422 | } |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 1423 | } |
Tyler Gunn | 9e806ee | 2017-02-06 20:49:24 -0800 | [diff] [blame] | 1424 | |
| 1425 | /** |
| 1426 | * Blocks until all Telecom handlers have completed their current work. |
| 1427 | * |
| 1428 | * See {@link com.android.commands.telecom.Telecom}. |
| 1429 | */ |
| 1430 | @Override |
| 1431 | public void waitOnHandlers() { |
| 1432 | try { |
| 1433 | Log.startSession("TSI.wOH"); |
| 1434 | enforceModifyPermission(); |
| 1435 | synchronized (mLock) { |
| 1436 | long token = Binder.clearCallingIdentity(); |
| 1437 | try { |
| 1438 | Log.i(this, "waitOnHandlers"); |
| 1439 | mCallsManager.waitOnHandlers(); |
| 1440 | } finally { |
| 1441 | Binder.restoreCallingIdentity(token); |
| 1442 | } |
| 1443 | } |
| 1444 | } finally { |
| 1445 | Log.endSession(); |
| 1446 | } |
| 1447 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1448 | }; |
| 1449 | |
Eugene Susla | ccba720 | 2017-02-10 10:56:53 -0800 | [diff] [blame] | 1450 | /** |
| 1451 | * @return whether to return early without doing the action/throwing |
| 1452 | * @throws SecurityException same as {@link Context#enforceCallingOrSelfPermission} |
| 1453 | */ |
| 1454 | private boolean enforceAnswerCallPermission(String packageName, int uid) { |
| 1455 | try { |
| 1456 | enforceModifyPermission(); |
| 1457 | } catch (SecurityException e) { |
| 1458 | final String permission = Manifest.permission.ANSWER_PHONE_CALLS; |
| 1459 | enforcePermission(permission); |
| 1460 | |
| 1461 | final int opCode = AppOpsManager.permissionToOpCode(permission); |
| 1462 | if (opCode != AppOpsManager.OP_NONE |
| 1463 | && mAppOpsManager.checkOp(opCode, uid, packageName) |
| 1464 | != AppOpsManager.MODE_ALLOWED) { |
| 1465 | return false; |
| 1466 | } |
| 1467 | } |
| 1468 | return true; |
| 1469 | } |
| 1470 | |
Tyler Gunn | 37a4dca | 2018-01-18 15:00:41 -0800 | [diff] [blame] | 1471 | /** |
| 1472 | * @return {@code true} if the app has the handover permission and has received runtime |
| 1473 | * permission to perform that operation, {@code false}. |
| 1474 | * @throws SecurityException same as {@link Context#enforceCallingOrSelfPermission} |
| 1475 | */ |
| 1476 | private boolean enforceAcceptHandoverPermission(String packageName, int uid) { |
| 1477 | mContext.enforceCallingOrSelfPermission(Manifest.permission.ACCEPT_HANDOVER, |
| 1478 | "App requires ACCEPT_HANDOVER permission to accept handovers."); |
| 1479 | |
| 1480 | final int opCode = AppOpsManager.permissionToOpCode(Manifest.permission.ACCEPT_HANDOVER); |
| 1481 | if (opCode != AppOpsManager.OP_ACCEPT_HANDOVER || ( |
| 1482 | mAppOpsManager.checkOp(opCode, uid, packageName) |
| 1483 | != AppOpsManager.MODE_ALLOWED)) { |
| 1484 | return false; |
| 1485 | } |
| 1486 | return true; |
| 1487 | } |
| 1488 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1489 | private Context mContext; |
| 1490 | private AppOpsManager mAppOpsManager; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1491 | private PackageManager mPackageManager; |
| 1492 | private CallsManager mCallsManager; |
| 1493 | private final PhoneAccountRegistrar mPhoneAccountRegistrar; |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1494 | private final CallIntentProcessor.Adapter mCallIntentProcessorAdapter; |
| 1495 | private final UserCallIntentProcessorFactory mUserCallIntentProcessorFactory; |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 1496 | private final DefaultDialerCache mDefaultDialerCache; |
Hall Liu | 0a6dd30 | 2015-12-16 15:06:49 -0800 | [diff] [blame] | 1497 | private final SubscriptionManagerAdapter mSubscriptionManagerAdapter; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1498 | private final TelecomSystem.SyncRoot mLock; |
| 1499 | |
| 1500 | public TelecomServiceImpl( |
| 1501 | Context context, |
| 1502 | CallsManager callsManager, |
| 1503 | PhoneAccountRegistrar phoneAccountRegistrar, |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1504 | CallIntentProcessor.Adapter callIntentProcessorAdapter, |
| 1505 | UserCallIntentProcessorFactory userCallIntentProcessorFactory, |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 1506 | DefaultDialerCache defaultDialerCache, |
Hall Liu | 0a6dd30 | 2015-12-16 15:06:49 -0800 | [diff] [blame] | 1507 | SubscriptionManagerAdapter subscriptionManagerAdapter, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1508 | TelecomSystem.SyncRoot lock) { |
| 1509 | mContext = context; |
| 1510 | mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); |
| 1511 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1512 | mPackageManager = mContext.getPackageManager(); |
| 1513 | |
| 1514 | mCallsManager = callsManager; |
| 1515 | mLock = lock; |
| 1516 | mPhoneAccountRegistrar = phoneAccountRegistrar; |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1517 | mUserCallIntentProcessorFactory = userCallIntentProcessorFactory; |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 1518 | mDefaultDialerCache = defaultDialerCache; |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1519 | mCallIntentProcessorAdapter = callIntentProcessorAdapter; |
Hall Liu | 0a6dd30 | 2015-12-16 15:06:49 -0800 | [diff] [blame] | 1520 | mSubscriptionManagerAdapter = subscriptionManagerAdapter; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 1523 | public ITelecomService.Stub getBinder() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1524 | return mBinderImpl; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | // |
| 1528 | // Supporting methods for the ITelecomService interface implementation. |
| 1529 | // |
| 1530 | |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1531 | private boolean isPhoneAccountHandleVisibleToCallingUser( |
| 1532 | PhoneAccountHandle phoneAccountUserHandle, UserHandle callingUser) { |
| 1533 | return mPhoneAccountRegistrar.getPhoneAccount(phoneAccountUserHandle, callingUser) != null; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | private boolean isCallerSystemApp() { |
| 1537 | int uid = Binder.getCallingUid(); |
| 1538 | String[] packages = mPackageManager.getPackagesForUid(uid); |
| 1539 | for (String packageName : packages) { |
| 1540 | if (isPackageSystemApp(packageName)) { |
| 1541 | return true; |
| 1542 | } |
| 1543 | } |
| 1544 | return false; |
| 1545 | } |
| 1546 | |
| 1547 | private boolean isPackageSystemApp(String packageName) { |
| 1548 | try { |
| 1549 | ApplicationInfo applicationInfo = mPackageManager.getApplicationInfo(packageName, |
| 1550 | PackageManager.GET_META_DATA); |
| 1551 | if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 1552 | return true; |
| 1553 | } |
| 1554 | } catch (PackageManager.NameNotFoundException e) { |
| 1555 | } |
| 1556 | return false; |
| 1557 | } |
| 1558 | |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 1559 | private void acceptRingingCallInternal(int videoState) { |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1560 | Call call = mCallsManager.getFirstCallWithState(CallState.RINGING); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1561 | if (call != null) { |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 1562 | if (videoState == DEFAULT_VIDEO_STATE || !isValidAcceptVideoState(videoState)) { |
| 1563 | videoState = call.getVideoState(); |
| 1564 | } |
| 1565 | call.answer(videoState); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1566 | } |
| 1567 | } |
| 1568 | |
Tyler Gunn | 587fc27 | 2018-02-07 16:07:29 -0800 | [diff] [blame] | 1569 | private boolean endCallInternal(String callingPackage) { |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1570 | // Always operate on the foreground call if one exists, otherwise get the first call in |
| 1571 | // priority order by call-state. |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1572 | Call call = mCallsManager.getForegroundCall(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1573 | if (call == null) { |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1574 | call = mCallsManager.getFirstCallWithState( |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1575 | CallState.ACTIVE, |
| 1576 | CallState.DIALING, |
Tyler Gunn | 1e37be5 | 2016-07-11 08:54:23 -0700 | [diff] [blame] | 1577 | CallState.PULLING, |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1578 | CallState.RINGING, |
| 1579 | CallState.ON_HOLD); |
| 1580 | } |
| 1581 | |
| 1582 | if (call != null) { |
Tyler Gunn | 275e882 | 2019-05-13 13:58:15 -0700 | [diff] [blame] | 1583 | if (call.isEmergencyCall()) { |
| 1584 | android.util.EventLog.writeEvent(0x534e4554, "132438333", -1, ""); |
| 1585 | return false; |
| 1586 | } |
| 1587 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1588 | if (call.getState() == CallState.RINGING) { |
Tyler Gunn | 587fc27 | 2018-02-07 16:07:29 -0800 | [diff] [blame] | 1589 | call.reject(false /* rejectWithMessage */, null, callingPackage); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1590 | } else { |
Tyler Gunn | 587fc27 | 2018-02-07 16:07:29 -0800 | [diff] [blame] | 1591 | call.disconnect(0 /* disconnectionTimeout */, callingPackage); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1592 | } |
| 1593 | return true; |
| 1594 | } |
| 1595 | |
| 1596 | return false; |
| 1597 | } |
| 1598 | |
Brad Ebinger | 62da8e1 | 2016-01-28 19:16:08 -0800 | [diff] [blame] | 1599 | // Enforce that the PhoneAccountHandle being passed in is both registered to the current user |
| 1600 | // and enabled. |
Tony Mak | 5851fa0 | 2016-02-23 19:41:52 +0000 | [diff] [blame] | 1601 | private void enforcePhoneAccountIsRegisteredEnabled(PhoneAccountHandle phoneAccountHandle, |
| 1602 | UserHandle callingUserHandle) { |
| 1603 | PhoneAccount phoneAccount = mPhoneAccountRegistrar.getPhoneAccount(phoneAccountHandle, |
| 1604 | callingUserHandle); |
Brad Ebinger | 62da8e1 | 2016-01-28 19:16:08 -0800 | [diff] [blame] | 1605 | if(phoneAccount == null) { |
| 1606 | EventLog.writeEvent(0x534e4554, "26864502", Binder.getCallingUid(), "R"); |
| 1607 | throw new SecurityException("This PhoneAccountHandle is not registered for this user!"); |
| 1608 | } |
| 1609 | if(!phoneAccount.isEnabled()) { |
| 1610 | EventLog.writeEvent(0x534e4554, "26864502", Binder.getCallingUid(), "E"); |
| 1611 | throw new SecurityException("This PhoneAccountHandle is not enabled for this user!"); |
| 1612 | } |
| 1613 | } |
| 1614 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1615 | private void enforcePhoneAccountModificationForPackage(String packageName) { |
| 1616 | // TODO: Use a new telecomm permission for this instead of reusing modify. |
| 1617 | |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1618 | int result = mContext.checkCallingOrSelfPermission(MODIFY_PHONE_STATE); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1619 | |
| 1620 | // Callers with MODIFY_PHONE_STATE can use the PhoneAccount mechanism to implement |
| 1621 | // built-in behavior even when PhoneAccounts are not exposed as a third-part API. They |
| 1622 | // may also modify PhoneAccounts on behalf of any 'packageName'. |
| 1623 | |
| 1624 | if (result != PackageManager.PERMISSION_GRANTED) { |
| 1625 | // Other callers are only allowed to modify PhoneAccounts if the relevant system |
| 1626 | // feature is enabled ... |
| 1627 | enforceConnectionServiceFeature(); |
| 1628 | // ... and the PhoneAccounts they refer to are for their own package. |
| 1629 | enforceCallingPackage(packageName); |
| 1630 | } |
| 1631 | } |
| 1632 | |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1633 | private void enforcePermissionOrPrivilegedDialer(String permission, String packageName) { |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 1634 | if (!isPrivilegedDialerCalling(packageName)) { |
| 1635 | try { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1636 | enforcePermission(permission); |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 1637 | } catch (SecurityException e) { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1638 | Log.e(this, e, "Caller must be the default or system dialer, or have the permission" |
| 1639 | + " %s to perform this operation.", permission); |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 1640 | throw e; |
| 1641 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1642 | } |
| 1643 | } |
| 1644 | |
| 1645 | private void enforceCallingPackage(String packageName) { |
| 1646 | mAppOpsManager.checkPackage(Binder.getCallingUid(), packageName); |
| 1647 | } |
| 1648 | |
| 1649 | private void enforceConnectionServiceFeature() { |
| 1650 | enforceFeature(PackageManager.FEATURE_CONNECTION_SERVICE); |
| 1651 | } |
| 1652 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1653 | private void enforceRegisterSimSubscriptionPermission() { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1654 | enforcePermission(REGISTER_SIM_SUBSCRIPTION); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1655 | } |
| 1656 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1657 | private void enforceModifyPermission() { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1658 | enforcePermission(MODIFY_PHONE_STATE); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1659 | } |
| 1660 | |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 1661 | private void enforceModifyPermission(String message) { |
| 1662 | mContext.enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, message); |
| 1663 | } |
| 1664 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1665 | private void enforcePermission(String permission) { |
| 1666 | mContext.enforceCallingOrSelfPermission(permission, null); |
| 1667 | } |
| 1668 | |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 1669 | private void enforceRegisterSelfManaged() { |
| 1670 | mContext.enforceCallingPermission(android.Manifest.permission.MANAGE_OWN_CALLS, null); |
| 1671 | } |
| 1672 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1673 | private void enforceRegisterMultiUser() { |
| 1674 | if (!isCallerSystemApp()) { |
| 1675 | throw new SecurityException("CAPABILITY_MULTI_USER is only available to system apps."); |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | private void enforceUserHandleMatchesCaller(PhoneAccountHandle accountHandle) { |
| 1680 | if (!Binder.getCallingUserHandle().equals(accountHandle.getUserHandle())) { |
| 1681 | throw new SecurityException("Calling UserHandle does not match PhoneAccountHandle's"); |
| 1682 | } |
| 1683 | } |
| 1684 | |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1685 | private void enforceCrossUserPermission(int callingUid) { |
| 1686 | if (callingUid != Process.SYSTEM_UID && callingUid != 0) { |
| 1687 | mContext.enforceCallingOrSelfPermission( |
| 1688 | android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, "Must be system or have" |
| 1689 | + " INTERACT_ACROSS_USERS_FULL permission"); |
| 1690 | } |
| 1691 | } |
| 1692 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1693 | private void enforceFeature(String feature) { |
| 1694 | PackageManager pm = mContext.getPackageManager(); |
| 1695 | if (!pm.hasSystemFeature(feature)) { |
| 1696 | throw new UnsupportedOperationException( |
| 1697 | "System does not support feature " + feature); |
| 1698 | } |
| 1699 | } |
| 1700 | |
Svet Ganov | 38f1a4d | 2015-04-17 15:28:03 -0700 | [diff] [blame] | 1701 | private boolean canReadPhoneState(String callingPackage, String message) { |
Yorke Lee | 57138a6 | 2015-05-18 18:18:08 -0700 | [diff] [blame] | 1702 | // The system/default dialer can always read phone state - so that emergency calls will |
| 1703 | // still work. |
| 1704 | if (isPrivilegedDialerCalling(callingPackage)) { |
| 1705 | return true; |
| 1706 | } |
| 1707 | |
Amit Mahajan | 3c29693 | 2015-07-14 10:23:15 -0700 | [diff] [blame] | 1708 | try { |
Amit Mahajan | 86b8e33 | 2015-07-30 16:02:52 -0700 | [diff] [blame] | 1709 | mContext.enforceCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE, message); |
| 1710 | // SKIP checking run-time OP_READ_PHONE_STATE since caller or self has PRIVILEGED |
| 1711 | // permission |
Amit Mahajan | 3c29693 | 2015-07-14 10:23:15 -0700 | [diff] [blame] | 1712 | return true; |
| 1713 | } catch (SecurityException e) { |
| 1714 | // Accessing phone state is gated by a special permission. |
| 1715 | mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, message); |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 1716 | |
Amit Mahajan | 3c29693 | 2015-07-14 10:23:15 -0700 | [diff] [blame] | 1717 | // Some apps that have the permission can be restricted via app ops. |
| 1718 | return mAppOpsManager.noteOp(AppOpsManager.OP_READ_PHONE_STATE, |
| 1719 | Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED; |
| 1720 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1723 | private boolean isSelfManagedConnectionService(PhoneAccountHandle phoneAccountHandle) { |
| 1724 | if (phoneAccountHandle != null) { |
| 1725 | PhoneAccount phoneAccount = mPhoneAccountRegistrar.getPhoneAccountUnchecked( |
| 1726 | phoneAccountHandle); |
Tyler Gunn | 9e806ee | 2017-02-06 20:49:24 -0800 | [diff] [blame] | 1727 | return phoneAccount != null && phoneAccount.isSelfManaged(); |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1728 | } |
| 1729 | return false; |
| 1730 | } |
| 1731 | |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 1732 | private boolean canCallPhone(String callingPackage, String message) { |
Yorke Lee | 57138a6 | 2015-05-18 18:18:08 -0700 | [diff] [blame] | 1733 | // The system/default dialer can always read phone state - so that emergency calls will |
| 1734 | // still work. |
| 1735 | if (isPrivilegedDialerCalling(callingPackage)) { |
| 1736 | return true; |
| 1737 | } |
| 1738 | |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 1739 | // Accessing phone state is gated by a special permission. |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1740 | mContext.enforceCallingOrSelfPermission(CALL_PHONE, message); |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 1741 | |
| 1742 | // Some apps that have the permission can be restricted via app ops. |
| 1743 | return mAppOpsManager.noteOp(AppOpsManager.OP_CALL_PHONE, |
| 1744 | Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED; |
| 1745 | } |
| 1746 | |
Sailesh Nepal | 2a98c97 | 2015-03-04 15:43:15 -0800 | [diff] [blame] | 1747 | private boolean isCallerSimCallManager() { |
Yorke Lee | 9427c0f | 2015-06-27 11:01:58 -0700 | [diff] [blame] | 1748 | long token = Binder.clearCallingIdentity(); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1749 | PhoneAccountHandle accountHandle = null; |
Yorke Lee | 9427c0f | 2015-06-27 11:01:58 -0700 | [diff] [blame] | 1750 | try { |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1751 | accountHandle = mPhoneAccountRegistrar.getSimCallManagerOfCurrentUser(); |
Yorke Lee | 9427c0f | 2015-06-27 11:01:58 -0700 | [diff] [blame] | 1752 | } finally { |
| 1753 | Binder.restoreCallingIdentity(token); |
| 1754 | } |
| 1755 | |
Sailesh Nepal | 2a98c97 | 2015-03-04 15:43:15 -0800 | [diff] [blame] | 1756 | if (accountHandle != null) { |
| 1757 | try { |
| 1758 | mAppOpsManager.checkPackage( |
| 1759 | Binder.getCallingUid(), accountHandle.getComponentName().getPackageName()); |
| 1760 | return true; |
| 1761 | } catch (SecurityException e) { |
| 1762 | } |
| 1763 | } |
| 1764 | return false; |
| 1765 | } |
| 1766 | |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 1767 | private boolean isPrivilegedDialerCalling(String callingPackage) { |
| 1768 | mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 1769 | return mDefaultDialerCache.isDefaultOrSystemDialer( |
| 1770 | callingPackage, Binder.getCallingUserHandle().getIdentifier()); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | private TelephonyManager getTelephonyManager() { |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1774 | return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1775 | } |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 1776 | |
| 1777 | /** |
| 1778 | * Determines if a video state is valid for accepting an incoming call. |
| 1779 | * For the purpose of accepting a call, states {@link VideoProfile#STATE_AUDIO_ONLY}, and |
| 1780 | * any combination of {@link VideoProfile#STATE_RX_ENABLED} and |
| 1781 | * {@link VideoProfile#STATE_TX_ENABLED} are considered valid. |
| 1782 | * |
| 1783 | * @param videoState The video state. |
| 1784 | * @return {@code true} if the video state is valid, {@code false} otherwise. |
| 1785 | */ |
| 1786 | private boolean isValidAcceptVideoState(int videoState) { |
| 1787 | // Given a video state input, turn off TX and RX so that we can determine if those were the |
| 1788 | // only bits set. |
| 1789 | int remainingState = videoState & ~VideoProfile.STATE_TX_ENABLED; |
| 1790 | remainingState = remainingState & ~VideoProfile.STATE_RX_ENABLED; |
| 1791 | |
| 1792 | // If only TX or RX were set (or neither), the video state is valid. |
| 1793 | return remainingState == 0; |
| 1794 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1795 | } |