Replace broadcast with adding a method in BugreportCallback
BUG: 154298410 Test: BetterBug can work normally in bug report shortcut flow Change-Id: Ibc1a5a8ac308c303399d28eb8c177096b805fdf9
This commit is contained in:
@@ -7501,6 +7501,7 @@ package android.os {
|
|||||||
|
|
||||||
public abstract static class BugreportManager.BugreportCallback {
|
public abstract static class BugreportManager.BugreportCallback {
|
||||||
ctor public BugreportManager.BugreportCallback();
|
ctor public BugreportManager.BugreportCallback();
|
||||||
|
method public void onEarlyReportFinished();
|
||||||
method public void onError(int);
|
method public void onError(int);
|
||||||
method public void onFinished();
|
method public void onFinished();
|
||||||
method public void onProgress(@FloatRange(from=0.0f, to=100.0f) float);
|
method public void onProgress(@FloatRange(from=0.0f, to=100.0f) float);
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import android.annotation.SystemApi;
|
|||||||
import android.annotation.SystemService;
|
import android.annotation.SystemService;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -52,8 +51,6 @@ import java.util.concurrent.Executor;
|
|||||||
public final class BugreportManager {
|
public final class BugreportManager {
|
||||||
|
|
||||||
private static final String TAG = "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 Context mContext;
|
||||||
private final IDumpstate mBinder;
|
private final IDumpstate mBinder;
|
||||||
@@ -126,6 +123,12 @@ public final class BugreportManager {
|
|||||||
* Called when taking bugreport finishes successfully.
|
* Called when taking bugreport finishes successfully.
|
||||||
*/
|
*/
|
||||||
public void onFinished() {}
|
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
|
@Override
|
||||||
public void onUiIntensiveBugreportDumpsFinished(String callingPackage)
|
public void onUiIntensiveBugreportDumpsFinished()
|
||||||
throws RemoteException {
|
throws RemoteException {
|
||||||
final long identity = Binder.clearCallingIdentity();
|
final long identity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
mExecutor.execute(() -> {
|
mExecutor.execute(() -> {
|
||||||
// Send intent to let calling app to show UI safely without interfering with
|
mCallback.onEarlyReportFinished();
|
||||||
// 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);
|
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(identity);
|
Binder.restoreCallingIdentity(identity);
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ public class BugreportManagerTest {
|
|||||||
// Wifi bugreports should not receive any progress.
|
// Wifi bugreports should not receive any progress.
|
||||||
assertThat(callback.hasReceivedProgress()).isFalse();
|
assertThat(callback.hasReceivedProgress()).isFalse();
|
||||||
assertThat(mBugreportFile.length()).isGreaterThan(0L);
|
assertThat(mBugreportFile.length()).isGreaterThan(0L);
|
||||||
|
assertThat(callback.hasEarlyReportFinished()).isTrue();
|
||||||
assertFdsAreClosed(mBugreportFd);
|
assertFdsAreClosed(mBugreportFd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,6 +136,7 @@ public class BugreportManagerTest {
|
|||||||
// Interactive bugreports show progress updates.
|
// Interactive bugreports show progress updates.
|
||||||
assertThat(callback.hasReceivedProgress()).isTrue();
|
assertThat(callback.hasReceivedProgress()).isTrue();
|
||||||
assertThat(mBugreportFile.length()).isGreaterThan(0L);
|
assertThat(mBugreportFile.length()).isGreaterThan(0L);
|
||||||
|
assertThat(callback.hasEarlyReportFinished()).isTrue();
|
||||||
assertFdsAreClosed(mBugreportFd);
|
assertFdsAreClosed(mBugreportFd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,6 +248,7 @@ public class BugreportManagerTest {
|
|||||||
private int mErrorCode = -1;
|
private int mErrorCode = -1;
|
||||||
private boolean mSuccess = false;
|
private boolean mSuccess = false;
|
||||||
private boolean mReceivedProgress = false;
|
private boolean mReceivedProgress = false;
|
||||||
|
private boolean mEarlyReportFinished = false;
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
|
|
||||||
@Override
|
@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. */
|
/* Indicates completion; and ended up with a success or error. */
|
||||||
public boolean isDone() {
|
public boolean isDone() {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
@@ -295,6 +305,12 @@ public class BugreportManagerTest {
|
|||||||
return mReceivedProgress;
|
return mReceivedProgress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasEarlyReportFinished() {
|
||||||
|
synchronized (mLock) {
|
||||||
|
return mEarlyReportFinished;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BugreportManager getBugreportManager() {
|
public static BugreportManager getBugreportManager() {
|
||||||
|
|||||||
@@ -386,6 +386,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
|
* 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.
|
* process. id is incremented in the dumpstate code.
|
||||||
|
|||||||
@@ -297,9 +297,8 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUiIntensiveBugreportDumpsFinished(String callingPackage)
|
public void onUiIntensiveBugreportDumpsFinished() throws RemoteException {
|
||||||
throws RemoteException {
|
mListener.onUiIntensiveBugreportDumpsFinished();
|
||||||
mListener.onUiIntensiveBugreportDumpsFinished(callingPackage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user