summaryrefslogtreecommitdiff
path: root/packages/Shell/src
diff options
context:
space:
mode:
author Abhijeet Kaur <abkaur@google.com> 2019-06-05 11:04:33 +0100
committer Abhijeet Kaur <abkaur@google.com> 2019-07-18 16:53:06 +0100
commit1a5030cc7d29c7cb1b73588e012f7ef26025fc54 (patch)
tree4b0fa2d109a0fed6907ac9466ba92522109360ae /packages/Shell/src
parent49db812ffd05ee6ca540dfb1b702b95b627cbeb4 (diff)
Add logic to create screenshot file
* Creating screenshot file for all types of bugreport * The logic to populate the screenshot file is in dumpstate (few bugreport types that do not need screenshots will leave the file untouched/empty) * Delete the empty screenshot file and set the file to null so that empty file does not get shared * This TODO was previously left as binder did not allow to send null screenshotfd, which was recently fixed. While fixing and testing the optional screenshot fd CL with these changes, left the value "null" by default. Fixed now. * Not adding any logic here on the basis of the type of bugreport as all that is already in dumpstate * Making the names of bugreport (.zip file) and bugreport screenshot (.png file) consistent. In the old flow also both have the same names. Bug: 123617758 Test: * Build and flash to the device * Turn on use bugreport API feature flag from Settings * Take interactive bugreport Expectation: On clicking the notification to "Share the bugreport" only 1 file (the bugreport zip file) gets shared. Also, there is no screenshot file in /bugreports/ in the device * Take full bugreport Expectation: On clicking the notification to "Share the bugreport" 2 files (bugreport zip and screenshot png file) get shared. Also we can see the screenshot file in /bugreports/ in the device Change-Id: I39cb6913033b6e3c61bd0c6655a76524c12d2428
Diffstat (limited to 'packages/Shell/src')
-rw-r--r--packages/Shell/src/com/android/shell/BugreportProgressService.java32
1 files changed, 17 insertions, 15 deletions
diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java
index ea878703f3d3..7173c98ae3db 100644
--- a/packages/Shell/src/com/android/shell/BugreportProgressService.java
+++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java
@@ -50,7 +50,6 @@ import android.os.BugreportManager;
import android.os.BugreportManager.BugreportCallback;
import android.os.BugreportManager.BugreportCallback.BugreportErrorCode;
import android.os.BugreportParams;
-import android.os.BugreportParams.BugreportMode;
import android.os.Bundle;
import android.os.FileUtils;
import android.os.Handler;
@@ -354,7 +353,7 @@ public class BugreportProgressService extends Service {
private final int mId;
private final BugreportInfo mInfo;
- BugreportCallbackImpl(String name, int id, @BugreportMode int bugreportType) {
+ BugreportCallbackImpl(String name, int id) {
mId = id;
// pid not used in this workflow, so setting default = 0
mInfo = new BugreportInfo(mContext, mId, 0 /* pid */, name,
@@ -544,21 +543,21 @@ public class BugreportProgressService extends Service {
private void startBugreportAPI(Intent intent) {
mUsingBugreportApi = true;
- String currentTimeStamp = new SimpleDateFormat("yyyy-MM-dd-HH-mm").format(
+ String bugreportName = "bugreport-" + new SimpleDateFormat("yyyy-MM-dd-HH-mm").format(
new Date());
// TODO(b/126862297): Make file naming same as dumpstate triggered bugreports
ParcelFileDescriptor bugreportFd = createReadWriteFile(BUGREPORT_DIR,
- "bugreport-" + currentTimeStamp + ".zip");
+ bugreportName + ".zip");
if (bugreportFd == null) {
Log.e(TAG, "Bugreport parcel file descriptor is null.");
return;
}
+ int bugreportType = intent.getIntExtra(EXTRA_BUGREPORT_TYPE,
+ BugreportParams.BUGREPORT_MODE_INTERACTIVE);
- // TODO(b/126862297): Screenshot file is not needed for INTERACTIVE_BUGREPORTS
- // Add logic to pass screenshot file only for specific bugreports.
ParcelFileDescriptor screenshotFd = createReadWriteFile(BUGREPORT_DIR,
- "screenshot-" + currentTimeStamp + ".png");
+ bugreportName + ".png");
if (screenshotFd == null) {
Log.e(TAG, "Screenshot parcel file descriptor is null.");
// TODO(b/123617758): Delete bugreport file created above
@@ -572,16 +571,13 @@ public class BugreportProgressService extends Service {
// Dumpstate increments PROPERTY_LAST_ID, may be racy if multiple calls
// to dumpstate are made simultaneously.
final int id = SystemProperties.getInt(PROPERTY_LAST_ID, 0) + 1;
- int bugreportType = intent.getIntExtra(EXTRA_BUGREPORT_TYPE,
- BugreportParams.BUGREPORT_MODE_INTERACTIVE);
Log.i(TAG, "bugreport type = " + bugreportType
+ " bugreport file fd: " + bugreportFd
+ " screenshot file fd: " + screenshotFd);
- BugreportCallbackImpl bugreportCallback = new BugreportCallbackImpl("bugreport-"
- + currentTimeStamp, id, bugreportType);
+ BugreportCallbackImpl bugreportCallback = new BugreportCallbackImpl(bugreportName, id);
try {
- mBugreportManager.startBugreport(bugreportFd, null,
+ mBugreportManager.startBugreport(bugreportFd, screenshotFd,
new BugreportParams(bugreportType), executor, bugreportCallback);
mBugreportInfos.put(bugreportCallback.mInfo.id, bugreportCallback.mInfo);
} catch (RuntimeException e) {
@@ -963,14 +959,20 @@ public class BugreportProgressService extends Service {
return;
}
final int max = -1; // this is to log metrics for dumpstate duration.
- final File screenshotFile = new File(BUGREPORT_DIR, info.name + ".png");
- // TODO(b/126862297): Screenshot file is not needed for INTERACTIVE_BUGREPORTS
- // Add logic to null check screenshot file only for specific bugreports.
+ File screenshotFile = new File(BUGREPORT_DIR, info.name + ".png");
if (screenshotFile == null) {
// Should never happen, an id always has a file linked to it.
Log.wtf(TAG, "Missing file " + screenshotFile.getPath() + " does not exist.");
return;
}
+ // If the screenshot file did not get populated implies this type of bugreport does not
+ // need the screenshot file; setting the file to null so that empty file doesnt get shared
+ if (screenshotFile.length() == 0) {
+ if (screenshotFile.delete()) {
+ Log.d(TAG, "screenshot file deleted successfully.");
+ }
+ screenshotFile = null;
+ }
onBugreportFinished(id, bugreportFile, screenshotFile, info.title, info.description, max);
}