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