Resolve API feedback TelecomManager#isInSelfManagedCall

As part of the mainline work, feedback has given to change the
hasCrossUserAccess param to better match the description. The
INTERACT_ACROSS_USERS permission has also been made an optional
parameter which is enforced when the user handle passed in doesn't match
the calling user or when the detectForAllUsers parameter is set to true.

Bug: 323958718
Bug: 311773409
Test: atest SelfManagedConnectionServiceTest
Change-Id: Ifcac2a6c971c604ec75f49979fa4db9b92d8716c
diff --git a/src/com/android/server/telecom/TelecomServiceImpl.java b/src/com/android/server/telecom/TelecomServiceImpl.java
index b954588..9ebe484 100644
--- a/src/com/android/server/telecom/TelecomServiceImpl.java
+++ b/src/com/android/server/telecom/TelecomServiceImpl.java
@@ -2506,22 +2506,28 @@
          * @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 it is
+         *                          set to true, the userHandle parameter is disregarded.
          * @return {@code true} if there are ongoing calls, {@code false} otherwise.
          */
         @Override
         public boolean isInSelfManagedCall(String packageName, UserHandle userHandle,
-                String callingPackage, boolean hasCrossUserAccess) {
+                String callingPackage, boolean detectForAllUsers) {
             try {
                 mContext.enforceCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE,
                         "READ_PRIVILEGED_PHONE_STATE required.");
-                enforceInAppCrossUserPermission();
+                // 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 || !Binder.getCallingUserHandle().equals(userHandle)) {
+                    enforceInAppCrossUserPermission();
+                }
 
                 Log.startSession("TSI.iISMC", Log.getPackageAbbreviation(callingPackage));
                 synchronized (mLock) {
                     long token = Binder.clearCallingIdentity();
                     try {
                         return mCallsManager.isInSelfManagedCallCrossUsers(
-                                packageName, userHandle, hasCrossUserAccess);
+                                packageName, userHandle, detectForAllUsers);
                     } finally {
                         Binder.restoreCallingIdentity(token);
                     }