From 2a35e6db849bd7c844bb87e7ef3f43b24bed4043 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Sat, 13 Jan 2018 14:27:50 -0800 Subject: [PATCH] Fix a couple PIP related issues. - Only show settings button when in the full PIP menu (71709327) - Fix issue with PIP not moving with keyboard due to new callback order (71584422) - Make home button consistent with recents button when in an activity over the lockscreen (64137485). When you tap home, it will now prompt you to unlock before going home (and auto-entering PIP if the app supports it) Bug: 71709327 Bug: 71584422 Bug: 64137485 Test: Manual, ensure that pip shifts with keyboard and verify that it launches into PIP from show-over-lockscreen activity Change-Id: I9122b7e20a5bfe82b32c8b576bd4fa11b5659c31 --- .../policy/KeyguardDismissCallback.java | 41 +++++++++++++++++++ .../systemui/pip/phone/PipMenuActivity.java | 2 +- .../server/am/ActivityManagerService.java | 13 +----- .../server/policy/PhoneWindowManager.java | 39 ++++++++++-------- .../server/wm/PinnedStackController.java | 13 ++++-- 5 files changed, 74 insertions(+), 34 deletions(-) create mode 100644 core/java/com/android/internal/policy/KeyguardDismissCallback.java diff --git a/core/java/com/android/internal/policy/KeyguardDismissCallback.java b/core/java/com/android/internal/policy/KeyguardDismissCallback.java new file mode 100644 index 0000000000000..38337ec6f274a --- /dev/null +++ b/core/java/com/android/internal/policy/KeyguardDismissCallback.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2018 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 com.android.internal.policy; + +import android.os.RemoteException; +import com.android.internal.policy.IKeyguardDismissCallback; + +/** + * @hide + */ +public class KeyguardDismissCallback extends IKeyguardDismissCallback.Stub { + + @Override + public void onDismissError() throws RemoteException { + // To be overidden + } + + @Override + public void onDismissSucceeded() throws RemoteException { + // To be overidden + } + + @Override + public void onDismissCancelled() throws RemoteException { + // To be overidden + } +} diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java index bfe07a980ce7c..0486a9dcca744 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java @@ -373,7 +373,7 @@ public class PipMenuActivity extends Activity { if (menuState == MENU_STATE_FULL) { mMenuContainerAnimator.playTogether(menuAnim, settingsAnim, dismissAnim); } else { - mMenuContainerAnimator.playTogether(settingsAnim, dismissAnim); + mMenuContainerAnimator.playTogether(dismissAnim); } mMenuContainerAnimator.setInterpolator(Interpolators.ALPHA_IN); mMenuContainerAnimator.setDuration(MENU_FADE_DURATION); diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 3dc237db137ec..14d84a3e7fbbc 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -397,6 +397,7 @@ import com.android.internal.os.ProcessCpuTracker; import com.android.internal.os.TransferPipe; import com.android.internal.os.Zygote; import com.android.internal.policy.IKeyguardDismissCallback; +import com.android.internal.policy.KeyguardDismissCallback; import com.android.internal.telephony.TelephonyIntents; import com.android.internal.util.ArrayUtils; import com.android.internal.util.DumpUtils; @@ -8386,21 +8387,11 @@ public class ActivityManagerService extends IActivityManager.Stub // entering picture-in-picture (this will prompt the user to authenticate if the // device is currently locked). try { - dismissKeyguard(token, new IKeyguardDismissCallback.Stub() { - @Override - public void onDismissError() throws RemoteException { - // Do nothing - } - + dismissKeyguard(token, new KeyguardDismissCallback() { @Override public void onDismissSucceeded() throws RemoteException { mHandler.post(enterPipRunnable); } - - @Override - public void onDismissCancelled() throws RemoteException { - // Do nothing - } }, null /* message */); } catch (RemoteException e) { // Local call diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index f722542f65512..7df417159f502 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -266,6 +266,7 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.logging.MetricsLogger; import com.android.internal.policy.IKeyguardDismissCallback; import com.android.internal.policy.IShortcutService; +import com.android.internal.policy.KeyguardDismissCallback; import com.android.internal.policy.PhoneWindow; import com.android.internal.statusbar.IStatusBarService; import com.android.internal.util.ArrayUtils; @@ -4203,20 +4204,23 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (isKeyguardShowingAndNotOccluded()) { // don't launch home if keyguard showing return; - } - - if (!mKeyguardOccluded && mKeyguardDelegate.isInputRestricted()) { + } else if (mKeyguardOccluded && mKeyguardDelegate.isShowing()) { + mKeyguardDelegate.dismiss(new KeyguardDismissCallback() { + @Override + public void onDismissSucceeded() throws RemoteException { + mHandler.post(() -> { + startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); + }); + } + }, null /* message */); + return; + } else if (!mKeyguardOccluded && mKeyguardDelegate.isInputRestricted()) { // when in keyguard restricted mode, must first verify unlock // before launching home mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { @Override public void onKeyguardExitResult(boolean success) { if (success) { - try { - ActivityManager.getService().stopAppSwitches(); - } catch (RemoteException e) { - } - sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); } } @@ -4226,11 +4230,11 @@ public class PhoneWindowManager implements WindowManagerPolicy { } // no keyguard stuff to worry about, just launch home! - try { - ActivityManager.getService().stopAppSwitches(); - } catch (RemoteException e) { - } if (mRecentsVisible) { + try { + ActivityManager.getService().stopAppSwitches(); + } catch (RemoteException e) {} + // Hide Recents and notify it to launch Home if (awakenFromDreams) { awakenDreams(); @@ -4238,7 +4242,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { hideRecentApps(false, true); } else { // Otherwise, just launch Home - sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); } } @@ -7631,6 +7634,11 @@ public class PhoneWindowManager implements WindowManagerPolicy { } void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { + try { + ActivityManager.getService().stopAppSwitches(); + } catch (RemoteException e) {} + sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); + if (awakenFromDreams) { awakenDreams(); } @@ -7670,11 +7678,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { } if (false) { // This code always brings home to the front. - try { - ActivityManager.getService().stopAppSwitches(); - } catch (RemoteException e) { - } - sendCloseSystemWindows(); startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); } else { // This code brings home to the front or, if it is already diff --git a/services/core/java/com/android/server/wm/PinnedStackController.java b/services/core/java/com/android/server/wm/PinnedStackController.java index 69cbe4607cf18..62519e12d5d98 100644 --- a/services/core/java/com/android/server/wm/PinnedStackController.java +++ b/services/core/java/com/android/server/wm/PinnedStackController.java @@ -360,14 +360,19 @@ class PinnedStackController { * Sets the Ime state and height. */ void setAdjustedForIme(boolean adjustedForIme, int imeHeight) { - // Return early if there is no state change - if (mIsImeShowing == adjustedForIme && mImeHeight == imeHeight) { + // Due to the order of callbacks from the system, we may receive an ime height even when + // {@param adjustedForIme} is false, and also a zero height when {@param adjustedForIme} + // is true. Instead, ensure that the ime state changes with the height and if the ime is + // showing, then the height is non-zero. + final boolean imeShowing = adjustedForIme && imeHeight > 0; + imeHeight = imeShowing ? imeHeight : 0; + if (imeShowing == mIsImeShowing && imeHeight == mImeHeight) { return; } - mIsImeShowing = adjustedForIme; + mIsImeShowing = imeShowing; mImeHeight = imeHeight; - notifyImeVisibilityChanged(adjustedForIme, imeHeight); + notifyImeVisibilityChanged(imeShowing, imeHeight); notifyMovementBoundsChanged(true /* fromImeAdjustment */); }