This commit is contained in:
Eric House 2019-04-02 21:40:28 -07:00
parent 71af4d3187
commit c82081521f
2 changed files with 34 additions and 40 deletions

View file

@ -66,12 +66,6 @@ public class NBSProto {
} }
} }
public static void onGameDictDownload( Context context, Intent oldIntent )
{
NetLaunchInfo nli = MultiService.getMissingDictData( context, oldIntent );
getCurThread( nli.phone ).addInviteFrom( context, nli );
}
public static void inviteRemote( Context context, String phone, public static void inviteRemote( Context context, String phone,
NetLaunchInfo nli ) NetLaunchInfo nli )
{ {
@ -90,6 +84,12 @@ public class NBSProto {
getCurThread( phone ).addGameDied( context, gameID ); getCurThread( phone ).addGameDied( context, gameID );
} }
public static void onGameDictDownload( Context context, Intent oldIntent )
{
NetLaunchInfo nli = MultiService.getMissingDictData( context, oldIntent );
getCurThread( nli.phone ).addInviteFrom( context, nli );
}
public static void stopThreads() public static void stopThreads()
{ {
stopCurThreads(); stopCurThreads();
@ -112,12 +112,11 @@ public class NBSProto {
super( "NBSProtoThread" ); super( "NBSProtoThread" );
mPhone = phone; mPhone = phone;
mPort = port; mPort = port;
boolean newSMSEnabled = XWPrefs.getSMSProtoEnabled( XWApp.getContext() ); mForceNow = !XWPrefs.getSMSProtoEnabled( XWApp.getContext() );
mForceNow = !newSMSEnabled;
} }
String getPhone() { return mPhone; } private String getPhone() { return mPhone; }
short getPort() { return mPort; } private short getPort() { return mPort; }
void addPacketFrom( Context context, byte[] data ) void addPacketFrom( Context context, byte[] data )
{ {
@ -149,11 +148,6 @@ public class NBSProto {
add( new SendElem( context, SMS_CMD.ACK_INVITE, gameID, null ) ); add( new SendElem( context, SMS_CMD.ACK_INVITE, gameID, null ) );
} }
void removeSelf()
{
NBSProto.removeSelf( this );
}
@Override @Override
public void run() { public void run() {
Log.d( TAG, "%s.run() starting for %s", this, mPhone ); Log.d( TAG, "%s.run() starting for %s", this, mPhone );
@ -166,8 +160,7 @@ public class NBSProto {
// there's something in the queue. // there's something in the queue.
long waitSecs = mWaitSecs[0] <= 0 ? 10 * 60 : mWaitSecs[0]; long waitSecs = mWaitSecs[0] <= 0 ? 10 * 60 : mWaitSecs[0];
QueueElem elem = mQueue.poll( waitSecs, TimeUnit.SECONDS ); QueueElem elem = mQueue.poll( waitSecs, TimeUnit.SECONDS );
boolean handled = process( elem, false ); if ( !process( elem, false ) ) {
if ( /*null == elem && */!handled ) {
break; break;
} }
} catch ( InterruptedException iex ) { } catch ( InterruptedException iex ) {
@ -176,7 +169,7 @@ public class NBSProto {
} }
} }
removeSelf(); // should stop additions to the queue removeSelf( this ); // should stop additions to the queue
// Now just empty out the queue, in case anything was added // Now just empty out the queue, in case anything was added
// late. Note that if we're abandoning a half-assembled // late. Note that if we're abandoning a half-assembled
@ -213,7 +206,7 @@ public class NBSProto {
for ( SMSProtoMsg msg : msgs ) { for ( SMSProtoMsg msg : msgs ) {
receive( elem.context, msg ); receive( elem.context, msg );
} }
getHelper(elem.context).postEvent( MultiEvent.SMS_RECEIVE_OK ); getHelper().postEvent( MultiEvent.SMS_RECEIVE_OK );
} else { } else {
Log.d( TAG, "receiveBuffer(): bogus or incomplete message from %s", Log.d( TAG, "receiveBuffer(): bogus or incomplete message from %s",
getPhone() ); getPhone() );
@ -227,15 +220,11 @@ public class NBSProto {
private boolean processSend( SendElem elem, boolean exiting ) private boolean processSend( SendElem elem, boolean exiting )
{ {
byte[][] msgs;
boolean forceNow = mForceNow || exiting; boolean forceNow = mForceNow || exiting;
if ( null != elem ) { byte[][] msgs = null != elem
msgs = XwJNI.smsproto_prepOutbound( elem.cmd, elem.gameID, elem.data, ? XwJNI.smsproto_prepOutbound( elem.cmd, elem.gameID, elem.data,
mPhone, mPort, forceNow, mWaitSecs ); mPhone, mPort, forceNow, mWaitSecs )
} else { // timed out : XwJNI.smsproto_prepOutbound( mPhone, mPort, forceNow, mWaitSecs );
msgs = XwJNI.smsproto_prepOutbound( SMS_CMD.NONE, 0, null, mPhone,
mPort, forceNow, mWaitSecs );
}
if ( null != msgs ) { if ( null != msgs ) {
sendBuffers( msgs ); sendBuffers( msgs );
@ -256,10 +245,10 @@ public class NBSProto {
} }
private SMSServiceHelper mHelper = null; private SMSServiceHelper mHelper = null;
protected SMSServiceHelper getHelper( Context context ) protected SMSServiceHelper getHelper()
{ {
if ( null == mHelper ) { if ( null == mHelper ) {
mHelper = new SMSServiceHelper( context ); mHelper = new SMSServiceHelper( XWApp.getContext() );
} }
return mHelper; return mHelper;
} }
@ -277,10 +266,10 @@ public class NBSProto {
} }
break; break;
case DEATH: case DEATH:
getHelper(context).postEvent( MultiEvent.MESSAGE_NOGAME, msg.gameID ); getHelper().postEvent( MultiEvent.MESSAGE_NOGAME, msg.gameID );
break; break;
case ACK_INVITE: case ACK_INVITE:
getHelper(context).postEvent( MultiEvent.NEWGAME_SUCCESS, msg.gameID ); getHelper().postEvent( MultiEvent.NEWGAME_SUCCESS, msg.gameID );
break; break;
default: default:
Log.w( TAG, "unexpected cmd %s", msg.cmd ); Log.w( TAG, "unexpected cmd %s", msg.cmd );
@ -292,7 +281,7 @@ public class NBSProto {
private boolean feedMessage( Context context, int gameID, byte[] msg, private boolean feedMessage( Context context, int gameID, byte[] msg,
CommsAddrRec addr ) CommsAddrRec addr )
{ {
XWServiceHelper.ReceiveResult rslt = getHelper(context) XWServiceHelper.ReceiveResult rslt = getHelper()
.receiveMessage( gameID, null, msg, addr ); .receiveMessage( gameID, null, msg, addr );
if ( XWServiceHelper.ReceiveResult.GAME_GONE == rslt ) { if ( XWServiceHelper.ReceiveResult.GAME_GONE == rslt ) {
sendDiedPacket( context, addr.sms_phone, gameID ); sendDiedPacket( context, addr.sms_phone, gameID );
@ -304,7 +293,6 @@ public class NBSProto {
{ {
if ( !s_sentDied.contains( gameID ) ) { if ( !s_sentDied.contains( gameID ) ) {
getCurThread( phone ).addGameDied( context, gameID ); getCurThread( phone ).addGameDied( context, gameID );
// resendFor( phone, SMS_CMD.DEATH, gameID, null );
s_sentDied.add( gameID ); s_sentDied.add( gameID );
} }
} }
@ -312,10 +300,11 @@ public class NBSProto {
private void makeForInvite( Context context, NetLaunchInfo nli ) private void makeForInvite( Context context, NetLaunchInfo nli )
{ {
if ( nli != null ) { if ( nli != null ) {
getHelper(context).handleInvitation( nli, mPhone, DictFetchOwner.OWNER_SMS ); getHelper().handleInvitation( nli, mPhone, DictFetchOwner.OWNER_SMS );
getCurThread(mPhone).addAck( context, nli.gameID() ); getCurThread(mPhone).addAck( context, nli.gameID() );
} }
} }
private void sendBuffers( byte[][] fragments ) private void sendBuffers( byte[][] fragments )
{ {
Context context = XWApp.getContext(); Context context = XWApp.getContext();
@ -353,8 +342,6 @@ public class NBSProto {
mgr.sendDataMessage( phone, null, port, fragment, mgr.sendDataMessage( phone, null, port, fragment,
sent, delivery ); sent, delivery );
} }
Log.d( TAG, "sendBuffers(): sent fragment of len %d",
fragment.length );
} }
success = true; success = true;
} catch ( IllegalArgumentException iae ) { } catch ( IllegalArgumentException iae ) {
@ -362,7 +349,7 @@ public class NBSProto {
} catch ( NullPointerException npe ) { } catch ( NullPointerException npe ) {
Assert.assertFalse( BuildConfig.DEBUG ); // shouldn't be trying to do this!!! Assert.assertFalse( BuildConfig.DEBUG ); // shouldn't be trying to do this!!!
} catch ( java.lang.SecurityException se ) { } catch ( java.lang.SecurityException se ) {
getHelper(context).postEvent( MultiEvent.SMS_SEND_FAILED_NOPERMISSION ); getHelper().postEvent( MultiEvent.SMS_SEND_FAILED_NOPERMISSION );
} catch ( Exception ee ) { } catch ( Exception ee ) {
Log.ex( TAG, ee ); Log.ex( TAG, ee );
} }
@ -415,6 +402,7 @@ public class NBSProto {
} }
private static class ReceiveElem extends QueueElem { private static class ReceiveElem extends QueueElem {
// One of these two will be set
byte[] data; byte[] data;
NetLaunchInfo nli; NetLaunchInfo nli;
ReceiveElem( Context context, byte[] data ) ReceiveElem( Context context, byte[] data )
@ -468,9 +456,9 @@ public class NBSProto {
} }
} }
private static class SMSMsgSink extends MultiMsgSink { private static class NBSMsgSink extends MultiMsgSink {
private Context mContext; private Context mContext;
public SMSMsgSink( Context context ) { public NBSMsgSink( Context context ) {
super( context ); super( context );
mContext = context; mContext = context;
} }
@ -493,7 +481,7 @@ public class NBSProto {
@Override @Override
protected MultiMsgSink getSink( long rowid ) protected MultiMsgSink getSink( long rowid )
{ {
return new SMSMsgSink( mContext ); return new NBSMsgSink( mContext );
} }
@Override @Override

View file

@ -438,6 +438,12 @@ public class XwJNI {
return smsproto_prepOutbound( getJNI().m_ptr, cmd, gameID, buf, phone, return smsproto_prepOutbound( getJNI().m_ptr, cmd, gameID, buf, phone,
port, forceNow, waitSecs ); port, forceNow, waitSecs );
} }
public static byte[][]
smsproto_prepOutbound( String phone, int port, boolean forceNow, int[] waitSecs )
{
return smsproto_prepOutbound( SMS_CMD.NONE, 0, null, phone, port, forceNow, waitSecs );
}
public static SMSProtoMsg[] smsproto_prepInbound( byte[] data, public static SMSProtoMsg[] smsproto_prepInbound( byte[] data,
String fromPhone, int wantPort ) String fromPhone, int wantPort )