Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc9922d8 authored by Pranav Madapurmath's avatar Pranav Madapurmath Committed by Android (Google) Code Review
Browse files

Merge "Formalize TelecomManager#isInSelfManagedCall" into main

parents 8729846c a8a8246b
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -4669,18 +4669,35 @@ public class CallsManager extends Call.ListenerBase
    }

    /**
     * Determines if there are any ongoing self managed calls for the given package/user.
     * Determines if there are any ongoing self-managed calls for the given package/user.
     * @param packageName The package name to check.
     * @param userHandle The userhandle to check.
     * @param userHandle The {@link UserHandle} to check.
     * @return {@code true} if the app has ongoing calls, or {@code false} otherwise.
     */
    public boolean isInSelfManagedCall(String packageName, UserHandle userHandle) {
        return isInSelfManagedCallCrossUsers(packageName, userHandle, false);
    }

    /**
     * Determines if there are any ongoing self-managed calls for the given package/user (unless
     * hasCrossUsers has been enabled).
     * @param packageName The package name to check.
     * @param userHandle The {@link UserHandle} to check.
     * @param hasCrossUserAccess indicates if calls across all users should be returned.
     * @return {@code true} if the app has ongoing calls, or {@code false} otherwise.
     */
    public boolean isInSelfManagedCallCrossUsers(
            String packageName, UserHandle userHandle, boolean hasCrossUserAccess) {
        return mSelfManagedCallsBeingSetup.stream().anyMatch(c -> c.isSelfManaged()
                && c.getTargetPhoneAccount().getComponentName().getPackageName().equals(packageName)
                && c.getTargetPhoneAccount().getUserHandle().equals(userHandle)) ||
                mCalls.stream().anyMatch(c -> c.isSelfManaged()
                && (!hasCrossUserAccess
                        ? c.getTargetPhoneAccount().getUserHandle().equals(userHandle)
                        : true))
                || mCalls.stream().anyMatch(c -> c.isSelfManaged()
                && c.getTargetPhoneAccount().getComponentName().getPackageName().equals(packageName)
                && c.getTargetPhoneAccount().getUserHandle().equals(userHandle));
                && (!hasCrossUserAccess
                        ? c.getTargetPhoneAccount().getUserHandle().equals(userHandle)
                        : true));
    }

    @VisibleForTesting
+4 −5
Original line number Diff line number Diff line
@@ -2510,19 +2510,18 @@ public class TelecomServiceImpl {
         */
        @Override
        public boolean isInSelfManagedCall(String packageName, UserHandle userHandle,
                String callingPackage) {
                String callingPackage, boolean hasCrossUserAccess) {
            try {
                if (Binder.getCallingUid() != Process.SYSTEM_UID) {
                    throw new SecurityException("Only the system can call this API");
                }
                mContext.enforceCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE,
                        "READ_PRIVILEGED_PHONE_STATE required.");
                enforceInAppCrossUserPermission();

                Log.startSession("TSI.iISMC", Log.getPackageAbbreviation(callingPackage));
                synchronized (mLock) {
                    long token = Binder.clearCallingIdentity();
                    try {
                        return mCallsManager.isInSelfManagedCall(packageName, userHandle);
                        return mCallsManager.isInSelfManagedCallCrossUsers(
                                packageName, userHandle, hasCrossUserAccess);
                    } finally {
                        Binder.restoreCallingIdentity(token);
                    }