Skip to content

Commit

Permalink
fix reported crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
j4velin committed Mar 18, 2018
1 parent b9df187 commit 301dc55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/main/java/de/j4velin/wifiAutoOff/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabaseLockedException;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.ArrayList;
Expand Down Expand Up @@ -120,10 +121,14 @@ public static List<Item> getLog(final Context context, int num) {
*/
public static void deleteOldLogs(final Context context, long duration) {
Database db = new Database(context);
int deleted = db.getWritableDatabase().delete(Database.DB_NAME, "date < ?",
new String[]{String.valueOf(System.currentTimeMillis() - duration)});
try {
int deleted = db.getWritableDatabase().delete(Database.DB_NAME, "date < ?",
new String[]{String.valueOf(System.currentTimeMillis() - duration)});
if (BuildConfig.DEBUG) Logger.log("deleted " + deleted + " old log entries");
} catch (SQLiteDatabaseLockedException e) {
if (BuildConfig.DEBUG) Logger.log("cant delete log: database locked");
}
db.close();
if (BuildConfig.DEBUG) Logger.log("deleted " + deleted + " old log entries");
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/play/java/de/j4velin/wifiAutoOff/Locations.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ protected void onActivityResult(int requestCode, int resultCode, final Intent da
public void onRequestPermissionsResult(int requestCode, final String[] permissions,
final int[] grantResults) {
if (requestCode == REQUEST_PERMISSIONS) {
if (grantResults[0] == PermissionChecker.PERMISSION_GRANTED &&
if (grantResults.length > 0 &&
grantResults[0] == PermissionChecker.PERMISSION_GRANTED &&
(grantResults.length < 2 ||
grantResults[1] == PermissionChecker.PERMISSION_GRANTED)) {
findViewById(R.id.permissionswarning).setVisibility(View.GONE);
Expand Down

0 comments on commit 301dc55

Please sign in to comment.