Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update credits even without a sink #398

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bumble/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from __future__ import annotations

from collections.abc import Callable, MutableMapping
from typing import cast, Any
from typing import cast, Any, Optional
import logging

from bumble import avdtp
Expand Down Expand Up @@ -69,14 +69,15 @@
class PacketTracer:
class AclStream:
psms: MutableMapping[int, int]
peer: PacketTracer.AclStream
peer: Optional[PacketTracer.AclStream]
avdtp_assemblers: MutableMapping[int, avdtp.MessageAssembler]

def __init__(self, analyzer: PacketTracer.Analyzer) -> None:
self.analyzer = analyzer
self.packet_assembler = HCI_AclDataPacketAssembler(self.on_acl_pdu)
self.avdtp_assemblers = {} # AVDTP assemblers, by source_cid
self.psms = {} # PSM, by source_cid
self.peer = None

# pylint: disable=too-many-nested-blocks
def on_acl_pdu(self, pdu: bytes) -> None:
Expand Down
5 changes: 3 additions & 2 deletions bumble/rfcomm.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,9 @@ def on_uih_frame(self, frame: RFCOMM_Frame) -> None:
f'[{self.dlci}] {len(data)} bytes, '
f'rx_credits={self.rx_credits}: {data.hex()}'
)
if len(data) and self.sink:
self.sink(data) # pylint: disable=not-callable
if data:
if self.sink:
self.sink(data) # pylint: disable=not-callable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have annotation now, it is no longer needed.

Suggested change
self.sink(data) # pylint: disable=not-callable
self.sink(data)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still get a pylint error without that comment:
bumble/rfcomm.py:543:16: E1102: self.sink is not callable (not-callable)


# Update the credits
if self.rx_credits > 0:
Expand Down
2 changes: 1 addition & 1 deletion extras/android/RemoteHCI/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {

defaultConfig {
applicationId = "com.github.google.bumble.remotehci"
minSdk = 26
minSdk = 29
targetSdk = 33
versionCode = 1
versionName = "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.Trace;
import android.util.Log;

import java.util.ArrayList;
Expand Down Expand Up @@ -53,6 +54,7 @@ class HciHidlHal extends android.hardware.bluetooth.V1_0.IBluetoothHciCallbacks.
private final android.hardware.bluetooth.V1_0.IBluetoothHci mHciService;
private final HciHalCallback mHciCallbacks;
private int mInitializationStatus = -1;
private final boolean mTracingEnabled = Trace.isEnabled();


public static HciHidlHal create(HciHalCallback hciCallbacks) {
Expand Down Expand Up @@ -89,6 +91,7 @@ public Status initialize() throws RemoteException, InterruptedException {
}

// Map the status code.
Log.d(TAG, "Initialization status = " + mInitializationStatus);
switch (mInitializationStatus) {
case android.hardware.bluetooth.V1_0.Status.SUCCESS:
return Status.SUCCESS;
Expand All @@ -108,6 +111,10 @@ public Status initialize() throws RemoteException, InterruptedException {
public void sendPacket(HciPacket.Type type, byte[] packet) {
ArrayList<Byte> data = HciPacket.byteArrayToList(packet);

if (mTracingEnabled) {
Trace.beginAsyncSection("SEND_PACKET_TO_HAL", 1);
}

try {
switch (type) {
case COMMAND:
Expand All @@ -125,6 +132,10 @@ public void sendPacket(HciPacket.Type type, byte[] packet) {
} catch (RemoteException error) {
Log.w(TAG, "failed to forward packet: " + error);
}

if (mTracingEnabled) {
Trace.endAsyncSection("SEND_PACKET_TO_HAL", 1);
}
}

@Override
Expand Down Expand Up @@ -157,6 +168,7 @@ class HciAidlHal extends android.hardware.bluetooth.IBluetoothHciCallbacks.Stub
private final android.hardware.bluetooth.IBluetoothHci mHciService;
private final HciHalCallback mHciCallbacks;
private int mInitializationStatus = android.hardware.bluetooth.Status.SUCCESS;
private final boolean mTracingEnabled = Trace.isEnabled();

public static HciAidlHal create(HciHalCallback hciCallbacks) {
IBinder binder = ServiceManager.getService("android.hardware.bluetooth.IBluetoothHci/default");
Expand Down Expand Up @@ -187,6 +199,7 @@ public Status initialize() throws RemoteException, InterruptedException {
}

// Map the status code.
Log.d(TAG, "Initialization status = " + mInitializationStatus);
switch (mInitializationStatus) {
case android.hardware.bluetooth.Status.SUCCESS:
return Status.SUCCESS;
Expand All @@ -208,6 +221,10 @@ public Status initialize() throws RemoteException, InterruptedException {
// HciHal methods.
@Override
public void sendPacket(HciPacket.Type type, byte[] packet) {
if (mTracingEnabled) {
Trace.beginAsyncSection("SEND_PACKET_TO_HAL", 1);
}

try {
switch (type) {
case COMMAND:
Expand All @@ -229,6 +246,10 @@ public void sendPacket(HciPacket.Type type, byte[] packet) {
} catch (RemoteException error) {
Log.w(TAG, "failed to forward packet: " + error);
}

if (mTracingEnabled) {
Trace.endAsyncSection("SEND_PACKET_TO_HAL", 1);
}
}

// IBluetoothHciCallbacks methods.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.google.bumble.remotehci;

import android.os.Trace;
import android.util.Log;

import java.io.IOException;
Expand All @@ -15,6 +16,7 @@ public class HciServer {
private final int mPort;
private final Listener mListener;
private OutputStream mOutputStream;
private final boolean mTracingEnabled = Trace.isEnabled();

public interface Listener extends HciParser.Sink {
void onHostConnectionState(boolean connected);
Expand All @@ -27,6 +29,8 @@ public interface Listener extends HciParser.Sink {
}

public void run() throws IOException {
Log.i(TAG, "Tracing enabled: " + mTracingEnabled);

for (;;) {
try {
loop();
Expand Down Expand Up @@ -73,6 +77,10 @@ private void loop() throws IOException {
}

public void sendPacket(HciPacket.Type type, byte[] packet) {
if (mTracingEnabled) {
Trace.beginAsyncSection("SEND_PACKET_FROM_HAL", 2);
}

// Create a combined data buffer so we can write it out in a single call.
byte[] data = new byte[packet.length + 1];
data[0] = type.value;
Expand All @@ -89,5 +97,9 @@ public void sendPacket(HciPacket.Type type, byte[] packet) {
Log.d(TAG, "no client, dropping packet");
}
}

if (mTracingEnabled) {
Trace.endAsyncSection("SEND_PACKET_FROM_HAL", 2);
}
}
}