trying to catch various dead system exception when scheduling new alarms and such
This commit is contained in:
parent
7e93f4519a
commit
49365511e4
|
@ -896,10 +896,14 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasInternetConnection() {
|
public boolean hasInternetConnection() {
|
||||||
ConnectivityManager cm = (ConnectivityManager) getApplicationContext()
|
final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
try {
|
||||||
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
|
final NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
|
||||||
return activeNetwork != null && activeNetwork.isConnected();
|
return activeNetwork != null && activeNetwork.isConnected();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
Log.d(Config.LOGTAG,"unable to check for internet connection",e);
|
||||||
|
return true; //if internet connection can not be checked it is probably best to just try
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("TrulyRandom")
|
@SuppressLint("TrulyRandom")
|
||||||
|
@ -1055,23 +1059,29 @@ public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
public void scheduleWakeUpCall(int seconds, int requestCode) {
|
public void scheduleWakeUpCall(int seconds, int requestCode) {
|
||||||
final long timeToWake = SystemClock.elapsedRealtime() + (seconds < 0 ? 1 : seconds + 1) * 1000;
|
final long timeToWake = SystemClock.elapsedRealtime() + (seconds < 0 ? 1 : seconds + 1) * 1000;
|
||||||
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
final AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||||
Intent intent = new Intent(this, EventReceiver.class);
|
Intent intent = new Intent(this, EventReceiver.class);
|
||||||
intent.setAction("ping");
|
intent.setAction("ping");
|
||||||
PendingIntent alarmIntent = PendingIntent.getBroadcast(this, requestCode, intent, 0);
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, requestCode, intent, 0);
|
||||||
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, timeToWake, alarmIntent);
|
try {
|
||||||
|
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, timeToWake, pendingIntent);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
Log.e(Config.LOGTAG, "unable to schedule alarm for ping", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.M)
|
@TargetApi(Build.VERSION_CODES.M)
|
||||||
private void scheduleNextIdlePing() {
|
private void scheduleNextIdlePing() {
|
||||||
Log.d(Config.LOGTAG, "schedule next idle ping");
|
final long timeToWake = SystemClock.elapsedRealtime() + (Config.IDLE_PING_INTERVAL * 1000);
|
||||||
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
final AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||||
Intent intent = new Intent(this, EventReceiver.class);
|
Intent intent = new Intent(this, EventReceiver.class);
|
||||||
intent.setAction(ACTION_IDLE_PING);
|
intent.setAction(ACTION_IDLE_PING);
|
||||||
alarmManager.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
|
||||||
SystemClock.elapsedRealtime() + (Config.IDLE_PING_INTERVAL * 1000),
|
try {
|
||||||
PendingIntent.getBroadcast(this, 0, intent, 0)
|
alarmManager.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, timeToWake, pendingIntent);
|
||||||
);
|
} catch (RuntimeException e) {
|
||||||
|
Log.d(Config.LOGTAG, "unable to schedule alarm for idle ping", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public XmppConnection createConnection(final Account account) {
|
public XmppConnection createConnection(final Account account) {
|
||||||
|
|
Loading…
Reference in New Issue