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 import android.content.Context; 24 25 import androidx.annotation.NonNull; 26 import androidx.lifecycle.AndroidViewModel; 27 import androidx.lifecycle.LiveData; 28 29 import java.util.List; 30 31 public class LeAudioViewModel extends AndroidViewModel { 32 private final BluetoothProxy bluetoothProxy; 33 LeAudioViewModel(@onNull Application application)34 public LeAudioViewModel(@NonNull Application application) { 35 super(application); 36 bluetoothProxy = BluetoothProxy.getBluetoothProxy(application); 37 bluetoothProxy.initProfiles(); 38 } 39 40 @Override onCleared()41 public void onCleared() { 42 bluetoothProxy.cleanupProfiles(); 43 } 44 queryDevices()45 public void queryDevices() { 46 bluetoothProxy.queryLeAudioDevices(); 47 } 48 connectLeAudio(BluetoothDevice device, boolean connect)49 public void connectLeAudio(BluetoothDevice device, boolean connect) { 50 bluetoothProxy.connectLeAudio(device, connect); 51 } 52 streamAction(Integer group_id, int action, Integer content_type)53 public void streamAction(Integer group_id, int action, Integer content_type) { 54 bluetoothProxy.streamAction(group_id, action, content_type); 55 } 56 groupSet(BluetoothDevice device, Integer group_id)57 public void groupSet(BluetoothDevice device, Integer group_id) { 58 bluetoothProxy.groupSet(device, group_id); 59 } 60 groupUnset(BluetoothDevice device, Integer group_id)61 public void groupUnset(BluetoothDevice device, Integer group_id) { 62 bluetoothProxy.groupUnset(device, group_id); 63 } 64 groupSetLock(Integer group_id, boolean lock)65 public void groupSetLock(Integer group_id, boolean lock) { 66 bluetoothProxy.groupSetLock(group_id, lock); 67 } 68 setVolume(BluetoothDevice device, int volume)69 public void setVolume(BluetoothDevice device, int volume) { 70 bluetoothProxy.setVolume(device, volume); 71 } 72 connectHap(BluetoothDevice device, boolean connect)73 public void connectHap(BluetoothDevice device, boolean connect) { 74 bluetoothProxy.connectHap(device, connect); 75 } 76 connectGattBr( Context context, LeAudioDeviceStateWrapper device_wrapper, boolean connect)77 public void connectGattBr( 78 Context context, LeAudioDeviceStateWrapper device_wrapper, boolean connect) { 79 bluetoothProxy.connectGattBr(context, device_wrapper, connect); 80 } 81 hapReadPresetInfo(BluetoothDevice device, int preset_index)82 public void hapReadPresetInfo(BluetoothDevice device, int preset_index) { 83 bluetoothProxy.hapReadPresetInfo(device, preset_index); 84 } 85 hapSetActivePreset(BluetoothDevice device, int preset_index)86 public void hapSetActivePreset(BluetoothDevice device, int preset_index) { 87 bluetoothProxy.hapSetActivePreset(device, preset_index); 88 } 89 hapSetActivePresetForGroup(BluetoothDevice device, int preset_index)90 public void hapSetActivePresetForGroup(BluetoothDevice device, int preset_index) { 91 bluetoothProxy.hapSetActivePresetForGroup(device, preset_index); 92 } 93 hapChangePresetName(BluetoothDevice device, int preset_index, String name)94 public void hapChangePresetName(BluetoothDevice device, int preset_index, String name) { 95 bluetoothProxy.hapChangePresetName(device, preset_index, name); 96 } 97 hapPreviousDevicePreset(BluetoothDevice device)98 public void hapPreviousDevicePreset(BluetoothDevice device) { 99 bluetoothProxy.hapPreviousDevicePreset(device); 100 } 101 hapNextDevicePreset(BluetoothDevice device)102 public void hapNextDevicePreset(BluetoothDevice device) { 103 bluetoothProxy.hapNextDevicePreset(device); 104 } 105 hapPreviousGroupPreset(int group_id)106 public boolean hapPreviousGroupPreset(int group_id) { 107 return bluetoothProxy.hapPreviousGroupPreset(group_id); 108 } 109 hapNextGroupPreset(int group_id)110 public boolean hapNextGroupPreset(int group_id) { 111 return bluetoothProxy.hapNextGroupPreset(group_id); 112 } 113 hapGetHapGroup(BluetoothDevice device)114 public int hapGetHapGroup(BluetoothDevice device) { 115 return bluetoothProxy.hapGetHapGroup(device); 116 } 117 getBluetoothEnabledLive()118 public LiveData<Boolean> getBluetoothEnabledLive() { 119 return bluetoothProxy.getBluetoothEnabled(); 120 } 121 getAllLeAudioDevicesLive()122 public LiveData<List<LeAudioDeviceStateWrapper>> getAllLeAudioDevicesLive() { 123 return bluetoothProxy.getAllLeAudioDevices(); 124 } 125 isLeAudioBroadcastSourceSupported()126 public boolean isLeAudioBroadcastSourceSupported() { 127 return bluetoothProxy.isLeAudioBroadcastSourceSupported(); 128 } 129 connectBass(BluetoothDevice sink, boolean connect)130 public void connectBass(BluetoothDevice sink, boolean connect) { 131 bluetoothProxy.connectBass(sink, connect); 132 } 133 stopBroadcastObserving()134 public boolean stopBroadcastObserving() { 135 return bluetoothProxy.stopBroadcastObserving(); 136 } 137 138 // TODO: Uncomment this method if necessary 139 // public boolean getBroadcastReceiverState(BluetoothDevice device, int receiver_id) { 140 // return bluetoothProxy.getBroadcastReceiverState(device, receiver_id); 141 // } 142 143 // TODO: Uncomment this method if necessary 144 // public boolean modifyBroadcastSource(BluetoothDevice device, int receiver_id, boolean 145 // sync_pa, 146 // List<BluetoothBroadcastAudioScanBaseConfig> configs) { 147 // return bluetoothProxy.modifyBroadcastSource(device, receiver_id, sync_pa, configs); 148 // } 149 removeBroadcastSource(BluetoothDevice sink, int receiver_id)150 public boolean removeBroadcastSource(BluetoothDevice sink, int receiver_id) { 151 // TODO: Find source ID from receiver_id. What is receiver_id? 152 int sourceId = receiver_id; 153 return bluetoothProxy.removeBroadcastSource(sink, sourceId); 154 } 155 setBroadcastCode(BluetoothDevice sink, int receiver_id, byte[] bcast_code)156 public boolean setBroadcastCode(BluetoothDevice sink, int receiver_id, byte[] bcast_code) { 157 // TODO: Find source ID from receiver_id. What is receiver_id? 158 // TODO: Build BluetoothLeBroadcastMetadata with the new bcast_code. 159 int sourceId = receiver_id; 160 BluetoothLeBroadcastMetadata metadata = null; 161 return bluetoothProxy.modifyBroadcastSource(sink, sourceId, metadata); 162 } 163 } 164