From 2e30ccd4c6a61178f943b92092576b040cf75ee4 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 22 May 2013 06:45:34 -0700 Subject: [PATCH] expect array of message bodies rather than just one --- .../eehouse/android/xw4/GCMIntentService.java | 14 +++++++++-- .../org/eehouse/android/xw4/RelayService.java | 24 +++++++++++-------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GCMIntentService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GCMIntentService.java index 23285a1fa..99945ca0a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GCMIntentService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GCMIntentService.java @@ -25,6 +25,7 @@ import android.content.Context; import android.content.Intent; import com.google.android.gcm.GCMBaseIntentService; import com.google.android.gcm.GCMRegistrar; +import org.json.JSONArray; public class GCMIntentService extends GCMBaseIntentService { @@ -63,11 +64,20 @@ public class GCMIntentService extends GCMBaseIntentService { RelayReceiver.RestartTimer( context, true ); } - value = intent.getStringExtra( "msg64" ); + value = intent.getStringExtra( "msgs64" ); if ( null != value ) { String connname = intent.getStringExtra( "connname" ); if ( null != connname ) { - RelayService.processMsg( context, connname, value ); + try { + JSONArray msgs64 = new JSONArray( value ); + String[] strs64 = new String[msgs64.length()]; + for ( int ii = 0; ii < strs64.length; ++ii ) { + strs64[ii] = msgs64.optString(ii); + } + RelayService.processMsgs( context, connname, strs64 ); + } catch (org.json.JSONException jse ) { + DbgUtils.loge( jse ); + } } } 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 0c2afed9f..8a97dc766 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java @@ -40,16 +40,15 @@ public class RelayService extends Service { private static final int MAX_BUF = MAX_SEND - 2; private static final String CMD_STR = "CMD"; - private static final int PROCESS_MSG = 1; - private static final String MSG = "MSG"; + private static final int PROCESS_MSGS = 1; + private static final String MSGS = "MSGS"; private static final String RELAY_ID = "RELAY_ID"; - public static void processMsg( Context context, String relayId, - String msg64 ) + public static void processMsgs( Context context, String relayId, + String[] msgs64 ) { - byte[] msg = XwJNI.base64Decode( msg64 ); - Intent intent = getIntentTo( context, PROCESS_MSG ) - .putExtra( MSG, msg ) + Intent intent = getIntentTo( context, PROCESS_MSGS ) + .putExtra( MSGS, msgs64 ) .putExtra( RELAY_ID, relayId ); context.startService( intent ); } @@ -86,13 +85,18 @@ public class RelayService extends Service { { int cmd = intent.getIntExtra( CMD_STR, -1 ); switch( cmd ) { - case PROCESS_MSG: + case PROCESS_MSGS: String[] relayIDs = new String[1]; relayIDs[0] = intent.getStringExtra( RELAY_ID ); long[] rowIDs = DBUtils.getRowIDsFor( this, relayIDs[0] ); if ( 0 < rowIDs.length ) { - byte[][][] msgs = new byte[1][1][1]; - msgs[0][0] = intent.getByteArrayExtra( MSG ); + String[] msgs64 = intent.getStringArrayExtra( MSGS ); + int count = msgs64.length; + + byte[][][] msgs = new byte[1][count][]; + for ( int ii = 0; ii < count; ++ii ) { + msgs[0][ii] = XwJNI.base64Decode( msgs64[ii] ); + } process( msgs, rowIDs, relayIDs ); } break;