From 4d0652699a88ad60c2dfdbf7b59065ee684df6d6 Mon Sep 17 00:00:00 2001 From: Shuo Qian Date: Tue, 20 Oct 2020 11:04:28 -0700 Subject: [PATCH] Introduce hasCompanionInCallServiceAccess API It retruns whether the caller has InCallService access for the companion apps. A companion app is an app associated with a physical wearable device via the {@link android.companion.CompanionDeviceManager} API. Test: cts Bug: 169595473 Change-Id: Id659bfae8556e965d3c31613848bde808f28a858 --- api/current.txt | 1 + non-updatable-api/current.txt | 1 + .../java/android/telecom/TelecomManager.java | 29 +++++++++++++++++++ .../internal/telecom/ITelecomService.aidl | 5 ++++ 4 files changed, 36 insertions(+) diff --git a/api/current.txt b/api/current.txt index 43c08695348bd..9c2f2dec89762 100644 --- a/api/current.txt +++ b/api/current.txt @@ -46508,6 +46508,7 @@ package android.telecom { method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getVoiceMailNumber(android.telecom.PhoneAccountHandle); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean handleMmi(String); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean handleMmi(String, android.telecom.PhoneAccountHandle); + method public boolean hasCompanionInCallServiceAccess(); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public boolean isInCall(); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public boolean isInManagedCall(); method public boolean isIncomingCallPermitted(android.telecom.PhoneAccountHandle); diff --git a/non-updatable-api/current.txt b/non-updatable-api/current.txt index 7c3ff268a10c4..3ef9da3f5379f 100644 --- a/non-updatable-api/current.txt +++ b/non-updatable-api/current.txt @@ -44634,6 +44634,7 @@ package android.telecom { method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getVoiceMailNumber(android.telecom.PhoneAccountHandle); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean handleMmi(String); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean handleMmi(String, android.telecom.PhoneAccountHandle); + method public boolean hasCompanionInCallServiceAccess(); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public boolean isInCall(); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public boolean isInManagedCall(); method public boolean isIncomingCallPermitted(android.telecom.PhoneAccountHandle); diff --git a/telecomm/java/android/telecom/TelecomManager.java b/telecomm/java/android/telecom/TelecomManager.java index 82da4475c1b9d..ae485d502a1e5 100644 --- a/telecomm/java/android/telecom/TelecomManager.java +++ b/telecomm/java/android/telecom/TelecomManager.java @@ -32,6 +32,7 @@ import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Process; import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; @@ -1604,6 +1605,30 @@ public class TelecomManager { return false; } + /** + * Returns whether the caller has {@link InCallService} access for companion apps. + * + * A companion app is an app associated with a physical wearable device via the + * {@link android.companion.CompanionDeviceManager} API. + * + * @return {@code true} if the caller has {@link InCallService} access for + * companion app; {@code false} otherwise. + */ + public boolean hasCompanionInCallServiceAccess() { + try { + if (isServiceConnected()) { + return getTelecomService().hasCompanionInCallServiceAccess( + mContext.getOpPackageName()); + } + } catch (RemoteException e) { + Log.e(TAG, "RemoteException calling hasCompanionInCallServiceAccess().", e); + if (!isSystemProcess()) { + e.rethrowAsRuntimeException(); + } + } + return false; + } + /** * Returns whether there is an ongoing call originating from a managed * {@link ConnectionService}. An ongoing call can be in dialing, ringing, active or holding @@ -2416,6 +2441,10 @@ public class TelecomManager { } } + private boolean isSystemProcess() { + return Process.myUid() == Process.SYSTEM_UID; + } + private ITelecomService getTelecomService() { if (mTelecomServiceOverride != null) { return mTelecomServiceOverride; diff --git a/telecomm/java/com/android/internal/telecom/ITelecomService.aidl b/telecomm/java/com/android/internal/telecom/ITelecomService.aidl index 7c6f1df972f38..e636b93deace7 100644 --- a/telecomm/java/com/android/internal/telecom/ITelecomService.aidl +++ b/telecomm/java/com/android/internal/telecom/ITelecomService.aidl @@ -178,6 +178,11 @@ interface ITelecomService { */ boolean isInCall(String callingPackage, String callingFeatureId); + /** + * @see TelecomServiceImpl#hasCompanionInCallServiceAccess + */ + boolean hasCompanionInCallServiceAccess(String callingPackage); + /** * @see TelecomServiceImpl#isInManagedCall */