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:
Eric House 2019-03-20 14:35:12 -07:00
parent b5714fadf8
commit a7da0e33bb
5 changed files with 72 additions and 55 deletions

View file

@ -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) );
} }
} }

View file

@ -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,8 +105,9 @@ 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 )
{ {
if ( stallCheckEnabled( context ) ) {
String name = clazz.getSimpleName(); String name = clazz.getSimpleName();
synchronized ( sPendingIntents ) { synchronized ( sPendingIntents ) {
if ( !sPendingIntents.containsKey( name )) { if ( !sPendingIntents.containsKey( name )) {
@ -119,10 +120,12 @@ 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 )
{ {
if ( stallCheckEnabled( context ) ) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long maxAge = 0; long maxAge = 0;
synchronized ( sPendingIntents ) { synchronized ( sPendingIntents ) {
@ -143,9 +146,11 @@ abstract class XWJIService extends JobIntentService {
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 )
{ {
if ( stallCheckEnabled( context ) ) {
String name = clazz.getSimpleName(); String name = clazz.getSimpleName();
synchronized ( sPendingIntents ) { synchronized ( sPendingIntents ) {
String found = null; String found = null;
@ -169,12 +174,17 @@ abstract class XWJIService extends JobIntentService {
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 )
{ {

View file

@ -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>

View file

@ -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

View file

@ -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"