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         String s = "StackEvent<device=" + mDevice + ", type =";
51         switch (mType) {
52             case EVENT_TYPE_CONNECTION_STATE_CHANGED:
53                 s += "EVENT_TYPE_CONNECTION_STATE_CHANGED, state=" + mState;
54                 break;
55             case EVENT_TYPE_AUDIO_STATE_CHANGED:
56                 s += "EVENT_TYPE_AUDIO_STATE_CHANGED, state=" + mState;
57                 break;
58             case EVENT_TYPE_AUDIO_CONFIG_CHANGED:
59                 s +=
60                         "EVENT_TYPE_AUDIO_CONFIG_CHANGED, sampleRate="
61                                 + mSampleRate
62                                 + ", channelCount="
63                                 + mChannelCount;
64                 break;
65             default:
66                 s += "Unknown";
67                 break;
68         }
69         s += ">";
70         return s;
71     }
72 
connectionStateChanged(BluetoothDevice device, int state)73     static StackEvent connectionStateChanged(BluetoothDevice device, int state) {
74         StackEvent event = new StackEvent(StackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED);
75         event.mDevice = device;
76         event.mState = state;
77         return event;
78     }
79 
audioStateChanged(BluetoothDevice device, int state)80     static StackEvent audioStateChanged(BluetoothDevice device, int state) {
81         StackEvent event = new StackEvent(StackEvent.EVENT_TYPE_AUDIO_STATE_CHANGED);
82         event.mDevice = device;
83         event.mState = state;
84         return event;
85     }
86 
audioConfigChanged(BluetoothDevice device, int sampleRate, int channelCount)87     static StackEvent audioConfigChanged(BluetoothDevice device, int sampleRate, int channelCount) {
88         StackEvent event = new StackEvent(StackEvent.EVENT_TYPE_AUDIO_CONFIG_CHANGED);
89         event.mDevice = device;
90         event.mSampleRate = sampleRate;
91         event.mChannelCount = channelCount;
92         return event;
93     }
94 }
95