Merge "Improvements to Bugreporting API." into rvc-dev am: af730a12bd am: 579689b464

Change-Id: Id3667685e5063b26f053b9330a86d8af6e003448
This commit is contained in:
Automerger Merge Worker
2020-02-29 00:40:13 +00:00
4 changed files with 38 additions and 3 deletions

View File

@@ -27,8 +27,10 @@ import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Handler;
import android.util.Log;
import android.widget.Toast;
import com.android.internal.R;
import com.android.internal.util.Preconditions;
import libcore.io.IoUtils;
@@ -155,12 +157,14 @@ public final class BugreportManager {
Preconditions.checkNotNull(executor);
Preconditions.checkNotNull(callback);
boolean validScreenshotFd = screenshotFd != null;
if (screenshotFd == null) {
// Binder needs a valid File Descriptor to be passed
screenshotFd = ParcelFileDescriptor.open(new File("/dev/null"),
ParcelFileDescriptor.MODE_READ_ONLY);
}
DumpstateListener dsListener = new DumpstateListener(executor, callback);
DumpstateListener dsListener = new DumpstateListener(executor, callback,
validScreenshotFd);
// Note: mBinder can get callingUid from the binder transaction.
mBinder.startBugreport(-1 /* callingUid */,
mContext.getOpPackageName(),
@@ -221,10 +225,13 @@ public final class BugreportManager {
private final class DumpstateListener extends IDumpstateListener.Stub {
private final Executor mExecutor;
private final BugreportCallback mCallback;
private final boolean mValidScreenshotFd;
DumpstateListener(Executor executor, BugreportCallback callback) {
DumpstateListener(Executor executor, BugreportCallback callback,
boolean validScreenshotFd) {
mExecutor = executor;
mCallback = callback;
mValidScreenshotFd = validScreenshotFd;
}
@Override
@@ -262,5 +269,20 @@ public final class BugreportManager {
Binder.restoreCallingIdentity(identity);
}
}
@Override
public void onScreenshotTaken(boolean success) throws RemoteException {
if (!mValidScreenshotFd) {
return;
}
Handler mainThreadHandler = new Handler(Looper.getMainLooper());
mainThreadHandler.post(
() -> {
int message = success ? R.string.bugreport_screenshot_success_toast
: R.string.bugreport_screenshot_failure_toast;
Toast.makeText(mContext, message, Toast.LENGTH_LONG).show();
});
}
}
}

View File

@@ -584,6 +584,12 @@
<!-- Format for build summary info [CHAR LIMIT=NONE] -->
<string name="bugreport_status" translatable="false">%s (%s)</string>
<!-- Toast for taking screenshot with bugreport successfully. [CHAR_LIMIT=100] -->
<string name="bugreport_screenshot_success_toast">Screenshot taken with bug report</string>
<!-- Toast for failed to take screenshot with bugreport. [CHAR_LIMIT=100] -->
<string name="bugreport_screenshot_failure_toast">Failed to take screenshot with bug report</string>
<!-- label for item that enables silent mode in phone options dialog -->
<string name="global_action_toggle_silent_mode">Silent mode</string>

View File

@@ -1789,6 +1789,8 @@
<java-symbol type="string" name="bugreport_option_full_title" />
<java-symbol type="string" name="bugreport_option_interactive_summary" />
<java-symbol type="string" name="bugreport_option_interactive_title" />
<java-symbol type="string" name="bugreport_screenshot_failure_toast" />
<java-symbol type="string" name="bugreport_screenshot_success_toast" />
<java-symbol type="string" name="bugreport_status" />
<java-symbol type="string" name="bugreport_title" />
<java-symbol type="string" name="faceunlock_multiple_failures" />

View File

@@ -275,6 +275,11 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
mListener.onFinished();
}
@Override
public void onScreenshotTaken(boolean success) throws RemoteException {
mListener.onScreenshotTaken(success);
}
@Override
public void binderDied() {
synchronized (mLock) {