diff options
author | Rhed Jao <rhedjao@google.com> | 2020-12-07 19:44:13 +0800 |
---|---|---|
committer | Rhed Jao <rhedjao@google.com> | 2020-12-21 04:20:03 +0000 |
commit | 7cb78fdf34e84e1ee58c4ad939ba5060688caff2 (patch) | |
tree | 07a65b108b828632e98a507da97084928b26d1bc /packages/Shell/src | |
parent | 39b6acbb55b037ba6dbeb092eb93caddd277a2cd (diff) |
Returns immediately if the bugreport file already exists
There's a case that BugreportProgressService is invoked twice quickly,
and both services create the same bugreport file name. The later one
may delete current running bugreport file in its clean function,
when it detects another bugreport is running.
Bug: 174314124
Bug: 175287931
Test: atest BugreportReceiverTest
Change-Id: I5e1802c5912f4414f1ad3b8bdaf7c7420332b9d6
Merged-In: I5e1802c5912f4414f1ad3b8bdaf7c7420332b9d6
Diffstat (limited to 'packages/Shell/src')
-rw-r--r-- | packages/Shell/src/com/android/shell/BugreportProgressService.java | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java index 2b71892ee8a5..8b73c5ed552e 100644 --- a/packages/Shell/src/com/android/shell/BugreportProgressService.java +++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java @@ -618,12 +618,21 @@ public class BugreportProgressService extends Service { BugreportInfo info = new BugreportInfo(mContext, baseName, name, shareTitle, shareDescription, bugreportType, mBugreportsDir); + synchronized (mLock) { + if (info.bugreportFile.exists()) { + Log.e(TAG, "Failed to start bugreport generation, the requested bugreport file " + + info.bugreportFile + " already exists"); + return; + } + info.createBugreportFile(); + } ParcelFileDescriptor bugreportFd = info.getBugreportFd(); if (bugreportFd == null) { Log.e(TAG, "Failed to start bugreport generation as " + " bugreport parcel file descriptor is null."); return; } + info.createScreenshotFile(mBugreportsDir); ParcelFileDescriptor screenshotFd = null; if (isDefaultScreenshotRequired(bugreportType, /* hasScreenshotButton= */ !mIsTv)) { screenshotFd = info.getDefaultScreenshotFd(); @@ -1918,12 +1927,10 @@ public class BugreportProgressService extends Service { this.shareDescription = shareDescription == null ? "" : shareDescription; this.type = type; this.baseName = baseName; - createBugreportFile(bugreportsDir); - createScreenshotFile(bugreportsDir); + this.bugreportFile = new File(bugreportsDir, getFileName(this, ".zip")); } - void createBugreportFile(File bugreportsDir) { - bugreportFile = new File(bugreportsDir, getFileName(this, ".zip")); + void createBugreportFile() { createReadWriteFile(bugreportFile); } |