Delete empty bugreport files onError

Bug: 152839953
Test: Take another bugreport, while one is in progress.
Without this change: bugreport files for the second bugreport can be
seen in /bugreports
With this change: no file for the second bugreport can be seen. This
is the expected behavior.

Change-Id: I45c1f66f3a52ba9a31413cf9748bc5504eaa65d0
This commit is contained in:
Abhijeet Kaur
2020-04-01 12:22:55 +01:00
parent 80849883c6
commit 1a5687df2c

View File

@@ -363,6 +363,7 @@ public class BugreportProgressService extends Service {
public void onError(@BugreportErrorCode int errorCode) {
synchronized (mLock) {
stopProgressLocked(mInfo.id);
mInfo.deleteEmptyFiles();
}
Log.e(TAG, "Bugreport API callback onError() errorCode = " + errorCode);
return;
@@ -1979,6 +1980,22 @@ public class BugreportProgressService extends Service {
bugreportFile.delete();
}
/**
* Deletes empty files for a given bugreport.
*/
private void deleteEmptyFiles() {
if (bugreportFile.length() == 0) {
Log.i(TAG, "Deleting empty bugreport file: " + bugreportFile);
bugreportFile.delete();
}
for (File file : screenshotFiles) {
if (file.length() == 0) {
Log.i(TAG, "Deleting empty screenshot file: " + file);
file.delete();
}
}
}
/**
* Rename all screenshots files so that they contain the new {@code name} instead of the
* {@code initialName} if user has changed it.