improve bad-protocol messaging: suggestion to upgrade is displayed on

both sides.
This commit is contained in:
Eric House 2014-09-22 08:09:58 -07:00
parent 59f5c17e78
commit 4c2c6e5814
6 changed files with 81 additions and 43 deletions

View file

@ -1856,8 +1856,11 @@
<!-- -->
<string name="new_bt_body_fmt">From a player on the device %1$s wants to start a game</string>
<!-- -->
<string name="bt_bad_proto_fmt">Crosswords on %1$s wrong version for
Bluetooth play.</string>
<string name="bt_bad_proto_fmt">The version of Crosswords on
\"%1$s\" is incompatible with this one for play using
Bluetooth. One of you may need to upgrade before you can
continue.</string>
<!-- -->
<string name="new_btmove_title">Invitation via Bluetooth</string>
<!-- -->

View file

@ -1593,8 +1593,10 @@
<!-- -->
<string name="new_bt_body_fmt">Morf a reyalp no eht ecived %1$s stnaw ot trats a emag</string>
<!-- -->
<string name="bt_bad_proto_fmt">Sdrowssorc no %1$s gnorw noisrev rof
Htooteulb yalp.</string>
<string name="bt_bad_proto_fmt">Eht noisrev fo Sdrowssorc no
\"%1$s\" si elbitapmocni htiw siht eno rof yalp gnisu
Htooteulb. Eno fo uoy yam deen ot edargpu erofeb uoy nac
eunitnoc.</string>
<!-- -->
<string name="new_btmove_title">Noitativni aiv Htooteulb</string>
<!-- -->

View file

@ -1593,8 +1593,10 @@
<!-- -->
<string name="new_bt_body_fmt">FROM A PLAYER ON THE DEVICE %1$s WANTS TO START A GAME</string>
<!-- -->
<string name="bt_bad_proto_fmt">CROSSWORDS ON %1$s WRONG VERSION FOR
BLUETOOTH PLAY.</string>
<string name="bt_bad_proto_fmt">THE VERSION OF CROSSWORDS ON
\"%1$s\" IS INCOMPATIBLE WITH THIS ONE FOR PLAY USING
BLUETOOTH. ONE OF YOU MAY NEED TO UPGRADE BEFORE YOU CAN
CONTINUE.</string>
<!-- -->
<string name="new_btmove_title">INVITATION VIA BLUETOOTH</string>
<!-- -->

View file

