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

Commit 6134efab authored by Peter Kalauskas's avatar Peter Kalauskas
Browse files

Restore guest item's original behavior in user switcher

Restore behavior of the guest item in the keyguard user switcher to it's
original behavior:

 - When signed in as guest, the guest item says "Remove guest"

 - When no guest account exists, the guest item says "Add guest"

 - When the guest exists but the current user is not guest, the guest
   item says "Guest"

Additionally:

 - Fix behavior of config_expandLockScreenUserSwitcher and
   lockscreenSimpleUserSwitcher

 - Remove "End guest session" button from keyguard user switcher

 - Remove "End guest session" string from SystemUI

Test: Open keyguard user switcher as guest user
Bug: 169783558
Bug: 181358587
Change-Id: Ibce9b3c7f28467e199db067b4bfb36b9fa35e4b4
parent 37e2f8d5
Loading
Loading
Loading
Loading
+0 −25
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>

<!--
  ~ Copyright (C) 2021 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License
  -->

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <stroke
        android:width="@dimen/end_guest_button_border_size"
        android:color="?android:attr/colorControlHighlight" />
    <corners android:radius="@dimen/end_guest_button_corner_radius" />
</shape>
+0 −30
Original line number Diff line number Diff line
@@ -30,34 +30,4 @@
        android:layout_gravity="top|end"
        android:gravity="end" />

    <LinearLayout
        android:id="@+id/end_guest_button"
        android:layout_height="@dimen/end_guest_button_layout_height"
        android:layout_width="wrap_content"
        android:layout_gravity="center_horizontal|bottom"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="@dimen/end_guest_button_margin_bottom"
        android:orientation="horizontal"
        android:gravity="center"
        android:paddingLeft="@dimen/end_guest_button_padding_horizontal"
        android:paddingRight="@dimen/end_guest_button_padding_horizontal"
        android:background="@drawable/end_guest_button_background"
        android:visibility="gone">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:src="@drawable/ic_exit_to_app"
            android:background="@android:color/transparent"
            android:color="?attr/wallpaperTextColor" />
        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:gravity="center"
            android:fontFamily="@*android:string/config_bodyFontFamilyMedium"
            android:textColor="?attr/wallpaperTextColor"
            android:textSize="13sp"
            android:text="@string/guest_exit_button" />
    </LinearLayout>

</com.android.systemui.statusbar.policy.KeyguardUserSwitcherView>
+0 −7
Original line number Diff line number Diff line
@@ -1333,13 +1333,6 @@
    <!-- Keyguard user switcher -->
    <dimen name="kg_user_switcher_text_size">16sp</dimen>

    <!-- End guest session button -->
    <dimen name="end_guest_button_layout_height">32dp</dimen>
    <dimen name="end_guest_button_padding_horizontal">16dp</dimen>
    <dimen name="end_guest_button_margin_bottom">96dp</dimen>
    <dimen name="end_guest_button_border_size">1dp</dimen>
    <dimen name="end_guest_button_corner_radius">16dp</dimen>

    <!-- Opacity at which the background for the shutdown UI will be drawn. -->
    <item name="shutdown_scrim_behind_alpha" format="float" type="dimen">0.95</item>

+0 −3
Original line number Diff line number Diff line
@@ -1121,9 +1121,6 @@
    <!-- Name for a freshly added user [CHAR LIMIT=30] -->
    <string name="user_new_user_name">New user</string>

    <!-- Label for button that exits guest session and clears the guest user data [CHAR LIMIT=50]-->
    <string name="guest_exit_button">End guest session</string>

    <!-- Title of the confirmation dialog when exiting guest session [CHAR LIMIT=NONE] -->
    <string name="guest_exit_guest_dialog_title">Remove guest?</string>

+12 −72
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.android.keyguard.KeyguardConstants;
import com.android.keyguard.KeyguardUpdateMonitor;
@@ -83,12 +82,10 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS

    // Child views of KeyguardUserSwitcherView
    private KeyguardUserSwitcherListView mListView;
    private LinearLayout mEndGuestButton;

    // State info for the user switcher
    private boolean mUserSwitcherOpen;
    private int mCurrentUserId = UserHandle.USER_NULL;
    private boolean mCurrentUserIsGuest;
    private int mBarState;
    private float mDarkAmount;

