mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-23 07:27:22 +01:00
remove debug-only warnings about relay stall
Yeah it stalls. That's why MQTT and why BT doesn't use Service any more.
This commit is contained in:
parent
ddd5f7b978
commit
178042159b
6 changed files with 2 additions and 211 deletions
|
@ -39,7 +39,6 @@ public class Channels {
|
|||
// HIGH seems to be required for sound
|
||||
,GAME_EVENT( R.string.gameevent_channel_expl,
|
||||
NotificationManager.IMPORTANCE_HIGH )
|
||||
,SERVICE_STALL( R.string.servicestall_channel_expl )
|
||||
,DUP_TIMER_RUNNING( R.string.dup_timer_expl )
|
||||
,DUP_PAUSED( R.string.dup_paused_expl )
|
||||
;
|
||||
|
|
|
@ -354,39 +354,6 @@ public class Utils {
|
|||
return pi;
|
||||
}
|
||||
|
||||
private static final String KEY_LAST_STALL_NOT = TAG + ".last_stall_note";
|
||||
private static final long MIN_STALL_NOTE_INTERVAL_MS = 1000 * 60 * 30;
|
||||
public static void showStallNotification( Context context, String typ,
|
||||
long ageMS )
|
||||
{
|
||||
String body = LocUtils.getString( context, R.string.notify_stall_body_fmt,
|
||||
typ, (ageMS + 500) / 1000,
|
||||
MIN_STALL_NOTE_INTERVAL_MS / (1000 * 60));
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
long lastStallNotify = DBUtils.getLongFor( context, KEY_LAST_STALL_NOT, 0 );
|
||||
if ( now - lastStallNotify > MIN_STALL_NOTE_INTERVAL_MS ) {
|
||||
String title = LocUtils.getString( context, R.string.notify_stall_title );
|
||||
Intent intent = GamesListDelegate
|
||||
.makeAlertWithEmailIntent( context, body );
|
||||
postNotification( context, intent, title, body,
|
||||
R.string.notify_stall_title,
|
||||
Channels.ID.SERVICE_STALL, false, null, 0 );
|
||||
DBUtils.setLongFor( context, KEY_LAST_STALL_NOT, now );
|
||||
} else {
|
||||
Log.e( TAG, "stalled, but too recent for notification: %s",
|
||||
body );
|
||||
}
|
||||
}
|
||||
|
||||
// If the OS starts delivering Intents before the user notices the
|
||||
// notification, remove it. PENDING: should I replace it with something
|
||||
// that tells how long the stall was?
|
||||
public static void clearStallNotification( Context context, long age )
|
||||
{
|
||||
cancelNotification( context, R.string.notify_stall_title );
|
||||
}
|
||||
|
||||
public static void cancelNotification( Context context, Channels.ID channel,
|
||||
long rowid )
|
||||
{
|
||||
|
|
|
@ -22,14 +22,9 @@ package org.eehouse.android.xw4;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import androidx.core.app.JobIntentService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
||||
|
@ -62,7 +57,6 @@ abstract class XWJIService extends JobIntentService {
|
|||
{
|
||||
long timestamp = getTimestamp(intent);
|
||||
long ageMS = System.currentTimeMillis() - timestamp;
|
||||
forget( this, getClass(), intent, ageMS );
|
||||
|
||||
XWJICmds cmd = cmdFrom( intent );
|
||||
if ( LOG_PACKETS ) {
|
||||
|
@ -76,9 +70,7 @@ abstract class XWJIService extends JobIntentService {
|
|||
|
||||
protected static void enqueueWork( Context context, Class clazz, Intent intent )
|
||||
{
|
||||
remember( context, clazz, intent );
|
||||
enqueueWork( context, clazz, sJobIDs.get(clazz), intent );
|
||||
checkForStall( context, clazz );
|
||||
}
|
||||
|
||||
static XWJICmds cmdFrom( Intent intent, XWJICmds[] values )
|
||||
|
@ -105,154 +97,4 @@ abstract class XWJIService extends JobIntentService {
|
|||
.putExtra( TIMESTAMP, System.currentTimeMillis() );
|
||||
return intent;
|
||||
}
|
||||
|
||||
private static Map<String, List<Intent>> sPendingIntents = new HashMap<>();
|
||||
|
||||
private static void remember( Context context, Class clazz, Intent intent )
|
||||
{
|
||||
if ( stallCheckEnabled( context ) ) {
|
||||
String name = clazz.getSimpleName();
|
||||
synchronized ( sPendingIntents ) {
|
||||
if ( !sPendingIntents.containsKey( name )) {
|
||||
sPendingIntents.put( name, new ArrayList<Intent>() );
|
||||
}
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final long AGE_THRESHOLD_MS = 1000 * 60; // one minute to start
|
||||
private static void checkForStall( Context context, Class clazz )
|
||||
{
|
||||
if ( stallCheckEnabled( context ) ) {
|
||||
long now = System.currentTimeMillis();
|
||||
long maxAge = 0;
|
||||
String maxName = null;
|
||||
synchronized ( sPendingIntents ) {
|
||||
for ( String simpleName : sPendingIntents.keySet() ) {
|
||||
List<Intent> 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;
|
||||
maxName = simpleName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( maxAge > AGE_THRESHOLD_MS ) {
|
||||
// ConnStatusHandler.noteStall( sTypes.get( clazz ), maxAge );
|
||||
Utils.showStallNotification( context, maxName, maxAge );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Called when an intent is successfully delivered
|
||||
private static void forget( Context context, Class clazz,
|
||||
Intent intent, long ageMS )
|
||||
{
|
||||
if ( stallCheckEnabled( context ) ) {
|
||||
String name = clazz.getSimpleName();
|
||||
synchronized ( sPendingIntents ) {
|
||||
String found = null;
|
||||
if ( sPendingIntents.containsKey( name ) ) {
|
||||
List<Intent> intents = sPendingIntents.get( name );
|
||||
for (Iterator<Intent> 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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConnStatusHandler.noteIntentHandled( context, sTypes.get( clazz ), ageMS );
|
||||
Utils.clearStallNotification( context, ageMS );
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
if ( equal ) {
|
||||
Bundle bundle1 = intent1.getExtras();
|
||||
equal = null != bundle1;
|
||||
if ( equal ) {
|
||||
Bundle bundle2 = intent2.getExtras();
|
||||
equal = null != bundle2 && bundle1.size() == bundle2.size();
|
||||
if ( equal ) {
|
||||
for ( final String key : bundle1.keySet()) {
|
||||
if ( ! bundle2.containsKey( key ) ) {
|
||||
equal = false;
|
||||
break;
|
||||
}
|
||||
|
||||
Object obj1 = bundle1.get( key );
|
||||
Object obj2 = bundle2.get( key );
|
||||
if ( obj1 == obj2 ) { // catches case where both null
|
||||
continue;
|
||||
} else if ( obj1 == null || obj2 == null ) {
|
||||
equal = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( obj1.getClass() != obj2.getClass() ) {
|
||||
equal = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( obj1 instanceof byte[] ) {
|
||||
equal = Arrays.equals( (byte[])obj1, (byte[])obj2 );
|
||||
} else if ( obj1 instanceof String[] ) {
|
||||
equal = Arrays.equals( (String[])obj1, (String[])obj2 );
|
||||
} else {
|
||||
if ( BuildConfig.DEBUG ) {
|
||||
if ( obj1 instanceof Long
|
||||
|| obj1 instanceof String
|
||||
|| obj1 instanceof Boolean
|
||||
|| obj1 instanceof Integer ) {
|
||||
// expected class; log nothing
|
||||
} else {
|
||||
Log.d( TAG, "areSame: using default for class %s",
|
||||
obj1.getClass().getSimpleName() );
|
||||
}
|
||||
}
|
||||
equal = obj1.equals( obj2 );
|
||||
}
|
||||
if ( ! equal ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return equal;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,6 @@
|
|||
<string name="key_notify_vibrate">key_notify_vibrate</string>
|
||||
<string name="key_enable_nbs">key_enable_nbs</string>
|
||||
<string name="key_enable_p2p">key_enable_p2p</string>
|
||||
<string name="key_enable_stallnotify">key_enable_stallnotify</string>
|
||||
<string name="key_prefs_defaults">key_prefs_defaults</string>
|
||||
<string name="key_network_behavior">key_network_behavior</string>
|
||||
<string name="key_keep_screenon">key_keep_screenon</string>
|
||||
|
|
|
@ -2473,24 +2473,13 @@
|
|||
<string name="nbsproxy_channel_expl">Alerts about NBSProxy</string>
|
||||
<!-- Explanation in settings for traditional move-arrived notification -->
|
||||
<string name="gameevent_channel_expl">In-game events</string>
|
||||
<!-- Notification that the OS isn't scheduling background services -->
|
||||
<string name="servicestall_channel_expl">Stalled messaging alerts</string>
|
||||
<string name="not_again_emptybtscan">If a scan doesn’t find the device you expect:\n
|
||||
• First, just Rescan\n
|
||||
• Make sure Bluetooth is enabled on the other device\n
|
||||
• Launch CrossWords on the other device\n
|
||||
• If all else fails, reboot this device\n
|
||||
</string>
|
||||
<string name="title_enable_stallnotify">Show stalled network notification</string>
|
||||
<string name="summary_enable_stallnotify">Notify when Android’s
|
||||
slow to process outgoing invitations and moves</string>
|
||||
<string name="notify_stall_title">Message sending is stalled</string>
|
||||
<string name="notify_stall_body_fmt">%1$s (and others?) could not send outbound messages
|
||||
for %2$d seconds.
|
||||
\n
|
||||
\nIf it happens again, e-mail the developer logs and info about your device.
|
||||
\n
|
||||
\nThis message will be seen at most once every %3$d minutes.</string>
|
||||
</string>
|
||||
|
||||
<string name="sms_banned_ok_only">The Google Play version of CrossWords no longer supports invitations or play via data SMS.</string>
|
||||
<string name="button_more_info">Read more</string>
|
||||
<string name="banned_nbs_perms">This game is set up to communicate via data SMS, but apps from the Google Play Store are no longer allowed to do so (with rare exceptions). You can still open the game, but it may not be able to send or receive moves.
|
||||
|
|
|
@ -341,11 +341,6 @@
|
|||
android:summary="@string/summary_enable_p2p"
|
||||
android:defaultValue="false"
|
||||
/>
|
||||
<CheckBoxPreference android:key="@string/key_enable_stallnotify"
|
||||
android:title="@string/title_enable_stallnotify"
|
||||
android:summary="@string/summary_enable_stallnotify"
|
||||
android:defaultValue="@bool/DEBUG"
|
||||
/>
|
||||
|
||||
<PreferenceScreen android:title="@string/network_advanced_title"
|
||||
android:summary="@string/network_advanced_summary"
|
||||
|
|
Loading…
Add table
Reference in a new issue