Skip to content

Commit 4440763

Browse files
Treehugger RobotAndroid (Google) Code Review
Treehugger Robot
authored and
Android (Google) Code Review
committed
Merge "Restart IMM connection when running on automitive visible bkg user" into main
2 parents d85ec01 + 9ef3271 commit 4440763

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

packages/SystemUI/multivalentTests/src/com/android/keyguard/KeyguardPasswordViewControllerTest.kt

+12-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.android.internal.util.LatencyTracker
2929
import com.android.internal.widget.LockPatternUtils
3030
import com.android.internal.widget.LockscreenCredential
3131
import com.android.keyguard.domain.interactor.KeyguardKeyboardInteractor
32+
import com.android.systemui.Flags as AconfigFlags
3233
import com.android.systemui.SysuiTestCase
3334
import com.android.systemui.classifier.FalsingCollector
3435
import com.android.systemui.flags.FakeFeatureFlags
@@ -56,7 +57,6 @@ import org.mockito.Mockito.never
5657
import org.mockito.Mockito.verify
5758
import org.mockito.Mockito.`when`
5859
import org.mockito.MockitoAnnotations
59-
import com.android.systemui.Flags as AconfigFlags
6060

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

189190
val eventHandled =
190-
keyListenerArgumentCaptor.value.onKey(keyguardPasswordView,
191+
keyListenerArgumentCaptor.value.onKey(
192+
keyguardPasswordView,
191193
KeyEvent.KEYCODE_SPACE,
192-
KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SPACE))
194+
KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SPACE)
195+
)
193196

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

206209
val eventHandled =
207-
keyListenerArgumentCaptor.value.onKey(keyguardPasswordView,
210+
keyListenerArgumentCaptor.value.onKey(
211+
keyguardPasswordView,
208212
KeyEvent.KEYCODE_ENTER,
209-
KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER))
213+
KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER)
214+
)
210215

211216
assertTrue("Unlock not attempted.", eventHandled)
212217
}

packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java

+29-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
import static com.android.systemui.flags.Flags.LOCKSCREEN_ENABLE_LANDSCAPE;
2020
import static com.android.systemui.util.kotlin.JavaAdapterKt.collectFlow;
2121

22+
import android.content.Context;
23+
import android.content.pm.PackageManager;
2224
import android.content.res.Resources;
2325
import android.graphics.drawable.Drawable;
2426
import android.os.UserHandle;
27+
import android.os.UserManager;
2528
import android.text.Editable;
2629
import android.text.InputType;
2730
import android.text.TextUtils;
@@ -170,8 +173,33 @@ protected void onViewAttached() {
170173
mPasswordEntry.setOnEditorActionListener(mOnEditorActionListener);
171174
mPasswordEntry.setOnKeyListener(mKeyListener);
172175
mPasswordEntry.addTextChangedListener(mTextWatcher);
176+
173177
// Poke the wakelock any time the text is selected or modified
174-
mPasswordEntry.setOnClickListener(v -> mKeyguardSecurityCallback.userActivity());
178+
// TODO(b/362362385): Revert to the previous onClickListener implementation once this bug is
179+
// fixed.
180+
mPasswordEntry.setOnClickListener(new View.OnClickListener() {
181+
182+
private final boolean mAutomotiveAndVisibleBackgroundUsers =
183+
isAutomotiveAndVisibleBackgroundUsers();
184+
185+
@Override
186+
public void onClick(View v) {
187+
if (mAutomotiveAndVisibleBackgroundUsers) {
188+
mInputMethodManager.restartInput(v);
189+
}
190+
mKeyguardSecurityCallback.userActivity();
191+
}
192+
193+
private boolean isAutomotiveAndVisibleBackgroundUsers() {
194+
final Context context = getContext();
195+
return context.getPackageManager().hasSystemFeature(
196+
PackageManager.FEATURE_AUTOMOTIVE)
197+
&& UserManager.isVisibleBackgroundUsersEnabled()
198+
&& context.getResources().getBoolean(
199+
android.R.bool.config_perDisplayFocusEnabled);
200+
}
201+
});
202+
175203
mSwitchImeButton.setOnClickListener(v -> {
176204
mKeyguardSecurityCallback.userActivity(); // Leave the screen on a bit longer
177205
// Do not show auxiliary subtypes in password lock screen.

0 commit comments

Comments
 (0)