diff --git a/docs/mkdocs/src/extras/android_remote_hci.md b/docs/mkdocs/src/extras/android_remote_hci.md index 706bccf0..4eab132e 100644 --- a/docs/mkdocs/src/extras/android_remote_hci.md +++ b/docs/mkdocs/src/extras/android_remote_hci.md @@ -79,10 +79,32 @@ Airplane Mode, then rebooting. The bluetooth process should, in theory, not rest $ adb shell cmd bluetooth_manager disable ``` -### Selecting a TCP port +### Starting the app +You can start the app from the Android launcher, from Android Studio, or with `adb` + +#### Launching from the launcher +Just tap the app icon on the launcher, check the TCP port that is configured, and tap +the "Start" button. + +#### Launching with `adb` +Using the `am` command, you can start the activity, and pass it arguments so that you can +automatically start the proxy, and/or set the port number. + +!!! tip "Launching from adb with auto-start" + ```bash + $ adb shell am start -n com.github.google.bumble.remotehci/.MainActivity --ez autostart true + ``` + +!!! tip "Launching from adb with auto-start and a port" + In this example, we auto-start the proxy upon launch, with the port set to 9995 + ```bash + $ adb shell am start -n com.github.google.bumble.remotehci/.MainActivity --ez autostart true --ei port 9995 + ``` + +#### Selecting a TCP port The RemoteHCI app's main activity has a "TCP Port" setting where you can change the port on which the proxy is accepting connections. If the default value isn't suitable, you can -change it there. +change it there (you can also use the special value 0 to let the OS assign a port number for you). ### Connecting to the proxy To connect the Bumble stack to the proxy, you need to be able to reach the phone's network diff --git a/docs/mkdocs/src/hardware/index.md b/docs/mkdocs/src/hardware/index.md index 986532ba..9eabab0a 100644 --- a/docs/mkdocs/src/hardware/index.md +++ b/docs/mkdocs/src/hardware/index.md @@ -3,7 +3,7 @@ HARDWARE The Bumble Host connects to a controller over an [HCI Transport](../transports/index.md). To use a hardware controller attached to the host on which the host application is running, the transport is typically either [HCI over UART](../transports/serial.md) or [HCI over USB](../transports/usb.md). -On Linux, the [VHCI Transport](../transports/vhci.md) can be used to communicate with any controller hardware managed by the operating system. Alternatively, a remote controller (a phyiscal controller attached to a remote host) can be used by connecting one of the networked transports (such as the [TCP Client transport](../transports/tcp_client.md), the [TCP Server transport](../transports/tcp_server.md) or the [UDP Transport](../transports/udp.md)) to an [HCI Bridge](../apps_and_tools/hci_bridge) bridging the network transport to a physical controller on a remote host. +On Linux, the [VHCI Transport](../transports/vhci.md) can be used to communicate with any controller hardware managed by the operating system. Alternatively, a remote controller (a phyiscal controller attached to a remote host) can be used by connecting one of the networked transports (such as the [TCP Client transport](../transports/tcp_client.md), the [TCP Server transport](../transports/tcp_server.md) or the [UDP Transport](../transports/udp.md)) to an [HCI Bridge](../apps_and_tools/hci_bridge.md) bridging the network transport to a physical controller on a remote host. In theory, any controller that is compliant with the HCI over UART or HCI over USB protocols can be used. diff --git a/extras/android/RemoteHCI/app/src/main/AndroidManifest.xml b/extras/android/RemoteHCI/app/src/main/AndroidManifest.xml index f96a335a..2cca4ada 100644 --- a/extras/android/RemoteHCI/app/src/main/AndroidManifest.xml +++ b/extras/android/RemoteHCI/app/src/main/AndroidManifest.xml @@ -21,7 +21,6 @@ android:theme="@style/Theme.RemoteHCI"> - diff --git a/extras/android/RemoteHCI/app/src/main/java/com/github/google/bumble/remotehci/HciServer.java b/extras/android/RemoteHCI/app/src/main/java/com/github/google/bumble/remotehci/HciServer.java index 5c71ec04..a78a86a0 100644 --- a/extras/android/RemoteHCI/app/src/main/java/com/github/google/bumble/remotehci/HciServer.java +++ b/extras/android/RemoteHCI/app/src/main/java/com/github/google/bumble/remotehci/HciServer.java @@ -39,31 +39,30 @@ public class HciServer { private void loop() throws IOException { mListener.onHostConnectionState(false); - mListener.onMessage("Waiting for connection on port " + mPort); - try ( - ServerSocket serverSocket = new ServerSocket(mPort); - Socket clientSocket = serverSocket.accept() - ) { - mListener.onHostConnectionState(true); - mListener.onMessage("Connected"); - HciParser parser = new HciParser(mListener); - InputStream inputStream = clientSocket.getInputStream(); - synchronized (this) { - mOutputStream = clientSocket.getOutputStream(); - } - byte[] buffer = new byte[BUFFER_SIZE]; - - try { - for (;;) { - int bytesRead = inputStream.read(buffer); - if (bytesRead < 0) { - Log.d(TAG, "end of stream"); - break; - } - parser.feedData(buffer, bytesRead); + try (ServerSocket serverSocket = new ServerSocket(mPort)) { + mListener.onMessage("Waiting for connection on port " + serverSocket.getLocalPort()); + try (Socket clientSocket = serverSocket.accept()) { + mListener.onHostConnectionState(true); + mListener.onMessage("Connected"); + HciParser parser = new HciParser(mListener); + InputStream inputStream = clientSocket.getInputStream(); + synchronized (this) { + mOutputStream = clientSocket.getOutputStream(); + } + byte[] buffer = new byte[BUFFER_SIZE]; + + try { + for (; ; ) { + int bytesRead = inputStream.read(buffer); + if (bytesRead < 0) { + Log.d(TAG, "end of stream"); + break; + } + parser.feedData(buffer, bytesRead); + } + } catch (IOException error) { + Log.d(TAG, "exception in read loop: " + error); } - } catch (IOException error) { - Log.d(TAG, "exception in read loop: " + error); } } finally { synchronized (this) { diff --git a/extras/android/RemoteHCI/app/src/main/java/com/github/google/bumble/remotehci/MainActivity.kt b/extras/android/RemoteHCI/app/src/main/java/com/github/google/bumble/remotehci/MainActivity.kt index eafab286..3a2630af 100644 --- a/extras/android/RemoteHCI/app/src/main/java/com/github/google/bumble/remotehci/MainActivity.kt +++ b/extras/android/RemoteHCI/app/src/main/java/com/github/google/bumble/remotehci/MainActivity.kt @@ -111,14 +111,18 @@ class MainActivity : ComponentActivity() { super.onCreate(savedInstanceState) appViewModel.loadPreferences(getPreferences(Context.MODE_PRIVATE)) + val tcpPort = intent.getIntExtra("port", -1) + if (tcpPort >= 0) { + appViewModel.tcpPort = tcpPport + } + setContent { MainView(appViewModel, ::startProxy) } - run() - } - - private fun run() { + if (intent.getBooleanExtra("autostart", false)) { + startProxy() + } } private fun startProxy() {