Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3f4b46c authored by Marie Janssen's avatar Marie Janssen Committed by android-build-merger
Browse files

Merge "JNI: style cleanup"

am: 78ec034c

Change-Id: I3e2d7818fae0fe7d7b67f68d0c5c5cff0e826c29
parents 22b07aa8 78ec034c
Loading
Loading
Loading
Loading
+20 −30
Original line number Diff line number Diff line
@@ -33,13 +33,11 @@ static const btav_interface_t *sBluetoothA2dpInterface = NULL;
static jobject mCallbacksObj = NULL;

static void bta2dp_connection_state_callback(btav_connection_state_t state, bt_bdaddr_t* bd_addr) {
    jbyteArray addr;

    ALOGI("%s", __func__);
    CallbackEnv sCallbackEnv(__func__);
    if (!sCallbackEnv.valid()) return;

    addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t));
    jbyteArray addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t));
    if (!addr) {
        ALOGE("Fail to new jbyteArray bd addr for connection state");
        return;
@@ -52,13 +50,11 @@ static void bta2dp_connection_state_callback(btav_connection_state_t state, bt_b
}

static void bta2dp_audio_state_callback(btav_audio_state_t state, bt_bdaddr_t* bd_addr) {
    jbyteArray addr;

    ALOGI("%s", __func__);
    CallbackEnv sCallbackEnv(__func__);
    if (!sCallbackEnv.valid()) return;

    addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t));
    jbyteArray addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t));
    if (!addr) {
        ALOGE("Fail to new jbyteArray bd addr for connection state");
        return;
@@ -84,14 +80,13 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
    method_onAudioStateChanged =
        env->GetMethodID(clazz, "onAudioStateChanged", "(I[B)V");

    ALOGI("%s: succeeds", __FUNCTION__);
    ALOGI("%s: succeeds", __func__);
}

