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