Merge "Improvements to Bugreporting API."
This commit is contained in:
@@ -79,23 +79,27 @@ public class BugreportManager {
|
||||
* Called when taking bugreport resulted in an error.
|
||||
*
|
||||
* @param errorCode the error that occurred. Possible values are
|
||||
* {@code BUGREPORT_ERROR_INVALID_INPUT}, {@code BUGREPORT_ERROR_RUNTIME}.
|
||||
* {@code BUGREPORT_ERROR_INVALID_INPUT},
|
||||
* {@code BUGREPORT_ERROR_RUNTIME},
|
||||
* {@code BUGREPORT_ERROR_USER_DENIED_CONSENT}.
|
||||
*/
|
||||
void onError(@BugreportErrorCode int errorCode);
|
||||
|
||||
/**
|
||||
* Called when taking bugreport finishes successfully
|
||||
*
|
||||
* @param durationMs time capturing bugreport took in milliseconds
|
||||
* @param title title for the bugreport; helpful in reminding the user why they took it
|
||||
* @param description detailed description for the bugreport
|
||||
* Called when taking bugreport finishes successfully.
|
||||
*/
|
||||
void onFinished(long durationMs, @NonNull String title,
|
||||
@NonNull String description);
|
||||
void onFinished();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a bugreport asynchronously.
|
||||
* Starts a bugreport.
|
||||
*
|
||||
* <p>This starts a bugreport in the background. However the call itself can take several
|
||||
* seconds to return in the worst case. {@code listener} will receive progress and status
|
||||
* updates.
|
||||
*
|
||||
* <p>The bugreport artifacts will be copied over to the given file descriptors only if the
|
||||
* user consents to sharing with the calling app.
|
||||
*
|
||||
* @param bugreportFd file to write the bugreport. This should be opened in write-only,
|
||||
* append mode.
|
||||
@@ -107,7 +111,7 @@ public class BugreportManager {
|
||||
@RequiresPermission(android.Manifest.permission.DUMP)
|
||||
public void startBugreport(@NonNull FileDescriptor bugreportFd,
|
||||
@Nullable FileDescriptor screenshotFd,
|
||||
@NonNull BugreportParams params, @Nullable BugreportListener listener) {
|
||||
@NonNull BugreportParams params, @NonNull BugreportListener listener) {
|
||||
// TODO(b/111441001): Enforce android.Manifest.permission.DUMP if necessary.
|
||||
DumpstateListener dsListener = new DumpstateListener(listener);
|
||||
|
||||
@@ -121,6 +125,18 @@ public class BugreportManager {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Cancels a currently running bugreport.
|
||||
*/
|
||||
@RequiresPermission(android.Manifest.permission.DUMP)
|
||||
public void cancelBugreport() {
|
||||
try {
|
||||
mBinder.cancelBugreport();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
private final class DumpstateListener extends IDumpstateListener.Stub
|
||||
implements DeathRecipient {
|
||||
private final BugreportListener mListener;
|
||||
@@ -145,9 +161,13 @@ public class BugreportManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinished(long durationMs, String title, String description)
|
||||
throws RemoteException {
|
||||
mListener.onFinished(durationMs, title, description);
|
||||
public void onFinished() throws RemoteException {
|
||||
try {
|
||||
mListener.onFinished();
|
||||
} finally {
|
||||
// The bugreport has finished. Let's shutdown the service to minimize its footprint.
|
||||
cancelBugreport();
|
||||
}
|
||||
}
|
||||
|
||||
// Old methods; should go away
|
||||
|
||||
@@ -1962,8 +1962,7 @@ public class BugreportProgressService extends Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinished(long durationMs, String title, String description)
|
||||
throws RemoteException {
|
||||
public void onFinished() throws RemoteException {
|
||||
// TODO(b/111441001): implement
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ public class BugreportManagerService extends SystemService {
|
||||
@Override
|
||||
public void onStart() {
|
||||
mService = new BugreportManagerServiceImpl(getContext());
|
||||
// TODO(b/111441001): Needs sepolicy to be submitted first.
|
||||
// publishBinderService(Context.BUGREPORT_SERVICE, mService);
|
||||
publishBinderService(Context.BUGREPORT_SERVICE, mService);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import java.io.FileDescriptor;
|
||||
*/
|
||||
class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
||||
private static final String TAG = "BugreportManagerService";
|
||||
private static final String BUGREPORT_SERVICE = "bugreportd";
|
||||
private static final long DEFAULT_BUGREPORT_SERVICE_TIMEOUT_MILLIS = 30 * 1000;
|
||||
|
||||
private IDumpstate mDs = null;
|
||||
@@ -64,6 +65,8 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
||||
throw new UnsupportedOperationException("setListener is not allowed on this service");
|
||||
}
|
||||
|
||||
// TODO(b/111441001): Intercept onFinished here in system server and shutdown
|
||||
// the bugreportd service.
|
||||
@Override
|
||||
@RequiresPermission(android.Manifest.permission.DUMP)
|
||||
public void startBugreport(int callingUidUnused, String callingPackage,
|
||||
@@ -84,6 +87,14 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
||||
bugreportFd, screenshotFd, bugreportMode, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RequiresPermission(android.Manifest.permission.DUMP)
|
||||
public void cancelBugreport() throws RemoteException {
|
||||
// This tells init to cancel bugreportd service.
|
||||
SystemProperties.set("ctl.stop", BUGREPORT_SERVICE);
|
||||
mDs = null;
|
||||
}
|
||||
|
||||
private boolean validate(@BugreportParams.BugreportMode int mode) {
|
||||
if (mode != BugreportParams.BUGREPORT_MODE_FULL
|
||||
&& mode != BugreportParams.BUGREPORT_MODE_INTERACTIVE
|
||||
@@ -107,7 +118,7 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
||||
*/
|
||||
private IDumpstate getDumpstateService() {
|
||||
// Start bugreport service.
|
||||
SystemProperties.set("ctl.start", "bugreport");
|
||||
SystemProperties.set("ctl.start", BUGREPORT_SERVICE);
|
||||
|
||||
IDumpstate ds = null;
|
||||
boolean timedOut = false;
|
||||
|
||||
Reference in New Issue
Block a user