Loading services/core/java/com/android/server/appop/AppOpHistoryHelper.java +12 −0 Original line number Diff line number Diff line Loading @@ -420,6 +420,9 @@ public class AppOpHistoryHelper { } private class SqliteWriteHandler extends Handler { // Max database size 50 MB private static final long MAX_DATABASE_SIZE_BYTES = 50 * 1024 * 1024; SqliteWriteHandler(Looper looper) { super(looper); } Loading @@ -433,6 +436,7 @@ public class AppOpHistoryHelper { SQLITE_APP_OP_EVENT_REPORTED__WRITE_TYPE__WRITE_PERIODIC); } finally { ensurePeriodicJobsAreScheduled(); ensureDatabaseSize(); } } case WRITE_DATABASE_CACHE_FULL -> { Loading @@ -450,6 +454,7 @@ public class AppOpHistoryHelper { SQLITE_APP_OP_EVENT_REPORTED__WRITE_TYPE__WRITE_CACHE_FULL); } finally { ensurePeriodicJobsAreScheduled(); ensureDatabaseSize(); } } case DELETE_EXPIRED_ENTRIES_PERIODIC -> { Loading @@ -465,6 +470,13 @@ public class AppOpHistoryHelper { } } private void ensureDatabaseSize() { long databaseSize = mDatabaseFile.length(); if (databaseSize > MAX_DATABASE_SIZE_BYTES) { mDbHelper.execSQL(AppOpHistoryTable.DELETE_TABLE_DATA_LEAST_RECENT_ENTRIES); } } void removeAllPendingMessages() { removeMessages(WRITE_DATABASE_PERIODIC); removeMessages(DELETE_EXPIRED_ENTRIES_PERIODIC); Loading services/core/java/com/android/server/appop/AppOpHistoryTable.java +9 −2 Original line number Diff line number Diff line Loading @@ -74,8 +74,10 @@ final class AppOpHistoryTable { static final String CHAIN_ID = "chain_id"; /** The actual access time of first event in a time window. */ static final String ACCESS_TIME = "access_time"; /** The actual duration of first event in a time window. Subsequent events with same * discretized duration are summed up in total duration. */ /** * The actual duration of first event in a time window. Subsequent events with same * discretized duration are summed up in total duration. */ static final String DURATION = "access_duration"; /** The sum of actual duration of the app op accesses in a time window. */ static final String TOTAL_DURATION = "total_duration"; Loading Loading @@ -160,6 +162,11 @@ final class AppOpHistoryTable { static final String DELETE_TABLE_DATA_BEFORE_ACCESS_TIME = "DELETE FROM " + TABLE_NAME + " WHERE " + Columns.ACCESS_TIME + " < ?"; // Delete at least 1024 (cache size) records, in other words the batch size for insertion. static final String DELETE_TABLE_DATA_LEAST_RECENT_ENTRIES = "DELETE FROM " + TABLE_NAME + " WHERE " + Columns.ACCESS_TIME + " <= (SELECT " + Columns.ACCESS_TIME + " FROM " + TABLE_NAME + " ORDER BY " + Columns.ACCESS_TIME + " LIMIT 1 OFFSET 1024)"; static final String DELETE_DATA_FOR_UID_PACKAGE = "DELETE FROM " + AppOpHistoryTable.TABLE_NAME + " WHERE " + Columns.UID + " = ? AND " + Columns.PACKAGE_NAME + " = ?"; Loading Loading
services/core/java/com/android/server/appop/AppOpHistoryHelper.java +12 −0 Original line number Diff line number Diff line Loading @@ -420,6 +420,9 @@ public class AppOpHistoryHelper { } private class SqliteWriteHandler extends Handler { // Max database size 50 MB private static final long MAX_DATABASE_SIZE_BYTES = 50 * 1024 * 1024; SqliteWriteHandler(Looper looper) { super(looper); } Loading @@ -433,6 +436,7 @@ public class AppOpHistoryHelper { SQLITE_APP_OP_EVENT_REPORTED__WRITE_TYPE__WRITE_PERIODIC); } finally { ensurePeriodicJobsAreScheduled(); ensureDatabaseSize(); } } case WRITE_DATABASE_CACHE_FULL -> { Loading @@ -450,6 +454,7 @@ public class AppOpHistoryHelper { SQLITE_APP_OP_EVENT_REPORTED__WRITE_TYPE__WRITE_CACHE_FULL); } finally { ensurePeriodicJobsAreScheduled(); ensureDatabaseSize(); } } case DELETE_EXPIRED_ENTRIES_PERIODIC -> { Loading @@ -465,6 +470,13 @@ public class AppOpHistoryHelper { } } private void ensureDatabaseSize() { long databaseSize = mDatabaseFile.length(); if (databaseSize > MAX_DATABASE_SIZE_BYTES) { mDbHelper.execSQL(AppOpHistoryTable.DELETE_TABLE_DATA_LEAST_RECENT_ENTRIES); } } void removeAllPendingMessages() { removeMessages(WRITE_DATABASE_PERIODIC); removeMessages(DELETE_EXPIRED_ENTRIES_PERIODIC); Loading
services/core/java/com/android/server/appop/AppOpHistoryTable.java +9 −2 Original line number Diff line number Diff line Loading @@ -74,8 +74,10 @@ final class AppOpHistoryTable { static final String CHAIN_ID = "chain_id"; /** The actual access time of first event in a time window. */ static final String ACCESS_TIME = "access_time"; /** The actual duration of first event in a time window. Subsequent events with same * discretized duration are summed up in total duration. */ /** * The actual duration of first event in a time window. Subsequent events with same * discretized duration are summed up in total duration. */ static final String DURATION = "access_duration"; /** The sum of actual duration of the app op accesses in a time window. */ static final String TOTAL_DURATION = "total_duration"; Loading Loading @@ -160,6 +162,11 @@ final class AppOpHistoryTable { static final String DELETE_TABLE_DATA_BEFORE_ACCESS_TIME = "DELETE FROM " + TABLE_NAME + " WHERE " + Columns.ACCESS_TIME + " < ?"; // Delete at least 1024 (cache size) records, in other words the batch size for insertion. static final String DELETE_TABLE_DATA_LEAST_RECENT_ENTRIES = "DELETE FROM " + TABLE_NAME + " WHERE " + Columns.ACCESS_TIME + " <= (SELECT " + Columns.ACCESS_TIME + " FROM " + TABLE_NAME + " ORDER BY " + Columns.ACCESS_TIME + " LIMIT 1 OFFSET 1024)"; static final String DELETE_DATA_FOR_UID_PACKAGE = "DELETE FROM " + AppOpHistoryTable.TABLE_NAME + " WHERE " + Columns.UID + " = ? AND " + Columns.PACKAGE_NAME + " = ?"; Loading