1 /* 2 * Copyright (C) 2018 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 package com.android.bluetooth.a2dpsink; 17 18 import android.bluetooth.BluetoothDevice; 19 20 final class StackEvent { 21 // Event types for STACK_EVENT message 22 static final int EVENT_TYPE_NONE = 0; 23 static final int EVENT_TYPE_CONNECTION_STATE_CHANGED = 1; 24 static final int EVENT_TYPE_AUDIO_STATE_CHANGED = 2; 25 static final int EVENT_TYPE_AUDIO_CONFIG_CHANGED = 3; 26 27 // match up with btav_connection_state_t enum of bt_av.h 28 static final int CONNECTION_STATE_DISCONNECTED = 0; 29 static final int CONNECTION_STATE_CONNECTING = 1; 30 static final int CONNECTION_STATE_CONNECTED = 2; 31 static final int CONNECTION_STATE_DISCONNECTING = 3; 32 33 // match up with btav_audio_state_t enum of bt_av.h 34 static final int AUDIO_STATE_REMOTE_SUSPEND = 0; 35 static final int AUDIO_STATE_STOPPED = 1; 36 static final int AUDIO_STATE_STARTED = 2; 37 38 int mType = EVENT_TYPE_NONE; 39 BluetoothDevice mDevice = null; 40 int mState = 0; 41 int mSampleRate = 0; 42 int mChannelCount = 0; 43 StackEvent(int type)44 private StackEvent(int type) { 45 this.mType = type; 46 } 47 48 @Override toString()49 public String toString() { 50 switch (mType) { 51 case EVENT_TYPE_CONNECTION_STATE_CHANGED: 52 return "EVENT_TYPE_CONNECTION_STATE_CHANGED " + mState; 53 case EVENT_TYPE_AUDIO_STATE_CHANGED: 54 return "EVENT_TYPE_AUDIO_STATE_CHANGED " + mState; 55 case EVENT_TYPE_AUDIO_CONFIG_CHANGED: 56 return "EVENT_TYPE_AUDIO_CONFIG_CHANGED " + mSampleRate + ":" + mChannelCount; 57 default: 58 return "Unknown"; 59 } 60 } 61 connectionStateChanged(BluetoothDevice device, int state)62 static StackEvent connectionStateChanged(BluetoothDevice device, int state) { 63 StackEvent event = new StackEvent(StackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED); 64 event.mDevice = device; 65 event.mState = state; 66 return event; 67 } 68 audioStateChanged(BluetoothDevice device, int state)69 static StackEvent audioStateChanged(BluetoothDevice device, int state) { 70 StackEvent event = new StackEvent(StackEvent.EVENT_TYPE_AUDIO_STATE_CHANGED); 71 event.mDevice = device; 72 event.mState = state; 73 return event; 74 } 75 audioConfigChanged(BluetoothDevice device, int sampleRate, int channelCount)76 static StackEvent audioConfigChanged(BluetoothDevice device, int sampleRate, 77 int channelCount) { 78 StackEvent event = new StackEvent(StackEvent.EVENT_TYPE_AUDIO_CONFIG_CHANGED); 79 event.mDevice = device; 80 event.mSampleRate = sampleRate; 81 event.mChannelCount = channelCount; 82 return event; 83 } 84 } 85