blob: 0db17643beaa53a67822d7f18f777048ee2262e8 [file] [log] [blame]
Santos Cordonf987d1a2014-12-02 03:37:03 -08001/*
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
17package com.android.server.telecom;
18
Yorke Leecb0bd8a2015-05-18 11:57:14 -070019import static android.Manifest.permission.CALL_PHONE;
Tyler Gunnb652dad2018-03-27 18:49:49 +000020import static android.Manifest.permission.CALL_PRIVILEGED;
Hall Liuecd74a52016-01-12 15:26:36 -080021import static android.Manifest.permission.DUMP;
Yorke Leecb0bd8a2015-05-18 11:57:14 -070022import static android.Manifest.permission.MODIFY_PHONE_STATE;
23import static android.Manifest.permission.READ_PHONE_STATE;
Amit Mahajan3c296932015-07-14 10:23:15 -070024import static android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE;
Yorke Leecb0bd8a2015-05-18 11:57:14 -070025import static android.Manifest.permission.REGISTER_SIM_SUBSCRIPTION;
Yorke Lee71734c22015-06-02 14:22:56 -070026import static android.Manifest.permission.WRITE_SECURE_SETTINGS;
Yorke Leecb0bd8a2015-05-18 11:57:14 -070027
Tyler Gunna90ba732017-01-26 07:24:08 -080028import android.Manifest;
Yorke Leeb3984302015-06-15 12:06:35 -070029import android.app.ActivityManager;
Santos Cordonf987d1a2014-12-02 03:37:03 -080030import android.app.AppOpsManager;
Santos Cordonf987d1a2014-12-02 03:37:03 -080031import android.content.ComponentName;
32import android.content.Context;
33import android.content.Intent;
34import android.content.pm.ApplicationInfo;
35import android.content.pm.PackageManager;
36import android.content.res.Resources;
37import android.net.Uri;
38import android.os.Binder;
39import android.os.Bundle;
Tony Mak240656f2015-12-04 11:36:22 +000040import android.os.Process;
Santos Cordonf987d1a2014-12-02 03:37:03 -080041import android.os.UserHandle;
Brad Ebingera3eccfe2016-10-05 15:45:22 -070042import android.telecom.Log;
Santos Cordonf987d1a2014-12-02 03:37:03 -080043import android.telecom.PhoneAccount;
44import android.telecom.PhoneAccountHandle;
Hall Liu874c0f82016-04-29 18:13:18 -070045import android.telecom.TelecomAnalytics;
Santos Cordonf987d1a2014-12-02 03:37:03 -080046import android.telecom.TelecomManager;
Tyler Gunn42ef8082015-11-24 15:34:34 -080047import android.telecom.VideoProfile;
Santos Cordonf987d1a2014-12-02 03:37:03 -080048import android.telephony.SubscriptionManager;
49import android.telephony.TelephonyManager;
Tyler Gunn0edfc662017-04-14 13:46:21 -070050import android.text.TextUtils;
Brad Ebinger62da8e12016-01-28 19:16:08 -080051import android.util.EventLog;
Santos Cordonf987d1a2014-12-02 03:37:03 -080052
Santos Cordonf987d1a2014-12-02 03:37:03 -080053import com.android.internal.telecom.ITelecomService;
54import com.android.internal.util.IndentingPrintWriter;
Hall Liuecda5542015-12-04 11:31:31 -080055import com.android.server.telecom.components.UserCallIntentProcessorFactory;
Mohamedc9261852016-02-05 14:10:17 -080056import com.android.server.telecom.settings.BlockedNumbersActivity;
Santos Cordonf987d1a2014-12-02 03:37:03 -080057
58import java.io.FileDescriptor;
59import java.io.PrintWriter;
Svet Ganov09611182015-04-16 12:29:01 -070060import java.util.Collections;
Santos Cordonf987d1a2014-12-02 03:37:03 -080061import java.util.List;
62
Eugene Suslaccba7202017-02-10 10:56:53 -080063// TODO: Needed for move to system service: import com.android.internal.R;
64
Santos Cordonf987d1a2014-12-02 03:37:03 -080065/**
66 * Implementation of the ITelecom interface.
67 */
Ihab Awad78a5e6b2015-02-06 10:13:05 -080068public class TelecomServiceImpl {
Hall Liu0a6dd302015-12-16 15:06:49 -080069
70 public interface SubscriptionManagerAdapter {
71 int getDefaultVoiceSubId();
72 }
73
74 static class SubscriptionManagerAdapterImpl implements SubscriptionManagerAdapter {
75 @Override
76 public int getDefaultVoiceSubId() {
Shishir Agrawalce688742016-01-25 15:02:21 -080077 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Hall Liu0a6dd302015-12-16 15:06:49 -080078 }
79 }
80
Tyler Gunn897e8512017-05-18 15:46:51 -070081 private static final String TIME_LINE_ARG = "timeline";
Tyler Gunn42ef8082015-11-24 15:34:34 -080082 private static final int DEFAULT_VIDEO_STATE = -1;
Santos Cordon73853962015-02-27 15:13:35 -080083
Ihab Awad8d5d9dd2015-03-12 11:11:06 -070084 private final ITelecomService.Stub mBinderImpl = new ITelecomService.Stub() {
Santos Cordonf987d1a2014-12-02 03:37:03 -080085 @Override
Svet Ganov09611182015-04-16 12:29:01 -070086 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme,
87 String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -080088 try {
89 Log.startSession("TSI.gDOPA");
90 synchronized (mLock) {
91 if (!canReadPhoneState(callingPackage, "getDefaultOutgoingPhoneAccount")) {
92 return null;
93 }
Svet Ganov09611182015-04-16 12:29:01 -070094
Brad Ebinger11623a32015-11-25 13:52:02 -080095 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 Cordonf987d1a2014-12-02 03:37:03 -0800106 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800107 } finally {
108 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -0800109 }
110 }
111
112 @Override
113 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700114 synchronized (mLock) {
115 try {
Brad Ebinger11623a32015-11-25 13:52:02 -0800116 Log.startSession("TSI.gUSOPA");
Tony Mak240656f2015-12-04 11:36:22 +0000117 final UserHandle callingUserHandle = Binder.getCallingUserHandle();
118 return mPhoneAccountRegistrar.getUserSelectedOutgoingPhoneAccount(
119 callingUserHandle);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700120 } catch (Exception e) {
121 Log.e(this, e, "getUserSelectedOutgoingPhoneAccount");
122 throw e;
Brad Ebinger11623a32015-11-25 13:52:02 -0800123 } finally {
124 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -0800125 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800126 }
127 }
128
129 @Override
130 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800131 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 Awad8d5d9dd2015-03-12 11:11:06 -0700146 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800147 } finally {
148 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -0800149 }
150 }
151
152 @Override
Santos Cordonea5cb932015-05-07 16:28:38 -0700153 public List<PhoneAccountHandle> getCallCapablePhoneAccounts(
154 boolean includeDisabledAccounts, String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800155 try {
156 Log.startSession("TSI.gCCPA");
157 if (!canReadPhoneState(callingPackage, "getDefaultOutgoingPhoneAccount")) {
158 return Collections.emptyList();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700159 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800160 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 Cordonf987d1a2014-12-02 03:37:03 -0800175 }
176 }
177
178 @Override
Tyler Gunnebfc9162017-04-07 15:00:49 -0700179 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 Ganov09611182015-04-16 12:29:01 -0700204 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme,
205 String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800206 try {
207 Log.startSession("TSI.gPASS");
Tyler Gunn322480c2017-07-17 15:34:02 -0700208 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 Ebinger11623a32015-11-25 13:52:02 -0800217 synchronized (mLock) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800218 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 Ganov09611182015-04-16 12:29:01 -0700229 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800230 } finally {
231 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -0800232 }
233 }
234
235 @Override
236 public List<PhoneAccountHandle> getPhoneAccountsForPackage(String packageName) {
Grace Jia0bf3b002020-06-18 14:12:56 -0700237 //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 Awad8d5d9dd2015-03-12 11:11:06 -0700254 synchronized (mLock) {
Tony Mak240656f2015-12-04 11:36:22 +0000255 final UserHandle callingUserHandle = Binder.getCallingUserHandle();
256 long token = Binder.clearCallingIdentity();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700257 try {
Brad Ebinger11623a32015-11-25 13:52:02 -0800258 Log.startSession("TSI.gPAFP");
Tony Mak240656f2015-12-04 11:36:22 +0000259 return mPhoneAccountRegistrar.getPhoneAccountsForPackage(packageName,
260 callingUserHandle);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700261 } catch (Exception e) {
262 Log.e(this, e, "getPhoneAccountsForPackage %s", packageName);
263 throw e;
Tony Mak240656f2015-12-04 11:36:22 +0000264 } finally {
265 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800266 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700267 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800268 }
269 }
270
271 @Override
272 public PhoneAccount getPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700273 synchronized (mLock) {
Tony Mak240656f2015-12-04 11:36:22 +0000274 final UserHandle callingUserHandle = Binder.getCallingUserHandle();
275 long token = Binder.clearCallingIdentity();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700276 try {
Brad Ebinger11623a32015-11-25 13:52:02 -0800277 Log.startSession("TSI.gPA");
Tony Mak240656f2015-12-04 11:36:22 +0000278 // 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 Awad8d5d9dd2015-03-12 11:11:06 -0700285 } catch (Exception e) {
286 Log.e(this, e, "getPhoneAccount %s", accountHandle);
287 throw e;
Tony Mak240656f2015-12-04 11:36:22 +0000288 } finally {
289 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800290 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -0800291 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800292 }
293 }
294
295 @Override
296 public int getAllPhoneAccountsCount() {
Tyler Gunn322480c2017-07-17 15:34:02 -0700297 try {
298 Log.startSession("TSI.gAPAC");
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700299 try {
Tyler Gunn322480c2017-07-17 15:34:02 -0700300 enforceModifyPermission(
301 "getAllPhoneAccountsCount requires MODIFY_PHONE_STATE permission.");
302 } catch (SecurityException e) {
303 EventLog.writeEvent(0x534e4554, "62347125", Binder.getCallingUid(),
304 "getAllPhoneAccountsCount");
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700305 throw e;
306 }
Tyler Gunn322480c2017-07-17 15:34:02 -0700307
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 Cordonf987d1a2014-12-02 03:37:03 -0800320 }
321 }
322
323 @Override
324 public List<PhoneAccount> getAllPhoneAccounts() {
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700325 synchronized (mLock) {
326 try {
Brad Ebinger11623a32015-11-25 13:52:02 -0800327 Log.startSession("TSI.gAPA");
Tyler Gunn322480c2017-07-17 15:34:02 -0700328 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 Mak240656f2015-12-04 11:36:22 +0000347 } finally {
Brad Ebinger11623a32015-11-25 13:52:02 -0800348 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -0800349 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800350 }
351 }
352
353 @Override
354 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
Tyler Gunn322480c2017-07-17 15:34:02 -0700355 try {
356 Log.startSession("TSI.gAPAH");
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700357 try {
Tyler Gunn322480c2017-07-17 15:34:02 -0700358 enforceModifyPermission(
359 "getAllPhoneAccountHandles requires MODIFY_PHONE_STATE permission.");
360 } catch (SecurityException e) {
361 EventLog.writeEvent(0x534e4554, "62347125", Binder.getCallingUid(),
362 "getAllPhoneAccountHandles");
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700363 throw e;
364 }
Tyler Gunn322480c2017-07-17 15:34:02 -0700365
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 Cordonf987d1a2014-12-02 03:37:03 -0800380 }
381 }
382
383 @Override
384 public PhoneAccountHandle getSimCallManager() {
Sailesh Nepalfc43ea82015-07-28 19:30:28 -0700385 try {
Brad Ebinger11623a32015-11-25 13:52:02 -0800386 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 Nepalfc43ea82015-07-28 19:30:28 -0700395 } finally {
Brad Ebinger11623a32015-11-25 13:52:02 -0800396 Log.endSession();
Sailesh Nepalfc43ea82015-07-28 19:30:28 -0700397 }
Sailesh Nepalfc43ea82015-07-28 19:30:28 -0700398 }
399
400 @Override
401 public PhoneAccountHandle getSimCallManagerForUser(int user) {
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700402 synchronized (mLock) {
403 try {
Brad Ebinger11623a32015-11-25 13:52:02 -0800404 Log.startSession("TSI.gSCMFU");
Tony Mak240656f2015-12-04 11:36:22 +0000405 final int callingUid = Binder.getCallingUid();
Santos Cordon59c21a72015-06-11 10:11:21 -0700406 long token = Binder.clearCallingIdentity();
407 try {
Tony Mak240656f2015-12-04 11:36:22 +0000408 if (user != ActivityManager.getCurrentUser()) {
409 enforceCrossUserPermission(callingUid);
410 }
411 return mPhoneAccountRegistrar.getSimCallManager(UserHandle.of(user));
Santos Cordon59c21a72015-06-11 10:11:21 -0700412 } finally {
Santos Cordon59c21a72015-06-11 10:11:21 -0700413 Binder.restoreCallingIdentity(token);
414 }
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700415 } catch (Exception e) {
416 Log.e(this, e, "getSimCallManager");
417 throw e;
Brad Ebinger11623a32015-11-25 13:52:02 -0800418 } finally {
419 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -0800420 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800421 }
422 }
423
424 @Override
Santos Cordonf987d1a2014-12-02 03:37:03 -0800425 public void registerPhoneAccount(PhoneAccount account) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800426 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 Awad8d5d9dd2015-03-12 11:11:06 -0700434 }
Yorke Lee58061752015-05-04 11:06:26 -0700435 try {
Brad Ebinger11623a32015-11-25 13:52:02 -0800436 enforcePhoneAccountModificationForPackage(
437 account.getAccountHandle().getComponentName().getPackageName());
Tyler Gunnacb3bc82017-01-09 09:43:56 -0800438 if (account.hasCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)) {
439 enforceRegisterSelfManaged();
Tyler Gunn9e806ee2017-02-06 20:49:24 -0800440 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 Gunn2b17f232017-03-08 08:51:00 -0800449
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 Gunnacb3bc82017-01-09 09:43:56 -0800453 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800454 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 Gunncbc9be22017-04-19 10:52:36 -0700461 final long token = Binder.clearCallingIdentity();
462 try {
463 mPhoneAccountRegistrar.registerPhoneAccount(account);
464 } finally {
465 Binder.restoreCallingIdentity(token);
466 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800467 } catch (Exception e) {
468 Log.e(this, e, "registerPhoneAccount %s", account);
469 throw e;
Yorke Lee58061752015-05-04 11:06:26 -0700470 }
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700471 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800472 } finally {
473 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -0800474 }
475 }
476
477 @Override
478 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700479 synchronized (mLock) {
480 try {
Brad Ebinger11623a32015-11-25 13:52:02 -0800481 Log.startSession("TSI.uPA");
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700482 enforcePhoneAccountModificationForPackage(
483 accountHandle.getComponentName().getPackageName());
484 enforceUserHandleMatchesCaller(accountHandle);
Tyler Gunncbc9be22017-04-19 10:52:36 -0700485 final long token = Binder.clearCallingIdentity();
486 try {
487 mPhoneAccountRegistrar.unregisterPhoneAccount(accountHandle);
488 } finally {
489 Binder.restoreCallingIdentity(token);
490 }
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700491 } catch (Exception e) {
492 Log.e(this, e, "unregisterPhoneAccount %s", accountHandle);
493 throw e;
Brad Ebinger11623a32015-11-25 13:52:02 -0800494 } finally {
495 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700496 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800497 }
498 }
499
500 @Override
501 public void clearAccounts(String packageName) {
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700502 synchronized (mLock) {
503 try {
Brad Ebinger11623a32015-11-25 13:52:02 -0800504 Log.startSession("TSI.cA");
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700505 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 Ebinger11623a32015-11-25 13:52:02 -0800511 } finally {
512 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700513 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800514 }
515 }
516
517 /**
518 * @see android.telecom.TelecomManager#isVoiceMailNumber
519 */
520 @Override
Svet Ganov09611182015-04-16 12:29:01 -0700521 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number,
522 String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800523 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 Ganov09611182015-04-16 12:29:01 -0700544 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800545 } finally {
546 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -0800547 }
548 }
549
550 /**
Yorke Leefb5ec302015-04-15 16:15:55 -0700551 * @see android.telecom.TelecomManager#getVoiceMailNumber
Santos Cordonf987d1a2014-12-02 03:37:03 -0800552 */
553 @Override
Svet Ganov09611182015-04-16 12:29:01 -0700554 public String getVoiceMailNumber(PhoneAccountHandle accountHandle, String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800555 try {
556 Log.startSession("TSI.gVMN");
557 synchronized (mLock) {
558 if (!canReadPhoneState(callingPackage, "getVoiceMailNumber")) {
Yorke Leefb5ec302015-04-15 16:15:55 -0700559 return null;
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700560 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800561 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 Liu0a6dd302015-12-16 15:06:49 -0800569 int subId = mSubscriptionManagerAdapter.getDefaultVoiceSubId();
Brad Ebinger11623a32015-11-25 13:52:02 -0800570 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 Awad8d5d9dd2015-03-12 11:11:06 -0700578 }
Ihab Awad78a5e6b2015-02-06 10:13:05 -0800579 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800580 } finally {
581 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -0800582 }
583 }
584
585 /**
Nancy Chenba304752015-01-24 23:29:22 -0800586 * @see android.telecom.TelecomManager#getLine1Number
587 */
588 @Override
Svet Ganov09611182015-04-16 12:29:01 -0700589 public String getLine1Number(PhoneAccountHandle accountHandle, String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800590 try {
591 Log.startSession("getL1N");
592 if (!canReadPhoneState(callingPackage, "getLine1Number")) {
Santos Cordonebf2d0f2015-05-15 10:28:29 -0700593 return null;
594 }
595
Brad Ebinger11623a32015-11-25 13:52:02 -0800596 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 Agrawalce688742016-01-25 15:02:21 -0800608 return getTelephonyManager().getLine1Number(subId);
Brad Ebinger11623a32015-11-25 13:52:02 -0800609 } catch (Exception e) {
610 Log.e(this, e, "getSubscriptionIdForPhoneAccount");
611 throw e;
612 } finally {
613 Binder.restoreCallingIdentity(token);
614 }
Nancy Chenba304752015-01-24 23:29:22 -0800615 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800616 } finally {
617 Log.endSession();
Nancy Chenba304752015-01-24 23:29:22 -0800618 }
619 }
620
621 /**
Santos Cordonf987d1a2014-12-02 03:37:03 -0800622 * @see android.telecom.TelecomManager#silenceRinger
623 */
624 @Override
Yorke Lee53101962015-04-29 16:25:29 -0700625 public void silenceRinger(String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800626 try {
627 Log.startSession("TSI.sR");
628 synchronized (mLock) {
629 enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage);
Santos Cordonebf2d0f2015-05-15 10:28:29 -0700630
Brad Ebinger11623a32015-11-25 13:52:02 -0800631 long token = Binder.clearCallingIdentity();
632 try {
633 Log.i(this, "Silence Ringer requested by %s", callingPackage);
Hall Liue091ab92015-12-18 17:05:30 -0800634 mCallsManager.getCallAudioManager().silenceRingers();
Sailesh Nepalc07b8e12016-01-23 16:43:10 -0800635 mCallsManager.getInCallController().silenceRinger();
Brad Ebinger11623a32015-11-25 13:52:02 -0800636 } finally {
637 Binder.restoreCallingIdentity(token);
638 }
Santos Cordonebf2d0f2015-05-15 10:28:29 -0700639 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800640 } finally {
641 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700642 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800643 }
644
645 /**
646 * @see android.telecom.TelecomManager#getDefaultPhoneApp
Yorke Lee5b3fc0a2015-04-23 17:42:57 -0700647 * @deprecated - Use {@link android.telecom.TelecomManager#getDefaultDialerPackage()}
648 * instead.
Santos Cordonf987d1a2014-12-02 03:37:03 -0800649 */
650 @Override
651 public ComponentName getDefaultPhoneApp() {
Brad Ebinger11623a32015-11-25 13:52:02 -0800652 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 Cordonf987d1a2014-12-02 03:37:03 -0800662 }
663
664 /**
Yorke Lee5291d4a2015-04-24 16:42:36 -0700665 * @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 Lee5b3fc0a2015-04-23 17:42:57 -0700668 * @see android.telecom.TelecomManager#getDefaultDialerPackage
669 */
670 @Override
671 public String getDefaultDialerPackage() {
Yorke Lee29c003e2015-05-04 17:09:27 -0700672 try {
Brad Ebinger11623a32015-11-25 13:52:02 -0800673 Log.startSession("TSI.gDDP");
674 final long token = Binder.clearCallingIdentity();
675 try {
Hall Liu7c928322016-12-06 18:15:39 -0800676 return mDefaultDialerCache.getDefaultDialerApplication(
677 ActivityManager.getCurrentUser());
Brad Ebinger11623a32015-11-25 13:52:02 -0800678 } finally {
679 Binder.restoreCallingIdentity(token);
680 }
Yorke Lee29c003e2015-05-04 17:09:27 -0700681 } finally {
Brad Ebinger11623a32015-11-25 13:52:02 -0800682 Log.endSession();
Yorke Lee29c003e2015-05-04 17:09:27 -0700683 }
Yorke Lee5b3fc0a2015-04-23 17:42:57 -0700684 }
685
686 /**
687 * @see android.telecom.TelecomManager#getSystemDialerPackage
688 */
689 @Override
690 public String getSystemDialerPackage() {
Brad Ebinger11623a32015-11-25 13:52:02 -0800691 try {
692 Log.startSession("TSI.gSDP");
693 return mContext.getResources().getString(R.string.ui_default_package);
694 } finally {
695 Log.endSession();
696 }
Yorke Lee5b3fc0a2015-04-23 17:42:57 -0700697 }
698
699 /**
Santos Cordonf987d1a2014-12-02 03:37:03 -0800700 * @see android.telecom.TelecomManager#isInCall
701 */
702 @Override
Svet Ganov09611182015-04-16 12:29:01 -0700703 public boolean isInCall(String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800704 try {
705 Log.startSession("TSI.iIC");
706 if (!canReadPhoneState(callingPackage, "isInCall")) {
707 return false;
708 }
Svet Ganov09611182015-04-16 12:29:01 -0700709
Brad Ebinger11623a32015-11-25 13:52:02 -0800710 synchronized (mLock) {
Tyler Gunnbaf105b2017-04-11 15:21:03 -0700711 return mCallsManager.hasOngoingCalls();
Brad Ebinger11623a32015-11-25 13:52:02 -0800712 }
713 } finally {
714 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700715 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800716 }
717
718 /**
Tyler Gunn37e782b2017-02-10 09:42:03 -0800719 * @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 Cordonf987d1a2014-12-02 03:37:03 -0800739 * @see android.telecom.TelecomManager#isRinging
740 */
741 @Override
Svet Ganov09611182015-04-16 12:29:01 -0700742 public boolean isRinging(String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800743 try {
744 Log.startSession("TSI.iR");
Tyler Gunn322480c2017-07-17 15:34:02 -0700745 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 Ebinger11623a32015-11-25 13:52:02 -0800753 }
Svet Ganov09611182015-04-16 12:29:01 -0700754
Brad Ebinger11623a32015-11-25 13:52:02 -0800755 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 Awad8d5d9dd2015-03-12 11:11:06 -0700765 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800766 }
767
768 /**
769 * @see TelecomManager#getCallState
770 */
771 @Override
772 public int getCallState() {
Brad Ebinger11623a32015-11-25 13:52:02 -0800773 try {
774 Log.startSession("TSI.getCallState");
775 synchronized (mLock) {
776 return mCallsManager.getCallState();
777 }
778 } finally {
779 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700780 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800781 }
782
783 /**
784 * @see android.telecom.TelecomManager#endCall
785 */
786 @Override
Tyler Gunn587fc272018-02-07 16:07:29 -0800787 public boolean endCall(String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800788 try {
789 Log.startSession("TSI.eC");
790 synchronized (mLock) {
Tyler Gunne27a5312018-05-02 13:41:44 -0700791 if (!enforceAnswerCallPermission(callingPackage, Binder.getCallingUid())) {
792 throw new SecurityException("requires ANSWER_PHONE_CALLS permission");
793 }
Santos Cordonebf2d0f2015-05-15 10:28:29 -0700794
Brad Ebinger11623a32015-11-25 13:52:02 -0800795 long token = Binder.clearCallingIdentity();
796 try {
Tyler Gunn587fc272018-02-07 16:07:29 -0800797 return endCallInternal(callingPackage);
Brad Ebinger11623a32015-11-25 13:52:02 -0800798 } finally {
799 Binder.restoreCallingIdentity(token);
800 }
Santos Cordonebf2d0f2015-05-15 10:28:29 -0700801 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800802 } finally {
803 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700804 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800805 }
806
807 /**
808 * @see android.telecom.TelecomManager#acceptRingingCall
809 */
810 @Override
Eugene Suslaccba7202017-02-10 10:56:53 -0800811 public void acceptRingingCall(String packageName) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800812 try {
813 Log.startSession("TSI.aRC");
814 synchronized (mLock) {
Eugene Suslaccba7202017-02-10 10:56:53 -0800815 if (!enforceAnswerCallPermission(packageName, Binder.getCallingUid())) return;
Santos Cordonebf2d0f2015-05-15 10:28:29 -0700816
Brad Ebinger11623a32015-11-25 13:52:02 -0800817 long token = Binder.clearCallingIdentity();
818 try {
819 acceptRingingCallInternal(DEFAULT_VIDEO_STATE);
820 } finally {
821 Binder.restoreCallingIdentity(token);
822 }
Tyler Gunn42ef8082015-11-24 15:34:34 -0800823 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800824 } finally {
825 Log.endSession();
Tyler Gunn42ef8082015-11-24 15:34:34 -0800826 }
827 }
828
829 /**
830 * @see android.telecom.TelecomManager#acceptRingingCall(int)
831 *
832 */
833 @Override
Eugene Suslaccba7202017-02-10 10:56:53 -0800834 public void acceptRingingCallWithVideoState(String packageName, int videoState) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800835 try {
836 Log.startSession("TSI.aRCWVS");
837 synchronized (mLock) {
Eugene Suslaccba7202017-02-10 10:56:53 -0800838 if (!enforceAnswerCallPermission(packageName, Binder.getCallingUid())) return;
Tyler Gunn42ef8082015-11-24 15:34:34 -0800839
Brad Ebinger11623a32015-11-25 13:52:02 -0800840 long token = Binder.clearCallingIdentity();
841 try {
842 acceptRingingCallInternal(videoState);
843 } finally {
844 Binder.restoreCallingIdentity(token);
845 }
Santos Cordonebf2d0f2015-05-15 10:28:29 -0700846 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800847 } finally {
848 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700849 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800850 }
851
852 /**
853 * @see android.telecom.TelecomManager#showInCallScreen
854 */
855 @Override
Svet Ganov09611182015-04-16 12:29:01 -0700856 public void showInCallScreen(boolean showDialpad, String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800857 try {
858 Log.startSession("TSI.sICS");
859 if (!canReadPhoneState(callingPackage, "showInCallScreen")) {
860 return;
Santos Cordonebf2d0f2015-05-15 10:28:29 -0700861 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800862
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 Awad8d5d9dd2015-03-12 11:11:06 -0700874 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800875 }
876
877 /**
878 * @see android.telecom.TelecomManager#cancelMissedCallsNotification
879 */
880 @Override
Yorke Lee53101962015-04-29 16:25:29 -0700881 public void cancelMissedCallsNotification(String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800882 try {
883 Log.startSession("TSI.cMCN");
884 synchronized (mLock) {
885 enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage);
Tony Maka9930942016-01-15 10:57:14 +0000886 UserHandle userHandle = Binder.getCallingUserHandle();
Brad Ebinger11623a32015-11-25 13:52:02 -0800887 long token = Binder.clearCallingIdentity();
888 try {
Tony Maka9930942016-01-15 10:57:14 +0000889 mCallsManager.getMissedCallNotifier().clearMissedCalls(userHandle);
Brad Ebinger11623a32015-11-25 13:52:02 -0800890 } finally {
891 Binder.restoreCallingIdentity(token);
892 }
Santos Cordonebf2d0f2015-05-15 10:28:29 -0700893 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800894 } finally {
895 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700896 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800897 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800898 /**
899 * @see android.telecom.TelecomManager#handleMmi
900 */
901 @Override
Yorke Lee53101962015-04-29 16:25:29 -0700902 public boolean handlePinMmi(String dialString, String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800903 try {
904 Log.startSession("TSI.hPM");
905 synchronized (mLock) {
906 enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage);
Santos Cordonf987d1a2014-12-02 03:37:03 -0800907
Brad Ebinger11623a32015-11-25 13:52:02 -0800908 // 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 Awad8d5d9dd2015-03-12 11:11:06 -0700919 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800920 }finally {
921 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -0800922 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800923 }
924
925 /**
926 * @see android.telecom.TelecomManager#handleMmi
927 */
928 @Override
Brad Ebinger11623a32015-11-25 13:52:02 -0800929 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 Cordonf987d1a2014-12-02 03:37:03 -0800935
Brad Ebinger11623a32015-11-25 13:52:02 -0800936 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 Awad8d5d9dd2015-03-12 11:11:06 -0700955 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800956 }finally {
957 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -0800958 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800959 }
960
961 /**
962 * @see android.telecom.TelecomManager#getAdnUriForPhoneAccount
963 */
964 @Override
Yorke Lee53101962015-04-29 16:25:29 -0700965 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle,
966 String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -0800967 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 Awad8d5d9dd2015-03-12 11:11:06 -0700988
Brad Ebinger11623a32015-11-25 13:52:02 -0800989 return Uri.parse(retval);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700990 }
Brad Ebinger11623a32015-11-25 13:52:02 -0800991 } finally {
992 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -0800993 }
Santos Cordonf987d1a2014-12-02 03:37:03 -0800994 }
995
996 /**
997 * @see android.telecom.TelecomManager#isTtySupported
998 */
999 @Override
Svet Ganov09611182015-04-16 12:29:01 -07001000 public boolean isTtySupported(String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -08001001 try {
1002 Log.startSession("TSI.iTS");
Sanket Padawe88efa0c2017-09-08 11:46:34 -07001003 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 Ebinger11623a32015-11-25 13:52:02 -08001006 }
Svet Ganov09611182015-04-16 12:29:01 -07001007
Brad Ebinger11623a32015-11-25 13:52:02 -08001008 synchronized (mLock) {
1009 return mCallsManager.isTtySupported();
1010 }
1011 } finally {
1012 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001013 }
Santos Cordonf987d1a2014-12-02 03:37:03 -08001014 }
1015
1016 /**
1017 * @see android.telecom.TelecomManager#getCurrentTtyMode
1018 */
1019 @Override
Svet Ganov09611182015-04-16 12:29:01 -07001020 public int getCurrentTtyMode(String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -08001021 try {
1022 Log.startSession("TSI.gCTM");
1023 if (!canReadPhoneState(callingPackage, "getCurrentTtyMode")) {
1024 return TelecomManager.TTY_MODE_OFF;
1025 }
Svet Ganov09611182015-04-16 12:29:01 -07001026
Brad Ebinger11623a32015-11-25 13:52:02 -08001027 synchronized (mLock) {
1028 return mCallsManager.getCurrentTtyMode();
1029 }
1030 } finally {
1031 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001032 }
Santos Cordonf987d1a2014-12-02 03:37:03 -08001033 }
1034
1035 /**
1036 * @see android.telecom.TelecomManager#addNewIncomingCall
1037 */
1038 @Override
1039 public void addNewIncomingCall(PhoneAccountHandle phoneAccountHandle, Bundle extras) {
Brad Ebinger11623a32015-11-25 13:52:02 -08001040 try {
1041 Log.startSession("TSI.aNIC");
1042 synchronized (mLock) {
1043 Log.i(this, "Adding new incoming call with phoneAccountHandle %s",
Sharvil Nanavati6d3efb42015-05-14 11:36:40 -07001044 phoneAccountHandle);
Brad Ebinger11623a32015-11-25 13:52:02 -08001045 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 Mak5851fa02016-02-23 19:41:52 +00001059 enforcePhoneAccountIsRegisteredEnabled(phoneAccountHandle,
1060 Binder.getCallingUserHandle());
Tyler Gunna90ba732017-01-26 07:24:08 -08001061 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 Gunn0c7cf9a2017-05-17 11:15:57 -07001067
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 Gunna90ba732017-01-26 07:24:08 -08001071 }
Sharvil Nanavati6d3efb42015-05-14 11:36:40 -07001072 }
Brad Ebinger11623a32015-11-25 13:52:02 -08001073 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 Sharkeye2e4cdf2016-03-18 12:19:02 -06001080 extras.setDefusable(true);
Brad Ebinger11623a32015-11-25 13:52:02 -08001081 intent.putExtra(TelecomManager.EXTRA_INCOMING_CALL_EXTRAS, extras);
1082 }
Hall Liuecda5542015-12-04 11:31:31 -08001083 mCallIntentProcessorAdapter.processIncomingCallIntent(
1084 mCallsManager, intent);
Brad Ebinger11623a32015-11-25 13:52:02 -08001085 } finally {
1086 Binder.restoreCallingIdentity(token);
1087 }
1088 } else {
1089 Log.w(this, "Null phoneAccountHandle. Ignoring request to add new" +
1090 " incoming call");
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001091 }
Santos Cordonf987d1a2014-12-02 03:37:03 -08001092 }
Brad Ebinger11623a32015-11-25 13:52:02 -08001093 } finally {
1094 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -08001095 }
1096 }
1097
1098 /**
Sanket Padaweccdf3642017-11-10 14:49:05 -08001099 * @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 Gunn37a4dca2018-01-18 15:00:41 -08001106 Log.i(this, "acceptHandover; srcAddr=%s, videoState=%s, dest=%s",
1107 Log.pii(srcAddr), VideoProfile.videoStateToString(videoState),
Sanket Padaweccdf3642017-11-10 14:49:05 -08001108 destAcct);
Tyler Gunn37a4dca2018-01-18 15:00:41 -08001109
Sanket Padaweccdf3642017-11-10 14:49:05 -08001110 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 Gunn37a4dca2018-01-18 15:00:41 -08001124 if (!enforceAcceptHandoverPermission(
1125 destAcct.getComponentName().getPackageName(),
1126 Binder.getCallingUid())) {
1127 throw new SecurityException("App must be granted runtime "
1128 + "ACCEPT_HANDOVER permission.");
1129 }
Sanket Padaweccdf3642017-11-10 14:49:05 -08001130
Tyler Gunn37a4dca2018-01-18 15:00:41 -08001131 long token = Binder.clearCallingIdentity();
1132 try {
1133 mCallsManager.acceptHandover(srcAddr, videoState, destAcct);
1134 } finally {
1135 Binder.restoreCallingIdentity(token);
1136 }
Sanket Padaweccdf3642017-11-10 14:49:05 -08001137 } 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 Cordonf987d1a2014-12-02 03:37:03 -08001148 * @see android.telecom.TelecomManager#addNewUnknownCall
1149 */
1150 @Override
1151 public void addNewUnknownCall(PhoneAccountHandle phoneAccountHandle, Bundle extras) {
Brad Ebinger11623a32015-11-25 13:52:02 -08001152 try {
1153 Log.startSession("TSI.aNUC");
Tyler Gunn322480c2017-07-17 15:34:02 -07001154 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 Ebinger11623a32015-11-25 13:52:02 -08001163 synchronized (mLock) {
1164 if (phoneAccountHandle != null &&
1165 phoneAccountHandle.getComponentName() != null) {
1166 mAppOpsManager.checkPackage(
1167 Binder.getCallingUid(),
1168 phoneAccountHandle.getComponentName().getPackageName());
Santos Cordonf987d1a2014-12-02 03:37:03 -08001169
Brad Ebinger11623a32015-11-25 13:52:02 -08001170 // Make sure it doesn't cross the UserHandle boundary
1171 enforceUserHandleMatchesCaller(phoneAccountHandle);
Tony Mak5851fa02016-02-23 19:41:52 +00001172 enforcePhoneAccountIsRegisteredEnabled(phoneAccountHandle,
1173 Binder.getCallingUserHandle());
Brad Ebinger11623a32015-11-25 13:52:02 -08001174 long token = Binder.clearCallingIdentity();
Santos Cordonf987d1a2014-12-02 03:37:03 -08001175
Brad Ebinger11623a32015-11-25 13:52:02 -08001176 try {
1177 Intent intent = new Intent(TelecomManager.ACTION_NEW_UNKNOWN_CALL);
Jeff Sharkeye2e4cdf2016-03-18 12:19:02 -06001178 if (extras != null) {
1179 extras.setDefusable(true);
1180 intent.putExtras(extras);
1181 }
Brad Ebinger11623a32015-11-25 13:52:02 -08001182 intent.putExtra(CallIntentProcessor.KEY_IS_UNKNOWN_CALL, true);
1183 intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,
1184 phoneAccountHandle);
Hall Liuecda5542015-12-04 11:31:31 -08001185 mCallIntentProcessorAdapter.processUnknownCallIntent(mCallsManager, intent);
Brad Ebinger11623a32015-11-25 13:52:02 -08001186 } 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 Nanavati6d3efb42015-05-14 11:36:40 -07001193 }
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001194 }
Brad Ebinger11623a32015-11-25 13:52:02 -08001195 } finally {
1196 Log.endSession();
Santos Cordonf987d1a2014-12-02 03:37:03 -08001197 }
1198 }
Tyler Gunn47689862014-12-17 17:10:28 -08001199
1200 /**
Yorke Leea3a3adc2015-04-23 12:49:01 -07001201 * @see android.telecom.TelecomManager#placeCall
1202 */
1203 @Override
1204 public void placeCall(Uri handle, Bundle extras, String callingPackage) {
Brad Ebinger11623a32015-11-25 13:52:02 -08001205 try {
1206 Log.startSession("TSI.pC");
1207 enforceCallingPackage(callingPackage);
Tyler Gunna90ba732017-01-26 07:24:08 -08001208
1209 PhoneAccountHandle phoneAccountHandle = null;
1210 if (extras != null) {
1211 phoneAccountHandle = extras.getParcelable(
1212 TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE);
Tyler Gunn141ef582017-05-26 13:38:13 -07001213 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 Gunna90ba732017-01-26 07:24:08 -08001217 }
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 Gunn0c7cf9a2017-05-17 11:15:57 -07001223
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 Gunna90ba732017-01-26 07:24:08 -08001233 } else if (!canCallPhone(callingPackage, "placeCall")) {
Brad Ebinger11623a32015-11-25 13:52:02 -08001234 throw new SecurityException("Package " + callingPackage
1235 + " is not allowed to place phone calls");
Yorke Lee58061752015-05-04 11:06:26 -07001236 }
Brad Ebinger11623a32015-11-25 13:52:02 -08001237
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 Gunnb652dad2018-03-27 18:49:49 +00001250 // 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 Ebinger11623a32015-11-25 13:52:02 -08001257
1258 synchronized (mLock) {
1259 final UserHandle userHandle = Binder.getCallingUserHandle();
1260 long token = Binder.clearCallingIdentity();
1261 try {
Tyler Gunnb652dad2018-03-27 18:49:49 +00001262 final Intent intent = new Intent(hasCallPrivilegedPermission ?
1263 Intent.ACTION_CALL_PRIVILEGED : Intent.ACTION_CALL, handle);
Jeff Sharkeye2e4cdf2016-03-18 12:19:02 -06001264 if (extras != null) {
1265 extras.setDefusable(true);
1266 intent.putExtras(extras);
1267 }
Hall Liuecda5542015-12-04 11:31:31 -08001268 mUserCallIntentProcessorFactory.create(mContext, userHandle)
1269 .processIntent(
Tyler Gunna90ba732017-01-26 07:24:08 -08001270 intent, callingPackage, isSelfManaged ||
Tyler Gunnb652dad2018-03-27 18:49:49 +00001271 (hasCallAppOp && hasCallPermission),
1272 true /* isLocalInvocation */);
Brad Ebinger11623a32015-11-25 13:52:02 -08001273 } finally {
1274 Binder.restoreCallingIdentity(token);
1275 }
1276 }
1277 } finally {
1278 Log.endSession();
Yorke Leea3a3adc2015-04-23 12:49:01 -07001279 }
1280 }
1281
1282 /**
Santos Cordonea5cb932015-05-07 16:28:38 -07001283 * @see android.telecom.TelecomManager#enablePhoneAccount
1284 */
1285 @Override
Yorke Lee71734c22015-06-02 14:22:56 -07001286 public boolean enablePhoneAccount(PhoneAccountHandle accountHandle, boolean isEnabled) {
Brad Ebinger11623a32015-11-25 13:52:02 -08001287 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 Lee71734c22015-06-02 14:22:56 -07001298 }
Brad Ebinger11623a32015-11-25 13:52:02 -08001299 } finally {
1300 Log.endSession();
Yorke Lee71734c22015-06-02 14:22:56 -07001301 }
1302 }
1303
1304 @Override
1305 public boolean setDefaultDialer(String packageName) {
Brad Ebinger11623a32015-11-25 13:52:02 -08001306 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 Liu7c928322016-12-06 18:15:39 -08001313 final boolean result = mDefaultDialerCache.setDefaultDialer(
1314 packageName, ActivityManager.getCurrentUser());
Brad Ebinger11623a32015-11-25 13:52:02 -08001315 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 Leeb3984302015-06-15 12:06:35 -07001326 }
Santos Cordonea5cb932015-05-07 16:28:38 -07001327 }
Brad Ebinger11623a32015-11-25 13:52:02 -08001328 } finally {
1329 Log.endSession();
Santos Cordonea5cb932015-05-07 16:28:38 -07001330 }
1331 }
1332
Hall Liuecd74a52016-01-12 15:26:36 -08001333 @Override
Hall Liu874c0f82016-04-29 18:13:18 -07001334 public TelecomAnalytics dumpCallAnalytics() {
Hall Liuecd74a52016-01-12 15:26:36 -08001335 try {
1336 Log.startSession("TSI.dCA");
1337 enforcePermission(DUMP);
Hall Liu874c0f82016-04-29 18:13:18 -07001338 return Analytics.dumpToParcelableAnalytics();
Hall Liuecd74a52016-01-12 15:26:36 -08001339 } finally {
1340 Log.endSession();
1341 }
1342 }
1343
Santos Cordonea5cb932015-05-07 16:28:38 -07001344 /**
Tyler Gunn47689862014-12-17 17:10:28 -08001345 * 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 Liu5bbbcf72016-08-08 17:23:20 -07001362 if (args.length > 0 && Analytics.ANALYTICS_DUMPSYS_ARG.equals(args[0])) {
1363 Analytics.dumpToEncodedProto(writer, args);
1364 return;
1365 }
Tyler Gunn897e8512017-05-18 15:46:51 -07001366 boolean isTimeLineView = (args.length > 0 && TIME_LINE_ARG.equalsIgnoreCase(args[0]));
Hall Liu5bbbcf72016-08-08 17:23:20 -07001367
Tyler Gunn47689862014-12-17 17:10:28 -08001368 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
Ihab Awad8de76912015-02-17 12:25:52 -08001369 if (mCallsManager != null) {
Ihab Awad78a5e6b2015-02-06 10:13:05 -08001370 pw.println("CallsManager: ");
Tyler Gunn47689862014-12-17 17:10:28 -08001371 pw.increaseIndent();
Ihab Awad8de76912015-02-17 12:25:52 -08001372 mCallsManager.dump(pw);
Tyler Gunn47689862014-12-17 17:10:28 -08001373 pw.decreaseIndent();
1374
Ihab Awad78a5e6b2015-02-06 10:13:05 -08001375 pw.println("PhoneAccountRegistrar: ");
Tyler Gunn47689862014-12-17 17:10:28 -08001376 pw.increaseIndent();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001377 mPhoneAccountRegistrar.dump(pw);
Tyler Gunn47689862014-12-17 17:10:28 -08001378 pw.decreaseIndent();
Hall Liu32587202015-11-18 11:10:08 -08001379
1380 pw.println("Analytics:");
1381 pw.increaseIndent();
1382 Analytics.dump(pw);
1383 pw.decreaseIndent();
Tyler Gunn47689862014-12-17 17:10:28 -08001384 }
Tyler Gunn897e8512017-05-18 15:46:51 -07001385 if (isTimeLineView) {
1386 Log.dumpEventsTimeline(pw);
1387 } else {
1388 Log.dumpEvents(pw);
1389 }
Tyler Gunn47689862014-12-17 17:10:28 -08001390 }
Abhijith Shastry7a846f52016-02-01 16:49:27 -08001391
Mohamedc9261852016-02-05 14:10:17 -08001392 /**
Abhijith Shastryb1308ec2016-02-29 16:26:09 -08001393 * @see android.telecom.TelecomManager#createManageBlockedNumbersIntent
1394 */
Abhijith Shastryebe7bbe2016-02-29 11:16:30 -08001395 @Override
1396 public Intent createManageBlockedNumbersIntent() {
Abhijith Shastryb1308ec2016-02-29 16:26:09 -08001397 return BlockedNumbersActivity.getIntentForStartingActivity();
Abhijith Shastryebe7bbe2016-02-29 11:16:30 -08001398 }
Tyler Gunnacb3bc82017-01-09 09:43:56 -08001399
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 Gunna90ba732017-01-26 07:24:08 -08001411 return mCallsManager.isIncomingCallPermitted(phoneAccountHandle);
Tyler Gunnacb3bc82017-01-09 09:43:56 -08001412 } finally {
1413 Binder.restoreCallingIdentity(token);
1414 }
1415 }
1416 } finally {
1417 Log.endSession();
1418 }
Tyler Gunnacb3bc82017-01-09 09:43:56 -08001419 }
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 Gunna90ba732017-01-26 07:24:08 -08001432 return mCallsManager.isOutgoingCallPermitted(phoneAccountHandle);
Tyler Gunnacb3bc82017-01-09 09:43:56 -08001433 } finally {
1434 Binder.restoreCallingIdentity(token);
1435 }
1436 }
1437 } finally {
1438 Log.endSession();
1439 }
Tyler Gunnacb3bc82017-01-09 09:43:56 -08001440 }
Tyler Gunn9e806ee2017-02-06 20:49:24 -08001441
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 Awad8d5d9dd2015-03-12 11:11:06 -07001465 };
1466
Eugene Suslaccba7202017-02-10 10:56:53 -08001467 /**
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 Gunn37a4dca2018-01-18 15:00:41 -08001488 /**
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 Awad8d5d9dd2015-03-12 11:11:06 -07001506 private Context mContext;
1507 private AppOpsManager mAppOpsManager;
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001508 private PackageManager mPackageManager;
1509 private CallsManager mCallsManager;
1510 private final PhoneAccountRegistrar mPhoneAccountRegistrar;
Hall Liuecda5542015-12-04 11:31:31 -08001511 private final CallIntentProcessor.Adapter mCallIntentProcessorAdapter;
1512 private final UserCallIntentProcessorFactory mUserCallIntentProcessorFactory;
Hall Liu7c928322016-12-06 18:15:39 -08001513 private final DefaultDialerCache mDefaultDialerCache;
Hall Liu0a6dd302015-12-16 15:06:49 -08001514 private final SubscriptionManagerAdapter mSubscriptionManagerAdapter;
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001515 private final TelecomSystem.SyncRoot mLock;
1516
1517 public TelecomServiceImpl(
1518 Context context,
1519 CallsManager callsManager,
1520 PhoneAccountRegistrar phoneAccountRegistrar,
Hall Liuecda5542015-12-04 11:31:31 -08001521 CallIntentProcessor.Adapter callIntentProcessorAdapter,
1522 UserCallIntentProcessorFactory userCallIntentProcessorFactory,
Hall Liu7c928322016-12-06 18:15:39 -08001523 DefaultDialerCache defaultDialerCache,
Hall Liu0a6dd302015-12-16 15:06:49 -08001524 SubscriptionManagerAdapter subscriptionManagerAdapter,
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001525 TelecomSystem.SyncRoot lock) {
1526 mContext = context;
1527 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
1528
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001529 mPackageManager = mContext.getPackageManager();
1530
1531 mCallsManager = callsManager;
1532 mLock = lock;
1533 mPhoneAccountRegistrar = phoneAccountRegistrar;
Hall Liuecda5542015-12-04 11:31:31 -08001534 mUserCallIntentProcessorFactory = userCallIntentProcessorFactory;
Hall Liu7c928322016-12-06 18:15:39 -08001535 mDefaultDialerCache = defaultDialerCache;
Hall Liuecda5542015-12-04 11:31:31 -08001536 mCallIntentProcessorAdapter = callIntentProcessorAdapter;
Hall Liu0a6dd302015-12-16 15:06:49 -08001537 mSubscriptionManagerAdapter = subscriptionManagerAdapter;
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001538 }
1539
Ihab Awadaa383cc2015-03-22 22:12:28 -07001540 public ITelecomService.Stub getBinder() {
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001541 return mBinderImpl;
Santos Cordonf987d1a2014-12-02 03:37:03 -08001542 }
1543
1544 //
1545 // Supporting methods for the ITelecomService interface implementation.
1546 //
1547
Tony Mak240656f2015-12-04 11:36:22 +00001548 private boolean isPhoneAccountHandleVisibleToCallingUser(
1549 PhoneAccountHandle phoneAccountUserHandle, UserHandle callingUser) {
1550 return mPhoneAccountRegistrar.getPhoneAccount(phoneAccountUserHandle, callingUser) != null;
Santos Cordonf987d1a2014-12-02 03:37:03 -08001551 }
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 Gunn42ef8082015-11-24 15:34:34 -08001576 private void acceptRingingCallInternal(int videoState) {
Ihab Awad8de76912015-02-17 12:25:52 -08001577 Call call = mCallsManager.getFirstCallWithState(CallState.RINGING);
Santos Cordonf987d1a2014-12-02 03:37:03 -08001578 if (call != null) {
Tyler Gunn42ef8082015-11-24 15:34:34 -08001579 if (videoState == DEFAULT_VIDEO_STATE || !isValidAcceptVideoState(videoState)) {
1580 videoState = call.getVideoState();
1581 }
1582 call.answer(videoState);
Santos Cordonf987d1a2014-12-02 03:37:03 -08001583 }
1584 }
1585
Tyler Gunn587fc272018-02-07 16:07:29 -08001586 private boolean endCallInternal(String callingPackage) {
Santos Cordonf987d1a2014-12-02 03:37:03 -08001587 // Always operate on the foreground call if one exists, otherwise get the first call in
1588 // priority order by call-state.
Ihab Awad8de76912015-02-17 12:25:52 -08001589 Call call = mCallsManager.getForegroundCall();
Santos Cordonf987d1a2014-12-02 03:37:03 -08001590 if (call == null) {
Ihab Awad8de76912015-02-17 12:25:52 -08001591 call = mCallsManager.getFirstCallWithState(
Santos Cordonf987d1a2014-12-02 03:37:03 -08001592 CallState.ACTIVE,
1593 CallState.DIALING,
Tyler Gunn1e37be52016-07-11 08:54:23 -07001594 CallState.PULLING,
Santos Cordonf987d1a2014-12-02 03:37:03 -08001595 CallState.RINGING,
1596 CallState.ON_HOLD);
1597 }
1598
1599 if (call != null) {
Tyler Gunn275e8822019-05-13 13:58:15 -07001600 if (call.isEmergencyCall()) {
1601 android.util.EventLog.writeEvent(0x534e4554, "132438333", -1, "");
1602 return false;
1603 }
1604
Santos Cordonf987d1a2014-12-02 03:37:03 -08001605 if (call.getState() == CallState.RINGING) {
Tyler Gunn587fc272018-02-07 16:07:29 -08001606 call.reject(false /* rejectWithMessage */, null, callingPackage);
Santos Cordonf987d1a2014-12-02 03:37:03 -08001607 } else {
Tyler Gunn587fc272018-02-07 16:07:29 -08001608 call.disconnect(0 /* disconnectionTimeout */, callingPackage);
Santos Cordonf987d1a2014-12-02 03:37:03 -08001609 }
1610 return true;
1611 }
1612
1613 return false;
1614 }
1615
Brad Ebinger62da8e12016-01-28 19:16:08 -08001616 // Enforce that the PhoneAccountHandle being passed in is both registered to the current user
1617 // and enabled.
Tony Mak5851fa02016-02-23 19:41:52 +00001618 private void enforcePhoneAccountIsRegisteredEnabled(PhoneAccountHandle phoneAccountHandle,
1619 UserHandle callingUserHandle) {
1620 PhoneAccount phoneAccount = mPhoneAccountRegistrar.getPhoneAccount(phoneAccountHandle,
1621 callingUserHandle);
Brad Ebinger62da8e12016-01-28 19:16:08 -08001622 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 Cordonf987d1a2014-12-02 03:37:03 -08001632 private void enforcePhoneAccountModificationForPackage(String packageName) {
1633 // TODO: Use a new telecomm permission for this instead of reusing modify.
1634
Yorke Leecb0bd8a2015-05-18 11:57:14 -07001635 int result = mContext.checkCallingOrSelfPermission(MODIFY_PHONE_STATE);
Santos Cordonf987d1a2014-12-02 03:37:03 -08001636
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 Leecb0bd8a2015-05-18 11:57:14 -07001650 private void enforcePermissionOrPrivilegedDialer(String permission, String packageName) {
Yorke Lee53101962015-04-29 16:25:29 -07001651 if (!isPrivilegedDialerCalling(packageName)) {
1652 try {
Yorke Leecb0bd8a2015-05-18 11:57:14 -07001653 enforcePermission(permission);
Yorke Lee53101962015-04-29 16:25:29 -07001654 } catch (SecurityException e) {
Yorke Leecb0bd8a2015-05-18 11:57:14 -07001655 Log.e(this, e, "Caller must be the default or system dialer, or have the permission"
1656 + " %s to perform this operation.", permission);
Yorke Lee53101962015-04-29 16:25:29 -07001657 throw e;
1658 }
Santos Cordonf987d1a2014-12-02 03:37:03 -08001659 }
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 Cordonf987d1a2014-12-02 03:37:03 -08001670 private void enforceRegisterSimSubscriptionPermission() {
Yorke Leecb0bd8a2015-05-18 11:57:14 -07001671 enforcePermission(REGISTER_SIM_SUBSCRIPTION);
Santos Cordonf987d1a2014-12-02 03:37:03 -08001672 }
1673
Santos Cordonf987d1a2014-12-02 03:37:03 -08001674 private void enforceModifyPermission() {
Yorke Leecb0bd8a2015-05-18 11:57:14 -07001675 enforcePermission(MODIFY_PHONE_STATE);
Santos Cordonf987d1a2014-12-02 03:37:03 -08001676 }
1677
Tyler Gunn322480c2017-07-17 15:34:02 -07001678 private void enforceModifyPermission(String message) {
1679 mContext.enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, message);
1680 }
1681
Santos Cordonf987d1a2014-12-02 03:37:03 -08001682 private void enforcePermission(String permission) {
1683 mContext.enforceCallingOrSelfPermission(permission, null);
1684 }
1685
Tyler Gunnacb3bc82017-01-09 09:43:56 -08001686 private void enforceRegisterSelfManaged() {
1687 mContext.enforceCallingPermission(android.Manifest.permission.MANAGE_OWN_CALLS, null);
1688 }
1689
Santos Cordonf987d1a2014-12-02 03:37:03 -08001690 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 Mak240656f2015-12-04 11:36:22 +00001702 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 Cordonf987d1a2014-12-02 03:37:03 -08001710 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 Ganov38f1a4d2015-04-17 15:28:03 -07001718 private boolean canReadPhoneState(String callingPackage, String message) {
Yorke Lee57138a62015-05-18 18:18:08 -07001719 // 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 Mahajan3c296932015-07-14 10:23:15 -07001725 try {
Amit Mahajan86b8e332015-07-30 16:02:52 -07001726 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 Mahajan3c296932015-07-14 10:23:15 -07001729 return true;
1730 } catch (SecurityException e) {
1731 // Accessing phone state is gated by a special permission.
1732 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, message);
Svet Ganov09611182015-04-16 12:29:01 -07001733
Amit Mahajan3c296932015-07-14 10:23:15 -07001734 // 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 Ganov09611182015-04-16 12:29:01 -07001738 }
1739
Tyler Gunna90ba732017-01-26 07:24:08 -08001740 private boolean isSelfManagedConnectionService(PhoneAccountHandle phoneAccountHandle) {
1741 if (phoneAccountHandle != null) {
1742 PhoneAccount phoneAccount = mPhoneAccountRegistrar.getPhoneAccountUnchecked(
1743 phoneAccountHandle);
Tyler Gunn9e806ee2017-02-06 20:49:24 -08001744 return phoneAccount != null && phoneAccount.isSelfManaged();
Tyler Gunna90ba732017-01-26 07:24:08 -08001745 }
1746 return false;
1747 }
1748
Yorke Leea3a3adc2015-04-23 12:49:01 -07001749 private boolean canCallPhone(String callingPackage, String message) {
Yorke Lee57138a62015-05-18 18:18:08 -07001750 // 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 Leea3a3adc2015-04-23 12:49:01 -07001756 // Accessing phone state is gated by a special permission.
Yorke Leecb0bd8a2015-05-18 11:57:14 -07001757 mContext.enforceCallingOrSelfPermission(CALL_PHONE, message);
Yorke Leea3a3adc2015-04-23 12:49:01 -07001758
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 Nepal2a98c972015-03-04 15:43:15 -08001764 private boolean isCallerSimCallManager() {
Yorke Lee9427c0f2015-06-27 11:01:58 -07001765 long token = Binder.clearCallingIdentity();
Tony Mak240656f2015-12-04 11:36:22 +00001766 PhoneAccountHandle accountHandle = null;
Yorke Lee9427c0f2015-06-27 11:01:58 -07001767 try {
Tony Mak240656f2015-12-04 11:36:22 +00001768 accountHandle = mPhoneAccountRegistrar.getSimCallManagerOfCurrentUser();
Yorke Lee9427c0f2015-06-27 11:01:58 -07001769 } finally {
1770 Binder.restoreCallingIdentity(token);
1771 }
1772
Sailesh Nepal2a98c972015-03-04 15:43:15 -08001773 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 Lee53101962015-04-29 16:25:29 -07001784 private boolean isPrivilegedDialerCalling(String callingPackage) {
1785 mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liu7c928322016-12-06 18:15:39 -08001786 return mDefaultDialerCache.isDefaultOrSystemDialer(
1787 callingPackage, Binder.getCallingUserHandle().getIdentifier());
Santos Cordonf987d1a2014-12-02 03:37:03 -08001788 }
1789
1790 private TelephonyManager getTelephonyManager() {
Hall Liuecda5542015-12-04 11:31:31 -08001791 return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
Santos Cordonf987d1a2014-12-02 03:37:03 -08001792 }
Tyler Gunn42ef8082015-11-24 15:34:34 -08001793
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 Cordonf987d1a2014-12-02 03:37:03 -08001812}