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

Commit 456741b7 authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

TelecomManager consolidate isInSelfManagedCall.

As per API feedback, consolidate TelecomManager#isInSelfManagedCall into
a single API which only takes a UserHandle and disregard the
hasCrossUserAccess parameter. Instead, the caller can specify
UserHandle.ALL in order to indicate that self managed calls across all
users should be checked.

Bug: 327029478
Bug: 311773409
Test: atest SelfManagedConnectionServiceTest
Change-Id: I89552f9bf4c1fce0f2477715ef79a3d56eeae922
parent 09c82ab9
Loading
Loading
Loading
Loading
+1 −13
Original line number Diff line number Diff line
@@ -4774,19 +4774,7 @@ public class CallsManager extends Call.ListenerBase
     * @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) {
        boolean hasCrossUserAccess = userHandle.equals(UserHandle.ALL);
        return mSelfManagedCallsBeingSetup.stream().anyMatch(c -> c.isSelfManaged()
                && c.getTargetPhoneAccount().getComponentName().getPackageName().equals(packageName)
                && (!hasCrossUserAccess
+4 −12
Original line number Diff line number Diff line
@@ -2563,34 +2563,26 @@ public class TelecomServiceImpl {
         * @param packageName    the package name of the app to check calls for.
         * @param userHandle     the user handle on which to check for calls.
         * @param callingPackage The caller's package name.
         * @param detectForAllUsers indicates if calls should be detected across all users. If the
         *                          caller does not have the ability to interact across users, get
         *                          managed calls for the caller instead.
         * @return {@code true} if there are ongoing calls, {@code false} otherwise.
         */
        @Override
        public boolean isInSelfManagedCall(String packageName, UserHandle userHandle,
                String callingPackage, boolean detectForAllUsers) {
                String callingPackage) {
            try {
                mContext.enforceCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE,
                        "READ_PRIVILEGED_PHONE_STATE required.");
                // Ensure that the caller has the INTERACT_ACROSS_USERS permission if it's trying
                // to access calls that don't belong to it.
                if (detectForAllUsers || (userHandle != null
                        && !Binder.getCallingUserHandle().equals(userHandle))) {
                if (!Binder.getCallingUserHandle().equals(userHandle)) {
                    enforceInAppCrossUserPermission();
                } else {
                    // If INTERACT_ACROSS_USERS doesn't need to be enforced, ensure that the user
                    // being checked is the caller.
                    userHandle = Binder.getCallingUserHandle();
                }

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