diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetUtils.java index abfa4893c..5f085cf25 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetUtils.java @@ -120,10 +120,10 @@ public class NetUtils { } } - public static String[] queryRelay( Context context, String[] ids, - int nBytes ) + public static byte[][][] queryRelay( Context context, String[] ids, + int nBytes ) { - String[] result = null; + byte[][][] msgs = null; try { Socket socket = MakeProxySocket( context, 8000 ); DataOutputStream outStream = @@ -148,7 +148,7 @@ public class NetUtils { new DataInputStream(socket.getInputStream()); short resLen = dis.readShort(); short nameCount = dis.readShort(); - byte[][][] msgs = null; + if ( nameCount == ids.length ) { msgs = new byte[nameCount][][]; for ( int ii = 0; ii < nameCount; ++ii ) { @@ -168,25 +168,6 @@ public class NetUtils { } socket.close(); - if ( null != msgs ) { - ArrayList idsWMsgs = - new ArrayList( nameCount ); - for ( int ii = 0; ii < nameCount; ++ii ) { - // if game has messages, open it and feed 'em - // to it. - if ( null != msgs[ii] ) { - if( GameUtils.feedMessages( context, ids[ii], - msgs[ii] ) ) { - idsWMsgs.add( ids[ii] ); - } - } - } - if ( 0 < idsWMsgs.size() ) { - ids = new String[idsWMsgs.size()]; - result = idsWMsgs.toArray( ids ); - } - } - } catch( java.net.UnknownHostException uhe ) { Utils.logf( uhe.toString() ); } catch( java.io.IOException ioe ) { @@ -194,7 +175,7 @@ public class NetUtils { } catch( NullPointerException npe ) { Utils.logf( npe.toString() ); } - return result; + return msgs; } // queryRelay } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java index 7ef40e73a..7572795a8 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java @@ -51,12 +51,31 @@ public class RelayService extends Service { int[] nBytes = new int[1]; String[] ids = collectIDs( nBytes ); if ( null != ids && 0 < ids.length ) { - String[] relayIDs = + byte[][][] msgs = NetUtils.queryRelay( RelayService.this, ids, nBytes[0] ); - if ( null != relayIDs ) { - if ( !DispatchNotify.tryHandle( relayIDs ) ) { - setupNotification( relayIDs ); + + int nameCount = ids.length; + if ( null != msgs ) { + ArrayList idsWMsgs = + new ArrayList( nameCount ); + for ( int ii = 0; ii < nameCount; ++ii ) { + // if game has messages, open it and feed 'em + // to it. + if ( null != msgs[ii] ) { + if ( GameUtils.feedMessages( RelayService.this, + ids[ii], + msgs[ii] ) ) { + idsWMsgs.add( ids[ii] ); + } + } + } + if ( 0 < idsWMsgs.size() ) { + String[] relayIDs = new String[idsWMsgs.size()]; + idsWMsgs.toArray( relayIDs ); + if ( !DispatchNotify.tryHandle( relayIDs ) ) { + setupNotification( relayIDs ); + } } } }