Skip to content

Commit 830fca5

Browse files
committed
Revert my mistakes
1 parent 65a1e42 commit 830fca5

16 files changed

Lines changed: 444 additions & 1072 deletions

play-services-wearable/core/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
88

9-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
109
<uses-permission android:name="android.permission.BLUETOOTH" />
1110
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
1211
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

play-services-wearable/core/src/main/java/org/microg/gms/wearable/AssetFetcher.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ public void fetchMissingAssets(String nodeId, WearableConnection connection,
9494

9595
connection.writeMessage(new RootMessage.Builder()
9696
.fetchAsset(new FetchAsset.Builder()
97-
.digest(assetName)
97+
.assetName(assetName)
98+
.packageName(packageName)
99+
.signatureDigest(signatureDigest)
98100
.build())
99101
.build());
100102

@@ -176,7 +178,10 @@ public void fetchMissingAssetsForRecord(WearableConnection connection,
176178
fetchingAssets.add(digest);
177179

178180
FetchAsset fetchAsset = new FetchAsset.Builder()
179-
.digest(digest)
181+
.assetName(digest)
182+
.packageName(record.packageName)
183+
.signatureDigest(record.signatureDigest)
184+
.permission(false)
180185
.build();
181186

182187
connection.writeMessage(new RootMessage.Builder()

play-services-wearable/core/src/main/java/org/microg/gms/wearable/MessageHandler.java

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
import org.microg.gms.common.Utils;
3535
import org.microg.gms.profile.Build;
3636
import org.microg.gms.settings.SettingsContract;
37-
import org.microg.gms.wearable.proto.ControlMessage;
38-
import org.microg.gms.wearable.proto.EncryptionHandshake;
39-
import org.microg.gms.wearable.proto.RemoveAsset;
37+
import org.microg.gms.wearable.proto.AckAsset;
4038
import org.microg.gms.wearable.proto.AppKey;
4139
import org.microg.gms.wearable.proto.AssetEntry;
4240
import org.microg.gms.wearable.proto.Connect;
@@ -113,12 +111,12 @@ public void onConnect(Connect connect) {
113111
wearable.onConnectReceived(getConnection(), oldConfigNodeId, connect);
114112
try {
115113
getConnection().writeMessage(new RootMessage.Builder().syncStart(new SyncStart.Builder()
116-
.timestamp(-1L)
117-
.sync_type(2)
114+
.receivedSeqId(-1L)
115+
.version(2)
118116
.syncTable(Arrays.asList(
119-
new SyncTableEntry.Builder().uri("cloud").version(1L).build(),
120-
new SyncTableEntry.Builder().uri(wearable.getLocalNodeId()).version(wearable.getCurrentSeqId(wearable.getLocalNodeId())).build(), // TODO
121-
new SyncTableEntry.Builder().uri(peerNodeId).version(wearable.getCurrentSeqId(peerNodeId)).build() // TODO
117+
new SyncTableEntry.Builder().key("cloud").value(1L).build(),
118+
new SyncTableEntry.Builder().key(wearable.getLocalNodeId()).value(wearable.getCurrentSeqId(wearable.getLocalNodeId())).build(), // TODO
119+
new SyncTableEntry.Builder().key(peerNodeId).value(wearable.getCurrentSeqId(peerNodeId)).build() // TODO
122120
)).build()).build());
123121
} catch (IOException e) {
124122
Log.w(TAG, e);
@@ -147,8 +145,8 @@ public void onSetAsset(SetAsset setAsset) {
147145
}
148146

149147
@Override
150-
public void onRemoveAsset(RemoveAsset ackAsset) {
151-
Log.d(TAG, "onRemoveAsset: " + ackAsset);
148+
public void onAckAsset(AckAsset ackAsset) {
149+
Log.d(TAG, "onAckAsset: " + ackAsset);
152150
}
153151

154152
@Override
@@ -159,14 +157,14 @@ public void onFetchAsset(FetchAsset fetchAsset) {
159157
@Override
160158
public void onSyncStart(SyncStart syncStart) {
161159
Log.d(TAG, "onSyncStart: " + syncStart);
162-
if (syncStart.sync_type < 2) {
163-
Log.d(TAG, "Sync uses sync_type " + syncStart.sync_type + " which is not supported (yet)");
160+
if (syncStart.version < 2) {
161+
Log.d(TAG, "Sync uses version " + syncStart.version + " which is not supported (yet)");
164162
}
165163
boolean hasLocalNode = false;
166164
if (syncStart.syncTable != null) {
167165
for (SyncTableEntry entry : syncStart.syncTable) {
168-
wearable.syncToPeer(peerNodeId, entry.uri, entry.version);
169-
if (wearable.getLocalNodeId().equals(entry.uri)) hasLocalNode = true;
166+
wearable.syncToPeer(peerNodeId, entry.key, entry.value);
167+
if (wearable.getLocalNodeId().equals(entry.key)) hasLocalNode = true;
170168
}
171169
} else {
172170
Log.d(TAG, "No sync table given.");
@@ -184,7 +182,7 @@ public void onSetDataItem(SetDataItem setDataItem) {
184182
public void onRpcRequest(Request rpcRequest) {
185183
Log.d(TAG, "onRpcRequest: " + rpcRequest);
186184
if (TextUtils.isEmpty(rpcRequest.targetNodeId) || rpcRequest.targetNodeId.equals(wearable.getLocalNodeId())) {
187-
int requestId = rpcRequest.requestId != null ? rpcRequest.requestId : 0;
185+
int requestId = rpcRequest.requestId + 31 * (rpcRequest.generation + 527);
188186
String path = rpcRequest.path;
189187
byte[] data = rpcRequest.rawData != null ? rpcRequest.rawData.toByteArray() : null;
190188
String sourceNodeId = TextUtils.isEmpty(rpcRequest.sourceNodeId) ? peerNodeId : rpcRequest.sourceNodeId;
@@ -199,11 +197,6 @@ public void onRpcRequest(Request rpcRequest) {
199197
}
200198
}
201199

202-
@Override
203-
public void onRpcWithResponseId(Request rpcWithResponseId) {
204-
205-
}
206-
207200
@Override
208201
public void onHeartbeat(Heartbeat heartbeat) {
209202
Log.d(TAG, "onHeartbeat: " + heartbeat);
@@ -212,24 +205,14 @@ public void onHeartbeat(Heartbeat heartbeat) {
212205
@Override
213206
public void onFilePiece(FilePiece filePiece) {
214207
Log.d(TAG, "onFilePiece: " + filePiece);
215-
handleFilePiece(getConnection(), filePiece.fileName, filePiece.data.toByteArray(), filePiece.isFinalPiece ? filePiece.fileName : null);
208+
handleFilePiece(getConnection(), filePiece.fileName, filePiece.piece.toByteArray(), filePiece.finalPiece ? filePiece.digest : null);
216209
}
217210

218211
@Override
219212
public void onChannelRequest(Request channelRequest) {
220213
Log.d(TAG, "onChannelRequest:" + channelRequest);
221214
}
222215

223-
@Override
224-
public void onEncryptionHandshake(EncryptionHandshake encryptionHandshake) {
225-
226-
}
227-
228-
@Override
229-
public void onControlMessage(ControlMessage controlMessage) {
230-
231-
}
232-
233216
public void handleMessage(WearableConnection connection, String sourceNodeId, RootMessage message) {
234217
Log.d(TAG, "handleMessage from " + sourceNodeId);
235218

@@ -257,19 +240,19 @@ public void handleMessage(WearableConnection connection, String sourceNodeId, Ro
257240
if (message.filePiece != null) {
258241
FilePiece piece = message.filePiece;
259242
handleFilePiece(connection, piece.fileName,
260-
piece.data != null ? piece.data.toByteArray() : new byte[0], piece.isFinalPiece ? piece.fileName : null);
243+
piece.piece != null ? piece.piece.toByteArray() : new byte[0], piece.finalPiece ? piece.digest : null);
261244
}
262245

263-
if (message.removeAsset != null) {
264-
Log.d(TAG, "Asset acknowledged: " + message.removeAsset.name);
246+
if (message.ackAsset != null) {
247+
Log.d(TAG, "Asset acknowledged: " + message.ackAsset.digest);
265248
}
266249

267250
if (message.fetchAsset != null) {
268251
handleFetchAsset(connection, sourceNodeId, message.fetchAsset);
269252
}
270253

271254
if (message.setAsset != null) {
272-
handleSetAsset(connection, sourceNodeId, message.setAsset, message.hasFileAttachment);
255+
handleSetAsset(connection, sourceNodeId, message.setAsset, message.hasAsset);
273256
}
274257
}
275258

@@ -325,27 +308,27 @@ private void handleSetAsset(WearableConnection connection, String sourceNodeId,
325308
private void handleSyncStart(WearableConnection connection, String sourceNodeId,
326309
org.microg.gms.wearable.proto.SyncStart syncStart) {
327310
Log.d(TAG, "handleSyncStart from " + sourceNodeId +
328-
": timestamp=" + syncStart.timestamp +
329-
", sync_type=" + syncStart.sync_type);
311+
": receivedSeqId=" + syncStart.receivedSeqId +
312+
", version=" + syncStart.version);
330313

331314
if (syncStart.syncTable != null) {
332315
for (org.microg.gms.wearable.proto.SyncTableEntry entry : syncStart.syncTable) {
333-
Log.d(TAG, " Watch sync state: key=" + entry.uri + ", seqId=" + entry.version);
316+
Log.d(TAG, " Watch sync state: key=" + entry.key + ", seqId=" + entry.value);
334317
}
335318
}
336319

337320
try {
338321
List<SyncTableEntry> syncTable = new ArrayList<>();
339322
syncTable.add(new org.microg.gms.wearable.proto.SyncTableEntry.Builder()
340-
.uri(wearable.getLocalNodeId())
341-
.version(wearable.getClockworkNodePreferences().getNextSeqId() - 1)
323+
.key(wearable.getLocalNodeId())
324+
.value(wearable.getClockworkNodePreferences().getNextSeqId() - 1)
342325
.build());
343326

344327
RootMessage response = new RootMessage.Builder()
345328
.syncStart(new org.microg.gms.wearable.proto.SyncStart.Builder()
346-
.timestamp(syncStart.timestamp)
329+
.receivedSeqId(syncStart.receivedSeqId)
347330
.syncTable(syncTable)
348-
.sync_type(2)
331+
.version(2)
349332
.build())
350333
.build();
351334

@@ -354,8 +337,8 @@ private void handleSyncStart(WearableConnection connection, String sourceNodeId,
354337

355338
if (syncStart.syncTable != null) {
356339
for (org.microg.gms.wearable.proto.SyncTableEntry entry : syncStart.syncTable) {
357-
String nodeId = entry.uri;
358-
long theirSeqId = entry.version;
340+
String nodeId = entry.key;
341+
long theirSeqId = entry.value;
359342
wearable.syncToPeer(sourceNodeId, nodeId, theirSeqId);
360343
}
361344
}
@@ -415,16 +398,16 @@ private void fetchMissingAssets(WearableConnection connection, DataItemRecord re
415398

416399
private void handleFetchAsset(WearableConnection connection, String sourceNodeId,
417400
FetchAsset fetchAsset) {
418-
Log.d(TAG, "handleFetchAsset: " + fetchAsset.digest);
401+
Log.d(TAG, "handleFetchAsset: " + fetchAsset.assetName);
419402

420-
File assetFile = wearable.createAssetFile(fetchAsset.digest);
403+
File assetFile = wearable.createAssetFile(fetchAsset.assetName);
421404
if (assetFile.exists()) {
422405
try {
423406
RootMessage announceMessage = new RootMessage.Builder()
424407
.setAsset(new SetAsset.Builder()
425-
.digest(fetchAsset.digest)
408+
.digest(fetchAsset.assetName)
426409
.build())
427-
.hasFileAttachment(true)
410+
.hasAsset(true)
428411
.build();
429412
connection.writeMessage(announceMessage);
430413

@@ -443,13 +426,13 @@ private void handleFetchAsset(WearableConnection connection, String sourceNodeId
443426
}
444427
fis.close();
445428
connection.writeMessage(new RootMessage.Builder()
446-
.filePiece(new FilePiece(fileName, true, lastPiece, fetchAsset.digest))
429+
.filePiece(new FilePiece(fileName, true, lastPiece, fetchAsset.assetName))
447430
.build());
448431
} catch (IOException e) {
449432
Log.e(TAG, "Failed to send asset", e);
450433
}
451434
} else {
452-
Log.w(TAG, "Asset not found: " + fetchAsset.digest);
435+
Log.w(TAG, "Asset not found: " + fetchAsset.assetName);
453436
}
454437
}
455438

@@ -489,7 +472,7 @@ public void handleFilePiece(WearableConnection connection, String fileName, byte
489472

490473
try {
491474
connection.writeMessage(new RootMessage.Builder()
492-
.removeAsset(new RemoveAsset(digest))
475+
.ackAsset(new AckAsset(digest))
493476
.build());
494477
} catch (IOException e) {
495478
Log.w(TAG, "Failed to send asset ACK", e);
@@ -558,6 +541,7 @@ private static Connect buildConnect(Context ctx, WearableImpl wearable,
558541
.id(wearable.getLocalNodeId())
559542
.networkId(config.nodeId)
560543
.peerAndroidId(androidId)
544+
.unknown4(3)
561545
.peerVersion(2);
562546

563547
if (config.migrating && config.role == ROLE_SERVER) {

play-services-wearable/core/src/main/java/org/microg/gms/wearable/MessageListener.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55

66
package org.microg.gms.wearable;
77

8+
import org.microg.gms.wearable.proto.AckAsset;
89
import org.microg.gms.wearable.proto.Connect;
9-
import org.microg.gms.wearable.proto.ControlMessage;
10-
import org.microg.gms.wearable.proto.EncryptionHandshake;
1110
import org.microg.gms.wearable.proto.FetchAsset;
1211
import org.microg.gms.wearable.proto.FilePiece;
1312
import org.microg.gms.wearable.proto.Heartbeat;
14-
import org.microg.gms.wearable.proto.RemoveAsset;
1513
import org.microg.gms.wearable.proto.Request;
1614
import org.microg.gms.wearable.proto.RootMessage;
1715
import org.microg.gms.wearable.proto.SetAsset;
@@ -39,8 +37,8 @@ public WearableConnection getConnection() {
3937
public void onMessage(WearableConnection connection, RootMessage message) {
4038
if (message.setAsset != null) {
4139
onSetAsset(message.setAsset);
42-
} else if (message.removeAsset != null) {
43-
onRemoveAsset(message.removeAsset);
40+
} else if (message.ackAsset != null) {
41+
onAckAsset(message.ackAsset);
4442
} else if (message.fetchAsset != null) {
4543
onFetchAsset(message.fetchAsset);
4644
} else if (message.connect != null) {
@@ -51,26 +49,20 @@ public void onMessage(WearableConnection connection, RootMessage message) {
5149
onSetDataItem(message.setDataItem);
5250
} else if (message.rpcRequest != null) {
5351
onRpcRequest(message.rpcRequest);
54-
} else if (message.rpcWithResponseId != null) {
55-
onRpcWithResponseId(message.rpcWithResponseId);
5652
} else if (message.heartbeat != null) {
5753
onHeartbeat(message.heartbeat);
5854
} else if (message.filePiece != null) {
5955
onFilePiece(message.filePiece);
6056
} else if (message.channelRequest != null) {
6157
onChannelRequest(message.channelRequest);
62-
} else if (message.encryption_handshake != null) {
63-
onEncryptionHandshake(message.encryption_handshake);
64-
} else if (message.control_message != null) {
65-
onControlMessage(message.control_message);
6658
} else {
6759
System.err.println("Unknown message: " + message);
6860
}
6961
}
7062

7163
public abstract void onSetAsset(SetAsset setAsset);
7264

73-
public abstract void onRemoveAsset(RemoveAsset removeAsset);
65+
public abstract void onAckAsset(AckAsset ackAsset);
7466

7567
public abstract void onFetchAsset(FetchAsset fetchAsset);
7668

@@ -82,15 +74,9 @@ public void onMessage(WearableConnection connection, RootMessage message) {
8274

8375
public abstract void onRpcRequest(Request rpcRequest);
8476

85-
public abstract void onRpcWithResponseId(Request rpcWithResponseId);
86-
8777
public abstract void onHeartbeat(Heartbeat heartbeat);
8878

8979
public abstract void onFilePiece(FilePiece filePiece);
9080

9181
public abstract void onChannelRequest(Request channelRequest);
92-
93-
public abstract void onEncryptionHandshake(EncryptionHandshake encryptionHandshake);
94-
95-
public abstract void onControlMessage(ControlMessage controlMessage);
96-
}
82+
}

play-services-wearable/core/src/main/java/org/microg/gms/wearable/WearableImpl.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.microg.gms.common.RemoteListenerProxy;
4848
import org.microg.gms.common.Utils;
4949
import org.microg.gms.wearable.bluetooth.BluetoothClient;
50-
import org.microg.gms.wearable.bluetooth.NetworkConnectionManager;
5150
import org.microg.gms.wearable.channel.ChannelAssetApiEnum;
5251
import org.microg.gms.wearable.channel.ChannelCallbacks;
5352
import org.microg.gms.wearable.channel.ChannelManager;
@@ -120,8 +119,6 @@ public class WearableImpl {
120119

121120
private AssetFetcher assetFetcher;
122121

123-
private NetworkConnectionManager networkManager;
124-
125122
public WearableImpl(Context context, NodeDatabaseHelper nodeDatabase, ConfigurationDatabaseHelper configDatabase) {
126123
this.context = context;
127124
this.nodeDatabase = nodeDatabase;
@@ -568,7 +565,7 @@ private void syncAssetToPeer(WearableConnection connection, DataItemRecord recor
568565
new AppKey(record.packageName, record.signatureDigest)
569566
)
570567
)
571-
).build()).hasFileAttachment(true).build();
568+
).build()).hasAsset(true).build();
572569

573570
connection.writeMessage(announceMessage);
574571

@@ -907,15 +904,7 @@ private void handleBle(ConnectionConfiguration config, boolean enabled) {
907904
}
908905

909906
private void handleNetwork(ConnectionConfiguration config, boolean enabled) {
910-
if (networkManager == null) {
911-
networkManager = new NetworkConnectionManager(context, this);
912-
}
913-
914-
if (enabled) {
915-
networkManager.addConfig(config);
916-
} else {
917-
networkManager.removeConfig(config);
918-
}
907+
Log.w(TAG, "Network not implemented");
919908
}
920909

921910
private void handleLegacy(ConnectionConfiguration config, boolean enabled) {
@@ -1015,9 +1004,11 @@ public int sendMessage(String packageName, String targetNodeId, String path, byt
10151004
.path(path)
10161005
.rawData(ByteString.of(data))
10171006
.packageName(packageName)
1007+
.signatureDigest(PackageUtils.firstSignatureDigest(context, packageName))
10181008
.sourceNodeId(getLocalNodeId())
1009+
.generation(state.generation)
10191010
.requestId(state.lastRequestId)
1020-
.is_response(true)
1011+
.requiresResponse(true)
10211012
.build()).build());
10221013
} catch (IOException e) {
10231014
Log.w(TAG, "Error while writing, closing link", e);

0 commit comments

Comments
 (0)