diff --git a/core/api/current.txt b/core/api/current.txt index 164e14a1bc392..19b476a5c5a37 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -8956,9 +8956,18 @@ package android.appwidget { package android.companion { + public final class AssociatedDevice implements android.os.Parcelable { + method public int describeContents(); + method @Nullable public android.bluetooth.le.ScanResult getBleDevice(); + method @Nullable public android.bluetooth.BluetoothDevice getBluetoothDevice(); + method @Nullable public android.net.wifi.ScanResult getWifiDevice(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; + } + public final class AssociationInfo implements android.os.Parcelable { method public int describeContents(); - method @Nullable public android.os.Parcelable getAssociatedDevice(); + method @Nullable public android.companion.AssociatedDevice getAssociatedDevice(); method @Nullable public android.net.MacAddress getDeviceMacAddress(); method @Nullable public String getDeviceProfile(); method @Nullable public CharSequence getDisplayName(); diff --git a/core/java/android/companion/AssociatedDevice.java b/core/java/android/companion/AssociatedDevice.java index 3758cdb680b10..a8336615fde5d 100644 --- a/core/java/android/companion/AssociatedDevice.java +++ b/core/java/android/companion/AssociatedDevice.java @@ -16,6 +16,7 @@ package android.companion; +import android.bluetooth.BluetoothDevice; import android.os.Parcel; import android.os.Parcelable; @@ -23,19 +24,14 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; /** - * Loose wrapper around device parcelable. Device can be one of three types: + * Container for device info from an association that is not self-managed. + * Device can be one of three types: * * - * - * This class serves as temporary wrapper to deliver a loosely-typed parcelable object from - * {@link com.android.companiondevicemanager.CompanionDeviceActivity} to the Companion app, - * and should only be used internally. - * - * @hide */ public final class AssociatedDevice implements Parcelable { private static final int CLASSIC_BLUETOOTH = 0; @@ -44,6 +40,7 @@ public final class AssociatedDevice implements Parcelable { @NonNull private final Parcelable mDevice; + /** @hide */ public AssociatedDevice(@NonNull Parcelable device) { mDevice = device; } @@ -54,11 +51,39 @@ public final class AssociatedDevice implements Parcelable { } /** - * Return device info. Cast to expected device type. + * Return bluetooth device info. Null if associated device is not a bluetooth device. + * @return Remote bluetooth device details containing MAC address. */ - @NonNull - public Parcelable getDevice() { - return mDevice; + @Nullable + public BluetoothDevice getBluetoothDevice() { + if (mDevice instanceof BluetoothDevice) { + return (BluetoothDevice) mDevice; + } + return null; + } + + /** + * Return bluetooth LE device info. Null if associated device is not a BLE device. + * @return BLE scan result containing details of detected BLE device. + */ + @Nullable + public android.bluetooth.le.ScanResult getBleDevice() { + if (mDevice instanceof android.bluetooth.le.ScanResult) { + return (android.bluetooth.le.ScanResult) mDevice; + } + return null; + } + + /** + * Return Wi-Fi device info. Null if associated device is not a Wi-Fi device. + * @return Wi-Fi scan result containing details of detected access point. + */ + @Nullable + public android.net.wifi.ScanResult getWifiDevice() { + if (mDevice instanceof android.net.wifi.ScanResult) { + return (android.net.wifi.ScanResult) mDevice; + } + return null; } @Override diff --git a/core/java/android/companion/AssociationInfo.java b/core/java/android/companion/AssociationInfo.java index 93964b3f41808..5fd39feceb23b 100644 --- a/core/java/android/companion/AssociationInfo.java +++ b/core/java/android/companion/AssociationInfo.java @@ -164,20 +164,19 @@ public final class AssociationInfo implements Parcelable { /** * Companion device that was associated. Note that this field is not persisted across sessions. - * - * Cast to expected device type before use: + * Device can be one of the following types: * * * * @return the companion device that was associated, or {@code null} if the device is - * self-managed. + * self-managed or this association info was retrieved from persistent storage. */ - public @Nullable Parcelable getAssociatedDevice() { - return mAssociatedDevice == null ? null : mAssociatedDevice.getDevice(); + public @Nullable AssociatedDevice getAssociatedDevice() { + return mAssociatedDevice; } /**