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

Commit bb821889 authored by Aaron Liu's avatar Aaron Liu
Browse files

[Bouncer] Add manage users to bouncer.

Add a manage users option to the user switcher for the Bouncer.
This adds a isMangeUsers property to the UserRecord and makes some
changes around that.

If user is on bouncer while trying to go to manage users or add a child
user, bouncer will show a message to indicate that user needs to unlock
the device in order to proceed.

Bug: 241811308
Test: Added a unit test and manual test. Manual test consists of testing
with new userswitcher code flag on and off, testing non fullscreen user
switcher, user switcher activity, and user switcher in the bouncer. In
addition to testing the manage users. I've added the max number of users and tested add user and add child user. I also tested scenarios where we click on manage users and then exit bouncer.

Change-Id: Ib20c32914fd95eb891676028b5b588009b9e50a6
parent 17976479
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -241,4 +241,6 @@
    <string name="clock_title_bubble">Bubble</string>
    <!-- Name of the "Analog" clock face [CHAR LIMIT=15]-->
    <string name="clock_title_analog">Analog</string>
    <!-- Title of bouncer when we want to authenticate before continuing with action. [CHAR LIMIT=NONE] -->
    <string name="keyguard_unlock_to_continue">Unlock your device to continue</string>
</resources>
+27 −26
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ import android.view.ViewGroup;
import android.view.WindowInsets;
import android.view.WindowInsetsAnimation;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
@@ -318,7 +317,8 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
    }

    void initMode(@Mode int mode, GlobalSettings globalSettings, FalsingManager falsingManager,
            UserSwitcherController userSwitcherController) {
            UserSwitcherController userSwitcherController,
            UserSwitcherViewMode.UserSwitcherCallback userSwitcherCallback) {
        if (mCurrentMode == mode) return;
        Log.i(TAG, "Switching mode from " + modeToString(mCurrentMode) + " to "
                + modeToString(mode));
@@ -330,7 +330,7 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
                mViewMode = new OneHandedViewMode();
                break;
            case MODE_USER_SWITCHER:
                mViewMode = new UserSwitcherViewMode();
                mViewMode = new UserSwitcherViewMode(userSwitcherCallback);
                break;
            default:
                mViewMode = new DefaultViewMode();
@@ -864,6 +864,12 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
        private UserSwitcherController.UserSwitchCallback mUserSwitchCallback =
                this::setupUserSwitcher;

        private UserSwitcherCallback mUserSwitcherCallback;

        UserSwitcherViewMode(UserSwitcherCallback userSwitcherCallback) {
            mUserSwitcherCallback = userSwitcherCallback;
        }

        @Override
        public void init(@NonNull ConstraintLayout v, @NonNull GlobalSettings globalSettings,
                @NonNull KeyguardSecurityViewFlipper viewFlipper,
@@ -1040,33 +1046,24 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
                }
            };

            if (adapter.getCount() < 2) {
                // The drop down arrow is at index 1
                ((LayerDrawable) mUserSwitcher.getBackground()).getDrawable(1).setAlpha(0);
                anchor.setClickable(false);
                return;
            } else {
                ((LayerDrawable) mUserSwitcher.getBackground()).getDrawable(1).setAlpha(255);
            }

            anchor.setOnClickListener((v) -> {
                if (mFalsingManager.isFalseTap(LOW_PENALTY)) return;
                mPopup = new KeyguardUserSwitcherPopupMenu(v.getContext(), mFalsingManager);
                mPopup.setAnchorView(anchor);
                mPopup.setAdapter(adapter);
                mPopup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        public void onItemClick(AdapterView parent, View view, int pos, long id) {
                mPopup.setOnItemClickListener((parent, view, pos, id) -> {
                    if (mFalsingManager.isFalseTap(LOW_PENALTY)) return;
                    if (!view.isEnabled()) return;

                    // Subtract one for the header
                    UserRecord user = adapter.getItem(pos - 1);
                    if (user.isManageUsers || user.isAddSupervisedUser) {
                        mUserSwitcherCallback.showUnlockToContinueMessage();
                    }
                    if (!user.isCurrent) {
                        adapter.onUserListItemClicked(user);
                    }
                    mPopup.dismiss();
                    mPopup = null;
                        }
                });
                mPopup.show();
            });
@@ -1122,6 +1119,10 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
                constraintSet.applyTo(mView);
            }
        }

        interface UserSwitcherCallback {
            void showUnlockToContinueMessage();
        }
    }

    /**
+3 −1
Original line number Diff line number Diff line
@@ -620,7 +620,9 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
            mode = KeyguardSecurityContainer.MODE_ONE_HANDED;
        }

        mView.initMode(mode, mGlobalSettings, mFalsingManager, mUserSwitcherController);
        mView.initMode(mode, mGlobalSettings, mFalsingManager, mUserSwitcherController,
                () -> showMessage(getContext().getString(R.string.keyguard_unlock_to_continue),
                        null));
    }

    public void reportFailedUnlockAttempt(int userId, int timeoutMs) {
+3 −2
Original line number Diff line number Diff line
@@ -35,8 +35,8 @@ protected constructor(
    protected val controller: UserSwitcherController,
) : BaseAdapter() {

    protected open val users: ArrayList<UserRecord>
        get() = controller.users
    protected open val users: List<UserRecord>
        get() = controller.users.filter { !controller.isKeyguardShowing || !it.isRestricted }

    init {
        controller.addAdapter(WeakReference(this))
@@ -112,6 +112,7 @@ protected constructor(
                    item.isGuest,
                    item.isAddSupervisedUser,
                    isTablet,
                    item.isManageUsers,
                )
            return checkNotNull(context.getDrawable(iconRes))
        }
+2 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import com.android.systemui.user.data.source.UserRecord;
import com.android.systemui.util.ViewController;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

@@ -456,7 +457,7 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
        }

        void refreshUserOrder() {
            ArrayList<UserRecord> users = super.getUsers();
            List<UserRecord> users = super.getUsers();
            mUsersOrdered = new ArrayList<>(users.size());
            for (int i = 0; i < users.size(); i++) {
                UserRecord record = users.get(i);
Loading