Merge "Replace broadcast with adding a method in BugreportCallback" am: d45d533b6e

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1507504

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ied674d7ff891caf26d751b6f15af2db9f0eea08f
This commit is contained in:
Gavin Corkery
2020-12-14 19:11:58 +00:00
committed by Automerger Merge Worker
5 changed files with 30 additions and 17 deletions

View File

@@ -7001,6 +7001,7 @@ package android.os {
public abstract static class BugreportManager.BugreportCallback {
ctor public BugreportManager.BugreportCallback();
method public void onEarlyReportFinished();
method public void onError(int);
method public void onFinished();
method public void onProgress(@FloatRange(from=0.0f, to=100.0f) float);

View File

@@ -26,7 +26,6 @@ import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.util.Log;
import android.widget.Toast;
@@ -52,8 +51,6 @@ import java.util.concurrent.Executor;
public final class BugreportManager {
private static final String TAG = "BugreportManager";
private static final String INTENT_UI_INTENSIVE_BUGREPORT_DUMPS_FINISHED =
"com.android.internal.intent.action.UI_INTENSIVE_BUGREPORT_DUMPS_FINISHED";
private final Context mContext;
private final IDumpstate mBinder;
@@ -126,6 +123,12 @@ public final class BugreportManager {
* Called when taking bugreport finishes successfully.
*/
public void onFinished() {}
/**
* Called when it is ready for calling app to show UI, showing any extra UI before this
* callback can interfere with bugreport generation.
*/
public void onEarlyReportFinished() {}
}
/**
@@ -288,21 +291,12 @@ public final class BugreportManager {
}
@Override
public void onUiIntensiveBugreportDumpsFinished(String callingPackage)
public void onUiIntensiveBugreportDumpsFinished()
throws RemoteException {
final long identity = Binder.clearCallingIdentity();
try {
mExecutor.execute(() -> {
// Send intent to let calling app to show UI safely without interfering with
// the bugreport/screenshot generation.
// TODO(b/154298410): When S is ready for API change, add a method in
// BugreportCallback so we can just call the callback instead of using
// broadcast.
Intent intent = new Intent(INTENT_UI_INTENSIVE_BUGREPORT_DUMPS_FINISHED);
intent.setPackage(callingPackage);
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
mContext.sendBroadcast(intent, android.Manifest.permission.DUMP);
mCallback.onEarlyReportFinished();
});
} finally {
Binder.restoreCallingIdentity(identity);

View File

@@ -118,6 +118,7 @@ public class BugreportManagerTest {
// Wifi bugreports should not receive any progress.
assertThat(callback.hasReceivedProgress()).isFalse();
assertThat(mBugreportFile.length()).isGreaterThan(0L);
assertThat(callback.hasEarlyReportFinished()).isTrue();
assertFdsAreClosed(mBugreportFd);
}
@@ -135,6 +136,7 @@ public class BugreportManagerTest {
// Interactive bugreports show progress updates.
assertThat(callback.hasReceivedProgress()).isTrue();
assertThat(mBugreportFile.length()).isGreaterThan(0L);
assertThat(callback.hasEarlyReportFinished()).isTrue();
assertFdsAreClosed(mBugreportFd);
}
@@ -246,6 +248,7 @@ public class BugreportManagerTest {
private int mErrorCode = -1;
private boolean mSuccess = false;
private boolean mReceivedProgress = false;
private boolean mEarlyReportFinished = false;
private final Object mLock = new Object();
@Override
@@ -271,6 +274,13 @@ public class BugreportManagerTest {
}
}
@Override
public void onEarlyReportFinished() {
synchronized (mLock) {
mEarlyReportFinished = true;
}
}
/* Indicates completion; and ended up with a success or error. */
public boolean isDone() {
synchronized (mLock) {
@@ -295,6 +305,12 @@ public class BugreportManagerTest {
return mReceivedProgress;
}
}
public boolean hasEarlyReportFinished() {
synchronized (mLock) {
return mEarlyReportFinished;
}
}
}
public static BugreportManager getBugreportManager() {

View File

@@ -378,6 +378,9 @@ public class BugreportProgressService extends Service {
}
}
@Override
public void onEarlyReportFinished() {}
/**
* Reads bugreport id and links it to the bugreport info to track a bugreport that is in
* process. id is incremented in the dumpstate code.

View File

@@ -297,9 +297,8 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
}
@Override
public void onUiIntensiveBugreportDumpsFinished(String callingPackage)
throws RemoteException {
mListener.onUiIntensiveBugreportDumpsFinished(callingPackage);
public void onUiIntensiveBugreportDumpsFinished() throws RemoteException {
mListener.onUiIntensiveBugreportDumpsFinished();
}
@Override