mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-23 07:27:22 +01:00
Problem: NBS port is being ignored by dispatcher to broadcast
receivers on receiving device, so variants are getting their own and all other NBS messages. Solution: change protocol to include port message is meant for so mis-delivered ones can be dropped.
This commit is contained in:
parent
7875d34757
commit
a26e642c8e
1 changed files with 32 additions and 6 deletions
|
@ -71,7 +71,9 @@ public class SMSService extends XWService {
|
||||||
private static final String MSG_SENT = "MSG_SENT";
|
private static final String MSG_SENT = "MSG_SENT";
|
||||||
private static final String MSG_DELIVERED = "MSG_DELIVERED";
|
private static final String MSG_DELIVERED = "MSG_DELIVERED";
|
||||||
|
|
||||||
private static final int SMS_PROTO_VERSION = 0;
|
private static final int SMS_PROTO_VERSION_ORIG = 0;
|
||||||
|
private static final int SMS_PROTO_VERSION_WITHPORT = 1;
|
||||||
|
private static final int SMS_PROTO_VERSION = SMS_PROTO_VERSION_WITHPORT;
|
||||||
private static final int MAX_LEN_TEXT = 100;
|
private static final int MAX_LEN_TEXT = 100;
|
||||||
private static final int MAX_LEN_BINARY = 100;
|
private static final int MAX_LEN_BINARY = 100;
|
||||||
private static final int MAX_MSG_COUNT = 16; // 1.6K enough? Should be....
|
private static final int MAX_MSG_COUNT = 16; // 1.6K enough? Should be....
|
||||||
|
@ -449,6 +451,7 @@ public class SMSService extends XWService {
|
||||||
ByteArrayOutputStream bas = new ByteArrayOutputStream( 128 );
|
ByteArrayOutputStream bas = new ByteArrayOutputStream( 128 );
|
||||||
DataOutputStream das = new DataOutputStream( bas );
|
DataOutputStream das = new DataOutputStream( bas );
|
||||||
das.writeByte( SMS_PROTO_VERSION );
|
das.writeByte( SMS_PROTO_VERSION );
|
||||||
|
das.writeShort( getNBSPort() );
|
||||||
das.writeByte( cmd.ordinal() );
|
das.writeByte( cmd.ordinal() );
|
||||||
das.write( bytes, 0, bytes.length );
|
das.write( bytes, 0, bytes.length );
|
||||||
das.flush();
|
das.flush();
|
||||||
|
@ -568,7 +571,7 @@ public class SMSService extends XWService {
|
||||||
{
|
{
|
||||||
boolean success = true;
|
boolean success = true;
|
||||||
if ( index == 0 && count == 1 ) { // most common case
|
if ( index == 0 && count == 1 ) { // most common case
|
||||||
disAssemble( senderPhone, msg );
|
success = disAssemble( senderPhone, msg );
|
||||||
} else if ( count > 0 && count < MAX_MSG_COUNT && index < count ) {
|
} else if ( count > 0 && count < MAX_MSG_COUNT && index < count ) {
|
||||||
// required? Should always be in main thread.
|
// required? Should always be in main thread.
|
||||||
synchronized( s_partialMsgs ) {
|
synchronized( s_partialMsgs ) {
|
||||||
|
@ -585,7 +588,7 @@ public class SMSService extends XWService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( store.add( index, msg ).isComplete() ) {
|
if ( store.add( index, msg ).isComplete() ) {
|
||||||
disAssemble( senderPhone, store.messageData() );
|
success = disAssemble( senderPhone, store.messageData() );
|
||||||
perPhone.remove( id );
|
perPhone.remove( id );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -595,21 +598,33 @@ public class SMSService extends XWService {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disAssemble( String senderPhone, byte[] fullMsg )
|
private boolean disAssemble( String senderPhone, byte[] fullMsg )
|
||||||
{
|
{
|
||||||
|
boolean success = false;
|
||||||
DataInputStream dis =
|
DataInputStream dis =
|
||||||
new DataInputStream( new ByteArrayInputStream(fullMsg) );
|
new DataInputStream( new ByteArrayInputStream(fullMsg) );
|
||||||
try {
|
try {
|
||||||
byte proto = dis.readByte();
|
byte proto = dis.readByte();
|
||||||
if ( SMS_PROTO_VERSION != proto ) {
|
short myPort = getNBSPort();
|
||||||
|
short sentPort;
|
||||||
|
if ( SMS_PROTO_VERSION_WITHPORT > proto ) {
|
||||||
|
sentPort = myPort;
|
||||||
|
} else {
|
||||||
|
sentPort = dis.readShort();
|
||||||
|
}
|
||||||
|
if ( SMS_PROTO_VERSION < proto ) {
|
||||||
DbgUtils.logf( "SMSService.disAssemble: bad proto %d from %s;"
|
DbgUtils.logf( "SMSService.disAssemble: bad proto %d from %s;"
|
||||||
+ " dropping", proto, senderPhone );
|
+ " dropping", proto, senderPhone );
|
||||||
sendResult( MultiEvent.BAD_PROTO_SMS, senderPhone );
|
sendResult( MultiEvent.BAD_PROTO_SMS, senderPhone );
|
||||||
|
} else if ( sentPort != myPort ) {
|
||||||
|
DbgUtils.logdf( "SMSService.disAssemble(): received on port %d"
|
||||||
|
+ " but expected %d", sentPort, myPort );
|
||||||
} else {
|
} else {
|
||||||
SMS_CMD cmd = SMS_CMD.values()[dis.readByte()];
|
SMS_CMD cmd = SMS_CMD.values()[dis.readByte()];
|
||||||
byte[] rest = new byte[dis.available()];
|
byte[] rest = new byte[dis.available()];
|
||||||
dis.read( rest );
|
dis.read( rest );
|
||||||
receive( cmd, rest, senderPhone );
|
receive( cmd, rest, senderPhone );
|
||||||
|
success = true;
|
||||||
}
|
}
|
||||||
} catch ( java.io.IOException ioe ) {
|
} catch ( java.io.IOException ioe ) {
|
||||||
DbgUtils.loge( ioe );
|
DbgUtils.loge( ioe );
|
||||||
|
@ -617,6 +632,7 @@ public class SMSService extends XWService {
|
||||||
// enum this older code doesn't know about; drop it
|
// enum this older code doesn't know about; drop it
|
||||||
DbgUtils.logf( "disAssemble: dropping message with too-new enum" );
|
DbgUtils.logf( "disAssemble: dropping message with too-new enum" );
|
||||||
}
|
}
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void postNotification( String phone, int gameID, long rowid )
|
private void postNotification( String phone, int gameID, long rowid )
|
||||||
|
@ -670,7 +686,7 @@ public class SMSService extends XWService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !success ) {
|
if ( !success ) {
|
||||||
short nbsPort = (short)Integer.parseInt( getString( R.string.nbs_port ) );
|
short nbsPort = getNBSPort();
|
||||||
try {
|
try {
|
||||||
SmsManager mgr = SmsManager.getDefault();
|
SmsManager mgr = SmsManager.getDefault();
|
||||||
PendingIntent sent = makeStatusIntent( MSG_SENT );
|
PendingIntent sent = makeStatusIntent( MSG_SENT );
|
||||||
|
@ -779,6 +795,16 @@ public class SMSService extends XWService {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Short s_nbsPort = null;
|
||||||
|
private short getNBSPort()
|
||||||
|
{
|
||||||
|
if ( null == s_nbsPort ) {
|
||||||
|
String asStr = getString( R.string.nbs_port );
|
||||||
|
s_nbsPort = new Short((short)Integer.parseInt( asStr ) );
|
||||||
|
}
|
||||||
|
return s_nbsPort;
|
||||||
|
}
|
||||||
|
|
||||||
private class SMSMsgSink extends MultiMsgSink {
|
private class SMSMsgSink extends MultiMsgSink {
|
||||||
public SMSMsgSink( Context context ) {
|
public SMSMsgSink( Context context ) {
|
||||||
super( context );
|
super( context );
|
||||||
|
|
Loading…
Add table
Reference in a new issue