From 5f97880714e0ee2c503bca0d7681e896c53386b0 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Thu, 8 Jun 2017 13:01:13 -0700 Subject: [PATCH] Closes Autofill UIs when back button is pressed. Test: existing CtsAutoFillServiceTestCases pass Test: LoginActivityTest#testSaveGoesAwayWhenTappingBackButton pass Fixes: 62272098 Change-Id: Id34767ca32836f040e04790f0f2935ae49d88d71 --- .../view/autofill/AutofillManagerInternal.java | 29 ++++++++++++++++++++++ .../server/autofill/AutofillManagerService.java | 13 +++++++++- .../android/server/policy/PhoneWindowManager.java | 12 +++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 core/java/android/view/autofill/AutofillManagerInternal.java diff --git a/core/java/android/view/autofill/AutofillManagerInternal.java b/core/java/android/view/autofill/AutofillManagerInternal.java new file mode 100644 index 000000000000..fc5d306ddcef --- /dev/null +++ b/core/java/android/view/autofill/AutofillManagerInternal.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2017 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. + */ +package android.view.autofill; + +/** + * Autofill Manager local system service interface. + * + * @hide Only for use within the system server. + */ +public abstract class AutofillManagerInternal { + + /** + * Notifies the manager that the back key was pressed. + */ + public abstract void onBackKeyPressed(); +} diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java index 03f25bf065d2..e85f96be3160 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java @@ -19,10 +19,10 @@ package com.android.server.autofill; import static android.Manifest.permission.MANAGE_AUTO_FILL; import static android.content.Context.AUTOFILL_MANAGER_SERVICE; +import static com.android.server.autofill.Helper.bundleToString; import static com.android.server.autofill.Helper.sDebug; import static com.android.server.autofill.Helper.sPartitionMaxCount; import static com.android.server.autofill.Helper.sVerbose; -import static com.android.server.autofill.Helper.bundleToString; import android.annotation.NonNull; import android.annotation.Nullable; @@ -58,6 +58,7 @@ import android.util.SparseArray; import android.util.SparseBooleanArray; import android.view.autofill.AutofillId; import android.view.autofill.AutofillManager; +import android.view.autofill.AutofillManagerInternal; import android.view.autofill.AutofillValue; import android.view.autofill.IAutoFillManager; import android.view.autofill.IAutoFillManagerClient; @@ -251,6 +252,7 @@ public final class AutofillManagerService extends SystemService { @Override public void onStart() { publishBinderService(AUTOFILL_MANAGER_SERVICE, new AutoFillManagerServiceStub()); + publishLocalService(AutofillManagerInternal.class, new LocalService()); } @Override @@ -463,6 +465,15 @@ public final class AutofillManagerService extends SystemService { } } + private final class LocalService extends AutofillManagerInternal { + + @Override + public void onBackKeyPressed() { + if (sDebug) Slog.d(TAG, "onBackKeyPressed()"); + mUi.hideAll(null); + } + } + final class AutoFillManagerServiceStub extends IAutoFillManager.Stub { @Override public int addClient(IAutoFillManagerClient client, int userId) { diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 6d46fda27b48..c2c9123170e1 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -221,6 +221,7 @@ import android.view.accessibility.AccessibilityManager; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.AnimationUtils; +import android.view.autofill.AutofillManagerInternal; import android.view.inputmethod.InputMethodManagerInternal; import com.android.internal.R; @@ -407,6 +408,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { WindowManagerInternal mWindowManagerInternal; PowerManager mPowerManager; ActivityManagerInternal mActivityManagerInternal; + AutofillManagerInternal mAutofillManagerInternal; InputManagerInternal mInputManagerInternal; InputMethodManagerInternal mInputMethodManagerInternal; DreamManagerInternal mDreamManagerInternal; @@ -831,6 +833,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { private static final int MSG_ACCESSIBILITY_SHORTCUT = 21; private static final int MSG_BUGREPORT_TV = 22; private static final int MSG_ACCESSIBILITY_TV = 23; + private static final int MSG_DISPATCH_BACK_KEY_TO_AUTOFILL = 24; private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0; private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1; @@ -917,6 +920,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { accessibilityShortcutActivated(); } break; + case MSG_DISPATCH_BACK_KEY_TO_AUTOFILL: + mAutofillManagerInternal.onBackKeyPressed(); + break; } } } @@ -1224,6 +1230,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } + if (mAutofillManagerInternal != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) { + mHandler.sendMessage(mHandler.obtainMessage(MSG_DISPATCH_BACK_KEY_TO_AUTOFILL)); + } + return handled; } @@ -7239,6 +7249,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { mSystemGestures.systemReady(); mImmersiveModeConfirmation.systemReady(); + + mAutofillManagerInternal = LocalServices.getService(AutofillManagerInternal.class); } /** {@inheritDoc} */ -- 2.11.0