Home | History | Annotate | Download | only in hearingaid
      1 /*
      2  * Copyright 2018 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.hearingaid;
     18 
     19 import android.bluetooth.BluetoothDevice;
     20 
     21 /**
     22  * Stack event sent via a callback from JNI to Java, or generated
     23  * internally by the Hearing Aid State Machine.
     24  */
     25 public class HearingAidStackEvent {
     26     // Event types for STACK_EVENT message (coming from native)
     27     private 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_DEVICE_AVAILABLE = 2;
     30 
     31     // Do not modify without updating the HAL bt_hearing_aid.h files.
     32     // Match up with enum class ConnectionState of bt_hearing_aid.h.
     33     static final int CONNECTION_STATE_DISCONNECTED = 0;
     34     static final int CONNECTION_STATE_CONNECTING = 1;
     35     static final int CONNECTION_STATE_CONNECTED = 2;
     36     static final int CONNECTION_STATE_DISCONNECTING = 3;
     37 
     38     public int type;
     39     public BluetoothDevice device;
     40     public int valueInt1;
     41     public long valueLong2;
     42 
     43     HearingAidStackEvent(int type) {
     44         this.type = type;
     45     }
     46 
     47     @Override
     48     public String toString() {
     49         // event dump
     50         StringBuilder result = new StringBuilder();
     51         result.append("HearingAidStackEvent {type:" + eventTypeToString(type));
     52         result.append(", device:" + device);
     53         result.append(", value1:" + valueInt1);
     54         result.append(", value2:" + valueLong2);
     55         result.append("}");
     56         return result.toString();
     57     }
     58 
     59     private static String eventTypeToString(int type) {
     60         switch (type) {
     61             case EVENT_TYPE_NONE:
     62                 return "EVENT_TYPE_NONE";
     63             case EVENT_TYPE_CONNECTION_STATE_CHANGED:
     64                 return "EVENT_TYPE_CONNECTION_STATE_CHANGED";
     65             case EVENT_TYPE_DEVICE_AVAILABLE:
     66                 return "EVENT_TYPE_DEVICE_AVAILABLE";
     67             default:
     68                 return "EVENT_TYPE_UNKNOWN:" + type;
     69         }
     70     }
     71 }
     72