blob: 1239a9ea0240ec4abfbf8aba363aad244c562f1b [file] [log] [blame]
Jason Monk49fa0162017-01-11 09:21:56 -05001/*
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
15package com.android.systemui.statusbar.phone;
16
17import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_ALT;
18import static android.app.StatusBarManager.NAVIGATION_HINT_IME_SHOWN;
19import static android.app.StatusBarManager.WINDOW_STATE_SHOWING;
20import static android.app.StatusBarManager.windowStateToString;
21
22import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050023import static com.android.systemui.statusbar.phone.StatusBar.DEBUG_WINDOW_STATE;
24import static com.android.systemui.statusbar.phone.StatusBar.dumpBarTransitions;
Matthew Ng9c3bce52018-02-01 22:00:31 +000025import static com.android.systemui.OverviewProxyService.OverviewProxyListener;
Jason Monk49fa0162017-01-11 09:21:56 -050026
Casey Burkhardt048c2bc2016-12-08 16:09:20 -080027import android.accessibilityservice.AccessibilityServiceInfo;
Mike Digman7d092772018-01-11 12:10:32 -080028import android.animation.Animator;
29import android.animation.AnimatorListenerAdapter;
Mike Digman7d092772018-01-11 12:10:32 -080030import android.animation.ObjectAnimator;
Matthew Ng9c3bce52018-02-01 22:00:31 +000031import android.annotation.IdRes;
Jason Monk49fa0162017-01-11 09:21:56 -050032import android.annotation.Nullable;
33import android.app.ActivityManager;
34import android.app.ActivityManagerNative;
35import android.app.Fragment;
36import android.app.IActivityManager;
37import android.app.StatusBarManager;
38import android.content.BroadcastReceiver;
Casey Burkhardtb9dcd662017-03-20 15:10:16 -070039import android.content.ContentResolver;
Jason Monk49fa0162017-01-11 09:21:56 -050040import android.content.Context;
41import android.content.Intent;
42import android.content.IntentFilter;
43import android.content.res.Configuration;
Casey Burkhardt74922c62017-02-13 12:43:16 -080044import android.database.ContentObserver;
Jason Monk49fa0162017-01-11 09:21:56 -050045import android.graphics.PixelFormat;
46import android.graphics.Rect;
Mike Digman7d092772018-01-11 12:10:32 -080047import android.graphics.drawable.AnimatedVectorDrawable;
Jason Monk49fa0162017-01-11 09:21:56 -050048import android.inputmethodservice.InputMethodService;
49import android.os.Binder;
50import android.os.Bundle;
51import android.os.Handler;
52import android.os.IBinder;
53import android.os.Message;
Jason Monk49fa0162017-01-11 09:21:56 -050054import android.os.RemoteException;
55import android.os.UserHandle;
Casey Burkhardt74922c62017-02-13 12:43:16 -080056import android.provider.Settings;
Jason Monk865246d2017-01-19 08:27:01 -050057import android.support.annotation.VisibleForTesting;
Jason Monk49fa0162017-01-11 09:21:56 -050058import android.telecom.TelecomManager;
59import android.text.TextUtils;
60import android.util.Log;
61import android.view.IRotationWatcher.Stub;
62import android.view.KeyEvent;
63import android.view.LayoutInflater;
64import android.view.MotionEvent;
Mike Digman85ff7fa2018-01-23 14:59:52 -080065import android.view.Surface;
Jason Monk49fa0162017-01-11 09:21:56 -050066import android.view.View;
67import android.view.ViewGroup;
68import android.view.WindowManager;
69import android.view.WindowManager.LayoutParams;
70import android.view.WindowManagerGlobal;
71import android.view.accessibility.AccessibilityEvent;
72import android.view.accessibility.AccessibilityManager;
Jason Monk91e587e2017-04-13 13:41:23 -040073import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener;
Matthew Ng9c3bce52018-02-01 22:00:31 +000074import android.widget.Button;
Jason Monk49fa0162017-01-11 09:21:56 -050075
76import com.android.internal.logging.MetricsLogger;
77import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jason Monkea03be12017-12-04 11:08:41 -050078import com.android.internal.util.LatencyTracker;
Jason Monk9c7844c2017-01-18 15:21:53 -050079import com.android.systemui.Dependency;
Matthew Ngdc79e5c2017-12-14 17:37:35 -080080import com.android.systemui.OverviewProxyService;
Mike Digman7d092772018-01-11 12:10:32 -080081import com.android.systemui.Interpolators;
Jason Monk49fa0162017-01-11 09:21:56 -050082import com.android.systemui.R;
Jason Monk9c7844c2017-01-18 15:21:53 -050083import com.android.systemui.SysUiServiceProvider;
Jason Monk49fa0162017-01-11 09:21:56 -050084import com.android.systemui.assist.AssistManager;
85import com.android.systemui.fragments.FragmentHostManager;
86import com.android.systemui.fragments.FragmentHostManager.FragmentListener;
87import com.android.systemui.recents.Recents;
Mike Digman7d092772018-01-11 12:10:32 -080088import com.android.systemui.recents.misc.SysUiTaskStackChangeListener;
89import com.android.systemui.shared.system.ActivityManagerWrapper;
Jason Monk49fa0162017-01-11 09:21:56 -050090import com.android.systemui.stackdivider.Divider;
91import com.android.systemui.statusbar.CommandQueue;
92import com.android.systemui.statusbar.CommandQueue.Callbacks;
Jason Monk91e587e2017-04-13 13:41:23 -040093import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
Mike Digman7d092772018-01-11 12:10:32 -080094import com.android.systemui.statusbar.policy.KeyButtonDrawable;
Jason Monk49fa0162017-01-11 09:21:56 -050095import com.android.systemui.statusbar.policy.KeyButtonView;
Mike Digman7d092772018-01-11 12:10:32 -080096import com.android.systemui.statusbar.policy.RotationLockController;
Jason Monk49fa0162017-01-11 09:21:56 -050097import com.android.systemui.statusbar.stack.StackStateAnimator;
98
99import java.io.FileDescriptor;
100import java.io.PrintWriter;
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800101import java.util.List;
Jason Monk49fa0162017-01-11 09:21:56 -0500102import java.util.Locale;
103
104/**
105 * Fragment containing the NavigationBarFragment. Contains logic for what happens
106 * on clicks and view states of the nav bar.
107 */
108public class NavigationBarFragment extends Fragment implements Callbacks {
109
Jason Monkd4afe152017-05-01 15:37:43 -0400110 public static final String TAG = "NavigationBar";
Jason Monk49fa0162017-01-11 09:21:56 -0500111 private static final boolean DEBUG = false;
112 private static final String EXTRA_DISABLE_STATE = "disabled_state";
113
114 /** Allow some time inbetween the long press for back and recents. */
115 private static final int LOCK_TO_APP_GESTURE_TOLERENCE = 200;
116
Mike Digman90402952018-01-22 16:05:51 -0800117 private static final int BUTTON_FADE_IN_OUT_DURATION_MS = 100;
Mike Digman7d092772018-01-11 12:10:32 -0800118
Jason Monk49fa0162017-01-11 09:21:56 -0500119 protected NavigationBarView mNavigationBarView = null;
120 protected AssistManager mAssistManager;
121
122 private int mNavigationBarWindowState = WINDOW_STATE_SHOWING;
123
124 private int mNavigationIconHints = 0;
125 private int mNavigationBarMode;
Mike Digman90402952018-01-22 16:05:51 -0800126 private boolean mAccessibilityFeedbackEnabled;
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800127 private AccessibilityManager mAccessibilityManager;
Casey Burkhardt74922c62017-02-13 12:43:16 -0800128 private MagnificationContentObserver mMagnificationObserver;
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700129 private ContentResolver mContentResolver;
Mike Digmanc94759d2018-01-23 11:01:21 -0800130 private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500131
132 private int mDisabledFlags1;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500133 private StatusBar mStatusBar;
Jason Monk49fa0162017-01-11 09:21:56 -0500134 private Recents mRecents;
135 private Divider mDivider;
136 private WindowManager mWindowManager;
137 private CommandQueue mCommandQueue;
138 private long mLastLockToAppLongPress;
139
140 private Locale mLocale;
141 private int mLayoutDirection;
142
143 private int mSystemUiVisibility;
144 private LightBarController mLightBarController;
Jason Monk49fa0162017-01-11 09:21:56 -0500145
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800146 private OverviewProxyService mOverviewProxyService;
147
Jason Monk49fa0162017-01-11 09:21:56 -0500148 public boolean mHomeBlockedThisTouch;
149
Mike Digman7d092772018-01-11 12:10:32 -0800150 private int mLastRotationSuggestion;
Mike Digman90402952018-01-22 16:05:51 -0800151 private boolean mHoveringRotationSuggestion;
Mike Digman7d092772018-01-11 12:10:32 -0800152 private RotationLockController mRotationLockController;
153 private TaskStackListenerImpl mTaskStackListener;
154
155 private final Runnable mRemoveRotationProposal = () -> setRotateSuggestionButtonState(false);
156 private Animator mRotateShowAnimator;
157 private Animator mRotateHideAnimator;
158
Matthew Ng9c3bce52018-02-01 22:00:31 +0000159 private final OverviewProxyListener mOverviewProxyListener = new OverviewProxyListener() {
160 @Override
161 public void onConnectionChanged(boolean isConnected) {
162 mNavigationBarView.onOverviewProxyConnectionChanged(isConnected);
163 updateScreenPinningGestures();
164 }
165
166 @Override
167 public void onRecentsAnimationStarted() {
168 mNavigationBarView.setRecentsAnimationStarted(true);
169 }
170 };
Mike Digman7d092772018-01-11 12:10:32 -0800171
Jason Monk49fa0162017-01-11 09:21:56 -0500172 // ----- Fragment Lifecycle Callbacks -----
173
174 @Override
175 public void onCreate(@Nullable Bundle savedInstanceState) {
176 super.onCreate(savedInstanceState);
Jason Monk9c7844c2017-01-18 15:21:53 -0500177 mCommandQueue = SysUiServiceProvider.getComponent(getContext(), CommandQueue.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500178 mCommandQueue.addCallbacks(this);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500179 mStatusBar = SysUiServiceProvider.getComponent(getContext(), StatusBar.class);
Jason Monk9c7844c2017-01-18 15:21:53 -0500180 mRecents = SysUiServiceProvider.getComponent(getContext(), Recents.class);
181 mDivider = SysUiServiceProvider.getComponent(getContext(), Divider.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500182 mWindowManager = getContext().getSystemService(WindowManager.class);
183 mAccessibilityManager = getContext().getSystemService(AccessibilityManager.class);
Jason Monk91e587e2017-04-13 13:41:23 -0400184 Dependency.get(AccessibilityManagerWrapper.class).addCallback(
185 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700186 mContentResolver = getContext().getContentResolver();
Casey Burkhardt74922c62017-02-13 12:43:16 -0800187 mMagnificationObserver = new MagnificationContentObserver(
188 getContext().getMainThreadHandler());
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700189 mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
Casey Burkhardt74922c62017-02-13 12:43:16 -0800190 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED), false,
Casey Burkhardt5d614402017-04-06 13:46:50 -0700191 mMagnificationObserver, UserHandle.USER_ALL);
Casey Burkhardt74922c62017-02-13 12:43:16 -0800192
Jason Monk49fa0162017-01-11 09:21:56 -0500193 if (savedInstanceState != null) {
194 mDisabledFlags1 = savedInstanceState.getInt(EXTRA_DISABLE_STATE, 0);
195 }
Jason Monk9c7844c2017-01-18 15:21:53 -0500196 mAssistManager = Dependency.get(AssistManager.class);
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800197 mOverviewProxyService = Dependency.get(OverviewProxyService.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500198
199 try {
200 WindowManagerGlobal.getWindowManagerService()
Andrii Kulian35fa3c22017-03-11 09:37:28 -0800201 .watchRotation(mRotationWatcher, getContext().getDisplay().getDisplayId());
Jason Monk49fa0162017-01-11 09:21:56 -0500202 } catch (RemoteException e) {
203 throw e.rethrowFromSystemServer();
204 }
Mike Digman7d092772018-01-11 12:10:32 -0800205
206 mRotationLockController = Dependency.get(RotationLockController.class);
207
208 // Register the task stack listener
209 mTaskStackListener = new TaskStackListenerImpl();
210 ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500211 }
212
213 @Override
214 public void onDestroy() {
215 super.onDestroy();
216 mCommandQueue.removeCallbacks(this);
Jason Monk91e587e2017-04-13 13:41:23 -0400217 Dependency.get(AccessibilityManagerWrapper.class).removeCallback(
218 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700219 mContentResolver.unregisterContentObserver(mMagnificationObserver);
Jason Monk49fa0162017-01-11 09:21:56 -0500220 try {
221 WindowManagerGlobal.getWindowManagerService()
222 .removeRotationWatcher(mRotationWatcher);
223 } catch (RemoteException e) {
224 throw e.rethrowFromSystemServer();
225 }
Mike Digman7d092772018-01-11 12:10:32 -0800226
227 // Unregister the task stack listener
228 ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500229 }
230
231 @Override
232 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
233 Bundle savedInstanceState) {
234 return inflater.inflate(R.layout.navigation_bar, container, false);
235 }
236
237 @Override
238 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
239 super.onViewCreated(view, savedInstanceState);
240 mNavigationBarView = (NavigationBarView) view;
241
242 mNavigationBarView.setDisabledFlags(mDisabledFlags1);
Matthew Ng78f88d12018-01-23 12:39:55 -0800243 mNavigationBarView.setComponents(mRecents, mDivider, mStatusBar.getPanel());
Jason Monk49fa0162017-01-11 09:21:56 -0500244 mNavigationBarView.setOnVerticalChangedListener(this::onVerticalChanged);
245 mNavigationBarView.setOnTouchListener(this::onNavigationTouch);
246 if (savedInstanceState != null) {
247 mNavigationBarView.getLightTransitionsController().restoreState(savedInstanceState);
248 }
249
250 prepareNavigationBarView();
251 checkNavBarModes();
252
253 IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
254 filter.addAction(Intent.ACTION_SCREEN_ON);
255 getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100256 notifyNavigationBarScreenOn();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000257 mOverviewProxyService.addCallback(mOverviewProxyListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500258 }
259
260 @Override
261 public void onDestroyView() {
262 super.onDestroyView();
Jason Monkaa573e92017-01-27 17:00:29 -0500263 mNavigationBarView.getLightTransitionsController().destroy(getContext());
Matthew Ng9c3bce52018-02-01 22:00:31 +0000264 mOverviewProxyService.removeCallback(mOverviewProxyListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500265 getContext().unregisterReceiver(mBroadcastReceiver);
266 }
267
268 @Override
269 public void onSaveInstanceState(Bundle outState) {
270 super.onSaveInstanceState(outState);
271 outState.putInt(EXTRA_DISABLE_STATE, mDisabledFlags1);
272 if (mNavigationBarView != null) {
273 mNavigationBarView.getLightTransitionsController().saveState(outState);
274 }
275 }
276
277 @Override
278 public void onConfigurationChanged(Configuration newConfig) {
279 super.onConfigurationChanged(newConfig);
280 final Locale locale = getContext().getResources().getConfiguration().locale;
281 final int ld = TextUtils.getLayoutDirectionFromLocale(locale);
282 if (!locale.equals(mLocale) || ld != mLayoutDirection) {
283 if (DEBUG) {
284 Log.v(TAG, String.format(
285 "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection,
286 locale, ld));
287 }
288 mLocale = locale;
289 mLayoutDirection = ld;
290 refreshLayout(ld);
291 }
292 repositionNavigationBar();
293 }
294
295 @Override
296 public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) {
297 if (mNavigationBarView != null) {
298 pw.print(" mNavigationBarWindowState=");
299 pw.println(windowStateToString(mNavigationBarWindowState));
300 pw.print(" mNavigationBarMode=");
301 pw.println(BarTransitions.modeToString(mNavigationBarMode));
302 dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions());
303 }
304
305 pw.print(" mNavigationBarView=");
306 if (mNavigationBarView == null) {
307 pw.println("null");
308 } else {
309 mNavigationBarView.dump(fd, pw, args);
310 }
311 }
312
313 // ----- CommandQueue Callbacks -----
314
315 @Override
316 public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
317 boolean showImeSwitcher) {
318 boolean imeShown = (vis & InputMethodService.IME_VISIBLE) != 0;
319 int hints = mNavigationIconHints;
Tarandeep Singh3fecef12018-01-22 14:33:33 -0800320 if (imeShown && backDisposition != InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS) {
Jason Monk49fa0162017-01-11 09:21:56 -0500321 hints |= NAVIGATION_HINT_BACK_ALT;
322 } else {
323 hints &= ~NAVIGATION_HINT_BACK_ALT;
324 }
325 if (showImeSwitcher) {
326 hints |= NAVIGATION_HINT_IME_SHOWN;
327 } else {
328 hints &= ~NAVIGATION_HINT_IME_SHOWN;
329 }
330 if (hints == mNavigationIconHints) return;
331
332 mNavigationIconHints = hints;
333
334 if (mNavigationBarView != null) {
335 mNavigationBarView.setNavigationIconHints(hints);
336 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500337 mStatusBar.checkBarModes();
Jason Monk49fa0162017-01-11 09:21:56 -0500338 }
339
340 @Override
341 public void topAppWindowChanged(boolean showMenu) {
342 if (mNavigationBarView != null) {
343 mNavigationBarView.setMenuVisibility(showMenu);
344 }
345 }
346
347 @Override
348 public void setWindowState(int window, int state) {
349 if (mNavigationBarView != null
350 && window == StatusBarManager.WINDOW_NAVIGATION_BAR
351 && mNavigationBarWindowState != state) {
352 mNavigationBarWindowState = state;
353 if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state));
354 }
355 }
356
Mike Digman7d092772018-01-11 12:10:32 -0800357 @Override
Mike Digmane0777312018-01-19 12:41:51 -0800358 public void onRotationProposal(final int rotation, boolean isValid) {
359 // This method will be called on rotation suggestion changes even if the proposed rotation
360 // is not valid for the top app. Use invalid rotation choices as a signal to remove the
361 // rotate button if shown.
362
363 if (!isValid) {
364 setRotateSuggestionButtonState(false);
365 return;
366 }
367
Mike Digman7d092772018-01-11 12:10:32 -0800368 if (rotation == mWindowManager.getDefaultDisplay().getRotation()) {
369 // Use this as a signal to remove any current suggestions
Mike Digman90402952018-01-22 16:05:51 -0800370 getView().getHandler().removeCallbacks(mRemoveRotationProposal);
Mike Digman7d092772018-01-11 12:10:32 -0800371 setRotateSuggestionButtonState(false);
372 } else {
373 mLastRotationSuggestion = rotation; // Remember rotation for click
374 setRotateSuggestionButtonState(true);
Mike Digman90402952018-01-22 16:05:51 -0800375 rescheduleRotationTimeout(false);
Mike Digmanc94759d2018-01-23 11:01:21 -0800376 mMetricsLogger.visible(MetricsEvent.ROTATION_SUGGESTION_SHOWN);
Mike Digman7d092772018-01-11 12:10:32 -0800377 }
378 }
379
Mike Digman90402952018-01-22 16:05:51 -0800380 private void rescheduleRotationTimeout(final boolean reasonHover) {
381 // May be called due to a new rotation proposal or a change in hover state
382 if (reasonHover) {
383 // Don't reschedule if a hide animator is running
384 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) {
385 return;
386 }
387 // Don't reschedule if not visible
388 if (mNavigationBarView.getRotateSuggestionButton().getVisibility() != View.VISIBLE) {
389 return;
390 }
391 }
392
393 Handler h = getView().getHandler();
394 h.removeCallbacks(mRemoveRotationProposal); // Stop any pending removal
395 h.postDelayed(mRemoveRotationProposal,
396 computeRotationProposalTimeout()); // Schedule timeout
397 }
398
399 private int computeRotationProposalTimeout() {
400 if (mAccessibilityFeedbackEnabled) return 20000;
401 if (mHoveringRotationSuggestion) return 16000;
402 return 6000;
403 }
404
Mike Digman7d092772018-01-11 12:10:32 -0800405 public void setRotateSuggestionButtonState(final boolean visible) {
406 setRotateSuggestionButtonState(visible, false);
407 }
408
409 public void setRotateSuggestionButtonState(final boolean visible, final boolean skipAnim) {
410 ButtonDispatcher rotBtn = mNavigationBarView.getRotateSuggestionButton();
Mike Digman90402952018-01-22 16:05:51 -0800411 final boolean currentlyVisible = rotBtn.getVisibility() == View.VISIBLE;
Mike Digman7d092772018-01-11 12:10:32 -0800412
413 // Rerun a show animation to indicate change but don't rerun a hide animation
414 if (!visible && !currentlyVisible) return;
415
Mike Digman90402952018-01-22 16:05:51 -0800416 View currentView = rotBtn.getCurrentView();
Mike Digman7d092772018-01-11 12:10:32 -0800417 if (currentView == null) return;
418
Mike Digman90402952018-01-22 16:05:51 -0800419 KeyButtonDrawable kbd = rotBtn.getImageDrawable();
Mike Digman7d092772018-01-11 12:10:32 -0800420 if (kbd == null) return;
421
Mike Digman90402952018-01-22 16:05:51 -0800422 AnimatedVectorDrawable animIcon = null;
423 if (kbd.getDrawable(0) instanceof AnimatedVectorDrawable) {
424 animIcon = (AnimatedVectorDrawable) kbd.getDrawable(0);
425 }
426
Mike Digman7d092772018-01-11 12:10:32 -0800427 if (visible) { // Appear and change
428 rotBtn.setVisibility(View.VISIBLE);
Eugene Susla72c510f2018-01-23 21:12:11 +0000429 mNavigationBarView.notifySubtreeAccessibilityStateChangedIfNeeded();
Mike Digman7d092772018-01-11 12:10:32 -0800430
431 if (skipAnim) {
432 currentView.setAlpha(1f);
433 return;
434 }
435
436 // Start a new animation if running
437 if (mRotateShowAnimator != null) mRotateShowAnimator.pause();
438 if (mRotateHideAnimator != null) mRotateHideAnimator.pause();
439
440 ObjectAnimator appearFade = ObjectAnimator.ofFloat(currentView, "alpha",
441 0f, 1f);
Mike Digman90402952018-01-22 16:05:51 -0800442 appearFade.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS);
Mike Digman7d092772018-01-11 12:10:32 -0800443 appearFade.setInterpolator(Interpolators.LINEAR);
444 mRotateShowAnimator = appearFade;
445 appearFade.start();
446
Mike Digman90402952018-01-22 16:05:51 -0800447 // Run the rotate icon's animation if it has one
448 if (animIcon != null) {
449 animIcon.reset();
450 animIcon.start();
451 }
452
Mike Digman7d092772018-01-11 12:10:32 -0800453 } else { // Hide
454
455 if (skipAnim) {
456 rotBtn.setVisibility(View.INVISIBLE);
Eugene Susla72c510f2018-01-23 21:12:11 +0000457 mNavigationBarView.notifySubtreeAccessibilityStateChangedIfNeeded();
Mike Digman7d092772018-01-11 12:10:32 -0800458 return;
459 }
460
461 // Don't start any new hide animations if one is running
462 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return;
463 // Pause any active show animations but don't reset the AVD to avoid jumps
464 if (mRotateShowAnimator != null) mRotateShowAnimator.pause();
465
466 ObjectAnimator fadeOut = ObjectAnimator.ofFloat(currentView, "alpha",
467 0f);
Mike Digman90402952018-01-22 16:05:51 -0800468 fadeOut.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS);
Mike Digman7d092772018-01-11 12:10:32 -0800469 fadeOut.setInterpolator(Interpolators.LINEAR);
470 fadeOut.addListener(new AnimatorListenerAdapter() {
471 @Override
472 public void onAnimationEnd(Animator animation) {
473 rotBtn.setVisibility(View.INVISIBLE);
Eugene Susla72c510f2018-01-23 21:12:11 +0000474 mNavigationBarView.notifySubtreeAccessibilityStateChangedIfNeeded();
Mike Digman7d092772018-01-11 12:10:32 -0800475 }
476 });
477
478 mRotateHideAnimator = fadeOut;
479 fadeOut.start();
480 }
481 }
482
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500483 // Injected from StatusBar at creation.
Jason Monk49fa0162017-01-11 09:21:56 -0500484 public void setCurrentSysuiVisibility(int systemUiVisibility) {
485 mSystemUiVisibility = systemUiVisibility;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500486 mNavigationBarMode = mStatusBar.computeBarMode(0, mSystemUiVisibility,
Jason Monk49fa0162017-01-11 09:21:56 -0500487 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
488 View.NAVIGATION_BAR_TRANSPARENT);
489 checkNavBarModes();
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500490 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500491 mLightBarController.onNavigationVisibilityChanged(mSystemUiVisibility, 0 /* mask */,
492 true /* nbModeChanged */, mNavigationBarMode);
493 }
494
495 @Override
496 public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis,
497 int mask, Rect fullscreenStackBounds, Rect dockedStackBounds) {
498 final int oldVal = mSystemUiVisibility;
499 final int newVal = (oldVal & ~mask) | (vis & mask);
500 final int diff = newVal ^ oldVal;
501 boolean nbModeChanged = false;
502 if (diff != 0) {
503 mSystemUiVisibility = newVal;
504
505 // update navigation bar mode
506 final int nbMode = getView() == null
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500507 ? -1 : mStatusBar.computeBarMode(oldVal, newVal,
Jason Monk49fa0162017-01-11 09:21:56 -0500508 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
509 View.NAVIGATION_BAR_TRANSPARENT);
510 nbModeChanged = nbMode != -1;
511 if (nbModeChanged) {
512 if (mNavigationBarMode != nbMode) {
513 mNavigationBarMode = nbMode;
514 checkNavBarModes();
515 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500516 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500517 }
518 }
519
520 mLightBarController.onNavigationVisibilityChanged(vis, mask, nbModeChanged,
521 mNavigationBarMode);
522 }
523
524 @Override
525 public void disable(int state1, int state2, boolean animate) {
526 // All navigation bar flags are in state1.
527 int masked = state1 & (StatusBarManager.DISABLE_HOME
528 | StatusBarManager.DISABLE_RECENT
529 | StatusBarManager.DISABLE_BACK
530 | StatusBarManager.DISABLE_SEARCH);
531 if (masked != mDisabledFlags1) {
532 mDisabledFlags1 = masked;
533 if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state1);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000534 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500535 }
536 }
537
538 // ----- Internal stuffz -----
539
540 private void refreshLayout(int layoutDirection) {
541 if (mNavigationBarView != null) {
542 mNavigationBarView.setLayoutDirection(layoutDirection);
543 }
544 }
545
546 private boolean shouldDisableNavbarGestures() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500547 return !mStatusBar.isDeviceProvisioned()
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800548 || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0
Matthew Ng9c3bce52018-02-01 22:00:31 +0000549 || mNavigationBarView.getRecentsButton().getVisibility() != View.VISIBLE;
Jason Monk49fa0162017-01-11 09:21:56 -0500550 }
551
552 private void repositionNavigationBar() {
553 if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return;
554
555 prepareNavigationBarView();
556
557 mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(),
558 ((View) mNavigationBarView.getParent()).getLayoutParams());
559 }
560
Matthew Ng9c3bce52018-02-01 22:00:31 +0000561 private void updateScreenPinningGestures() {
562 if (mNavigationBarView == null) {
563 return;
564 }
565
566 // Change the cancel pin gesture to home and back if recents button is invisible
567 boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible();
568 ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
569 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
570 if (recentsVisible) {
571 homeButton.setOnLongClickListener(this::onHomeLongClick);
572 backButton.setOnLongClickListener(this::onLongPressBackRecents);
573 } else {
574 homeButton.setOnLongClickListener(this::onLongPressBackHome);
575 backButton.setOnLongClickListener(this::onLongPressBackHome);
576 }
577 }
578
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100579 private void notifyNavigationBarScreenOn() {
580 mNavigationBarView.notifyScreenOn();
Jason Monk49fa0162017-01-11 09:21:56 -0500581 }
582
583 private void prepareNavigationBarView() {
584 mNavigationBarView.reorient();
585
586 ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton();
587 recentsButton.setOnClickListener(this::onRecentsClick);
588 recentsButton.setOnTouchListener(this::onRecentsTouch);
589 recentsButton.setLongClickable(true);
590 recentsButton.setOnLongClickListener(this::onLongPressBackRecents);
591
592 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
593 backButton.setLongClickable(true);
Jason Monk49fa0162017-01-11 09:21:56 -0500594
595 ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
596 homeButton.setOnTouchListener(this::onHomeTouch);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800597
598 ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton();
599 accessibilityButton.setOnClickListener(this::onAccessibilityClick);
600 accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick);
Phil Weaverdb9a7742017-04-18 08:15:06 -0700601 updateAccessibilityServicesState(mAccessibilityManager);
Mike Digman7d092772018-01-11 12:10:32 -0800602
603 ButtonDispatcher rotateSuggestionButton = mNavigationBarView.getRotateSuggestionButton();
604 rotateSuggestionButton.setOnClickListener(this::onRotateSuggestionClick);
Mike Digman90402952018-01-22 16:05:51 -0800605 rotateSuggestionButton.setOnHoverListener(this::onRotateSuggestionHover);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000606 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500607 }
608
609 private boolean onHomeTouch(View v, MotionEvent event) {
610 if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) {
611 return true;
612 }
613 // If an incoming call is ringing, HOME is totally disabled.
614 // (The user is already on the InCallUI at this point,
615 // and his ONLY options are to answer or reject the call.)
616 switch (event.getAction()) {
617 case MotionEvent.ACTION_DOWN:
618 mHomeBlockedThisTouch = false;
619 TelecomManager telecomManager =
620 getContext().getSystemService(TelecomManager.class);
621 if (telecomManager != null && telecomManager.isRinging()) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500622 if (mStatusBar.isKeyguardShowing()) {
Jason Monk49fa0162017-01-11 09:21:56 -0500623 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " +
624 "No heads up");
625 mHomeBlockedThisTouch = true;
626 return true;
627 }
628 }
629 break;
630 case MotionEvent.ACTION_UP:
631 case MotionEvent.ACTION_CANCEL:
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500632 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500633 break;
634 }
635 return false;
636 }
637
638 private void onVerticalChanged(boolean isVertical) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500639 mStatusBar.setQsScrimEnabled(!isVertical);
Jason Monk49fa0162017-01-11 09:21:56 -0500640 }
641
642 private boolean onNavigationTouch(View v, MotionEvent event) {
Eliot Courtneycb5d3162017-08-09 16:53:15 +0900643 mStatusBar.checkUserAutohide(event);
Jason Monk49fa0162017-01-11 09:21:56 -0500644 return false;
645 }
646
Jason Monk865246d2017-01-19 08:27:01 -0500647 @VisibleForTesting
648 boolean onHomeLongClick(View v) {
Jason Monk49fa0162017-01-11 09:21:56 -0500649 if (shouldDisableNavbarGestures()) {
650 return false;
651 }
Mike Digmanc94759d2018-01-23 11:01:21 -0800652 mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS);
Jason Monk49fa0162017-01-11 09:21:56 -0500653 mAssistManager.startAssist(new Bundle() /* args */);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500654 mStatusBar.awakenDreams();
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800655
Jason Monk49fa0162017-01-11 09:21:56 -0500656 if (mNavigationBarView != null) {
657 mNavigationBarView.abortCurrentGesture();
658 }
659 return true;
660 }
661
662 // additional optimization when we have software system buttons - start loading the recent
663 // tasks on touch down
664 private boolean onRecentsTouch(View v, MotionEvent event) {
665 int action = event.getAction() & MotionEvent.ACTION_MASK;
666 if (action == MotionEvent.ACTION_DOWN) {
667 mCommandQueue.preloadRecentApps();
668 } else if (action == MotionEvent.ACTION_CANCEL) {
669 mCommandQueue.cancelPreloadRecentApps();
670 } else if (action == MotionEvent.ACTION_UP) {
671 if (!v.isPressed()) {
672 mCommandQueue.cancelPreloadRecentApps();
673 }
674 }
675 return false;
676 }
677
678 private void onRecentsClick(View v) {
679 if (LatencyTracker.isEnabled(getContext())) {
680 LatencyTracker.getInstance(getContext()).onActionStart(
681 LatencyTracker.ACTION_TOGGLE_RECENTS);
682 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500683 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500684 mCommandQueue.toggleRecentApps();
685 }
686
Matthew Ng9c3bce52018-02-01 22:00:31 +0000687 private boolean onLongPressBackHome(View v) {
688 return onLongPressNavigationButtons(v, R.id.back, R.id.home);
689 }
690
691 private boolean onLongPressBackRecents(View v) {
692 return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps);
693 }
694
Jason Monk49fa0162017-01-11 09:21:56 -0500695 /**
Matthew Ng9c3bce52018-02-01 22:00:31 +0000696 * This handles long-press of both back and recents/home. Back is the common button with
697 * combination of recents if it is visible or home if recents is invisible.
698 * They are handled together to capture them both being long-pressed
Jason Monk49fa0162017-01-11 09:21:56 -0500699 * at the same time to exit screen pinning (lock task).
700 *
Matthew Ng9c3bce52018-02-01 22:00:31 +0000701 * When accessibility mode is on, only a long-press from recents/home
Jason Monk49fa0162017-01-11 09:21:56 -0500702 * is required to exit.
703 *
704 * In all other circumstances we try to pass through long-press events
705 * for Back, so that apps can still use it. Which can be from two things.
706 * 1) Not currently in screen pinning (lock task).
Matthew Ng9c3bce52018-02-01 22:00:31 +0000707 * 2) Back is long-pressed without recents/home.
Jason Monk49fa0162017-01-11 09:21:56 -0500708 */
Matthew Ng9c3bce52018-02-01 22:00:31 +0000709 private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) {
Jason Monk49fa0162017-01-11 09:21:56 -0500710 try {
711 boolean sendBackLongPress = false;
712 IActivityManager activityManager = ActivityManagerNative.getDefault();
713 boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled();
714 boolean inLockTaskMode = activityManager.isInLockTaskMode();
715 if (inLockTaskMode && !touchExplorationEnabled) {
716 long time = System.currentTimeMillis();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000717
Jason Monk49fa0162017-01-11 09:21:56 -0500718 // If we recently long-pressed the other button then they were
719 // long-pressed 'together'
720 if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) {
Benjamin Franza83859f2017-07-03 16:34:14 +0100721 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500722 // When exiting refresh disabled flags.
723 mNavigationBarView.setDisabledFlags(mDisabledFlags1, true);
724 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000725 } else if (v.getId() == btnId1) {
726 ButtonDispatcher button = btnId2 == R.id.recent_apps
727 ? mNavigationBarView.getRecentsButton()
728 : mNavigationBarView.getHomeButton();
729 if (!button.getCurrentView().isPressed()) {
730 // If we aren't pressing recents/home right now then they presses
731 // won't be together, so send the standard long-press action.
732 sendBackLongPress = true;
733 }
Jason Monk49fa0162017-01-11 09:21:56 -0500734 }
735 mLastLockToAppLongPress = time;
736 } else {
737 // If this is back still need to handle sending the long-press event.
Matthew Ng9c3bce52018-02-01 22:00:31 +0000738 if (v.getId() == btnId1) {
Jason Monk49fa0162017-01-11 09:21:56 -0500739 sendBackLongPress = true;
740 } else if (touchExplorationEnabled && inLockTaskMode) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000741 // When in accessibility mode a long press that is recents/home (not back)
Jason Monk49fa0162017-01-11 09:21:56 -0500742 // should stop lock task.
Benjamin Franza83859f2017-07-03 16:34:14 +0100743 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500744 // When exiting refresh disabled flags.
745 mNavigationBarView.setDisabledFlags(mDisabledFlags1, true);
746 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000747 } else if (v.getId() == btnId2) {
748 return btnId2 == R.id.recent_apps
749 ? onLongPressRecents()
750 : onHomeLongClick(mNavigationBarView.getHomeButton().getCurrentView());
Jason Monk49fa0162017-01-11 09:21:56 -0500751 }
752 }
753 if (sendBackLongPress) {
754 KeyButtonView keyButtonView = (KeyButtonView) v;
755 keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
756 keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
757 return true;
758 }
759 } catch (RemoteException e) {
760 Log.d(TAG, "Unable to reach activity manager", e);
761 }
762 return false;
763 }
764
765 private boolean onLongPressRecents() {
Erik Wolsheimer9be3a062017-05-31 14:59:57 -0700766 if (mRecents == null || !ActivityManager.supportsMultiWindow(getContext())
Matthew Ng43db6d22017-06-27 15:29:39 -0700767 || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible()
768 || Recents.getConfiguration().isLowRamDevice) {
Jason Monk49fa0162017-01-11 09:21:56 -0500769 return false;
770 }
771
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500772 return mStatusBar.toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS,
Jason Monk49fa0162017-01-11 09:21:56 -0500773 MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS);
774 }
775
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800776 private void onAccessibilityClick(View v) {
777 mAccessibilityManager.notifyAccessibilityButtonClicked();
778 }
779
780 private boolean onAccessibilityLongClick(View v) {
Casey Burkhardt5e8b9802017-03-24 10:07:20 -0700781 Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON);
782 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Casey Burkhardt5d614402017-04-06 13:46:50 -0700783 v.getContext().startActivityAsUser(intent, UserHandle.CURRENT);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800784 return true;
785 }
786
Phil Weaverdb9a7742017-04-18 08:15:06 -0700787 private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800788 int requestingServices = 0;
789 try {
Casey Burkhardt5d614402017-04-06 13:46:50 -0700790 if (Settings.Secure.getIntForUser(mContentResolver,
791 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
792 UserHandle.USER_CURRENT) == 1) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800793 requestingServices++;
794 }
795 } catch (Settings.SettingNotFoundException e) {
796 }
797
Mike Digman90402952018-01-22 16:05:51 -0800798 boolean feedbackEnabled = false;
Casey Burkhardt5d614402017-04-06 13:46:50 -0700799 // AccessibilityManagerService resolves services for the current user since the local
800 // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800801 final List<AccessibilityServiceInfo> services =
Phil Weaverdb9a7742017-04-18 08:15:06 -0700802 accessibilityManager.getEnabledAccessibilityServiceList(
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800803 AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800804 for (int i = services.size() - 1; i >= 0; --i) {
805 AccessibilityServiceInfo info = services.get(i);
806 if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) {
807 requestingServices++;
808 }
Mike Digman90402952018-01-22 16:05:51 -0800809
810 if (info.feedbackType != 0 && info.feedbackType !=
811 AccessibilityServiceInfo.FEEDBACK_GENERIC) {
812 feedbackEnabled = true;
813 }
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800814 }
815
Mike Digman90402952018-01-22 16:05:51 -0800816 mAccessibilityFeedbackEnabled = feedbackEnabled;
817
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800818 final boolean showAccessibilityButton = requestingServices >= 1;
819 final boolean targetSelection = requestingServices >= 2;
820 mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection);
821 }
822
Mike Digman7d092772018-01-11 12:10:32 -0800823 private void onRotateSuggestionClick(View v) {
Mike Digmanc94759d2018-01-23 11:01:21 -0800824 mMetricsLogger.action(MetricsEvent.ACTION_ROTATION_SUGGESTION_ACCEPTED);
Mike Digman7d092772018-01-11 12:10:32 -0800825 mRotationLockController.setRotationLockedAtAngle(true, mLastRotationSuggestion);
826 }
827
Mike Digman90402952018-01-22 16:05:51 -0800828 private boolean onRotateSuggestionHover(View v, MotionEvent event) {
829 final int action = event.getActionMasked();
830 mHoveringRotationSuggestion = (action == MotionEvent.ACTION_HOVER_ENTER)
831 || (action == MotionEvent.ACTION_HOVER_MOVE);
832 rescheduleRotationTimeout(true);
833 return false; // Must return false so a11y hover events are dispatched correctly.
834 }
835
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500836 // ----- Methods that StatusBar talks to (should be minimized) -----
Jason Monk49fa0162017-01-11 09:21:56 -0500837
Jason Monk49fa0162017-01-11 09:21:56 -0500838 public void setLightBarController(LightBarController lightBarController) {
839 mLightBarController = lightBarController;
840 mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController());
841 }
842
843 public boolean isSemiTransparent() {
844 return mNavigationBarMode == MODE_SEMI_TRANSPARENT;
845 }
846
Jason Monk49fa0162017-01-11 09:21:56 -0500847 public void disableAnimationsDuringHide(long delay) {
848 mNavigationBarView.setLayoutTransitionsEnabled(false);
849 mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true),
850 delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE);
851 }
852
Jason Monk49fa0162017-01-11 09:21:56 -0500853 public BarTransitions getBarTransitions() {
854 return mNavigationBarView.getBarTransitions();
855 }
856
857 public void checkNavBarModes() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500858 mStatusBar.checkBarMode(mNavigationBarMode,
Jason Monk49fa0162017-01-11 09:21:56 -0500859 mNavigationBarWindowState, mNavigationBarView.getBarTransitions());
860 }
861
862 public void finishBarAnimations() {
863 mNavigationBarView.getBarTransitions().finishAnimations();
864 }
865
Jason Monk91e587e2017-04-13 13:41:23 -0400866 private final AccessibilityServicesStateChangeListener mAccessibilityListener =
867 this::updateAccessibilityServicesState;
868
Casey Burkhardt74922c62017-02-13 12:43:16 -0800869 private class MagnificationContentObserver extends ContentObserver {
870
871 public MagnificationContentObserver(Handler handler) {
872 super(handler);
873 }
874
875 @Override
876 public void onChange(boolean selfChange) {
Phil Weaverdb9a7742017-04-18 08:15:06 -0700877 NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager);
Casey Burkhardt74922c62017-02-13 12:43:16 -0800878 }
879 }
880
Jason Monk49fa0162017-01-11 09:21:56 -0500881 private final Stub mRotationWatcher = new Stub() {
882 @Override
Mike Digman90402952018-01-22 16:05:51 -0800883 public void onRotationChanged(final int rotation) throws RemoteException {
Jason Monk49fa0162017-01-11 09:21:56 -0500884 // We need this to be scheduled as early as possible to beat the redrawing of
885 // window in response to the orientation change.
886 Handler h = getView().getHandler();
887 Message msg = Message.obtain(h, () -> {
Mike Digman85ff7fa2018-01-23 14:59:52 -0800888
889 // If the screen rotation changes while locked, potentially update lock to flow with
Mike Digman90402952018-01-22 16:05:51 -0800890 // new screen rotation and hide any showing suggestions.
891 if (mRotationLockController.isRotationLocked()) {
Mike Digman85ff7fa2018-01-23 14:59:52 -0800892 if (shouldOverrideUserLockPrefs(rotation)) {
893 mRotationLockController.setRotationLockedAtAngle(true, rotation);
894 }
Mike Digman90402952018-01-22 16:05:51 -0800895 setRotateSuggestionButtonState(false, true);
896 }
897
Jason Monk49fa0162017-01-11 09:21:56 -0500898 if (mNavigationBarView != null
899 && mNavigationBarView.needsReorient(rotation)) {
900 repositionNavigationBar();
901 }
902 });
903 msg.setAsynchronous(true);
904 h.sendMessageAtFrontOfQueue(msg);
905 }
Mike Digman85ff7fa2018-01-23 14:59:52 -0800906
907 private boolean shouldOverrideUserLockPrefs(final int rotation) {
908 // Only override user prefs when returning to portrait.
909 // Don't let apps that force landscape or 180 alter user lock.
910 return rotation == Surface.ROTATION_0;
911 }
Jason Monk49fa0162017-01-11 09:21:56 -0500912 };
913
914 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
915 @Override
916 public void onReceive(Context context, Intent intent) {
917 String action = intent.getAction();
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100918 if (Intent.ACTION_SCREEN_OFF.equals(action)
919 || Intent.ACTION_SCREEN_ON.equals(action)) {
920 notifyNavigationBarScreenOn();
Jason Monk49fa0162017-01-11 09:21:56 -0500921 }
922 }
923 };
924
Mike Digman7d092772018-01-11 12:10:32 -0800925 class TaskStackListenerImpl extends SysUiTaskStackChangeListener {
926 // Invalidate any rotation suggestion on task change or activity orientation change
927 // Note: all callbacks happen on main thread
928
929 @Override
930 public void onTaskStackChanged() {
931 setRotateSuggestionButtonState(false);
932 }
933
934 @Override
935 public void onTaskRemoved(int taskId) {
936 setRotateSuggestionButtonState(false);
937 }
938
939 @Override
940 public void onTaskMovedToFront(int taskId) {
941 setRotateSuggestionButtonState(false);
942 }
943
944 @Override
945 public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation) {
946 setRotateSuggestionButtonState(false);
947 }
948 }
949
Jason Monk49fa0162017-01-11 09:21:56 -0500950 public static View create(Context context, FragmentListener listener) {
951 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
952 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
953 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
954 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
955 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
956 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
957 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
958 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
959 | WindowManager.LayoutParams.FLAG_SLIPPERY,
960 PixelFormat.TRANSLUCENT);
961 lp.token = new Binder();
Jason Monk49fa0162017-01-11 09:21:56 -0500962 lp.setTitle("NavigationBar");
963 lp.windowAnimations = 0;
964
965 View navigationBarView = LayoutInflater.from(context).inflate(
966 R.layout.navigation_bar_window, null);
967
968 if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView);
969 if (navigationBarView == null) return null;
970
971 context.getSystemService(WindowManager.class).addView(navigationBarView, lp);
972 FragmentHostManager fragmentHost = FragmentHostManager.get(navigationBarView);
973 NavigationBarFragment fragment = new NavigationBarFragment();
974 fragmentHost.getFragmentManager().beginTransaction()
975 .replace(R.id.navigation_bar_frame, fragment, TAG)
976 .commit();
977 fragmentHost.addTagListener(TAG, listener);
978 return navigationBarView;
979 }
980}