@ -86,20 +86,21 @@ public class BTService extends XWService {
private static final String BT_ADDRESS_STR = "BT_ADDRESS_STR";
private enum BTCmd {
PING,
PONG,
SCAN,
INVITE,
INVITE_ACCPT,
INVITE_DECL,
INVITE_DUPID,
INVITE_FAILED, // generic error
MESG_SEND,
MESG_ACCPT,
MESG_DECL,
MESG_GAMEGONE,
REMOVE_FOR,
};
BAD_PROTO,
PING,
PONG,
SCAN,
INVITE,
INVITE_ACCPT,
INVITE_DECL,
INVITE_DUPID,
INVITE_FAILED, // generic error
MESG_SEND,
MESG_ACCPT,
MESG_DECL,
MESG_GAMEGONE,
REMOVE_FOR,
};
private class BTQueueElem {
int m_failCount;
@ -409,9 +410,12 @@ public class BTService extends XWService {
byte proto = inStream.readByte();
if ( proto != BT_PROTO ) {
DataOutputStream os = new DataOutputStream( socket.getOutputStream() );
os.writeByte( BTCmd.BAD_PROTO.ordinal() );
os.flush();
socket.close();
sendResult( MultiEvent.BAD_PROTO,
socket.getRemoteDevice().getName() );
sendBadProto( socket );
} else {
byte msg = inStream.readByte();
BTCmd cmd = BTCmd.values()[msg];
@ -464,7 +468,6 @@ public class BTService extends XWService {
private void receivePing( BluetoothSocket socket ) throws IOException
{
DbgUtils.logf( "got PING!!!" );
DataInputStream inStream = new DataInputStream( socket.getInputStream() );
int gameID = inStream.readInt();
boolean deleted = 0 != gameID && !DBUtils.haveGame( BTService.this, gameID );
@ -716,9 +719,14 @@ public class BTService extends XWService {
DataInputStream is =
new DataInputStream( socket.getInputStream() );
gotReply = BTCmd.PONG == BTCmd.values()[is.readByte()];
if ( gotReply && is.readBoolean() ) {
sendResult( MultiEvent.MESSAGE_NOGAME, gameID );
BTCmd reply = BTCmd.values()[is.readByte()];
if ( BTCmd.BAD_PROTO == reply ) {
sendBadProto( socket );
} else {
gotReply = BTCmd.PONG == reply;
if ( gotReply && is.readBoolean() ) {
sendResult( MultiEvent.MESSAGE_NOGAME, gameID );
}
}
receiveWorking = true;
@ -751,7 +759,7 @@ public class BTService extends XWService {
BluetoothSocket socket =
dev.createRfcommSocketToServiceRecord( XWApp.getAppUUID() );
if ( null != socket ) {
boolean success = false;
BTCmd reply = null;
DataOutputStream outStream = connect( socket, BTCmd.INVITE );
if ( null != outStream ) {
outStream.writeInt( elem.m_gameID );
@ -764,16 +772,23 @@ public class BTService extends XWService {
DataInputStream inStream =
new DataInputStream( socket.getInputStream() );
success = BTCmd.INVITE_ACCPT
== BTCmd.values()[inStream.readByte()];
DbgUtils.logf( "sendInvite(): invite done: success=%b",
success );
reply = BTCmd.values()[inStream.readByte()];
}
socket.close();
MultiEvent evt = success ? MultiEvent.NEWGAME_SUCCESS
: MultiEvent.NEWGAME_FAILURE;
sendResult( evt, elem.m_gameID );
if ( BTCmd.BAD_PROTO == reply ) {
sendBadProto( socket );
} else {
MultiEvent evt = null;
switch( reply ) {
case INVITE_ACCPT:
evt = MultiEvent.NEWGAME_SUCCESS;
break;
default:
evt = MultiEvent.NEWGAME_FAILURE;
}
sendResult( evt, elem.m_gameID );
}
}
} catch ( IOException ioe ) {
logIOE( ioe );
@ -820,6 +835,10 @@ public class BTService extends XWService {
success = true;
switch ( reply ) {
case BAD_PROTO:
sendBadProto( socket );
evt = null;
break;
case MESG_ACCPT:
evt = MultiEvent.MESSAGE_ACCEPTED;
break;
@ -836,12 +855,14 @@ public class BTService extends XWService {
}
}
String btName = nameForAddr( elem.m_btAddr );
sendResult( evt, elem.m_gameID, 0, btName );
if ( ! success ) {
int failCount = elem.incrFailCount();
sendResult( MultiEvent.MESSAGE_RESEND, btName,
RESEND_TIMEOUT, failCount );
if ( null != evt ) {
String btName = nameForAddr( elem.m_btAddr );
sendResult( evt, elem.m_gameID, 0, btName );
if ( ! success ) {
int failCount = elem.incrFailCount();
sendResult( MultiEvent.MESSAGE_RESEND, btName,
RESEND_TIMEOUT, failCount );
}
}
return success;
} // sendMsg
@ -1058,6 +1079,11 @@ public class BTService extends XWService {
// }
}
private void sendBadProto( BluetoothSocket socket )
{
sendResult( MultiEvent.BAD_PROTO, socket.getRemoteDevice().getName() );
}
private void postNotification( int gameID, int title, String body,
long rowid )
{

View file

@ -456,6 +456,14 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
} catch ( java.lang.RuntimeException re ) {}
DbgUtils.logf( "Bluetooth error count: %d", count );
break;
case BAD_PROTO:
final String msg = getString( R.string.bt_bad_proto_fmt, (String)args[0] );
runOnUiThread( new Runnable() {
public void run() {
showOKOnlyDialog( msg );
}
});
break;
default:
DbgUtils.logf( "DelegateBase.eventOccurred(event=%s) (DROPPED)", event.toString() );
}

View file

@ -394,9 +394,6 @@ public class DlgDelegate {
String msg = null;
boolean asToast = true;
switch( event ) {
case BAD_PROTO:
msg = getString( R.string.bt_bad_proto_fmt, (String)args[0] );
break;
case MESSAGE_RESEND:
msg = getString( R.string.bt_resend_fmt, (String)args[0],
(Long)args[1], (Integer)args[2] );