1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.car.settings.sound; 18 19 import static android.media.AudioDeviceInfo.TYPE_BLUETOOTH_A2DP; 20 import static android.media.AudioDeviceInfo.TYPE_BUS; 21 22 import android.annotation.SuppressLint; 23 import android.media.AudioDeviceAttributes; 24 import android.media.AudioDeviceInfo; 25 26 import androidx.annotation.Nullable; 27 28 import com.android.settingslib.bluetooth.CachedBluetoothDevice; 29 30 /** 31 * A class to encapsulate audio route information. 32 */ 33 public class AudioRouteItem { 34 private String mName; 35 private String mAddress; 36 37 private @AudioDeviceInfo.AudioDeviceType int mAudioRouteType; 38 @Nullable 39 private CachedBluetoothDevice mBluetoothDevice; 40 @Nullable 41 private AudioDeviceAttributes mAudioDeviceAttributes; 42 43 @SuppressLint("MissingPermission") AudioRouteItem(CachedBluetoothDevice bluetoothDevice)44 public AudioRouteItem(CachedBluetoothDevice bluetoothDevice) { 45 mName = bluetoothDevice.getName(); 46 mAddress = bluetoothDevice.getAddress(); 47 mAudioRouteType = TYPE_BLUETOOTH_A2DP; 48 mBluetoothDevice = bluetoothDevice; 49 } 50 AudioRouteItem(AudioDeviceAttributes audioDeviceAttributes)51 public AudioRouteItem(AudioDeviceAttributes audioDeviceAttributes) { 52 mName = audioDeviceAttributes.getName(); 53 mAddress = audioDeviceAttributes.getAddress(); 54 mAudioRouteType = TYPE_BUS; 55 mAudioDeviceAttributes = audioDeviceAttributes; 56 } 57 getName()58 public String getName() { 59 return mName; 60 } 61 getAddress()62 public String getAddress() { 63 return mAddress; 64 } 65 getAudioRouteType()66 public @AudioDeviceInfo.AudioDeviceType int getAudioRouteType() { 67 return mAudioRouteType; 68 } 69 70 @Nullable getBluetoothDevice()71 public CachedBluetoothDevice getBluetoothDevice() { 72 return mBluetoothDevice; 73 } 74 75 @Nullable getAudioDeviceAttributes()76 public AudioDeviceAttributes getAudioDeviceAttributes() { 77 return mAudioDeviceAttributes; 78 } 79 setBluetoothDevice(CachedBluetoothDevice bluetoothDevice)80 public void setBluetoothDevice(CachedBluetoothDevice bluetoothDevice) { 81 mBluetoothDevice = bluetoothDevice; 82 } 83 setAudioRouteType(@udioDeviceInfo.AudioDeviceType int audioRouteType)84 public void setAudioRouteType(@AudioDeviceInfo.AudioDeviceType int audioRouteType) { 85 mAudioRouteType = audioRouteType; 86 } 87 } 88