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

Commit 4d509e0a authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Separate TelecomManager#isInSelfManagedCall APIs

Instead of consolidating the TelecomManager#isInSelfManagedCall APIs
which combine the cross user logic with the ability to also specifiy a
user handle, create two separate APIs to handle this. One will allow the
caller to specify a user handle while the other will allow them to
specify if calls should be verified across all users.

Ensure that if the user handle specified isn't the caller or that
interacting across users is defined in the parameter, that the
permission check is enforced properly. Otherwise, ensure that the user
handle being verified is always the caller.

Bug: 323958718
Bug: 311773409
Test: atest SelfManagedConnectionServiceTest
Change-Id: Ie7096c0a876cca2cf8e1e70cd3ae102127f60197
parent 6041a507
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -13977,7 +13977,8 @@ package android.telecom {
    method @Deprecated public java.util.List<android.telecom.PhoneAccountHandle> getPhoneAccountsForPackage();
    method @Deprecated public java.util.List<android.telecom.PhoneAccountHandle> getPhoneAccountsForPackage();
    method @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public java.util.List<android.telecom.PhoneAccountHandle> getPhoneAccountsSupportingScheme(String);
    method @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public java.util.List<android.telecom.PhoneAccountHandle> getPhoneAccountsSupportingScheme(String);
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean isInEmergencyCall();
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean isInEmergencyCall();
    method @FlaggedApi("com.android.server.telecom.flags.telecom_resolve_hidden_dependencies") @RequiresPermission(allOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public boolean isInSelfManagedCall(@NonNull String, @NonNull android.os.UserHandle, boolean);
    method @FlaggedApi("com.android.server.telecom.flags.telecom_resolve_hidden_dependencies") @RequiresPermission(allOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public boolean isInSelfManagedCall(@NonNull String, @NonNull android.os.UserHandle);
    method @FlaggedApi("com.android.server.telecom.flags.telecom_resolve_hidden_dependencies") @RequiresPermission(allOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public boolean isInSelfManagedCall(@NonNull String, boolean);
    method @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isRinging();
    method @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isRinging();
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setUserSelectedOutgoingPhoneAccount(@Nullable android.telecom.PhoneAccountHandle);
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setUserSelectedOutgoingPhoneAccount(@Nullable android.telecom.PhoneAccountHandle);
    field public static final String ACTION_CURRENT_TTY_MODE_CHANGED = "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
    field public static final String ACTION_CURRENT_TTY_MODE_CHANGED = "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
+1 −1
Original line number Original line Diff line number Diff line
@@ -8155,7 +8155,7 @@ public class NotificationManagerService extends SystemService {
                try {
                try {
                    return mTelecomManager.isInManagedCall()
                    return mTelecomManager.isInManagedCall()
                            || mTelecomManager.isInSelfManagedCall(pkg,
                            || mTelecomManager.isInSelfManagedCall(pkg,
                            UserHandle.getUserHandleForUid(uid), /* hasCrossUserAccess */ true);
                            /* hasCrossUserAccess */ true);
                } catch (IllegalStateException ise) {
                } catch (IllegalStateException ise) {
                    // Telecom is not ready (this is likely early boot), so there are no calls.
                    // Telecom is not ready (this is likely early boot), so there are no calls.
                    return false;
                    return false;
+2 −2
Original line number Original line Diff line number Diff line
@@ -11941,7 +11941,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        // style + self managed call - bypasses block
        // style + self managed call - bypasses block
        when(mTelecomManager.isInSelfManagedCall(
        when(mTelecomManager.isInSelfManagedCall(
                r.getSbn().getPackageName(), r.getUser(), true)).thenReturn(true);
                r.getSbn().getPackageName(), true)).thenReturn(true);
        assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(),
        assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(),
                r.getSbn().getId(), r.getSbn().getTag(), r, false, false)).isTrue();
                r.getSbn().getId(), r.getSbn().getTag(), r, false, false)).isTrue();
@@ -12024,7 +12024,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        // style + self managed call - bypasses block
        // style + self managed call - bypasses block
        mService.clearNotifications();
        mService.clearNotifications();
        reset(mUsageStats);
        reset(mUsageStats);
        when(mTelecomManager.isInSelfManagedCall(r.getSbn().getPackageName(), r.getUser(), true))
        when(mTelecomManager.isInSelfManagedCall(r.getSbn().getPackageName(), true))
                .thenReturn(true);
                .thenReturn(true);
        mService.addEnqueuedNotification(r);
        mService.addEnqueuedNotification(r);
+38 −7
Original line number Original line Diff line number Diff line
@@ -2772,13 +2772,10 @@ public class TelecomManager {
     * calls for a given {@code packageName} and {@code userHandle}.
     * calls for a given {@code packageName} and {@code userHandle}.
     *
     *
     * @param packageName the package name of the app to check calls for.
     * @param packageName the package name of the app to check calls for.
     * @param userHandle the user handle on which to check for calls.
     * @param userHandle the user handle to check calls for.
     * @param detectForAllUsers indicates if calls should be detected across all users. If it is
     *                          set to {@code true}, and the caller has the ability to interact
     *                          across users, the userHandle parameter is disregarded.
     * @return {@code true} if there are ongoing calls, {@code false} otherwise.
     * @return {@code true} if there are ongoing calls, {@code false} otherwise.
     * @throws SecurityException if detectForAllUsers is true or userHandle is not the calling user
     * @throws SecurityException if the userHandle is not the calling user and the caller does not
     * and the caller does not grant the ability to interact across users.
     * grant the ability to interact across users.
     * @hide
     * @hide
     */
     */
    @SystemApi
    @SystemApi
@@ -2786,11 +2783,45 @@ public class TelecomManager {
    @RequiresPermission(allOf = {Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
    @RequiresPermission(allOf = {Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
            Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
            Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
    public boolean isInSelfManagedCall(@NonNull String packageName,
    public boolean isInSelfManagedCall(@NonNull String packageName,
            @NonNull UserHandle userHandle, boolean detectForAllUsers) {
            @NonNull UserHandle userHandle) {
        ITelecomService service = getTelecomService();
        ITelecomService service = getTelecomService();
        if (service != null) {
        if (service != null) {
            try {
            try {
                return service.isInSelfManagedCall(packageName, userHandle,
                return service.isInSelfManagedCall(packageName, userHandle,
                        mContext.getOpPackageName(), false);
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException isInSelfManagedCall: " + e);
                e.rethrowFromSystemServer();
                return false;
            }
        } else {
            throw new IllegalStateException("Telecom service is not present");
        }
    }

    /**
     * Determines whether there are any ongoing {@link PhoneAccount#CAPABILITY_SELF_MANAGED}
     * calls for a given {@code packageName} amongst all users, given that detectForAllUsers is true
     * and the caller has the ability to interact across users. If detectForAllUsers isn't enabled,
     * the calls will be checked against the caller.
     *
     * @param packageName the package name of the app to check calls for.
     * @param detectForAllUsers indicates if calls should be detected across all users.
     * @return {@code true} if there are ongoing calls, {@code false} otherwise.
     * @throws SecurityException if detectForAllUsers is true and the caller does not grant the
     * ability to interact across users.
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_TELECOM_RESOLVE_HIDDEN_DEPENDENCIES)
    @RequiresPermission(allOf = {Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
            Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
    public boolean isInSelfManagedCall(@NonNull String packageName,
            boolean detectForAllUsers) {
        ITelecomService service = getTelecomService();
        if (service != null) {
            try {
                return service.isInSelfManagedCall(packageName, null,
                        mContext.getOpPackageName(), detectForAllUsers);
                        mContext.getOpPackageName(), detectForAllUsers);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException isInSelfManagedCall: " + e);
                Log.e(TAG, "RemoteException isInSelfManagedCall: " + e);