From c7ebe6e80eb567075e76a6d0ff0e909b3b76b3d1 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 10 Dec 2019 14:42:54 -0800 Subject: [PATCH] add debug-only pending-msg count to connstatus display I'm bringing this in from another branch because it'll be useful for debugging bluetooth problems. --- xwords4/android/app/build.gradle | 10 +++---- .../java/org/eehouse/android/xw4/Assert.java | 1 + .../eehouse/android/xw4/BoardDelegate.java | 7 +++++ .../eehouse/android/xw4/CommsTransport.java | 14 +++++++-- .../android/xw4/ConnStatusHandler.java | 29 ++++++++++++++++++- .../org/eehouse/android/xw4/MultiMsgSink.java | 17 ++++++++--- .../eehouse/android/xw4/NetLaunchInfo.java | 10 +++++-- .../eehouse/android/xw4/jni/CommsAddrRec.java | 2 ++ .../android/xw4/jni/TransportProcs.java | 3 ++ xwords4/android/jni/xportwrapper.c | 14 +++++++++ xwords4/common/comms.c | 12 ++++++++ xwords4/common/comms.h | 3 ++ xwords4/linux/cursesmain.c | 7 +++++ xwords4/linux/gtkboard.c | 14 +++++++++ xwords4/linux/gtkboard.h | 1 + 15 files changed, 129 insertions(+), 15 deletions(-) diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle index d27b8170a..b74c4495a 100644 --- a/xwords4/android/app/build.gradle +++ b/xwords4/android/app/build.gradle @@ -67,7 +67,7 @@ android { flavorDimensions "variant"//, "abi" productFlavors { all { - buildConfigField "String", "DB_NAME", "\"xwdb\""; + buildConfigField "String", "DB_NAME", "\"xwdb\"" buildConfigField "String", "BUILD_INFO_NAME", "\"${BUILD_INFO_NAME}\"" buildConfigField "boolean", "IS_TAGGED_BUILD", "${CURTAG}" == '' ? "false" : "true" resValue "string", "invite_prefix", "/and/" @@ -257,7 +257,7 @@ android { } ext { - SUPPORT_LIB_VERSION = '27.1.1' + SUPPORT_LIB_VERSION = '28.0.0' } dependencies { @@ -270,10 +270,10 @@ dependencies { // 2.6.8 is probably as far forward as I can go without upping my // min-supported SDK version xw4dImplementation('com.crashlytics.sdk.android:crashlytics:2.6.3@aar') { // rm-for-fdroid - transitive = true; // rm-for-fdroid + transitive = true // rm-for-fdroid } // rm-for-fdroid xw4dNoSMSImplementation('com.crashlytics.sdk.android:crashlytics:2.6.3@aar') { // rm-for-fdroid - transitive = true; // rm-for-fdroid + transitive = true // rm-for-fdroid } // rm-for-fdroid implementation 'com.google.firebase:firebase-messaging:17.3.4' // rm-for-fdroid @@ -320,7 +320,7 @@ task mkXml(type: Exec) { } afterEvaluate { - ArrayList cleanCmdLst = new ArrayList<>(["rm", "-rf"]); + ArrayList cleanCmdLst = new ArrayList<>(["rm", "-rf"]) android.applicationVariants.all { variant -> // print "variant: " + variant.name + "\n" String BUILD = variant.getBuildType().getName() diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Assert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Assert.java index 4df7486c5..b93a56d10 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Assert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Assert.java @@ -37,6 +37,7 @@ public class Assert { Log.e( TAG, "firing assert!" ); DbgUtils.printStack( TAG ); assert false; + throw new RuntimeException(); } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java index 618ba381a..8ec61e6b9 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java @@ -1490,6 +1490,13 @@ public class BoardDelegate extends DelegateBase } } + @Override + public void tpmCountChanged( int newCount ) + { + Log.d( TAG, "tpmCountChanged(%d)", newCount ); + ConnStatusHandler.updateMoveCount( m_activity, newCount ); + } + ////////////////////////////////////////////////// // DwnldActivity.DownloadFinishedListener interface ////////////////////////////////////////////////// diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/CommsTransport.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/CommsTransport.java index e9b6d389e..9cbab9934 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/CommsTransport.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/CommsTransport.java @@ -416,9 +416,15 @@ public class CommsTransport implements TransportProcs, return success; } - private static int sendForAddr( Context context, CommsAddrRec addr, - CommsConnType conType, long rowID, - int gameID, byte[] buf, String msgID ) + @Override + public void countChanged( int newCount ) + { + m_tpHandler.tpmCountChanged( newCount ); + } + + private int sendForAddr( Context context, CommsAddrRec addr, + CommsConnType conType, long rowID, + int gameID, byte[] buf, String msgID ) { int nSent = -1; switch ( conType ) { @@ -437,6 +443,8 @@ public class CommsTransport implements TransportProcs, nSent = WiDirService .sendPacket( context, addr.p2p_addr, gameID, buf ); break; + case COMMS_CONN_NFC: + break; default: Assert.fail(); break; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnStatusHandler.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnStatusHandler.java index 89b1c5403..a4676a623 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnStatusHandler.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnStatusHandler.java @@ -23,6 +23,7 @@ package org.eehouse.android.xw4; import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.drawable.Drawable; @@ -61,8 +62,14 @@ public class ConnStatusHandler { private static Rect s_rect; private static boolean s_downOnMe = false; private static ConnStatusCBacks s_cbacks; - private static Paint s_fillPaint = new Paint( Paint.ANTI_ALIAS_FLAG ); + private static Paint s_fillPaint; + static { + s_fillPaint = new Paint( Paint.ANTI_ALIAS_FLAG ); + s_fillPaint.setTextAlign( Paint.Align.CENTER ); + } + private static boolean[] s_showSuccesses = { false, false }; + private static int s_moveCount = 0; private static class SuccessRecord implements java.io.Serializable { public long lastSuccess; @@ -122,6 +129,7 @@ public class ConnStatusHandler { public static void setRect( int left, int top, int right, int bottom ) { s_rect = new Rect( left, top, right, bottom ); + s_fillPaint.setTextSize( s_rect.height()/2 ); } public static void clearRect() @@ -330,6 +338,14 @@ public class ConnStatusHandler { } } + public static void updateMoveCount( Context context, int newCount ) + { + if ( BuildConfig.DEBUG ) { + s_moveCount = newCount; + invalidateParent(); + } + } + public static void updateStatus( Context context, ConnStatusCBacks cbacks, CommsConnType connType, boolean success ) { @@ -436,6 +452,14 @@ public class ConnStatusHandler { || 1 >= Math.abs(scratchR.width() - scratchR.height()) ); drawIn( canvas, res, R.drawable.multigame__gen, scratchR ); + + if ( BuildConfig.DEBUG && 0 < s_moveCount ) { + String str = String.format( "%d", s_moveCount ); + s_fillPaint.setColor( Color.BLACK ); + canvas.drawText( str, s_rect.left + (s_rect.width() / 2), + s_rect.top + (s_rect.height()*2/3), + s_fillPaint ); + } } } } @@ -622,6 +646,9 @@ public class ConnStatusHandler { case COMMS_CONN_P2P: result = WiDirService.connecting(); break; + case COMMS_CONN_NFC: + result = NFCUtils.nfcAvail( context )[1]; + break; default: Log.w( TAG, "connTypeEnabled: %s not handled", connType.toString() ); break; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiMsgSink.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiMsgSink.java index 33be8f3d8..bb1a7cdf5 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiMsgSink.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiMsgSink.java @@ -56,24 +56,24 @@ public class MultiMsgSink implements TransportProcs { // These will be overridden by e.g. BTService which for sendViaBluetooth() // can just insert a message into its queue - public int sendViaRelay( byte[] buf, String msgID, int gameID ) + int sendViaRelay( byte[] buf, String msgID, int gameID ) { Assert.assertTrue( BuildConfig.UDP_ENABLED ); return RelayService.sendPacket( m_context, getRowID(), buf, msgID ); } - public int sendViaBluetooth( byte[] buf, String msgID, int gameID, + int sendViaBluetooth( byte[] buf, String msgID, int gameID, CommsAddrRec addr ) { return BTService.sendPacket( m_context, buf, msgID, addr, gameID ); } - public int sendViaSMS( byte[] buf, String msgID, int gameID, CommsAddrRec addr ) + int sendViaSMS( byte[] buf, String msgID, int gameID, CommsAddrRec addr ) { return NBSProto.sendPacket( m_context, addr.sms_phone, gameID, buf, msgID ); } - public int sendViaP2P( byte[] buf, int gameID, CommsAddrRec addr ) + int sendViaP2P( byte[] buf, int gameID, CommsAddrRec addr ) { return WiDirService .sendPacket( m_context, addr.p2p_addr, gameID, buf ); @@ -106,6 +106,9 @@ public class MultiMsgSink implements TransportProcs { case COMMS_CONN_P2P: nSent = sendViaP2P( buf, gameID, addr ); break; + case COMMS_CONN_NFC: + Log.d( TAG, "transportSend(): got for NFC" ); + break; default: Assert.fail(); break; @@ -133,6 +136,12 @@ public class MultiMsgSink implements TransportProcs { { } + @Override + public void countChanged( int newCount ) + { + Log.d( TAG, "countChanged(new=%d); dropping", newCount ); + } + @Override public boolean relayNoConnProc( byte[] buf, String msgNo, String relayID ) { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetLaunchInfo.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetLaunchInfo.java index e6d1b3315..2a5bd78bc 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetLaunchInfo.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetLaunchInfo.java @@ -40,7 +40,6 @@ import java.util.List; import org.json.JSONException; import org.json.JSONObject; - import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; import org.eehouse.android.xw4.jni.CommsAddrRec; @@ -155,7 +154,7 @@ public class NetLaunchInfo implements Serializable { String nliData = dis.readUTF(); nli = NetLaunchInfo.makeFrom( context, nliData ); } catch ( java.io.IOException ex ) { - Assert.assertFalse( BuildConfig.DEBUG ); + Log.d( TAG, "not an nli" ); } return nli; } @@ -294,6 +293,8 @@ public class NetLaunchInfo implements Serializable { case COMMS_CONN_P2P: addP2PInfo( context ); break; + case COMMS_CONN_NFC: + break; default: Assert.fail(); break; @@ -448,6 +449,8 @@ public class NetLaunchInfo implements Serializable { case COMMS_CONN_P2P: result.setP2PParams( p2pMacAddress ); break; + case COMMS_CONN_NFC: + break; default: Assert.fail(); break; @@ -503,6 +506,9 @@ public class NetLaunchInfo implements Serializable { p2pMacAddress = json.optString( P2P_MAC_KEY ); doAdd = !hasAddrs && null != p2pMacAddress; break; + case COMMS_CONN_NFC: + doAdd = NFCUtils.nfcAvail( context )[0]; + break; default: doAdd = false; Assert.fail(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java index 6a9f79cfb..d419e496d 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java @@ -403,6 +403,8 @@ public class CommsAddrRec { case COMMS_CONN_P2P: p2p_addr = WiDirService.getMyMacAddress( context ); break; + case COMMS_CONN_NFC: + break; default: Assert.fail(); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/TransportProcs.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/TransportProcs.java index b76064e27..419d60a4a 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/TransportProcs.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/TransportProcs.java @@ -41,6 +41,8 @@ public interface TransportProcs { void relayConnd( String room, int devOrder, boolean allHere, int nMissing ); + void countChanged( int newCount ); + public static enum XWRELAY_ERROR { NONE ,OLDFLAGS ,BADPROTO @@ -66,5 +68,6 @@ public interface TransportProcs { public void tpmRelayConnd( String room, int devOrder, boolean allHere, int nMissing ); public void tpmRelayErrorProc( XWRELAY_ERROR relayErr ); + public void tpmCountChanged( int newCount ); } } diff --git a/xwords4/android/jni/xportwrapper.c b/xwords4/android/jni/xportwrapper.c index 436623c6f..f3c8597d3 100644 --- a/xwords4/android/jni/xportwrapper.c +++ b/xwords4/android/jni/xportwrapper.c @@ -145,6 +145,19 @@ and_xport_sendNoConn( const XP_U8* buf, XP_U16 len, const XP_UCHAR* msgNo, return result; } +static void +and_xport_countChanged( void* closure, XP_U16 count ) +{ + XP_LOGF( "%s(count=%d)", __func__, count ); + AndTransportProcs* aprocs = (AndTransportProcs*)closure; + if ( NULL != aprocs && NULL != aprocs->jxport ) { + JNIEnv* env = ENVFORME( aprocs->ti ); + const char* sig = "(I)V"; + jmethodID mid = getMethodID( env, aprocs->jxport, "countChanged", sig ); + (*env)->CallVoidMethod( env, aprocs->jxport, mid, count ); + } +} + static void and_xport_relayError( void* closure, XWREASON relayErr ) { @@ -185,6 +198,7 @@ makeXportProcs( MPFORMAL EnvThreadInfo* ti, jobject jxport ) aprocs->tp.rconnd = and_xport_relayConnd; aprocs->tp.rerror = and_xport_relayError; aprocs->tp.sendNoConn = and_xport_sendNoConn; + aprocs->tp.countChanged = and_xport_countChanged; aprocs->tp.closure = aprocs; return (TransportProcs*)aprocs; diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c index d970c55fb..bbf0cd805 100644 --- a/xwords4/common/comms.c +++ b/xwords4/common/comms.c @@ -203,6 +203,7 @@ static void freeElem( const CommsCtxt* comms, MsgQueueElem* elem ); static XP_U16 countAddrRecs( const CommsCtxt* comms ); static void sendConnect( CommsCtxt* comms, XP_Bool breakExisting ); +static void notifyQueueChanged( const CommsCtxt* comms ); #if 0 < COMMS_VERSION static XP_U16 makeFlags( const CommsCtxt* comms ); #endif @@ -750,6 +751,8 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util, } } + notifyQueueChanged( comms ); + return comms; } /* comms_makeFromStream */ @@ -1244,6 +1247,13 @@ comms_send( CommsCtxt* comms, XWStreamCtxt* stream ) return result; } /* comms_send */ +static void +notifyQueueChanged( const CommsCtxt* comms ) +{ + XP_U16 count = comms->queueLen; + (*comms->procs.countChanged)( comms->procs.closure, count ); +} + /* Add new message to the end of the list. The list needs to be kept in order * by ascending msgIDs within each channel since if there's a resend that's * the order in which they need to be sent. @@ -1272,6 +1282,7 @@ addToQueue( CommsCtxt* comms, MsgQueueElem* newElem ) if ( newElem == asAdded ) { ++comms->queueLen; + notifyQueueChanged( comms ); } XP_ASSERT( comms->queueLen <= 128 ); /* reasonable limit in testing */ return asAdded; @@ -1388,6 +1399,7 @@ removeFromQueue( CommsCtxt* comms, XP_PlayerAddr channelNo, MsgID msgID ) elem = asAdded; /* for non-assert case */ } } + notifyQueueChanged( comms ); } XP_LOGF( "%s: queueLen now %d", __func__, comms->queueLen ); diff --git a/xwords4/common/comms.h b/xwords4/common/comms.h index 97e46bdf2..4547647d4 100644 --- a/xwords4/common/comms.h +++ b/xwords4/common/comms.h @@ -147,6 +147,8 @@ typedef void (*RelayRequestJoinProc)( void* closure, const XP_UCHAR* devID, # endif #endif +typedef void (*MsgCountChange)( void* closure, XP_U16 msgCount ); + typedef enum { COMMS_XPORT_FLAGS_NONE = 0 ,COMMS_XPORT_FLAGS_HASNOCONN = 1 @@ -174,6 +176,7 @@ typedef struct _TransportProcs { # ifdef RELAY_VIA_HTTP RelayRequestJoinProc requestJoin; # endif + MsgCountChange countChanged; #endif void* closure; } TransportProcs; diff --git a/xwords4/linux/cursesmain.c b/xwords4/linux/cursesmain.c index 4ae3ab22a..bed4a4838 100644 --- a/xwords4/linux/cursesmain.c +++ b/xwords4/linux/cursesmain.c @@ -1872,6 +1872,12 @@ smsMsgReceivedCurses( void* closure, const CommsAddrRec* from, /* } */ } +static void +curses_countChanged( void* XP_UNUSED(closure), XP_U16 newCount ) +{ + XP_LOGF( "%s(newCount=%d)", __func__, newCount ); +} + void cursesmain( XP_Bool isServer, LaunchParams* params ) { @@ -1965,6 +1971,7 @@ cursesmain( XP_Bool isServer, LaunchParams* params ) #ifdef RELAY_VIA_HTTP .requestJoin = relay_requestJoin_curses, #endif + .countChanged = curses_countChanged, # ifdef COMMS_XPORT_FLAGSPROC .getFlags = curses_getFlags, diff --git a/xwords4/linux/gtkboard.c b/xwords4/linux/gtkboard.c index d35875e52..17e62780f 100644 --- a/xwords4/linux/gtkboard.c +++ b/xwords4/linux/gtkboard.c @@ -484,6 +484,15 @@ gtk_getFlags( void* closure ) } #endif +static void +countChanged_gtk( void* closure, XP_U16 newCount ) +{ + GtkGameGlobals* globals = (GtkGameGlobals*)closure; + gchar buf[128]; + snprintf( buf, VSIZE(buf), "pending count: %d", newCount ); + gtk_label_set_text( GTK_LABEL(globals->countLabel), buf ); +} + static void setTransportProcs( TransportProcs* procs, GtkGameGlobals* globals ) { @@ -503,6 +512,7 @@ setTransportProcs( TransportProcs* procs, GtkGameGlobals* globals ) # ifdef RELAY_VIA_HTTP procs->requestJoin = relay_requestJoin_gtk; # endif + procs->countChanged = countChanged_gtk; #endif } @@ -2815,6 +2825,10 @@ initGlobals( GtkGameGlobals* globals, LaunchParams* params, CurGameInfo* gi ) gtk_box_pack_start( GTK_BOX(vbox), hbox/* drawing_area */, TRUE, TRUE, 0); + GtkWidget* label = globals->countLabel = gtk_label_new( "" ); + gtk_box_pack_start( GTK_BOX(vbox), label, TRUE, TRUE, 0); + gtk_widget_show( label ); + id = g_signal_connect( drawing_area, "configure-event", G_CALLBACK(configure_event), globals ); XP_ASSERT( id > 0 ); diff --git a/xwords4/linux/gtkboard.h b/xwords4/linux/gtkboard.h index d2abde645..72a1867f6 100644 --- a/xwords4/linux/gtkboard.h +++ b/xwords4/linux/gtkboard.h @@ -117,6 +117,7 @@ typedef struct GtkGameGlobals { #ifdef XWFEATURE_CHAT GtkWidget* chat_button; #endif + GtkWidget* countLabel; EngineCtxt* engine;