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 68d650d53..c677b06a4 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
@@ -291,16 +291,16 @@ public class Utils {
}
private static final String KEY_LAST_STALL_NOT = TAG + ".last_stall_note";
- private static final long MIN_STALL_NOT_INTERVAL_MS = 1000 * 60 * 30;
+ private static final long MIN_STALL_NOTE_INTERVAL_MS = 1000 * 60 * 30;
public static void showStallNotification( Context context, long ageMS )
{
long now = System.currentTimeMillis();
long lastStallNotify = DBUtils.getLongFor( context, KEY_LAST_STALL_NOT, 0 );
- if ( now - lastStallNotify > MIN_STALL_NOT_INTERVAL_MS ) {
+ if ( now - lastStallNotify > MIN_STALL_NOTE_INTERVAL_MS ) {
String title = LocUtils.getString( context, R.string.notify_stall_title );
String body = LocUtils.getString( context, R.string.notify_stall_body_fmt,
(ageMS + 500) / 1000,
- MIN_STALL_NOT_INTERVAL_MS / (1000 * 60));
+ MIN_STALL_NOTE_INTERVAL_MS / (1000 * 60));
String channelID = Channels.getChannelID( context,
Channels.ID.SERVICE_STALL );
@@ -309,9 +309,6 @@ public class Utils {
postNotification( context, intent, title, body,
R.string.notify_stall_title, channelID );
DBUtils.setLongFor( context, KEY_LAST_STALL_NOT, now );
- } else {
- // Log.d( TAG, "showStallNotification(): not posting for another %d ms",
- // MIN_STALL_NOT_INTERVAL_MS - (now - lastStallNotify) );
}
}
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWJIService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWJIService.java
index bb429c89f..927deeb3f 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWJIService.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWJIService.java
@@ -57,7 +57,7 @@ abstract class XWJIService extends JobIntentService {
@Override
public final void onHandleWork( Intent intent )
{
- forget( getClass(), intent );
+ forget( this, getClass(), intent );
long timestamp = getTimestamp(intent);
XWJICmds cmd = cmdFrom( intent );
@@ -73,7 +73,7 @@ abstract class XWJIService extends JobIntentService {
protected static void enqueueWork( Context context, Class clazz, Intent intent )
{
- remember( clazz, intent );
+ remember( context, clazz, intent );
enqueueWork( context, clazz, sJobIDs.get(clazz), intent );
checkForStall( context );
}
@@ -105,17 +105,19 @@ abstract class XWJIService extends JobIntentService {
private static Map> sPendingIntents = new HashMap<>();
- private static void remember( Class clazz, Intent intent )
+ private static void remember( Context context, Class clazz, Intent intent )
{
- String name = clazz.getSimpleName();
- synchronized ( sPendingIntents ) {
- if ( !sPendingIntents.containsKey( name )) {
- sPendingIntents.put( name, new ArrayList() );
- }
- sPendingIntents.get(name).add( intent );
- if ( LOG_INTENT_COUNTS ) {
- Log.d( TAG, "remember(): now have %d intents for class %s",
- sPendingIntents.get(name).size(), name );
+ if ( stallCheckEnabled( context ) ) {
+ String name = clazz.getSimpleName();
+ synchronized ( sPendingIntents ) {
+ if ( !sPendingIntents.containsKey( name )) {
+ sPendingIntents.put( name, new ArrayList() );
+ }
+ sPendingIntents.get(name).add( intent );
+ if ( LOG_INTENT_COUNTS ) {
+ Log.d( TAG, "remember(): now have %d intents for class %s",
+ sPendingIntents.get(name).size(), name );
+ }
}
}
}
@@ -123,59 +125,67 @@ abstract class XWJIService extends JobIntentService {
private static final long AGE_THRESHOLD_MS = 1000 * 60; // one minute to start
private static void checkForStall( Context context )
{
- long now = System.currentTimeMillis();
- long maxAge = 0;
- synchronized ( sPendingIntents ) {
- for ( String simpleName : sPendingIntents.keySet() ) {
- List intents = sPendingIntents.get( simpleName );
- if ( 1 <= intents.size() ) {
- Intent intent = intents.get(0);
- long timestamp = intent.getLongExtra( TIMESTAMP, -1 );
- long age = now - timestamp;
- if ( age > maxAge ) {
- maxAge = age;
+ if ( stallCheckEnabled( context ) ) {
+ long now = System.currentTimeMillis();
+ long maxAge = 0;
+ synchronized ( sPendingIntents ) {
+ for ( String simpleName : sPendingIntents.keySet() ) {
+ List intents = sPendingIntents.get( simpleName );
+ if ( 1 <= intents.size() ) {
+ Intent intent = intents.get(0);
+ long timestamp = intent.getLongExtra( TIMESTAMP, -1 );
+ long age = now - timestamp;
+ if ( age > maxAge ) {
+ maxAge = age;
+ }
}
}
}
- }
- if ( maxAge > AGE_THRESHOLD_MS ) {
- Utils.showStallNotification( context, maxAge );
+ if ( maxAge > AGE_THRESHOLD_MS ) {
+ Utils.showStallNotification( context, maxAge );
+ }
}
}
- private static void forget( Class clazz, Intent intent )
+ private static void forget( Context context, Class clazz, Intent intent )
{
- String name = clazz.getSimpleName();
- synchronized ( sPendingIntents ) {
- String found = null;
- if ( sPendingIntents.containsKey( name ) ) {
- List intents = sPendingIntents.get( name );
- for (Iterator iter = intents.iterator();
- iter.hasNext(); ) {
- Intent candidate = iter.next();
- if ( areSame( candidate, intent ) ) {
- found = name;
- iter.remove();
- break;
- } else {
- Log.d( TAG, "skipping intent: %s",
- DbgUtils.extrasToString( candidate ) );
+ if ( stallCheckEnabled( context ) ) {
+ String name = clazz.getSimpleName();
+ synchronized ( sPendingIntents ) {
+ String found = null;
+ if ( sPendingIntents.containsKey( name ) ) {
+ List intents = sPendingIntents.get( name );
+ for (Iterator iter = intents.iterator();
+ iter.hasNext(); ) {
+ Intent candidate = iter.next();
+ if ( areSame( candidate, intent ) ) {
+ found = name;
+ iter.remove();
+ break;
+ } else {
+ Log.d( TAG, "skipping intent: %s",
+ DbgUtils.extrasToString( candidate ) );
+ }
}
- }
- if ( found != null ) {
- if ( LOG_INTENT_COUNTS ) {
- Log.d( TAG, "forget(): now have %d intents for class %s",
- sPendingIntents.get(found).size(), found );
+ if ( found != null ) {
+ if ( LOG_INTENT_COUNTS ) {
+ Log.d( TAG, "forget(): now have %d intents for class %s",
+ sPendingIntents.get(found).size(), found );
+ }
}
- } else {
- Log.e( TAG, "intent %s not found", intent );
}
}
}
}
+ private static boolean stallCheckEnabled( Context context )
+ {
+ return XWPrefs.getPrefsBoolean( context, R.string.key_enable_stallnotify,
+ BuildConfig.DEBUG );
+ }
+
private static boolean areSame( Intent intent1, Intent intent2 )
{
boolean equal = intent1.filterEquals( intent2 );
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 e166a7f0c..d30b0b4bc 100644
--- a/xwords4/android/app/src/main/res/values/common_rsrc.xml
+++ b/xwords4/android/app/src/main/res/values/common_rsrc.xml
@@ -64,6 +64,7 @@
key_notify_vibrate
key_enable_nbs
key_enable_p2p
+ key_enable_stallnotify
key_network_behavior
key_keep_screenon
key_thumbsize3
diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml
index cf3dd8744..ffcefc008 100644
--- a/xwords4/android/app/src/main/res/values/strings.xml
+++ b/xwords4/android/app/src/main/res/values/strings.xml
@@ -2805,6 +2805,10 @@
• If all else fails, reboot this device\n
+ Show stalled network notification
+ Notify when Android\'s
+ slow to process outgoing invitations and moves
+
Message sending is stalled
Though it normally takes less
diff --git a/xwords4/android/app/src/main/res/xml/xwprefs.xml b/xwords4/android/app/src/main/res/xml/xwprefs.xml
index 1611bd3b7..ecefc9781 100644
--- a/xwords4/android/app/src/main/res/xml/xwprefs.xml
+++ b/xwords4/android/app/src/main/res/xml/xwprefs.xml
@@ -340,6 +340,11 @@
android:summary="@string/summary_enable_p2p"
android:defaultValue="false"
/>
+