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

Commit bed16edd authored by Raphael Kim's avatar Raphael Kim Committed by Android (Google) Code Review
Browse files

Merge "[CDM] Move transport flags from attachSystemDataTransport to AssociationInfo." into main

parents 9694c7eb 8fa788fa
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -939,6 +939,7 @@ package android.companion {
    method @NonNull public android.companion.AssociationInfo.Builder setSelfManaged(boolean);
    method @NonNull public android.companion.AssociationInfo.Builder setSystemDataSyncFlags(int);
    method @NonNull public android.companion.AssociationInfo.Builder setTimeApproved(long);
    method @NonNull public android.companion.AssociationInfo.Builder setTransportFlags(int);
  }

  public final class AssociationRequest implements android.os.Parcelable {
+30 −3
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ public final class AssociationInfo implements Parcelable {
     */
    private final long mLastTimeConnectedMs;
    private final int mSystemDataSyncFlags;
    private final int mTransportFlags;
    @Nullable
    private final DeviceId mDeviceId;
    @Nullable
@@ -104,7 +105,7 @@ public final class AssociationInfo implements Parcelable {
            @Nullable String deviceProfile, @Nullable AssociatedDevice associatedDevice,
            boolean selfManaged, boolean notifyOnDeviceNearby, boolean revoked, boolean pending,
            long timeApprovedMs, long lastTimeConnectedMs, int systemDataSyncFlags,
            @Nullable Icon deviceIcon, @Nullable DeviceId deviceId,
            int transportFlags, @Nullable Icon deviceIcon, @Nullable DeviceId deviceId,
            @Nullable List<String> packagesToNotify) {
        if (id <= 0) {
            throw new IllegalArgumentException("Association ID should be greater than 0");
@@ -128,6 +129,7 @@ public final class AssociationInfo implements Parcelable {
        mTimeApprovedMs = timeApprovedMs;
        mLastTimeConnectedMs = lastTimeConnectedMs;
        mSystemDataSyncFlags = systemDataSyncFlags;
        mTransportFlags = transportFlags;
        mDeviceIcon = deviceIcon;
        mDeviceId = deviceId;
        mPackagesToNotify = packagesToNotify;
@@ -288,6 +290,14 @@ public final class AssociationInfo implements Parcelable {
        return mSystemDataSyncFlags;
    }

    /**
     * @return Flags to be used when attaching a new transport for this association.
     * @hide
     */
    public int getTransportFlags() {
        return mTransportFlags;
    }

    /**
     * Get the device icon of the associated device. The device icon represents the device type.
     *
@@ -382,6 +392,7 @@ public final class AssociationInfo implements Parcelable {
                    mLastTimeConnectedMs == Long.MAX_VALUE
                        ? LAST_TIME_CONNECTED_NONE : new Date(mLastTimeConnectedMs))
                + ", mSystemDataSyncFlags=" + mSystemDataSyncFlags
                + ", mTransportFlags=" + mTransportFlags
                + ", mDeviceId=" + mDeviceId
                + ", mPackagesToNotify=" + mPackagesToNotify
                + '}';
@@ -407,6 +418,7 @@ public final class AssociationInfo implements Parcelable {
                && Objects.equals(mDeviceProfile, that.mDeviceProfile)
                && Objects.equals(mAssociatedDevice, that.mAssociatedDevice)
                && mSystemDataSyncFlags == that.mSystemDataSyncFlags
                && mTransportFlags == that.mTransportFlags
                && isSameIcon(mDeviceIcon, that.mDeviceIcon)
                && Objects.equals(mDeviceId, that.mDeviceId)
                && Objects.equals(mPackagesToNotify, that.mPackagesToNotify);
@@ -423,8 +435,8 @@ public final class AssociationInfo implements Parcelable {
    public int hashCode() {
        return Objects.hash(mId, mUserId, mPackageName, mDeviceMacAddress, mDisplayName,
                mDeviceProfile, mAssociatedDevice, mSelfManaged, mNotifyOnDeviceNearby, mRevoked,
                mPending, mTimeApprovedMs, mLastTimeConnectedMs, mSystemDataSyncFlags, mDeviceIcon,
                mDeviceId, mPackagesToNotify);
                mPending, mTimeApprovedMs, mLastTimeConnectedMs, mSystemDataSyncFlags,
                mTransportFlags, mDeviceIcon, mDeviceId, mPackagesToNotify);
    }

    @Override
@@ -448,6 +460,7 @@ public final class AssociationInfo implements Parcelable {
        dest.writeLong(mTimeApprovedMs);
        dest.writeLong(mLastTimeConnectedMs);
        dest.writeInt(mSystemDataSyncFlags);
        dest.writeInt(mTransportFlags);
        if (Flags.associationDeviceIcon() && mDeviceIcon != null) {
            dest.writeInt(1);
            mDeviceIcon.writeToParcel(dest, flags);
@@ -480,6 +493,7 @@ public final class AssociationInfo implements Parcelable {
        mTimeApprovedMs = in.readLong();
        mLastTimeConnectedMs = in.readLong();
        mSystemDataSyncFlags = in.readInt();
        mTransportFlags = in.readInt();
        int deviceIcon = in.readInt();
        if (Flags.associationDeviceIcon() && deviceIcon == 1) {
            mDeviceIcon = Icon.CREATOR.createFromParcel(in);
@@ -531,6 +545,7 @@ public final class AssociationInfo implements Parcelable {
        private long mTimeApprovedMs = System.currentTimeMillis();
        private long mLastTimeConnectedMs = Long.MAX_VALUE; // Never connected.
        private int mSystemDataSyncFlags = -1; // By default, all system data sync is enabled.
        private int mTransportFlags;
        private Icon mDeviceIcon;
        private DeviceId mDeviceId;
        private List<String> mPackagesToNotify;
@@ -560,6 +575,7 @@ public final class AssociationInfo implements Parcelable {
            mTimeApprovedMs = info.mTimeApprovedMs;
            mLastTimeConnectedMs = info.mLastTimeConnectedMs;
            mSystemDataSyncFlags = info.mSystemDataSyncFlags;
            mTransportFlags = info.mTransportFlags;
            mDeviceIcon = info.mDeviceIcon;
            mDeviceId = info.mDeviceId;
            mPackagesToNotify = info.mPackagesToNotify;
@@ -586,6 +602,7 @@ public final class AssociationInfo implements Parcelable {
            mTimeApprovedMs = info.mTimeApprovedMs;
            mLastTimeConnectedMs = info.mLastTimeConnectedMs;
            mSystemDataSyncFlags = info.mSystemDataSyncFlags;
            mTransportFlags = info.mTransportFlags;
            mDeviceIcon = info.mDeviceIcon;
            mDeviceId = info.mDeviceId;
            mPackagesToNotify = info.mPackagesToNotify;
@@ -700,6 +717,15 @@ public final class AssociationInfo implements Parcelable {
            return this;
        }

        /** @hide */
        @TestApi
        @NonNull
        @SuppressLint("MissingGetterMatchingBuilder")
        public Builder setTransportFlags(int flags) {
            mTransportFlags = flags;
            return this;
        }

        /** @hide */
        @TestApi
        @NonNull
@@ -745,6 +771,7 @@ public final class AssociationInfo implements Parcelable {
                    mTimeApprovedMs,
                    mLastTimeConnectedMs,
                    mSystemDataSyncFlags,
                    mTransportFlags,
                    mDeviceIcon,
                    mDeviceId,
                    mPackagesToNotify
+2 −70
Original line number Diff line number Diff line
@@ -286,23 +286,6 @@ public final class CompanionDeviceManager {
     */
    public static final int MESSAGE_ONEWAY_TO_WEARABLE = 0x43847987; // +TOW


    /** @hide */
    @IntDef(flag = true, prefix = { "TRANSPORT_FLAG_" }, value = {
            TRANSPORT_FLAG_EXTEND_PATCH_DIFF,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface TransportFlags {}

    /**
     * A security flag that allows transports to be attached to devices that may be more vulnerable
     * due to infrequent updates. Can only be used for associations with
     * {@link AssociationRequest#DEVICE_PROFILE_WEARABLE_SENSING} device profile.
     *
     * @hide
     */
    public static final int TRANSPORT_FLAG_EXTEND_PATCH_DIFF = 1;

    /**
     * Callback for applications to receive updates about and the outcome of
     * {@link AssociationRequest} issued via {@code associate()} call.
@@ -1511,52 +1494,7 @@ public final class CompanionDeviceManager {
            }

            try {
                final Transport transport = new Transport(associationId, in, out, 0);
                mTransports.put(associationId, transport);
                transport.start();
            } catch (IOException e) {
                throw new RuntimeException("Failed to attach transport", e);
            }
        }
    }

    /**
     * Attach a bidirectional communication stream to be used as a transport channel for
     * transporting system data between associated devices. Flags can be provided to further
     * customize the behavior of the transport.
     *
     * @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.
     * @param flags Flags to customize transport behavior.
     * @throws DeviceNotAssociatedException Thrown if the associationId was not previously
     * associated with this app.
     *
     * @see #buildPermissionTransferUserConsentIntent(int)
     * @see #startSystemDataTransfer(int, Executor, OutcomeReceiver)
     * @see #detachSystemDataTransport(int)
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES)
    public void attachSystemDataTransport(int associationId,
            @NonNull InputStream in,
            @NonNull OutputStream out,
            @TransportFlags int flags) throws DeviceNotAssociatedException {
        if (mService == null) {
            Log.w(TAG, "CompanionDeviceManager service is not available.");
            return;
        }

        synchronized (mTransports) {
            if (mTransports.contains(associationId)) {
                detachSystemDataTransport(associationId);
            }

            try {
                final Transport transport = new Transport(associationId, in, out, flags);
                final Transport transport = new Transport(associationId, in, out);
                mTransports.put(associationId, transport);
                transport.start();
            } catch (IOException e) {
@@ -2098,7 +2036,6 @@ public final class CompanionDeviceManager {
        private final int mAssociationId;
        private final InputStream mRemoteIn;
        private final OutputStream mRemoteOut;
        private final int mFlags;

        private InputStream mLocalIn;
        private OutputStream mLocalOut;
@@ -2106,14 +2043,9 @@ public final class CompanionDeviceManager {
        private volatile boolean mStopped;

        Transport(int associationId, InputStream remoteIn, OutputStream remoteOut) {
            this(associationId, remoteIn, remoteOut, 0);
        }

        Transport(int associationId, InputStream remoteIn, OutputStream remoteOut, int flags) {
            mAssociationId = associationId;
            mRemoteIn = remoteIn;
            mRemoteOut = remoteOut;
            mFlags = flags;
        }

        public void start() throws IOException {
@@ -2130,7 +2062,7 @@ public final class CompanionDeviceManager {

            try {
                mService.attachSystemDataTransport(mContext.getOpPackageName(),
                        mContext.getUserId(), mAssociationId, remoteFd, mFlags);
                        mContext.getUserId(), mAssociationId, remoteFd);
            } catch (RemoteException e) {
                throw new IOException("Failed to configure transport", e);
            }
+1 −1
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ interface ICompanionDeviceManager {
        in ISystemDataTransferCallback callback);

    @EnforcePermission("DELIVER_COMPANION_MESSAGES")
    void attachSystemDataTransport(String packageName, int userId, int associationId, in ParcelFileDescriptor fd, int flags);
    void attachSystemDataTransport(String packageName, int userId, int associationId, in ParcelFileDescriptor fd);

    @EnforcePermission("DELIVER_COMPANION_MESSAGES")
    void detachSystemDataTransport(String packageName, int userId, int associationId);
+2 −2
Original line number Diff line number Diff line
@@ -594,10 +594,10 @@ public class CompanionDeviceManagerService extends SystemService {
        @Override
        @EnforcePermission(DELIVER_COMPANION_MESSAGES)
        public void attachSystemDataTransport(String packageName, int userId, int associationId,
                                              ParcelFileDescriptor fd, int flags) {
                                              ParcelFileDescriptor fd) {
            attachSystemDataTransport_enforcePermission();

            mTransportManager.attachSystemDataTransport(associationId, fd, flags);
            mTransportManager.attachSystemDataTransport(associationId, fd);
        }

        @Override
Loading