Merge "Clean up code of starting bug report" into rvc-dev

This commit is contained in:
Paul Chang
2020-02-29 00:20:04 +00:00
committed by Android (Google) Code Review

View File

@@ -615,7 +615,9 @@ public class BugreportProgressService extends Service {
+ " bugreport parcel file descriptor is null."); + " bugreport parcel file descriptor is null.");
return; return;
} }
ParcelFileDescriptor screenshotFd = info.getDefaultScreenshotFd(); ParcelFileDescriptor screenshotFd = null;
if (isDefaultScreenshotRequired(bugreportType)) {
screenshotFd = info.getDefaultScreenshotFd();
if (screenshotFd == null) { if (screenshotFd == null) {
Log.e(TAG, "Failed to start bugreport generation as" Log.e(TAG, "Failed to start bugreport generation as"
+ " screenshot parcel file descriptor is null. Deleting bugreport file"); + " screenshot parcel file descriptor is null. Deleting bugreport file");
@@ -623,6 +625,7 @@ public class BugreportProgressService extends Service {
info.bugreportFile.delete(); info.bugreportFile.delete();
return; return;
} }
}
mBugreportManager = (BugreportManager) mContext.getSystemService( mBugreportManager = (BugreportManager) mContext.getSystemService(
Context.BUGREPORT_SERVICE); Context.BUGREPORT_SERVICE);
@@ -641,9 +644,19 @@ public class BugreportProgressService extends Service {
// The binder call didn't go through successfully, so need to close the fds. // The binder call didn't go through successfully, so need to close the fds.
// If the calls went through API takes ownership. // If the calls went through API takes ownership.
FileUtils.closeQuietly(bugreportFd); FileUtils.closeQuietly(bugreportFd);
if (screenshotFd != null) {
FileUtils.closeQuietly(screenshotFd); FileUtils.closeQuietly(screenshotFd);
} }
} }
}
private static boolean isDefaultScreenshotRequired(
@BugreportParams.BugreportMode int bugreportType) {
// Modify dumpstate#SetOptionsFromMode as well for default system screenshots.
// We override dumpstate for interactive bugreports.
return bugreportType == BugreportParams.BUGREPORT_MODE_FULL
|| bugreportType == BugreportParams.BUGREPORT_MODE_WEAR;
}
private static ParcelFileDescriptor getFd(File file) { private static ParcelFileDescriptor getFd(File file) {
try { try {