Change su logs time granularity

This commit is contained in:
topjohnwu 2017-07-24 01:20:03 +08:00
parent 356065d1ee
commit ab199d883d
2 changed files with 9 additions and 5 deletions

View File

@ -27,7 +27,7 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
public static final String MULTIUSER_MODE = "multiuser_mode";
public static final String MNT_NS = "mnt_ns";
private static final int DATABASE_VER = 2;
private static final int DATABASE_VER = 3;
private static final String POLICY_TABLE = "policies";
private static final String LOG_TABLE = "logs";
private static final String SETTINGS_TABLE = "settings";
@ -76,6 +76,10 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
}
++oldVersion;
}
if (oldVersion == 2) {
db.execSQL("UPDATE " + LOG_TABLE + " SET time=time*1000");
++oldVersion;
}
}
private void createTables(SQLiteDatabase db) {
@ -104,7 +108,7 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
new String[] { String.valueOf(System.currentTimeMillis() / 1000) });
// Clear outdated logs
mDb.delete(LOG_TABLE, "time < ?", new String[] { String.valueOf(
System.currentTimeMillis() / 1000 - magiskManager.suLogTimeout * 86400) });
System.currentTimeMillis() - magiskManager.suLogTimeout * 86400000) });
}
public void deletePolicy(Policy policy) {
@ -189,7 +193,7 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
List<Integer> list = null;
String dateString = null, newString;
while (c.moveToNext()) {
Date date = new Date(c.getLong(c.getColumnIndex("time")) * 1000);
Date date = new Date(c.getLong(c.getColumnIndex("time")));
newString = DateFormat.getDateInstance(DateFormat.MEDIUM, MagiskManager.locale).format(date);
if (!TextUtils.equals(dateString, newString)) {
dateString = newString;

View File

@ -30,7 +30,7 @@ public class SuLogEntry {
appName = c.getString(c.getColumnIndex("app_name"));
command = c.getString(c.getColumnIndex("command"));
action = c.getInt(c.getColumnIndex("action")) != 0;
date = new Date(c.getLong(c.getColumnIndex("time")) * 1000);
date = new Date(c.getLong(c.getColumnIndex("time")));
}
public ContentValues getContentValues() {
@ -42,7 +42,7 @@ public class SuLogEntry {
values.put("command", command);
values.put("to_uid", toUid);
values.put("action", action ? 1 : 0);
values.put("time", date.getTime() / 1000);
values.put("time", date.getTime());
return values;
}