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.vc; 19 20 import android.bluetooth.BluetoothDevice; 21 22 public class VolumeControlStackEvent { 23 // Event types for STACK_EVENT message (coming from native) 24 private static final int EVENT_TYPE_NONE = 0; 25 public static final int EVENT_TYPE_CONNECTION_STATE_CHANGED = 1; 26 public static final int EVENT_TYPE_VOLUME_STATE_CHANGED = 2; 27 public static final int EVENT_TYPE_DEVICE_AVAILABLE = 3; 28 public static final int EVENT_TYPE_EXT_AUDIO_OUT_VOL_OFFSET_CHANGED = 4; 29 public static final int EVENT_TYPE_EXT_AUDIO_OUT_LOCATION_CHANGED = 5; 30 public static final int EVENT_TYPE_EXT_AUDIO_OUT_DESCRIPTION_CHANGED = 6; 31 32 // Do not modify without updating the HAL bt_vc_aid.h files. 33 // Match up with enum class ConnectionState of bt_vc_aid.h. 34 static final int CONNECTION_STATE_DISCONNECTED = 0; 35 static final int CONNECTION_STATE_CONNECTING = 1; 36 static final int CONNECTION_STATE_CONNECTED = 2; 37 static final int CONNECTION_STATE_DISCONNECTING = 3; 38 39 public int type; 40 public BluetoothDevice device; 41 public int valueInt1; 42 public int valueInt2; 43 public boolean valueBool1; 44 public boolean valueBool2; 45 public String valueString1; 46 47 /* Might need more for other callbacks*/ 48 VolumeControlStackEvent(int type)49 VolumeControlStackEvent(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("VolumeControlStackEvent {type:" + eventTypeToString(type)); 58 result.append(", device:" + device); 59 result.append(", valueInt1:" + eventTypeValue1ToString(type, valueInt1)); 60 result.append(", valueInt2:" + eventTypeValue2ToString(type, valueInt2)); 61 result.append(", valueBool1:" + eventTypeValueBool1ToString(type, valueBool1)); 62 result.append(", valueBool2:" + eventTypeValueBool2ToString(type, valueBool2)); 63 result.append(", valueString1:" + eventTypeString1ToString(type, valueString1)); 64 result.append("}"); 65 return result.toString(); 66 } 67 eventTypeToString(int type)68 private static String eventTypeToString(int type) { 69 switch (type) { 70 case EVENT_TYPE_NONE: 71 return "EVENT_TYPE_NONE"; 72 case EVENT_TYPE_CONNECTION_STATE_CHANGED: 73 return "EVENT_TYPE_CONNECTION_STATE_CHANGED"; 74 case EVENT_TYPE_VOLUME_STATE_CHANGED: 75 return "EVENT_TYPE_VOLUME_STATE_CHANGED"; 76 case EVENT_TYPE_DEVICE_AVAILABLE: 77 return "EVENT_TYPE_DEVICE_AVAILABLE"; 78 case EVENT_TYPE_EXT_AUDIO_OUT_VOL_OFFSET_CHANGED: 79 return "EVENT_TYPE_EXT_AUDIO_OUT_VOL_OFFSET_CHANGED"; 80 case EVENT_TYPE_EXT_AUDIO_OUT_LOCATION_CHANGED: 81 return "EVENT_TYPE_EXT_AUDIO_OUT_LOCATION_CHANGED"; 82 case EVENT_TYPE_EXT_AUDIO_OUT_DESCRIPTION_CHANGED: 83 return "EVENT_TYPE_EXT_AUDIO_OUT_DESCRIPTION_CHANGED"; 84 default: 85 return "EVENT_TYPE_UNKNOWN:" + type; 86 } 87 } 88 eventTypeValue1ToString(int type, int value)89 private static String eventTypeValue1ToString(int type, int value) { 90 switch (type) { 91 case EVENT_TYPE_CONNECTION_STATE_CHANGED: 92 switch (value) { 93 case CONNECTION_STATE_DISCONNECTED: 94 return "CONNECTION_STATE_DISCONNECTED"; 95 case CONNECTION_STATE_CONNECTING: 96 return "CONNECTION_STATE_CONNECTING"; 97 case CONNECTION_STATE_CONNECTED: 98 return "CONNECTION_STATE_CONNECTED"; 99 case CONNECTION_STATE_DISCONNECTING: 100 return "CONNECTION_STATE_DISCONNECTING"; 101 default: 102 return "UNKNOWN"; 103 } 104 case EVENT_TYPE_VOLUME_STATE_CHANGED: 105 return "{group_id:" + value + "}"; 106 case EVENT_TYPE_DEVICE_AVAILABLE: 107 return "{num_ext_outputs:" + value + "}"; 108 case EVENT_TYPE_EXT_AUDIO_OUT_VOL_OFFSET_CHANGED: 109 case EVENT_TYPE_EXT_AUDIO_OUT_LOCATION_CHANGED: 110 case EVENT_TYPE_EXT_AUDIO_OUT_DESCRIPTION_CHANGED: 111 return "{ext output id:" + value + "}"; 112 default: 113 break; 114 } 115 return Integer.toString(value); 116 } 117 eventTypeValue2ToString(int type, int value)118 private static String eventTypeValue2ToString(int type, int value) { 119 switch (type) { 120 case EVENT_TYPE_CONNECTION_STATE_CHANGED: 121 switch (value) { 122 case CONNECTION_STATE_DISCONNECTED: 123 return "CONNECTION_STATE_DISCONNECTED"; 124 case CONNECTION_STATE_CONNECTING: 125 return "CONNECTION_STATE_CONNECTING"; 126 case CONNECTION_STATE_CONNECTED: 127 return "CONNECTION_STATE_CONNECTED"; 128 case CONNECTION_STATE_DISCONNECTING: 129 return "CONNECTION_STATE_DISCONNECTING"; 130 default: 131 return "UNKNOWN"; 132 } 133 case EVENT_TYPE_VOLUME_STATE_CHANGED: 134 return "{volume:" + value + "}"; 135 default: 136 break; 137 } 138 return Integer.toString(value); 139 } 140 eventTypeValueBool1ToString(int type, boolean value)141 private static String eventTypeValueBool1ToString(int type, boolean value) { 142 switch (type) { 143 case EVENT_TYPE_VOLUME_STATE_CHANGED: 144 return "{muted:" + value + "}"; 145 default: 146 break; 147 } 148 return Boolean.toString(value); 149 } 150 eventTypeValueBool2ToString(int type, boolean value)151 private static String eventTypeValueBool2ToString(int type, boolean value) { 152 switch (type) { 153 case EVENT_TYPE_VOLUME_STATE_CHANGED: 154 return "{isAutonomous:" + value + "}"; 155 default: 156 break; 157 } 158 return Boolean.toString(value); 159 } 160 eventTypeString1ToString(int type, String value)161 private static String eventTypeString1ToString(int type, String value) { 162 switch (type) { 163 case EVENT_TYPE_EXT_AUDIO_OUT_DESCRIPTION_CHANGED: 164 return "{descrition:" + value + "}"; 165 default: 166 break; 167 } 168 return value; 169 } 170 } 171