diff options
| author | 2022-01-25 22:16:52 +0000 | |
|---|---|---|
| committer | 2022-01-25 22:16:52 +0000 | |
| commit | 1a09b387867ea391994a068cecbe3be92b581d81 (patch) | |
| tree | 4df4bb31beffc08dda6597f2990714b11350b89c | |
| parent | 2b6cc61257c849f39a546c09d433d2a03db139e6 (diff) | |
| parent | 3422dffeeed30bf039173ebdb61993354ae2da24 (diff) | |
Merge "[Output Switcher] Add a manager class that handles requests for nearby devices."
3 files changed, 144 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/nearby/MediaNearbyDevicesManager.kt b/packages/SystemUI/src/com/android/systemui/media/nearby/MediaNearbyDevicesManager.kt new file mode 100644 index 000000000000..0453fdb45931 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/media/nearby/MediaNearbyDevicesManager.kt @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.media.nearby + +import com.android.systemui.dagger.SysUISingleton + +/** + * A manager that returns information about devices that are nearby and can receive media transfers. + */ +@SysUISingleton +class MediaNearbyDevicesManager { + + /** Returns a list containing the current nearby devices. */ + fun getCurrentNearbyDevices(): List<NearbyDevice> { + // TODO(b/216313420): Implement this function. + return emptyList() + } + + /** + * Registers [callback] to be notified each time a device's range changes or when a new device + * comes within range. + */ + fun registerNearbyDevicesCallback( + callback: (device: NearbyDevice) -> Unit + ) { + // TODO(b/216313420): Implement this function. + } + + /** + * Un-registers [callback]. See [registerNearbyDevicesCallback]. + */ + fun unregisterNearbyDevicesCallback( + callback: (device: NearbyDevice) -> Unit + ) { + // TODO(b/216313420): Implement this function. + } +} diff --git a/packages/SystemUI/src/com/android/systemui/media/nearby/NearbyDevice.kt b/packages/SystemUI/src/com/android/systemui/media/nearby/NearbyDevice.kt new file mode 100644 index 000000000000..96b853f394d4 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/media/nearby/NearbyDevice.kt @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.media.nearby + +import android.os.Parcel +import android.os.Parcelable + +/** + * A parcelable representing a nearby device that can be used for media transfer. + * + * This class includes: + * - [routeId] identifying the media route + * - [rangeZone] specifying how far away the device with the media route is from this device. + */ +class NearbyDevice(parcel: Parcel) : Parcelable { + var routeId: String? = null + @RangeZone val rangeZone: Int + + init { + routeId = parcel.readString() ?: "unknown" + rangeZone = parcel.readInt() + } + + override fun describeContents() = 0 + + override fun writeToParcel(out: Parcel, flags: Int) { + out.writeString(routeId) + out.writeInt(rangeZone) + } + + companion object CREATOR : Parcelable.Creator<NearbyDevice?> { + override fun createFromParcel(parcel: Parcel) = NearbyDevice(parcel) + override fun newArray(size: Int) = arrayOfNulls<NearbyDevice?>(size) + } +} diff --git a/packages/SystemUI/src/com/android/systemui/media/nearby/RangeZone.kt b/packages/SystemUI/src/com/android/systemui/media/nearby/RangeZone.kt new file mode 100644 index 000000000000..3c890bc9efab --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/media/nearby/RangeZone.kt @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.media.nearby + +import androidx.annotation.IntDef +import kotlin.annotation.AnnotationRetention + +@IntDef( + RangeZone.RANGE_UNKNOWN, + RangeZone.RANGE_FAR, + RangeZone.RANGE_LONG, + RangeZone.RANGE_CLOSE, + RangeZone.RANGE_WITHIN_REACH +) +@Retention(AnnotationRetention.SOURCE) +/** The various range zones a device can be in, in relation to the current device. */ +annotation class RangeZone { + companion object { + /** Unknown distance range. */ + const val RANGE_UNKNOWN = 0 + /** Distance is very far away from the peer device. */ + const val RANGE_FAR = 1 + /** Distance is relatively long from the peer device, typically a few meters. */ + const val RANGE_LONG = 2 + /** Distance is close to the peer device, typically with one or two meter. */ + const val RANGE_CLOSE = 3 + /** Distance is very close to the peer device, typically within one meter or less. */ + const val RANGE_WITHIN_REACH = 4 + } +} |