|
19 | 19 | import com.google.android.gms.wearable.ConnectionConfiguration; |
20 | 20 |
|
21 | 21 | import org.microg.gms.wearable.MessageHandler; |
| 22 | +import org.microg.gms.wearable.TransportConnectionHandler; |
22 | 23 | import org.microg.gms.wearable.WearableConnection; |
23 | 24 | import org.microg.gms.wearable.WearableImpl; |
24 | 25 | import org.microg.gms.wearable.proto.Connect; |
@@ -209,11 +210,21 @@ private void connect() throws IOException, InterruptedException { |
209 | 210 | isConnected = true; |
210 | 211 | markActivity(); |
211 | 212 |
|
212 | | - wearableConnection = new BluetoothWearableConnection( |
213 | | - socket, config.nodeId, |
214 | | - new ConnectionListener(context, config, wearableImpl, this) |
215 | | - ); |
216 | | - wearableConnection.run(); |
| 213 | + BluetoothWearableConnection btConn = |
| 214 | + new BluetoothWearableConnection(socket, config.nodeId, |
| 215 | + new WearableConnection.Listener() { |
| 216 | + public void onConnected(WearableConnection c) {} |
| 217 | + public void onMessage(WearableConnection c, RootMessage m) {} |
| 218 | + public void onDisconnected() {} |
| 219 | + }); |
| 220 | + wearableConnection = btConn; |
| 221 | + |
| 222 | + if (!btConn.handshake()) { |
| 223 | + Log.e(TAG, "Handshake failed"); |
| 224 | + return; |
| 225 | + } |
| 226 | + |
| 227 | + new TransportConnectionHandler(wearableImpl, config).handle(btConn); |
217 | 228 | } |
218 | 229 |
|
219 | 230 | @RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT) |
@@ -468,57 +479,4 @@ public void close(){ |
468 | 479 | signalRetry(); |
469 | 480 | interrupt(); |
470 | 481 | } |
471 | | - |
472 | | - private static class ConnectionListener implements WearableConnection.Listener { |
473 | | - private final Context context; |
474 | | - private final ConnectionConfiguration config; |
475 | | - private final WearableImpl wearableImpl; |
476 | | - private Connect peerConnect; |
477 | | - private WearableConnection connection; |
478 | | - |
479 | | - private final BluetoothConnectionThread thread; |
480 | | - |
481 | | - private MessageHandler messageHandler; |
482 | | - |
483 | | - public ConnectionListener(Context context, ConnectionConfiguration config, WearableImpl wearableImpl, BluetoothConnectionThread thread) { |
484 | | - this.context = context; |
485 | | - this.config = config; |
486 | | - this.wearableImpl = wearableImpl; |
487 | | - this.thread = thread; |
488 | | - } |
489 | | - |
490 | | - @Override |
491 | | - public void onConnected(WearableConnection connection) { |
492 | | - Log.d(TAG, "Wearable connection established for " + config.address); |
493 | | - thread.markActivity(); |
494 | | - thread.isConnected = true; |
495 | | - |
496 | | - this.connection = connection; |
497 | | - |
498 | | - BluetoothWearableConnection btConnection = (BluetoothWearableConnection) connection; |
499 | | - this.peerConnect = btConnection.getPeerConnect(); |
500 | | - |
501 | | - this.messageHandler = new MessageHandler(context, wearableImpl, config); |
502 | | - |
503 | | - wearableImpl.onConnectReceived(connection, config.nodeId, peerConnect); |
504 | | - } |
505 | | - |
506 | | - @Override |
507 | | - public void onMessage(WearableConnection connection, RootMessage message) { |
508 | | - Log.d(TAG, "Message received from " + config.address + ": " + message.toString()); |
509 | | - thread.markActivity(); |
510 | | - |
511 | | - if (peerConnect != null && messageHandler != null) |
512 | | - messageHandler.handleMessage(connection, peerConnect.id, message); |
513 | | - } |
514 | | - |
515 | | - @Override |
516 | | - public void onDisconnected() { |
517 | | - Log.d(TAG, "Wearable connection disconnected for " + config.address); |
518 | | - thread.isConnected = false; |
519 | | - if (connection != null && peerConnect != null) { |
520 | | - wearableImpl.onDisconnectReceived(connection, peerConnect); |
521 | | - } |
522 | | - } |
523 | | - } |
524 | 482 | } |
0 commit comments