1 /* 2 * Copyright 2020 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.le_audio; 19 20 import android.bluetooth.BluetoothDevice; 21 22 /** 23 * Stack event sent via a callback from JNI to Java, or generated 24 * internally by the LeAudio State Machine. 25 */ 26 public class LeAudioStackEvent { 27 // Event types for STACK_EVENT message (coming from native in bt_le_audio.h) 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_GROUP_STATUS_CHANGED = 2; 31 public static final int EVENT_TYPE_AUDIO_CONF_CHANGED = 4; 32 public static final int EVENT_TYPE_SET_MEMBER_AVAILABLE = 5; 33 // -------- DO NOT PUT ANY NEW UNICAST EVENTS BELOW THIS LINE------------- 34 public static final int EVENT_TYPE_UNICAST_MAX = 7; 35 36 // Do not modify without updating the HAL bt_le_audio.h files. 37 // Match up with GroupStatus enum of bt_le_audio.h 38 static final int CONNECTION_STATE_DISCONNECTED = 0; 39 static final int CONNECTION_STATE_CONNECTING = 1; 40 static final int CONNECTION_STATE_CONNECTED = 2; 41 static final int CONNECTION_STATE_DISCONNECTING = 3; 42 43 static final int GROUP_STATUS_IDLE = 0; 44 static final int GROUP_STATUS_STREAMING = 1; 45 static final int GROUP_STATUS_SUSPENDED = 2; 46 static final int GROUP_STATUS_RECONFIGURED = 3; 47 static final int GROUP_STATUS_DESTROYED = 4; 48 49 public int type = EVENT_TYPE_NONE; 50 public BluetoothDevice device; 51 public int valueInt1 = 0; 52 public int valueInt2 = 0; 53 public int valueInt3 = 0; 54 public int valueInt4 = 0; 55 LeAudioStackEvent(int type)56 LeAudioStackEvent(int type) { 57 this.type = type; 58 } 59 60 @Override toString()61 public String toString() { 62 // event dump 63 StringBuilder result = new StringBuilder(); 64 result.append("LeAudioStackEvent {type:" + eventTypeToString(type)); 65 result.append(", device:" + device); 66 result.append(", value1:" + eventTypeValue1ToString(type, valueInt1)); 67 result.append(", value2:" + eventTypeValue2ToString(type, valueInt2)); 68 result.append(", value3:" + eventTypeValue3ToString(type, valueInt3)); 69 result.append(", value4:" + eventTypeValue4ToString(type, valueInt4)); 70 result.append("}"); 71 return result.toString(); 72 } 73 eventTypeToString(int type)74 private static String eventTypeToString(int type) { 75 switch (type) { 76 case EVENT_TYPE_NONE: 77 return "EVENT_TYPE_NONE"; 78 case EVENT_TYPE_CONNECTION_STATE_CHANGED: 79 return "EVENT_TYPE_CONNECTION_STATE_CHANGED"; 80 case EVENT_TYPE_GROUP_STATUS_CHANGED: 81 return "EVENT_TYPE_GROUP_STATUS_CHANGED"; 82 case EVENT_TYPE_AUDIO_CONF_CHANGED: 83 return "EVENT_TYPE_AUDIO_CONF_CHANGED"; 84 case EVENT_TYPE_SET_MEMBER_AVAILABLE: 85 return "EVENT_TYPE_SET_MEMBER_AVAILABLE"; 86 default: 87 return "EVENT_TYPE_UNKNOWN:" + type; 88 } 89 } 90 eventTypeValue1ToString(int type, int value)91 private static String eventTypeValue1ToString(int type, int value) { 92 switch (type) { 93 case EVENT_TYPE_CONNECTION_STATE_CHANGED: 94 switch (value) { 95 case CONNECTION_STATE_DISCONNECTED: 96 return "CONNECTION_STATE_DISCONNECTED"; 97 case CONNECTION_STATE_CONNECTING: 98 return "CONNECTION_STATE_CONNECTING"; 99 case CONNECTION_STATE_CONNECTED: 100 return "CONNECTION_STATE_CONNECTED"; 101 case CONNECTION_STATE_DISCONNECTING: 102 return "CONNECTION_STATE_DISCONNECTING"; 103 default: 104 return "UNKNOWN"; 105 } 106 case EVENT_TYPE_GROUP_STATUS_CHANGED: 107 // same as EVENT_TYPE_GROUP_STATUS_CHANGED 108 case EVENT_TYPE_SET_MEMBER_AVAILABLE: 109 // same as EVENT_TYPE_GROUP_STATUS_CHANGED 110 case EVENT_TYPE_AUDIO_CONF_CHANGED: 111 // FIXME: It should have proper direction names here 112 return "{direction:" + value + "}"; 113 default: 114 break; 115 } 116 return Integer.toString(value); 117 } 118 eventTypeValue2ToString(int type, int value)119 private static String eventTypeValue2ToString(int type, int value) { 120 switch (type) { 121 case EVENT_TYPE_GROUP_STATUS_CHANGED: 122 switch (value) { 123 case GROUP_STATUS_IDLE: 124 return "GROUP_STATUS_IDLE"; 125 case GROUP_STATUS_STREAMING: 126 return "GROUP_STATUS_STREAMING"; 127 case GROUP_STATUS_SUSPENDED: 128 return "GROUP_STATUS_SUSPENDED"; 129 case GROUP_STATUS_RECONFIGURED: 130 return "GROUP_STATUS_RECONFIGURED"; 131 case GROUP_STATUS_DESTROYED: 132 return "GROUP_STATUS_DESTROYED"; 133 default: 134 break; 135 } 136 break; 137 case EVENT_TYPE_AUDIO_CONF_CHANGED: 138 return "{group_id:" + Integer.toString(value) + "}"; 139 default: 140 break; 141 } 142 return Integer.toString(value); 143 } 144 eventTypeValue3ToString(int type, int value)145 private static String eventTypeValue3ToString(int type, int value) { 146 switch (type) { 147 case EVENT_TYPE_GROUP_STATUS_CHANGED: 148 return "{group_flags:" + Integer.toString(value) + "}"; 149 case EVENT_TYPE_AUDIO_CONF_CHANGED: 150 // FIXME: It should have proper location names here 151 return "{snk_audio_loc:" + value + "}"; 152 default: 153 break; 154 } 155 return Integer.toString(value); 156 } 157 eventTypeValue4ToString(int type, int value)158 private static String eventTypeValue4ToString(int type, int value) { 159 switch (type) { 160 case EVENT_TYPE_AUDIO_CONF_CHANGED: 161 // FIXME: It should have proper location names here 162 return "{src_audio_loc:" + value + "}"; 163 default: 164 break; 165 } 166 return Integer.toString(value); 167 } 168 } 169