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

Commit b8a0feed authored by John Spurlock's avatar John Spurlock Committed by Android (Google) Code Review
Browse files

Merge "Resurrect global actions, remove confirmation for Power off." into lmp-preview-dev

parents 05dc18d6 822e5cc4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1538,6 +1538,7 @@
         -->
    <string-array translatable="false" name="config_globalActionsList">
        <item>power</item>
        <item>bugreport</item>
        <item>users</item>
    </string-array>

+38 −45
Original line number Diff line number Diff line
@@ -185,7 +185,8 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac

        // If we only have 1 item and it's a simple press action, just do this action.
        if (mAdapter.getCount() == 1
                && mAdapter.getItem(0) instanceof SinglePressAction) {
                && mAdapter.getItem(0) instanceof SinglePressAction
                && !(mAdapter.getItem(0) instanceof LongPressAction)) {
            ((SinglePressAction) mAdapter.getItem(0)).onPress();
        } else {
            WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
@@ -262,7 +263,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                continue;
            }
            if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
                mItems.add(getPowerAction());
                mItems.add(new PowerAction());
            } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
                mItems.add(mAirplaneModeOn);
            } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)
@@ -300,7 +301,11 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                    @Override
                    public boolean onItemLongClick(AdapterView<?> parent, View view, int position,
                            long id) {
                        return mAdapter.getItem(position).onLongPress();
                        final Action action = mAdapter.getItem(position);
                        if (action instanceof LongPressAction) {
                            return ((LongPressAction) action).onLongPress();
                        }
                        return false;
                    }
        });
        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
@@ -310,29 +315,33 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
        return dialog;
    }

    private Action getPowerAction() {
        return new SinglePressAction(
                com.android.internal.R.drawable.ic_lock_power_off,
                R.string.global_action_power_off) {

            public void onPress() {
                // shutdown by making sure radio and power are handled accordingly.
                mWindowManagerFuncs.shutdown(true);
    private final class PowerAction extends SinglePressAction implements LongPressAction {
        private PowerAction() {
            super(com.android.internal.R.drawable.ic_lock_power_off,
                R.string.global_action_power_off);
        }

        @Override
        public boolean onLongPress() {
            mWindowManagerFuncs.rebootSafeMode(true);
            return true;
        }

        @Override
        public boolean showDuringKeyguard() {
            return true;
        }

        @Override
        public boolean showBeforeProvisioning() {
            return true;
        }
        };

        @Override
        public void onPress() {
            // shutdown by making sure radio and power are handled accordingly.
            mWindowManagerFuncs.shutdown(false /* confirm */);
        }
    }

    private Action getBugReportAction() {
@@ -367,10 +376,6 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                dialog.show();
            }

            public boolean onLongPress() {
                return false;
            }

            public boolean showDuringKeyguard() {
                return true;
            }
@@ -392,11 +397,6 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                mContext.startActivity(intent);
            }

            @Override
            public boolean onLongPress() {
                return false;
            }

            @Override
            public boolean showDuringKeyguard() {
                return true;
@@ -583,8 +583,6 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac

        void onPress();

        public boolean onLongPress();

        /**
         * @return whether this action should appear in the dialog when the keygaurd
         *    is showing.
@@ -600,6 +598,13 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
        boolean isEnabled();
    }

    /**
     * An action that also supports long press.
     */
    private interface LongPressAction extends Action {
        boolean onLongPress();
    }

    /**
     * A single press action maintains no state, just responds to a press
     * and takes an action.
@@ -637,10 +642,6 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac

        abstract public void onPress();

        public boolean onLongPress() {
            return false;
        }

        public View create(
                Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
            View v = inflater.inflate(R.layout.global_actions_item, parent, false);
@@ -769,10 +770,6 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
            changeStateFromPress(nowOn);
        }

        public boolean onLongPress() {
            return false;
        }

        public boolean isEnabled() {
            return !mState.inTransition();
        }
@@ -862,10 +859,6 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
        public void onPress() {
        }

        public boolean onLongPress() {
            return false;
        }

        public boolean showDuringKeyguard() {
            return true;
        }