explain where deleted game message comes from

Not sure it'll make release builds, but it's useful for figuring out if
the deletes should actually be there.
This commit is contained in:
Eric House 2020-11-23 21:35:35 -08:00
parent 48cf291c5a
commit 82a11e5ebf
5 changed files with 50 additions and 18 deletions

View file

@ -53,6 +53,7 @@ import org.eehouse.android.xw4.DbgUtils.DeadlockWatch;
import org.eehouse.android.xw4.MultiService.DictFetchOwner;
import org.eehouse.android.xw4.MultiService.MultiEvent;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec.ConnExpl;
import org.eehouse.android.xw4.jni.CommsAddrRec;
import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.loc.LocUtils;
@ -962,7 +963,8 @@ public class BTUtils {
mHelper.postEvent( MultiEvent.BAD_PROTO_BT,
socket.getRemoteDevice().getName() );
} else {
handleReply( inStream, cmd, gameID, reply );
String remoteName = socket.getRemoteDevice().getName();
handleReply( inStream, cmd, gameID, remoteName, reply );
}
++nDone;
}
@ -979,18 +981,19 @@ public class BTUtils {
} // writeAndCheck()
private void handleReply( DataInputStream inStream, BTCmd cmd, int gameID,
BTCmd reply ) throws IOException
String remoteName, BTCmd reply ) throws IOException
{
MultiEvent evt = null;
switch ( cmd ) {
case MESG_SEND:
case MESG_GAMEGONE:
switch ( reply ) {
case MESG_ACCPT:
evt = MultiEvent.MESSAGE_ACCEPTED;
mHelper.postEvent( MultiEvent.MESSAGE_ACCEPTED, gameID, 0, mName );
break;
case MESG_GAMEGONE:
evt = MultiEvent.MESSAGE_NOGAME;
ConnExpl expl = new ConnExpl( CommsConnType.COMMS_CONN_BT,
remoteName );
mHelper.postEvent( MultiEvent.MESSAGE_NOGAME, gameID, expl );
break;
}
break;
@ -1028,10 +1031,6 @@ public class BTUtils {
Log.e( TAG, "handleReply(cmd=%s) case not handled", cmd );
Assert.failDbg(); // fired
}
if ( null != evt ) {
mHelper.postEvent( evt, gameID, 0, mName );
}
}
private BluetoothSocket connect( BluetoothDevice remote, int timeout )

View file

@ -262,8 +262,14 @@ public class BoardDelegate extends DelegateBase
case DLG_DELETED: {
String gameName = GameUtils.getName( m_activity, m_rowid );
CommsAddrRec.ConnExpl expl = params.length == 0 ? null
: (CommsAddrRec.ConnExpl)params[0];
String message = getString( R.string.msg_dev_deleted_fmt, gameName );
if ( null != expl ) {
message += "\n\n" + expl.getUserExpl( m_activity );
}
ab = ab.setTitle( R.string.query_title )
.setMessage( getString( R.string.msg_dev_deleted_fmt, gameName ) )
.setMessage( message )
.setPositiveButton( android.R.string.ok, null );
lstnr = new OnClickListener() {
@Override
@ -429,7 +435,7 @@ public class BoardDelegate extends DelegateBase
} // makeDialog
private boolean mDeletePosted;
private void postDeleteOnce()
private void postDeleteOnce( final CommsAddrRec.ConnExpl expl )
{
if ( !mDeletePosted ) {
// PENDING: could clear this if user says "ok" rather than "delete"
@ -437,7 +443,7 @@ public class BoardDelegate extends DelegateBase
post( new Runnable() {
@Override
public void run() {
showDialogFragment( DlgID.DLG_DELETED );
showDialogFragment( DlgID.DLG_DELETED, expl );
}
} );
}
@ -1309,7 +1315,11 @@ public class BoardDelegate extends DelegateBase
case MESSAGE_NOGAME:
final int gameID = (Integer)args[0];
if ( null != m_gi && gameID == m_gi.gameID && !isFinishing() ) {
postDeleteOnce();
CommsAddrRec.ConnExpl expl = null;
if ( 1 < args.length && args[1] instanceof CommsAddrRec.ConnExpl ) {
expl = (CommsAddrRec.ConnExpl)args[1];
}
postDeleteOnce( expl );
}
break;
@ -1395,7 +1405,7 @@ public class BoardDelegate extends DelegateBase
case DEADGAME:
case DELETED:
postDeleteOnce();
postDeleteOnce( null );
break;
case OLDFLAGS:

View file

@ -40,8 +40,9 @@ import javax.net.ssl.HttpsURLConnection;
import org.json.JSONException;
import org.json.JSONObject;
import org.eehouse.android.xw4.jni.CommsAddrRec;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec.ConnExpl;
import org.eehouse.android.xw4.jni.CommsAddrRec;
import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.loc.LocUtils;
@ -605,8 +606,12 @@ public class MQTTUtils extends Thread implements IMqttActionListener, MqttCallba
public static void handleGameGone( Context context, CommsAddrRec from, int gameID )
{
if ( BuildConfig.DO_MQTT_GAME_GONE ) {
String player = XwJNI.kplr_nameForMqttDev( from.mqtt_devID );
ConnExpl expl = null == player ? null
: new ConnExpl( CommsConnType.COMMS_CONN_MQTT, player );
new MQTTServiceHelper( context, from )
.postEvent( MultiService.MultiEvent.MESSAGE_NOGAME, gameID );
.postEvent( MultiService.MultiEvent.MESSAGE_NOGAME, gameID,
expl );
} else {
Log.d( TAG, "not posting game-gone for now (gameID: %d)" , gameID );
}

View file

@ -42,8 +42,9 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.io.Serializable;
public class CommsAddrRec implements java.io.Serializable {
public class CommsAddrRec implements Serializable {
private static final String TAG = CommsAddrRec.class.getSimpleName();
public enum CommsConnType {
@ -99,6 +100,23 @@ public class CommsAddrRec implements java.io.Serializable {
}
};
// Pairs how and name of device in that context
public static class ConnExpl implements Serializable {
public final CommsConnType mType;
public final String mName;
public ConnExpl( CommsConnType typ, String name )
{
mType = typ;
mName = name;
}
public String getUserExpl( Context context )
{
return String.format( "%s: %s", mType, mName );
}
}
public static class CommsConnTypeSet extends HashSet<CommsConnType> {
private static final int BIT_VECTOR_MASK = 0x8000;

View file

@ -525,7 +525,7 @@
<!-- In "more info" about sent invitations when mqtt used and
player is known. -->
<string name="invit_expl_player_fmt">Invite forwarded via MQTT/internet
to known player “%1$s” on %2$s.</string>
to Known Player “%1$s” on %2$s.</string>
<!-- Explanation shown when you choose the radio button to invite
by QR Code -->