summaryrefslogtreecommitdiff
path: root/packages/Shell/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/Shell/src')
-rw-r--r--packages/Shell/src/com/android/shell/BugreportProgressService.java92
1 files changed, 72 insertions, 20 deletions
diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java
index 16a6061caed2..7b4cf0f748d3 100644
--- a/packages/Shell/src/com/android/shell/BugreportProgressService.java
+++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java
@@ -47,6 +47,7 @@ import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
+import android.os.Binder;
import android.os.BugreportManager;
import android.os.BugreportManager.BugreportCallback;
import android.os.BugreportManager.BugreportCallback.BugreportErrorCode;
@@ -186,7 +187,7 @@ public class BugreportProgressService extends Service {
static final int SCREENSHOT_DELAY_SECONDS = 3;
/** System property where dumpstate stores last triggered bugreport id */
- private static final String PROPERTY_LAST_ID = "dumpstate.last_id";
+ static final String PROPERTY_LAST_ID = "dumpstate.last_id";
private static final String BUGREPORT_SERVICE = "bugreport";
@@ -233,7 +234,7 @@ public class BugreportProgressService extends Service {
private File mBugreportsDir;
- private BugreportManager mBugreportManager;
+ @VisibleForTesting BugreportManager mBugreportManager;
/**
* id of the notification used to set service on foreground.
@@ -248,6 +249,11 @@ public class BugreportProgressService extends Service {
*/
private boolean mTakingScreenshot;
+ /**
+ * The delay timeout before taking a screenshot.
+ */
+ @VisibleForTesting int mScreenshotDelaySec = SCREENSHOT_DELAY_SECONDS;
+
@GuardedBy("sNotificationBundle")
private static final Bundle sNotificationBundle = new Bundle();
@@ -282,6 +288,7 @@ public class BugreportProgressService extends Service {
mContext.getString(R.string.bugreport_notification_channel),
isTv(this) ? NotificationManager.IMPORTANCE_DEFAULT
: NotificationManager.IMPORTANCE_LOW));
+ mBugreportManager = mContext.getSystemService(BugreportManager.class);
}
@Override
@@ -305,7 +312,7 @@ public class BugreportProgressService extends Service {
@Override
public IBinder onBind(Intent intent) {
- return null;
+ return new LocalBinder();
}
@Override
@@ -373,8 +380,14 @@ 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));
}
}
@@ -400,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);
@@ -609,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();
@@ -627,8 +645,6 @@ public class BugreportProgressService extends Service {
}
}
- mBugreportManager = (BugreportManager) mContext.getSystemService(
- Context.BUGREPORT_SERVICE);
final Executor executor = ActivityThread.currentActivityThread().getExecutor();
Log.i(TAG, "bugreport type = " + bugreportType
@@ -888,12 +904,12 @@ public class BugreportProgressService extends Service {
collapseNotificationBar();
final String msg = mContext.getResources()
.getQuantityString(com.android.internal.R.plurals.bugreport_countdown,
- SCREENSHOT_DELAY_SECONDS, SCREENSHOT_DELAY_SECONDS);
+ mScreenshotDelaySec, mScreenshotDelaySec);
Log.i(TAG, msg);
// Show a toast just once, otherwise it might be captured in the screenshot.
Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
- takeScreenshot(id, SCREENSHOT_DELAY_SECONDS);
+ takeScreenshot(id, mScreenshotDelaySec);
}
/**
@@ -1248,6 +1264,7 @@ public class BugreportProgressService extends Service {
.setContentText(content)
.setContentIntent(PendingIntent.getService(mContext, info.id, shareIntent,
PendingIntent.FLAG_UPDATE_CURRENT))
+ .setOnlyAlertOnce(false)
.setDeleteIntent(newCancelIntent(mContext, info));
if (!TextUtils.isEmpty(info.getName())) {
@@ -1287,6 +1304,7 @@ public class BugreportProgressService extends Service {
.setLocalOnly(true)
.setColor(context.getColor(
com.android.internal.R.color.system_notification_accent_color))
+ .setOnlyAlertOnce(true)
.extend(new Notification.TvExtender());
}
@@ -1621,6 +1639,16 @@ public class BugreportProgressService extends Service {
}
/**
+ * A local binder with interface to return an instance of BugreportProgressService for the
+ * purpose of testing.
+ */
+ final class LocalBinder extends Binder {
+ @VisibleForTesting BugreportProgressService getService() {
+ return BugreportProgressService.this;
+ }
+ }
+
+ /**
* Helper class encapsulating the UI elements and logic used to display a dialog where user
* can change the details of a bugreport.
*/
@@ -1749,6 +1777,22 @@ public class BugreportProgressService extends Service {
}
}
+ /**
+ * Notifies the dialog that the bugreport has finished so it disables the {@code name}
+ * field.
+ * <p>Once the bugreport is finished dumpstate has already generated the final files, so
+ * changing the name would have no effect.
+ */
+ void onBugreportFinished(BugreportInfo info) {
+ if (mId == info.id && mInfoName != null) {
+ mInfoName.setEnabled(false);
+ mInfoName.setText(null);
+ if (!TextUtils.isEmpty(info.getName())) {
+ mInfoName.setText(info.getName());
+ }
+ }
+ }
+
void cancel() {
if (mDialog != null) {
mDialog.cancel();
@@ -1883,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);
}
@@ -1993,12 +2035,21 @@ public class BugreportProgressService extends Service {
Log.i(TAG, "Deleting empty bugreport file: " + bugreportFile);
bugreportFile.delete();
}
- for (File file : screenshotFiles) {
- if (file.length() == 0) {
+ deleteEmptyScreenshots();
+ }
+
+ /**
+ * Deletes empty screenshot files.
+ */
+ private void deleteEmptyScreenshots() {
+ screenshotFiles.removeIf(file -> {
+ final long length = file.length();
+ if (length == 0) {
Log.i(TAG, "Deleting empty screenshot file: " + file);
file.delete();
}
- }
+ return length == 0;
+ });
}
/**
@@ -2006,7 +2057,8 @@ public class BugreportProgressService extends Service {
* {@code initialName} if user has changed it.
*/
void renameScreenshots() {
- if (TextUtils.isEmpty(name)) {
+ deleteEmptyScreenshots();
+ if (TextUtils.isEmpty(name) || screenshotFiles.isEmpty()) {
return;
}
final List<File> renamedFiles = new ArrayList<>(screenshotFiles.size());
@@ -2025,7 +2077,7 @@ public class BugreportProgressService extends Service {
if (newFile.length() > 0) {
renamedFiles.add(newFile);
} else if (newFile.delete()) {
- Log.d(TAG, "screenshot file: " + newFile + "deleted successfully.");
+ Log.d(TAG, "screenshot file: " + newFile + " deleted successfully.");
}
}
screenshotFiles = renamedFiles;