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

Commit bc4ba823 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Remove user switcher from long-press power menu

Bug: 7252218

Also lock the screen before doing the user switch. This prevents the
janky behavior of showing the target user's homescreen after the switch
and then the lock screen. This is also a privacy issue.

Change-Id: I9f8db047335d06fc93505d7b5cca71e27ca3ac39
parent 195b6e12
Loading
Loading
Loading
Loading
+34 −27
Original line number Diff line number Diff line
@@ -286,6 +286,39 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
            mItems.add(mSilentModeAction);
        }

        // one more thing: optionally add a list of users to switch to
        if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
            addUsersToMenu(mItems);
        }

        mAdapter = new MyAdapter();

        AlertParams params = new AlertParams(mContext);
        params.mAdapter = mAdapter;
        params.mOnClickListener = this;
        params.mForceInverseBackground = true;

        GlobalActionsDialog dialog = new GlobalActionsDialog(mContext, params);
        dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.

        dialog.getListView().setItemsCanFocus(true);
        dialog.getListView().setLongClickable(true);
        dialog.getListView().setOnItemLongClickListener(
                new AdapterView.OnItemLongClickListener() {
                    @Override
                    public boolean onItemLongClick(AdapterView<?> parent, View view, int position,
                            long id) {
                        return mAdapter.getItem(position).onLongPress();
                    }
        });
        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);

        dialog.setOnDismissListener(this);

        return dialog;
    }

    private void addUsersToMenu(ArrayList<Action> items) {
        List<UserInfo> users = ((UserManager) mContext.getSystemService(Context.USER_SERVICE))
                .getUsers();
        if (users.size() > 1) {
@@ -320,35 +353,9 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                        return false;
                    }
                };
                mItems.add(switchToUser);
                items.add(switchToUser);
            }
        }

        mAdapter = new MyAdapter();

        AlertParams params = new AlertParams(mContext);
        params.mAdapter = mAdapter;
        params.mOnClickListener = this;
        params.mForceInverseBackground = true;

        GlobalActionsDialog dialog = new GlobalActionsDialog(mContext, params);
        dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.

        dialog.getListView().setItemsCanFocus(true);
        dialog.getListView().setLongClickable(true);
        dialog.getListView().setOnItemLongClickListener(
                new AdapterView.OnItemLongClickListener() {
                    @Override
                    public boolean onItemLongClick(AdapterView<?> parent, View view, int position,
                            long id) {
                        return mAdapter.getItem(position).onLongPress();
                    }
        });
        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);

        dialog.setOnDismissListener(this);

        return dialog;
    }

    private void prepareDialog() {
+1 −0
Original line number Diff line number Diff line
@@ -14057,6 +14057,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    return false;
                }
                mWindowManager.lockNow();
                mWindowManager.startFreezingScreen(R.anim.screen_user_exit,
                        R.anim.screen_user_enter);