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

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

Merge "Make CDM system data transfer APIs public"

parents 2a5a9434 45d8a3f5
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -9270,8 +9270,10 @@ package android.companion {
    method @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES") public void addOnAssociationsChangedListener(@NonNull java.util.concurrent.Executor, @NonNull android.companion.CompanionDeviceManager.OnAssociationsChangedListener);
    method @RequiresPermission(anyOf={android.Manifest.permission.REQUEST_COMPANION_PROFILE_WATCH, android.Manifest.permission.REQUEST_COMPANION_PROFILE_COMPUTER, android.Manifest.permission.REQUEST_COMPANION_PROFILE_APP_STREAMING, android.Manifest.permission.REQUEST_COMPANION_PROFILE_AUTOMOTIVE_PROJECTION}, conditional=true) public void associate(@NonNull android.companion.AssociationRequest, @NonNull android.companion.CompanionDeviceManager.Callback, @Nullable android.os.Handler);
    method @RequiresPermission(anyOf={android.Manifest.permission.REQUEST_COMPANION_PROFILE_WATCH, android.Manifest.permission.REQUEST_COMPANION_PROFILE_COMPUTER, android.Manifest.permission.REQUEST_COMPANION_PROFILE_APP_STREAMING, android.Manifest.permission.REQUEST_COMPANION_PROFILE_AUTOMOTIVE_PROJECTION}, conditional=true) public void associate(@NonNull android.companion.AssociationRequest, @NonNull java.util.concurrent.Executor, @NonNull android.companion.CompanionDeviceManager.Callback);
    method @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES) public void attachSystemDataTransport(int, @NonNull java.io.InputStream, @NonNull java.io.OutputStream) throws android.companion.DeviceNotAssociatedException;
    method @Nullable public android.content.IntentSender buildAssociationCancellationIntent();
    method @Nullable public android.content.IntentSender buildPermissionTransferUserConsentIntent(int) throws android.companion.DeviceNotAssociatedException;
    method @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES) public void detachSystemDataTransport(int) throws android.companion.DeviceNotAssociatedException;
    method public void disableSystemDataSync(int, int);
    method @Deprecated public void disassociate(@NonNull String);
    method public void disassociate(int);
@@ -9283,6 +9285,7 @@ package android.companion {
    method @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES") public void removeOnAssociationsChangedListener(@NonNull android.companion.CompanionDeviceManager.OnAssociationsChangedListener);
    method public void requestNotificationAccess(android.content.ComponentName);
    method @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void startObservingDevicePresence(@NonNull String) throws android.companion.DeviceNotAssociatedException;
    method public void startSystemDataTransfer(int, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<java.lang.Void,android.companion.CompanionException>) throws android.companion.DeviceNotAssociatedException;
    method @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void stopObservingDevicePresence(@NonNull String) throws android.companion.DeviceNotAssociatedException;
    field public static final String EXTRA_ASSOCIATION = "android.companion.extra.ASSOCIATION";
    field @Deprecated public static final String EXTRA_DEVICE = "android.companion.extra.DEVICE";
@@ -9308,6 +9311,8 @@ package android.companion {
  public abstract class CompanionDeviceService extends android.app.Service {
    ctor public CompanionDeviceService();
    method @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES) public final void attachSystemDataTransport(int, @NonNull java.io.InputStream, @NonNull java.io.OutputStream) throws android.companion.DeviceNotAssociatedException;
    method @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES) public final void detachSystemDataTransport(int) throws android.companion.DeviceNotAssociatedException;
    method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent);
    method @Deprecated @MainThread public void onDeviceAppeared(@NonNull String);
    method @MainThread public void onDeviceAppeared(@NonNull android.companion.AssociationInfo);
@@ -9316,6 +9321,9 @@ package android.companion {
    field public static final String SERVICE_INTERFACE = "android.companion.CompanionDeviceService";
  }
  public class CompanionException extends java.lang.RuntimeException {
  }
  public interface DeviceFilter<D extends android.os.Parcelable> extends android.os.Parcelable {
  }
