Home | History | Annotate | Download | only in jni
      1 /*
      2  * Copyright (c) 2014 The Android Open Source Project
      3  * Copyright (C) 2012 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 #ifndef COM_ANDROID_BLUETOOTH_H
     19 #define COM_ANDROID_BLUETOOTH_H
     20 
     21 #include "JNIHelp.h"
     22 #include "android_runtime/AndroidRuntime.h"
     23 #include "android_runtime/Log.h"
     24 #include "hardware/bluetooth.h"
     25 #include "hardware/hardware.h"
     26 #include "jni.h"
     27 #include "nativehelper/ScopedLocalRef.h"
     28 #include "utils/Log.h"
     29 
     30 namespace android {
     31 
     32 JNIEnv* getCallbackEnv();
     33 
     34 class CallbackEnv {
     35 public:
     36     CallbackEnv(const char *methodName) : mName(methodName) {
     37         mCallbackEnv = getCallbackEnv();
     38     }
     39 
     40     ~CallbackEnv() {
     41       if (mCallbackEnv && mCallbackEnv->ExceptionCheck()) {
     42           ALOGE("An exception was thrown by callback '%s'.", mName);
     43           LOGE_EX(mCallbackEnv);
     44           mCallbackEnv->ExceptionClear();
     45       }
     46     }
     47 
     48     bool valid() const {
     49       JNIEnv *env = AndroidRuntime::getJNIEnv();
     50       if (!mCallbackEnv || (mCallbackEnv != env)) {
     51           ALOGE("%s: Callback env fail: env: %p, callback: %p", mName, env, mCallbackEnv);
     52           return false;
     53       }
     54       return true;
     55     }
     56 
     57     JNIEnv *operator-> () const {
     58         return mCallbackEnv;
     59     }
     60 
     61     JNIEnv *get() const {
     62         return mCallbackEnv;
     63     }
     64 
     65 private:
     66     JNIEnv *mCallbackEnv;
     67     const char *mName;
     68 
     69     DISALLOW_COPY_AND_ASSIGN(CallbackEnv);
     70 };
     71 
     72 const bt_interface_t* getBluetoothInterface();
     73 
     74 int register_com_android_bluetooth_hfp(JNIEnv* env);
     75 
     76 int register_com_android_bluetooth_hfpclient(JNIEnv* env);
     77 
     78 int register_com_android_bluetooth_a2dp(JNIEnv* env);
     79 
     80 int register_com_android_bluetooth_a2dp_sink(JNIEnv* env);
     81 
     82 int register_com_android_bluetooth_avrcp(JNIEnv* env);
     83 
     84 int register_com_android_bluetooth_avrcp_controller(JNIEnv* env);
     85 
     86 int register_com_android_bluetooth_hid(JNIEnv* env);
     87 
     88 int register_com_android_bluetooth_hidd(JNIEnv* env);
     89 
     90 int register_com_android_bluetooth_hdp(JNIEnv* env);
     91 
     92 int register_com_android_bluetooth_pan(JNIEnv* env);
     93 
     94 int register_com_android_bluetooth_gatt (JNIEnv* env);
     95 
     96 int register_com_android_bluetooth_sdp (JNIEnv* env);
     97 
     98 }
     99 
    100 #endif /* COM_ANDROID_BLUETOOTH_H */
    101