Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4c88c8e authored by Paul Chang's avatar Paul Chang Committed by Android (Google) Code Review
Browse files

Merge "Improvements to Bugreporting API."

parents ee5e2258 1f627bda
Loading
Loading
Loading
Loading
+25 −3
Original line number Diff line number Diff line
@@ -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();
                    });
        }
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -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>

+2 −0
Original line number Diff line number Diff line
@@ -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" />
+5 −0
Original line number Diff line number Diff line
@@ -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) {