1 /*
2  * Copyright 2021 HIMSA II K/S - www.himsa.com.
3  * Represented by EHIMA - www.ehima.com
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package com.android.bluetooth.leaudio;
19 
20 import android.app.Application;
21 import android.bluetooth.BluetoothDevice;
22 import android.bluetooth.BluetoothLeBroadcastMetadata;
23 
24 import androidx.annotation.NonNull;
25 import androidx.lifecycle.AndroidViewModel;
26 import androidx.lifecycle.LiveData;
27 
28 import java.util.List;
29 
30 public class LeAudioViewModel extends AndroidViewModel {
31     private final BluetoothProxy bluetoothProxy;
32 
LeAudioViewModel(@onNull Application application)33     public LeAudioViewModel(@NonNull Application application) {
34         super(application);
35         bluetoothProxy = BluetoothProxy.getBluetoothProxy(application);
36         bluetoothProxy.initProfiles();
37     }
38 
39     @Override
onCleared()40     public void onCleared() {
41         bluetoothProxy.cleanupProfiles();
42     }
43 
queryDevices()44     public void queryDevices() {
45         bluetoothProxy.queryLeAudioDevices();
46     }
47 
connectLeAudio(BluetoothDevice device, boolean connect)48     public void connectLeAudio(BluetoothDevice device, boolean connect) {
49         bluetoothProxy.connectLeAudio(device, connect);
50     }
51 
streamAction(Integer group_id, int action, Integer content_type)52     public void streamAction(Integer group_id, int action, Integer content_type) {
53         bluetoothProxy.streamAction(group_id, action, content_type);
54     }
55 
groupSet(BluetoothDevice device, Integer group_id)56     public void groupSet(BluetoothDevice device, Integer group_id) {
57         bluetoothProxy.groupSet(device, group_id);
58     }
59 
groupUnset(BluetoothDevice device, Integer group_id)60     public void groupUnset(BluetoothDevice device, Integer group_id) {
61         bluetoothProxy.groupUnset(device, group_id);
62     }
63 
groupSetLock(Integer group_id, boolean lock)64     public void groupSetLock(Integer group_id, boolean lock) {
65         bluetoothProxy.groupSetLock(group_id, lock);
66     }
67 
setVolume(BluetoothDevice device, int volume)68     public void setVolume(BluetoothDevice device, int volume) {
69         bluetoothProxy.setVolume(device, volume);
70     }
71 
connectHap(BluetoothDevice device, boolean connect)72     public void connectHap(BluetoothDevice device, boolean connect) {
73         bluetoothProxy.connectHap(device, connect);
74     }
75 
hapReadPresetInfo(BluetoothDevice device, int preset_index)76     public void hapReadPresetInfo(BluetoothDevice device, int preset_index) {
77         bluetoothProxy.hapReadPresetInfo(device, preset_index);
78     }
79 
hapSetActivePreset(BluetoothDevice device, int preset_index)80     public void hapSetActivePreset(BluetoothDevice device, int preset_index) {
81         bluetoothProxy.hapSetActivePreset(device, preset_index);
82     }
83 
hapSetActivePresetForGroup(BluetoothDevice device, int preset_index)84     public void hapSetActivePresetForGroup(BluetoothDevice device, int preset_index) {
85         bluetoothProxy.hapSetActivePresetForGroup(device, preset_index);
86     }
87 
hapChangePresetName(BluetoothDevice device, int preset_index, String name)88     public void hapChangePresetName(BluetoothDevice device, int preset_index, String name) {
89         bluetoothProxy.hapChangePresetName(device, preset_index, name);
90     }
91 
hapPreviousDevicePreset(BluetoothDevice device)92     public void hapPreviousDevicePreset(BluetoothDevice device) {
93         bluetoothProxy.hapPreviousDevicePreset(device);
94     }
95 
hapNextDevicePreset(BluetoothDevice device)96     public void hapNextDevicePreset(BluetoothDevice device) {
97         bluetoothProxy.hapNextDevicePreset(device);
98     }
99 
hapPreviousGroupPreset(int group_id)100     public boolean hapPreviousGroupPreset(int group_id) {
101         return bluetoothProxy.hapPreviousGroupPreset(group_id);
102     }
103 
hapNextGroupPreset(int group_id)104     public boolean hapNextGroupPreset(int group_id) {
105         return bluetoothProxy.hapNextGroupPreset(group_id);
106     }
107 
hapGetHapGroup(BluetoothDevice device)108     public int hapGetHapGroup(BluetoothDevice device) {
109         return bluetoothProxy.hapGetHapGroup(device);
110     }
111 
getBluetoothEnabledLive()112     public LiveData<Boolean> getBluetoothEnabledLive() {
113         return bluetoothProxy.getBluetoothEnabled();
114     }
115 
getAllLeAudioDevicesLive()116     public LiveData<List<LeAudioDeviceStateWrapper>> getAllLeAudioDevicesLive() {
117         return bluetoothProxy.getAllLeAudioDevices();
118     }
119 
isLeAudioBroadcastSourceSupported()120     public boolean isLeAudioBroadcastSourceSupported() {
121         return bluetoothProxy.isLeAudioBroadcastSourceSupported();
122     }
123 
connectBass(BluetoothDevice sink, boolean connect)124     public void connectBass(BluetoothDevice sink, boolean connect) {
125         bluetoothProxy.connectBass(sink, connect);
126     }
127 
stopBroadcastObserving()128     public boolean stopBroadcastObserving() {
129         return bluetoothProxy.stopBroadcastObserving();
130     }
131 
132     // TODO: Uncomment this method if necessary
133     //    public boolean getBroadcastReceiverState(BluetoothDevice device, int receiver_id) {
134     //        return bluetoothProxy.getBroadcastReceiverState(device, receiver_id);
135     //    }
136 
137     // TODO: Uncomment this method if necessary
138     //    public boolean modifyBroadcastSource(BluetoothDevice device, int receiver_id, boolean
139     // sync_pa,
140     //            List<BluetoothBroadcastAudioScanBaseConfig> configs) {
141     //        return bluetoothProxy.modifyBroadcastSource(device, receiver_id, sync_pa, configs);
142     //    }
143 
removeBroadcastSource(BluetoothDevice sink, int receiver_id)144     public boolean removeBroadcastSource(BluetoothDevice sink, int receiver_id) {
145         // TODO: Find source ID from receiver_id. What is receiver_id?
146         int sourceId = receiver_id;
147         return bluetoothProxy.removeBroadcastSource(sink, sourceId);
148     }
149 
setBroadcastCode(BluetoothDevice sink, int receiver_id, byte[] bcast_code)150     public boolean setBroadcastCode(BluetoothDevice sink, int receiver_id, byte[] bcast_code) {
151         // TODO: Find source ID from receiver_id. What is receiver_id?
152         // TODO: Build BluetoothLeBroadcastMetadata with the new bcast_code.
153         int sourceId = receiver_id;
154         BluetoothLeBroadcastMetadata metadata = null;
155         return bluetoothProxy.modifyBroadcastSource(sink, sourceId, metadata);
156     }
157 }
158