fix so emailed invitations from current shipping version can be

received. I think NFC works too. Bluetooth doesn't, and isn't worth
the time to fix since users get a very clear "upgrade already"
message.
This commit is contained in:
Eric House 2015-02-26 21:39:21 -08:00
parent 3e27721ca4
commit 13b3905458
7 changed files with 131 additions and 73 deletions

View file

@ -286,7 +286,7 @@ public class BTService extends XWService {
public static void gotGameViaNFC( Context context, NetLaunchInfo bli )
{
Intent intent = getIntentTo( context, BTAction.NFCINVITE );
intent.putExtra( GAMEID_KEY, bli.gameID );
intent.putExtra( GAMEID_KEY, bli.gameID() );
intent.putExtra( DICT_KEY, bli.dict );
intent.putExtra( LANG_KEY, bli.lang );
intent.putExtra( NTO_KEY, bli.nPlayersT );
@ -370,7 +370,7 @@ public class BTService extends XWService {
break;
case INVITE:
String jsonData = intent.getStringExtra( GAMEDATA_KEY );
NetLaunchInfo nli = new NetLaunchInfo( jsonData );
NetLaunchInfo nli = new NetLaunchInfo( this, jsonData );
DbgUtils.logf( "onStartCommand: nli: %s", nli.toString() );
// int gameID = intent.getIntExtra( GAMEID_KEY, -1 );
// String btAddr = intent.getStringExtra( ADDR_KEY );
@ -545,7 +545,7 @@ public class BTService extends XWService {
{
BTCmd result;
String asJson = is.readUTF();
NetLaunchInfo nli = new NetLaunchInfo( asJson );
NetLaunchInfo nli = new NetLaunchInfo( context, asJson );
BluetoothDevice host = socket.getRemoteDevice();
addAddr( host );
@ -1064,7 +1064,7 @@ public class BTService extends XWService {
DictFetchOwner.OWNER_BT );
// NetLaunchInfo.putExtras( intent, gameID, btName, btAddr );
MultiService.postMissingDictNotification( context, intent,
nli.gameID );
nli.gameID() );
result = BTCmd.INVITE_ACCPT; // ???
}
return result;
@ -1074,7 +1074,7 @@ public class BTService extends XWService {
String sender, String senderAddress )
{
BTCmd result;
long[] rowids = DBUtils.getRowIDsFor( BTService.this, nli.gameID );
long[] rowids = DBUtils.getRowIDsFor( BTService.this, nli.gameID() );
if ( null == rowids || 0 == rowids.length ) {
CommsAddrRec addr = nli.makeAddrRec( context );
long rowid = GameUtils.makeNewMultiGame( context, nli, m_btMsgSink );
@ -1088,7 +1088,7 @@ public class BTService extends XWService {
String body = LocUtils.getString( BTService.this,
R.string.new_bt_body_fmt,
sender );
postNotification( nli.gameID, R.string.new_bt_title, body, rowid );
postNotification( nli.gameID(), R.string.new_bt_title, body, rowid );
sendResult( MultiEvent.BT_GAME_CREATED, rowid );
}
} else {

View file

@ -1880,6 +1880,7 @@ public class BoardDelegate extends DelegateBase
pairs.m_paths, langName );
}
// XwJNI.game_summarize( m_jniGamePtr, m_summary );
DbgUtils.logf( "BoardDelegate:after makeFromStream: room name: %s",
m_summary.roomName );

View file

@ -694,7 +694,7 @@ public class DBUtils {
{
Date result = null;
String selection = String.format("%s=%d", DBHelper.GAMEID, nli.gameID );
String selection = String.format("%s=%d", DBHelper.GAMEID, nli.gameID() );
String[] columns = { DBHelper.CREATE_TIME };
initDB( context );
@ -710,7 +710,7 @@ public class DBUtils {
cursor.close();
db.close();
}
DbgUtils.logf( "getMostRecentCreate(%d) => %H", nli.gameID, result );
DbgUtils.logf( "getMostRecentCreate(%d) => %H", nli.gameID(), result );
return result;
}

View file

@ -471,7 +471,7 @@ public class GameUtils {
return makeNewMultiGame( context, sink, DBUtils.GROUPID_UNSPEC, addr,
new int[] {nli.lang}, new String[] { nli.dict },
nli.nPlayersT, nli.nPlayersH, nli.forceChannel,
nli.inviteID(), nli.gameID, false );
nli.inviteID(), nli.gameID(), false );
}
public static long makeNewMultiGame( Context context )
@ -1082,7 +1082,7 @@ public class GameUtils {
if ( XWApp.ATTACH_SUPPORTED ) {
byte[] data = nli.makeLaunchJSON().getBytes();
File file = new File( dir, String.format("invite_%d", nli.gameID ));
File file = new File( dir, String.format("invite_%d", nli.gameID() ));
try {
FileOutputStream fos = new FileOutputStream( file );
fos.write( data, 0, data.length );

View file

@ -1775,7 +1775,7 @@ public class GamesListDelegate extends ListDelegateBase
{
NetLaunchInfo nli = null;
if ( MultiService.isMissingDictIntent( intent ) ) {
nli = new NetLaunchInfo( intent );
nli = new NetLaunchInfo( m_activity, intent );
} else {
Uri data = intent.getData();
if ( null != data ) {
@ -1839,7 +1839,7 @@ public class GamesListDelegate extends ListDelegateBase
{
String data = NFCUtils.getFromIntent( intent );
if ( null != data ) {
NetLaunchInfo nli = new NetLaunchInfo( data );
NetLaunchInfo nli = new NetLaunchInfo( m_activity, data );
if ( nli.isValid() ) {
startNewNetGame( nli );
}

View file

@ -69,8 +69,7 @@ public class NetLaunchInfo {
protected boolean isGSM;
protected int osVers;
protected int gameID;
private int m_gameID = 0;
private CommsConnTypeSet m_addrs;
private boolean m_valid;
private String m_inviteID;
@ -80,16 +79,16 @@ public class NetLaunchInfo {
m_addrs = new CommsConnTypeSet();
}
public NetLaunchInfo( String data )
public NetLaunchInfo( Context context, String data )
{
init( data );
init( context, data );
}
public NetLaunchInfo( Intent intent )
public NetLaunchInfo( Context context, Intent intent )
{
String data = intent.getStringExtra( MultiService.NLI_DATA );
Assert.assertNotNull( data );
init( data );
init( context, data );
}
public NetLaunchInfo( Bundle bundle )
@ -102,7 +101,7 @@ public class NetLaunchInfo {
gameName = bundle.getString( MultiService.GAMENAME );
nPlayersT = bundle.getInt( MultiService.NPLAYERST );
nPlayersH = bundle.getInt( MultiService.NPLAYERSH );
gameID = bundle.getInt( MultiService.GAMEID );
m_gameID = bundle.getInt( MultiService.GAMEID );
btName = bundle.getString( MultiService.BT_NAME );
btAddress = bundle.getString( MultiService.BT_ADDRESS );
@ -128,22 +127,48 @@ public class NetLaunchInfo {
room = json.getString( MultiService.ROOM );
m_inviteID = json.getString( MultiService.INVITEID );
} else {
int addrs = Integer.decode( data.getQueryParameter( ADDRS_KEY ) );
m_addrs = new CommsConnTypeSet( addrs );
String val = data.getQueryParameter( ADDRS_KEY );
boolean hasAddrs = null != val;
if ( hasAddrs ) {
m_addrs = new CommsConnTypeSet( Integer.decode( val ) );
} else {
m_addrs = new CommsConnTypeSet();
}
if ( m_addrs.contains( CommsConnType.COMMS_CONN_RELAY ) ) {
room = data.getQueryParameter( ROOM_KEY );
m_inviteID = data.getQueryParameter( ID_KEY );
}
if ( m_addrs.contains( CommsConnType.COMMS_CONN_BT ) ) {
btAddress = data.getQueryParameter( BTADDR_KEY );
btName = data.getQueryParameter( BTNAME_KEY );
}
if ( m_addrs.contains( CommsConnType.COMMS_CONN_SMS ) ) {
phone = data.getQueryParameter( PHONE_KEY );
isGSM = 1 == Integer
.decode(data.getQueryParameter( GSM_KEY ) );
osVers = Integer.decode(data.getQueryParameter(OSVERS_KEY));
CommsConnTypeSet supported = CommsConnTypeSet.getSupported( context );
for ( CommsConnType typ : supported.getTypes() ) {
if ( hasAddrs && !m_addrs.contains( typ ) ) {
continue;
}
boolean doAdd;
switch ( typ ) {
case COMMS_CONN_BT:
btAddress = data.getQueryParameter( BTADDR_KEY );
btName = data.getQueryParameter( BTNAME_KEY );
doAdd = !hasAddrs && null != btAddress;
break;
case COMMS_CONN_RELAY:
room = data.getQueryParameter( ROOM_KEY );
m_inviteID = data.getQueryParameter( ID_KEY );
doAdd = !hasAddrs && null != room;
break;
case COMMS_CONN_SMS:
phone = data.getQueryParameter( PHONE_KEY );
val = data.getQueryParameter( GSM_KEY );
isGSM = null != val && 1 == Integer.decode( val );
val = data.getQueryParameter( OSVERS_KEY );
if ( null != val ) {
osVers = Integer.decode( val );
}
doAdd = !hasAddrs && null != phone;
break;
default:
doAdd = false;
Assert.fail();
}
if ( doAdd ) {
m_addrs.add( typ );
}
}
dict = data.getQueryParameter( WORDLIST_KEY );
@ -152,9 +177,11 @@ public class NetLaunchInfo {
String np = data.getQueryParameter( TOTPLAYERS_KEY );
nPlayersT = Integer.decode( np );
String nh = data.getQueryParameter( HEREPLAYERS_KEY );
nPlayersH = Integer.decode( nh );
gameID = Integer.decode( data.getQueryParameter( GID_KEY ) );
forceChannel = Integer.decode( data.getQueryParameter( FORCECHANNEL_KEY ) );
nPlayersH = nh == null ? 1 : Integer.decode( nh );
val = data.getQueryParameter( GID_KEY );
m_gameID = null == val ? 0 : Integer.decode( val );
val = data.getQueryParameter( FORCECHANNEL_KEY );
forceChannel = null == val ? 0 : Integer.decode( val );
}
calcValid();
} catch ( Exception e ) {
@ -173,7 +200,7 @@ public class NetLaunchInfo {
lang = dictLang;
nPlayersT = nPlayers;
nPlayersH = 1;
gameID = gamID;
m_gameID = gamID;
}
public NetLaunchInfo( GameSummary summary, CurGameInfo gi, int numHere, int fc )
@ -220,12 +247,25 @@ public class NetLaunchInfo {
{
String result = m_inviteID;
if ( null == result ) {
result = GameUtils.formatGameID( gameID );
result = GameUtils.formatGameID( m_gameID );
DbgUtils.logf( "inviteID(): m_inviteID null so substituting %s", result );
}
return result;
}
public int gameID()
{
int result = m_gameID;
if ( 0 == result ) {
Assert.assertNotNull( m_inviteID );
result = Integer.parseInt( m_inviteID, 16 );
DbgUtils.logf( "gameID(): m_gameID -1 so substituting %d", result );
m_gameID = result;
}
Assert.assertTrue( 0 != result );
return result;
}
public void putSelf( Bundle bundle )
{
bundle.putString( MultiService.ROOM, room );
@ -235,7 +275,7 @@ public class NetLaunchInfo {
bundle.putString( MultiService.GAMENAME, gameName );
bundle.putInt( MultiService.NPLAYERST, nPlayersT );
bundle.putInt( MultiService.NPLAYERSH, nPlayersH );
bundle.putInt( MultiService.GAMEID, gameID );
bundle.putInt( MultiService.GAMEID, gameID() );
bundle.putString( MultiService.BT_NAME, btName );
bundle.putString( MultiService.BT_ADDRESS, btAddress );
bundle.putInt( MultiService.FORCECHANNEL, forceChannel );
@ -255,7 +295,7 @@ public class NetLaunchInfo {
.put( MultiService.GAMENAME, gameName )
.put( MultiService.NPLAYERST, nPlayersT )
.put( MultiService.NPLAYERSH, nPlayersH )
.put( MultiService.GAMEID, gameID )
.put( MultiService.GAMEID, gameID() )
.put( MultiService.FORCECHANNEL, forceChannel );
if ( m_addrs.contains( CommsConnType.COMMS_CONN_RELAY ) ) {
@ -307,44 +347,57 @@ public class NetLaunchInfo {
return result;
}
private void init( String data )
private void init( Context context, String data )
{
try {
JSONObject json = new JSONObject( data );
int flags = json.getInt(ADDRS_KEY);
m_addrs = new CommsConnTypeSet( flags );
int flags = json.optInt(ADDRS_KEY, -1);
boolean hasAddrs = -1 != flags;
m_addrs = hasAddrs ?
new CommsConnTypeSet( flags ) : new CommsConnTypeSet();
lang = json.optInt( MultiService.LANG, -1 );
forceChannel = json.optInt( MultiService.FORCECHANNEL, 0 );
dict = json.optString( MultiService.DICT );
gameName = json.optString( MultiService.GAMENAME );
nPlayersT = json.optInt( MultiService.NPLAYERST, -1 );
nPlayersH = json.optInt( MultiService.NPLAYERSH, -1 );
gameID = json.optInt( MultiService.GAMEID, -1 );
nPlayersH = json.optInt( MultiService.NPLAYERSH, 1 ); // absent ok
m_gameID = json.optInt( MultiService.GAMEID, 0 );
for ( CommsConnType typ : m_addrs.getTypes() ) {
// Try each type
CommsConnTypeSet supported = CommsConnTypeSet.getSupported( context );
for ( CommsConnType typ : supported.getTypes() ) {
if ( hasAddrs && !m_addrs.contains( typ ) ) {
continue;
}
boolean doAdd;
switch ( typ ) {
case COMMS_CONN_BT:
btAddress = json.getString( MultiService.BT_ADDRESS );
btName = json.getString( MultiService.BT_NAME );
btAddress = json.optString( MultiService.BT_ADDRESS );
btName = json.optString( MultiService.BT_NAME );
doAdd = !hasAddrs && !btAddress.isEmpty();
break;
case COMMS_CONN_RELAY:
room = json.getString( MultiService.ROOM );
m_inviteID = json.optString( MultiService.INVITEID );
doAdd = !hasAddrs && !room.isEmpty();
break;
case COMMS_CONN_SMS:
phone = json.getString( PHONE_KEY );
isGSM = json.getBoolean( GSM_KEY );
osVers = json.getInt( OSVERS_KEY );
phone = json.optString( PHONE_KEY );
isGSM = json.optBoolean( GSM_KEY, false );
osVers = json.optInt( OSVERS_KEY, 0 );
doAdd = !hasAddrs && !phone.isEmpty();
break;
default:
DbgUtils.logf( "Unexpected typ %s", typ.toString() );
break;
doAdd = false;
Assert.fail();
}
if ( doAdd ) {
m_addrs.add( typ );
}
}
calcValid();
} catch ( JSONException jse ) {
DbgUtils.loge( jse );
}
@ -368,7 +421,7 @@ public class NetLaunchInfo {
appendInt( ub, LANG_KEY, lang );
appendInt( ub, TOTPLAYERS_KEY, nPlayersT );
appendInt( ub, HEREPLAYERS_KEY, nPlayersH );
appendInt( ub, GID_KEY, gameID );
appendInt( ub, GID_KEY, gameID() );
appendInt( ub, FORCECHANNEL_KEY, forceChannel );
appendInt( ub, ADDRS_KEY, addrs );
@ -451,24 +504,28 @@ public class NetLaunchInfo {
return null != dict
&& 0 < lang
&& 0 < nPlayersT
&& 0 != gameID;
&& 0 != gameID();
}
private void calcValid()
{
boolean valid = hasCommon();
for ( Iterator<CommsConnType> iter = m_addrs.iterator();
valid && iter.hasNext(); ) {
switch ( iter.next() ) {
case COMMS_CONN_RELAY:
valid = null != room && null != inviteID();
break;
case COMMS_CONN_BT:
valid = null != btAddress && 0 != gameID;
break;
case COMMS_CONN_SMS:
valid = null != phone && 0 < osVers;
break;
boolean valid = hasCommon() && null != m_addrs;
DbgUtils.logf( "calcValid(%s)", toString() );
if ( valid ) {
for ( Iterator<CommsConnType> iter = m_addrs.iterator();
valid && iter.hasNext(); ) {
CommsConnType typ = iter.next();
switch ( typ ) {
case COMMS_CONN_RELAY:
valid = null != room && null != inviteID();
break;
case COMMS_CONN_BT:
valid = null != btAddress;
break;
case COMMS_CONN_SMS:
valid = null != phone && 0 < osVers;
break;
}
}
}
m_valid = valid;

View file

@ -495,7 +495,7 @@ public class SMSService extends XWService {
switch( cmd ) {
case INVITE:
String nliData = dis.readUTF();
NetLaunchInfo nli = new NetLaunchInfo( nliData );
NetLaunchInfo nli = new NetLaunchInfo( this, nliData );
if ( nli.isValid() ) {
if ( DictLangCache.haveDict( this, nli.lang, nli.dict ) ) {
makeForInvite( phone, nli );
@ -621,8 +621,8 @@ public class SMSService extends XWService {
{
SMSMsgSink sink = new SMSMsgSink( this );
long rowid = GameUtils.makeNewMultiGame( this, nli, sink );
postNotification( phone, nli.gameID, rowid );
ackInvite( phone, nli.gameID );
postNotification( phone, nli.gameID(), rowid );
ackInvite( phone, nli.gameID() );
}
private void makeForInvite( String phone, int gameID, String gameName,