mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-09 05:24:44 +01:00
show the stalled-service alert based on pref
Allow users to turn the notification on; otherwise skip it. And set the default on/off based on DEBUG type of build.
This commit is contained in:
parent
b5714fadf8
commit
a7da0e33bb
5 changed files with 72 additions and 55 deletions
|
@ -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) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String, List<Intent>> 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<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 );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<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;
|
||||
if ( stallCheckEnabled( context ) ) {
|
||||
long now = System.currentTimeMillis();
|
||||
long maxAge = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<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 ( 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 );
|
||||
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 );
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
<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_network_behavior">key_network_behavior</string>
|
||||
<string name="key_keep_screenon">key_keep_screenon</string>
|
||||
<string name="key_thumbsize">key_thumbsize3</string>
|
||||
|
|
|
@ -2805,6 +2805,10 @@
|
|||
• 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">Though it normally takes less
|
||||
|
|
|
@ -340,6 +340,11 @@
|
|||
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…
Reference in a new issue