Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.statusbar.phone; |
| 16 | |
| 17 | import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_ALT; |
| 18 | import static android.app.StatusBarManager.NAVIGATION_HINT_IME_SHOWN; |
| 19 | import static android.app.StatusBarManager.WINDOW_STATE_SHOWING; |
| 20 | import static android.app.StatusBarManager.windowStateToString; |
| 21 | |
Mike Digman | ab65025 | 2018-03-06 11:01:41 -0800 | [diff] [blame] | 22 | import static com.android.internal.view.RotationPolicy.NATURAL_ROTATION; |
| 23 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 24 | import static com.android.systemui.shared.system.NavigationBarCompat.InteractionType; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 25 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 26 | import static com.android.systemui.statusbar.phone.StatusBar.DEBUG_WINDOW_STATE; |
| 27 | import static com.android.systemui.statusbar.phone.StatusBar.dumpBarTransitions; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 28 | import static com.android.systemui.OverviewProxyService.OverviewProxyListener; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 29 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 30 | import android.accessibilityservice.AccessibilityServiceInfo; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 31 | import android.animation.Animator; |
| 32 | import android.animation.AnimatorListenerAdapter; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 33 | import android.animation.ObjectAnimator; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 34 | import android.annotation.IdRes; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 35 | import android.annotation.Nullable; |
| 36 | import android.app.ActivityManager; |
| 37 | import android.app.ActivityManagerNative; |
| 38 | import android.app.Fragment; |
| 39 | import android.app.IActivityManager; |
| 40 | import android.app.StatusBarManager; |
| 41 | import android.content.BroadcastReceiver; |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 42 | import android.content.ContentResolver; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 43 | import android.content.Context; |
| 44 | import android.content.Intent; |
| 45 | import android.content.IntentFilter; |
| 46 | import android.content.res.Configuration; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 47 | import android.database.ContentObserver; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 48 | import android.graphics.PixelFormat; |
| 49 | import android.graphics.Rect; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 50 | import android.graphics.drawable.AnimatedVectorDrawable; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 51 | import android.inputmethodservice.InputMethodService; |
| 52 | import android.os.Binder; |
| 53 | import android.os.Bundle; |
| 54 | import android.os.Handler; |
| 55 | import android.os.IBinder; |
| 56 | import android.os.Message; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 57 | import android.os.RemoteException; |
| 58 | import android.os.UserHandle; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 59 | import android.provider.Settings; |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 60 | import android.support.annotation.VisibleForTesting; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 61 | import android.telecom.TelecomManager; |
| 62 | import android.text.TextUtils; |
| 63 | import android.util.Log; |
| 64 | import android.view.IRotationWatcher.Stub; |
| 65 | import android.view.KeyEvent; |
| 66 | import android.view.LayoutInflater; |
| 67 | import android.view.MotionEvent; |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 68 | import android.view.Surface; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 69 | import android.view.View; |
| 70 | import android.view.ViewGroup; |
| 71 | import android.view.WindowManager; |
| 72 | import android.view.WindowManager.LayoutParams; |
| 73 | import android.view.WindowManagerGlobal; |
| 74 | import android.view.accessibility.AccessibilityEvent; |
| 75 | import android.view.accessibility.AccessibilityManager; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 76 | import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 77 | |
| 78 | import com.android.internal.logging.MetricsLogger; |
| 79 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | ea03be1 | 2017-12-04 11:08:41 -0500 | [diff] [blame] | 80 | import com.android.internal.util.LatencyTracker; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 81 | import com.android.systemui.Dependency; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 82 | import com.android.systemui.Interpolators; |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 83 | import com.android.systemui.OverviewProxyService; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 84 | import com.android.systemui.R; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 85 | import com.android.systemui.SysUiServiceProvider; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 86 | import com.android.systemui.assist.AssistManager; |
| 87 | import com.android.systemui.fragments.FragmentHostManager; |
| 88 | import com.android.systemui.fragments.FragmentHostManager.FragmentListener; |
| 89 | import com.android.systemui.recents.Recents; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 90 | import com.android.systemui.recents.misc.SysUiTaskStackChangeListener; |
| 91 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Matthew Ng | 64543e6 | 2018-02-28 17:35:10 -0800 | [diff] [blame] | 92 | import com.android.systemui.shared.system.WindowManagerWrapper; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 93 | import com.android.systemui.stackdivider.Divider; |
| 94 | import com.android.systemui.statusbar.CommandQueue; |
| 95 | import com.android.systemui.statusbar.CommandQueue.Callbacks; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 96 | import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 97 | import com.android.systemui.statusbar.policy.KeyButtonDrawable; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 98 | import com.android.systemui.statusbar.policy.KeyButtonView; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 99 | import com.android.systemui.statusbar.policy.RotationLockController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 100 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
| 101 | |
| 102 | import java.io.FileDescriptor; |
| 103 | import java.io.PrintWriter; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 104 | import java.util.List; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 105 | import java.util.Locale; |
| 106 | |
| 107 | /** |
| 108 | * Fragment containing the NavigationBarFragment. Contains logic for what happens |
| 109 | * on clicks and view states of the nav bar. |
| 110 | */ |
| 111 | public class NavigationBarFragment extends Fragment implements Callbacks { |
| 112 | |
Jason Monk | d4afe15 | 2017-05-01 15:37:43 -0400 | [diff] [blame] | 113 | public static final String TAG = "NavigationBar"; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 114 | private static final boolean DEBUG = false; |
Mike Digman | 3e33da6 | 2018-03-14 16:25:11 -0700 | [diff] [blame] | 115 | private static final boolean DEBUG_ROTATION = true; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 116 | private static final String EXTRA_DISABLE_STATE = "disabled_state"; |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 117 | private static final String EXTRA_DISABLE2_STATE = "disabled2_state"; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 118 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 119 | private final static int BUTTON_FADE_IN_OUT_DURATION_MS = 100; |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 120 | private final static int NAVBAR_HIDDEN_PENDING_ICON_TIMEOUT_MS = 20000; |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 121 | |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 122 | private static final int NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION = 3; |
| 123 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 124 | /** Allow some time inbetween the long press for back and recents. */ |
| 125 | private static final int LOCK_TO_APP_GESTURE_TOLERENCE = 200; |
| 126 | |
| 127 | protected NavigationBarView mNavigationBarView = null; |
| 128 | protected AssistManager mAssistManager; |
| 129 | |
| 130 | private int mNavigationBarWindowState = WINDOW_STATE_SHOWING; |
| 131 | |
| 132 | private int mNavigationIconHints = 0; |
| 133 | private int mNavigationBarMode; |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 134 | private boolean mAccessibilityFeedbackEnabled; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 135 | private AccessibilityManager mAccessibilityManager; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 136 | private MagnificationContentObserver mMagnificationObserver; |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 137 | private ContentResolver mContentResolver; |
Mike Digman | c94759d | 2018-01-23 11:01:21 -0800 | [diff] [blame] | 138 | private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 139 | |
| 140 | private int mDisabledFlags1; |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 141 | private int mDisabledFlags2; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 142 | private StatusBar mStatusBar; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 143 | private Recents mRecents; |
| 144 | private Divider mDivider; |
| 145 | private WindowManager mWindowManager; |
| 146 | private CommandQueue mCommandQueue; |
| 147 | private long mLastLockToAppLongPress; |
| 148 | |
| 149 | private Locale mLocale; |
| 150 | private int mLayoutDirection; |
| 151 | |
| 152 | private int mSystemUiVisibility; |
| 153 | private LightBarController mLightBarController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 154 | |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 155 | private OverviewProxyService mOverviewProxyService; |
| 156 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 157 | public boolean mHomeBlockedThisTouch; |
| 158 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 159 | private int mLastRotationSuggestion; |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 160 | private boolean mPendingRotationSuggestion; |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 161 | private boolean mHoveringRotationSuggestion; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 162 | private RotationLockController mRotationLockController; |
| 163 | private TaskStackListenerImpl mTaskStackListener; |
| 164 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 165 | private final Runnable mRemoveRotationProposal = () -> setRotateSuggestionButtonState(false); |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 166 | private final Runnable mCancelPendingRotationProposal = |
| 167 | () -> mPendingRotationSuggestion = false; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 168 | private Animator mRotateHideAnimator; |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 169 | private ViewRippler mViewRippler = new ViewRippler(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 170 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 171 | private final OverviewProxyListener mOverviewProxyListener = new OverviewProxyListener() { |
| 172 | @Override |
| 173 | public void onConnectionChanged(boolean isConnected) { |
Winson Chung | f9e3027 | 2018-03-26 17:25:36 -0700 | [diff] [blame^] | 174 | mNavigationBarView.updateStates(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 175 | updateScreenPinningGestures(); |
Matthew Ng | 64543e6 | 2018-02-28 17:35:10 -0800 | [diff] [blame] | 176 | WindowManagerWrapper.getInstance() |
| 177 | .setNavBarVirtualKeyHapticFeedbackEnabled(!isConnected); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | @Override |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 181 | public void onQuickStepStarted() { |
| 182 | mNavigationBarView.onQuickStepStarted(); |
Mike Digman | 85a9bea | 2018-02-23 15:08:53 -0800 | [diff] [blame] | 183 | |
| 184 | // Use navbar dragging as a signal to hide the rotate button |
| 185 | setRotateSuggestionButtonState(false); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 186 | } |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 187 | |
| 188 | @Override |
| 189 | public void onInteractionFlagsChanged(@InteractionType int flags) { |
| 190 | mNavigationBarView.updateStates(); |
Winson Chung | f9e3027 | 2018-03-26 17:25:36 -0700 | [diff] [blame^] | 191 | updateScreenPinningGestures(); |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 192 | } |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 193 | }; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 194 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 195 | // ----- Fragment Lifecycle Callbacks ----- |
| 196 | |
| 197 | @Override |
| 198 | public void onCreate(@Nullable Bundle savedInstanceState) { |
| 199 | super.onCreate(savedInstanceState); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 200 | mCommandQueue = SysUiServiceProvider.getComponent(getContext(), CommandQueue.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 201 | mCommandQueue.addCallbacks(this); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 202 | mStatusBar = SysUiServiceProvider.getComponent(getContext(), StatusBar.class); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 203 | mRecents = SysUiServiceProvider.getComponent(getContext(), Recents.class); |
| 204 | mDivider = SysUiServiceProvider.getComponent(getContext(), Divider.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 205 | mWindowManager = getContext().getSystemService(WindowManager.class); |
| 206 | mAccessibilityManager = getContext().getSystemService(AccessibilityManager.class); |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 207 | Dependency.get(AccessibilityManagerWrapper.class).addCallback( |
| 208 | mAccessibilityListener); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 209 | mContentResolver = getContext().getContentResolver(); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 210 | mMagnificationObserver = new MagnificationContentObserver( |
| 211 | getContext().getMainThreadHandler()); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 212 | mContentResolver.registerContentObserver(Settings.Secure.getUriFor( |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 213 | Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED), false, |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 214 | mMagnificationObserver, UserHandle.USER_ALL); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 215 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 216 | if (savedInstanceState != null) { |
| 217 | mDisabledFlags1 = savedInstanceState.getInt(EXTRA_DISABLE_STATE, 0); |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 218 | mDisabledFlags2 = savedInstanceState.getInt(EXTRA_DISABLE2_STATE, 0); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 219 | } |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 220 | mAssistManager = Dependency.get(AssistManager.class); |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 221 | mOverviewProxyService = Dependency.get(OverviewProxyService.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 222 | |
| 223 | try { |
| 224 | WindowManagerGlobal.getWindowManagerService() |
Andrii Kulian | 35fa3c2 | 2017-03-11 09:37:28 -0800 | [diff] [blame] | 225 | .watchRotation(mRotationWatcher, getContext().getDisplay().getDisplayId()); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 226 | } catch (RemoteException e) { |
| 227 | throw e.rethrowFromSystemServer(); |
| 228 | } |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 229 | |
| 230 | mRotationLockController = Dependency.get(RotationLockController.class); |
| 231 | |
Mike Digman | ab65025 | 2018-03-06 11:01:41 -0800 | [diff] [blame] | 232 | // Reset user rotation pref to match that of the WindowManager if starting in locked mode |
| 233 | // This will automatically happen when switching from auto-rotate to locked mode |
| 234 | if (mRotationLockController.isRotationLocked()) { |
| 235 | final int winRotation = mWindowManager.getDefaultDisplay().getRotation(); |
| 236 | mRotationLockController.setRotationLockedAtAngle(true, winRotation); |
| 237 | } |
| 238 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 239 | // Register the task stack listener |
| 240 | mTaskStackListener = new TaskStackListenerImpl(); |
| 241 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | @Override |
| 245 | public void onDestroy() { |
| 246 | super.onDestroy(); |
| 247 | mCommandQueue.removeCallbacks(this); |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 248 | Dependency.get(AccessibilityManagerWrapper.class).removeCallback( |
| 249 | mAccessibilityListener); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 250 | mContentResolver.unregisterContentObserver(mMagnificationObserver); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 251 | try { |
| 252 | WindowManagerGlobal.getWindowManagerService() |
| 253 | .removeRotationWatcher(mRotationWatcher); |
| 254 | } catch (RemoteException e) { |
| 255 | throw e.rethrowFromSystemServer(); |
| 256 | } |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 257 | |
| 258 | // Unregister the task stack listener |
| 259 | ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, |
| 264 | Bundle savedInstanceState) { |
| 265 | return inflater.inflate(R.layout.navigation_bar, container, false); |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 270 | super.onViewCreated(view, savedInstanceState); |
| 271 | mNavigationBarView = (NavigationBarView) view; |
| 272 | |
| 273 | mNavigationBarView.setDisabledFlags(mDisabledFlags1); |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 274 | mNavigationBarView.setComponents(mRecents, mDivider, mStatusBar.getPanel()); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 275 | mNavigationBarView.setOnVerticalChangedListener(this::onVerticalChanged); |
| 276 | mNavigationBarView.setOnTouchListener(this::onNavigationTouch); |
| 277 | if (savedInstanceState != null) { |
| 278 | mNavigationBarView.getLightTransitionsController().restoreState(savedInstanceState); |
| 279 | } |
| 280 | |
| 281 | prepareNavigationBarView(); |
| 282 | checkNavBarModes(); |
| 283 | |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 284 | setDisabled2Flags(mDisabledFlags2); |
| 285 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 286 | IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); |
| 287 | filter.addAction(Intent.ACTION_SCREEN_ON); |
| 288 | getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null); |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 289 | notifyNavigationBarScreenOn(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 290 | mOverviewProxyService.addCallback(mOverviewProxyListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | @Override |
| 294 | public void onDestroyView() { |
| 295 | super.onDestroyView(); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 296 | mNavigationBarView.getLightTransitionsController().destroy(getContext()); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 297 | mOverviewProxyService.removeCallback(mOverviewProxyListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 298 | getContext().unregisterReceiver(mBroadcastReceiver); |
| 299 | } |
| 300 | |
| 301 | @Override |
| 302 | public void onSaveInstanceState(Bundle outState) { |
| 303 | super.onSaveInstanceState(outState); |
| 304 | outState.putInt(EXTRA_DISABLE_STATE, mDisabledFlags1); |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 305 | outState.putInt(EXTRA_DISABLE2_STATE, mDisabledFlags2); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 306 | if (mNavigationBarView != null) { |
| 307 | mNavigationBarView.getLightTransitionsController().saveState(outState); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public void onConfigurationChanged(Configuration newConfig) { |
| 313 | super.onConfigurationChanged(newConfig); |
| 314 | final Locale locale = getContext().getResources().getConfiguration().locale; |
| 315 | final int ld = TextUtils.getLayoutDirectionFromLocale(locale); |
| 316 | if (!locale.equals(mLocale) || ld != mLayoutDirection) { |
| 317 | if (DEBUG) { |
| 318 | Log.v(TAG, String.format( |
| 319 | "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection, |
| 320 | locale, ld)); |
| 321 | } |
| 322 | mLocale = locale; |
| 323 | mLayoutDirection = ld; |
| 324 | refreshLayout(ld); |
| 325 | } |
| 326 | repositionNavigationBar(); |
| 327 | } |
| 328 | |
| 329 | @Override |
| 330 | public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) { |
| 331 | if (mNavigationBarView != null) { |
| 332 | pw.print(" mNavigationBarWindowState="); |
| 333 | pw.println(windowStateToString(mNavigationBarWindowState)); |
| 334 | pw.print(" mNavigationBarMode="); |
| 335 | pw.println(BarTransitions.modeToString(mNavigationBarMode)); |
| 336 | dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions()); |
| 337 | } |
| 338 | |
| 339 | pw.print(" mNavigationBarView="); |
| 340 | if (mNavigationBarView == null) { |
| 341 | pw.println("null"); |
| 342 | } else { |
| 343 | mNavigationBarView.dump(fd, pw, args); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | // ----- CommandQueue Callbacks ----- |
| 348 | |
| 349 | @Override |
| 350 | public void setImeWindowStatus(IBinder token, int vis, int backDisposition, |
| 351 | boolean showImeSwitcher) { |
| 352 | boolean imeShown = (vis & InputMethodService.IME_VISIBLE) != 0; |
| 353 | int hints = mNavigationIconHints; |
Yohei Yukawa | 386f50e | 2018-03-14 13:03:42 -0700 | [diff] [blame] | 354 | switch (backDisposition) { |
| 355 | case InputMethodService.BACK_DISPOSITION_DEFAULT: |
| 356 | case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS: |
| 357 | case InputMethodService.BACK_DISPOSITION_WILL_DISMISS: |
| 358 | if (imeShown) { |
| 359 | hints |= NAVIGATION_HINT_BACK_ALT; |
| 360 | } else { |
| 361 | hints &= ~NAVIGATION_HINT_BACK_ALT; |
| 362 | } |
| 363 | break; |
| 364 | case InputMethodService.BACK_DISPOSITION_ADJUST_NOTHING: |
| 365 | hints &= ~NAVIGATION_HINT_BACK_ALT; |
| 366 | break; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 367 | } |
| 368 | if (showImeSwitcher) { |
| 369 | hints |= NAVIGATION_HINT_IME_SHOWN; |
| 370 | } else { |
| 371 | hints &= ~NAVIGATION_HINT_IME_SHOWN; |
| 372 | } |
| 373 | if (hints == mNavigationIconHints) return; |
| 374 | |
| 375 | mNavigationIconHints = hints; |
| 376 | |
| 377 | if (mNavigationBarView != null) { |
| 378 | mNavigationBarView.setNavigationIconHints(hints); |
| 379 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 380 | mStatusBar.checkBarModes(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public void topAppWindowChanged(boolean showMenu) { |
| 385 | if (mNavigationBarView != null) { |
| 386 | mNavigationBarView.setMenuVisibility(showMenu); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | @Override |
| 391 | public void setWindowState(int window, int state) { |
| 392 | if (mNavigationBarView != null |
| 393 | && window == StatusBarManager.WINDOW_NAVIGATION_BAR |
| 394 | && mNavigationBarWindowState != state) { |
| 395 | mNavigationBarWindowState = state; |
| 396 | if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state)); |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 397 | |
| 398 | // If the navbar is visible, show the rotate button if there's a pending suggestion |
| 399 | if (state == WINDOW_STATE_SHOWING && mPendingRotationSuggestion) { |
| 400 | showAndLogRotationSuggestion(); |
| 401 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 405 | @Override |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 406 | public void onRotationProposal(final int rotation, boolean isValid) { |
Mike Digman | 3e33da6 | 2018-03-14 16:25:11 -0700 | [diff] [blame] | 407 | final int winRotation = mWindowManager.getDefaultDisplay().getRotation(); |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 408 | final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(mDisabledFlags2); |
Mike Digman | 3e33da6 | 2018-03-14 16:25:11 -0700 | [diff] [blame] | 409 | if (DEBUG_ROTATION) { |
| 410 | Log.v(TAG, "onRotationProposal proposedRotation=" + Surface.rotationToString(rotation) |
| 411 | + ", winRotation=" + Surface.rotationToString(winRotation) |
| 412 | + ", isValid=" + isValid + ", mNavBarWindowState=" |
| 413 | + StatusBarManager.windowStateToString(mNavigationBarWindowState) |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 414 | + ", rotateSuggestionsDisabled=" + rotateSuggestionsDisabled |
Mike Digman | 3e33da6 | 2018-03-14 16:25:11 -0700 | [diff] [blame] | 415 | + ", isRotateButtonVisible=" + (mNavigationBarView == null ? "null" : |
| 416 | mNavigationBarView.isRotateButtonVisible())); |
| 417 | } |
| 418 | |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 419 | // Respect the disabled flag, no need for action as flag change callback will handle hiding |
| 420 | if (rotateSuggestionsDisabled) return; |
| 421 | |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 422 | // This method will be called on rotation suggestion changes even if the proposed rotation |
| 423 | // is not valid for the top app. Use invalid rotation choices as a signal to remove the |
| 424 | // rotate button if shown. |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 425 | if (!isValid) { |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 426 | setRotateSuggestionButtonState(false); |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 427 | return; |
| 428 | } |
| 429 | |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 430 | // If window rotation matches suggested rotation, remove any current suggestions |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 431 | if (rotation == winRotation) { |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 432 | getView().removeCallbacks(mRemoveRotationProposal); |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 433 | setRotateSuggestionButtonState(false); |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 434 | return; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 435 | } |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 436 | |
| 437 | // Prepare to show the navbar icon by updating the icon style to change anim params |
| 438 | mLastRotationSuggestion = rotation; // Remember rotation for click |
| 439 | if (mNavigationBarView != null) { |
| 440 | final boolean rotationCCW = isRotationAnimationCCW(winRotation, rotation); |
| 441 | int style; |
| 442 | if (winRotation == Surface.ROTATION_0 || winRotation == Surface.ROTATION_180) { |
| 443 | style = rotationCCW ? R.style.RotateButtonCCWStart90 : |
| 444 | R.style.RotateButtonCWStart90; |
| 445 | } else { // 90 or 270 |
| 446 | style = rotationCCW ? R.style.RotateButtonCCWStart0 : |
| 447 | R.style.RotateButtonCWStart0; |
| 448 | } |
| 449 | mNavigationBarView.updateRotateSuggestionButtonStyle(style, true); |
| 450 | } |
| 451 | |
| 452 | if (mNavigationBarWindowState != WINDOW_STATE_SHOWING) { |
| 453 | // If the navbar isn't shown, flag the rotate icon to be shown should the navbar become |
| 454 | // visible given some time limit. |
| 455 | mPendingRotationSuggestion = true; |
| 456 | getView().removeCallbacks(mCancelPendingRotationProposal); |
| 457 | getView().postDelayed(mCancelPendingRotationProposal, |
| 458 | NAVBAR_HIDDEN_PENDING_ICON_TIMEOUT_MS); |
| 459 | |
| 460 | } else { // The navbar is visible so show the icon right away |
| 461 | showAndLogRotationSuggestion(); |
| 462 | } |
| 463 | } |
| 464 | |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 465 | private void onRotationSuggestionsDisabled() { |
| 466 | // Immediately hide the rotate button and clear any planned removal |
| 467 | setRotateSuggestionButtonState(false, true); |
Mike Digman | e14c475 | 2018-03-20 12:14:54 -0700 | [diff] [blame] | 468 | |
| 469 | // This method can be called before view setup is done, ensure getView isn't null |
| 470 | final View v = getView(); |
| 471 | if (v != null) v.removeCallbacks(mRemoveRotationProposal); |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 474 | private void showAndLogRotationSuggestion() { |
| 475 | setRotateSuggestionButtonState(true); |
| 476 | rescheduleRotationTimeout(false); |
| 477 | mMetricsLogger.visible(MetricsEvent.ROTATION_SUGGESTION_SHOWN); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 478 | } |
| 479 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 480 | private boolean isRotationAnimationCCW(int from, int to) { |
| 481 | // All 180deg WM rotation animations are CCW, match that |
| 482 | if (from == Surface.ROTATION_0 && to == Surface.ROTATION_90) return false; |
| 483 | if (from == Surface.ROTATION_0 && to == Surface.ROTATION_180) return true; //180d so CCW |
| 484 | if (from == Surface.ROTATION_0 && to == Surface.ROTATION_270) return true; |
| 485 | if (from == Surface.ROTATION_90 && to == Surface.ROTATION_0) return true; |
| 486 | if (from == Surface.ROTATION_90 && to == Surface.ROTATION_180) return false; |
| 487 | if (from == Surface.ROTATION_90 && to == Surface.ROTATION_270) return true; //180d so CCW |
| 488 | if (from == Surface.ROTATION_180 && to == Surface.ROTATION_0) return true; //180d so CCW |
| 489 | if (from == Surface.ROTATION_180 && to == Surface.ROTATION_90) return true; |
| 490 | if (from == Surface.ROTATION_180 && to == Surface.ROTATION_270) return false; |
| 491 | if (from == Surface.ROTATION_270 && to == Surface.ROTATION_0) return false; |
| 492 | if (from == Surface.ROTATION_270 && to == Surface.ROTATION_90) return true; //180d so CCW |
| 493 | if (from == Surface.ROTATION_270 && to == Surface.ROTATION_180) return true; |
| 494 | return false; // Default |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 495 | } |
| 496 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 497 | public void setRotateSuggestionButtonState(final boolean visible) { |
| 498 | setRotateSuggestionButtonState(visible, false); |
| 499 | } |
| 500 | |
| 501 | public void setRotateSuggestionButtonState(final boolean visible, final boolean force) { |
| 502 | if (mNavigationBarView == null) return; |
| 503 | |
| 504 | // At any point the the button can become invisible because an a11y service became active. |
| 505 | // Similarly, a call to make the button visible may be rejected because an a11y service is |
| 506 | // active. Must account for this. |
| 507 | |
| 508 | ButtonDispatcher rotBtn = mNavigationBarView.getRotateSuggestionButton(); |
| 509 | final boolean currentlyVisible = mNavigationBarView.isRotateButtonVisible(); |
| 510 | |
| 511 | // Rerun a show animation to indicate change but don't rerun a hide animation |
| 512 | if (!visible && !currentlyVisible) return; |
| 513 | |
| 514 | View view = rotBtn.getCurrentView(); |
| 515 | if (view == null) return; |
| 516 | |
| 517 | KeyButtonDrawable kbd = rotBtn.getImageDrawable(); |
| 518 | if (kbd == null) return; |
| 519 | |
| 520 | // The KBD and AVD is recreated every new valid suggestion because of style changes. |
| 521 | AnimatedVectorDrawable animIcon = null; |
| 522 | if (kbd.getDrawable(0) instanceof AnimatedVectorDrawable) { |
| 523 | animIcon = (AnimatedVectorDrawable) kbd.getDrawable(0); |
| 524 | } |
| 525 | |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 526 | // Clear any pending suggestion flag as it has either been nullified or is being shown |
| 527 | mPendingRotationSuggestion = false; |
| 528 | getView().removeCallbacks(mCancelPendingRotationProposal); |
| 529 | |
| 530 | // Handle the visibility change and animation |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 531 | if (visible) { // Appear and change (cannot force) |
Mike Digman | 85a9bea | 2018-02-23 15:08:53 -0800 | [diff] [blame] | 532 | // Stop and clear any currently running hide animations |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 533 | if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) { |
Mike Digman | 85a9bea | 2018-02-23 15:08:53 -0800 | [diff] [blame] | 534 | mRotateHideAnimator.cancel(); |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 535 | } |
Mike Digman | 85a9bea | 2018-02-23 15:08:53 -0800 | [diff] [blame] | 536 | mRotateHideAnimator = null; |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 537 | |
| 538 | // Reset the alpha if any has changed due to hide animation |
| 539 | view.setAlpha(1f); |
| 540 | |
| 541 | // Run the rotate icon's animation if it has one |
| 542 | if (animIcon != null) { |
| 543 | animIcon.reset(); |
| 544 | animIcon.start(); |
| 545 | } |
| 546 | |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 547 | if (!isRotateSuggestionIntroduced()) mViewRippler.start(view); |
| 548 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 549 | // Set visibility, may fail if a11y service is active. |
| 550 | // If invisible, call will stop animation. |
| 551 | mNavigationBarView.setRotateButtonVisibility(true); |
| 552 | |
| 553 | } else { // Hide |
| 554 | |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 555 | mViewRippler.stop(); // Prevent any pending ripples, force hide or not |
| 556 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 557 | if (force) { |
| 558 | // If a hide animator is running stop it and make invisible |
| 559 | if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) { |
| 560 | mRotateHideAnimator.pause(); |
| 561 | } |
| 562 | mNavigationBarView.setRotateButtonVisibility(false); |
| 563 | return; |
| 564 | } |
| 565 | |
| 566 | // Don't start any new hide animations if one is running |
| 567 | if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return; |
| 568 | |
| 569 | ObjectAnimator fadeOut = ObjectAnimator.ofFloat(view, "alpha", |
| 570 | 0f); |
| 571 | fadeOut.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS); |
| 572 | fadeOut.setInterpolator(Interpolators.LINEAR); |
| 573 | fadeOut.addListener(new AnimatorListenerAdapter() { |
| 574 | @Override |
| 575 | public void onAnimationEnd(Animator animation) { |
| 576 | mNavigationBarView.setRotateButtonVisibility(false); |
| 577 | } |
| 578 | }); |
| 579 | |
| 580 | mRotateHideAnimator = fadeOut; |
| 581 | fadeOut.start(); |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 582 | } |
| 583 | } |
| 584 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 585 | private void rescheduleRotationTimeout(final boolean reasonHover) { |
| 586 | // May be called due to a new rotation proposal or a change in hover state |
| 587 | if (reasonHover) { |
| 588 | // Don't reschedule if a hide animator is running |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 589 | if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return; |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 590 | // Don't reschedule if not visible |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 591 | if (!mNavigationBarView.isRotateButtonVisible()) return; |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 592 | } |
| 593 | |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 594 | getView().removeCallbacks(mRemoveRotationProposal); // Stop any pending removal |
| 595 | getView().postDelayed(mRemoveRotationProposal, |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 596 | computeRotationProposalTimeout()); // Schedule timeout |
| 597 | } |
| 598 | |
| 599 | private int computeRotationProposalTimeout() { |
| 600 | if (mAccessibilityFeedbackEnabled) return 20000; |
| 601 | if (mHoveringRotationSuggestion) return 16000; |
| 602 | return 6000; |
| 603 | } |
| 604 | |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 605 | private boolean isRotateSuggestionIntroduced() { |
| 606 | ContentResolver cr = getContext().getContentResolver(); |
| 607 | return Settings.Secure.getInt(cr, Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, 0) |
| 608 | >= NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION; |
| 609 | } |
| 610 | |
| 611 | private void incrementNumAcceptedRotationSuggestionsIfNeeded() { |
| 612 | // Get the number of accepted suggestions |
| 613 | ContentResolver cr = getContext().getContentResolver(); |
| 614 | final int numSuggestions = Settings.Secure.getInt(cr, |
| 615 | Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, 0); |
| 616 | |
| 617 | // Increment the number of accepted suggestions only if it would change intro mode |
| 618 | if (numSuggestions < NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION) { |
| 619 | Settings.Secure.putInt(cr, Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, |
| 620 | numSuggestions + 1); |
| 621 | } |
| 622 | } |
| 623 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 624 | // Injected from StatusBar at creation. |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 625 | public void setCurrentSysuiVisibility(int systemUiVisibility) { |
| 626 | mSystemUiVisibility = systemUiVisibility; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 627 | mNavigationBarMode = mStatusBar.computeBarMode(0, mSystemUiVisibility, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 628 | View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT, |
| 629 | View.NAVIGATION_BAR_TRANSPARENT); |
| 630 | checkNavBarModes(); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 631 | mStatusBar.touchAutoHide(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 632 | mLightBarController.onNavigationVisibilityChanged(mSystemUiVisibility, 0 /* mask */, |
| 633 | true /* nbModeChanged */, mNavigationBarMode); |
| 634 | } |
| 635 | |
| 636 | @Override |
| 637 | public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis, |
| 638 | int mask, Rect fullscreenStackBounds, Rect dockedStackBounds) { |
| 639 | final int oldVal = mSystemUiVisibility; |
| 640 | final int newVal = (oldVal & ~mask) | (vis & mask); |
| 641 | final int diff = newVal ^ oldVal; |
| 642 | boolean nbModeChanged = false; |
| 643 | if (diff != 0) { |
| 644 | mSystemUiVisibility = newVal; |
| 645 | |
| 646 | // update navigation bar mode |
| 647 | final int nbMode = getView() == null |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 648 | ? -1 : mStatusBar.computeBarMode(oldVal, newVal, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 649 | View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT, |
| 650 | View.NAVIGATION_BAR_TRANSPARENT); |
| 651 | nbModeChanged = nbMode != -1; |
| 652 | if (nbModeChanged) { |
| 653 | if (mNavigationBarMode != nbMode) { |
| 654 | mNavigationBarMode = nbMode; |
| 655 | checkNavBarModes(); |
| 656 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 657 | mStatusBar.touchAutoHide(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
| 661 | mLightBarController.onNavigationVisibilityChanged(vis, mask, nbModeChanged, |
| 662 | mNavigationBarMode); |
| 663 | } |
| 664 | |
| 665 | @Override |
| 666 | public void disable(int state1, int state2, boolean animate) { |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 667 | // Navigation bar flags are in both state1 and state2. |
| 668 | final int masked = state1 & (StatusBarManager.DISABLE_HOME |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 669 | | StatusBarManager.DISABLE_RECENT |
| 670 | | StatusBarManager.DISABLE_BACK |
| 671 | | StatusBarManager.DISABLE_SEARCH); |
| 672 | if (masked != mDisabledFlags1) { |
| 673 | mDisabledFlags1 = masked; |
| 674 | if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state1); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 675 | updateScreenPinningGestures(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 676 | } |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 677 | |
| 678 | final int masked2 = state2 & (StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS); |
| 679 | if (masked2 != mDisabledFlags2) { |
| 680 | mDisabledFlags2 = masked2; |
| 681 | setDisabled2Flags(masked2); |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | private void setDisabled2Flags(int state2) { |
| 686 | // Method only called on change of disable2 flags |
| 687 | final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(state2); |
| 688 | if (rotateSuggestionsDisabled) onRotationSuggestionsDisabled(); |
| 689 | } |
| 690 | |
| 691 | private boolean hasDisable2RotateSuggestionFlag(int disable2Flags) { |
| 692 | return (disable2Flags & StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS) != 0; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | // ----- Internal stuffz ----- |
| 696 | |
| 697 | private void refreshLayout(int layoutDirection) { |
| 698 | if (mNavigationBarView != null) { |
| 699 | mNavigationBarView.setLayoutDirection(layoutDirection); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | private boolean shouldDisableNavbarGestures() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 704 | return !mStatusBar.isDeviceProvisioned() |
Matthew Ng | fee0b5b | 2018-02-21 15:38:21 -0800 | [diff] [blame] | 705 | || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | private void repositionNavigationBar() { |
| 709 | if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return; |
| 710 | |
| 711 | prepareNavigationBarView(); |
| 712 | |
| 713 | mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(), |
| 714 | ((View) mNavigationBarView.getParent()).getLayoutParams()); |
| 715 | } |
| 716 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 717 | private void updateScreenPinningGestures() { |
| 718 | if (mNavigationBarView == null) { |
| 719 | return; |
| 720 | } |
| 721 | |
| 722 | // Change the cancel pin gesture to home and back if recents button is invisible |
| 723 | boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 724 | ButtonDispatcher backButton = mNavigationBarView.getBackButton(); |
| 725 | if (recentsVisible) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 726 | backButton.setOnLongClickListener(this::onLongPressBackRecents); |
| 727 | } else { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 728 | backButton.setOnLongClickListener(this::onLongPressBackHome); |
| 729 | } |
| 730 | } |
| 731 | |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 732 | private void notifyNavigationBarScreenOn() { |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 733 | mNavigationBarView.updateNavButtonIcons(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | private void prepareNavigationBarView() { |
| 737 | mNavigationBarView.reorient(); |
| 738 | |
| 739 | ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton(); |
| 740 | recentsButton.setOnClickListener(this::onRecentsClick); |
| 741 | recentsButton.setOnTouchListener(this::onRecentsTouch); |
| 742 | recentsButton.setLongClickable(true); |
| 743 | recentsButton.setOnLongClickListener(this::onLongPressBackRecents); |
| 744 | |
| 745 | ButtonDispatcher backButton = mNavigationBarView.getBackButton(); |
| 746 | backButton.setLongClickable(true); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 747 | |
| 748 | ButtonDispatcher homeButton = mNavigationBarView.getHomeButton(); |
| 749 | homeButton.setOnTouchListener(this::onHomeTouch); |
Matthew Ng | fee0b5b | 2018-02-21 15:38:21 -0800 | [diff] [blame] | 750 | homeButton.setOnLongClickListener(this::onHomeLongClick); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 751 | |
| 752 | ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton(); |
| 753 | accessibilityButton.setOnClickListener(this::onAccessibilityClick); |
| 754 | accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick); |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 755 | updateAccessibilityServicesState(mAccessibilityManager); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 756 | |
| 757 | ButtonDispatcher rotateSuggestionButton = mNavigationBarView.getRotateSuggestionButton(); |
| 758 | rotateSuggestionButton.setOnClickListener(this::onRotateSuggestionClick); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 759 | rotateSuggestionButton.setOnHoverListener(this::onRotateSuggestionHover); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 760 | updateScreenPinningGestures(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | private boolean onHomeTouch(View v, MotionEvent event) { |
| 764 | if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) { |
| 765 | return true; |
| 766 | } |
| 767 | // If an incoming call is ringing, HOME is totally disabled. |
| 768 | // (The user is already on the InCallUI at this point, |
| 769 | // and his ONLY options are to answer or reject the call.) |
| 770 | switch (event.getAction()) { |
| 771 | case MotionEvent.ACTION_DOWN: |
| 772 | mHomeBlockedThisTouch = false; |
| 773 | TelecomManager telecomManager = |
| 774 | getContext().getSystemService(TelecomManager.class); |
| 775 | if (telecomManager != null && telecomManager.isRinging()) { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 776 | if (mStatusBar.isKeyguardShowing()) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 777 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " + |
| 778 | "No heads up"); |
| 779 | mHomeBlockedThisTouch = true; |
| 780 | return true; |
| 781 | } |
| 782 | } |
| 783 | break; |
| 784 | case MotionEvent.ACTION_UP: |
| 785 | case MotionEvent.ACTION_CANCEL: |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 786 | mStatusBar.awakenDreams(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 787 | break; |
| 788 | } |
| 789 | return false; |
| 790 | } |
| 791 | |
| 792 | private void onVerticalChanged(boolean isVertical) { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 793 | mStatusBar.setQsScrimEnabled(!isVertical); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | private boolean onNavigationTouch(View v, MotionEvent event) { |
Eliot Courtney | cb5d316 | 2017-08-09 16:53:15 +0900 | [diff] [blame] | 797 | mStatusBar.checkUserAutohide(event); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 798 | return false; |
| 799 | } |
| 800 | |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 801 | @VisibleForTesting |
| 802 | boolean onHomeLongClick(View v) { |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 803 | if (!mNavigationBarView.isRecentsButtonVisible() |
| 804 | && ActivityManagerWrapper.getInstance().isScreenPinningActive()) { |
Matthew Ng | fee0b5b | 2018-02-21 15:38:21 -0800 | [diff] [blame] | 805 | return onLongPressBackHome(v); |
| 806 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 807 | if (shouldDisableNavbarGestures()) { |
| 808 | return false; |
| 809 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 810 | mNavigationBarView.onNavigationButtonLongPress(v); |
Mike Digman | c94759d | 2018-01-23 11:01:21 -0800 | [diff] [blame] | 811 | mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 812 | mAssistManager.startAssist(new Bundle() /* args */); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 813 | mStatusBar.awakenDreams(); |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 814 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 815 | if (mNavigationBarView != null) { |
| 816 | mNavigationBarView.abortCurrentGesture(); |
| 817 | } |
| 818 | return true; |
| 819 | } |
| 820 | |
| 821 | // additional optimization when we have software system buttons - start loading the recent |
| 822 | // tasks on touch down |
| 823 | private boolean onRecentsTouch(View v, MotionEvent event) { |
| 824 | int action = event.getAction() & MotionEvent.ACTION_MASK; |
| 825 | if (action == MotionEvent.ACTION_DOWN) { |
| 826 | mCommandQueue.preloadRecentApps(); |
| 827 | } else if (action == MotionEvent.ACTION_CANCEL) { |
| 828 | mCommandQueue.cancelPreloadRecentApps(); |
| 829 | } else if (action == MotionEvent.ACTION_UP) { |
| 830 | if (!v.isPressed()) { |
| 831 | mCommandQueue.cancelPreloadRecentApps(); |
| 832 | } |
| 833 | } |
| 834 | return false; |
| 835 | } |
| 836 | |
| 837 | private void onRecentsClick(View v) { |
| 838 | if (LatencyTracker.isEnabled(getContext())) { |
| 839 | LatencyTracker.getInstance(getContext()).onActionStart( |
| 840 | LatencyTracker.ACTION_TOGGLE_RECENTS); |
| 841 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 842 | mStatusBar.awakenDreams(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 843 | mCommandQueue.toggleRecentApps(); |
| 844 | } |
| 845 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 846 | private boolean onLongPressBackHome(View v) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 847 | mNavigationBarView.onNavigationButtonLongPress(v); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 848 | return onLongPressNavigationButtons(v, R.id.back, R.id.home); |
| 849 | } |
| 850 | |
| 851 | private boolean onLongPressBackRecents(View v) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 852 | mNavigationBarView.onNavigationButtonLongPress(v); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 853 | return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps); |
| 854 | } |
| 855 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 856 | /** |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 857 | * This handles long-press of both back and recents/home. Back is the common button with |
| 858 | * combination of recents if it is visible or home if recents is invisible. |
| 859 | * They are handled together to capture them both being long-pressed |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 860 | * at the same time to exit screen pinning (lock task). |
| 861 | * |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 862 | * When accessibility mode is on, only a long-press from recents/home |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 863 | * is required to exit. |
| 864 | * |
| 865 | * In all other circumstances we try to pass through long-press events |
| 866 | * for Back, so that apps can still use it. Which can be from two things. |
| 867 | * 1) Not currently in screen pinning (lock task). |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 868 | * 2) Back is long-pressed without recents/home. |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 869 | */ |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 870 | private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 871 | try { |
| 872 | boolean sendBackLongPress = false; |
| 873 | IActivityManager activityManager = ActivityManagerNative.getDefault(); |
| 874 | boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled(); |
| 875 | boolean inLockTaskMode = activityManager.isInLockTaskMode(); |
| 876 | if (inLockTaskMode && !touchExplorationEnabled) { |
| 877 | long time = System.currentTimeMillis(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 878 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 879 | // If we recently long-pressed the other button then they were |
| 880 | // long-pressed 'together' |
| 881 | if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 882 | activityManager.stopSystemLockTaskMode(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 883 | // When exiting refresh disabled flags. |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 884 | mNavigationBarView.updateNavButtonIcons(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 885 | return true; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 886 | } else if (v.getId() == btnId1) { |
| 887 | ButtonDispatcher button = btnId2 == R.id.recent_apps |
| 888 | ? mNavigationBarView.getRecentsButton() |
| 889 | : mNavigationBarView.getHomeButton(); |
| 890 | if (!button.getCurrentView().isPressed()) { |
| 891 | // If we aren't pressing recents/home right now then they presses |
| 892 | // won't be together, so send the standard long-press action. |
| 893 | sendBackLongPress = true; |
| 894 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 895 | } |
| 896 | mLastLockToAppLongPress = time; |
| 897 | } else { |
| 898 | // If this is back still need to handle sending the long-press event. |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 899 | if (v.getId() == btnId1) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 900 | sendBackLongPress = true; |
| 901 | } else if (touchExplorationEnabled && inLockTaskMode) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 902 | // When in accessibility mode a long press that is recents/home (not back) |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 903 | // should stop lock task. |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 904 | activityManager.stopSystemLockTaskMode(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 905 | // When exiting refresh disabled flags. |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 906 | mNavigationBarView.updateNavButtonIcons(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 907 | return true; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 908 | } else if (v.getId() == btnId2) { |
| 909 | return btnId2 == R.id.recent_apps |
| 910 | ? onLongPressRecents() |
| 911 | : onHomeLongClick(mNavigationBarView.getHomeButton().getCurrentView()); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | if (sendBackLongPress) { |
| 915 | KeyButtonView keyButtonView = (KeyButtonView) v; |
| 916 | keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS); |
| 917 | keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 918 | return true; |
| 919 | } |
| 920 | } catch (RemoteException e) { |
| 921 | Log.d(TAG, "Unable to reach activity manager", e); |
| 922 | } |
| 923 | return false; |
| 924 | } |
| 925 | |
| 926 | private boolean onLongPressRecents() { |
Erik Wolsheimer | 9be3a06 | 2017-05-31 14:59:57 -0700 | [diff] [blame] | 927 | if (mRecents == null || !ActivityManager.supportsMultiWindow(getContext()) |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 928 | || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible() |
| 929 | || Recents.getConfiguration().isLowRamDevice) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 930 | return false; |
| 931 | } |
| 932 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 933 | return mStatusBar.toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 934 | MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS); |
| 935 | } |
| 936 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 937 | private void onAccessibilityClick(View v) { |
| 938 | mAccessibilityManager.notifyAccessibilityButtonClicked(); |
| 939 | } |
| 940 | |
| 941 | private boolean onAccessibilityLongClick(View v) { |
Casey Burkhardt | 5e8b980 | 2017-03-24 10:07:20 -0700 | [diff] [blame] | 942 | Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON); |
| 943 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 944 | v.getContext().startActivityAsUser(intent, UserHandle.CURRENT); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 945 | return true; |
| 946 | } |
| 947 | |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 948 | private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) { |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 949 | int requestingServices = 0; |
| 950 | try { |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 951 | if (Settings.Secure.getIntForUser(mContentResolver, |
| 952 | Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, |
| 953 | UserHandle.USER_CURRENT) == 1) { |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 954 | requestingServices++; |
| 955 | } |
| 956 | } catch (Settings.SettingNotFoundException e) { |
| 957 | } |
| 958 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 959 | boolean feedbackEnabled = false; |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 960 | // AccessibilityManagerService resolves services for the current user since the local |
| 961 | // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 962 | final List<AccessibilityServiceInfo> services = |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 963 | accessibilityManager.getEnabledAccessibilityServiceList( |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 964 | AccessibilityServiceInfo.FEEDBACK_ALL_MASK); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 965 | for (int i = services.size() - 1; i >= 0; --i) { |
| 966 | AccessibilityServiceInfo info = services.get(i); |
| 967 | if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) { |
| 968 | requestingServices++; |
| 969 | } |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 970 | |
| 971 | if (info.feedbackType != 0 && info.feedbackType != |
| 972 | AccessibilityServiceInfo.FEEDBACK_GENERIC) { |
| 973 | feedbackEnabled = true; |
| 974 | } |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 975 | } |
| 976 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 977 | mAccessibilityFeedbackEnabled = feedbackEnabled; |
| 978 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 979 | final boolean showAccessibilityButton = requestingServices >= 1; |
| 980 | final boolean targetSelection = requestingServices >= 2; |
| 981 | mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection); |
| 982 | } |
| 983 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 984 | private void onRotateSuggestionClick(View v) { |
Mike Digman | c94759d | 2018-01-23 11:01:21 -0800 | [diff] [blame] | 985 | mMetricsLogger.action(MetricsEvent.ACTION_ROTATION_SUGGESTION_ACCEPTED); |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 986 | incrementNumAcceptedRotationSuggestionsIfNeeded(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 987 | mRotationLockController.setRotationLockedAtAngle(true, mLastRotationSuggestion); |
| 988 | } |
| 989 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 990 | private boolean onRotateSuggestionHover(View v, MotionEvent event) { |
| 991 | final int action = event.getActionMasked(); |
| 992 | mHoveringRotationSuggestion = (action == MotionEvent.ACTION_HOVER_ENTER) |
| 993 | || (action == MotionEvent.ACTION_HOVER_MOVE); |
| 994 | rescheduleRotationTimeout(true); |
| 995 | return false; // Must return false so a11y hover events are dispatched correctly. |
| 996 | } |
| 997 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 998 | // ----- Methods that StatusBar talks to (should be minimized) ----- |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 999 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1000 | public void setLightBarController(LightBarController lightBarController) { |
| 1001 | mLightBarController = lightBarController; |
| 1002 | mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController()); |
| 1003 | } |
| 1004 | |
| 1005 | public boolean isSemiTransparent() { |
| 1006 | return mNavigationBarMode == MODE_SEMI_TRANSPARENT; |
| 1007 | } |
| 1008 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1009 | public void disableAnimationsDuringHide(long delay) { |
| 1010 | mNavigationBarView.setLayoutTransitionsEnabled(false); |
| 1011 | mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true), |
| 1012 | delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE); |
| 1013 | } |
| 1014 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1015 | public BarTransitions getBarTransitions() { |
| 1016 | return mNavigationBarView.getBarTransitions(); |
| 1017 | } |
| 1018 | |
| 1019 | public void checkNavBarModes() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 1020 | mStatusBar.checkBarMode(mNavigationBarMode, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1021 | mNavigationBarWindowState, mNavigationBarView.getBarTransitions()); |
| 1022 | } |
| 1023 | |
| 1024 | public void finishBarAnimations() { |
| 1025 | mNavigationBarView.getBarTransitions().finishAnimations(); |
| 1026 | } |
| 1027 | |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 1028 | private final AccessibilityServicesStateChangeListener mAccessibilityListener = |
| 1029 | this::updateAccessibilityServicesState; |
| 1030 | |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 1031 | private class MagnificationContentObserver extends ContentObserver { |
| 1032 | |
| 1033 | public MagnificationContentObserver(Handler handler) { |
| 1034 | super(handler); |
| 1035 | } |
| 1036 | |
| 1037 | @Override |
| 1038 | public void onChange(boolean selfChange) { |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 1039 | NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1043 | private final Stub mRotationWatcher = new Stub() { |
| 1044 | @Override |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 1045 | public void onRotationChanged(final int rotation) throws RemoteException { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1046 | // We need this to be scheduled as early as possible to beat the redrawing of |
| 1047 | // window in response to the orientation change. |
| 1048 | Handler h = getView().getHandler(); |
| 1049 | Message msg = Message.obtain(h, () -> { |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 1050 | |
| 1051 | // If the screen rotation changes while locked, potentially update lock to flow with |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 1052 | // new screen rotation and hide any showing suggestions. |
| 1053 | if (mRotationLockController.isRotationLocked()) { |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 1054 | if (shouldOverrideUserLockPrefs(rotation)) { |
| 1055 | mRotationLockController.setRotationLockedAtAngle(true, rotation); |
| 1056 | } |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 1057 | setRotateSuggestionButtonState(false, true); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 1058 | } |
| 1059 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1060 | if (mNavigationBarView != null |
| 1061 | && mNavigationBarView.needsReorient(rotation)) { |
| 1062 | repositionNavigationBar(); |
| 1063 | } |
| 1064 | }); |
| 1065 | msg.setAsynchronous(true); |
| 1066 | h.sendMessageAtFrontOfQueue(msg); |
| 1067 | } |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 1068 | |
| 1069 | private boolean shouldOverrideUserLockPrefs(final int rotation) { |
Mike Digman | ab65025 | 2018-03-06 11:01:41 -0800 | [diff] [blame] | 1070 | // Only override user prefs when returning to the natural rotation (normally portrait). |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 1071 | // Don't let apps that force landscape or 180 alter user lock. |
Mike Digman | ab65025 | 2018-03-06 11:01:41 -0800 | [diff] [blame] | 1072 | return rotation == NATURAL_ROTATION; |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 1073 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1074 | }; |
| 1075 | |
| 1076 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 1077 | @Override |
| 1078 | public void onReceive(Context context, Intent intent) { |
| 1079 | String action = intent.getAction(); |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 1080 | if (Intent.ACTION_SCREEN_OFF.equals(action) |
| 1081 | || Intent.ACTION_SCREEN_ON.equals(action)) { |
| 1082 | notifyNavigationBarScreenOn(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1083 | } |
| 1084 | } |
| 1085 | }; |
| 1086 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 1087 | class TaskStackListenerImpl extends SysUiTaskStackChangeListener { |
| 1088 | // Invalidate any rotation suggestion on task change or activity orientation change |
| 1089 | // Note: all callbacks happen on main thread |
| 1090 | |
| 1091 | @Override |
| 1092 | public void onTaskStackChanged() { |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 1093 | setRotateSuggestionButtonState(false); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | @Override |
| 1097 | public void onTaskRemoved(int taskId) { |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 1098 | setRotateSuggestionButtonState(false); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | @Override |
| 1102 | public void onTaskMovedToFront(int taskId) { |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 1103 | setRotateSuggestionButtonState(false); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | @Override |
| 1107 | public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation) { |
Mike Digman | 85a9bea | 2018-02-23 15:08:53 -0800 | [diff] [blame] | 1108 | // Only hide the icon if the top task changes its requestedOrientation |
| 1109 | // Launcher can alter its requestedOrientation while it's not on top, don't hide on this |
| 1110 | final boolean top = ActivityManagerWrapper.getInstance().getRunningTask().id == taskId; |
| 1111 | if (top) setRotateSuggestionButtonState(false); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 1115 | private class ViewRippler { |
| 1116 | private static final int RIPPLE_OFFSET_MS = 50; |
| 1117 | private static final int RIPPLE_INTERVAL_MS = 2000; |
| 1118 | private View mRoot; |
| 1119 | |
| 1120 | public void start(View root) { |
| 1121 | stop(); // Stop any pending ripple animations |
| 1122 | |
| 1123 | mRoot = root; |
| 1124 | |
| 1125 | // Schedule pending ripples, offset the 1st to avoid problems with visibility change |
| 1126 | mRoot.postOnAnimationDelayed(mRipple, RIPPLE_OFFSET_MS); |
| 1127 | mRoot.postOnAnimationDelayed(mRipple, RIPPLE_INTERVAL_MS); |
| 1128 | mRoot.postOnAnimationDelayed(mRipple, 2*RIPPLE_INTERVAL_MS); |
| 1129 | } |
| 1130 | |
| 1131 | public void stop() { |
| 1132 | if (mRoot != null) mRoot.removeCallbacks(mRipple); |
| 1133 | } |
| 1134 | |
| 1135 | private final Runnable mRipple = new Runnable() { |
| 1136 | @Override |
| 1137 | public void run() { // Cause the ripple to fire via false presses |
| 1138 | mRoot.setPressed(true); |
| 1139 | mRoot.setPressed(false); |
| 1140 | } |
| 1141 | }; |
| 1142 | } |
| 1143 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1144 | public static View create(Context context, FragmentListener listener) { |
| 1145 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1146 | LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, |
| 1147 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, |
| 1148 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING |
| 1149 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1150 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 1151 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 1152 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH |
| 1153 | | WindowManager.LayoutParams.FLAG_SLIPPERY, |
| 1154 | PixelFormat.TRANSLUCENT); |
| 1155 | lp.token = new Binder(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1156 | lp.setTitle("NavigationBar"); |
Phil Weaver | 8583ae8 | 2018-02-13 11:01:24 -0800 | [diff] [blame] | 1157 | lp.accessibilityTitle = context.getString(R.string.nav_bar); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1158 | lp.windowAnimations = 0; |
| 1159 | |
| 1160 | View navigationBarView = LayoutInflater.from(context).inflate( |
| 1161 | R.layout.navigation_bar_window, null); |
| 1162 | |
| 1163 | if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView); |
| 1164 | if (navigationBarView == null) return null; |
| 1165 | |
| 1166 | context.getSystemService(WindowManager.class).addView(navigationBarView, lp); |
| 1167 | FragmentHostManager fragmentHost = FragmentHostManager.get(navigationBarView); |
| 1168 | NavigationBarFragment fragment = new NavigationBarFragment(); |
| 1169 | fragmentHost.getFragmentManager().beginTransaction() |
| 1170 | .replace(R.id.navigation_bar_frame, fragment, TAG) |
| 1171 | .commit(); |
| 1172 | fragmentHost.addTagListener(TAG, listener); |
| 1173 | return navigationBarView; |
| 1174 | } |
| 1175 | } |