cleanup from review of diffs (nothing significant)

This commit is contained in:
Eric House 2019-01-15 07:44:38 -08:00
parent 73a469a428
commit cf3d3bc156
7 changed files with 39 additions and 63 deletions

View file

@ -341,9 +341,8 @@ public class BTService extends XWService {
NetLaunchInfo nli ) NetLaunchInfo nli )
{ {
Assert.assertTrue( null != btAddr && 0 < btAddr.length() ); Assert.assertTrue( null != btAddr && 0 < btAddr.length() );
String nliData = nli.toString();
Intent intent = getIntentTo( context, BTAction.INVITE ) Intent intent = getIntentTo( context, BTAction.INVITE )
.putExtra( GAMEDATA_KEY, nliData ) .putExtra( GAMEDATA_KEY, nli.toString() )
.putExtra( ADDR_KEY, btAddr ); .putExtra( ADDR_KEY, btAddr );
startService( context, intent ); startService( context, intent );
} }
@ -410,9 +409,7 @@ public class BTService extends XWService {
private static boolean canRunForegroundService() private static boolean canRunForegroundService()
{ {
// added in API level 26 // added in API level 26
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
// && Prefs.runForegroundServiceEnabled( context, true )
;
} }
private static Intent getIntentTo( Context context, BTAction cmd ) private static Intent getIntentTo( Context context, BTAction cmd )
@ -458,13 +455,6 @@ public class BTService extends XWService {
return result; return result;
} }
@Override
public void onDestroy()
{
Log.d( TAG, "%s.onDestroy()", this );
super.onDestroy();
}
private int handleCommand( Intent intent ) private int handleCommand( Intent intent )
{ {
int result; int result;
@ -497,7 +487,7 @@ public class BTService extends XWService {
case INVITE: case INVITE:
String jsonData = intent.getStringExtra( GAMEDATA_KEY ); String jsonData = intent.getStringExtra( GAMEDATA_KEY );
NetLaunchInfo nli = NetLaunchInfo.makeFrom( this, jsonData ); NetLaunchInfo nli = NetLaunchInfo.makeFrom( this, jsonData );
Log.i( TAG, "handleCommand: nli: %s", nli.toString() ); Log.i( TAG, "handleCommand: nli: %s", nli );
String btAddr = intent.getStringExtra( ADDR_KEY ); String btAddr = intent.getStringExtra( ADDR_KEY );
m_sender.add( new BTQueueElem( BTCmd.INVITE, nli, btAddr ) ); m_sender.add( new BTQueueElem( BTCmd.INVITE, nli, btAddr ) );
break; break;

View file

@ -367,7 +367,6 @@ public class DBUtils {
String phone, String relayID, String p2pAddr ) String phone, String relayID, String p2pAddr )
{ {
try ( GameLock lock = GameLock.getFor( rowid ).tryLock() ) { try ( GameLock lock = GameLock.getFor( rowid ).tryLock() ) {
Assert.assertNotNull( lock );
if ( null != lock ) { if ( null != lock ) {
GameSummary summary = getSummary( context, lock ); GameSummary summary = getSummary( context, lock );
if ( null != btAddr ) { if ( null != btAddr ) {
@ -384,6 +383,7 @@ public class DBUtils {
} }
saveSummary( context, lock, summary ); saveSummary( context, lock, summary );
} else { } else {
Assert.assertFalse( BuildConfig.DEBUG );
Log.e( TAG, "addRematchInfo(%d): unable to lock game" ); Log.e( TAG, "addRematchInfo(%d): unable to lock game" );
} }
} }
@ -1124,9 +1124,7 @@ public class DBUtils {
deleteGame( context, lock ); deleteGame( context, lock );
} else { } else {
Log.e( TAG, "deleteGame: unable to lock rowid %d", rowid ); Log.e( TAG, "deleteGame: unable to lock rowid %d", rowid );
if ( BuildConfig.DEBUG ) { Assert.assertFalse( BuildConfig.DEBUG );
Assert.fail();
}
} }
} }
} }

View file

@ -30,7 +30,6 @@ import android.text.format.Time;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Formatter; import java.util.Formatter;
import java.util.Iterator;
import java.util.Set; import java.util.Set;

View file

