1 /* 2 * Copyright (c) 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 // Defines an event that is sent via a callback from JNI -> Java. 18 // 19 // See examples in NativeInterface.java 20 package com.android.bluetooth.hfpclient; 21 22 import android.bluetooth.BluetoothDevice; 23 24 public class StackEvent { 25 // Type of event that signifies a native event and consumed by state machine 26 public static final int STACK_EVENT = 100; 27 28 // Event types for STACK_EVENT message (coming from native) 29 public static final int EVENT_TYPE_NONE = 0; 30 public static final int EVENT_TYPE_CONNECTION_STATE_CHANGED = 1; 31 public static final int EVENT_TYPE_AUDIO_STATE_CHANGED = 2; 32 public static final int EVENT_TYPE_VR_STATE_CHANGED = 3; 33 public static final int EVENT_TYPE_NETWORK_STATE = 4; 34 public static final int EVENT_TYPE_ROAMING_STATE = 5; 35 public static final int EVENT_TYPE_NETWORK_SIGNAL = 6; 36 public static final int EVENT_TYPE_BATTERY_LEVEL = 7; 37 public static final int EVENT_TYPE_OPERATOR_NAME = 8; 38 public static final int EVENT_TYPE_CALL = 9; 39 public static final int EVENT_TYPE_CALLSETUP = 10; 40 public static final int EVENT_TYPE_CALLHELD = 11; 41 public static final int EVENT_TYPE_RESP_AND_HOLD = 12; 42 public static final int EVENT_TYPE_CLIP = 13; 43 public static final int EVENT_TYPE_CALL_WAITING = 14; 44 public static final int EVENT_TYPE_CURRENT_CALLS = 15; 45 public static final int EVENT_TYPE_VOLUME_CHANGED = 16; 46 public static final int EVENT_TYPE_CMD_RESULT = 17; 47 public static final int EVENT_TYPE_SUBSCRIBER_INFO = 18; 48 public static final int EVENT_TYPE_IN_BAND_RINGTONE = 19; 49 public static final int EVENT_TYPE_RING_INDICATION = 21; 50 public static final int EVENT_TYPE_UNKNOWN_EVENT = 22; 51 52 public int type = EVENT_TYPE_NONE; 53 public int valueInt = 0; 54 public int valueInt2 = 0; 55 public int valueInt3 = 0; 56 public int valueInt4 = 0; 57 public String valueString = null; 58 public BluetoothDevice device = null; 59 StackEvent(int type)60 StackEvent(int type) { 61 this.type = type; 62 } 63 64 @Override toString()65 public String toString() { 66 // event dump 67 StringBuilder result = new StringBuilder(); 68 result.append("StackEvent {type:" + eventTypeToString(type)); 69 result.append(", value1:" + valueInt); 70 result.append(", value2:" + valueInt2); 71 result.append(", value3:" + valueInt3); 72 result.append(", value4:" + valueInt4); 73 result.append(", string: \"" + valueString + "\""); 74 result.append(", device:" + device + "}"); 75 return result.toString(); 76 } 77 78 // for debugging only eventTypeToString(int type)79 private static String eventTypeToString(int type) { 80 switch (type) { 81 case EVENT_TYPE_NONE: 82 return "EVENT_TYPE_NONE"; 83 case EVENT_TYPE_CONNECTION_STATE_CHANGED: 84 return "EVENT_TYPE_CONNECTION_STATE_CHANGED"; 85 case EVENT_TYPE_AUDIO_STATE_CHANGED: 86 return "EVENT_TYPE_AUDIO_STATE_CHANGED"; 87 case EVENT_TYPE_NETWORK_STATE: 88 return "EVENT_TYPE_NETWORK_STATE"; 89 case EVENT_TYPE_ROAMING_STATE: 90 return "EVENT_TYPE_ROAMING_STATE"; 91 case EVENT_TYPE_NETWORK_SIGNAL: 92 return "EVENT_TYPE_NETWORK_SIGNAL"; 93 case EVENT_TYPE_BATTERY_LEVEL: 94 return "EVENT_TYPE_BATTERY_LEVEL"; 95 case EVENT_TYPE_OPERATOR_NAME: 96 return "EVENT_TYPE_OPERATOR_NAME"; 97 case EVENT_TYPE_CALL: 98 return "EVENT_TYPE_CALL"; 99 case EVENT_TYPE_CALLSETUP: 100 return "EVENT_TYPE_CALLSETUP"; 101 case EVENT_TYPE_CALLHELD: 102 return "EVENT_TYPE_CALLHELD"; 103 case EVENT_TYPE_CLIP: 104 return "EVENT_TYPE_CLIP"; 105 case EVENT_TYPE_CALL_WAITING: 106 return "EVENT_TYPE_CALL_WAITING"; 107 case EVENT_TYPE_CURRENT_CALLS: 108 return "EVENT_TYPE_CURRENT_CALLS"; 109 case EVENT_TYPE_VOLUME_CHANGED: 110 return "EVENT_TYPE_VOLUME_CHANGED"; 111 case EVENT_TYPE_CMD_RESULT: 112 return "EVENT_TYPE_CMD_RESULT"; 113 case EVENT_TYPE_SUBSCRIBER_INFO: 114 return "EVENT_TYPE_SUBSCRIBER_INFO"; 115 case EVENT_TYPE_RESP_AND_HOLD: 116 return "EVENT_TYPE_RESP_AND_HOLD"; 117 case EVENT_TYPE_RING_INDICATION: 118 return "EVENT_TYPE_RING_INDICATION"; 119 default: 120 return "EVENT_TYPE_UNKNOWN:" + type; 121 } 122 } 123 } 124 125