@@ -417,9 +417,7 @@ public void onConnectedNodes(List<NodeParcelable> nodes) {
417
417
}
418
418
419
419
public DataItemRecord putData (PutDataRequest request , String packageName ) {
420
- String host = request .getUri ().getHost ();
421
- if (TextUtils .isEmpty (host )) host = getLocalNodeId ();
422
- DataItemInternal dataItem = new DataItemInternal (host , request .getUri ().getPath ());
420
+ DataItemInternal dataItem = new DataItemInternal (fixHost (request .getUri ().getHost (), true ), request .getUri ().getPath ());
423
421
for (Map .Entry <String , Asset > assetEntry : request .getAssets ().entrySet ()) {
424
422
Asset asset = prepareAsset (packageName , assetEntry .getValue ());
425
423
if (asset != null ) {
@@ -443,30 +441,36 @@ public DataHolder getDataItemsAsHolder(String packageName) {
443
441
return DataHolder .fromCursor (dataHolderItems , 0 , null );
444
442
}
445
443
444
+ private String fixHost (String host , boolean nothingToLocal ) {
445
+ if (TextUtils .isEmpty (host ) && nothingToLocal ) return getLocalNodeId ();
446
+ if (TextUtils .isEmpty (host )) return null ;
447
+ if (host .equals ("local" )) return getLocalNodeId ();
448
+ return host ;
449
+ }
450
+
446
451
public DataHolder getDataItemsByUriAsHolder (Uri uri , String packageName ) {
447
452
String firstSignature ;
448
453
try {
449
454
firstSignature = PackageUtils .firstSignatureDigest (context , packageName );
450
455
} catch (Exception e ) {
451
456
return null ;
452
457
}
453
- Cursor dataHolderItems = nodeDatabase .getDataItemsForDataHolderByHostAndPath (packageName , firstSignature , uri .getHost (), uri .getPath ());
454
- while (dataHolderItems .moveToNext ()) {
455
- Log .d (TAG , "getDataItems[]: path=" + Uri .parse (dataHolderItems .getString (1 )).getPath ());
456
- }
457
- dataHolderItems .moveToFirst ();
458
- dataHolderItems .moveToPrevious ();
459
- return new DataHolder (dataHolderItems , 0 , null );
460
- }
461
-
462
- public DataHolder getDataItemForRecordAsHolder (DataItemRecord record ) {
463
- Cursor dataHolderItems = nodeDatabase .getDataItemsForDataHolderByHostAndPath (record .packageName , record .signatureDigest , record .dataItem .uri .getHost (), record .dataItem .uri .getPath ());
458
+ Cursor dataHolderItems = nodeDatabase .getDataItemsForDataHolderByHostAndPath (packageName , firstSignature , fixHost (uri .getHost (), false ), uri .getPath ());
459
+ int j = 0 ;
464
460
while (dataHolderItems .moveToNext ()) {
465
- Log .d (TAG , "getDataItems[]: path=" + Uri .parse (dataHolderItems .getString (1 )).getPath ());
461
+ for (int i = 0 ; i < dataHolderItems .getColumnCount (); i ++) {
462
+ if (dataHolderItems .getType (i ) == Cursor .FIELD_TYPE_STRING ) {
463
+ Log .d (TAG , "getDataItems[" + j + "]: " + dataHolderItems .getColumnName (i ) + "=" + dataHolderItems .getString (i ));
464
+ }
465
+ if (dataHolderItems .getType (i ) == Cursor .FIELD_TYPE_INTEGER )
466
+ Log .d (TAG , "getDataItems[" + j + "]: " + dataHolderItems .getColumnName (i ) + "=" + dataHolderItems .getLong (i ));
467
+ }
466
468
}
467
469
dataHolderItems .moveToFirst ();
468
470
dataHolderItems .moveToPrevious ();
469
- return new DataHolder (dataHolderItems , 0 , null );
471
+ DataHolder dataHolder = new DataHolder (dataHolderItems , 0 , null );
472
+ Log .d (TAG , "Returning data holder of size " + dataHolder .getCount () + " for query " + uri );
473
+ return dataHolder ;
470
474
}
471
475
472
476
public synchronized void addListener (String packageName , IWearableListener listener ) {
@@ -515,7 +519,7 @@ public void createConnection(ConnectionConfiguration config) {
515
519
}
516
520
517
521
public int deleteDataItems (Uri uri , String packageName ) {
518
- List <DataItemRecord > records = nodeDatabase .deleteDataItems (packageName , PackageUtils .firstSignatureDigest (context , packageName ), uri .getHost (), uri .getPath ());
522
+ List <DataItemRecord > records = nodeDatabase .deleteDataItems (packageName , PackageUtils .firstSignatureDigest (context , packageName ), fixHost ( uri .getHost (), false ), uri .getPath ());
519
523
for (DataItemRecord record : records ) {
520
524
syncRecordToAll (record );
521
525
}
@@ -533,7 +537,7 @@ public void sendMessageReceived(String packageName, MessageEventParcelable messa
533
537
}
534
538
535
539
public DataItemRecord getDataItemByUri (Uri uri , String packageName ) {
536
- Cursor cursor = nodeDatabase .getDataItemsByHostAndPath (packageName , PackageUtils .firstSignatureDigest (context , packageName ), uri .getHost (), uri .getPath ());
540
+ Cursor cursor = nodeDatabase .getDataItemsByHostAndPath (packageName , PackageUtils .firstSignatureDigest (context , packageName ), fixHost ( uri .getHost (), true ), uri .getPath ());
537
541
DataItemRecord record = null ;
538
542
if (cursor != null ) {
539
543
if (cursor .moveToNext ()) {
0 commit comments