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

Commit 05a2e365 authored by Guojing Yuan's avatar Guojing Yuan Committed by Android (Google) Code Review
Browse files

Merge "[Perm Sync] Add an API for the companion app to get the perm sync consent" into main

parents 6d596d2b 8b5928ed
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9676,6 +9676,7 @@ package android.companion {
    method @Deprecated @NonNull public java.util.List<java.lang.String> getAssociations();
    method @NonNull public java.util.List<android.companion.AssociationInfo> getMyAssociations();
    method @Deprecated public boolean hasNotificationAccess(android.content.ComponentName);
    method @FlaggedApi("android.companion.perm_sync_user_consent") public boolean isPermissionTransferUserConsented(int);
    method public void requestNotificationAccess(android.content.ComponentName);
    method @FlaggedApi("android.companion.association_tag") public void setAssociationTag(int, @NonNull String);
    method @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void startObservingDevicePresence(@NonNull String) throws android.companion.DeviceNotAssociatedException;
+30 −0
Original line number Diff line number Diff line
@@ -1357,6 +1357,36 @@ public final class CompanionDeviceManager {
        }
    }

    /**
     * Return the current state of consent for permission transfer for the association.
     * True if the user has allowed permission transfer for the association, false otherwise.
     *
     * <p>
     * Note: The initial user consent is collected via
     * {@link #buildPermissionTransferUserConsentIntent(int) a permission transfer user consent dialog}.
     * After the user has made their initial selection, they can toggle the permission transfer
     * feature in the settings.
     * This method always returns the state of the toggle setting.
     * </p>
     *
     * @param associationId The unique {@link AssociationInfo#getId ID} assigned to the association
     *                      of the companion device recorded by CompanionDeviceManager
     * @return True if the user has consented to the permission transfer, or false otherwise.
     * @throws DeviceNotAssociatedException Exception if the companion device is not associated with
     *                                      the user or the calling app.
     */
    @UserHandleAware
    @FlaggedApi(Flags.FLAG_PERM_SYNC_USER_CONSENT)
    public boolean isPermissionTransferUserConsented(int associationId) {
        try {
            return mService.isPermissionTransferUserConsented(mContext.getOpPackageName(),
                    mContext.getUserId(), associationId);
        } catch (RemoteException e) {
            ExceptionUtils.propagateIfInstanceOf(e.getCause(), DeviceNotAssociatedException.class);
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Start system data transfer which has been previously approved by the user.
     *
+2 −0
Original line number Diff line number Diff line
@@ -97,6 +97,8 @@ interface ICompanionDeviceManager {
    PendingIntent buildPermissionTransferUserConsentIntent(String callingPackage, int userId,
        int associationId);

    boolean isPermissionTransferUserConsented(String callingPackage, int userId, int associationId);

    void startSystemDataTransfer(String packageName, int userId, int associationId,
        in ISystemDataTransferCallback callback);

+7 −0
Original line number Diff line number Diff line
@@ -27,3 +27,10 @@ flag {
    description: "Enable device presence APIs"
    bug: "283000075"
}

flag {
    name: "perm_sync_user_consent"
    namespace: "companion"
    description: "Expose perm sync user consent API"
    bug: "309528663"
}
 No newline at end of file
+7 −0
Original line number Diff line number Diff line
@@ -832,6 +832,13 @@ public class CompanionDeviceManagerService extends SystemService {
                    packageName, userId, associationId);
        }

        @Override
        public boolean isPermissionTransferUserConsented(String packageName, int userId,
                int associationId) {
            return mSystemDataTransferProcessor.isPermissionTransferUserConsented(packageName,
                    userId, associationId);
        }

        @Override
        public void startSystemDataTransfer(String packageName, int userId, int associationId,
                ISystemDataTransferCallback callback) {
Loading