HeadsetStackEvent.java revision 764073b18d2a0a44a021325db841a6b33e26241b
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 17package com.android.bluetooth.hfp; 18 19import android.bluetooth.BluetoothDevice; 20 21import java.util.Objects; 22 23/** 24 * Callback events from native layer 25 */ 26public 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_NOICE_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 48 public int type = EVENT_TYPE_NONE; 49 public int valueInt = 0; 50 public int valueInt2 = 0; 51 public String valueString = null; 52 public BluetoothDevice device = null; 53 54 /** 55 * Create a headset stack event 56 * 57 * @param type type of the event 58 * @param device device of interest 59 */ 60 public HeadsetStackEvent(int type, BluetoothDevice device) { 61 this.type = type; 62 this.device = Objects.requireNonNull(device); 63 } 64 65 /** 66 * Create a headset stack event 67 * 68 * @param type type of the event 69 * @param valueInt an integer value in the event 70 * @param device device of interest 71 */ 72 public HeadsetStackEvent(int type, int valueInt, BluetoothDevice device) { 73 this.type = type; 74 this.valueInt = valueInt; 75 this.device = Objects.requireNonNull(device); 76 } 77 78 /** 79 * Create a headset stack event 80 * 81 * @param type type of the event 82 * @param valueInt an integer value in the event 83 * @param valueInt2 another integer value in the event 84 * @param device device of interest 85 */ 86 public HeadsetStackEvent(int type, int valueInt, int valueInt2, BluetoothDevice device) { 87 this.type = type; 88 this.valueInt = valueInt; 89 this.valueInt2 = valueInt2; 90 this.device = Objects.requireNonNull(device); 91 } 92 93 /** 94 * Create a headset stack event 95 * 96 * @param type type of the event 97 * @param valueString an integer value in the event 98 * @param device device of interest 99 */ 100 public HeadsetStackEvent(int type, String valueString, BluetoothDevice device) { 101 this.type = type; 102 this.valueString = valueString; 103 this.device = Objects.requireNonNull(device); 104 } 105 106 /** 107 * Get a string that represents this event 108 * 109 * @return String that represents this event 110 */ 111 public String getTypeString() { 112 switch (type) { 113 case EVENT_TYPE_NONE: 114 return "EVENT_TYPE_NONE"; 115 case EVENT_TYPE_CONNECTION_STATE_CHANGED: 116 return "EVENT_TYPE_CONNECTION_STATE_CHANGED"; 117 case EVENT_TYPE_AUDIO_STATE_CHANGED: 118 return "EVENT_TYPE_AUDIO_STATE_CHANGED"; 119 case EVENT_TYPE_VR_STATE_CHANGED: 120 return "EVENT_TYPE_VR_STATE_CHANGED"; 121 case EVENT_TYPE_ANSWER_CALL: 122 return "EVENT_TYPE_ANSWER_CALL"; 123 case EVENT_TYPE_HANGUP_CALL: 124 return "EVENT_TYPE_HANGUP_CALL"; 125 case EVENT_TYPE_VOLUME_CHANGED: 126 return "EVENT_TYPE_VOLUME_CHANGED"; 127 case EVENT_TYPE_DIAL_CALL: 128 return "EVENT_TYPE_DIAL_CALL"; 129 case EVENT_TYPE_SEND_DTMF: 130 return "EVENT_TYPE_SEND_DTMF"; 131 case EVENT_TYPE_NOICE_REDUCTION: 132 return "EVENT_TYPE_NOICE_REDUCTION"; 133 case EVENT_TYPE_AT_CHLD: 134 return "EVENT_TYPE_AT_CHLD"; 135 case EVENT_TYPE_SUBSCRIBER_NUMBER_REQUEST: 136 return "EVENT_TYPE_SUBSCRIBER_NUMBER_REQUEST"; 137 case EVENT_TYPE_AT_CIND: 138 return "EVENT_TYPE_AT_CIND"; 139 case EVENT_TYPE_AT_COPS: 140 return "EVENT_TYPE_AT_COPS"; 141 case EVENT_TYPE_AT_CLCC: 142 return "EVENT_TYPE_AT_CLCC"; 143 case EVENT_TYPE_UNKNOWN_AT: 144 return "EVENT_TYPE_UNKNOWN_AT"; 145 case EVENT_TYPE_KEY_PRESSED: 146 return "EVENT_TYPE_KEY_PRESSED"; 147 case EVENT_TYPE_WBS: 148 return "EVENT_TYPE_WBS"; 149 case EVENT_TYPE_BIND: 150 return "EVENT_TYPE_BIND"; 151 case EVENT_TYPE_BIEV: 152 return "EVENT_TYPE_BIEV"; 153 default: 154 return "UNKNOWN"; 155 } 156 } 157 158 @Override 159 public void buildString(StringBuilder builder) { 160 if (builder == null) { 161 return; 162 } 163 builder.append(getTypeString()) 164 .append("[") 165 .append(type) 166 .append("]") 167 .append(", valInt=") 168 .append(valueInt) 169 .append(", valInt2=") 170 .append(valueInt2) 171 .append(", valString=") 172 .append(valueString) 173 .append(", device=") 174 .append(device); 175 } 176} 177