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
This commit is contained in:
Shuo Qian
2020-10-20 11:04:28 -07:00
parent 8094421605
commit 4d0652699a
4 changed files with 36 additions and 0 deletions

View File

@@ -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;