Skip to content

Commit

Permalink
catch some exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
j4velin committed Aug 11, 2019
1 parent 7eb59eb commit edd1bbf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/main/java/de/j4velin/wifiAutoOff/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ public static void deleteOldLogs(final Context context, long duration) {
if (BuildConfig.DEBUG) Logger.log("deleted " + deleted + " old log entries");
} catch (SQLiteDatabaseLockedException e) {
if (BuildConfig.DEBUG) Logger.log("cant delete log: database locked");
} catch (Throwable t) {
if (BuildConfig.DEBUG) Logger.log("cant delete log: " + t.getMessage());
} finally {
db.close();
}
db.close();
}

/**
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/de/j4velin/wifiAutoOff/StartReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ public void onReceive(final Context context, final Intent intent) {
}
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
// AC already connected on boot?
Intent batteryIntent =
context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
if (plugged == BatteryManager.BATTERY_PLUGGED_AC ||
plugged == BatteryManager.BATTERY_PLUGGED_USB) {
context.sendBroadcast(
// we're not allowed to send Intent.ACTION_POWER_CONNECTED, so use our own action
new Intent(context, Receiver.class).setAction(Receiver.POWER_CONNECTED));
try {
Intent batteryIntent = context.registerReceiver(null,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
if (plugged == BatteryManager.BATTERY_PLUGGED_AC ||
plugged == BatteryManager.BATTERY_PLUGGED_USB) {
context.sendBroadcast(
// we're not allowed to send Intent.ACTION_POWER_CONNECTED, so use our own action
new Intent(context, Receiver.class)
.setAction(Receiver.POWER_CONNECTED));
}
} catch (Throwable t) {
// ReceiverCallNotAllowedException might be thrown on Samsung devices...
if (BuildConfig.DEBUG) Logger.log(t);
}
}
Start.start(context);
Expand Down

0 comments on commit edd1bbf

Please sign in to comment.