Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Bluetooth support for WearOS devices#3178

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
SBALAVIGNESH123 wants to merge23 commits intomicrog:master
base:master
Choose a base branch
Loading
fromSBALAVIGNESH123:wearos-bluetooth-support
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
23 commits
Select commitHold shift + click to select a range
6fb0195
Add Bluetooth support for WearOS devices
Dec 10, 2025
ef58386
Fix bugs reported by code review: thread safety, socket leaks, file l…
Dec 11, 2025
f663ea8
Fix bugs: race conditions, NPE, missing flush (Round 2)
Dec 11, 2025
febb05c
Refactor: Use standard MessageHandler for full protocol support (Roun…
Dec 11, 2025
5cf84de
Feat: Add basic Wearable UI for managing connections
Dec 11, 2025
7b4047c
Fix: Clear static impl reference on service destroy
Dec 11, 2025
ece85ec
Fix: TOCTOU race condition in WearableSettingsActivity
Dec 11, 2025
80ee65f
Fix: Socket leak on handshake failure and incomplete Connect message
Dec 11, 2025
ff4c1a9
Fix: Thread-safety for static impl and missing null check in Connecti…
Dec 11, 2025
fcba2eb
Fix: Define undefined adapter variable in ConnectionThread
Dec 11, 2025
1c4933f
Fix: Sync race condition in activeConnections access
Dec 11, 2025
725e7d4
Fix: Remove duplicate ACCESS_NETWORK_STATE permission
Dec 11, 2025
882fa2f
Docs: Add comments to handshake logic
Dec 11, 2025
0ffc9c2
Feat: UI/UX Improvements (Material Design, Scan, Disconnect)
Dec 11, 2025
6631713
Fix: Perms, Connection Race, and UI Status Logic
Dec 11, 2025
9149be9
Fix variable shadowing and connection race condition
Dec 12, 2025
b1d1aaa
Fix compilation error: remove duplicate closing brace
Dec 12, 2025
09f6146
Fix: Resolve all compilation errors for WearOS Bluetooth support
Dec 14, 2025
2b9c0be
Merge branch 'master' into wearos-bluetooth-support
SBALAVIGNESH123Dec 14, 2025
c59523d
Fix: Add missing BLUETOOTH_CONNECT permission
Dec 15, 2025
eda5727
Merge branch 'wearos-bluetooth-support' of https://github.com/SBALAVI…
Dec 15, 2025
9440651
Merge branch 'master' into wearos-bluetooth-support
SBALAVIGNESH123Dec 16, 2025
22b8895
Fix: Add runtime permission checks for BLUETOOTH_CONNECT
Dec 16, 2025
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
NextNext commit
Add Bluetooth support for WearOS devices
Implements RFCOMM transport layer for WearOS connectivity without Google Play Services.- Created BluetoothWearableConnection for Bluetooth Classic transport- Added automatic device discovery and connection in WearableImpl- Added necessary Bluetooth permissions to manifestAddresses#2843 - + bounty for WearOS support
  • Loading branch information
SBALAVIGNESH123 committedDec 10, 2025
commit6fb01957c60bdacb426928f450063e0c409726be
7 changes: 7 additions & 0 deletionsplay-services-core/src/main/AndroidManifest.xml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -138,6 +138,13 @@

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<!-- For Android 12+ -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2013-2019 microG Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.microg.gms.wearable;

import android.bluetooth.BluetoothSocket;

import com.squareup.wire.Wire;

import org.microg.wearable.WearableConnection;
import org.microg.wearable.proto.MessagePiece;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**
* Bluetooth transport implementation for Wearable connections.
* Uses RFCOMM sockets to communicate with WearOS devices over Bluetooth Classic.
*/
public class BluetoothWearableConnection extends WearableConnection {
private final int MAX_PIECE_SIZE = 20 * 1024 * 1024; // 20MB limit
private final BluetoothSocket socket;
private final DataInputStream is;
private final DataOutputStream os;

public BluetoothWearableConnection(BluetoothSocket socket, Listener listener) throws IOException {
super(listener);
this.socket = socket;
this.is = new DataInputStream(socket.getInputStream());
this.os = new DataOutputStream(socket.getOutputStream());
}

@Override
protected void writeMessagePiece(MessagePiece piece) throws IOException {
byte[] bytes = piece.toByteArray();
os.writeInt(bytes.length);
os.write(bytes);
}

@Override
protected MessagePiece readMessagePiece() throws IOException {
int len = is.readInt();
if (len > MAX_PIECE_SIZE || len < 0) {
throw new IOException("Piece size " + len + " exceeded limit of " + MAX_PIECE_SIZE + " bytes.");
}
byte[] bytes = new byte[len];
is.readFully(bytes);
return new Wire().parseFrom(bytes, MessagePiece.class);
}

@Override
public void close() throws IOException {
socket.close();
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,9 @@
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;

import androidx.annotation.Nullable;

Expand DownExpand Up@@ -69,13 +72,16 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;

import okio.ByteString;

public class WearableImpl {

private static final String TAG = "GmsWear";
// Standard Serial Port Profile UUID for Bluetooth Classic
private static final UUID UUID_WEAR = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

private static final int WEAR_TCP_PORT = 5601;

Expand All@@ -87,6 +93,7 @@ public class WearableImpl {
private final Map<String, WearableConnection> activeConnections = new HashMap<String, WearableConnection>();
private RpcHelper rpcHelper;
private SocketConnectionThread sct;
private ConnectionThread btThread;
private ConnectionConfiguration[] configurations;
private boolean configurationsUpdated = false;
private ClockworkNodePreferences clockworkNodePreferences;
Expand All@@ -105,6 +112,13 @@ public WearableImpl(Context context, NodeDatabaseHelper nodeDatabase, Configurat
networkHandlerLock.countDown();
Looper.loop();
}).start();

// Start Bluetooth connection thread if Bluetooth is available
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter != null) {
btThread = new ConnectionThread();
btThread.start();
}
}

public String getLocalNodeId() {
Expand DownExpand Up@@ -628,6 +642,10 @@ public void stop() {
} catch (InterruptedException e) {
Log.w(TAG, e);
}
if (btThread != null) {
btThread.interrupt();
btThread = null;
}
}

private class ListenerInfo {
Expand All@@ -639,4 +657,90 @@ private ListenerInfo(IWearableListener listener, IntentFilter[] filters) {
this.filters = filters;
}
}

private class ConnectionThread extends Thread {
@Override
public void run() {
while (!isInterrupted()) {
try {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null && adapter.isEnabled()) {
Set<BluetoothDevice> bondedDevices = adapter.getBondedDevices();
for (BluetoothDevice device : bondedDevices) {
// Skip if already connected
if (activeConnections.containsKey(device.getAddress())) {
continue;
}

Log.d(TAG, "Attempting BT connection to " + device.getName() + " (" + device.getAddress() + ")");

try {
// Create RFCOMM socket using SPP UUID
BluetoothSocket socket = device.createRfcommSocketToServiceRecord(UUID_WEAR);
socket.connect();

if (socket.isConnected()) {
Log.d(TAG, "Successfully connected via Bluetooth to " + device.getName());

// Create wearable connection wrapper
BluetoothWearableConnection connection = new BluetoothWearableConnection(
socket,
new WearableConnection.Listener() {
@Override
public void onConnected(WearableConnection connection) {
// Connection established, wait for handshake
}

@Override
public void onMessage(WearableConnection connection, RootMessage message) {
// Handle incoming protocol messages
if (message.connect != null) {
onConnectReceived(connection, message.connect.id, message.connect);
} else if (message.filePiece != null) {
handleFilePiece(connection, message.filePiece.fileName,
message.filePiece.piece.toByteArray(), message.filePiece.digest);
} else {
Log.d(TAG, "Received message: " + message);
}
}

@Override
public void onDisconnected() {
// Cleanup handled by existing logic
}
}
);

// Start message processing thread
new Thread(connection).start();

// Send our identity to the watch
String localId = getLocalNodeId();
connection.writeMessage(
new RootMessage.Builder()
.connect(new Connect.Builder()
.id(localId)
.name("Phone")
.build())
.build()
);
}
} catch (IOException e) {
Log.d(TAG, "BT connection failed: " + e.getMessage());
}
}
}
} catch (Exception e) {
Log.w(TAG, "Error in Bluetooth ConnectionThread", e);
}

// Wait before next scan attempt
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
break;
}
}
}
}
}

[8]ページ先頭

©2009-2025 Movatter.jp