Bugreporting API: Take ownership of fds.

BUG: 126434607
FIXES: 127649051
Test: manual
Change-Id: I39e8421925c53061b6bc2954dffe3bccb7b3314d
This commit is contained in:
Nandana Dutt
2019-03-13 16:42:17 +00:00
parent be80e309ea
commit 9d6ff2968e
2 changed files with 90 additions and 11 deletions

View File

@@ -27,6 +27,8 @@ import android.content.Context;
import com.android.internal.util.Preconditions;
import libcore.io.IoUtils;
import java.io.FileDescriptor;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -123,6 +125,8 @@ public class BugreportManager {
* <p>The bugreport artifacts will be copied over to the given file descriptors only if the
* user consents to sharing with the calling app.
*
* <p>{@link BugreportManager} takes ownership of {@code bugreportFd} and {@code screenshotFd}.
*
* @param bugreportFd file to write the bugreport. This should be opened in write-only,
* append mode.
* @param screenshotFd file to write the screenshot, if necessary. This should be opened
@@ -136,12 +140,13 @@ public class BugreportManager {
@NonNull BugreportParams params,
@NonNull @CallbackExecutor Executor executor,
@NonNull BugreportCallback callback) {
Preconditions.checkNotNull(bugreportFd);
Preconditions.checkNotNull(params);
Preconditions.checkNotNull(executor);
Preconditions.checkNotNull(callback);
DumpstateListener dsListener = new DumpstateListener(executor, callback);
try {
Preconditions.checkNotNull(bugreportFd);
Preconditions.checkNotNull(params);
Preconditions.checkNotNull(executor);
Preconditions.checkNotNull(callback);
DumpstateListener dsListener = new DumpstateListener(executor, callback);
// Note: mBinder can get callingUid from the binder transaction.
mBinder.startBugreport(-1 /* callingUid */,
mContext.getOpPackageName(),
@@ -151,6 +156,12 @@ public class BugreportManager {
params.getMode(), dsListener);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
} finally {
// We can close the file descriptors here because binder would have duped them.
IoUtils.closeQuietly(bugreportFd);
if (screenshotFd != null) {
IoUtils.closeQuietly(screenshotFd);
}
}
}
@@ -170,7 +181,7 @@ public class BugreportManager {
private final Executor mExecutor;
private final BugreportCallback mCallback;
DumpstateListener(Executor executor, @Nullable BugreportCallback callback) {
DumpstateListener(Executor executor, BugreportCallback callback) {
mExecutor = executor;
mCallback = callback;
}