+52 −25
Original line number Diff line number Diff line
@@ -924,14 +924,25 @@ public final class CompanionDeviceManager {
        Log.w(LOG_TAG, "dispatchMessage replaced by attachSystemDataTransport");
    }

    /** {@hide} */
    /**
     * Attach a bidirectional communication stream to be used as a transport channel for
     * transporting system data between associated devices.
     *
     * @param associationId id of the associated device.
     * @param in Already connected stream of data incoming from remote
     *           associated device.
     * @param out Already connected stream of data outgoing to remote associated
     *            device.
     * @throws DeviceNotAssociatedException Thrown if the associationId was not previously
     * associated with this app.
     *
     * @see #buildPermissionTransferUserConsentIntent(int)
     * @see #startSystemDataTransfer(int, Executor, OutcomeReceiver)
     * @see #detachSystemDataTransport(int)
     */
    @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES)
    public void attachSystemDataTransport(int associationId, @NonNull InputStream in,
            @NonNull OutputStream out) throws DeviceNotAssociatedException {
        if (!FeatureUtils.isPermSyncEnabled()) {
            Log.e(LOG_TAG, "Calling attachSystemDataTransport, but perm sync is disabled.");
            return;
        }
        synchronized (mTransports) {
            if (mTransports.contains(associationId)) {
                detachSystemDataTransport(associationId);
@@ -947,14 +958,19 @@ public final class CompanionDeviceManager {
        }
    }

    /** {@hide} */
    /**
     * Detach the transport channel that's previously attached for the associated device. The system
     * will stop transferring any system data when this method is called.
     *
     * @param associationId id of the associated device.
     * @throws DeviceNotAssociatedException Thrown if the associationId was not previously
     * associated with this app.
     *
     * @see #attachSystemDataTransport(int, InputStream, OutputStream)
     */
    @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES)
    public void detachSystemDataTransport(int associationId)
            throws DeviceNotAssociatedException {
        if (!FeatureUtils.isPermSyncEnabled()) {
            Log.e(LOG_TAG, "Calling detachSystemDataTransport, but perm sync is disabled.");
            return;
        }
        synchronized (mTransports) {
            final Transport transport = mTransports.get(associationId);
            if (transport != null) {
@@ -1044,28 +1060,33 @@ public final class CompanionDeviceManager {
     *
     * <p>Only the companion app which owns the association can call this method. Otherwise a null
     * IntentSender will be returned from this method and an error will be logged.
     * The The app should launch the {@link Activity} in the returned {@code intentSender}
     * The app should launch the {@link Activity} in the returned {@code intentSender}
     * {@link IntentSender} by calling
     * {@link Activity#startIntentSenderForResult(IntentSender, int, Intent, int, int, int)}.</p>
     *
     * <p>The permission transfer doesn't happen immediately after the call or user consented.
     * The app needs to trigger the system data transfer manually by calling
     * {@code #startSystemDataTransfer(int)}, when it confirms the communication channel between
     * the two devices is established.</p>
     * <p>The permission transfer doesn't happen immediately after the call or when the user
     * consents. The app needs to call
     * {@link #attachSystemDataTransport(int, InputStream, OutputStream)} to attach a transport
     * channel and
     * {@link #startSystemDataTransfer(int, Executor, OutcomeReceiver)} to trigger the system data
     * transfer}.</p>
     *
     * @param associationId The unique {@link AssociationInfo#getId ID} assigned to the association
     *                      of the companion device recorded by CompanionDeviceManager
     * @return An {@link IntentSender} that the app should use to launch the UI for
     *         the user to confirm the system data transfer request.
     *
     * @see #attachSystemDataTransport(int, InputStream, OutputStream)
     * @see #startSystemDataTransfer(int, Executor, OutcomeReceiver)
     */
    @UserHandleAware
    @Nullable
    public IntentSender buildPermissionTransferUserConsentIntent(int associationId)
            throws DeviceNotAssociatedException {
        if (!FeatureUtils.isPermSyncEnabled()) {
            Log.e(LOG_TAG, "Calling buildPermissionTransferUserConsentIntent,"
                    + " but perm sync is disabled.");
            return null;
            throw new UnsupportedOperationException("Calling"
                    + " buildPermissionTransferUserConsentIntent, but this API is disabled by the"
                    + " system.");
        }
        try {
            PendingIntent pendingIntent = mService.buildPermissionTransferUserConsentIntent(
@@ -1100,8 +1121,8 @@ public final class CompanionDeviceManager {
    @UserHandleAware
    public void startSystemDataTransfer(int associationId) throws DeviceNotAssociatedException {
        if (!FeatureUtils.isPermSyncEnabled()) {
            Log.e(LOG_TAG, "Calling startSystemDataTransfer, but perm sync is disabled.");
            return;
            throw new UnsupportedOperationException("Calling startSystemDataTransfer, but this API"
                    + " is disabled by the system.");
        }
        try {
            mService.startSystemDataTransfer(mContext.getOpPackageName(), mContext.getUserId(),
@@ -1115,17 +1136,19 @@ public final class CompanionDeviceManager {
    /**
     * Start system data transfer which has been previously approved by the user.
     *
     * <p>Before calling this method, the app needs to make sure there's a communication channel
     * between two devices, and has prompted user consent dialogs built by one of these methods:
     * {@link #buildPermissionTransferUserConsentIntent(int)}.
     * The transfer may fail if the communication channel is disconnected during the transfer.</p>
     * <p>Before calling this method, the app needs to make sure
     * {@link #attachSystemDataTransport(int, InputStream, OutputStream) the transport channel is
     * attached}, and
     * {@link #buildPermissionTransferUserConsentIntent(int) the user consent dialog has prompted to
     * the user}.
     * The transfer will fail if the transport channel is disconnected or
     * {@link #detachSystemDataTransport(int) detached} during the transfer.</p>
     *
     * @param associationId The unique {@link AssociationInfo#getId ID} assigned to the Association
     *                      of the companion device recorded by CompanionDeviceManager
     * @param executor The executor which will be used to invoke the result callback.
     * @param result The callback to notify the app of the result of the system data transfer.
     * @throws DeviceNotAssociatedException Exception if the companion device is not associated
     * @hide
     */
    @UserHandleAware
    public void startSystemDataTransfer(
@@ -1133,6 +1156,10 @@ public final class CompanionDeviceManager {
            @NonNull Executor executor,
            @NonNull OutcomeReceiver<Void, CompanionException> result)
            throws DeviceNotAssociatedException {
        if (!FeatureUtils.isPermSyncEnabled()) {
            throw new UnsupportedOperationException("Calling startSystemDataTransfer, but this API"
                    + " is disabled by the system.");
        }
        try {
            mService.startSystemDataTransfer(mContext.getOpPackageName(), mContext.getUserId(),
                    associationId, new SystemDataTransferCallbackProxy(executor, result));
+0 −2
Original line number Diff line number Diff line
@@ -216,7 +216,6 @@ public abstract class CompanionDeviceService extends Service {
     *            associated device
     * @param out already connected stream of data outgoing to remote associated
     *            device
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES)
    public final void attachSystemDataTransport(int associationId, @NonNull InputStream in,
@@ -232,7 +231,6 @@ public abstract class CompanionDeviceService extends Service {
     * through {@link #attachSystemDataTransport}.
     *
     * @param associationId id of the associated device
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES)
    public final void detachSystemDataTransport(int associationId)
+0 −2
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@ import android.annotation.NonNull;
/**
 * {@code CompanionException} can be thrown during the companion system data
 * transfer process.
 *
 * @hide
 */
public class CompanionException extends RuntimeException {
    /** @hide */