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

Commit 92232a80 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Restart IMM connection when running on automitive visible bkg user" into main

parents 9a6338cd 48adff60
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.internal.util.LatencyTracker
import com.android.internal.widget.LockPatternUtils
import com.android.internal.widget.LockscreenCredential
import com.android.keyguard.domain.interactor.KeyguardKeyboardInteractor
import com.android.systemui.Flags as AconfigFlags
import com.android.systemui.SysuiTestCase
import com.android.systemui.classifier.FalsingCollector
import com.android.systemui.flags.FakeFeatureFlags
@@ -56,7 +57,6 @@ import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import org.mockito.MockitoAnnotations
import com.android.systemui.Flags as AconfigFlags

@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -66,8 +66,7 @@ import com.android.systemui.Flags as AconfigFlags
class KeyguardPasswordViewControllerTest : SysuiTestCase() {
    @Mock private lateinit var keyguardPasswordView: KeyguardPasswordView
    @Mock private lateinit var passwordEntry: EditText
    private var passwordEntryLayoutParams =
        ViewGroup.LayoutParams(/* width = */ 0, /* height = */ 0)
    private var passwordEntryLayoutParams = ViewGroup.LayoutParams(/* width= */ 0, /* height= */ 0)
    @Mock lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
    @Mock lateinit var securityMode: KeyguardSecurityModel.SecurityMode
    @Mock lateinit var lockPatternUtils: LockPatternUtils
@@ -106,6 +105,8 @@ class KeyguardPasswordViewControllerTest : SysuiTestCase() {
        whenever(keyguardPasswordView.findViewById<ImageView>(R.id.switch_ime_button))
            .thenReturn(mock(ImageView::class.java))
        `when`(keyguardPasswordView.resources).thenReturn(context.resources)
        // TODO(b/362362385): No need to mock keyguardPasswordView.context once this bug is fixed.
        `when`(keyguardPasswordView.context).thenReturn(context)
        whenever(passwordEntry.layoutParams).thenReturn(passwordEntryLayoutParams)
        val keyguardKeyboardInteractor = KeyguardKeyboardInteractor(FakeKeyboardRepository())
        val fakeFeatureFlags = FakeFeatureFlags()
@@ -187,9 +188,11 @@ class KeyguardPasswordViewControllerTest : SysuiTestCase() {
        verify(passwordEntry).setOnKeyListener(keyListenerArgumentCaptor.capture())

        val eventHandled =
            keyListenerArgumentCaptor.value.onKey(keyguardPasswordView,
            keyListenerArgumentCaptor.value.onKey(
                keyguardPasswordView,
                KeyEvent.KEYCODE_SPACE,
                KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SPACE))
                KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SPACE)
            )

        assertFalse("Unlock attempted.", eventHandled)
    }
@@ -204,9 +207,11 @@ class KeyguardPasswordViewControllerTest : SysuiTestCase() {
        verify(passwordEntry).setOnKeyListener(keyListenerArgumentCaptor.capture())

        val eventHandled =
            keyListenerArgumentCaptor.value.onKey(keyguardPasswordView,
            keyListenerArgumentCaptor.value.onKey(
                keyguardPasswordView,
                KeyEvent.KEYCODE_ENTER,
                KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER))
                KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER)
            )

        assertTrue("Unlock not attempted.", eventHandled)
    }
+29 −1
Original line number Diff line number Diff line
@@ -19,9 +19,12 @@ package com.android.keyguard;
import static com.android.systemui.flags.Flags.LOCKSCREEN_ENABLE_LANDSCAPE;
import static com.android.systemui.util.kotlin.JavaAdapterKt.collectFlow;

import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
@@ -170,8 +173,33 @@ public class KeyguardPasswordViewController
        mPasswordEntry.setOnEditorActionListener(mOnEditorActionListener);
        mPasswordEntry.setOnKeyListener(mKeyListener);
        mPasswordEntry.addTextChangedListener(mTextWatcher);

        // Poke the wakelock any time the text is selected or modified
        mPasswordEntry.setOnClickListener(v -> mKeyguardSecurityCallback.userActivity());
        // TODO(b/362362385): Revert to the previous onClickListener implementation once this bug is
        //  fixed.
        mPasswordEntry.setOnClickListener(new View.OnClickListener() {

            private final boolean mAutomotiveAndVisibleBackgroundUsers =
                    isAutomotiveAndVisibleBackgroundUsers();

            @Override
            public void onClick(View v) {
                if (mAutomotiveAndVisibleBackgroundUsers) {
                    mInputMethodManager.restartInput(v);
                }
                mKeyguardSecurityCallback.userActivity();
            }

            private boolean isAutomotiveAndVisibleBackgroundUsers() {
                final Context context = getContext();
                return context.getPackageManager().hasSystemFeature(
                        PackageManager.FEATURE_AUTOMOTIVE)
                        && UserManager.isVisibleBackgroundUsersEnabled()
                        && context.getResources().getBoolean(
                        android.R.bool.config_perDisplayFocusEnabled);
            }
        });

        mSwitchImeButton.setOnClickListener(v -> {
            mKeyguardSecurityCallback.userActivity(); // Leave the screen on a bit longer
            // Do not show auxiliary subtypes in password lock screen.