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.
This commit is contained in:
Eric House 2019-12-10 14:42:54 -08:00
parent b7ef8935d8
commit c7ebe6e80e
15 changed files with 129 additions and 15 deletions

View file

@ -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<String> cleanCmdLst = new ArrayList<>(["rm", "-rf"]);
ArrayList<String> cleanCmdLst = new ArrayList<>(["rm", "-rf"])
android.applicationVariants.all { variant ->
// print "variant: " + variant.name + "\n"
String BUILD = variant.getBuildType().getName()

View file

@ -37,6 +37,7 @@ public class Assert {
Log.e( TAG, "firing assert!" );
DbgUtils.printStack( TAG );
assert false;
throw new RuntimeException();
}
}

View file

@ -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
//////////////////////////////////////////////////

View file

@ -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;

View file

@ -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;

View file

@ -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 )
{

View file

@ -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();

View file

@ -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();
}

View file

@ -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 );
}
}

View file

@ -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;

View file

@ -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 );

View file

@ -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;

View file

@ -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,

View file

@ -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 );

View file

@ -117,6 +117,7 @@ typedef struct GtkGameGlobals {
#ifdef XWFEATURE_CHAT
GtkWidget* chat_button;
#endif
GtkWidget* countLabel;
EngineCtxt* engine;