static void initNative(JNIEnv *env, jobject object) {
    const bt_interface_t* btInf;
    bt_status_t status;

    if ( (btInf = getBluetoothInterface()) == NULL) {
    const bt_interface_t* btInf = getBluetoothInterface();
    if (btInf == NULL) {
        ALOGE("Bluetooth module is not loaded");
        return;
    }
@@ -113,13 +108,15 @@ static void initNative(JNIEnv *env, jobject object) {
        return;
    }

    if ( (sBluetoothA2dpInterface = (btav_interface_t *)
          btInf->get_profile_interface(BT_PROFILE_ADVANCED_AUDIO_ID)) == NULL) {
    sBluetoothA2dpInterface = (btav_interface_t *)
          btInf->get_profile_interface(BT_PROFILE_ADVANCED_AUDIO_ID);
    if (sBluetoothA2dpInterface == NULL) {
        ALOGE("Failed to get Bluetooth A2DP Interface");
        return;
    }

    if ( (status = sBluetoothA2dpInterface->init(&sBluetoothA2dpCallbacks)) != BT_STATUS_SUCCESS) {
    bt_status_t status = sBluetoothA2dpInterface->init(&sBluetoothA2dpCallbacks);
    if (status != BT_STATUS_SUCCESS) {
        ALOGE("Failed to initialize Bluetooth A2DP, status: %d", status);
        sBluetoothA2dpInterface = NULL;
        return;
@@ -127,9 +124,8 @@ static void initNative(JNIEnv *env, jobject object) {
}

static void cleanupNative(JNIEnv *env, jobject object) {
    const bt_interface_t* btInf;

    if ( (btInf = getBluetoothInterface()) == NULL) {
    const bt_interface_t* btInf = getBluetoothInterface();
    if (btInf == NULL) {
        ALOGE("Bluetooth module is not loaded");
        return;
    }
@@ -146,21 +142,17 @@ static void cleanupNative(JNIEnv *env, jobject object) {
}

static jboolean connectA2dpNative(JNIEnv *env, jobject object, jbyteArray address) {
    jbyte *addr;
    bt_bdaddr_t * btAddr;
    bt_status_t status;

    ALOGI("%s: sBluetoothA2dpInterface: %p", __FUNCTION__, sBluetoothA2dpInterface);
    ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
    if (!sBluetoothA2dpInterface) return JNI_FALSE;

    addr = env->GetByteArrayElements(address, NULL);
    btAddr = (bt_bdaddr_t *) addr;
    jbyte *addr = env->GetByteArrayElements(address, NULL);
    if (!addr) {
        jniThrowIOException(env, EINVAL);
        return JNI_FALSE;
    }

    if ((status = sBluetoothA2dpInterface->connect((bt_bdaddr_t *)addr)) != BT_STATUS_SUCCESS) {
    bt_status_t status = sBluetoothA2dpInterface->connect((bt_bdaddr_t *)addr);
    if (status != BT_STATUS_SUCCESS) {
        ALOGE("Failed HF connection, status: %d", status);
    }
    env->ReleaseByteArrayElements(address, addr, 0);
@@ -168,18 +160,16 @@ static jboolean connectA2dpNative(JNIEnv *env, jobject object, jbyteArray addres
}

static jboolean disconnectA2dpNative(JNIEnv *env, jobject object, jbyteArray address) {
    jbyte *addr;
    bt_status_t status;

    if (!sBluetoothA2dpInterface) return JNI_FALSE;

    addr = env->GetByteArrayElements(address, NULL);
    jbyte *addr = env->GetByteArrayElements(address, NULL);
    if (!addr) {
        jniThrowIOException(env, EINVAL);
        return JNI_FALSE;
    }

    if ( (status = sBluetoothA2dpInterface->disconnect((bt_bdaddr_t *)addr)) != BT_STATUS_SUCCESS) {
    bt_status_t status = sBluetoothA2dpInterface->disconnect((bt_bdaddr_t *)addr);
    if (status != BT_STATUS_SUCCESS) {
        ALOGE("Failed HF disconnection, status: %d", status);
    }
    env->ReleaseByteArrayElements(address, addr, 0);
+21 −36
Original line number Diff line number Diff line
@@ -34,13 +34,11 @@ static const btav_interface_t *sBluetoothA2dpInterface = NULL;
static jobject mCallbacksObj = NULL;

static void bta2dp_connection_state_callback(btav_connection_state_t state, bt_bdaddr_t* bd_addr) {
    jbyteArray addr;

    ALOGI("%s", __func__);
    CallbackEnv sCallbackEnv(__func__);
    if (!sCallbackEnv.valid()) return;

    addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t));
   jbyteArray addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t));
    if (!addr) {
        ALOGE("Fail to new jbyteArray bd addr for connection state");
        return;
@@ -53,13 +51,11 @@ static void bta2dp_connection_state_callback(btav_connection_state_t state, bt_b
}

static void bta2dp_audio_state_callback(btav_audio_state_t state, bt_bdaddr_t* bd_addr) {
    jbyteArray addr;

    ALOGI("%s", __func__);
    CallbackEnv sCallbackEnv(__func__);
    if (!sCallbackEnv.valid()) return;

    addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t));
    jbyteArray addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t));
    if (!addr) {
        ALOGE("Fail to new jbyteArray bd addr for connection state");
        return;
@@ -72,13 +68,11 @@ static void bta2dp_audio_state_callback(btav_audio_state_t state, bt_bdaddr_t* b
}

static void bta2dp_audio_config_callback(bt_bdaddr_t *bd_addr, uint32_t sample_rate, uint8_t channel_count) {
    jbyteArray addr;

    ALOGI("%s", __func__);
    CallbackEnv sCallbackEnv(__func__);
    if (!sCallbackEnv.valid()) return;

    addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t));
    jbyteArray addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t));
    if (!addr) {
        ALOGE("Fail to new jbyteArray bd addr for connection state");
        return;
@@ -106,14 +100,12 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
    method_onAudioConfigChanged =
        env->GetMethodID(clazz, "onAudioConfigChanged", "([BII)V");

    ALOGI("%s: succeeds", __FUNCTION__);
    ALOGI("%s: succeeds", __func__);
}

static void initNative(JNIEnv *env, jobject object) {
    const bt_interface_t* btInf;
    bt_status_t status;

    if ( (btInf = getBluetoothInterface()) == NULL) {
    const bt_interface_t* btInf = getBluetoothInterface();
    if (btInf == NULL) {
        ALOGE("Bluetooth module is not loaded");
        return;
    }
@@ -130,13 +122,15 @@ static void initNative(JNIEnv *env, jobject object) {
         mCallbacksObj = NULL;
    }

    if ( (sBluetoothA2dpInterface = (btav_interface_t *)
          btInf->get_profile_interface(BT_PROFILE_ADVANCED_AUDIO_SINK_ID)) == NULL) {
    sBluetoothA2dpInterface = (btav_interface_t *)
          btInf->get_profile_interface(BT_PROFILE_ADVANCED_AUDIO_SINK_ID);
    if (sBluetoothA2dpInterface == NULL) {
        ALOGE("Failed to get Bluetooth A2DP Sink Interface");
        return;
    }

    if ( (status = sBluetoothA2dpInterface->init(&sBluetoothA2dpCallbacks)) != BT_STATUS_SUCCESS) {
    bt_status_t status = sBluetoothA2dpInterface->init(&sBluetoothA2dpCallbacks);
    if (status != BT_STATUS_SUCCESS) {
        ALOGE("Failed to initialize Bluetooth A2DP Sink, status: %d", status);
        sBluetoothA2dpInterface = NULL;
        return;
@@ -146,9 +140,9 @@ static void initNative(JNIEnv *env, jobject object) {
}

static void cleanupNative(JNIEnv *env, jobject object) {
    const bt_interface_t* btInf;
    const bt_interface_t* btInf = getBluetoothInterface();

    if ( (btInf = getBluetoothInterface()) == NULL) {
    if (btInf == NULL) {
        ALOGE("Bluetooth module is not loaded");
        return;
    }
@@ -165,21 +159,17 @@ static void cleanupNative(JNIEnv *env, jobject object) {
}

static jboolean connectA2dpNative(JNIEnv *env, jobject object, jbyteArray address) {
    jbyte *addr;
    bt_bdaddr_t * btAddr;
    bt_status_t status;

    ALOGI("%s: sBluetoothA2dpInterface: %p", __FUNCTION__, sBluetoothA2dpInterface);
    ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
    if (!sBluetoothA2dpInterface) return JNI_FALSE;

    addr = env->GetByteArrayElements(address, NULL);
    btAddr = (bt_bdaddr_t *) addr;
    jbyte *addr = env->GetByteArrayElements(address, NULL);
    if (!addr) {
        jniThrowIOException(env, EINVAL);
        return JNI_FALSE;
    }

    if ((status = sBluetoothA2dpInterface->connect((bt_bdaddr_t *)addr)) != BT_STATUS_SUCCESS) {
    bt_status_t status = sBluetoothA2dpInterface->connect((bt_bdaddr_t *)addr);
    if (status != BT_STATUS_SUCCESS) {
        ALOGE("Failed HF connection, status: %d", status);
    }
    env->ReleaseByteArrayElements(address, addr, 0);
@@ -187,18 +177,17 @@ static jboolean connectA2dpNative(JNIEnv *env, jobject object, jbyteArray addres
}

static jboolean disconnectA2dpNative(JNIEnv *env, jobject object, jbyteArray address) {
    jbyte *addr;
    bt_status_t status;

    if (!sBluetoothA2dpInterface) return JNI_FALSE;

    addr = env->GetByteArrayElements(address, NULL);
    jbyte *addr = env->GetByteArrayElements(address, NULL);
    if (!addr) {
        jniThrowIOException(env, EINVAL);
        return JNI_FALSE;
    }

    if ( (status = sBluetoothA2dpInterface->disconnect((bt_bdaddr_t *)addr)) != BT_STATUS_SUCCESS) {
    bt_status_t status = sBluetoothA2dpInterface->disconnect((bt_bdaddr_t *)addr);
    if (status != BT_STATUS_SUCCESS) {
        ALOGE("Failed HF disconnection, status: %d", status);
    }
    env->ReleaseByteArrayElements(address, addr, 0);
@@ -207,16 +196,12 @@ static jboolean disconnectA2dpNative(JNIEnv *env, jobject object, jbyteArray add

static void informAudioFocusStateNative(JNIEnv *env, jobject object, jint focus_state) {
    if (!sBluetoothA2dpInterface) return;

    sBluetoothA2dpInterface->set_audio_focus_state((uint8_t) focus_state);

}

static void informAudioTrackGainNative(JNIEnv *env, jobject object, jfloat gain) {
    if (!sBluetoothA2dpInterface) return;

    sBluetoothA2dpInterface->set_audio_track_gain((float) gain);

}

static JNINativeMethod sMethods[] = {
+233 −340

File changed.

Preview size limit exceeded, changes collapsed.

+134 −194

File changed.

Preview size limit exceeded, changes collapsed.

+225 −303

File changed.

Preview size limit exceeded, changes collapsed.

Loading