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 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 )
|
public static void showStallNotification( Context context, long ageMS )
|
||||||
{
|
{
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
long lastStallNotify = DBUtils.getLongFor( context, KEY_LAST_STALL_NOT, 0 );
|
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 title = LocUtils.getString( context, R.string.notify_stall_title );
|
||||||
String body = LocUtils.getString( context, R.string.notify_stall_body_fmt,
|
String body = LocUtils.getString( context, R.string.notify_stall_body_fmt,
|
||||||
(ageMS + 500) / 1000,
|
(ageMS + 500) / 1000,
|
||||||
MIN_STALL_NOT_INTERVAL_MS / (1000 * 60));
|
MIN_STALL_NOTE_INTERVAL_MS / (1000 * 60));
|
||||||
String channelID = Channels.getChannelID( context,
|
String channelID = Channels.getChannelID( context,
|
||||||
Channels.ID.SERVICE_STALL );
|
Channels.ID.SERVICE_STALL );
|
||||||
|
|
||||||
|
@ -309,9 +309,6 @@ public class Utils {
|
||||||
postNotification( context, intent, title, body,
|
postNotification( context, intent, title, body,
|
||||||
R.string.notify_stall_title, channelID );
|
R.string.notify_stall_title, channelID );
|
||||||
DBUtils.setLongFor( context, KEY_LAST_STALL_NOT, now );
|
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
|
@Override
|
||||||
public final void onHandleWork( Intent intent )
|
public final void onHandleWork( Intent intent )
|
||||||
{
|
{
|
||||||
forget( getClass(), intent );
|
forget( this, getClass(), intent );
|
||||||
|
|
||||||
long timestamp = getTimestamp(intent);
|
long timestamp = getTimestamp(intent);
|
||||||
XWJICmds cmd = cmdFrom( intent );
|
XWJICmds cmd = cmdFrom( intent );
|
||||||
|
@ -73,7 +73,7 @@ abstract class XWJIService extends JobIntentService {
|
||||||
|
|
||||||
protected static void enqueueWork( Context context, Class clazz, Intent intent )
|
protected static void enqueueWork( Context context, Class clazz, Intent intent )
|
||||||
{
|
{
|
||||||
remember( clazz, intent );
|
remember( context, clazz, intent );
|
||||||
enqueueWork( context, clazz, sJobIDs.get(clazz), intent );
|
enqueueWork( context, clazz, sJobIDs.get(clazz), intent );
|
||||||
checkForStall( context );
|
checkForStall( context );
|
||||||
}
|
}
|
||||||
|
@ -105,17 +105,19 @@ abstract class XWJIService extends JobIntentService {
|
||||||
|
|
||||||
private static Map<String, List<Intent>> sPendingIntents = new HashMap<>();
|
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();
|
if ( stallCheckEnabled( context ) ) {
|
||||||
synchronized ( sPendingIntents ) {
|
String name = clazz.getSimpleName();
|
||||||
if ( !sPendingIntents.containsKey( name )) {
|
synchronized ( sPendingIntents ) {
|
||||||
sPendingIntents.put( name, new ArrayList<Intent>() );
|
if ( !sPendingIntents.containsKey( name )) {
|
||||||
}
|
sPendingIntents.put( name, new ArrayList<Intent>() );
|
||||||
sPendingIntents.get(name).add( intent );
|
}
|
||||||
if ( LOG_INTENT_COUNTS ) {
|
sPendingIntents.get(name).add( intent );
|
||||||
Log.d( TAG, "remember(): now have %d intents for class %s",
|
if ( LOG_INTENT_COUNTS ) {
|
||||||
sPendingIntents.get(name).size(), name );
|
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 final long AGE_THRESHOLD_MS = 1000 * 60; // one minute to start
|
||||||
private static void checkForStall( Context context )
|
private static void checkForStall( Context context )
|
||||||
{
|
{
|
||||||
long now = System.currentTimeMillis();
|
if ( stallCheckEnabled( context ) ) {
|
||||||
long maxAge = 0;
|
long now = System.currentTimeMillis();
|
||||||
synchronized ( sPendingIntents ) {
|
long maxAge = 0;
|
||||||
for ( String simpleName : sPendingIntents.keySet() ) {
|
synchronized ( sPendingIntents ) {
|
||||||
List<Intent> intents = sPendingIntents.get( simpleName );
|
for ( String simpleName : sPendingIntents.keySet() ) {
|
||||||
if ( 1 <= intents.size() ) {
|
List<Intent> intents = sPendingIntents.get( simpleName );
|
||||||
Intent intent = intents.get(0);
|
if ( 1 <= intents.size() ) {
|
||||||
long timestamp = intent.getLongExtra( TIMESTAMP, -1 );
|
Intent intent = intents.get(0);
|
||||||
long age = now - timestamp;
|
long timestamp = intent.getLongExtra( TIMESTAMP, -1 );
|
||||||
if ( age > maxAge ) {
|
long age = now - timestamp;
|
||||||
maxAge = age;
|
if ( age > maxAge ) {
|
||||||
|
maxAge = age;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( maxAge > AGE_THRESHOLD_MS ) {
|
if ( maxAge > AGE_THRESHOLD_MS ) {
|
||||||
Utils.showStallNotification( context, maxAge );
|
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();
|
if ( stallCheckEnabled( context ) ) {
|
||||||
synchronized ( sPendingIntents ) {
|
String name = clazz.getSimpleName();
|
||||||
String found = null;
|
synchronized ( sPendingIntents ) {
|
||||||
if ( sPendingIntents.containsKey( name ) ) {
|
String found = null;
|
||||||
List<Intent> intents = sPendingIntents.get( name );
|
if ( sPendingIntents.containsKey( name ) ) {
|
||||||
for (Iterator<Intent> iter = intents.iterator();
|
List<Intent> intents = sPendingIntents.get( name );
|
||||||
iter.hasNext(); ) {
|
for (Iterator<Intent> iter = intents.iterator();
|
||||||
Intent candidate = iter.next();
|
iter.hasNext(); ) {
|
||||||
if ( areSame( candidate, intent ) ) {
|
Intent candidate = iter.next();
|
||||||
found = name;
|
if ( areSame( candidate, intent ) ) {
|
||||||
iter.remove();
|
found = name;
|
||||||
break;
|
iter.remove();
|
||||||
} else {
|
break;
|
||||||
Log.d( TAG, "skipping intent: %s",
|
} else {
|
||||||
DbgUtils.extrasToString( candidate ) );
|
Log.d( TAG, "skipping intent: %s",
|
||||||
|
DbgUtils.extrasToString( candidate ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( found != null ) {
|
if ( found != null ) {
|
||||||
if ( LOG_INTENT_COUNTS ) {
|
if ( LOG_INTENT_COUNTS ) {
|
||||||
Log.d( TAG, "forget(): now have %d intents for class %s",
|
Log.d( TAG, "forget(): now have %d intents for class %s",
|
||||||
sPendingIntents.get(found).size(), found );
|
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 )
|
private static boolean areSame( Intent intent1, Intent intent2 )
|
||||||
{
|
{
|
||||||
boolean equal = intent1.filterEquals( intent2 );
|
boolean equal = intent1.filterEquals( intent2 );
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
<string name="key_notify_vibrate">key_notify_vibrate</string>
|
<string name="key_notify_vibrate">key_notify_vibrate</string>
|
||||||
<string name="key_enable_nbs">key_enable_nbs</string>
|
<string name="key_enable_nbs">key_enable_nbs</string>
|
||||||
<string name="key_enable_p2p">key_enable_p2p</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_network_behavior">key_network_behavior</string>
|
||||||
<string name="key_keep_screenon">key_keep_screenon</string>
|
<string name="key_keep_screenon">key_keep_screenon</string>
|
||||||
<string name="key_thumbsize">key_thumbsize3</string>
|
<string name="key_thumbsize">key_thumbsize3</string>
|
||||||
|
|
|
@ -2805,6 +2805,10 @@
|
||||||
• If all else fails, reboot this device\n
|
• If all else fails, reboot this device\n
|
||||||
</string>
|
</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_title">Message sending is stalled</string>
|
||||||
|
|
||||||
<string name="notify_stall_body_fmt">Though it normally takes less
|
<string name="notify_stall_body_fmt">Though it normally takes less
|
||||||
|
|
|
@ -340,6 +340,11 @@
|
||||||
android:summary="@string/summary_enable_p2p"
|
android:summary="@string/summary_enable_p2p"
|
||||||
android:defaultValue="false"
|
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"
|
<PreferenceScreen android:title="@string/network_advanced_title"
|
||||||
android:summary="@string/network_advanced_summary"
|
android:summary="@string/network_advanced_summary"
|
||||||
|
|
Loading…
Reference in a new issue