@ -91,7 +91,7 @@ public class GameLock implements AutoCloseable {
// OR // OR
// * existing locks are ReadOnly and this request is readOnly // * existing locks are ReadOnly and this request is readOnly
// OR // OR
// * the requesting thread already holds the lock // * the requesting thread already holds the lock (later...)
private GameLock tryLockImpl( boolean readOnly ) private GameLock tryLockImpl( boolean readOnly )
{ {
GameLock result = null; GameLock result = null;
@ -169,17 +169,6 @@ public class GameLock implements AutoCloseable {
return result; return result;
} }
// @NonNull
// public GameLock lockRO() throws InterruptedException
// {
// if ( BuildConfig.DEBUG ) {
// DbgUtils.assertOnUIThread( false );
// }
// GameLock result = lockImpl( Long.MAX_VALUE, true );
// Assert.assertNotNull( result );
// return result;
// }
// Version that's allowed to return null -- if maxMillis > 0 // Version that's allowed to return null -- if maxMillis > 0
public GameLock lock( long maxMillis ) throws GameLockedException public GameLock lock( long maxMillis ) throws GameLockedException
{ {

View file

@ -1231,14 +1231,6 @@ public class GamesListDelegate extends ListDelegateBase
final Object ... args ) final Object ... args )
{ {
switch( event ) { switch( event ) {
// case HOST_PONGED:
// post( new Runnable() {
// public void run() {
// DbgUtils.showf( m_activity,
// "Pong from %s", args[0].toString() );
// }
// });
// break;
case BT_GAME_CREATED: case BT_GAME_CREATED:
post( new Runnable() { post( new Runnable() {
public void run() { public void run() {
@ -2689,30 +2681,29 @@ public class GamesListDelegate extends ListDelegateBase
private static Intent makeSelfIntent( Context context ) private static Intent makeSelfIntent( Context context )
{ {
Intent intent = new Intent( context, MainActivity.class ); Intent intent = new Intent( context, MainActivity.class )
intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP .setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP ); | Intent.FLAG_ACTIVITY_SINGLE_TOP );
return intent; return intent;
} }
public static Intent makeBackgroundIntent( Context context ) public static Intent makeBackgroundIntent( Context context )
{ {
Intent intent = makeSelfIntent( context ); return makeSelfIntent( context )
intent.putExtra( BACKGROUND_EXTRA, true ); .putExtra( BACKGROUND_EXTRA, true );
return intent;
} }
public static Intent makeRowidIntent( Context context, long rowid ) public static Intent makeRowidIntent( Context context, long rowid )
{ {
Intent intent = makeSelfIntent( context ); Intent intent = makeSelfIntent( context )
intent.putExtra( ROWID_EXTRA, rowid ); .putExtra( ROWID_EXTRA, rowid );
return intent; return intent;
} }
public static Intent makeGameIDIntent( Context context, int gameID ) public static Intent makeGameIDIntent( Context context, int gameID )
{ {
Intent intent = makeSelfIntent( context ); Intent intent = makeSelfIntent( context )
intent.putExtra( GAMEID_EXTRA, gameID ); .putExtra( GAMEID_EXTRA, gameID );
return intent; return intent;
} }
@ -2724,14 +2715,14 @@ public class GamesListDelegate extends ListDelegateBase
String newName ) String newName )
{ {
Intent intent = null; Intent intent = null;
intent = makeSelfIntent( context );
intent.putExtra( REMATCH_ROWID_EXTRA, rowid );
intent.putExtra( REMATCH_DICT_EXTRA, gi.dictName );
boolean isSolo = gi.serverRole == CurGameInfo.DeviceRole.SERVER_STANDALONE; boolean isSolo = gi.serverRole == CurGameInfo.DeviceRole.SERVER_STANDALONE;
intent.putExtra( REMATCH_IS_SOLO, isSolo ); intent = makeSelfIntent( context )
intent.putExtra( REMATCH_LANG_EXTRA, gi.dictLang ); .putExtra( REMATCH_ROWID_EXTRA, rowid )
intent.putExtra( REMATCH_PREFS_EXTRA, gi.getJSONData() ); .putExtra( REMATCH_DICT_EXTRA, gi.dictName )
intent.putExtra( REMATCH_NEWNAME_EXTRA, newName ); .putExtra( REMATCH_IS_SOLO, isSolo )
.putExtra( REMATCH_LANG_EXTRA, gi.dictLang )
.putExtra( REMATCH_PREFS_EXTRA, gi.getJSONData() )
.putExtra( REMATCH_NEWNAME_EXTRA, newName );
if ( null != addrTypes ) { if ( null != addrTypes ) {
intent.putExtra( REMATCH_ADDRS_EXTRA, addrTypes.toInt() ); intent.putExtra( REMATCH_ADDRS_EXTRA, addrTypes.toInt() );
@ -2757,8 +2748,8 @@ public class GamesListDelegate extends ListDelegateBase
public static Intent makeAlertIntent( Context context, String msg ) public static Intent makeAlertIntent( Context context, String msg )
{ {
Intent intent = makeSelfIntent( context ); Intent intent = makeSelfIntent( context )
intent.putExtra( ALERT_MSG, msg ); .putExtra( ALERT_MSG, msg );
return intent; return intent;
} }
@ -2771,8 +2762,8 @@ public class GamesListDelegate extends ListDelegateBase
public static void openGame( Context context, Uri data ) public static void openGame( Context context, Uri data )
{ {
Intent intent = makeSelfIntent( context ); Intent intent = makeSelfIntent( context )
intent.setData( data ); .setData( data );
context.startActivity( intent ); context.startActivity( intent );
} }
} }

View file

@ -101,6 +101,16 @@ public class MultiService {
public void setListener( MultiEventListener li ) public void setListener( MultiEventListener li )
{ {
synchronized( this ) { synchronized( this ) {
// If this is happening, the order of resume/pause isn't what we
// expect. Might need to keep a set of these instead of a
// singleton.
if ( BuildConfig.DEBUG ) {
if ( m_li == null && li == null ) {
Assert.fail();
} else if ( m_li != null && li != null ) {
Assert.fail();
}
}
m_li = li; m_li = li;
} }
} }

View file

@ -982,6 +982,7 @@ public class RelayService extends JobIntentService
void setService( RelayService service ) void setService( RelayService service )
{ {
Assert.assertNotNull( service );
synchronized ( mServiceHolder ) { synchronized ( mServiceHolder ) {
mServiceHolder[0] = service; mServiceHolder[0] = service;
// unblock waiters for non-null Service // unblock waiters for non-null Service
@ -1058,11 +1059,9 @@ public class RelayService extends JobIntentService
private void connectSocket() throws InterruptedException private void connectSocket() throws InterruptedException
{ {
if ( null == m_UDPSocket ) { if ( null == m_UDPSocket ) {
int port;
String host;
final RelayService service = getService(); final RelayService service = getService();
port = XWPrefs.getDefaultRelayPort( service ); int port = XWPrefs.getDefaultRelayPort( service );
host = XWPrefs.getDefaultRelayHost( service ); String host = XWPrefs.getDefaultRelayHost( service );
try { try {
m_UDPSocket = new DatagramSocket(); m_UDPSocket = new DatagramSocket();