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.hfp; 18 19 import android.bluetooth.BluetoothDevice; 20 21 import java.util.Objects; 22 23 /** 24 * Callback events from native layer 25 */ 26 public class HeadsetStackEvent extends HeadsetMessageObject { 27 public static final int EVENT_TYPE_NONE = 0; 28 public static final int EVENT_TYPE_CONNECTION_STATE_CHANGED = 1; 29 public static final int EVENT_TYPE_AUDIO_STATE_CHANGED = 2; 30 public static final int EVENT_TYPE_VR_STATE_CHANGED = 3; 31 public static final int EVENT_TYPE_ANSWER_CALL = 4; 32 public static final int EVENT_TYPE_HANGUP_CALL = 5; 33 public static final int EVENT_TYPE_VOLUME_CHANGED = 6; 34 public static final int EVENT_TYPE_DIAL_CALL = 7; 35 public static final int EVENT_TYPE_SEND_DTMF = 8; 36 public static final int EVENT_TYPE_NOISE_REDUCTION = 9; 37 public static final int EVENT_TYPE_AT_CHLD = 10; 38 public static final int EVENT_TYPE_SUBSCRIBER_NUMBER_REQUEST = 11; 39 public static final int EVENT_TYPE_AT_CIND = 12; 40 public static final int EVENT_TYPE_AT_COPS = 13; 41 public static final int EVENT_TYPE_AT_CLCC = 14; 42 public static final int EVENT_TYPE_UNKNOWN_AT = 15; 43 public static final int EVENT_TYPE_KEY_PRESSED = 16; 44 public static final int EVENT_TYPE_WBS = 17; 45 public static final int EVENT_TYPE_BIND = 18; 46 public static final int EVENT_TYPE_BIEV = 19; 47 public static final int EVENT_TYPE_BIA = 20; 48 49 public final int type; 50 public final int valueInt; 51 public final int valueInt2; 52 public final String valueString; 53 public final HeadsetMessageObject valueObject; 54 public final BluetoothDevice device; 55 56 /** 57 * Create a headset stack event 58 * 59 * @param type type of the event 60 * @param device device of interest 61 */ HeadsetStackEvent(int type, BluetoothDevice device)62 public HeadsetStackEvent(int type, BluetoothDevice device) { 63 this(type, 0, 0, null, null, device); 64 } 65 66 /** 67 * Create a headset stack event 68 * 69 * @param type type of the event 70 * @param valueInt an integer value in the event 71 * @param device device of interest 72 */ HeadsetStackEvent(int type, int valueInt, BluetoothDevice device)73 public HeadsetStackEvent(int type, int valueInt, BluetoothDevice device) { 74 this(type, valueInt, 0, null, null, device); 75 } 76 77 /** 78 * Create a headset stack event 79 * 80 * @param type type of the event 81 * @param valueInt an integer value in the event 82 * @param valueInt2 another integer value in the event 83 * @param device device of interest 84 */ HeadsetStackEvent(int type, int valueInt, int valueInt2, BluetoothDevice device)85 public HeadsetStackEvent(int type, int valueInt, int valueInt2, BluetoothDevice device) { 86 this(type, valueInt, valueInt2, null, null, device); 87 } 88 89 /** 90 * Create a headset stack event 91 * 92 * @param type type of the event 93 * @param valueString an string value in the event 94 * @param device device of interest 95 */ HeadsetStackEvent(int type, String valueString, BluetoothDevice device)96 public HeadsetStackEvent(int type, String valueString, BluetoothDevice device) { 97 this(type, 0, 0, valueString, null, device); 98 } 99 100 /** 101 * Create a headset stack event 102 * 103 * @param type type of the event 104 * @param valueObject an object value in the event 105 * @param device device of interest 106 */ HeadsetStackEvent(int type, HeadsetMessageObject valueObject, BluetoothDevice device)107 public HeadsetStackEvent(int type, HeadsetMessageObject valueObject, BluetoothDevice device) { 108 this(type, 0, 0, null, valueObject, device); 109 } 110 111 /** 112 * Create a headset stack event 113 * 114 * @param type type of the event 115 * @param valueInt an integer value in the event 116 * @param valueInt2 another integer value in the event 117 * @param valueString a string value in the event 118 * @param valueObject an object value in the event 119 * @param device device of interest 120 */ HeadsetStackEvent(int type, int valueInt, int valueInt2, String valueString, HeadsetMessageObject valueObject, BluetoothDevice device)121 public HeadsetStackEvent(int type, int valueInt, int valueInt2, String valueString, 122 HeadsetMessageObject valueObject, BluetoothDevice device) { 123 this.type = type; 124 this.valueInt = valueInt; 125 this.valueInt2 = valueInt2; 126 this.valueString = valueString; 127 this.valueObject = valueObject; 128 this.device = Objects.requireNonNull(device); 129 } 130 131 /** 132 * Get a string that represents this event 133 * 134 * @return String that represents this event 135 */ getTypeString()136 public String getTypeString() { 137 switch (type) { 138 case EVENT_TYPE_NONE: 139 return "EVENT_TYPE_NONE"; 140 case EVENT_TYPE_CONNECTION_STATE_CHANGED: 141 return "EVENT_TYPE_CONNECTION_STATE_CHANGED"; 142 case EVENT_TYPE_AUDIO_STATE_CHANGED: 143 return "EVENT_TYPE_AUDIO_STATE_CHANGED"; 144 case EVENT_TYPE_VR_STATE_CHANGED: 145 return "EVENT_TYPE_VR_STATE_CHANGED"; 146 case EVENT_TYPE_ANSWER_CALL: 147 return "EVENT_TYPE_ANSWER_CALL"; 148 case EVENT_TYPE_HANGUP_CALL: 149 return "EVENT_TYPE_HANGUP_CALL"; 150 case EVENT_TYPE_VOLUME_CHANGED: 151 return "EVENT_TYPE_VOLUME_CHANGED"; 152 case EVENT_TYPE_DIAL_CALL: 153 return "EVENT_TYPE_DIAL_CALL"; 154 case EVENT_TYPE_SEND_DTMF: 155 return "EVENT_TYPE_SEND_DTMF"; 156 case EVENT_TYPE_NOISE_REDUCTION: 157 return "EVENT_TYPE_NOISE_REDUCTION"; 158 case EVENT_TYPE_AT_CHLD: 159 return "EVENT_TYPE_AT_CHLD"; 160 case EVENT_TYPE_SUBSCRIBER_NUMBER_REQUEST: 161 return "EVENT_TYPE_SUBSCRIBER_NUMBER_REQUEST"; 162 case EVENT_TYPE_AT_CIND: 163 return "EVENT_TYPE_AT_CIND"; 164 case EVENT_TYPE_AT_COPS: 165 return "EVENT_TYPE_AT_COPS"; 166 case EVENT_TYPE_AT_CLCC: 167 return "EVENT_TYPE_AT_CLCC"; 168 case EVENT_TYPE_UNKNOWN_AT: 169 return "EVENT_TYPE_UNKNOWN_AT"; 170 case EVENT_TYPE_KEY_PRESSED: 171 return "EVENT_TYPE_KEY_PRESSED"; 172 case EVENT_TYPE_WBS: 173 return "EVENT_TYPE_WBS"; 174 case EVENT_TYPE_BIND: 175 return "EVENT_TYPE_BIND"; 176 case EVENT_TYPE_BIEV: 177 return "EVENT_TYPE_BIEV"; 178 case EVENT_TYPE_BIA: 179 return "EVENT_TYPE_BIA"; 180 default: 181 return "UNKNOWN"; 182 } 183 } 184 185 @Override buildString(StringBuilder builder)186 public void buildString(StringBuilder builder) { 187 if (builder == null) { 188 return; 189 } 190 builder.append(getTypeString()) 191 .append("[") 192 .append(type) 193 .append("]") 194 .append(", valInt=") 195 .append(valueInt) 196 .append(", valInt2=") 197 .append(valueInt2) 198 .append(", valString=") 199 .append(valueString) 200 .append(", valObject=") 201 .append(valueObject) 202 .append(", device=") 203 .append(device); 204 } 205 } 206