From dfd4a3f6f6d8d173962594c0346f4b375802b9cc Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 26 Jul 2018 19:16:50 -0700 Subject: [PATCH 001/145] put the api-26 changes back lost in a rebase apparently --- xwords4/android/app/build.gradle | 2 +- xwords4/android/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle index 1359656ab..8b68bd894 100644 --- a/xwords4/android/app/build.gradle +++ b/xwords4/android/app/build.gradle @@ -33,7 +33,7 @@ android { buildToolsVersion '27.0.3' defaultConfig { minSdkVersion 8 - targetSdkVersion 23 + targetSdkVersion 26 versionCode VERSION_CODE_BASE versionName VERSION_NAME } diff --git a/xwords4/android/build.gradle b/xwords4/android/build.gradle index 8e6c7f8a9..de085ae7f 100644 --- a/xwords4/android/build.gradle +++ b/xwords4/android/build.gradle @@ -29,7 +29,7 @@ subprojects { afterEvaluate {project -> if (project.hasProperty("android")) { android { - compileSdkVersion 23 + compileSdkVersion 26 } } } From 45600a295adf8795b3b800c6e783e2d7c3f9d973 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 13 Sep 2018 19:49:49 -0700 Subject: [PATCH 002/145] use NotificationChannel to work on O and beyond with SDK 26 Notifications don't work on Oreo without this change, which includes a new Support Library in order to get NotificationChannel and creates and uses that as docs describe. Requires that MinSDK be raised from 8 to 14, which may lock some users out. It *should* be possible not to do this in the fdroid variant since their app store doesn't requires SDK 26, but I'll look at that later. --- xwords4/android/app/build.gradle | 9 ++++-- .../java/org/eehouse/android/xw4/Utils.java | 30 ++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle index 283ced899..2176ad851 100644 --- a/xwords4/android/app/build.gradle +++ b/xwords4/android/app/build.gradle @@ -32,7 +32,7 @@ android { // default changes and .travis.yml can be kept in sync buildToolsVersion '27.0.3' defaultConfig { - minSdkVersion 8 + minSdkVersion 14 targetSdkVersion 26 versionCode VERSION_CODE_BASE versionName VERSION_NAME @@ -197,11 +197,16 @@ android { } } +ext { + SUPPORT_LIB_VERSION = '27.1.1' +} + dependencies { // Look into replacing this with a fetch too PENDING xw4Implementation files('../libs/gcm.jar') - implementation 'com.android.support:support-v4:23.4.0' + implementation "com.android.support:support-v4:$SUPPORT_LIB_VERSION" + implementation "com.android.support:support-compat:$SUPPORT_LIB_VERSION" // 2.6.8 is probably as far forward as I can go without upping my // min-supported SDK version diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java index c5a02bf0e..f83fd30a8 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java @@ -23,6 +23,7 @@ package org.eehouse.android.xw4; import android.app.Activity; import android.app.Dialog; import android.app.Notification; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.ContentResolver; @@ -38,6 +39,7 @@ import android.database.Cursor; import android.media.Ringtone; import android.media.RingtoneManager; import android.net.Uri; +import android.os.Build; import android.provider.ContactsContract.PhoneLookup; import android.support.v4.app.NotificationCompat; import android.support.v4.content.FileProvider; @@ -81,6 +83,8 @@ public class Utils { private static final String TAG = Utils.class.getSimpleName(); public static final int TURN_COLOR = 0x7F00FF00; + private static final String CHANNEL_ID = BuildConfig.APPLICATION_ID + "_channel_id"; + private static final String DB_PATH = "XW_GAMES"; private static final String HIDDEN_PREFS = "xwprefs_hidden"; private static final String FIRST_VERSION_KEY = "FIRST_VERSION_KEY"; @@ -236,6 +240,8 @@ public class Utils { String title, String body, int id ) { + makeNotificationChannel( context ); + /* nextRandomInt: per this link http://stackoverflow.com/questions/10561419/scheduling-more-than-one-pendingintent-to-same-activity-using-alarmmanager one way to avoid getting the same PendingIntent for similar @@ -254,9 +260,10 @@ public class Utils { defaults |= Notification.DEFAULT_VIBRATE; } - Notification notification = new NotificationCompat.Builder( context ) + Notification notification = new NotificationCompat.Builder( context, CHANNEL_ID ) .setContentIntent( pi ) .setSmallIcon( R.drawable.notify ) + .setPriority(NotificationCompat.PRIORITY_LOW) //.setTicker(body) //.setWhen(time) .setAutoCancel( true ) @@ -611,4 +618,25 @@ public class Utils { } } + private static boolean sChannelMade = false; + private static void makeNotificationChannel( Context context ) + { + if ( !sChannelMade ) { + sChannelMade = true; + if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) { + NotificationManager notMgr = (NotificationManager) + context.getSystemService( Context.NOTIFICATION_SERVICE ); + + String channelDescription = "XWORDS Default Channel"; + NotificationChannel channel = notMgr.getNotificationChannel( CHANNEL_ID ); + if ( channel == null ) { + channel = new NotificationChannel( CHANNEL_ID, channelDescription, + NotificationManager.IMPORTANCE_LOW ); + // channel.setLightColor(Color.GREEN); + channel.enableVibration( true ); + notMgr.createNotificationChannel( channel ); + } + } + } + } } From 24440230bace47e2e3ab31f5c2aad697f3c454e7 Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 21 Sep 2018 15:21:04 -0700 Subject: [PATCH 003/145] refactor so startService can change (no behavior change yet) --- .../org/eehouse/android/xw4/BTService.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index 20c0bad8d..98d851b16 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -227,7 +227,7 @@ public class BTService extends XWService { public static void startService( Context context ) { if ( XWApp.BTSUPPORTED ) { - context.startService( new Intent( context, BTService.class ) ); + startService( context, new Intent( context, BTService.class ) ); } } @@ -235,20 +235,20 @@ public class BTService extends XWService { { Intent intent = getIntentTo( context, BTAction.RADIO ); intent.putExtra( RADIO_KEY, cameOn ); - context.startService( intent ); + startService( context, intent ); } public static void clearDevices( Context context, String[] btAddrs ) { Intent intent = getIntentTo( context, BTAction.CLEAR ); intent.putExtra( CLEAR_KEY, btAddrs ); - context.startService( intent ); + startService( context, intent ); } public static void scan( Context context ) { Intent intent = getIntentTo( context, BTAction.SCAN ); - context.startService( intent ); + startService( context, intent ); } public static void pingHost( Context context, String hostAddr, int gameID ) @@ -257,7 +257,7 @@ public class BTService extends XWService { Intent intent = getIntentTo( context, BTAction.PINGHOST ); intent.putExtra( ADDR_KEY, hostAddr ); intent.putExtra( GAMEID_KEY, gameID ); - context.startService( intent ); + startService( context, intent ); } public static void inviteRemote( Context context, String btAddr, @@ -269,7 +269,7 @@ public class BTService extends XWService { intent.putExtra( GAMEDATA_KEY, nliData ); intent.putExtra( ADDR_KEY, btAddr ); - context.startService( intent ); + startService( context, intent ); } public static void gotGameViaNFC( Context context, NetLaunchInfo bli ) @@ -282,7 +282,7 @@ public class BTService extends XWService { intent.putExtra( BT_NAME_KEY, bli.btName ); intent.putExtra( BT_ADDRESS_KEY, bli.btAddress ); - context.startService( intent ); + startService( context, intent ); } public static int enqueueFor( Context context, byte[] buf, @@ -296,7 +296,7 @@ public class BTService extends XWService { intent.putExtra( MSG_KEY, buf ); intent.putExtra( ADDR_KEY, btAddr ); intent.putExtra( GAMEID_KEY, gameID ); - context.startService( intent ); + startService( context, intent ); nSent = buf.length; } @@ -312,6 +312,11 @@ public class BTService extends XWService { Intent intent = getIntentTo( context, BTAction.REMOVE ); intent.putExtra( GAMEID_KEY, gameID ); intent.putExtra( ADDR_KEY, btAddr ); + startService( context, intent ); + } + + private static void startService( Context context, Intent intent ) + { context.startService( intent ); } From 6bafbecd75597c6d7ea17dd9f867eb74f30fe9d2 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sat, 22 Sep 2018 09:22:37 -0700 Subject: [PATCH 004/145] toward service working on Oreo Did a bunch of stuff to inherit from JobIntentService and use enqueue(), but doesn't work yet. OS is unable to bind, with this error: 09-21 17:20:51.678 3050 3050 W JobServiceContext: Time-out while trying to bind 2edee28 #u0a277/1111 org.eehouse.android.xw4dbg/org.eehouse.android.xw4.BTService, dropping. --- .../android/app/src/main/AndroidManifest.xml | 10 +- .../org/eehouse/android/xw4/BTService.java | 28 ++- .../org/eehouse/android/xw4/BoardView.java | 3 +- .../org/eehouse/android/xw4/DbgUtils.java | 3 +- .../eehouse/android/xw4/NetStateCache.java | 16 +- .../org/eehouse/android/xw4/RelayService.java | 220 ++++++++++-------- .../java/org/eehouse/android/xw4/Utils.java | 6 + .../org/eehouse/android/xw4/XWService.java | 19 +- 8 files changed, 189 insertions(+), 116 deletions(-) diff --git a/xwords4/android/app/src/main/AndroidManifest.xml b/xwords4/android/app/src/main/AndroidManifest.xml index 27df1905e..810e8b25a 100644 --- a/xwords4/android/app/src/main/AndroidManifest.xml +++ b/xwords4/android/app/src/main/AndroidManifest.xml @@ -179,8 +179,14 @@ - - + + diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index 98d851b16..61b033bd3 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -29,6 +29,7 @@ import android.bluetooth.BluetoothServerSocket; import android.bluetooth.BluetoothSocket; import android.content.Context; import android.content.Intent; +import android.support.v4.app.JobIntentService; import junit.framework.Assert; @@ -228,6 +229,8 @@ public class BTService extends XWService { { if ( XWApp.BTSUPPORTED ) { startService( context, new Intent( context, BTService.class ) ); + // didn't help + // startService( context, new Intent( /*context, BTService.class*/ ) ); } } @@ -317,12 +320,19 @@ public class BTService extends XWService { private static void startService( Context context, Intent intent ) { - context.startService( intent ); + Log.d( TAG, "startService(%s)", intent ); + + if ( false ) { + // requires asking for Manifest.permission.FOREGROUND_SERVICE + context.startForegroundService( intent ); + } else { + JobIntentService.enqueueWork( context, BTService.class, 1111, intent ); + } } private static Intent getIntentTo( Context context, BTAction cmd ) { - Intent intent = new Intent( context, BTService.class ); + Intent intent = new Intent( /*context, BTService.class*/ ); intent.putExtra( CMD_KEY, cmd.ordinal() ); return intent; } @@ -347,6 +357,11 @@ public class BTService extends XWService { @Override public int onStartCommand( Intent intent, int flags, int startId ) + { + return handleCommand( intent ); + } + + private int handleCommand( Intent intent ) { int result; if ( XWApp.BTSUPPORTED && null != intent ) { @@ -433,7 +448,14 @@ public class BTService extends XWService { result = Service.START_STICKY_COMPATIBILITY; } return result; - } // onStartCommand() + } // handleCommand() + + @Override + protected void onHandleWork( Intent intent ) + { + Log.e( TAG, "onHandleWork(%s)", intent ); + /*(void)*/handleCommand( intent ); + } private class BTListenerThread extends Thread { private BluetoothServerSocket m_serverSocket; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardView.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardView.java index d0c9f33de..fff413910 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardView.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardView.java @@ -46,7 +46,6 @@ public class BoardView extends View implements BoardHandler, SyncedDraw { private static final float MIN_FONT_DIPS = 10.0f; private static final int MULTI_INACTIVE = -1; - private static final int VERSION_CODES_N = 24; // until we're building on SDK 24... private static boolean s_isFirstDraw; private static int s_curGameID; @@ -205,7 +204,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw { synchronized( this ) { if ( layoutBoardOnce() && m_measuredFromDims ) { Bitmap bitmap = s_bitmap; - if ( Build.VERSION.SDK_INT >= VERSION_CODES_N ) { + if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ) { bitmap = Bitmap.createBitmap(bitmap); } canvas.drawBitmap( bitmap, 0, 0, new Paint() ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DbgUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DbgUtils.java index f6116d8de..db5664334 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DbgUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DbgUtils.java @@ -25,7 +25,6 @@ import android.content.Intent; import android.database.Cursor; import android.database.DatabaseUtils; import android.os.Bundle; -import android.os.Looper; import android.text.TextUtils; import android.text.format.Time; @@ -103,7 +102,7 @@ public class DbgUtils { public static void assertOnUIThread() { - Assert.assertTrue( Looper.getMainLooper().equals(Looper.myLooper()) ); + Assert.assertTrue( Utils.isOnUIThread() ); } public static void printStack( String tag, StackTraceElement[] trace ) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java index 3081ccc41..101f52059 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java @@ -54,17 +54,21 @@ public class NetStateCache { public static void register( Context context, StateChangedIf proc ) { - initIfNot( context ); - synchronized( s_ifs ) { - s_ifs.add( proc ); + if ( Utils.isOnUIThread() ) { + initIfNot( context ); + synchronized( s_ifs ) { + s_ifs.add( proc ); + } } } public static void unregister( Context context, StateChangedIf proc ) { - initIfNot( context ); - synchronized( s_ifs ) { - s_ifs.remove( proc ); + if ( Utils.isOnUIThread() ) { + initIfNot( context ); + synchronized( s_ifs ) { + s_ifs.remove( proc ); + } } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java index 0b79002e5..8082adaef 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java @@ -25,6 +25,7 @@ import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Handler; +import android.support.v4.app.JobIntentService; import android.text.TextUtils; import junit.framework.Assert; @@ -192,13 +193,25 @@ public class RelayService extends XWService { Log.i( TAG, "startService()" ); Intent intent = getIntentTo( context, MsgCmds.UDP_CHANGED ); - context.startService( intent ); + startService( context, intent ); + } + + private static void startService( Context context, Intent intent ) + { + Log.d( TAG, "startService(%s)", intent ); + + if ( false ) { + // requires asking for Manifest.permission.FOREGROUND_SERVICE + context.startForegroundService( intent ); + } else { + JobIntentService.enqueueWork( context, RelayService.class, 1112, intent ); + } } private static void stopService( Context context ) { Intent intent = getIntentTo( context, MsgCmds.STOP ); - context.startService( intent ); + startService( context, intent ); } public static void inviteRemote( Context context, int destDevID, @@ -206,7 +219,7 @@ public class RelayService extends XWService { int myDevID = DevID.getRelayDevIDInt( context ); if ( 0 != myDevID ) { - context.startService( getIntentTo( context, MsgCmds.INVITE ) + startService( context, getIntentTo( context, MsgCmds.INVITE ) .putExtra( DEV_ID_SRC, myDevID ) .putExtra( DEV_ID_DEST, destDevID ) .putExtra( RELAY_ID, relayID ) @@ -217,13 +230,13 @@ public class RelayService extends XWService public static void reset( Context context ) { Intent intent = getIntentTo( context, MsgCmds.RESET ); - context.startService( intent ); + startService( context, intent ); } public static void timerFired( Context context ) { Intent intent = getIntentTo( context, MsgCmds.TIMER_FIRED ); - context.startService( intent ); + startService( context, intent ); } public static int sendPacket( Context context, long rowid, byte[] msg ) @@ -234,7 +247,7 @@ public class RelayService extends XWService Intent intent = getIntentTo( context, MsgCmds.SEND ) .putExtra( ROWID, rowid ) .putExtra( BINBUFFER, msg ); - context.startService( intent ); + startService( context, intent ); result = msg.length; } else { Log.w( TAG, "sendPacket: network down" ); @@ -251,7 +264,7 @@ public class RelayService extends XWService .putExtra( ROWID, rowid ) .putExtra( RELAY_ID, relayID ) .putExtra( BINBUFFER, msg ); - context.startService( intent ); + startService( context, intent ); result = msg.length; } return result; @@ -287,7 +300,7 @@ public class RelayService extends XWService Intent intent = getIntentTo( context, MsgCmds.RECEIVE ) .putExtra( ROWID, rowid ) .putExtra( BINBUFFER, msg ); - context.startService( intent ); + startService( context, intent ); } else { Log.w( TAG, "postData(): Dropping message for rowid %d:" + " not on device", rowid ); @@ -305,14 +318,14 @@ public class RelayService extends XWService Intent intent = getIntentTo( context, MsgCmds.PROCESS_GAME_MSGS ) .putExtra( MSGS_ARR, msgs64 ) .putExtra( RELAY_ID, relayId ); - context.startService( intent ); + startService( context, intent ); } public static void processDevMsgs( Context context, String[] msgs64 ) { Intent intent = getIntentTo( context, MsgCmds.PROCESS_DEV_MSGS ) .putExtra( MSGS_ARR, msgs64 ); - context.startService( intent ); + startService( context, intent ); } private static Intent getIntentTo( Context context, MsgCmds cmd ) @@ -356,94 +369,7 @@ public class RelayService extends XWService @Override public int onStartCommand( Intent intent, int flags, int startId ) { - Integer result = null; - if ( null != intent ) { - MsgCmds cmd; - try { - cmd = MsgCmds.values()[intent.getIntExtra( CMD_STR, -1 )]; - } catch (Exception ex) { // OOB most likely - cmd = null; - } - if ( null != cmd ) { - // Log.d( TAG, "onStartCommand(): cmd=%s", cmd.toString() ); - switch( cmd ) { - case PROCESS_GAME_MSGS: - String[] relayIDs = new String[1]; - relayIDs[0] = intent.getStringExtra( RELAY_ID ); - long[] rowIDs = DBUtils.getRowIDsFor( this, relayIDs[0] ); - if ( 0 < rowIDs.length ) { - byte[][][] msgs = expandMsgsArray( intent ); - process( msgs, rowIDs, relayIDs ); - } - break; - case PROCESS_DEV_MSGS: - byte[][][] msgss = expandMsgsArray( intent ); - for ( byte[][] msgs : msgss ) { - for ( byte[] msg : msgs ) { - gotPacket( msg, true, false ); - } - } - break; - case UDP_CHANGED: - startThreads(); - break; - case RESET: - stopThreads(); - startThreads(); - break; - case UPGRADE: - UpdateCheckReceiver.checkVersions( this, false ); - break; - case GOT_INVITE: - int srcDevID = intent.getIntExtra( INVITE_FROM, 0 ); - NetLaunchInfo nli - = NetLaunchInfo.makeFrom( this, intent.getStringExtra(NLI_DATA) ); - receiveInvitation( srcDevID, nli ); - break; - case SEND: - case RECEIVE: - case SENDNOCONN: - startUDPThreadsIfNot(); - long rowid = intent.getLongExtra( ROWID, -1 ); - byte[] msg = intent.getByteArrayExtra( BINBUFFER ); - if ( MsgCmds.SEND == cmd ) { - sendMessage( rowid, msg ); - } else if ( MsgCmds.SENDNOCONN == cmd ) { - String relayID = intent.getStringExtra( RELAY_ID ); - sendNoConnMessage( rowid, relayID, msg ); - } else { - receiveMessage( this, rowid, null, msg, s_addr ); - } - break; - case INVITE: - startUDPThreadsIfNot(); - srcDevID = intent.getIntExtra( DEV_ID_SRC, 0 ); - int destDevID = intent.getIntExtra( DEV_ID_DEST, 0 ); - String relayID = intent.getStringExtra( RELAY_ID ); - String nliData = intent.getStringExtra( NLI_DATA ); - sendInvitation( srcDevID, destDevID, relayID, nliData ); - break; - case TIMER_FIRED: - if ( !NetStateCache.netAvail( this ) ) { - Log.w( TAG, "not connecting: no network" ); - } else if ( startFetchThreadIfNotUDP() ) { - // do nothing - } else if ( registerWithRelayIfNot() ) { - requestMessages(); - } - RelayReceiver.setTimer( this ); - break; - case STOP: - stopThreads(); - stopSelf(); - break; - default: - Assert.fail(); - } - - result = Service.START_STICKY; - } - } + Integer result = handleCommand( intent ); if ( null == result ) { result = Service.START_STICKY_COMPATIBILITY; @@ -465,12 +391,110 @@ public class RelayService extends XWService super.onDestroy(); } + @Override + protected void onHandleWork( Intent intent ) + { + Log.e( TAG, "onHandleWork(%s)", intent ); + handleCommand( intent ); + } + // NetStateCache.StateChangedIf interface public void onNetAvail( boolean nowAvailable ) { startService( this ); // bad name: will *stop* threads too } + private Integer handleCommand( Intent intent ) + { + Integer result = null; + MsgCmds cmd; + try { + cmd = MsgCmds.values()[intent.getIntExtra( CMD_STR, -1 )]; + } catch (Exception ex) { // OOB most likely + cmd = null; + } + if ( null != cmd ) { + // Log.d( TAG, "onStartCommand(): cmd=%s", cmd.toString() ); + switch( cmd ) { + case PROCESS_GAME_MSGS: + String[] relayIDs = new String[1]; + relayIDs[0] = intent.getStringExtra( RELAY_ID ); + long[] rowIDs = DBUtils.getRowIDsFor( this, relayIDs[0] ); + if ( 0 < rowIDs.length ) { + byte[][][] msgs = expandMsgsArray( intent ); + process( msgs, rowIDs, relayIDs ); + } + break; + case PROCESS_DEV_MSGS: + byte[][][] msgss = expandMsgsArray( intent ); + for ( byte[][] msgs : msgss ) { + for ( byte[] msg : msgs ) { + gotPacket( msg, true, false ); + } + } + break; + case UDP_CHANGED: + startThreads(); + break; + case RESET: + stopThreads(); + startThreads(); + break; + case UPGRADE: + UpdateCheckReceiver.checkVersions( this, false ); + break; + case GOT_INVITE: + int srcDevID = intent.getIntExtra( INVITE_FROM, 0 ); + NetLaunchInfo nli + = NetLaunchInfo.makeFrom( this, intent.getStringExtra(NLI_DATA) ); + receiveInvitation( srcDevID, nli ); + break; + case SEND: + case RECEIVE: + case SENDNOCONN: + startUDPThreadsIfNot(); + long rowid = intent.getLongExtra( ROWID, -1 ); + byte[] msg = intent.getByteArrayExtra( BINBUFFER ); + if ( MsgCmds.SEND == cmd ) { + sendMessage( rowid, msg ); + } else if ( MsgCmds.SENDNOCONN == cmd ) { + String relayID = intent.getStringExtra( RELAY_ID ); + sendNoConnMessage( rowid, relayID, msg ); + } else { + receiveMessage( this, rowid, null, msg, s_addr ); + } + break; + case INVITE: + startUDPThreadsIfNot(); + srcDevID = intent.getIntExtra( DEV_ID_SRC, 0 ); + int destDevID = intent.getIntExtra( DEV_ID_DEST, 0 ); + String relayID = intent.getStringExtra( RELAY_ID ); + String nliData = intent.getStringExtra( NLI_DATA ); + sendInvitation( srcDevID, destDevID, relayID, nliData ); + break; + case TIMER_FIRED: + if ( !NetStateCache.netAvail( this ) ) { + Log.w( TAG, "not connecting: no network" ); + } else if ( startFetchThreadIfNotUDP() ) { + // do nothing + } else if ( registerWithRelayIfNot() ) { + requestMessages(); + } + RelayReceiver.setTimer( this ); + break; + case STOP: + stopThreads(); + stopSelf(); + break; + default: + Assert.fail(); + } + + result = Service.START_STICKY; + } + return result; + } + private void setupNotifications( String[] relayIDs, BackMoveResult[] bmrs, ArrayList locals ) { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java index f83fd30a8..96f64f19b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java @@ -40,6 +40,7 @@ import android.media.Ringtone; import android.media.RingtoneManager; import android.net.Uri; import android.os.Build; +import android.os.Looper; import android.provider.ContactsContract.PhoneLookup; import android.support.v4.app.NotificationCompat; import android.support.v4.content.FileProvider; @@ -533,6 +534,11 @@ public class Utils { return result; } + public static boolean isOnUIThread() + { + return Looper.getMainLooper().equals(Looper.myLooper()); + } + public static String base64Encode( byte[] in ) { return Base64.encodeToString( in, Base64.NO_WRAP ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWService.java index 62e680abf..bd045895a 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWService.java @@ -23,7 +23,9 @@ package org.eehouse.android.xw4; import android.app.Service; import android.content.Context; import android.content.Intent; +import android.os.Build; import android.os.IBinder; +import android.support.v4.app.JobIntentService; import junit.framework.Assert; @@ -37,7 +39,7 @@ import org.eehouse.android.xw4.jni.UtilCtxtImpl; import java.util.HashSet; import java.util.Set; -abstract class XWService extends Service { +abstract class XWService extends JobIntentService { private static final String TAG = XWService.class.getSimpleName(); public static enum ReceiveResult { OK, GAME_GONE, UNCONSUMED }; @@ -46,10 +48,21 @@ abstract class XWService extends Service { private UtilCtxt m_utilCtxt; + // @Override + // public IBinder onBind( Intent intent ) + // { + // IBinder result = null; + // if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) { + // result = super.onBind( intent ); + // } + // return result; + // } + @Override - public IBinder onBind( Intent intent ) + protected void onHandleWork(Intent intent) { - return null; + Log.e( TAG, "%s.onHandleWork(%s); dropping!!!", getClass().getSimpleName(), + intent ); } public final static void setListener( MultiService.MultiEventListener li ) From dfcac132c870ca370dde337bc767383e9d436d9d Mon Sep 17 00:00:00 2001 From: Eric House Date: Sat, 22 Sep 2018 14:21:04 -0700 Subject: [PATCH 005/145] up strings for new translations-only release --- xwords4/android/app/build.gradle | 4 ++-- .../android/app/src/main/assets/changes.html | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle index 0ca4752d2..9d7fcf467 100644 --- a/xwords4/android/app/build.gradle +++ b/xwords4/android/app/build.gradle @@ -1,6 +1,6 @@ def INITIAL_CLIENT_VERS = 8 -def VERSION_CODE_BASE = 135 -def VERSION_NAME = '4.4.139' +def VERSION_CODE_BASE = 136 +def VERSION_NAME = '4.4.140' def FABRIC_API_KEY = System.getenv("FABRIC_API_KEY") def GCM_SENDER_ID = System.getenv("GCM_SENDER_ID") def BUILD_INFO_NAME = "build-info.txt" diff --git a/xwords4/android/app/src/main/assets/changes.html b/xwords4/android/app/src/main/assets/changes.html index b873c30b0..e8979d7b2 100644 --- a/xwords4/android/app/src/main/assets/changes.html +++ b/xwords4/android/app/src/main/assets/changes.html @@ -13,9 +13,9 @@ -

CrossWords 4.4.139 release

+

CrossWords 4.4.140 release

-

This release fixes a bug with picking tiles face-up

+

This release updates translations for Catalan, French, German and Japanese.

Please take @@ -25,19 +25,18 @@

New with this release

    -
  • Don't put up multiple tile pickers. (This feature is rarely - used, but had apparently been broken for a while.)
  • -
  • Fix two more bugs reported by users (Thanks!)
  • -
  • Include new translations for Catalan and Norwegian
  • +
  • Include changes made by Weblate volunteers for four + languages. (Thanks!)
-

(The full changelog +

(The full changelog is here.)

Next up

    -
  • Continue work to support WiFi Direct (currently working - sporadically)
  • +
  • Make changes in how background networking and bluetooth work + that Google's mandating for all releases after 1 + November.

Please let me know From 61779142131838eaca0ecd2e291fb8b929a88b2a Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 22 Nov 2018 08:13:49 -0800 Subject: [PATCH 006/145] add lifecycle lib (events only logged only so far) --- xwords4/android/app/build.gradle | 3 +++ .../java/org/eehouse/android/xw4/XWApp.java | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle index 2176ad851..94d68ce0b 100644 --- a/xwords4/android/app/build.gradle +++ b/xwords4/android/app/build.gradle @@ -208,6 +208,9 @@ dependencies { implementation "com.android.support:support-v4:$SUPPORT_LIB_VERSION" implementation "com.android.support:support-compat:$SUPPORT_LIB_VERSION" + implementation "android.arch.lifecycle:extensions:1.1.1" + annotationProcessor "android.arch.lifecycle:compiler:1.1.1" + // 2.6.8 is probably as far forward as I can go without upping my // min-supported SDK version xw4dImplementation('com.crashlytics.sdk.android:crashlytics:2.6.3@aar') { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java index 15cde5677..307b1230f 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java @@ -21,6 +21,11 @@ package org.eehouse.android.xw4; import android.app.Application; +import android.arch.lifecycle.Lifecycle; +import android.arch.lifecycle.LifecycleObserver; +import android.arch.lifecycle.LifecycleOwner; +import android.arch.lifecycle.OnLifecycleEvent; +import android.arch.lifecycle.ProcessLifecycleOwner; import android.content.Context; import android.graphics.Color; import android.os.Build; @@ -32,7 +37,9 @@ import java.util.UUID; import junit.framework.Assert; -public class XWApp extends Application { +import static android.arch.lifecycle.Lifecycle.Event.ON_ANY; + +public class XWApp extends Application implements LifecycleObserver { private static final String TAG = XWApp.class.getSimpleName(); public static final boolean BTSUPPORTED = true; @@ -65,6 +72,8 @@ public class XWApp extends Application { Assert.assertTrue( s_context == s_context.getApplicationContext() ); super.onCreate(); + ProcessLifecycleOwner.get().getLifecycle().addObserver(this); + // This one line should always get logged even if logging is // off -- because logging is on by default until logEnable is // called. @@ -91,6 +100,12 @@ public class XWApp extends Application { WiDirWrapper.init( this ); } + @OnLifecycleEvent(ON_ANY) + public void onAny(LifecycleOwner source, Lifecycle.Event event) + { + Log.d( TAG, "onAny(%s, %s)", source, event ); + } + // This is called on emulator only, but good for ensuring no memory leaks // by forcing JNI cleanup @Override From 2ba5982ddfaa7adfba6f846b81206384d738d93c Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 22 Nov 2018 15:18:57 -0800 Subject: [PATCH 007/145] use foregroundService on devices that can handle it And show the notification regardless. Tested only on pre-Oreo device so far. --- .../android/app/src/main/AndroidManifest.xml | 11 +-- .../org/eehouse/android/xw4/BTService.java | 85 ++++++++++++++++--- .../android/xw4/GamesListDelegate.java | 6 ++ .../org/eehouse/android/xw4/RelayService.java | 11 +-- .../java/org/eehouse/android/xw4/Utils.java | 2 +- .../java/org/eehouse/android/xw4/XWApp.java | 13 ++- .../org/eehouse/android/xw4/XWService.java | 19 +---- 7 files changed, 99 insertions(+), 48 deletions(-) diff --git a/xwords4/android/app/src/main/AndroidManifest.xml b/xwords4/android/app/src/main/AndroidManifest.xml index 810e8b25a..ccc7396e2 100644 --- a/xwords4/android/app/src/main/AndroidManifest.xml +++ b/xwords4/android/app/src/main/AndroidManifest.xml @@ -179,15 +179,16 @@ - - + + diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index 61b033bd3..8b1f3a9b1 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -21,6 +21,8 @@ package org.eehouse.android.xw4; import android.app.Activity; +import android.app.Notification; +import android.app.PendingIntent; import android.app.Service; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothClass.Device.Major; @@ -29,7 +31,8 @@ import android.bluetooth.BluetoothServerSocket; import android.bluetooth.BluetoothSocket; import android.content.Context; import android.content.Intent; -import android.support.v4.app.JobIntentService; +import android.os.Build; +import android.support.v4.app.NotificationCompat; import junit.framework.Assert; @@ -66,6 +69,8 @@ public class BTService extends XWService { private static final int BT_PROTO = BT_PROTO_JSONS; // change in a release or two private enum BTAction { _NONE, + START_FOREGROUND, + START_BACKGROUND, SCAN, INVITE, SEND, @@ -93,6 +98,8 @@ public class BTService extends XWService { private static final String BT_NAME_KEY = "BT_NAME"; private static final String BT_ADDRESS_KEY = "BT_ADDRESS"; + private static Boolean sInForeground; + private enum BTCmd { BAD_PROTO, PING, @@ -225,12 +232,33 @@ public class BTService extends XWService { return result; } + private static void onAppStateChange( Context context, boolean inForeground ) + { + if ( sInForeground == null || sInForeground != inForeground ) { + sInForeground = inForeground; + + Intent intent = + getIntentTo( context, + inForeground ? BTAction.START_FOREGROUND + : BTAction.START_BACKGROUND ); + startService( context, intent ); + } + } + + static void onAppToForeground( Context context ) + { + onAppStateChange( context, true ); + } + + static void onAppToBackground( Context context ) + { + onAppStateChange( context, false ); + } + public static void startService( Context context ) { if ( XWApp.BTSUPPORTED ) { startService( context, new Intent( context, BTService.class ) ); - // didn't help - // startService( context, new Intent( /*context, BTService.class*/ ) ); } } @@ -322,17 +350,26 @@ public class BTService extends XWService { { Log.d( TAG, "startService(%s)", intent ); - if ( false ) { - // requires asking for Manifest.permission.FOREGROUND_SERVICE + if ( ! sInForeground && canRunForegroundService() ) { context.startForegroundService( intent ); - } else { - JobIntentService.enqueueWork( context, BTService.class, 1111, intent ); + } else if ( sInForeground || Build.VERSION.SDK_INT < Build.VERSION_CODES.O ) { + context.startService( intent ); } } + // We can run a foreground service IIF the OS version is recent enough AND + // user hasn't said not to do it. + private static boolean canRunForegroundService() + { + // added in API level 26 + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O + // && Prefs.runForegroundServiceEnabled( context, true ) + ; + } + private static Intent getIntentTo( Context context, BTAction cmd ) { - Intent intent = new Intent( /*context, BTService.class*/ ); + Intent intent = new Intent( context, BTService.class ); intent.putExtra( CMD_KEY, cmd.ordinal() ); return intent; } @@ -358,7 +395,13 @@ public class BTService extends XWService { @Override public int onStartCommand( Intent intent, int flags, int startId ) { - return handleCommand( intent ); + int result = handleCommand( intent ); + + if ( Service.START_STICKY == result && !sInForeground ) { + startForeground(); + } + + return result; } private int handleCommand( Intent intent ) @@ -375,6 +418,12 @@ public class BTService extends XWService { BTAction cmd = BTAction.values()[ordinal]; Log.i( TAG, "onStartCommand; cmd=%s", cmd.toString() ); switch( cmd ) { + case START_FOREGROUND: + stopForeground( true ); // Kill the notification + // FALLTHRU + case START_BACKGROUND: + break; + case CLEAR: String[] btAddrs = intent.getStringArrayExtra( CLEAR_KEY ); clearDevs( btAddrs ); @@ -450,11 +499,21 @@ public class BTService extends XWService { return result; } // handleCommand() - @Override - protected void onHandleWork( Intent intent ) + private void startForeground() { - Log.e( TAG, "onHandleWork(%s)", intent ); - /*(void)*/handleCommand( intent ); + Intent notifIntent = GamesListDelegate.makeBackgroundIntent( this ); + PendingIntent pendIntent = PendingIntent + .getActivity(this, Utils.nextRandomInt(), notifIntent, PendingIntent.FLAG_ONE_SHOT); + Notification notification = + new NotificationCompat.Builder(this, Utils.CHANNEL_ID) + .setSmallIcon( R.drawable.notify ) + .setContentTitle( BTService.class.getSimpleName() ) + .setContentText("listening for bluetooth messages...") + .setContentIntent(pendIntent) + .build(); + + Log.d( TAG, "calling startForeground()" ); + startForeground( 1337, notification ); } private class BTListenerThread extends Thread { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index 086c6cff3..16077063c 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -2665,6 +2665,12 @@ public class GamesListDelegate extends ListDelegateBase return intent; } + public static Intent makeBackgroundIntent( Context context ) + { + Intent intent = makeSelfIntent( context ); + return intent; + } + public static Intent makeRowidIntent( Context context, long rowid ) { Intent intent = makeSelfIntent( context ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java index 8082adaef..b89c623eb 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java @@ -25,7 +25,6 @@ import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.support.v4.app.JobIntentService; import android.text.TextUtils; import junit.framework.Assert; @@ -201,10 +200,9 @@ public class RelayService extends XWService Log.d( TAG, "startService(%s)", intent ); if ( false ) { - // requires asking for Manifest.permission.FOREGROUND_SERVICE context.startForegroundService( intent ); } else { - JobIntentService.enqueueWork( context, RelayService.class, 1112, intent ); + context.startService( intent ); } } @@ -391,13 +389,6 @@ public class RelayService extends XWService super.onDestroy(); } - @Override - protected void onHandleWork( Intent intent ) - { - Log.e( TAG, "onHandleWork(%s)", intent ); - handleCommand( intent ); - } - // NetStateCache.StateChangedIf interface public void onNetAvail( boolean nowAvailable ) { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java index 96f64f19b..8bcfbf672 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java @@ -84,7 +84,7 @@ public class Utils { private static final String TAG = Utils.class.getSimpleName(); public static final int TURN_COLOR = 0x7F00FF00; - private static final String CHANNEL_ID = BuildConfig.APPLICATION_ID + "_channel_id"; + static final String CHANNEL_ID = BuildConfig.APPLICATION_ID + "_channel_id"; private static final String DB_PATH = "XW_GAMES"; private static final String HIDDEN_PREFS = "xwprefs_hidden"; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java index 307b1230f..7927c4f65 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java @@ -94,16 +94,23 @@ public class XWApp extends Application implements LifecycleObserver { } UpdateCheckReceiver.restartTimer( this ); - BTService.startService( this ); RelayService.startService( this ); GCMIntentService.init( this ); WiDirWrapper.init( this ); } @OnLifecycleEvent(ON_ANY) - public void onAny(LifecycleOwner source, Lifecycle.Event event) + public void onAny( LifecycleOwner source, Lifecycle.Event event ) { - Log.d( TAG, "onAny(%s, %s)", source, event ); + Log.d( TAG, "onAny(%s)", event ); + switch( event ) { + case ON_RESUME: + BTService.onAppToForeground( this ); + break; + case ON_STOP: + BTService.onAppToBackground( this ); + break; + } } // This is called on emulator only, but good for ensuring no memory leaks diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWService.java index bd045895a..62e680abf 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWService.java @@ -23,9 +23,7 @@ package org.eehouse.android.xw4; import android.app.Service; import android.content.Context; import android.content.Intent; -import android.os.Build; import android.os.IBinder; -import android.support.v4.app.JobIntentService; import junit.framework.Assert; @@ -39,7 +37,7 @@ import org.eehouse.android.xw4.jni.UtilCtxtImpl; import java.util.HashSet; import java.util.Set; -abstract class XWService extends JobIntentService { +abstract class XWService extends Service { private static final String TAG = XWService.class.getSimpleName(); public static enum ReceiveResult { OK, GAME_GONE, UNCONSUMED }; @@ -48,21 +46,10 @@ abstract class XWService extends JobIntentService { private UtilCtxt m_utilCtxt; - // @Override - // public IBinder onBind( Intent intent ) - // { - // IBinder result = null; - // if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) { - // result = super.onBind( intent ); - // } - // return result; - // } - @Override - protected void onHandleWork(Intent intent) + public IBinder onBind( Intent intent ) { - Log.e( TAG, "%s.onHandleWork(%s); dropping!!!", getClass().getSimpleName(), - intent ); + return null; } public final static void setListener( MultiService.MultiEventListener li ) From f8e15bd3a0406c8917d922a2381a0d08c13576ec Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 23 Nov 2018 08:21:52 -0800 Subject: [PATCH 008/145] add explanation for foreground service notification --- .../org/eehouse/android/xw4/GamesListDelegate.java | 13 +++++++++++++ .../android/app/src/main/res/values/common_rsrc.xml | 1 + xwords4/android/app/src/main/res/values/strings.xml | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index 16077063c..1f14fe7f2 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -86,6 +86,7 @@ public class GamesListDelegate extends ListDelegateBase private static final String RELAYIDS_EXTRA = "relayids"; private static final String ROWID_EXTRA = "rowid"; + private static final String BACKGROUND_EXTRA = "bkgrnd"; private static final String GAMEID_EXTRA = "gameid"; private static final String REMATCH_ROWID_EXTRA = "rm_rowid"; private static final String REMATCH_DICT_EXTRA = "rm_dict"; @@ -2267,6 +2268,16 @@ public class GamesListDelegate extends ListDelegateBase } } + private void tryBackgroundIntent( Intent intent ) + { + if ( intent.getBooleanExtra( BACKGROUND_EXTRA, false ) ) { + makeNotAgainBuilder( R.string.not_again_btservice, + R.string.key_notagain_btservice, + Action.OPEN_GAME ) + .show(); + } + } + private void askDefaultName() { String name = CommonPrefs.getDefaultPlayerName( m_activity, 0, true ); @@ -2481,6 +2492,7 @@ public class GamesListDelegate extends ListDelegateBase startRematch( intent ); tryAlert( intent ); tryNFCIntent( intent ); + tryBackgroundIntent( intent ); } private void doOpenGame( Object[] params ) @@ -2668,6 +2680,7 @@ public class GamesListDelegate extends ListDelegateBase public static Intent makeBackgroundIntent( Context context ) { Intent intent = makeSelfIntent( context ); + intent.putExtra( BACKGROUND_EXTRA, true ); return intent; } diff --git a/xwords4/android/app/src/main/res/values/common_rsrc.xml b/xwords4/android/app/src/main/res/values/common_rsrc.xml index b776b8be4..389e79ddb 100644 --- a/xwords4/android/app/src/main/res/values/common_rsrc.xml +++ b/xwords4/android/app/src/main/res/values/common_rsrc.xml @@ -136,6 +136,7 @@ key_invite_multi key_notagain_rematch_two_only key_notagain_dfltname + key_notagain_btservice key_na_comms_bt key_na_comms_p2p diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index 7427f169a..d330d7eda 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -2641,6 +2641,14 @@ player name \"%1$s\". Would you like to personalize with your own name before you create this game? + This notification is present + whenever CrossWords is ready to receive Bluetooth messages in the + background. This readiness has a slight impact on battery. If you + don\'t want to listen in the background disable the \"Enable + Background Listener\" preference. CrossWords will still receive + Bluetooth moves and invitations while in the foreground, but any + sent while it\'s in the background will be lost. + This game has sent no invitations Disable side-by-side From eb6831ea1284b15948398dfce80759c64a607b91 Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 23 Nov 2018 09:47:18 -0800 Subject: [PATCH 009/145] add bt-in-background preference And clear it from a button in the alert that's posted when the foreground service notification is selected. --- .../main/java/org/eehouse/android/xw4/BTService.java | 4 +++- .../main/java/org/eehouse/android/xw4/DlgDelegate.java | 1 + .../org/eehouse/android/xw4/GamesListDelegate.java | 10 ++++++++-- .../src/main/java/org/eehouse/android/xw4/XWPrefs.java | 10 ++++++++++ .../android/app/src/main/res/values/common_rsrc.xml | 1 + xwords4/android/app/src/main/res/values/strings.xml | 5 +++++ xwords4/android/app/src/main/res/xml/xwprefs.xml | 5 +++++ 7 files changed, 33 insertions(+), 3 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index 8b1f3a9b1..e969812f0 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -351,7 +351,9 @@ public class BTService extends XWService { Log.d( TAG, "startService(%s)", intent ); if ( ! sInForeground && canRunForegroundService() ) { - context.startForegroundService( intent ); + if ( XWPrefs.getBTBackgroundEnabled( context ) ) { + context.startForegroundService( intent ); + } } else if ( sInForeground || Build.VERSION.SDK_INT < Build.VERSION_CODES.O ) { context.startService( intent ); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java index 8b13e3b91..c805f4999 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java @@ -57,6 +57,7 @@ public class DlgDelegate { SET_HIDE_NEWGAME_BUTTONS, DWNLD_LOC_DICT, NEW_GAME_DFLT_NAME, + DISABLE_BT_BACK, // BoardDelegate UNDO_LAST_ACTION, diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index 1f14fe7f2..73a6e9395 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -1360,6 +1360,10 @@ public class GamesListDelegate extends ListDelegateBase true ); break; + case DISABLE_BT_BACK: + XWPrefs.setBTBackgroundEnabled( m_activity, false ); + break; + default: handled = super.onPosButton( action, params ); } @@ -2271,9 +2275,11 @@ public class GamesListDelegate extends ListDelegateBase private void tryBackgroundIntent( Intent intent ) { if ( intent.getBooleanExtra( BACKGROUND_EXTRA, false ) ) { + ActionPair pair = new ActionPair( Action.DISABLE_BT_BACK, + R.string.disable_bt_back ); makeNotAgainBuilder( R.string.not_again_btservice, - R.string.key_notagain_btservice, - Action.OPEN_GAME ) + R.string.key_notagain_btservice ) + .setActionPair( pair ) .show(); } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java index 4de7cb416..fafe5208e 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java @@ -52,6 +52,16 @@ public class XWPrefs { setPrefsBoolean( context, R.string.key_enable_sms, enabled ); } + public static void setBTBackgroundEnabled( Context context, boolean enabled ) + { + setPrefsBoolean( context, R.string.key_btback_enabled, enabled ); + } + + public static boolean getBTBackgroundEnabled( Context context ) + { + return getPrefsBoolean( context, R.string.key_btback_enabled, true ); + } + public static boolean getDebugEnabled( Context context ) { return getPrefsBoolean( context, R.string.key_enable_debug, false ); diff --git a/xwords4/android/app/src/main/res/values/common_rsrc.xml b/xwords4/android/app/src/main/res/values/common_rsrc.xml index 389e79ddb..5d8eef505 100644 --- a/xwords4/android/app/src/main/res/values/common_rsrc.xml +++ b/xwords4/android/app/src/main/res/values/common_rsrc.xml @@ -61,6 +61,7 @@ key_notify_sound key_disable_relay key_notify_vibrate + key_btback_enabled key_enable_sms key_enable_p2p key_network_behavior diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index d330d7eda..6ab747561 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -2026,6 +2026,9 @@ Enable WiFi Direct Experimental, uses lots of battery + Enable background Bluetooth + Always listen for Bluetooth messages + Confirm your SMS plan @@ -2649,6 +2652,8 @@ Bluetooth moves and invitations while in the foreground, but any sent while it\'s in the background will be lost. + Disable Background + This game has sent no invitations Disable side-by-side diff --git a/xwords4/android/app/src/main/res/xml/xwprefs.xml b/xwords4/android/app/src/main/res/xml/xwprefs.xml index 8d6204d6d..fdb679770 100644 --- a/xwords4/android/app/src/main/res/xml/xwprefs.xml +++ b/xwords4/android/app/src/main/res/xml/xwprefs.xml @@ -335,6 +335,11 @@ android:summary="@string/notify_other_summary" android:defaultValue="false" /> + Date: Sat, 24 Nov 2018 13:04:14 -0800 Subject: [PATCH 010/145] fix crashes (NPE and RelayService trying to run in background) Still need to figure out what RelayService does. It needn't run for long except where GCM isn't present. --- .../org/eehouse/android/xw4/BTService.java | 21 +++++++++++++------ .../eehouse/android/xw4/OnBootReceiver.java | 4 +++- .../org/eehouse/android/xw4/RelayService.java | 13 +++++++++--- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index e969812f0..a58d03898 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -234,7 +234,8 @@ public class BTService extends XWService { private static void onAppStateChange( Context context, boolean inForeground ) { - if ( sInForeground == null || sInForeground != inForeground ) { + Log.d( TAG, "onAppStateChange(inForeground=%b)", inForeground ); + if ( null == sInForeground || inForeground() != inForeground ) { sInForeground = inForeground; Intent intent = @@ -245,6 +246,11 @@ public class BTService extends XWService { } } + private static boolean inForeground() + { + return sInForeground != null && sInForeground; + } + static void onAppToForeground( Context context ) { onAppStateChange( context, true ); @@ -348,14 +354,17 @@ public class BTService extends XWService { private static void startService( Context context, Intent intent ) { - Log.d( TAG, "startService(%s)", intent ); + boolean inForeground = inForeground(); + Log.d( TAG, "startService(%s); inForeground = %b", intent, inForeground ); - if ( ! sInForeground && canRunForegroundService() ) { + if ( ! inForeground && canRunForegroundService() ) { if ( XWPrefs.getBTBackgroundEnabled( context ) ) { context.startForegroundService( intent ); } - } else if ( sInForeground || Build.VERSION.SDK_INT < Build.VERSION_CODES.O ) { + } else if ( inForeground || Build.VERSION.SDK_INT < Build.VERSION_CODES.O ) { context.startService( intent ); + } else { + Log.d( TAG, "startService(); not starting" ); } } @@ -399,7 +408,7 @@ public class BTService extends XWService { { int result = handleCommand( intent ); - if ( Service.START_STICKY == result && !sInForeground ) { + if ( Service.START_STICKY == result && ! inForeground() ) { startForeground(); } @@ -514,7 +523,7 @@ public class BTService extends XWService { .setContentIntent(pendIntent) .build(); - Log.d( TAG, "calling startForeground()" ); + Log.d( TAG, "calling service.startForeground()" ); startForeground( 1337, notification ); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/OnBootReceiver.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/OnBootReceiver.java index 3a1088efe..75525e924 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/OnBootReceiver.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/OnBootReceiver.java @@ -30,10 +30,12 @@ public class OnBootReceiver extends BroadcastReceiver { @Override public void onReceive( Context context, Intent intent ) { - if ( null != intent && null != intent.getAction() + if ( null != intent + && null != intent.getAction() && intent.getAction().equals( Intent.ACTION_BOOT_COMPLETED ) ) { Log.d( TAG, "got ACTION_BOOT_COMPLETED" ); startTimers( context ); + BTService.onAppToBackground( context ); } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java index b89c623eb..501891edd 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java @@ -77,6 +77,8 @@ public class RelayService extends XWService private static final String CMD_STR = "CMD"; + private static Boolean sInForeground; + private static enum MsgCmds { INVALID, PROCESS_GAME_MSGS, PROCESS_DEV_MSGS, @@ -188,6 +190,11 @@ public class RelayService extends XWService enabledChanged( context ); } + private static boolean inForeground() + { + return sInForeground != null && sInForeground; + } + public static void startService( Context context ) { Log.i( TAG, "startService()" ); @@ -199,10 +206,10 @@ public class RelayService extends XWService { Log.d( TAG, "startService(%s)", intent ); - if ( false ) { - context.startForegroundService( intent ); - } else { + if ( inForeground() || Build.VERSION.SDK_INT < Build.VERSION_CODES.O ) { context.startService( intent ); + } else { + Log.d( TAG, "startService(); not starting" ); } } From 988ac55eaa046ae447a5998c8425950cf5151918 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 27 Nov 2018 10:06:38 -0800 Subject: [PATCH 011/145] tweak apk-cmp script --- xwords4/android/scripts/apk-cmp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwords4/android/scripts/apk-cmp.py b/xwords4/android/scripts/apk-cmp.py index 06ff387cf..379175ec2 100755 --- a/xwords4/android/scripts/apk-cmp.py +++ b/xwords4/android/scripts/apk-cmp.py @@ -105,7 +105,7 @@ def compare( apks, apkData, indices ): printDiff( apks, key ) index += 1 if 0 != same: - print "(skipped {same} files)".format(same=same) + print "({same} identical files skipped)".format(same=same) def main(): apks = [] From 843c95e7ae7e301896815821c2990ca24bbb5d72 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 27 Nov 2018 11:27:18 -0800 Subject: [PATCH 012/145] new icon for omnipresent BTService notification --- xwords4/android/app/build.gradle | 1 + .../java/org/eehouse/android/xw4/BTService.java | 2 +- .../src/main/res/drawable/notify_btservice.png | Bin 0 -> 313 bytes 3 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 xwords4/android/app/src/main/res/drawable/notify_btservice.png diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle index b48d1b914..21e7193ae 100644 --- a/xwords4/android/app/build.gradle +++ b/xwords4/android/app/build.gradle @@ -230,6 +230,7 @@ task copyStrings(type: Exec) { task ndkSetup(type: Exec) { workingDir '../' + // remove ', "--arm-only"' for Genymotion builds commandLine "./scripts/ndksetup.sh", "--with-clang", "--arm-only" } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index a58d03898..1350edd28 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -517,7 +517,7 @@ public class BTService extends XWService { .getActivity(this, Utils.nextRandomInt(), notifIntent, PendingIntent.FLAG_ONE_SHOT); Notification notification = new NotificationCompat.Builder(this, Utils.CHANNEL_ID) - .setSmallIcon( R.drawable.notify ) + .setSmallIcon( R.drawable.notify_btservice ) .setContentTitle( BTService.class.getSimpleName() ) .setContentText("listening for bluetooth messages...") .setContentIntent(pendIntent) diff --git a/xwords4/android/app/src/main/res/drawable/notify_btservice.png b/xwords4/android/app/src/main/res/drawable/notify_btservice.png new file mode 100644 index 0000000000000000000000000000000000000000..99209ad54c28cdc894b71a142c34128a1f59581a GIT binary patch literal 313 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDD3?#L31Vw-pXMj(LD+5FN|NsAiJlpFZrGOM; zNswPKgTu2MX&_FLx4R2N2dk_HNO^%rWHAGSp&1A>&U)^o02E{|@$_|Nf5a^TPd&Y|Yhu=)JV&VVNz~}hLbb(L0&1F$JHkBK*dG_(X`?SK~MBTkh z6TYg6xbj;#T(h>45IESotoXu&?H115yZX1~OfUT_R3fF3VH@^Wt8=#+bNOAKIVTN_ y*Ys-dx3_jH>5%Kr*PeV_X+cGhY~1tzSNN5*>i?cLU!V(gG=rzBpUXO@geCxT1Z-&l literal 0 HcmV?d00001 From 7eb278033ab552876ed0040355354c2cbe5dd8a7 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 28 Nov 2018 19:20:43 -0800 Subject: [PATCH 013/145] revert change setting notifiction priority low --- .../android/app/src/main/java/org/eehouse/android/xw4/Utils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java index 8bcfbf672..03d8dc8f1 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java @@ -264,7 +264,6 @@ public class Utils { Notification notification = new NotificationCompat.Builder( context, CHANNEL_ID ) .setContentIntent( pi ) .setSmallIcon( R.drawable.notify ) - .setPriority(NotificationCompat.PRIORITY_LOW) //.setTicker(body) //.setWhen(time) .setAutoCancel( true ) From fc699caaa8630757b9bc7a7bcb807169b906349a Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 28 Nov 2018 19:27:32 -0800 Subject: [PATCH 014/145] ensure channel id always setup before use --- .../java/org/eehouse/android/xw4/BTService.java | 2 +- .../main/java/org/eehouse/android/xw4/Utils.java | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index 1350edd28..dc1f985b0 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -516,7 +516,7 @@ public class BTService extends XWService { PendingIntent pendIntent = PendingIntent .getActivity(this, Utils.nextRandomInt(), notifIntent, PendingIntent.FLAG_ONE_SHOT); Notification notification = - new NotificationCompat.Builder(this, Utils.CHANNEL_ID) + new NotificationCompat.Builder( this, Utils.getChannelId(this) ) .setSmallIcon( R.drawable.notify_btservice ) .setContentTitle( BTService.class.getSimpleName() ) .setContentText("listening for bluetooth messages...") diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java index 03d8dc8f1..f80ff4018 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java @@ -84,7 +84,7 @@ public class Utils { private static final String TAG = Utils.class.getSimpleName(); public static final int TURN_COLOR = 0x7F00FF00; - static final String CHANNEL_ID = BuildConfig.APPLICATION_ID + "_channel_id"; + private static final String _CHANNEL_ID = BuildConfig.APPLICATION_ID + "_channel_id"; private static final String DB_PATH = "XW_GAMES"; private static final String HIDDEN_PREFS = "xwprefs_hidden"; @@ -241,8 +241,6 @@ public class Utils { String title, String body, int id ) { - makeNotificationChannel( context ); - /* nextRandomInt: per this link http://stackoverflow.com/questions/10561419/scheduling-more-than-one-pendingintent-to-same-activity-using-alarmmanager one way to avoid getting the same PendingIntent for similar @@ -261,7 +259,8 @@ public class Utils { defaults |= Notification.DEFAULT_VIBRATE; } - Notification notification = new NotificationCompat.Builder( context, CHANNEL_ID ) + Notification notification = + new NotificationCompat.Builder( context, getChannelId(context) ) .setContentIntent( pi ) .setSmallIcon( R.drawable.notify ) //.setTicker(body) @@ -624,7 +623,7 @@ public class Utils { } private static boolean sChannelMade = false; - private static void makeNotificationChannel( Context context ) + static String getChannelId( Context context ) { if ( !sChannelMade ) { sChannelMade = true; @@ -633,9 +632,9 @@ public class Utils { context.getSystemService( Context.NOTIFICATION_SERVICE ); String channelDescription = "XWORDS Default Channel"; - NotificationChannel channel = notMgr.getNotificationChannel( CHANNEL_ID ); + NotificationChannel channel = notMgr.getNotificationChannel( _CHANNEL_ID ); if ( channel == null ) { - channel = new NotificationChannel( CHANNEL_ID, channelDescription, + channel = new NotificationChannel( _CHANNEL_ID, channelDescription, NotificationManager.IMPORTANCE_LOW ); // channel.setLightColor(Color.GREEN); channel.enableVibration( true ); @@ -643,5 +642,6 @@ public class Utils { } } } + return _CHANNEL_ID; } } From ce3cb62f0243d2db71f563483842b2975cd3e84a Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 28 Nov 2018 19:35:24 -0800 Subject: [PATCH 015/145] add reversed version of btservice notification icon For the Dbg variant to match its normal notification icon. --- .../src/xw4d/res/drawable/notify_btservice.png | Bin 0 -> 472 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 xwords4/android/app/src/xw4d/res/drawable/notify_btservice.png diff --git a/xwords4/android/app/src/xw4d/res/drawable/notify_btservice.png b/xwords4/android/app/src/xw4d/res/drawable/notify_btservice.png new file mode 100644 index 0000000000000000000000000000000000000000..43be5ea612a7932b2b38786951463905023e31b1 GIT binary patch literal 472 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDD3?#L31Vw-pOS+@4BLl<6e(pbstU$g(vPY0F z14ES>14Ba#1H&(%P{RubhEkx$R|yOZRx=nF#0%!^3bX-A@C5jTxH2%L1DXH-|7Tzb zeOvZC6v$yL3GxeOaCmkj4a7vL>4nJ7@C1FH=O z_D9^Z%nF**yVtx03N80^aSYKozxI+L-(dwF)&TL9p+_~Xio0T(&gA+frJlL6boW)x zpHq&isimC=^SAk!+QaZ*i{8$wDm(aQL~@IEAI~m3@L=Pw2&;l?fGf01S4kY(NC?0j}9GfNFq!N!G*TZ>PmO_upu zn6vy%^Q8SuF9T90%>K;qMS)*#L* Date: Wed, 28 Nov 2018 20:14:49 -0800 Subject: [PATCH 016/145] trying to fix travis build --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 132ede1e8..605f42385 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: android jdk: oraclejdk8 env: global: - - ANDROID_TARGET=android-15 + - ANDROID_TARGET=android-14 - ANDROID_ABI=armeabi-v7a,x86 - secure: d8PwteM+xp1IRU3QkvmHtxh+1Ta9n/kl/SJ3EZa3iColVVXY1etzjY3cKrEGKKMJuI4be30kPzvNw9/BVTawDpnU9/NtWqykJ8QHXNWnZIvUQ/kxHBS1DbcstmcYU9gvR83EFb8BT+Y9frpNfMcZDlSvBpEGqDQEPmxiDzSmjdUmJJQWStncxL9pE+lCdM6lHBgtfYoMMiqCQF/DxkQisjyUVF4mbTGuT9JOOWjVsTGPA7ehzsWDHoJ3p2ai8UKHAYucUWZcTt4rkq9l35ExvgKd3L8luk8U3X3Fk9yzVhPJC56T0XNbNrsQ2W7/7oGRv6EQFV3aKDZimJ7CVjBcEjZmPxeUVvCsMW8XB41ZvYcy6xsjF96oyjn1gb0r/2mZbTaWP0izSTwMYZ5vFNKUamDtRZgrneD0lfvXgfTzirrCU7FqO2RH7ZK5PQpSgSoZxKsKyeyFPEa2ihivc95rz1MS6mamle9wrIlSAgEGcaZMIYvKiOnCLk7CZCKuwm2dhYPgzCHW3PUopay59BBwMsSqWpxsiHEr5jYGpb0pHGbzPTJNUpg1LNQX5eMQOMlEt7rfpoC7JG24hR9vxl4Yf9LhxYlSwUiPy7TYHdbA0kUS68skfzxU6+ekWZF2QFM+L4vWCYmEHDy7n+I0df+PavycgNW989ROlAKhQjtMyqM= android: @@ -10,7 +10,7 @@ android: - tools - platform-tools - build-tools-27.0.3 - - android-23 + - android-26 licenses: - android-sdk-preview-license-.+ - android-sdk-license-.+ From b2bf3a6e806d797023b04bd9b38246670f962d57 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 28 Nov 2018 20:38:43 -0800 Subject: [PATCH 017/145] move google() above maven (to fix travis?) --- xwords4/android/app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle index 21e7193ae..e49c1dab1 100644 --- a/xwords4/android/app/build.gradle +++ b/xwords4/android/app/build.gradle @@ -23,8 +23,8 @@ if ( FABRIC_API_KEY && hasProperty('useCrashlytics') ) { apply plugin: 'io.fabric' } repositories { - maven { url 'https://maven.fabric.io/public' } google() + maven { url 'https://maven.fabric.io/public' } } android { From 91828cb851d2157c74745dd12122c41d771798fc Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 28 Nov 2018 21:21:48 -0800 Subject: [PATCH 018/145] add more google() still trying to fix travis builds --- xwords4/android/build.gradle | 3 ++- xwords4/android/scripts/build_with_lint.sh | 5 ----- 2 files changed, 2 insertions(+), 6 deletions(-) delete mode 100755 xwords4/android/scripts/build_with_lint.sh diff --git a/xwords4/android/build.gradle b/xwords4/android/build.gradle index de085ae7f..85b486c88 100644 --- a/xwords4/android/build.gradle +++ b/xwords4/android/build.gradle @@ -2,9 +2,9 @@ buildscript { repositories { + google() jcenter() maven { url 'https://maven.fabric.io/public' } - google() } dependencies { classpath 'com.android.tools.build:gradle:3.1.2' @@ -17,6 +17,7 @@ buildscript { allprojects { repositories { + google() jcenter() } } diff --git a/xwords4/android/scripts/build_with_lint.sh b/xwords4/android/scripts/build_with_lint.sh deleted file mode 100755 index 46fc23078..000000000 --- a/xwords4/android/scripts/build_with_lint.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -# invoke the build process with javac lint features enabled - -ant "-Djava.compilerargs=-Xlint:unchecked -Xlint:deprecation" clean debug From 9eec5c37ef87b59e64d296ccaf7cda169abddf0f Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 29 Nov 2018 09:30:14 -0800 Subject: [PATCH 019/145] fix path name string causing JNI crash on emulator --- xwords4/android/jni/utilwrapper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xwords4/android/jni/utilwrapper.c b/xwords4/android/jni/utilwrapper.c index 4e948a906..03eab0bf4 100644 --- a/xwords4/android/jni/utilwrapper.c +++ b/xwords4/android/jni/utilwrapper.c @@ -702,10 +702,10 @@ and_dutil_deviceRegistered( XW_DUtilCtxt* duc, DevIDType typ, const XP_UCHAR* idRelay ) { DUTIL_CBK_HEADER( "deviceRegistered", - "(L" PKG_PATH("jni/UtilCtxt$DevIDType") ";Ljava/lang/String;)V" ); + "(L" PKG_PATH("jni/DUtilCtxt$DevIDType") ";Ljava/lang/String;)V" ); jstring jstr = (*env)->NewStringUTF( env, idRelay ); jobject jtyp = intToJEnum( env, typ, - PKG_PATH("jni/UtilCtxt$DevIDType") ); + PKG_PATH("jni/DUtilCtxt$DevIDType") ); (*env)->CallVoidMethod( env, dutil->jdutil, mid, jtyp, jstr ); deleteLocalRefs( env, jstr, jtyp, DELETE_NO_REF ); DUTIL_CBK_TAIL(); From b23b83700963a275c74f9eae1bec1d179ab2975c Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 29 Nov 2018 09:30:14 -0800 Subject: [PATCH 020/145] fix path name string causing JNI crash on emulator And catch NPE that also seems to be emulator-only --- .../src/main/java/org/eehouse/android/xw4/WiDirService.java | 2 ++ xwords4/android/jni/utilwrapper.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirService.java index 693647426..e7695401e 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirService.java @@ -214,6 +214,8 @@ public class WiDirService extends XWService { sHavePermission = false; } catch ( SecurityException se ) { // perm not in manifest sHavePermission = false; + } catch ( NullPointerException npe ) { // Seeing this on Oreo emulator + sHavePermission = false; } } diff --git a/xwords4/android/jni/utilwrapper.c b/xwords4/android/jni/utilwrapper.c index 4e948a906..03eab0bf4 100644 --- a/xwords4/android/jni/utilwrapper.c +++ b/xwords4/android/jni/utilwrapper.c @@ -702,10 +702,10 @@ and_dutil_deviceRegistered( XW_DUtilCtxt* duc, DevIDType typ, const XP_UCHAR* idRelay ) { DUTIL_CBK_HEADER( "deviceRegistered", - "(L" PKG_PATH("jni/UtilCtxt$DevIDType") ";Ljava/lang/String;)V" ); + "(L" PKG_PATH("jni/DUtilCtxt$DevIDType") ";Ljava/lang/String;)V" ); jstring jstr = (*env)->NewStringUTF( env, idRelay ); jobject jtyp = intToJEnum( env, typ, - PKG_PATH("jni/UtilCtxt$DevIDType") ); + PKG_PATH("jni/DUtilCtxt$DevIDType") ); (*env)->CallVoidMethod( env, dutil->jdutil, mid, jtyp, jstr ); deleteLocalRefs( env, jstr, jtyp, DELETE_NO_REF ); DUTIL_CBK_TAIL(); From 0a0107dd7fdc5eaadc631141b10b3054fd8d10c5 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 29 Nov 2018 09:35:08 -0800 Subject: [PATCH 021/145] fix to contact relay in foreground on Oreo+ Background still needs a lot of work. --- .../org/eehouse/android/xw4/RelayService.java | 27 ++++++++++++++++++- .../java/org/eehouse/android/xw4/XWApp.java | 2 ++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java index 501891edd..ada0eeeb0 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java @@ -192,7 +192,32 @@ public class RelayService extends XWService private static boolean inForeground() { - return sInForeground != null && sInForeground; + boolean result = sInForeground != null && sInForeground; + Log.d( TAG, "inForeground() => %b", result ); + return result; + } + + private static void onAppStateChange( Context context, boolean inForeground ) + { + Log.d( TAG, "onAppStateChange(inForeground=%b)", inForeground ); + if ( null == sInForeground || inForeground() != inForeground ) { + sInForeground = inForeground; + // Intent intent = + // getIntentTo( context, + // inForeground ? BTAction.START_FOREGROUND + // : BTAction.START_BACKGROUND ); + // startService( context, intent ); + } + } + + static void onAppToForeground( Context context ) + { + onAppStateChange( context, true ); + } + + static void onAppToBackground( Context context ) + { + onAppStateChange( context, false ); } public static void startService( Context context ) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java index 7927c4f65..cbbc2e1dc 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java @@ -106,9 +106,11 @@ public class XWApp extends Application implements LifecycleObserver { switch( event ) { case ON_RESUME: BTService.onAppToForeground( this ); + RelayService.onAppToForeground( this ); break; case ON_STOP: BTService.onAppToBackground( this ); + RelayService.onAppToBackground( this ); break; } } From 813669fafb4273a1c88ed7ba7bad8841da55e7d0 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 29 Nov 2018 12:55:35 -0800 Subject: [PATCH 022/145] include X86 native library again It's a pain to have to change code to run in Genymotion, and to have upgrade not testable using Genymotion. Consider verting this change before next release. --- xwords4/android/app/build.gradle | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle index e49c1dab1..21bc531e4 100644 --- a/xwords4/android/app/build.gradle +++ b/xwords4/android/app/build.gradle @@ -231,7 +231,12 @@ task copyStrings(type: Exec) { task ndkSetup(type: Exec) { workingDir '../' // remove ', "--arm-only"' for Genymotion builds - commandLine "./scripts/ndksetup.sh", "--with-clang", "--arm-only" + + // I'm putting ARM back for a while. It's too much trouble having + // builds, including those built by travis, that don't run on the + // emulator. Maybe remove this change before each release? + commandLine "./scripts/ndksetup.sh", "--with-clang" + // commandLine "./scripts/ndksetup.sh", "--with-clang", "--arm-only" } task myPreBuild(dependsOn: ['ndkSetup', 'mkImages', 'copyStrings', 'mkXml']) { From 3fe1289a8db5850497909ff47da44c64d4ed4eb5 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 29 Nov 2018 17:07:14 -0800 Subject: [PATCH 023/145] include new permission to install third-party apks Fixed upgrade of Dbg variant not working on Oreo. --- xwords4/android/app/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/xwords4/android/app/src/main/AndroidManifest.xml b/xwords4/android/app/src/main/AndroidManifest.xml index ccc7396e2..db24701c9 100644 --- a/xwords4/android/app/src/main/AndroidManifest.xml +++ b/xwords4/android/app/src/main/AndroidManifest.xml @@ -24,6 +24,7 @@ + From af7b9fcba00d71c20034278c6dddcc491c888c2b Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 29 Nov 2018 18:02:06 -0800 Subject: [PATCH 024/145] Always call startForeground after startForegroundService It's an error to e.g. stopSelf() without having called startForeground, so do it even when about to exit. --- .../org/eehouse/android/xw4/BTService.java | 63 ++++++++++++++----- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index dc1f985b0..11234f7e4 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -56,6 +56,25 @@ import java.util.Set; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; +// Notes on running under Oreo +// +// The goal is to be running only when useful: when user wants to play via +// BT. Ideally we'd not run the foreground service when BT is turned off, but +// there's no way to be notified of its being turned on without installing a +// receiver. So *something* has to be running, whether it's listening on a BT +// socket or hosting the receiver. Might as well be the socket listener. Users +// who want the service not running when BT's off can turn it off via app +// preferences. When they try to start a BT game we can note the preference +// and suggest they change it. And when an invitation sent is not received the +// sender can be told to suggest to his opponent to turn on the preference. +// +// When there's no BT adapter at all (Emulator case) there's no point in +// starting the service. Let's catch that early. +// +// Note also that we need to be careful to NEVER call stopSelf() after calling +// startForegroundService() until AFTER calling startForeground(). Doing so +// will cause a crash. + public class BTService extends XWService { private static final String TAG = BTService.class.getSimpleName(); private static final String BOGUS_MARSHMALLOW_ADDR = "02:00:00:00:00:00"; @@ -169,6 +188,7 @@ public class BTService extends XWService { private BTMsgSink m_btMsgSink; private BTListenerThread m_listener; private BTSenderThread m_sender; + private Notification m_notification; // make once use many private static int s_errCount = 0; public static boolean BTAvailable() @@ -388,6 +408,8 @@ public class BTService extends XWService { @Override public void onCreate() { + startForegroundIf(); + BluetoothAdapter adapter = XWApp.BTSUPPORTED ? BluetoothAdapter.getDefaultAdapter() : null; if ( null != adapter && adapter.isEnabled() ) { @@ -406,11 +428,9 @@ public class BTService extends XWService { @Override public int onStartCommand( Intent intent, int flags, int startId ) { - int result = handleCommand( intent ); + startForegroundIf(); - if ( Service.START_STICKY == result && ! inForeground() ) { - startForeground(); - } + int result = handleCommand( intent ); return result; } @@ -510,21 +530,30 @@ public class BTService extends XWService { return result; } // handleCommand() - private void startForeground() + private void startForegroundIf() { - Intent notifIntent = GamesListDelegate.makeBackgroundIntent( this ); - PendingIntent pendIntent = PendingIntent - .getActivity(this, Utils.nextRandomInt(), notifIntent, PendingIntent.FLAG_ONE_SHOT); - Notification notification = - new NotificationCompat.Builder( this, Utils.getChannelId(this) ) - .setSmallIcon( R.drawable.notify_btservice ) - .setContentTitle( BTService.class.getSimpleName() ) - .setContentText("listening for bluetooth messages...") - .setContentIntent(pendIntent) - .build(); + if ( ! inForeground() ) { + Log.d( TAG, "startForegroundIf(): starting" ); - Log.d( TAG, "calling service.startForeground()" ); - startForeground( 1337, notification ); + if ( null == m_notification ) { + Intent notifIntent = GamesListDelegate.makeBackgroundIntent( this ); + PendingIntent pendIntent = PendingIntent + .getActivity( this, Utils.nextRandomInt(), notifIntent, + PendingIntent.FLAG_ONE_SHOT ); + m_notification = + new NotificationCompat.Builder( this, Utils.getChannelId(this) ) + .setSmallIcon( R.drawable.notify_btservice ) + .setContentTitle( BTService.class.getSimpleName() ) + .setContentText("listening for bluetooth messages...") + .setContentIntent(pendIntent) + .build(); + } + + Log.d( TAG, "calling service.startForeground()" ); + startForeground( R.string.app_name, m_notification ); + } else { + Log.d( TAG, "startForegroundIf(): NOT starting" ); + } } private class BTListenerThread extends Thread { From 683bb384029d2d3b0d84c277a01806fef604d70b Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 3 Dec 2018 08:26:47 -0800 Subject: [PATCH 025/145] replace junit's assert with my own And have it log before throwing. Should be easier to track down asserts coming from jni callbacks this way than in the C code. --- .../org/eehouse/android/xw4/AboutAlert.java | 1 - .../java/org/eehouse/android/xw4/Assert.java | 58 +++++++++++++++++++ .../eehouse/android/xw4/BTInviteDelegate.java | 1 - .../org/eehouse/android/xw4/BTService.java | 1 - .../org/eehouse/android/xw4/BiDiSockWrap.java | 1 - .../org/eehouse/android/xw4/BoardCanvas.java | 1 - .../eehouse/android/xw4/BoardContainer.java | 1 - .../eehouse/android/xw4/BoardDelegate.java | 1 - .../org/eehouse/android/xw4/BoardView.java | 1 - .../org/eehouse/android/xw4/ChatDelegate.java | 1 - .../eehouse/android/xw4/CommsTransport.java | 1 - .../android/xw4/ConnStatusHandler.java | 1 - .../android/xw4/ConnViaViewLayout.java | 1 - .../java/org/eehouse/android/xw4/DBAlert.java | 1 - .../java/org/eehouse/android/xw4/DBUtils.java | 1 - .../org/eehouse/android/xw4/DbgUtils.java | 1 - .../org/eehouse/android/xw4/DelegateBase.java | 1 - .../android/xw4/DictBrowseDelegate.java | 1 - .../eehouse/android/xw4/DictLangCache.java | 1 - .../org/eehouse/android/xw4/DictUtils.java | 1 - .../eehouse/android/xw4/DictsDelegate.java | 1 - .../org/eehouse/android/xw4/DisablesItem.java | 1 - .../org/eehouse/android/xw4/DlgDelegate.java | 1 - .../eehouse/android/xw4/DlgDelegateAlert.java | 1 - .../org/eehouse/android/xw4/DlgState.java | 1 - .../eehouse/android/xw4/DwnldDelegate.java | 1 - .../eehouse/android/xw4/EnableSMSAlert.java | 1 - .../eehouse/android/xw4/ExpiringDelegate.java | 1 - .../android/xw4/GameConfigDelegate.java | 1 - .../org/eehouse/android/xw4/GameListItem.java | 1 - .../org/eehouse/android/xw4/GameLock.java | 1 - .../org/eehouse/android/xw4/GameUtils.java | 1 - .../android/xw4/GamesListDelegate.java | 1 - .../android/xw4/HeaderWithExpander.java | 1 - .../org/eehouse/android/xw4/HostDelegate.java | 1 - .../android/xw4/InviteChoicesAlert.java | 1 - .../eehouse/android/xw4/InviteDelegate.java | 1 - .../org/eehouse/android/xw4/LookupAlert.java | 1 - .../eehouse/android/xw4/LookupAlertView.java | 1 - .../org/eehouse/android/xw4/MainActivity.java | 1 - .../org/eehouse/android/xw4/MultiMsgSink.java | 1 - .../org/eehouse/android/xw4/MultiService.java | 1 - .../eehouse/android/xw4/NagTurnReceiver.java | 1 - .../eehouse/android/xw4/NetLaunchInfo.java | 1 - .../eehouse/android/xw4/NetStateCache.java | 1 - .../org/eehouse/android/xw4/NetUtils.java | 1 - .../eehouse/android/xw4/NotAgainAlert.java | 1 - .../org/eehouse/android/xw4/OkOnlyAlert.java | 1 - .../java/org/eehouse/android/xw4/Perms23.java | 1 - .../eehouse/android/xw4/PrefsActivity.java | 1 - .../eehouse/android/xw4/PrefsDelegate.java | 1 - .../android/xw4/RelayInviteDelegate.java | 1 - .../org/eehouse/android/xw4/RelayService.java | 1 - .../android/xw4/SMSInviteDelegate.java | 1 - .../org/eehouse/android/xw4/SMSService.java | 1 - .../android/xw4/StudyListDelegate.java | 1 - .../eehouse/android/xw4/TilePickAlert.java | 1 - .../org/eehouse/android/xw4/TilePickView.java | 1 - .../java/org/eehouse/android/xw4/Toolbar.java | 1 - .../java/org/eehouse/android/xw4/Utils.java | 1 - .../android/xw4/WiDirInviteDelegate.java | 1 - .../org/eehouse/android/xw4/WiDirService.java | 1 - .../org/eehouse/android/xw4/XWActivity.java | 1 - .../java/org/eehouse/android/xw4/XWApp.java | 1 - .../android/xw4/XWConnAddrPreference.java | 1 - .../eehouse/android/xw4/XWDialogFragment.java | 1 - .../eehouse/android/xw4/XWExpListAdapter.java | 1 - .../org/eehouse/android/xw4/XWFragment.java | 1 - .../java/org/eehouse/android/xw4/XWPrefs.java | 1 - .../org/eehouse/android/xw4/XWService.java | 1 - .../eehouse/android/xw4/jni/CommsAddrRec.java | 3 +- .../eehouse/android/xw4/jni/CurGameInfo.java | 2 +- .../eehouse/android/xw4/jni/DUtilCtxt.java | 3 +- .../eehouse/android/xw4/jni/GameSummary.java | 3 +- .../eehouse/android/xw4/jni/JNIThread.java | 3 +- .../eehouse/android/xw4/jni/JNIUtilsImpl.java | 3 +- .../eehouse/android/xw4/jni/LocalPlayer.java | 3 +- .../eehouse/android/xw4/jni/UtilCtxtImpl.java | 1 - .../org/eehouse/android/xw4/jni/XwJNI.java | 3 +- .../org/eehouse/android/xw4/loc/LocUtils.java | 2 +- .../eehouse/android/xw4/GCMIntentService.java | 1 - xwords4/android/scripts/mk_xml.py | 2 +- 82 files changed, 68 insertions(+), 88 deletions(-) create mode 100644 xwords4/android/app/src/main/java/org/eehouse/android/xw4/Assert.java diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/AboutAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/AboutAlert.java index a64e659c0..da8820309 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/AboutAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/AboutAlert.java @@ -33,7 +33,6 @@ import android.widget.TextView; import java.text.DateFormat; import java.util.Date; -import junit.framework.Assert; import org.eehouse.android.xw4.loc.LocUtils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Assert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Assert.java new file mode 100644 index 000000000..8f8a62d81 --- /dev/null +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Assert.java @@ -0,0 +1,58 @@ +/* -*- compile-command: "find-and-gradle.sh insXw4Deb"; -*- */ +/* + * Copyright 2012 by Eric House (xwords@eehouse.org). All rights + * reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package org.eehouse.android.xw4; + +public class Assert { + private static final String TAG = Assert.class.getSimpleName(); + + public static void fail() { + assertTrue(false); + } + + public static void assertFalse(boolean val) + { + assertTrue(! val); + } + + public static void assertTrue(boolean val) { + if (! val) { + Log.e( TAG, "firing assert!" ); + DbgUtils.printStack( TAG ); + junit.framework.Assert.fail(); + } + } + + public static void assertNotNull( Object val ) + { + assertTrue( val != null ); + } + + public static void assertNull( Object val ) + { + assertTrue( val == null ); + } + + public static void assertEquals( Object obj1, Object obj2 ) + { + assertTrue( (obj1 == null && obj2 == null) + || (obj1 != null && obj1.equals(obj2)) ); + } +} diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java index de9535a06..9a769cb8b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java @@ -27,7 +27,6 @@ import android.os.Bundle; import android.view.View; import android.widget.Button; -import junit.framework.Assert; import org.eehouse.android.xw4.DBUtils.SentInvitesInfo; import org.eehouse.android.xw4.DlgDelegate.Action; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index 11234f7e4..fedfe3f87 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -34,7 +34,6 @@ import android.content.Intent; import android.os.Build; import android.support.v4.app.NotificationCompat; -import junit.framework.Assert; import org.eehouse.android.xw4.MultiService.DictFetchOwner; import org.eehouse.android.xw4.MultiService.MultiEvent; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BiDiSockWrap.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BiDiSockWrap.java index e2744c9f5..a62fce31e 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BiDiSockWrap.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BiDiSockWrap.java @@ -27,7 +27,6 @@ import java.net.Socket; import java.util.concurrent.LinkedBlockingQueue; import org.json.JSONObject; -import junit.framework.Assert; public class BiDiSockWrap { private static final String TAG = BiDiSockWrap.class.getSimpleName(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardCanvas.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardCanvas.java index f58412ae9..217986941 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardCanvas.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardCanvas.java @@ -31,7 +31,6 @@ import android.graphics.RectF; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; -import junit.framework.Assert; import org.eehouse.android.xw4.jni.BoardDims; import org.eehouse.android.xw4.jni.CommonPrefs; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardContainer.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardContainer.java index 19bb03e6c..e2b092f4b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardContainer.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardContainer.java @@ -29,7 +29,6 @@ import android.view.View; import android.view.View.MeasureSpec; import android.graphics.Rect; -import junit.framework.Assert; public class BoardContainer extends ViewGroup { private static final String TAG = BoardContainer.class.getSimpleName(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java index b2ed17c5d..ba5e64e8f 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java @@ -49,7 +49,6 @@ import java.util.Map; import java.util.Map; import java.util.Set; -import junit.framework.Assert; import org.eehouse.android.xw4.DBUtils.SentInvitesInfo; import org.eehouse.android.xw4.DlgDelegate.Action; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardView.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardView.java index fff413910..5d059fcf8 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardView.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardView.java @@ -31,7 +31,6 @@ import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; -import junit.framework.Assert; import org.eehouse.android.xw4.jni.BoardDims; import org.eehouse.android.xw4.jni.BoardHandler; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ChatDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ChatDelegate.java index 1219b8d57..f3239e590 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ChatDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ChatDelegate.java @@ -40,7 +40,6 @@ import android.widget.TextView; import java.text.DateFormat; import android.text.format.DateUtils; -import junit.framework.Assert; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.jni.JNIThread; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/CommsTransport.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/CommsTransport.java index 4c51b9af5..b486b89fa 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/CommsTransport.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/CommsTransport.java @@ -22,7 +22,6 @@ package org.eehouse.android.xw4; import android.content.Context; -import junit.framework.Assert; import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnStatusHandler.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnStatusHandler.java index ac9d8dfeb..efe49c8b2 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnStatusHandler.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnStatusHandler.java @@ -32,7 +32,6 @@ import android.provider.Settings; import android.text.format.DateUtils; import android.text.format.Time; -import junit.framework.Assert; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnViaViewLayout.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnViaViewLayout.java index 2e234e949..d90cbf290 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnViaViewLayout.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnViaViewLayout.java @@ -30,7 +30,6 @@ import android.widget.LinearLayout; import java.util.Map; -import junit.framework.Assert; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBAlert.java index bdf5d0337..9a3724f54 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBAlert.java @@ -34,7 +34,6 @@ import org.eehouse.android.xw4.loc.LocUtils; import java.io.Serializable; -import junit.framework.Assert; public class DBAlert extends XWDialogFragment { private static final String TAG = DBAlert.class.getSimpleName(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java index 035d107e2..700b918a8 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java @@ -33,7 +33,6 @@ import android.graphics.BitmapFactory; import android.os.Environment; import android.text.TextUtils; -import junit.framework.Assert; import org.eehouse.android.xw4.DictUtils.DictLoc; import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify.InviteMeans; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DbgUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DbgUtils.java index db5664334..e1b6f86c1 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DbgUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DbgUtils.java @@ -33,7 +33,6 @@ import java.util.Formatter; import java.util.Iterator; import java.util.Set; -import junit.framework.Assert; import org.eehouse.android.xw4.loc.LocUtils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java index 144c61b91..66932cfa1 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java @@ -40,7 +40,6 @@ import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; -import junit.framework.Assert; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.ActionPair; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictBrowseDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictBrowseDelegate.java index 5a165bcf1..05fc4c51e 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictBrowseDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictBrowseDelegate.java @@ -37,7 +37,6 @@ import android.widget.SectionIndexer; import android.widget.Spinner; import android.widget.TextView; -import junit.framework.Assert; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.jni.JNIUtilsImpl; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictLangCache.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictLangCache.java index b614446b2..9573533a5 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictLangCache.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictLangCache.java @@ -25,7 +25,6 @@ import android.content.res.Resources; import android.os.Handler; import android.widget.ArrayAdapter; -import junit.framework.Assert; import org.eehouse.android.xw4.DictUtils.DictAndLoc; import org.eehouse.android.xw4.DictUtils.DictLoc; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictUtils.java index f354b1e29..cd46b0106 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictUtils.java @@ -24,7 +24,6 @@ import android.content.Context; import android.content.res.AssetManager; import android.os.Environment; -import junit.framework.Assert; import org.eehouse.android.xw4.jni.JNIUtilsImpl; import org.eehouse.android.xw4.jni.XwJNI; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictsDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictsDelegate.java index 19ede5444..c02d61c19 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictsDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictsDelegate.java @@ -45,7 +45,6 @@ import android.widget.ListView; import android.widget.PopupMenu; import android.widget.TextView; -import junit.framework.Assert; import org.eehouse.android.xw4.DictUtils.DictAndLoc; import org.eehouse.android.xw4.DictUtils.DictLoc; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DisablesItem.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DisablesItem.java index 6cb9f16ad..9eebd7584 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DisablesItem.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DisablesItem.java @@ -31,7 +31,6 @@ import android.widget.TextView; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; -import junit.framework.Assert; public class DisablesItem extends LinearLayout { private CommsConnType m_type; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java index c805f4999..526e26107 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java @@ -34,7 +34,6 @@ import android.view.View; import java.io.Serializable; -import junit.framework.Assert; import org.eehouse.android.xw4.DBUtils.SentInvitesInfo; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegateAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegateAlert.java index f30ad2f1a..8c2266033 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegateAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegateAlert.java @@ -31,7 +31,6 @@ import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.ActionPair; import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify; -import junit.framework.Assert; import org.eehouse.android.xw4.loc.LocUtils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgState.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgState.java index e3ce8f217..850971e10 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgState.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgState.java @@ -32,7 +32,6 @@ import java.util.List; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.ActionPair; -import junit.framework.Assert; public class DlgState implements Parcelable { private static final String TAG = DlgState.class.getSimpleName(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DwnldDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DwnldDelegate.java index 858787047..df6e900fa 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DwnldDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DwnldDelegate.java @@ -34,7 +34,6 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; -import junit.framework.Assert; import java.io.File; import java.io.FileOutputStream; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EnableSMSAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EnableSMSAlert.java index 07548ab49..41760d3c1 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EnableSMSAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EnableSMSAlert.java @@ -30,7 +30,6 @@ import android.widget.AdapterView; import android.widget.Button; import android.widget.Spinner; -import junit.framework.Assert; import org.eehouse.android.xw4.loc.LocUtils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ExpiringDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ExpiringDelegate.java index 3987291eb..d1c21ca91 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ExpiringDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ExpiringDelegate.java @@ -29,7 +29,6 @@ import android.graphics.drawable.Drawable; import android.os.Handler; import android.view.View; -import junit.framework.Assert; import java.lang.ref.WeakReference; import java.util.ArrayList; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java index 81fa89ca2..9c5f1d1ee 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java @@ -45,7 +45,6 @@ import android.widget.TextView; import java.util.HashMap; import java.util.Map; -import junit.framework.Assert; import org.eehouse.android.xw4.DictLangCache.LangsArrayAdapter; import org.eehouse.android.xw4.DlgDelegate.Action; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameListItem.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameListItem.java index ae98e4fab..cb3203c48 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameListItem.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameListItem.java @@ -33,7 +33,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import junit.framework.Assert; import org.eehouse.android.xw4.jni.GameSummary; import org.eehouse.android.xw4.jni.JNIThread; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameLock.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameLock.java index 54b8e1643..85d66310b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameLock.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameLock.java @@ -20,7 +20,6 @@ package org.eehouse.android.xw4; -import junit.framework.Assert; import java.util.HashMap; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java index 2d9963ed5..ba3d807d5 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java @@ -31,7 +31,6 @@ import android.text.Html; import android.text.TextUtils; import android.view.Display; -import junit.framework.Assert; import org.eehouse.android.xw4.jni.CommonPrefs; import org.eehouse.android.xw4.jni.CommsAddrRec; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index 73a6e9395..bae29f46e 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -44,7 +44,6 @@ import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; -import junit.framework.Assert; import org.eehouse.android.xw4.DBUtils.GameChangeType; import org.eehouse.android.xw4.DBUtils.GameGroupInfo; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/HeaderWithExpander.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/HeaderWithExpander.java index fd32744d5..153d01776 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/HeaderWithExpander.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/HeaderWithExpander.java @@ -27,7 +27,6 @@ import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; -import junit.framework.Assert; import org.eehouse.android.xw4.loc.LocUtils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/HostDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/HostDelegate.java index e93665297..f69bd5927 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/HostDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/HostDelegate.java @@ -26,7 +26,6 @@ import android.content.Intent; import org.eehouse.android.xw4.DlgDelegate.Action; -import junit.framework.Assert; class HostDelegate extends DelegateBase { private static final String ACTION = "ACTION"; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java index a9ed0250e..0b15bedd7 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java @@ -31,7 +31,6 @@ import android.widget.Button; import java.util.ArrayList; -import junit.framework.Assert; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.ActionPair; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java index c536cec93..d5c060d06 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java @@ -42,7 +42,6 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; -import junit.framework.Assert; abstract class InviteDelegate extends ListDelegateBase implements View.OnClickListener, diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/LookupAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/LookupAlert.java index 45df88f55..f1ed332fb 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/LookupAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/LookupAlert.java @@ -26,7 +26,6 @@ import android.os.Bundle; import android.support.v4.app.DialogFragment; import java.io.Serializable; -import junit.framework.Assert; import org.eehouse.android.xw4.loc.LocUtils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/LookupAlertView.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/LookupAlertView.java index 3f48cba0d..e82b12322 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/LookupAlertView.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/LookupAlertView.java @@ -36,7 +36,6 @@ import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; -import junit.framework.Assert; import org.eehouse.android.xw4.loc.LocUtils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MainActivity.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MainActivity.java index d4142fc47..8ea9949f3 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MainActivity.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MainActivity.java @@ -35,7 +35,6 @@ import android.view.MenuItem; import android.view.View; import android.widget.LinearLayout; -import junit.framework.Assert; import java.lang.ref.WeakReference; import java.util.ArrayList; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiMsgSink.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiMsgSink.java index 0a08833e2..64197516c 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiMsgSink.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiMsgSink.java @@ -22,7 +22,6 @@ package org.eehouse.android.xw4; import android.content.Context; -import junit.framework.Assert; import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiService.java index 5aac018c5..91dbd8390 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiService.java @@ -26,7 +26,6 @@ import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.os.Bundle; -import junit.framework.Assert; import org.eehouse.android.xw4.loc.LocUtils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NagTurnReceiver.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NagTurnReceiver.java index ba4ea6d33..5327b6c90 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NagTurnReceiver.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NagTurnReceiver.java @@ -27,7 +27,6 @@ import android.content.Context; import android.content.Intent; import android.text.TextUtils; -import junit.framework.Assert; import org.eehouse.android.xw4.DBUtils.NeedsNagInfo; import org.eehouse.android.xw4.jni.GameSummary; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetLaunchInfo.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetLaunchInfo.java index ebc7a99f0..551a24cb5 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetLaunchInfo.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetLaunchInfo.java @@ -39,7 +39,6 @@ import java.util.Iterator; import org.json.JSONException; import org.json.JSONObject; -import junit.framework.Assert; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java index 101f52059..6c5ed36f5 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java @@ -29,7 +29,6 @@ import android.net.NetworkInfo; import android.os.Build; import android.os.Handler; -import junit.framework.Assert; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetUtils.java index acf6ac4be..1c07bf43b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetUtils.java @@ -23,7 +23,6 @@ package org.eehouse.android.xw4; import android.content.Context; import android.text.TextUtils; -import junit.framework.Assert; import org.json.JSONArray; import org.json.JSONException; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NotAgainAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NotAgainAlert.java index d12a0cd4e..6e90fb9b3 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NotAgainAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NotAgainAlert.java @@ -30,7 +30,6 @@ import android.support.v4.app.DialogFragment; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.ActionPair; -import junit.framework.Assert; import org.eehouse.android.xw4.loc.LocUtils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/OkOnlyAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/OkOnlyAlert.java index 3a74feacf..317b2cb6f 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/OkOnlyAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/OkOnlyAlert.java @@ -30,7 +30,6 @@ import android.support.v4.app.DialogFragment; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.ActionPair; -import junit.framework.Assert; import org.eehouse.android.xw4.loc.LocUtils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Perms23.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Perms23.java index 2610d5146..f8b3be7bf 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Perms23.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Perms23.java @@ -38,7 +38,6 @@ import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.loc.LocUtils; -import junit.framework.Assert; public class Perms23 { private static final String TAG = Perms23.class.getSimpleName(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsActivity.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsActivity.java index 8c9787c32..816943179 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsActivity.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsActivity.java @@ -27,7 +27,6 @@ import android.os.Bundle; import android.preference.PreferenceActivity; import android.support.v4.app.DialogFragment; -import junit.framework.Assert; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.ConfirmThenBuilder; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsDelegate.java index a64e9dcda..faef1f88b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsDelegate.java @@ -36,7 +36,6 @@ import android.preference.PreferenceScreen; import android.view.View; import android.widget.Button; -import junit.framework.Assert; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.loc.LocUtils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayInviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayInviteDelegate.java index f8b043aba..8d738b3c2 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayInviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayInviteDelegate.java @@ -52,7 +52,6 @@ import java.util.Set; import org.json.JSONArray; import org.json.JSONObject; -import junit.framework.Assert; import org.eehouse.android.xw4.DlgDelegate.Action; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java index ada0eeeb0..4934b75d5 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java @@ -27,7 +27,6 @@ import android.os.Build; import android.os.Handler; import android.text.TextUtils; -import junit.framework.Assert; import org.eehouse.android.xw4.GameUtils.BackMoveResult; import org.eehouse.android.xw4.MultiService.DictFetchOwner; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/SMSInviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/SMSInviteDelegate.java index e80006550..23942077a 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/SMSInviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/SMSInviteDelegate.java @@ -36,7 +36,6 @@ import android.view.View; import android.widget.Button; import android.widget.EditText; -import junit.framework.Assert; import org.eehouse.android.xw4.DBUtils.SentInvitesInfo; import org.eehouse.android.xw4.DlgDelegate.Action; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/SMSService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/SMSService.java index 49d26e588..610d1421a 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/SMSService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/SMSService.java @@ -34,7 +34,6 @@ import android.telephony.PhoneNumberUtils; import android.telephony.SmsManager; import android.telephony.TelephonyManager; -import junit.framework.Assert; import org.eehouse.android.xw4.MultiService.DictFetchOwner; import org.eehouse.android.xw4.MultiService.MultiEvent; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/StudyListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/StudyListDelegate.java index db51df1f4..bcf218584 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/StudyListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/StudyListDelegate.java @@ -36,7 +36,6 @@ import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Spinner; -import junit.framework.Assert; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.jni.GameSummary; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/TilePickAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/TilePickAlert.java index d855a22a1..a45e350df 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/TilePickAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/TilePickAlert.java @@ -31,7 +31,6 @@ import android.widget.Button; import java.io.Serializable; -import junit.framework.Assert; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/TilePickView.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/TilePickView.java index 4469176f5..6a9d4fc7d 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/TilePickView.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/TilePickView.java @@ -38,7 +38,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import junit.framework.Assert; public class TilePickView extends LinearLayout { private static final String TAG = TilePickView.class.getSimpleName(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Toolbar.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Toolbar.java index 4eded5deb..0ecefa929 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Toolbar.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Toolbar.java @@ -35,7 +35,6 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; -import junit.framework.Assert; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.HasDlgDelegate; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java index f80ff4018..848da6f3f 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java @@ -74,7 +74,6 @@ import java.util.Iterator; import java.util.List; import java.util.Random; -import junit.framework.Assert; import org.eehouse.android.xw4.Perms23.Perm; import org.eehouse.android.xw4.jni.CommonPrefs; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirInviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirInviteDelegate.java index a1d6343a6..6d39ffe53 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirInviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirInviteDelegate.java @@ -30,7 +30,6 @@ import android.widget.TextView; import java.util.Iterator; import java.util.Map; -import junit.framework.Assert; public class WiDirInviteDelegate extends InviteDelegate implements WiDirService.DevSetListener { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirService.java index e7695401e..600c03770 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirService.java @@ -69,7 +69,6 @@ import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.loc.LocUtils; -import junit.framework.Assert; public class WiDirService extends XWService { private static final String TAG = WiDirService.class.getSimpleName(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWActivity.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWActivity.java index 82a8dab89..df83b45fb 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWActivity.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWActivity.java @@ -40,7 +40,6 @@ import android.widget.ListView; import org.eehouse.android.xw4.DlgDelegate.Action; -import junit.framework.Assert; public class XWActivity extends FragmentActivity implements Delegator, DlgDelegate.DlgClickNotify { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java index cbbc2e1dc..441e3d67b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java @@ -35,7 +35,6 @@ import org.eehouse.android.xw4.jni.XwJNI; import java.util.UUID; -import junit.framework.Assert; import static android.arch.lifecycle.Lifecycle.Event.ON_ANY; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWConnAddrPreference.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWConnAddrPreference.java index de57f1bef..3c63c41a1 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWConnAddrPreference.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWConnAddrPreference.java @@ -27,7 +27,6 @@ import android.preference.DialogPreference; import android.util.AttributeSet; import android.view.View; -import junit.framework.Assert; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWDialogFragment.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWDialogFragment.java index 2ecd0bf7e..38eac8ea2 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWDialogFragment.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWDialogFragment.java @@ -30,7 +30,6 @@ import android.view.View; import java.util.HashMap; import java.util.Map; -import junit.framework.Assert; abstract class XWDialogFragment extends DialogFragment { private static final String TAG = XWDialogFragment.class.getSimpleName(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWExpListAdapter.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWExpListAdapter.java index 77fe2c807..b07b937ae 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWExpListAdapter.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWExpListAdapter.java @@ -23,7 +23,6 @@ package org.eehouse.android.xw4; import android.view.View; import android.view.ViewGroup; -import junit.framework.Assert; import java.util.Arrays; import java.util.HashMap; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWFragment.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWFragment.java index db4b076c7..7509d2fb5 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWFragment.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWFragment.java @@ -36,7 +36,6 @@ import android.widget.ListView; import java.util.HashSet; import java.util.Set; -import junit.framework.Assert; abstract class XWFragment extends Fragment implements Delegator { private static final String TAG = XWFragment.class.getSimpleName(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java index fafe5208e..3262b8fef 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java @@ -29,7 +29,6 @@ import android.text.TextUtils; import org.json.JSONException; import org.json.JSONObject; -import junit.framework.Assert; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWService.java index 62e680abf..524695feb 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWService.java @@ -25,7 +25,6 @@ import android.content.Context; import android.content.Intent; import android.os.IBinder; -import junit.framework.Assert; import org.eehouse.android.xw4.MultiService.DictFetchOwner; import org.eehouse.android.xw4.MultiService.MultiEvent; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java index 3701610d9..512500082 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java @@ -23,8 +23,7 @@ package org.eehouse.android.xw4.jni; import android.content.Context; import android.text.TextUtils; -import junit.framework.Assert; - +import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.BTService; import org.eehouse.android.xw4.GameUtils; import org.eehouse.android.xw4.Log; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CurGameInfo.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CurGameInfo.java index 4d9b2d8f1..ac898b2b5 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CurGameInfo.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CurGameInfo.java @@ -29,8 +29,8 @@ import java.util.HashSet; import java.util.Random; import org.json.JSONObject; -import junit.framework.Assert; +import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.BuildConfig; import org.eehouse.android.xw4.DictLangCache; import org.eehouse.android.xw4.DictUtils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/DUtilCtxt.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/DUtilCtxt.java index 8192636f7..ae13ba97d 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/DUtilCtxt.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/DUtilCtxt.java @@ -23,8 +23,7 @@ package org.eehouse.android.xw4.jni; import android.content.Context; import android.telephony.PhoneNumberUtils; -import junit.framework.Assert; - +import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.XWApp; import org.eehouse.android.xw4.DBUtils; import org.eehouse.android.xw4.DevID; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/GameSummary.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/GameSummary.java index 654661e79..2c7c43247 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/GameSummary.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/GameSummary.java @@ -28,8 +28,7 @@ import java.util.Arrays; import org.json.JSONObject; -import junit.framework.Assert; - +import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.BuildConfig; import org.eehouse.android.xw4.DBUtils; import org.eehouse.android.xw4.Log; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIThread.java index d6c9a6c37..91bc41ae8 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIThread.java @@ -26,8 +26,7 @@ import android.graphics.Bitmap; import android.os.Handler; import android.os.Message; -import junit.framework.Assert; - +import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.BuildConfig; import org.eehouse.android.xw4.CommsTransport; import org.eehouse.android.xw4.ConnStatusHandler; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIUtilsImpl.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIUtilsImpl.java index 79743be24..5d8c6a060 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIUtilsImpl.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIUtilsImpl.java @@ -22,8 +22,7 @@ package org.eehouse.android.xw4.jni; import android.content.Context; -import junit.framework.Assert; - +import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.DBUtils; import org.eehouse.android.xw4.XWApp; import org.eehouse.android.xw4.Log; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/LocalPlayer.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/LocalPlayer.java index 0a9109857..ca1106a5f 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/LocalPlayer.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/LocalPlayer.java @@ -25,8 +25,7 @@ import android.text.TextUtils; import java.io.Serializable; -import junit.framework.Assert; - +import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.BuildConfig; import org.eehouse.android.xw4.R; import org.eehouse.android.xw4.Utils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/UtilCtxtImpl.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/UtilCtxtImpl.java index 6b3883086..2a1c30043 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/UtilCtxtImpl.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/UtilCtxtImpl.java @@ -22,7 +22,6 @@ package org.eehouse.android.xw4.jni; import android.content.Context; -import junit.framework.Assert; import org.eehouse.android.xw4.Log; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java index 315b51c86..2b9f96110 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java @@ -24,8 +24,7 @@ import android.graphics.Rect; import java.util.Arrays; -import junit.framework.Assert; - +import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.Log; import org.eehouse.android.xw4.NetLaunchInfo; import org.eehouse.android.xw4.Utils; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/loc/LocUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/loc/LocUtils.java index af983d125..c63374251 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/loc/LocUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/loc/LocUtils.java @@ -42,8 +42,8 @@ import android.widget.Spinner; import android.widget.SpinnerAdapter; import android.widget.TextView; -import junit.framework.Assert; +import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.DBUtils; import org.eehouse.android.xw4.DbgUtils; import org.eehouse.android.xw4.Log; diff --git a/xwords4/android/app/src/xw4/java/org/eehouse/android/xw4/GCMIntentService.java b/xwords4/android/app/src/xw4/java/org/eehouse/android/xw4/GCMIntentService.java index 5069dea57..bc2f8e4f4 100644 --- a/xwords4/android/app/src/xw4/java/org/eehouse/android/xw4/GCMIntentService.java +++ b/xwords4/android/app/src/xw4/java/org/eehouse/android/xw4/GCMIntentService.java @@ -29,7 +29,6 @@ import com.google.android.gcm.GCMRegistrar; import org.json.JSONArray; -import junit.framework.Assert; public class GCMIntentService extends GCMBaseIntentService { private static final String TAG = GCMIntentService.class.getSimpleName(); diff --git a/xwords4/android/scripts/mk_xml.py b/xwords4/android/scripts/mk_xml.py index 706b0e9b0..b71e01542 100755 --- a/xwords4/android/scripts/mk_xml.py +++ b/xwords4/android/scripts/mk_xml.py @@ -95,8 +95,8 @@ def printStrings( pairs, outfile, target ): package org.eehouse.android.xw4.loc; import android.content.Context; -import junit.framework.Assert; +import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.R; import org.eehouse.android.xw4.Log; From ff51dd78309aef3e273f041466ce3b52847c1622 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 4 Dec 2018 05:10:05 -0800 Subject: [PATCH 026/145] remove assert Constructor is called from JNI code and so not on the UI thread. --- .../src/main/java/org/eehouse/android/xw4/NetStateCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java index 6c5ed36f5..373c88ce2 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java @@ -181,7 +181,7 @@ public class NetStateCache { public PvtBroadcastReceiver() { - DbgUtils.assertOnUIThread(); + // DbgUtils.assertOnUIThread(); // firing mHandler = new Handler(); mLastStateSent = s_netAvail; } From 4540f9c0778092b23add5ad7314ec8e10979bdd7 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 4 Dec 2018 05:18:29 -0800 Subject: [PATCH 027/145] change foreground-service notification text --- .../app/src/main/java/org/eehouse/android/xw4/BTService.java | 5 ++--- xwords4/android/app/src/main/res/values/strings.xml | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index fedfe3f87..1bc51167a 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -542,9 +542,8 @@ public class BTService extends XWService { m_notification = new NotificationCompat.Builder( this, Utils.getChannelId(this) ) .setSmallIcon( R.drawable.notify_btservice ) - .setContentTitle( BTService.class.getSimpleName() ) - .setContentText("listening for bluetooth messages...") - .setContentIntent(pendIntent) + .setContentText( getString(R.string.bkng_notify_text) ) + .setContentIntent( pendIntent ) .build(); } diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index 6ab747561..e5d84f35f 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -2028,6 +2028,7 @@ Enable background Bluetooth Always listen for Bluetooth messages + Accepting Bluetooth messages… Confirm your SMS plan From 9537100399f120b2404bd0c525b11737908bb22d Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 4 Dec 2018 06:17:47 -0800 Subject: [PATCH 028/145] btinvite dlg shows results of scan not all paired devs Moving toward a better BT invite experience: use BTService to scan for ourselves on all paired devices, and only allow selecting from among those on which we're running (and so likely to respond to an invitation.) --- .../eehouse/android/xw4/BTInviteDelegate.java | 22 ++-- .../org/eehouse/android/xw4/BTService.java | 120 +++--------------- .../app/src/main/res/layout/bt_buttons.xml | 9 +- .../app/src/main/res/values/strings.xml | 21 +-- 4 files changed, 42 insertions(+), 130 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java index 9a769cb8b..8ecd1a1ee 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java @@ -22,6 +22,7 @@ package org.eehouse.android.xw4; import android.app.Activity; import android.app.AlertDialog; +import android.app.ProgressDialog; import android.content.Intent; import android.os.Bundle; import android.view.View; @@ -35,12 +36,13 @@ import java.util.Iterator; import java.util.Set; public class BTInviteDelegate extends InviteDelegate { - private static final int[] BUTTONIDS = { R.id.button_add, + private static final String TAG = BTInviteDelegate.class.getSimpleName(); + private static final int[] BUTTONIDS = { R.id.button_scan, R.id.button_settings, - R.id.button_clear, }; private Activity m_activity; private TwoStringPair[] m_pairs; + private ProgressDialog m_progress; public static void launchForResult( Activity activity, int nMissing, SentInvitesInfo info, @@ -67,28 +69,25 @@ public class BTInviteDelegate extends InviteDelegate { @Override protected void init( Bundle savedInstanceState ) { - String msg = getString( R.string.bt_pick_addall_button ); - msg = getQuantityString( R.plurals.invite_bt_desc_fmt, m_nMissing, - m_nMissing, msg ); + String msg = getQuantityString( R.plurals.invite_bt_desc_fmt_2, m_nMissing, + m_nMissing ); super.init( msg, 0 ); addButtonBar( R.layout.bt_buttons, BUTTONIDS ); BTService.clearDevices( m_activity, null ); // will return names + + scan(); } @Override protected void onBarButtonClicked( int id ) { switch( id ) { - case R.id.button_add: + case R.id.button_scan: scan(); break; case R.id.button_settings: BTService.openBTSettings( m_activity ); break; - case R.id.button_clear: - removeSelected(); - clearChecked(); - break; } } @@ -101,6 +100,7 @@ public class BTInviteDelegate extends InviteDelegate { post( new Runnable() { public void run() { synchronized( BTInviteDelegate.this ) { + m_progress.cancel(); m_pairs = null; if ( 0 < args.length ) { @@ -143,6 +143,8 @@ public class BTInviteDelegate extends InviteDelegate { { int count = BTService.getPairedCount( m_activity ); if ( 0 < count ) { + String msg = getQuantityString( R.plurals.bt_scan_progress_fmt, count, count ); + m_progress = ProgressDialog.show( m_activity, msg, null, true, true ); BTService.scan( m_activity ); } else { makeConfirmThenBuilder( R.string.bt_no_devs, diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index 1bc51167a..b6e384799 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -183,7 +183,6 @@ public class BTService extends XWService { } private BluetoothAdapter m_adapter; - private Set m_addrs; private BTMsgSink m_btMsgSink; private BTListenerThread m_listener; private BTSenderThread m_sender; @@ -415,7 +414,6 @@ public class BTService extends XWService { m_adapter = adapter; Log.i( TAG, "onCreate(); bt name = %s; bt addr = %s", adapter.getName(), adapter.getAddress() ); - initAddrs(); startListener(); startSender(); } else { @@ -456,8 +454,6 @@ public class BTService extends XWService { case CLEAR: String[] btAddrs = intent.getStringArrayExtra( CLEAR_KEY ); - clearDevs( btAddrs ); - sendNames(); break; case SCAN: m_sender.add( new BTQueueElem( BTCmd.SCAN ) ); @@ -572,7 +568,6 @@ public class BTService extends XWService { while ( null != m_serverSocket && m_adapter.isEnabled() ) { try { BluetoothSocket socket = m_serverSocket.accept(); // blocks - addAddr( socket ); DataInputStream inStream = new DataInputStream( socket.getInputStream() ); @@ -678,8 +673,6 @@ public class BTService extends XWService { } BluetoothDevice host = socket.getRemoteDevice(); - addAddr( host ); - result = makeOrNotify( nli, host.getName(), host.getAddress() ); DataOutputStream os = new DataOutputStream( socket.getOutputStream() ); @@ -699,7 +692,6 @@ public class BTService extends XWService { byte[] buffer = new byte[dis.readShort()]; dis.readFully( buffer ); BluetoothDevice host = socket.getRemoteDevice(); - addAddr( host ); CommsAddrRec addr = new CommsAddrRec( host.getName(), host.getAddress() ); @@ -731,35 +723,6 @@ public class BTService extends XWService { } // receiveMessage } // class BTListenerThread - private void addAddr( BluetoothSocket socket ) - { - addAddr( socket.getRemoteDevice() ); - } - - private void addAddr( BluetoothDevice dev ) - { - addAddr( dev.getAddress(), dev.getName() ); - } - - private void addAddr( String btAddr, String btName ) - { - boolean save = false; - synchronized( m_addrs ) { - save = !m_addrs.contains( btAddr ); - if ( save ) { - m_addrs.add( btAddr ); - } - } - if ( save ) { - saveAddrs(); - } - } - - private boolean haveAddr( String btAddr ) - { - return m_addrs.contains( btAddr ); - } - private static Map s_namesToAddrs; private static String getSafeAddr( CommsAddrRec addr ) { @@ -786,18 +749,6 @@ public class BTService extends XWService { return btAddr; } - private void clearDevs( String[] btAddrs ) - { - if ( null != btAddrs ) { - synchronized( m_addrs ) { - for ( String btAddr : btAddrs ) { - m_addrs.remove( btAddr ); - } - } - } - saveAddrs(); - } - private class BTSenderThread extends Thread { private LinkedBlockingQueue m_queue; private HashMap > m_resends; @@ -836,15 +787,15 @@ public class BTService extends XWService { switch( elem.m_cmd ) { case PING: if ( null == elem.m_btAddr ) { - sendPings( MultiEvent.HOST_PONGED ); + sendPings( MultiEvent.HOST_PONGED, null ); } else { sendPing( elem.m_btAddr, elem.m_gameID ); } break; case SCAN: - addAllToNames(); - sendNames(); - saveAddrs(); + Set devs = new HashSet<>(); + sendPings( null, devs ); + sendNames( devs ); break; case INVITE: sendInvite( elem ); @@ -870,18 +821,17 @@ public class BTService extends XWService { } } // run - private void sendPings( MultiEvent event ) + private void sendPings( MultiEvent event, Set addrs ) { Set pairedDevs = m_adapter.getBondedDevices(); // DbgUtils.logf( "ping: got %d paired devices", pairedDevs.size() ); for ( BluetoothDevice dev : pairedDevs ) { String btAddr = dev.getAddress(); - if ( haveAddr( btAddr ) ) { - continue; - } if ( sendPing( dev, 0 ) ) { // did we get a reply? - addAddr( dev ); + if ( null != addrs ) { + addrs.add( dev ); + } if ( null != event ) { postEvent( event, dev.getName() ); } @@ -927,6 +877,7 @@ public class BTService extends XWService { } updateStatusOut( sendWorking ); updateStatusIn( receiveWorking ); + Log.d( TAG, "sendPing(%s) => %b", dev, gotReply ); return gotReply; } // sendPing @@ -1130,60 +1081,21 @@ public class BTService extends XWService { } return found; } - } // class BTSenderThread - private void addAllToNames() + private void sendNames( Set devs ) { - Set pairedDevs = m_adapter.getBondedDevices(); - synchronized( m_addrs ) { - for ( BluetoothDevice dev : pairedDevs ) { - int clazz = dev.getBluetoothClass().getMajorDeviceClass(); - if ( Major.PHONE == clazz - || (XWApp.BT_SCAN_COMPUTERS && Major.COMPUTER == clazz) ) { - m_addrs.add( dev.getAddress() ); - } - } - } - } - - private void sendNames() - { - String[] btAddrs = getAddrs(); - int size = btAddrs.length; - String[] btNames = new String[size]; - for ( int ii = 0; ii < size; ++ii ) { + String[] btNames = new String[devs.size()]; + String[] btAddrs = new String[devs.size()]; + int ii = 0; + for ( BluetoothDevice dev : devs ) { + btAddrs[ii] = dev.getAddress(); btNames[ii] = nameForAddr( m_adapter, btAddrs[ii] ); + ++ii; } postEvent( MultiEvent.SCAN_DONE, (Object)btAddrs, (Object)btNames ); } - private void initAddrs() - { - m_addrs = new HashSet(); - - String[] addrs = XWPrefs.getBTAddresses( this ); - if ( null != addrs ) { - for ( String btAddr : addrs ) { - m_addrs.add( btAddr ); - } - } - } - - private String[] getAddrs() - { - String[] addrs; - synchronized( m_addrs ) { - addrs = m_addrs.toArray( new String[m_addrs.size()] ); - } - return addrs; - } - - private void saveAddrs() - { - XWPrefs.setBTAddresses( this, getAddrs() ); - } - private void startListener() { m_btMsgSink = new BTMsgSink(); diff --git a/xwords4/android/app/src/main/res/layout/bt_buttons.xml b/xwords4/android/app/src/main/res/layout/bt_buttons.xml index ea287c312..df6e78e69 100644 --- a/xwords4/android/app/src/main/res/layout/bt_buttons.xml +++ b/xwords4/android/app/src/main/res/layout/bt_buttons.xml @@ -5,8 +5,8 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" > -