diff options
author | 2020-12-07 17:58:26 +0800 | |
---|---|---|
committer | 2020-12-10 19:51:29 +0800 | |
commit | 8ba3c84cffebe4cb3f545ec9810cf944cab90b3f (patch) | |
tree | 35f00b4d37feda9c76b468be4682be58b2cf5ad0 | |
parent | bc1f3bff515dc27881be2a2bc22c432f0433d145 (diff) |
Fixes an error handling in BugreportProgressService
Calls onError function when bugreport is finished and file is empty.
Bug: 174314124
Test: atest BugreportReceiverTest
Change-Id: I4542568fd2d2ad1c75c7c3b223accca4995938a3
-rw-r--r-- | packages/Shell/src/com/android/shell/BugreportProgressService.java | 9 | ||||
-rw-r--r-- | packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java | 15 |
2 files changed, 19 insertions, 5 deletions
diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java index d50f08df947a..d1a0b49014ce 100644 --- a/packages/Shell/src/com/android/shell/BugreportProgressService.java +++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java @@ -380,6 +380,11 @@ public class BugreportProgressService extends Service { public void onFinished() { mInfo.renameBugreportFile(); mInfo.renameScreenshots(); + if (mInfo.bugreportFile.length() == 0) { + Log.e(TAG, "Bugreport file empty. File path = " + mInfo.bugreportFile); + onError(BUGREPORT_ERROR_RUNTIME); + return; + } synchronized (mLock) { sendBugreportFinishedBroadcastLocked(); mMainThreadHandler.post(() -> mInfoDialog.onBugreportFinished(mInfo)); @@ -408,10 +413,6 @@ public class BugreportProgressService extends Service { @GuardedBy("mLock") private void sendBugreportFinishedBroadcastLocked() { final String bugreportFilePath = mInfo.bugreportFile.getAbsolutePath(); - if (mInfo.bugreportFile.length() == 0) { - Log.e(TAG, "Bugreport file empty. File path = " + bugreportFilePath); - return; - } if (mInfo.type == BugreportParams.BUGREPORT_MODE_REMOTE) { sendRemoteBugreportFinishedBroadcast(mContext, bugreportFilePath, mInfo.bugreportFile); diff --git a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java index 43147cdfc86d..89cdeaea199c 100644 --- a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java +++ b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java @@ -513,6 +513,17 @@ public class BugreportReceiverTest { } @Test + public void testBugreportFinished_withEmptyBugreportFile() throws Exception { + sendBugreportStarted(); + + IoUtils.closeQuietly(mBugreportFd); + mBugreportFd = null; + sendBugreportFinished(); + + assertServiceNotRunning(); + } + + @Test public void testShareBugreportAfterServiceDies() throws Exception { sendBugreportStarted(); waitForScreenshotButtonEnabled(true); @@ -647,7 +658,9 @@ public class BugreportReceiverTest { * Callbacks to service to finish the bugreport. */ private void sendBugreportFinished() throws Exception { - writeZipFile(mBugreportFd, BUGREPORT_FILE, BUGREPORT_CONTENT); + if (mBugreportFd != null) { + writeZipFile(mBugreportFd, BUGREPORT_FILE, BUGREPORT_CONTENT); + } if (mScreenshotFd != null) { writeScreenshotFile(mScreenshotFd, SCREENSHOT_CONTENT); } |