@@ -185,11 +182,6 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
        if (DEBUG) Log.d(TAG, "onInit");

        mListView = mView.findViewById(R.id.keyguard_user_switcher_list);
        mEndGuestButton = mView.findViewById(R.id.end_guest_button);

        mEndGuestButton.setOnClickListener(v -> {
            mUserSwitcherController.showExitGuestDialog(mCurrentUserId);
        });

        mView.setOnTouchListener((v, event) -> {
            if (!isListAnimating()) {
@@ -209,10 +201,15 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
        mKeyguardUpdateMonitor.registerCallback(mInfoCallback);
        mStatusBarStateController.addCallback(mStatusBarStateListener);
        mScreenLifecycle.addObserver(mScreenObserver);
        if (isSimpleUserSwitcher()) {
            // Don't use the background for the simple user switcher
            setUserSwitcherOpened(true /* open */, true /* animate */);
        } else {
            mView.addOnLayoutChangeListener(mBackground);
            mView.setBackground(mBackground);
            mBackground.setAlpha(0);
        }
    }

    @Override
    protected void onViewDetached() {
@@ -291,7 +288,6 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
                    }
                    foundCurrentUser = true;
                    mCurrentUserId = userTag.info.id;
                    mCurrentUserIsGuest = userTag.isGuest;
                    // Current user is always visible
                    newView.updateVisibilities(true /* showItem */,
                            mUserSwitcherOpen /* showTextName */, false /* animate */);
@@ -317,7 +313,6 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
        if (!foundCurrentUser) {
            Log.w(TAG, "Current user is not listed");
            mCurrentUserId = UserHandle.USER_NULL;
            mCurrentUserIsGuest = false;
        }
    }

@@ -398,7 +393,6 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS

    private void updateVisibilities(boolean animate) {
        if (DEBUG) Log.d(TAG, String.format("updateVisibilities: animate=%b", animate));
        mEndGuestButton.animate().cancel();
        if (mBgAnimator != null) {
            mBgAnimator.cancel();
        }
@@ -426,44 +420,6 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
            });
            mBgAnimator.start();
        }

        if (mUserSwitcherOpen && mCurrentUserIsGuest) {
            // Show the "End guest session" button
            mEndGuestButton.setVisibility(View.VISIBLE);
            if (animate) {
                mEndGuestButton.setAlpha(0f);
                mEndGuestButton.animate()
                        .alpha(1f)
                        .setDuration(360)
                        .setInterpolator(Interpolators.ALPHA_IN)
                        .withEndAction(() -> {
                            mEndGuestButton.setClickable(true);
                        });
            } else {
                mEndGuestButton.setClickable(true);
                mEndGuestButton.setAlpha(1f);
            }
        } else {
            // Hide the "End guest session" button. If it's already GONE, don't try to
            // animate it or it will appear again for an instant.
            mEndGuestButton.setClickable(false);
            if (animate && mEndGuestButton.getVisibility() != View.GONE) {
                mEndGuestButton.setVisibility(View.VISIBLE);
                mEndGuestButton.setAlpha(1f);
                mEndGuestButton.animate()
                        .alpha(0f)
                        .setDuration(360)
                        .setInterpolator(Interpolators.ALPHA_OUT)
                        .withEndAction(() -> {
                            mEndGuestButton.setVisibility(View.GONE);
                            mEndGuestButton.setAlpha(1f);
                        });
            } else {
                mEndGuestButton.setVisibility(View.GONE);
                mEndGuestButton.setAlpha(1f);
            }
        }

        mListView.updateVisibilities(mUserSwitcherOpen, animate);
    }

@@ -524,15 +480,6 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
            return createUserDetailItemView(convertView, parent, item);
        }

        @Override
        public String getName(Context context, UserSwitcherController.UserRecord item) {
            if (item.isGuest) {
                return context.getString(com.android.settingslib.R.string.guest_nickname);
            } else {
                return super.getName(context, item);
            }
        }

        KeyguardUserDetailItemView convertOrInflate(View convertView, ViewGroup parent) {
            if (!(convertView instanceof KeyguardUserDetailItemView)
                    || !(convertView.getTag() instanceof UserSwitcherController.UserRecord)) {
@@ -600,18 +547,11 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
            }

            if (mKeyguardUserSwitcherController.isUserSwitcherOpen()) {
                if (user.isCurrent) {
                    // Close the switcher if tapping the current user
                    mKeyguardUserSwitcherController.setUserSwitcherOpened(
                            false /* open */, true /* animate */);
                } else if (user.isSwitchToEnabled) {
                    if (!user.isAddUser && !user.isRestricted && !user.isDisabledByAdmin) {
                        if (mCurrentUserView != null) {
                            mCurrentUserView.setActivated(false);
                        }
                        v.setActivated(true);
                    }
                if (!user.isCurrent || user.isGuest) {
                    onUserListItemClicked(user);
                } else {
                    mKeyguardUserSwitcherController.closeSwitcherIfOpenAndNotSimple(
                            true /* animate */);
                }
            } else {
                // If switcher is closed, tapping anywhere in the view will open it