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