summaryrefslogtreecommitdiff
path: root/services/backup/java
diff options
context:
space:
mode:
author beatricemarch <beatricemarch@google.com> 2023-08-31 12:53:16 +0000
committer Beatrice Marchegiani <beatricemarch@google.com> 2023-09-21 15:19:52 +0000
commit3f8ff83497f421bef686a71b65c4afcf28ee9695 (patch)
treec14d5c6ddc5b8687fb66717ef74b5a13f8991d06 /services/backup/java
parent501eeee21a5fb200b88b42eb8ed53be67bd16e56 (diff)
Add a 2.5 MB size limit to the text file storing BMM Events.
Test: atest CtsBackupHostTestCases, GtsBackupHostTestCases atest BackupManagerMonitorDumpsysUtilsTest, UserBackupManagerServiceTest Bug: 297163567 Change-Id: Ia1fdc0b465b960337f5e5c626460e305d96f4eb2
Diffstat (limited to 'services/backup/java')
-rw-r--r--services/backup/java/com/android/server/backup/UserBackupManagerService.java10
-rw-r--r--services/backup/java/com/android/server/backup/utils/BackupManagerMonitorDumpsysUtils.java25
2 files changed, 34 insertions, 1 deletions
diff --git a/services/backup/java/com/android/server/backup/UserBackupManagerService.java b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
index 2d80af92eea5..38af61b16ef3 100644
--- a/services/backup/java/com/android/server/backup/UserBackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
@@ -486,6 +486,13 @@ public class UserBackupManagerService {
File baseStateDir,
File dataDir,
TransportManager transportManager) {
+ // check if we are past the retention period for BMM Events,
+ // if so delete expired events and do not print them to dumpsys
+ BackupManagerMonitorDumpsysUtils backupManagerMonitorDumpsysUtils =
+ new BackupManagerMonitorDumpsysUtils();
+ if (backupManagerMonitorDumpsysUtils.deleteExpiredBMMEvents() && DEBUG){
+ Slog.d(TAG, "BMM Events recorded for dumpsys have expired");
+ }
return new UserBackupManagerService(
userId,
context,
@@ -4197,6 +4204,9 @@ public class UserBackupManagerService {
// We have not recorded BMMEvents yet.
pw.println("NO BACKUP MANAGER MONITOR EVENTS");
return;
+ } else if (bm.isFileLargerThanSizeLimit(events)){
+ pw.println("BACKUP MANAGER MONITOR EVENTS FILE OVER SIZE LIMIT - "
+ + "future events will not be recorded");
}
pw.println("START OF BACKUP MANAGER MONITOR EVENTS");
try (BufferedReader reader = new BufferedReader(new FileReader(events))) {
diff --git a/services/backup/java/com/android/server/backup/utils/BackupManagerMonitorDumpsysUtils.java b/services/backup/java/com/android/server/backup/utils/BackupManagerMonitorDumpsysUtils.java
index 16da846a093a..4b0d5a4928b6 100644
--- a/services/backup/java/com/android/server/backup/utils/BackupManagerMonitorDumpsysUtils.java
+++ b/services/backup/java/com/android/server/backup/utils/BackupManagerMonitorDumpsysUtils.java
@@ -57,11 +57,17 @@ public class BackupManagerMonitorDumpsysUtils {
// Retention period of 60 days (in millisec) for the BMM Events.
// After tha time has passed the text file containing the BMM events will be emptied
private static final long LOGS_RETENTION_PERIOD_MILLISEC = 60 * TimeUnit.DAYS.toMillis(1);
+ // Size limit for the text file containing the BMM events
+ private static final long BMM_FILE_SIZE_LIMIT_BYTES = 25 * 1024 * 1000; // 2.5 MB
+
// We cache the value of IsAfterRetentionPeriod() to avoid unnecessary disk I/O
// mIsAfterRetentionPeriodCached tracks if we have cached the value of IsAfterRetentionPeriod()
private boolean mIsAfterRetentionPeriodCached = false;
- // The cahched value of IsAfterRetentionPeriod()
+ // The cached value of IsAfterRetentionPeriod()
private boolean mIsAfterRetentionPeriod;
+ // If isFileLargerThanSizeLimit(bmmEvents) returns true we cache the value to avoid
+ // unnecessary disk I/O
+ private boolean mIsFileLargerThanSizeLimit = false;
/**
* Parses the BackupManagerMonitor bundle for a RESTORE event in a series of strings that
@@ -116,6 +122,11 @@ public class BackupManagerMonitorDumpsysUtils {
recordSetUpTimestamp();
}
+ if(isFileLargerThanSizeLimit(bmmEvents)){
+ // Do not write more events if the file is over size limit
+ return;
+ }
+
try (FileOutputStream out = new FileOutputStream(bmmEvents, /*append*/ true);
PrintWriter pw = new FastPrintWriter(out);) {
@@ -192,6 +203,13 @@ public class BackupManagerMonitorDumpsysUtils {
return fname;
}
+ public boolean isFileLargerThanSizeLimit(File events){
+ if (!mIsFileLargerThanSizeLimit) {
+ mIsFileLargerThanSizeLimit = events.length() > getBMMEventsFileSizeLimit();
+ }
+ return mIsFileLargerThanSizeLimit;
+ }
+
private String timestamp() {
long currentTime = System.currentTimeMillis();
Date date = new Date(currentTime);
@@ -402,6 +420,11 @@ public class BackupManagerMonitorDumpsysUtils {
return LOGS_RETENTION_PERIOD_MILLISEC;
}
+ @VisibleForTesting
+ long getBMMEventsFileSizeLimit(){
+ return BMM_FILE_SIZE_LIMIT_BYTES;
+ }
+
/**
* Delete the BMM Events file after the retention period has passed.
*