Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e0b2443 authored by Ricky Wai's avatar Ricky Wai
Browse files

Report all watchlist events before last midnight

Also, remove all watchlist events before last midnight when we want to clear db

Bug: 63908748
Test: Visit watchlist site, then set date to tomorrow and reboot
will see records in db is removed and watchlist report has this record

Change-Id: I9543441a49c3ad3a0bf79ad9a9ec231ff10c0748
parent 9712788a
Loading
Loading
Loading
Loading
+10 −15
Original line number Diff line number Diff line
@@ -141,20 +141,19 @@ class WatchlistReportDbHelper extends SQLiteOpenHelper {
    }

    /**
     * Aggregate the records in database, and return a rappor encoded result.
     * Aggregate all records before most recent local midnight in database, and return a
     * rappor encoded result.
     */
    public AggregatedResult getAggregatedRecords() {
        final long twoDaysBefore = getTwoDaysBeforeTimestamp();
        final long yesterday = getYesterdayTimestamp();
        final String selectStatement = WhiteListReportContract.TIMESTAMP + " >= ? AND " +
                WhiteListReportContract.TIMESTAMP + " <= ?";
        final long lastMidnightTime = getLastMidnightTime();
        final String selectStatement = WhiteListReportContract.TIMESTAMP + " < ?";

        final SQLiteDatabase db = getReadableDatabase();
        Cursor c = null;
        try {
            c = db.query(true /* distinct */,
                    WhiteListReportContract.TABLE, DIGEST_DOMAIN_PROJECTION, selectStatement,
                    new String[]{"" + twoDaysBefore, "" + yesterday}, null, null,
                    new String[]{"" + lastMidnightTime}, null, null,
                    null, null);
            if (c == null) {
                return null;
@@ -182,23 +181,19 @@ class WatchlistReportDbHelper extends SQLiteOpenHelper {
    }

    /**
     * Remove all the records before yesterday.
     * Remove all the records before most recent local midnight.
     *
     * @return True if success.
     */
    public boolean cleanup() {
        final SQLiteDatabase db = getWritableDatabase();
        final long twoDaysBefore = getTwoDaysBeforeTimestamp();
        final String clause = WhiteListReportContract.TIMESTAMP + "< " + twoDaysBefore;
        final long midnightTime = getLastMidnightTime();
        final String clause = WhiteListReportContract.TIMESTAMP + "< " + midnightTime;
        return db.delete(WhiteListReportContract.TABLE, clause, null) != 0;
    }

    static long getTwoDaysBeforeTimestamp() {
        return getMidnightTimestamp(2);
    }

    static long getYesterdayTimestamp() {
        return getMidnightTimestamp(1);
    static long getLastMidnightTime() {
        return getMidnightTimestamp(0);
    }

    static long getMidnightTimestamp(int daysBefore) {