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

Commit c4f127bc authored by Evan Chen's avatar Evan Chen Committed by Android (Google) Code Review
Browse files

Merge "CDM Cross App Association Sharing & Device Presence" into main

parents 6c9e4bd1 d41e663f
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -10108,7 +10108,7 @@ package android.companion {
    method public int describeContents();
    method @Nullable public android.companion.AssociatedDevice getAssociatedDevice();
    method @FlaggedApi("android.companion.association_device_icon") @Nullable public android.graphics.drawable.Icon getDeviceIcon();
    method @FlaggedApi("android.companion.association_tag") @Nullable public android.companion.DeviceId getDeviceId();
    method @Nullable public android.companion.DeviceId getDeviceId();
    method @Nullable public android.net.MacAddress getDeviceMacAddress();
    method @Nullable public String getDeviceProfile();
    method @Nullable public CharSequence getDisplayName();
@@ -10187,6 +10187,7 @@ package android.companion {
    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 @FlaggedApi("android.companion.association_verification") @Nullable public android.companion.DeviceId createAndSetDeviceId(int, @Nullable android.companion.DeviceId);
    method @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES) public void detachSystemDataTransport(int) throws android.companion.DeviceNotAssociatedException;
    method public void disableSystemDataSyncForTypes(int, int);
    method @Deprecated public void disassociate(@NonNull String);
@@ -10198,7 +10199,7 @@ package android.companion {
    method @FlaggedApi("android.companion.perm_sync_user_consent") public boolean isPermissionTransferUserConsented(int);
    method @FlaggedApi("android.companion.unpair_associated_device") @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean removeBond(int);
    method public void requestNotificationAccess(android.content.ComponentName);
    method @FlaggedApi("android.companion.association_tag") public void setDeviceId(int, @Nullable android.companion.DeviceId);
    method @Deprecated @FlaggedApi("android.companion.association_verification") public void setDeviceId(int, @Nullable android.companion.DeviceId);
    method @Deprecated @FlaggedApi("android.companion.device_presence") @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void startObservingDevicePresence(@NonNull String) throws android.companion.DeviceNotAssociatedException;
    method @FlaggedApi("android.companion.device_presence") @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void startObservingDevicePresence(@NonNull android.companion.ObservingDevicePresenceRequest);
    method public void startSystemDataTransfer(int, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<java.lang.Void,android.companion.CompanionException>) throws android.companion.DeviceNotAssociatedException;
@@ -10243,7 +10244,7 @@ package android.companion {
  public interface DeviceFilter<D extends android.os.Parcelable> extends android.os.Parcelable {
  }
  @FlaggedApi("android.companion.association_tag") public final class DeviceId implements android.os.Parcelable {
  public final class DeviceId implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public String getCustomId();
    method @Nullable public android.net.MacAddress getMacAddress();
+10 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ package android {
    field public static final String ACCESS_BROADCAST_RADIO = "android.permission.ACCESS_BROADCAST_RADIO";
    field public static final String ACCESS_BROADCAST_RESPONSE_STATS = "android.permission.ACCESS_BROADCAST_RESPONSE_STATS";
    field public static final String ACCESS_CACHE_FILESYSTEM = "android.permission.ACCESS_CACHE_FILESYSTEM";
    field @FlaggedApi("android.companion.association_verification") public static final String ACCESS_COMPANION_INFO = "android.permission.ACCESS_COMPANION_INFO";
    field public static final String ACCESS_CONTEXTUAL_SEARCH = "android.permission.ACCESS_CONTEXTUAL_SEARCH";
    field public static final String ACCESS_CONTEXT_HUB = "android.permission.ACCESS_CONTEXT_HUB";
    field public static final String ACCESS_DRM_CERTIFICATES = "android.permission.ACCESS_DRM_CERTIFICATES";
@@ -3405,6 +3406,7 @@ package android.companion {
    method @RequiresPermission(android.Manifest.permission.ASSOCIATE_COMPANION_DEVICES) public void associate(@NonNull String, @NonNull android.net.MacAddress, @NonNull byte[]);
    method @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES") public boolean canPairWithoutPrompt(@NonNull String, @NonNull String, @NonNull android.os.UserHandle);
    method @NonNull @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES") public java.util.List<android.companion.AssociationInfo> getAllAssociations();
    method @FlaggedApi("android.companion.association_verification") @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_COMPANION_INFO) public android.companion.AssociationInfo getAssociationByDeviceId(@NonNull android.companion.DeviceId);
    method @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES") public boolean isDeviceAssociatedForWifiConnection(@NonNull String, @NonNull android.net.MacAddress, @NonNull android.os.UserHandle);
    method @RequiresPermission(android.Manifest.permission.REQUEST_COMPANION_SELF_MANAGED) public void notifyDeviceAppeared(int);
    method @RequiresPermission(android.Manifest.permission.REQUEST_COMPANION_SELF_MANAGED) public void notifyDeviceDisappeared(int);
@@ -3415,6 +3417,14 @@ package android.companion {
    method public void onAssociationsChanged(@NonNull java.util.List<android.companion.AssociationInfo>);
  }
  @FlaggedApi("android.companion.device_presence") public final class ObservingDevicePresenceRequest implements android.os.Parcelable {
    method @FlaggedApi("android.companion.association_verification") @Nullable public android.companion.DeviceId getDeviceId();
  }
  public static final class ObservingDevicePresenceRequest.Builder {
    method @FlaggedApi("android.companion.association_verification") @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_COMPANION_INFO) public android.companion.ObservingDevicePresenceRequest.Builder setDeviceId(@NonNull android.companion.DeviceId);
  }
}
package android.companion.virtual {
+2 −1
Original line number Diff line number Diff line
@@ -913,12 +913,13 @@ package android.companion {
    method @NonNull public android.companion.AssociationInfo build();
    method @NonNull public android.companion.AssociationInfo.Builder setAssociatedDevice(@Nullable android.companion.AssociatedDevice);
    method @FlaggedApi("android.companion.association_device_icon") @NonNull public android.companion.AssociationInfo.Builder setDeviceIcon(@Nullable android.graphics.drawable.Icon);
    method @FlaggedApi("android.companion.association_tag") @NonNull public android.companion.AssociationInfo.Builder setDeviceId(@Nullable android.companion.DeviceId);
    method @NonNull public android.companion.AssociationInfo.Builder setDeviceId(@Nullable android.companion.DeviceId);
    method @NonNull public android.companion.AssociationInfo.Builder setDeviceMacAddress(@Nullable android.net.MacAddress);
    method @NonNull public android.companion.AssociationInfo.Builder setDeviceProfile(@Nullable String);
    method @NonNull public android.companion.AssociationInfo.Builder setDisplayName(@Nullable CharSequence);
    method @NonNull public android.companion.AssociationInfo.Builder setLastTimeConnected(long);
    method @NonNull public android.companion.AssociationInfo.Builder setNotifyOnDeviceNearby(boolean);
    method @NonNull public android.companion.AssociationInfo.Builder setPackagesToNotify(@Nullable java.util.List<java.lang.String>);
    method @NonNull public android.companion.AssociationInfo.Builder setRevoked(boolean);
    method @NonNull public android.companion.AssociationInfo.Builder setSelfManaged(boolean);
    method @NonNull public android.companion.AssociationInfo.Builder setSystemDataSyncFlags(int);
+40 −9
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.Parcel;
import android.os.Parcelable;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
@@ -85,6 +86,8 @@ public final class AssociationInfo implements Parcelable {
    private final int mSystemDataSyncFlags;
    @Nullable
    private final DeviceId mDeviceId;
    @Nullable
    private final List<String> mPackagesToNotify;

    /**
     * A device icon displayed on a selfManaged association dialog.
@@ -101,7 +104,8 @@ 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) {
            @Nullable Icon deviceIcon, @Nullable DeviceId deviceId,
            @Nullable List<String> packagesToNotify) {
        if (id <= 0) {
            throw new IllegalArgumentException("Association ID should be greater than 0");
        }
@@ -126,6 +130,7 @@ public final class AssociationInfo implements Parcelable {
        mSystemDataSyncFlags = systemDataSyncFlags;
        mDeviceIcon = deviceIcon;
        mDeviceId = deviceId;
        mPackagesToNotify = packagesToNotify;
    }

    /**
@@ -158,7 +163,6 @@ public final class AssociationInfo implements Parcelable {
     * @return the {@link DeviceId} of this association.
     * @see CompanionDeviceManager#setDeviceId(int, DeviceId)
     */
    @FlaggedApi(Flags.FLAG_ASSOCIATION_TAG)
    @Nullable
    public DeviceId getDeviceId() {
        return mDeviceId;
@@ -298,6 +302,16 @@ public final class AssociationInfo implements Parcelable {
        return mDeviceIcon;
    }

    /**
     * @return a list of packages that need to notify for device presence.
     * @hide
     */
    @FlaggedApi(Flags.FLAG_ASSOCIATION_VERIFICATION)
    @Nullable
    public List<String> getPackagesToNotify() {
        return mPackagesToNotify;
    }

    /**
     * Utility method for checking if the association represents a device with the given MAC
     * address.
@@ -368,7 +382,8 @@ public final class AssociationInfo implements Parcelable {
                    mLastTimeConnectedMs == Long.MAX_VALUE
                        ? LAST_TIME_CONNECTED_NONE : new Date(mLastTimeConnectedMs))
                + ", mSystemDataSyncFlags=" + mSystemDataSyncFlags
                + ", mDeviceId='" + mDeviceId
                + ", mDeviceId=" + mDeviceId
                + ", mPackagesToNotify=" + mPackagesToNotify
                + '}';
    }

@@ -393,7 +408,8 @@ public final class AssociationInfo implements Parcelable {
                && Objects.equals(mAssociatedDevice, that.mAssociatedDevice)
                && mSystemDataSyncFlags == that.mSystemDataSyncFlags
                && isSameIcon(mDeviceIcon, that.mDeviceIcon)
                && Objects.equals(mDeviceId, that.mDeviceId);
                && Objects.equals(mDeviceId, that.mDeviceId)
                && Objects.equals(mPackagesToNotify, that.mPackagesToNotify);
    }

    private boolean isSameIcon(Icon iconA, Icon iconB) {
@@ -408,7 +424,7 @@ public final class AssociationInfo implements Parcelable {
        return Objects.hash(mId, mUserId, mPackageName, mDeviceMacAddress, mDisplayName,
                mDeviceProfile, mAssociatedDevice, mSelfManaged, mNotifyOnDeviceNearby, mRevoked,
                mPending, mTimeApprovedMs, mLastTimeConnectedMs, mSystemDataSyncFlags, mDeviceIcon,
                mDeviceId);
                mDeviceId, mPackagesToNotify);
    }

    @Override
@@ -439,12 +455,14 @@ public final class AssociationInfo implements Parcelable {
            dest.writeInt(0);
        }

        if (Flags.associationTag() && mDeviceId != null) {
        if (mDeviceId != null) {
            dest.writeInt(1);
            dest.writeTypedObject(mDeviceId, flags);
        } else {
            dest.writeInt(0);
        }

        dest.writeStringList(mPackagesToNotify);
    }

    private AssociationInfo(@NonNull Parcel in) {
@@ -469,11 +487,12 @@ public final class AssociationInfo implements Parcelable {
            mDeviceIcon = null;
        }
        int deviceId = in.readInt();
        if (Flags.associationTag() && deviceId == 1) {
        if (deviceId == 1) {
            mDeviceId = in.readTypedObject(DeviceId.CREATOR);
        } else {
            mDeviceId = null;
        }
        mPackagesToNotify = in.createStringArrayList();
    }

    @NonNull
@@ -514,6 +533,7 @@ public final class AssociationInfo implements Parcelable {
        private int mSystemDataSyncFlags;
        private Icon mDeviceIcon;
        private DeviceId mDeviceId;
        private List<String> mPackagesToNotify;

        /** @hide */
        @TestApi
@@ -542,6 +562,7 @@ public final class AssociationInfo implements Parcelable {
            mSystemDataSyncFlags = info.mSystemDataSyncFlags;
            mDeviceIcon = info.mDeviceIcon;
            mDeviceId = info.mDeviceId;
            mPackagesToNotify = info.mPackagesToNotify;
        }

        /**
@@ -567,10 +588,10 @@ public final class AssociationInfo implements Parcelable {
            mSystemDataSyncFlags = info.mSystemDataSyncFlags;
            mDeviceIcon = info.mDeviceIcon;
            mDeviceId = info.mDeviceId;
            mPackagesToNotify = info.mPackagesToNotify;
        }

        /** @hide */
        @FlaggedApi(Flags.FLAG_ASSOCIATION_TAG)
        @TestApi
        @NonNull
        public Builder setDeviceId(@Nullable DeviceId deviceId) {
@@ -689,6 +710,15 @@ public final class AssociationInfo implements Parcelable {
            return this;
        }

        /** @hide */
        @TestApi
        @NonNull
        @SuppressLint("MissingGetterMatchingBuilder")
        public Builder setPackagesToNotify(@Nullable List<String> packagesToNotify) {
            mPackagesToNotify = packagesToNotify;
            return this;
        }

        /** @hide */
        @TestApi
        @NonNull
@@ -716,7 +746,8 @@ public final class AssociationInfo implements Parcelable {
                    mLastTimeConnectedMs,
                    mSystemDataSyncFlags,
                    mDeviceIcon,
                    mDeviceId
                    mDeviceId,
                    mPackagesToNotify
            );
        }
    }
+66 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.Manifest.permission.REQUEST_COMPANION_PROFILE_WATCH;
import static android.graphics.drawable.Icon.TYPE_URI;
import static android.graphics.drawable.Icon.TYPE_URI_ADAPTIVE_BITMAP;

import android.Manifest;
import android.annotation.CallbackExecutor;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
@@ -1873,9 +1874,11 @@ public final class CompanionDeviceManager {
     * @param associationId The unique {@link AssociationInfo#getId ID} assigned to the Association
     *                          of the companion device recorded by CompanionDeviceManager.
     * @param deviceId to be used as device identifier to represent the associated device.
     *
     * @deprecated use {@link #createAndSetDeviceId(int, DeviceId)} instead.
     */
    @FlaggedApi(Flags.FLAG_ASSOCIATION_TAG)
    @UserHandleAware
    @FlaggedApi(Flags.FLAG_ASSOCIATION_VERIFICATION)
    @Deprecated
    public void setDeviceId(int associationId, @Nullable DeviceId deviceId) {
        if (mService == null) {
            Log.w(TAG, "CompanionDeviceManager service is not available.");
@@ -1889,6 +1892,67 @@ public final class CompanionDeviceManager {
        }
    }

    /**
     * Returns a new {@link DeviceId} which can be passed to device manufacturers' apps,
     * allowing them to fetch {@link AssociationInfo} or observe device presence for this
     * associated device. This method creates a new object and does not mutate any existing
     * {@link DeviceId}.
     *
     * <p>The system will generate and assign a new, random 128-bit key to this returned
     * {@link DeviceId}. Each call to this method generates a new key, any previously associated
     * key will be obsoleted. Therefore, the returned {@link DeviceId} is the one that contains
     * the newly assigned key and should be used for subsequent operations.
     *
     * <p>This device id also helps the system uniquely identify your device for efficient device
     * management and prevents duplicate entries.
     *
     * <p>WARNING: Do not pass the returned DeviceId to apps you do not trust.
     *
     * @param associationId The unique {@link AssociationInfo#getId} assigned to the Association
     *                          of the companion device recorded by CompanionDeviceManager.
     * @param deviceId to be used as device identifier to represent the associated device.
     *
     * @see AssociationInfo#getDeviceId()
     */
    @FlaggedApi(Flags.FLAG_ASSOCIATION_VERIFICATION)
    @Nullable
    public DeviceId createAndSetDeviceId(int associationId, @Nullable DeviceId deviceId) {
        if (mService == null) {
            Log.w(TAG, "CompanionDeviceManager service is not available.");
            return null;
        }

        try {
            return mService.setDeviceId(associationId, deviceId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns an {@link AssociationInfo} matching the specified device id, or {@code null}
     * if not found or the key in the {@link DeviceId} is invalid.
     *
     * @param deviceId A device id represents a device identifier managed by the companion app.
     *
     * @see #createAndSetDeviceId(int, DeviceId)
     * @hide
     */
    @FlaggedApi(Flags.FLAG_ASSOCIATION_VERIFICATION)
    @UserHandleAware
    @SystemApi
    @RequiresPermission(Manifest.permission.ACCESS_COMPANION_INFO)
    @Nullable
    public AssociationInfo getAssociationByDeviceId(@NonNull DeviceId deviceId) {
        Objects.requireNonNull(deviceId, "DeviceId can not be null.");

        try {
            return mService.getAssociationByDeviceId(mContext.getUserId(), deviceId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    private static class AssociationRequestCallbackProxy extends IAssociationRequestCallback.Stub {
        private final Handler mHandler;
        private final Callback mCallback;
Loading