Loading core/api/current.txt +3 −0 Original line number Diff line number Diff line Loading @@ -9530,6 +9530,7 @@ package android.companion { method @Nullable public CharSequence getDisplayName(); method public int getId(); method public int getSystemDataSyncFlags(); method @Nullable public String getTag(); method public void writeToParcel(@NonNull android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator<android.companion.AssociationInfo> CREATOR; } Loading Loading @@ -9599,6 +9600,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 public void clearAssociationTag(int); 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); Loading @@ -9608,6 +9610,7 @@ package android.companion { method @NonNull public java.util.List<android.companion.AssociationInfo> getMyAssociations(); method @Deprecated public boolean hasNotificationAccess(android.content.ComponentName); method public void requestNotificationAccess(android.content.ComponentName); method 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; 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; core/java/android/companion/AssociationInfo.java +34 −5 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ public final class AssociationInfo implements Parcelable { private final boolean mSelfManaged; private final boolean mNotifyOnDeviceNearby; private final int mSystemDataSyncFlags; private final String mTag; /** * Indicates that the association has been revoked (removed), but we keep the association Loading @@ -78,10 +79,11 @@ public final class AssociationInfo implements Parcelable { * @hide */ public AssociationInfo(int id, @UserIdInt int userId, @NonNull String packageName, @Nullable MacAddress macAddress, @Nullable CharSequence displayName, @Nullable String deviceProfile, @Nullable AssociatedDevice associatedDevice, boolean selfManaged, boolean notifyOnDeviceNearby, boolean revoked, long timeApprovedMs, long lastTimeConnectedMs, int systemDataSyncFlags) { @Nullable String tag, @Nullable MacAddress macAddress, @Nullable CharSequence displayName, @Nullable String deviceProfile, @Nullable AssociatedDevice associatedDevice, boolean selfManaged, boolean notifyOnDeviceNearby, boolean revoked, long timeApprovedMs, long lastTimeConnectedMs, int systemDataSyncFlags) { if (id <= 0) { throw new IllegalArgumentException("Association ID should be greater than 0"); } Loading @@ -97,6 +99,7 @@ public final class AssociationInfo implements Parcelable { mDeviceMacAddress = macAddress; mDisplayName = displayName; mTag = tag; mDeviceProfile = deviceProfile; mAssociatedDevice = associatedDevice; Loading @@ -115,6 +118,14 @@ public final class AssociationInfo implements Parcelable { return mId; } /** * @return the tag of this association. * @see CompanionDeviceManager#setAssociationTag(int, String) */ public @Nullable String getTag() { return mTag; } /** * @return the ID of the user who "owns" this association. * @hide Loading Loading @@ -287,6 +298,7 @@ public final class AssociationInfo implements Parcelable { + "mId=" + mId + ", mUserId=" + mUserId + ", mPackageName='" + mPackageName + '\'' + ", mTag='" + mTag + '\'' + ", mDeviceMacAddress=" + mDeviceMacAddress + ", mDisplayName='" + mDisplayName + '\'' + ", mDeviceProfile='" + mDeviceProfile + '\'' Loading Loading @@ -315,6 +327,7 @@ public final class AssociationInfo implements Parcelable { && mTimeApprovedMs == that.mTimeApprovedMs && mLastTimeConnectedMs == that.mLastTimeConnectedMs && Objects.equals(mPackageName, that.mPackageName) && Objects.equals(mTag, that.mTag) && Objects.equals(mDeviceMacAddress, that.mDeviceMacAddress) && Objects.equals(mDisplayName, that.mDisplayName) && Objects.equals(mDeviceProfile, that.mDeviceProfile) Loading @@ -324,7 +337,7 @@ public final class AssociationInfo implements Parcelable { @Override public int hashCode() { return Objects.hash(mId, mUserId, mPackageName, mDeviceMacAddress, mDisplayName, return Objects.hash(mId, mUserId, mPackageName, mTag, mDeviceMacAddress, mDisplayName, mDeviceProfile, mAssociatedDevice, mSelfManaged, mNotifyOnDeviceNearby, mRevoked, mTimeApprovedMs, mLastTimeConnectedMs, mSystemDataSyncFlags); } Loading @@ -340,6 +353,7 @@ public final class AssociationInfo implements Parcelable { dest.writeInt(mUserId); dest.writeString(mPackageName); dest.writeString(mTag); dest.writeTypedObject(mDeviceMacAddress, 0); dest.writeCharSequence(mDisplayName); Loading @@ -359,6 +373,7 @@ public final class AssociationInfo implements Parcelable { mUserId = in.readInt(); mPackageName = in.readString(); mTag = in.readString(); mDeviceMacAddress = in.readTypedObject(MacAddress.CREATOR); mDisplayName = in.readCharSequence(); Loading Loading @@ -413,9 +428,11 @@ public final class AssociationInfo implements Parcelable { private boolean mRevoked; private long mLastTimeConnectedMs; private int mSystemDataSyncFlags; private String mTag; private Builder(@NonNull AssociationInfo info) { mOriginalInfo = info; mTag = info.mTag; mNotifyOnDeviceNearby = info.mNotifyOnDeviceNearby; mRevoked = info.mRevoked; mLastTimeConnectedMs = info.mLastTimeConnectedMs; Loading Loading @@ -459,6 +476,14 @@ public final class AssociationInfo implements Parcelable { return this; } /** @hide */ @Override @NonNull public Builder setTag(String tag) { mTag = tag; return this; } /** @hide */ @NonNull public AssociationInfo build() { Loading @@ -466,6 +491,7 @@ public final class AssociationInfo implements Parcelable { mOriginalInfo.mId, mOriginalInfo.mUserId, mOriginalInfo.mPackageName, mTag, mOriginalInfo.mDeviceMacAddress, mOriginalInfo.mDisplayName, mOriginalInfo.mDeviceProfile, Loading Loading @@ -508,5 +534,8 @@ public final class AssociationInfo implements Parcelable { /** @hide */ @NonNull Builder setSystemDataSyncFlags(int flags); /** @hide */ Builder setTag(String tag); } } core/java/android/companion/CompanionDeviceManager.java +44 −0 Original line number Diff line number Diff line Loading @@ -1372,6 +1372,50 @@ public final class CompanionDeviceManager { } } /** * Sets the {@link AssociationInfo#getTag() tag} for this association. * * <p>The length of the tag must be at most 20 characters. * * <p>This allows to store useful information about the associated devices. * * @param associationId The unique {@link AssociationInfo#getId ID} assigned to the Association * of the companion device recorded by CompanionDeviceManager * @param tag the tag of this association */ @UserHandleAware public void setAssociationTag(int associationId, @NonNull String tag) { Objects.requireNonNull(tag, "tag cannot be null"); if (tag.length() > 20) { throw new IllegalArgumentException("Length of the tag must be at most 20 characters"); } try { mService.setAssociationTag(associationId, tag); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Clears the {@link AssociationInfo#getTag() tag} for this association. * * <p>The tag will be set to null for this association when calling this API. * * @param associationId The unique {@link AssociationInfo#getId ID} assigned to the Association * of the companion device recorded by CompanionDeviceManager * @see CompanionDeviceManager#setAssociationTag(int, String) */ @UserHandleAware public void clearAssociationTag(int associationId) { try { mService.clearAssociationTag(associationId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } private boolean checkFeaturePresent() { boolean featurePresent = mService != null; if (!featurePresent && DEBUG) { Loading core/java/android/companion/ICompanionDeviceManager.aidl +4 −0 Original line number Diff line number Diff line Loading @@ -115,4 +115,8 @@ interface ICompanionDeviceManager { @EnforcePermission("MANAGE_COMPANION_DEVICES") void enableSecureTransport(boolean enabled); void setAssociationTag(int associationId, String tag); void clearAssociationTag(int associationId); } services/companion/java/com/android/server/companion/AssociationRequestsProcessor.java +3 −3 Original line number Diff line number Diff line Loading @@ -281,9 +281,9 @@ class AssociationRequestsProcessor { final long timestamp = System.currentTimeMillis(); final AssociationInfo association = new AssociationInfo(id, userId, packageName, macAddress, displayName, deviceProfile, associatedDevice, selfManaged, /* notifyOnDeviceNearby */ false, /* revoked */ false, timestamp, Long.MAX_VALUE, /* systemDataSyncFlags */ 0); /* tag */ null, macAddress, displayName, deviceProfile, associatedDevice, selfManaged, /* notifyOnDeviceNearby */ false, /* revoked */ false, timestamp, Long.MAX_VALUE, /* systemDataSyncFlags */ 0); if (deviceProfile != null) { // If the "Device Profile" is specified, make the companion application a holder of the Loading Loading
core/api/current.txt +3 −0 Original line number Diff line number Diff line Loading @@ -9530,6 +9530,7 @@ package android.companion { method @Nullable public CharSequence getDisplayName(); method public int getId(); method public int getSystemDataSyncFlags(); method @Nullable public String getTag(); method public void writeToParcel(@NonNull android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator<android.companion.AssociationInfo> CREATOR; } Loading Loading @@ -9599,6 +9600,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 public void clearAssociationTag(int); 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); Loading @@ -9608,6 +9610,7 @@ package android.companion { method @NonNull public java.util.List<android.companion.AssociationInfo> getMyAssociations(); method @Deprecated public boolean hasNotificationAccess(android.content.ComponentName); method public void requestNotificationAccess(android.content.ComponentName); method 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; 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;
core/java/android/companion/AssociationInfo.java +34 −5 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ public final class AssociationInfo implements Parcelable { private final boolean mSelfManaged; private final boolean mNotifyOnDeviceNearby; private final int mSystemDataSyncFlags; private final String mTag; /** * Indicates that the association has been revoked (removed), but we keep the association Loading @@ -78,10 +79,11 @@ public final class AssociationInfo implements Parcelable { * @hide */ public AssociationInfo(int id, @UserIdInt int userId, @NonNull String packageName, @Nullable MacAddress macAddress, @Nullable CharSequence displayName, @Nullable String deviceProfile, @Nullable AssociatedDevice associatedDevice, boolean selfManaged, boolean notifyOnDeviceNearby, boolean revoked, long timeApprovedMs, long lastTimeConnectedMs, int systemDataSyncFlags) { @Nullable String tag, @Nullable MacAddress macAddress, @Nullable CharSequence displayName, @Nullable String deviceProfile, @Nullable AssociatedDevice associatedDevice, boolean selfManaged, boolean notifyOnDeviceNearby, boolean revoked, long timeApprovedMs, long lastTimeConnectedMs, int systemDataSyncFlags) { if (id <= 0) { throw new IllegalArgumentException("Association ID should be greater than 0"); } Loading @@ -97,6 +99,7 @@ public final class AssociationInfo implements Parcelable { mDeviceMacAddress = macAddress; mDisplayName = displayName; mTag = tag; mDeviceProfile = deviceProfile; mAssociatedDevice = associatedDevice; Loading @@ -115,6 +118,14 @@ public final class AssociationInfo implements Parcelable { return mId; } /** * @return the tag of this association. * @see CompanionDeviceManager#setAssociationTag(int, String) */ public @Nullable String getTag() { return mTag; } /** * @return the ID of the user who "owns" this association. * @hide Loading Loading @@ -287,6 +298,7 @@ public final class AssociationInfo implements Parcelable { + "mId=" + mId + ", mUserId=" + mUserId + ", mPackageName='" + mPackageName + '\'' + ", mTag='" + mTag + '\'' + ", mDeviceMacAddress=" + mDeviceMacAddress + ", mDisplayName='" + mDisplayName + '\'' + ", mDeviceProfile='" + mDeviceProfile + '\'' Loading Loading @@ -315,6 +327,7 @@ public final class AssociationInfo implements Parcelable { && mTimeApprovedMs == that.mTimeApprovedMs && mLastTimeConnectedMs == that.mLastTimeConnectedMs && Objects.equals(mPackageName, that.mPackageName) && Objects.equals(mTag, that.mTag) && Objects.equals(mDeviceMacAddress, that.mDeviceMacAddress) && Objects.equals(mDisplayName, that.mDisplayName) && Objects.equals(mDeviceProfile, that.mDeviceProfile) Loading @@ -324,7 +337,7 @@ public final class AssociationInfo implements Parcelable { @Override public int hashCode() { return Objects.hash(mId, mUserId, mPackageName, mDeviceMacAddress, mDisplayName, return Objects.hash(mId, mUserId, mPackageName, mTag, mDeviceMacAddress, mDisplayName, mDeviceProfile, mAssociatedDevice, mSelfManaged, mNotifyOnDeviceNearby, mRevoked, mTimeApprovedMs, mLastTimeConnectedMs, mSystemDataSyncFlags); } Loading @@ -340,6 +353,7 @@ public final class AssociationInfo implements Parcelable { dest.writeInt(mUserId); dest.writeString(mPackageName); dest.writeString(mTag); dest.writeTypedObject(mDeviceMacAddress, 0); dest.writeCharSequence(mDisplayName); Loading @@ -359,6 +373,7 @@ public final class AssociationInfo implements Parcelable { mUserId = in.readInt(); mPackageName = in.readString(); mTag = in.readString(); mDeviceMacAddress = in.readTypedObject(MacAddress.CREATOR); mDisplayName = in.readCharSequence(); Loading Loading @@ -413,9 +428,11 @@ public final class AssociationInfo implements Parcelable { private boolean mRevoked; private long mLastTimeConnectedMs; private int mSystemDataSyncFlags; private String mTag; private Builder(@NonNull AssociationInfo info) { mOriginalInfo = info; mTag = info.mTag; mNotifyOnDeviceNearby = info.mNotifyOnDeviceNearby; mRevoked = info.mRevoked; mLastTimeConnectedMs = info.mLastTimeConnectedMs; Loading Loading @@ -459,6 +476,14 @@ public final class AssociationInfo implements Parcelable { return this; } /** @hide */ @Override @NonNull public Builder setTag(String tag) { mTag = tag; return this; } /** @hide */ @NonNull public AssociationInfo build() { Loading @@ -466,6 +491,7 @@ public final class AssociationInfo implements Parcelable { mOriginalInfo.mId, mOriginalInfo.mUserId, mOriginalInfo.mPackageName, mTag, mOriginalInfo.mDeviceMacAddress, mOriginalInfo.mDisplayName, mOriginalInfo.mDeviceProfile, Loading Loading @@ -508,5 +534,8 @@ public final class AssociationInfo implements Parcelable { /** @hide */ @NonNull Builder setSystemDataSyncFlags(int flags); /** @hide */ Builder setTag(String tag); } }
core/java/android/companion/CompanionDeviceManager.java +44 −0 Original line number Diff line number Diff line Loading @@ -1372,6 +1372,50 @@ public final class CompanionDeviceManager { } } /** * Sets the {@link AssociationInfo#getTag() tag} for this association. * * <p>The length of the tag must be at most 20 characters. * * <p>This allows to store useful information about the associated devices. * * @param associationId The unique {@link AssociationInfo#getId ID} assigned to the Association * of the companion device recorded by CompanionDeviceManager * @param tag the tag of this association */ @UserHandleAware public void setAssociationTag(int associationId, @NonNull String tag) { Objects.requireNonNull(tag, "tag cannot be null"); if (tag.length() > 20) { throw new IllegalArgumentException("Length of the tag must be at most 20 characters"); } try { mService.setAssociationTag(associationId, tag); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Clears the {@link AssociationInfo#getTag() tag} for this association. * * <p>The tag will be set to null for this association when calling this API. * * @param associationId The unique {@link AssociationInfo#getId ID} assigned to the Association * of the companion device recorded by CompanionDeviceManager * @see CompanionDeviceManager#setAssociationTag(int, String) */ @UserHandleAware public void clearAssociationTag(int associationId) { try { mService.clearAssociationTag(associationId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } private boolean checkFeaturePresent() { boolean featurePresent = mService != null; if (!featurePresent && DEBUG) { Loading
core/java/android/companion/ICompanionDeviceManager.aidl +4 −0 Original line number Diff line number Diff line Loading @@ -115,4 +115,8 @@ interface ICompanionDeviceManager { @EnforcePermission("MANAGE_COMPANION_DEVICES") void enableSecureTransport(boolean enabled); void setAssociationTag(int associationId, String tag); void clearAssociationTag(int associationId); }
services/companion/java/com/android/server/companion/AssociationRequestsProcessor.java +3 −3 Original line number Diff line number Diff line Loading @@ -281,9 +281,9 @@ class AssociationRequestsProcessor { final long timestamp = System.currentTimeMillis(); final AssociationInfo association = new AssociationInfo(id, userId, packageName, macAddress, displayName, deviceProfile, associatedDevice, selfManaged, /* notifyOnDeviceNearby */ false, /* revoked */ false, timestamp, Long.MAX_VALUE, /* systemDataSyncFlags */ 0); /* tag */ null, macAddress, displayName, deviceProfile, associatedDevice, selfManaged, /* notifyOnDeviceNearby */ false, /* revoked */ false, timestamp, Long.MAX_VALUE, /* systemDataSyncFlags */ 0); if (deviceProfile != null) { // If the "Device Profile" is specified, make the companion application a holder of the Loading