• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 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 
17 package com.android.bluetooth.a2dp;
18 
19 import android.bluetooth.BluetoothCodecStatus;
20 import android.bluetooth.BluetoothDevice;
21 
22 /**
23  * Stack event sent via a callback from JNI to Java, or generated
24  * internally by the A2DP State Machine.
25  */
26 public class A2dpStackEvent {
27     // Event types for STACK_EVENT message (coming from native)
28     private static final int EVENT_TYPE_NONE = 0;
29     public static final int EVENT_TYPE_CONNECTION_STATE_CHANGED = 1;
30     public static final int EVENT_TYPE_AUDIO_STATE_CHANGED = 2;
31     public static final int EVENT_TYPE_CODEC_CONFIG_CHANGED = 3;
32 
33     // Do not modify without updating the HAL bt_av.h files.
34     // Match up with btav_connection_state_t enum of bt_av.h
35     static final int CONNECTION_STATE_DISCONNECTED = 0;
36     static final int CONNECTION_STATE_CONNECTING = 1;
37     static final int CONNECTION_STATE_CONNECTED = 2;
38     static final int CONNECTION_STATE_DISCONNECTING = 3;
39     // Match up with btav_audio_state_t enum of bt_av.h
40     static final int AUDIO_STATE_REMOTE_SUSPEND = 0;
41     static final int AUDIO_STATE_STOPPED = 1;
42     static final int AUDIO_STATE_STARTED = 2;
43 
44     public int type = EVENT_TYPE_NONE;
45     public BluetoothDevice device;
46     public int valueInt = 0;
47     public BluetoothCodecStatus codecStatus;
48 
A2dpStackEvent(int type)49     A2dpStackEvent(int type) {
50         this.type = type;
51     }
52 
53     @Override
toString()54     public String toString() {
55         // event dump
56         StringBuilder result = new StringBuilder();
57         result.append("A2dpStackEvent {type:" + eventTypeToString(type));
58         result.append(", device:" + device);
59         result.append(", value1:" + eventTypeValueIntToString(type, valueInt));
60         if (codecStatus != null) {
61             result.append(", codecStatus:" + codecStatus);
62         }
63         result.append("}");
64         return result.toString();
65     }
66 
eventTypeToString(int type)67     private static String eventTypeToString(int type) {
68         switch (type) {
69             case EVENT_TYPE_NONE:
70                 return "EVENT_TYPE_NONE";
71             case EVENT_TYPE_CONNECTION_STATE_CHANGED:
72                 return "EVENT_TYPE_CONNECTION_STATE_CHANGED";
73             case EVENT_TYPE_AUDIO_STATE_CHANGED:
74                 return "EVENT_TYPE_AUDIO_STATE_CHANGED";
75             case EVENT_TYPE_CODEC_CONFIG_CHANGED:
76                 return "EVENT_TYPE_CODEC_CONFIG_CHANGED";
77             default:
78                 return "EVENT_TYPE_UNKNOWN:" + type;
79         }
80     }
81 
eventTypeValueIntToString(int type, int value)82     private static String eventTypeValueIntToString(int type, int value) {
83         switch (type) {
84             case EVENT_TYPE_CONNECTION_STATE_CHANGED:
85                 switch (value) {
86                     case CONNECTION_STATE_DISCONNECTED:
87                         return "DISCONNECTED";
88                     case CONNECTION_STATE_CONNECTING:
89                         return "CONNECTING";
90                     case CONNECTION_STATE_CONNECTED:
91                         return "CONNECTED";
92                     case CONNECTION_STATE_DISCONNECTING:
93                         return "DISCONNECTING";
94                     default:
95                         break;
96                 }
97                 break;
98             case EVENT_TYPE_AUDIO_STATE_CHANGED:
99                 switch (value) {
100                     case AUDIO_STATE_REMOTE_SUSPEND:
101                         return "REMOTE_SUSPEND";
102                     case AUDIO_STATE_STOPPED:
103                         return "STOPPED";
104                     case AUDIO_STATE_STARTED:
105                         return "STARTED";
106                     default:
107                         break;
108                 }
109                 break;
110             default:
111                 break;
112         }
113         return Integer.toString(value);
114     }
115 }
116