diff options
author | 2019-01-23 09:47:56 -0800 | |
---|---|---|
committer | 2019-01-23 09:47:56 -0800 | |
commit | 9de4d6a3f58c13223de25319a972d83f9d34a536 (patch) | |
tree | 0f43463305ea48c07d94ef386452825ad2275f4d | |
parent | 161833f209fc433b8d8c849c86d43f083d030bf9 (diff) | |
parent | 73226aa0f8250875ecab20588dec28477d1f1df5 (diff) |
Merge "Improvements to Bugreporting API." am: 212353c896 am: 42df2e1602
am: 73226aa0f8
Change-Id: I947ffa533288c91b169863a045d71e735486773e
4 files changed, 47 insertions, 18 deletions
diff --git a/core/java/android/os/BugreportManager.java b/core/java/android/os/BugreportManager.java index c5a51f133047..518528dd1a5b 100644 --- a/core/java/android/os/BugreportManager.java +++ b/core/java/android/os/BugreportManager.java @@ -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 diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java index 2d7471d9aca5..a9ff21fef99c 100644 --- a/packages/Shell/src/com/android/shell/BugreportProgressService.java +++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java @@ -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 } diff --git a/services/core/java/com/android/server/os/BugreportManagerService.java b/services/core/java/com/android/server/os/BugreportManagerService.java index e2415911e929..bee7a8b7166e 100644 --- a/services/core/java/com/android/server/os/BugreportManagerService.java +++ b/services/core/java/com/android/server/os/BugreportManagerService.java @@ -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); } } diff --git a/services/core/java/com/android/server/os/BugreportManagerServiceImpl.java b/services/core/java/com/android/server/os/BugreportManagerServiceImpl.java index 1178cc18f828..f736056c5c7f 100644 --- a/services/core/java/com/android/server/os/BugreportManagerServiceImpl.java +++ b/services/core/java/com/android/server/os/BugreportManagerServiceImpl.java @@ -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; |