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

Commit e974f7ef authored by Felipe Leme's avatar Felipe Leme
Browse files

Changed the action executed when "Take bug report" is selected.

By default, it executes the new, enhanced bugreport (service
'bugreportplus'), which is more user-friendly (it shows a system
notification with the progress, allow user to cancel, etc...), but
causes more interference in the system operations.

But on long press, it executes the old, lighter workflow (service
'bugreport'), which is less user-friendly but causes less
interference (and hence should be used in the cases where the device is
slow or unresponsive).

BUG: 26034608
Change-Id: I6759e4c8c2c2a970d0a2bb99ca3471854d01780a
parent 5144d154
Loading
Loading
Loading
Loading
+55 −55
Original line number Diff line number Diff line
@@ -278,7 +278,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
            } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
                if (Settings.Global.getInt(mContext.getContentResolver(),
                        Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
                    mItems.add(getBugReportAction());
                    mItems.add(new BugReportAction());
                }
            } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
                if (mShowSilentToggle) {
@@ -367,19 +367,14 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
        }
    }

    private Action getBugReportAction() {
        return new SinglePressAction(com.android.internal.R.drawable.ic_lock_bugreport,
                R.string.bugreport_title) {
    private class BugReportAction extends SinglePressAction implements LongPressAction {

        public BugReportAction() {
            super(com.android.internal.R.drawable.ic_lock_bugreport, R.string.bugreport_title);
        }

            public void onPress() {
                AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                builder.setTitle(com.android.internal.R.string.bugreport_title);
                builder.setMessage(com.android.internal.R.string.bugreport_message);
                builder.setNegativeButton(com.android.internal.R.string.cancel, null);
                builder.setPositiveButton(com.android.internal.R.string.report,
                        new DialogInterface.OnClickListener() {
        @Override
                            public void onClick(DialogInterface dialog, int which) {
        public void onPress() {
            // don't actually trigger the bugreport if we are running stability
            // tests via monkey
            if (ActivityManager.isUserAMonkey()) {
@@ -388,27 +383,40 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
            // Add a little delay before executing, to give the
            // dialog a chance to go away before it takes a
            // screenshot.
            // TODO: remove once screenshots are handled by Shell (instead of dumpstate)
            mHandler.postDelayed(new Runnable() {
                                    @Override public void run() {
                                        //  TODO: select 'progress' flag according to menu choice
                @Override
                public void run() {
                    try {
                                            ActivityManagerNative.getDefault()
                                                    .requestBugReport(true);
                        // Take a "heavy" bugreport: it's more user friendly, but causes more
                        // interference.
                        ActivityManagerNative.getDefault().requestBugReport(true);
                    } catch (RemoteException e) {
                    }
                }
            }, 500);
        }
                        });
                AlertDialog dialog = builder.create();
                dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
                dialog.show();

        @Override
        public boolean onLongPress() {
            // don't actually trigger the bugreport if we are running stability
            // tests via monkey
            if (ActivityManager.isUserAMonkey()) {
                return false;
            }
            try {
                // Take a "light" bugreport, with less interference.
                ActivityManagerNative.getDefault().requestBugReport(false);
            } catch (RemoteException e) {
            }
            return true;
        }

        public boolean showDuringKeyguard() {
            return true;
        }

        @Override
        public boolean showBeforeProvisioning() {
            return false;
        }
@@ -420,7 +428,6 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                    Build.VERSION.RELEASE,
                    Build.ID);
        }
        };
    }

    private Action getSettingsAction() {
@@ -742,13 +749,6 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
            mIcon = icon;
        }

        protected SinglePressAction(int iconResId, CharSequence message) {
            mIconResId = iconResId;
            mMessageResId = 0;
            mMessage = message;
            mIcon = null;
        }

        public boolean isEnabled() {
            return true;
        }