mirror of
https://github.com/google/bumble.git
synced 2026-04-16 00:25:31 +00:00
update credits even without a sink
This commit is contained in:
@@ -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
|
||||
@@ -69,7 +69,7 @@ PSM_NAMES = {
|
||||
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:
|
||||
@@ -77,6 +77,7 @@ class PacketTracer:
|
||||
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:
|
||||
|
||||
@@ -538,8 +538,9 @@ class DLC(EventEmitter):
|
||||
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 len(data):
|
||||
if self.sink:
|
||||
self.sink(data) # pylint: disable=not-callable
|
||||
|
||||
# Update the credits
|
||||
if self.rx_credits > 0:
|
||||
|
||||
@@ -10,7 +10,7 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.github.google.bumble.remotehci"
|
||||
minSdk = 26
|
||||
minSdk = 29
|
||||
targetSdk = 33
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.hardware.bluetooth.V1_0.Status;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.Trace;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -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) {
|
||||
@@ -89,6 +91,7 @@ class HciHidlHal extends android.hardware.bluetooth.V1_0.IBluetoothHciCallbacks.
|
||||
}
|
||||
|
||||
// Map the status code.
|
||||
Log.d(TAG, "Initialization status = " + mInitializationStatus);
|
||||
switch (mInitializationStatus) {
|
||||
case android.hardware.bluetooth.V1_0.Status.SUCCESS:
|
||||
return Status.SUCCESS;
|
||||
@@ -108,6 +111,10 @@ class HciHidlHal extends android.hardware.bluetooth.V1_0.IBluetoothHciCallbacks.
|
||||
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:
|
||||
@@ -125,6 +132,10 @@ class HciHidlHal extends android.hardware.bluetooth.V1_0.IBluetoothHciCallbacks.
|
||||
} catch (RemoteException error) {
|
||||
Log.w(TAG, "failed to forward packet: " + error);
|
||||
}
|
||||
|
||||
if (mTracingEnabled) {
|
||||
Trace.endAsyncSection("SEND_PACKET_TO_HAL", 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -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");
|
||||
@@ -187,6 +199,7 @@ class HciAidlHal extends android.hardware.bluetooth.IBluetoothHciCallbacks.Stub
|
||||
}
|
||||
|
||||
// Map the status code.
|
||||
Log.d(TAG, "Initialization status = " + mInitializationStatus);
|
||||
switch (mInitializationStatus) {
|
||||
case android.hardware.bluetooth.Status.SUCCESS:
|
||||
return Status.SUCCESS;
|
||||
@@ -208,6 +221,10 @@ class HciAidlHal extends android.hardware.bluetooth.IBluetoothHciCallbacks.Stub
|
||||
// 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:
|
||||
@@ -229,6 +246,10 @@ class HciAidlHal extends android.hardware.bluetooth.IBluetoothHciCallbacks.Stub
|
||||
} catch (RemoteException error) {
|
||||
Log.w(TAG, "failed to forward packet: " + error);
|
||||
}
|
||||
|
||||
if (mTracingEnabled) {
|
||||
Trace.endAsyncSection("SEND_PACKET_TO_HAL", 1);
|
||||
}
|
||||
}
|
||||
|
||||
// IBluetoothHciCallbacks methods.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.github.google.bumble.remotehci;
|
||||
|
||||
import android.os.Trace;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -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);
|
||||
@@ -27,6 +29,8 @@ public class HciServer {
|
||||
}
|
||||
|
||||
public void run() throws IOException {
|
||||
Log.i(TAG, "Tracing enabled: " + mTracingEnabled);
|
||||
|
||||
for (;;) {
|
||||
try {
|
||||
loop();
|
||||
@@ -73,6 +77,10 @@ public class HciServer {
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -89,5 +97,9 @@ public class HciServer {
|
||||
Log.d(TAG, "no client, dropping packet");
|
||||
}
|
||||
}
|
||||
|
||||
if (mTracingEnabled) {
|
||||
Trace.endAsyncSection("SEND_PACKET_FROM_HAL", 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user