diff --git a/telecomm/java/android/telecom/TelecomManager.java b/telecomm/java/android/telecom/TelecomManager.java index df114dbabe5b8..e0f5b20951901 100644 --- a/telecomm/java/android/telecom/TelecomManager.java +++ b/telecomm/java/android/telecom/TelecomManager.java @@ -2600,6 +2600,33 @@ public class TelecomManager { return false; } + /** + * Determines whether there are any ongoing {@link PhoneAccount#CAPABILITY_SELF_MANAGED} + * calls for a given {@code packageName} and {@code userHandle}. + * + * @param packageName the package name of the app to check calls for. + * @param userHandle the user handle on which to check for calls. + * @return {@code true} if there are ongoing calls, {@code false} otherwise. + * @hide + */ + @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) + public boolean isInSelfManagedCall(@NonNull String packageName, + @NonNull UserHandle userHandle) { + ITelecomService service = getTelecomService(); + if (service != null) { + try { + return service.isInSelfManagedCall(packageName, userHandle, + mContext.getOpPackageName()); + } catch (RemoteException e) { + Log.e(TAG, "RemoteException isInSelfManagedCall: " + e); + e.rethrowFromSystemServer(); + return false; + } + } else { + throw new IllegalStateException("Telecom service is not present"); + } + } + /** * Handles {@link Intent#ACTION_CALL} intents trampolined from UserCallActivity. * @param intent The {@link Intent#ACTION_CALL} intent to handle. diff --git a/telecomm/java/com/android/internal/telecom/ITelecomService.aidl b/telecomm/java/com/android/internal/telecom/ITelecomService.aidl index 9999c897d1b69..07e18d524701b 100644 --- a/telecomm/java/com/android/internal/telecom/ITelecomService.aidl +++ b/telecomm/java/com/android/internal/telecom/ITelecomService.aidl @@ -22,6 +22,7 @@ import android.telecom.TelecomAnalytics; import android.telecom.PhoneAccountHandle; import android.net.Uri; import android.os.Bundle; +import android.os.UserHandle; import android.telecom.PhoneAccount; /** @@ -374,4 +375,10 @@ interface ITelecomService { * @see TelecomServiceImpl#setTestCallDiagnosticService */ void setTestCallDiagnosticService(in String packageName); + + /** + * @see TelecomServiceImpl#isInSelfManagedCall + */ + boolean isInSelfManagedCall(String packageName, in UserHandle userHandle, + String callingPackage); }