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.BluetoothLeBroadcastMetadata; 22 import android.bluetooth.BluetoothLeBroadcastSettings; 23 24 import androidx.annotation.NonNull; 25 import androidx.core.util.Pair; 26 import androidx.lifecycle.AndroidViewModel; 27 import androidx.lifecycle.LiveData; 28 29 import java.util.List; 30 31 public class BroadcasterViewModel extends AndroidViewModel { 32 private final BluetoothProxy mBluetooth; 33 private final Application mApplication; 34 BroadcasterViewModel(@onNull Application application)35 public BroadcasterViewModel(@NonNull Application application) { 36 super(application); 37 mApplication = application; 38 39 mBluetooth = BluetoothProxy.getBluetoothProxy(application); 40 mBluetooth.initProfiles(); 41 } 42 startBroadcast(BluetoothLeBroadcastSettings settings)43 public boolean startBroadcast(BluetoothLeBroadcastSettings settings) { 44 return mBluetooth.startBroadcast(settings); 45 } 46 stopBroadcast(int broadcastId)47 public boolean stopBroadcast(int broadcastId) { 48 return mBluetooth.stopBroadcast(broadcastId); 49 } 50 updateBroadcast(int broadcastId, BluetoothLeBroadcastSettings settings)51 public boolean updateBroadcast(int broadcastId, BluetoothLeBroadcastSettings settings) { 52 return mBluetooth.updateBroadcast(broadcastId, settings); 53 } 54 getMaximumNumberOfBroadcast()55 public int getMaximumNumberOfBroadcast() { 56 return mBluetooth.getMaximumNumberOfBroadcast(); 57 } 58 getAllBroadcastMetadata()59 public List<BluetoothLeBroadcastMetadata> getAllBroadcastMetadata() { 60 return mBluetooth.getAllLocalBroadcasts(); 61 } 62 getBroadcastCount()63 public int getBroadcastCount() { 64 return mBluetooth.getAllLocalBroadcasts().size(); 65 } 66 getBroadcastUpdateMetadataLive()67 public LiveData<BluetoothLeBroadcastMetadata> getBroadcastUpdateMetadataLive() { 68 return mBluetooth.getBroadcastUpdateMetadataLive(); 69 } 70 71 public LiveData<Pair<Integer /* reason */, Integer /* broadcastId */>> getBroadcastPlaybackStartedMutableLive()72 getBroadcastPlaybackStartedMutableLive() { 73 return mBluetooth.getBroadcastPlaybackStartedMutableLive(); 74 } 75 76 public LiveData<Pair<Integer /* reason */, Integer /* broadcastId */>> getBroadcastPlaybackStoppedMutableLive()77 getBroadcastPlaybackStoppedMutableLive() { 78 return mBluetooth.getBroadcastPlaybackStoppedMutableLive(); 79 } 80 getBroadcastAddedMutableLive()81 public LiveData<Integer /* broadcastId */> getBroadcastAddedMutableLive() { 82 return mBluetooth.getBroadcastAddedMutableLive(); 83 } 84 85 public LiveData<Pair<Integer /* reason */, Integer /* broadcastId */>> getBroadcastRemovedMutableLive()86 getBroadcastRemovedMutableLive() { 87 return mBluetooth.getBroadcastRemovedMutableLive(); 88 } 89 getBroadcastStatusMutableLive()90 public LiveData<String> getBroadcastStatusMutableLive() { 91 return mBluetooth.getBroadcastStatusMutableLive(); 92 } 93 94 @Override onCleared()95 public void onCleared() {} 96 } 97