blob: 329a33d91b1b2295a3dc62b2a3ff4f1f945e9e43 [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
Winson Chung2dbcf092018-10-24 13:00:41 -070022import static com.android.systemui.recents.OverviewProxyService.OverviewProxyListener;
Matthew Ng8f25fb962018-01-16 17:17:24 -080023import static com.android.systemui.shared.system.NavigationBarCompat.InteractionType;
Tracy Zhou1ac592c2018-07-25 13:47:37 -070024import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT_TRANSPARENT;
Jason Monk49fa0162017-01-11 09:21:56 -050025import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT;
Tracy Zhou1ac592c2018-07-25 13:47:37 -070026import static com.android.systemui.statusbar.phone.BarTransitions.MODE_TRANSPARENT;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050027import static com.android.systemui.statusbar.phone.StatusBar.DEBUG_WINDOW_STATE;
28import static com.android.systemui.statusbar.phone.StatusBar.dumpBarTransitions;
Jason Monk49fa0162017-01-11 09:21:56 -050029
Casey Burkhardt048c2bc2016-12-08 16:09:20 -080030import android.accessibilityservice.AccessibilityServiceInfo;
Matthew Ng9c3bce52018-02-01 22:00:31 +000031import android.annotation.IdRes;
Jason Monk49fa0162017-01-11 09:21:56 -050032import android.annotation.Nullable;
Winson Chung67f5c8b2018-09-24 12:09:19 -070033import android.app.ActivityManager;
Wale Ogunwale65ebd952018-04-25 15:41:44 -070034import android.app.ActivityTaskManager;
Jason Monk49fa0162017-01-11 09:21:56 -050035import android.app.Fragment;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -070036import android.app.IActivityTaskManager;
Jason Monk49fa0162017-01-11 09:21:56 -050037import 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;
47import android.inputmethodservice.InputMethodService;
48import android.os.Binder;
49import android.os.Bundle;
50import android.os.Handler;
51import android.os.IBinder;
Jason Monk49fa0162017-01-11 09:21:56 -050052import android.os.RemoteException;
53import android.os.UserHandle;
Casey Burkhardt74922c62017-02-13 12:43:16 -080054import android.provider.Settings;
Jason Monk49fa0162017-01-11 09:21:56 -050055import android.telecom.TelecomManager;
56import android.text.TextUtils;
57import android.util.Log;
58import android.view.IRotationWatcher.Stub;
59import android.view.KeyEvent;
60import android.view.LayoutInflater;
61import android.view.MotionEvent;
Mike Digman85ff7fa2018-01-23 14:59:52 -080062import android.view.Surface;
Jason Monk49fa0162017-01-11 09:21:56 -050063import android.view.View;
64import android.view.ViewGroup;
65import android.view.WindowManager;
66import android.view.WindowManager.LayoutParams;
Jason Monk49fa0162017-01-11 09:21:56 -050067import android.view.accessibility.AccessibilityEvent;
68import android.view.accessibility.AccessibilityManager;
Jason Monk91e587e2017-04-13 13:41:23 -040069import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener;
Jason Monk49fa0162017-01-11 09:21:56 -050070
Matthew Ng761562d2018-09-17 11:13:21 -070071import androidx.annotation.VisibleForTesting;
72
Jason Monk49fa0162017-01-11 09:21:56 -050073import com.android.internal.logging.MetricsLogger;
74import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jason Monkea03be12017-12-04 11:08:41 -050075import com.android.internal.util.LatencyTracker;
Jason Monk9c7844c2017-01-18 15:21:53 -050076import com.android.systemui.Dependency;
Winson Chung2dbcf092018-10-24 13:00:41 -070077import com.android.systemui.recents.OverviewProxyService;
Jason Monk49fa0162017-01-11 09:21:56 -050078import com.android.systemui.R;
Jason Monk9c7844c2017-01-18 15:21:53 -050079import com.android.systemui.SysUiServiceProvider;
Jason Monk49fa0162017-01-11 09:21:56 -050080import com.android.systemui.assist.AssistManager;
81import com.android.systemui.fragments.FragmentHostManager;
82import com.android.systemui.fragments.FragmentHostManager.FragmentListener;
83import com.android.systemui.recents.Recents;
Mike Digman7d092772018-01-11 12:10:32 -080084import com.android.systemui.shared.system.ActivityManagerWrapper;
Jason Monk49fa0162017-01-11 09:21:56 -050085import com.android.systemui.stackdivider.Divider;
86import com.android.systemui.statusbar.CommandQueue;
87import com.android.systemui.statusbar.CommandQueue.Callbacks;
Matthew Ng761562d2018-09-17 11:13:21 -070088import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
89import com.android.systemui.statusbar.phone.ContextualButton.ContextButtonListener;
Jason Monk91e587e2017-04-13 13:41:23 -040090import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
Jason Monk297c04e2018-08-23 17:16:59 -040091import com.android.systemui.statusbar.policy.DeviceProvisionedController;
Jason Monk49fa0162017-01-11 09:21:56 -050092import com.android.systemui.statusbar.policy.KeyButtonView;
Jason Monk49fa0162017-01-11 09:21:56 -050093
94import java.io.FileDescriptor;
95import java.io.PrintWriter;
Casey Burkhardt048c2bc2016-12-08 16:09:20 -080096import java.util.List;
Jason Monk49fa0162017-01-11 09:21:56 -050097import java.util.Locale;
Matthew Ng761562d2018-09-17 11:13:21 -070098import java.util.function.Consumer;
Jason Monk49fa0162017-01-11 09:21:56 -050099
100/**
101 * Fragment containing the NavigationBarFragment. Contains logic for what happens
102 * on clicks and view states of the nav bar.
103 */
104public class NavigationBarFragment extends Fragment implements Callbacks {
105
Jason Monkd4afe152017-05-01 15:37:43 -0400106 public static final String TAG = "NavigationBar";
Jason Monk49fa0162017-01-11 09:21:56 -0500107 private static final boolean DEBUG = false;
108 private static final String EXTRA_DISABLE_STATE = "disabled_state";
Mike Digmandd2f49e2018-03-16 10:54:22 -0700109 private static final String EXTRA_DISABLE2_STATE = "disabled2_state";
Jason Monk49fa0162017-01-11 09:21:56 -0500110
111 /** Allow some time inbetween the long press for back and recents. */
112 private static final int LOCK_TO_APP_GESTURE_TOLERENCE = 200;
113
Jason Monk297c04e2018-08-23 17:16:59 -0400114 private final DeviceProvisionedController mDeviceProvisionedController =
115 Dependency.get(DeviceProvisionedController.class);
116
Jason Monk49fa0162017-01-11 09:21:56 -0500117 protected NavigationBarView mNavigationBarView = null;
118 protected AssistManager mAssistManager;
119
120 private int mNavigationBarWindowState = WINDOW_STATE_SHOWING;
121
122 private int mNavigationIconHints = 0;
123 private int mNavigationBarMode;
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800124 private AccessibilityManager mAccessibilityManager;
Casey Burkhardt74922c62017-02-13 12:43:16 -0800125 private MagnificationContentObserver mMagnificationObserver;
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700126 private ContentResolver mContentResolver;
Mike Digmanc94759d2018-01-23 11:01:21 -0800127 private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500128
129 private int mDisabledFlags1;
Mike Digmandd2f49e2018-03-16 10:54:22 -0700130 private int mDisabledFlags2;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500131 private StatusBar mStatusBar;
Jason Monk49fa0162017-01-11 09:21:56 -0500132 private Recents mRecents;
133 private Divider mDivider;
134 private WindowManager mWindowManager;
135 private CommandQueue mCommandQueue;
136 private long mLastLockToAppLongPress;
137
138 private Locale mLocale;
139 private int mLayoutDirection;
140
141 private int mSystemUiVisibility;
142 private LightBarController mLightBarController;
Jason Monk49fa0162017-01-11 09:21:56 -0500143
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800144 private OverviewProxyService mOverviewProxyService;
145
Jason Monk49fa0162017-01-11 09:21:56 -0500146 public boolean mHomeBlockedThisTouch;
147
Matthew Ng9c3bce52018-02-01 22:00:31 +0000148 private final OverviewProxyListener mOverviewProxyListener = new OverviewProxyListener() {
149 @Override
150 public void onConnectionChanged(boolean isConnected) {
Winson Chungf9e30272018-03-26 17:25:36 -0700151 mNavigationBarView.updateStates();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000152 updateScreenPinningGestures();
153 }
154
155 @Override
Matthew Ng2ea93b72018-03-14 19:43:18 +0000156 public void onQuickStepStarted() {
Mike Digman85a9bea2018-02-23 15:08:53 -0800157 // Use navbar dragging as a signal to hide the rotate button
Matthew Ng761562d2018-09-17 11:13:21 -0700158 mNavigationBarView.getRotateSuggestionButton().setRotateSuggestionButtonState(false);
Matthew Ng90ef0632018-08-15 13:53:15 -0700159
160 // Hide the notifications panel when quick step starts
161 mStatusBar.collapsePanel(true /* animate */);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000162 }
Matthew Ng8f25fb962018-01-16 17:17:24 -0800163
164 @Override
165 public void onInteractionFlagsChanged(@InteractionType int flags) {
166 mNavigationBarView.updateStates();
Winson Chungf9e30272018-03-26 17:25:36 -0700167 updateScreenPinningGestures();
Matthew Ng8f25fb962018-01-16 17:17:24 -0800168 }
Matthew Ng96985e72018-05-08 15:46:13 -0700169
170 @Override
171 public void onBackButtonAlphaChanged(float alpha, boolean animate) {
172 final ButtonDispatcher backButton = mNavigationBarView.getBackButton();
Matthew Ngb687c8a2018-10-02 11:31:38 -0700173 if (QuickStepController.shouldhideBackButton(getContext())) {
Matthew Ngc83b9892018-08-21 16:31:13 -0700174 // If property was changed to hide/show back button, going home will trigger
175 // launcher to to change the back button alpha to reflect property change
176 backButton.setVisibility(View.GONE);
177 } else {
178 backButton.setVisibility(alpha > 0 ? View.VISIBLE : View.INVISIBLE);
179 backButton.setAlpha(alpha, animate);
180 }
Matthew Ng96985e72018-05-08 15:46:13 -0700181 }
Matthew Ng9c3bce52018-02-01 22:00:31 +0000182 };
Mike Digman7d092772018-01-11 12:10:32 -0800183
Matthew Ng761562d2018-09-17 11:13:21 -0700184 private final ContextButtonListener mRotationButtonListener = new ContextButtonListener() {
185 @Override
186 public void onVisibilityChanged(ContextualButton button, boolean visible) {
187 if (visible) {
188 // If the button will actually become visible and the navbar is about to hide,
189 // tell the statusbar to keep it around for longer
190 mStatusBar.touchAutoHide();
191 }
192 }
193 };
194
Jason Monk49fa0162017-01-11 09:21:56 -0500195 // ----- Fragment Lifecycle Callbacks -----
196
197 @Override
198 public void onCreate(@Nullable Bundle savedInstanceState) {
199 super.onCreate(savedInstanceState);
Jason Monk9c7844c2017-01-18 15:21:53 -0500200 mCommandQueue = SysUiServiceProvider.getComponent(getContext(), CommandQueue.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500201 mCommandQueue.addCallbacks(this);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500202 mStatusBar = SysUiServiceProvider.getComponent(getContext(), StatusBar.class);
Jason Monk9c7844c2017-01-18 15:21:53 -0500203 mRecents = SysUiServiceProvider.getComponent(getContext(), Recents.class);
204 mDivider = SysUiServiceProvider.getComponent(getContext(), Divider.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500205 mWindowManager = getContext().getSystemService(WindowManager.class);
206 mAccessibilityManager = getContext().getSystemService(AccessibilityManager.class);
Jason Monk91e587e2017-04-13 13:41:23 -0400207 Dependency.get(AccessibilityManagerWrapper.class).addCallback(
208 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700209 mContentResolver = getContext().getContentResolver();
Casey Burkhardt74922c62017-02-13 12:43:16 -0800210 mMagnificationObserver = new MagnificationContentObserver(
211 getContext().getMainThreadHandler());
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700212 mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
Casey Burkhardt74922c62017-02-13 12:43:16 -0800213 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED), false,
Casey Burkhardt5d614402017-04-06 13:46:50 -0700214 mMagnificationObserver, UserHandle.USER_ALL);
Casey Burkhardt74922c62017-02-13 12:43:16 -0800215
Jason Monk49fa0162017-01-11 09:21:56 -0500216 if (savedInstanceState != null) {
217 mDisabledFlags1 = savedInstanceState.getInt(EXTRA_DISABLE_STATE, 0);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700218 mDisabledFlags2 = savedInstanceState.getInt(EXTRA_DISABLE2_STATE, 0);
Jason Monk49fa0162017-01-11 09:21:56 -0500219 }
Jason Monk9c7844c2017-01-18 15:21:53 -0500220 mAssistManager = Dependency.get(AssistManager.class);
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800221 mOverviewProxyService = Dependency.get(OverviewProxyService.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500222 }
223
224 @Override
225 public void onDestroy() {
226 super.onDestroy();
227 mCommandQueue.removeCallbacks(this);
Jason Monk91e587e2017-04-13 13:41:23 -0400228 Dependency.get(AccessibilityManagerWrapper.class).removeCallback(
229 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700230 mContentResolver.unregisterContentObserver(mMagnificationObserver);
Jason Monk49fa0162017-01-11 09:21:56 -0500231 }
232
233 @Override
234 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
235 Bundle savedInstanceState) {
236 return inflater.inflate(R.layout.navigation_bar, container, false);
237 }
238
239 @Override
240 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
241 super.onViewCreated(view, savedInstanceState);
242 mNavigationBarView = (NavigationBarView) view;
243
Winson Chung67f5c8b2018-09-24 12:09:19 -0700244 mNavigationBarView.setComponents(mStatusBar.getPanel());
Matthew Ngf0f84542018-10-15 11:53:22 -0700245 mNavigationBarView.setDisabledFlags(mDisabledFlags1);
Jason Monk49fa0162017-01-11 09:21:56 -0500246 mNavigationBarView.setOnVerticalChangedListener(this::onVerticalChanged);
247 mNavigationBarView.setOnTouchListener(this::onNavigationTouch);
248 if (savedInstanceState != null) {
249 mNavigationBarView.getLightTransitionsController().restoreState(savedInstanceState);
250 }
251
252 prepareNavigationBarView();
253 checkNavBarModes();
254
Mike Digmandd2f49e2018-03-16 10:54:22 -0700255 setDisabled2Flags(mDisabledFlags2);
256
Jason Monk49fa0162017-01-11 09:21:56 -0500257 IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
258 filter.addAction(Intent.ACTION_SCREEN_ON);
Phil Weavera858c5f2018-04-26 13:27:30 -0700259 filter.addAction(Intent.ACTION_USER_SWITCHED);
Jason Monk49fa0162017-01-11 09:21:56 -0500260 getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100261 notifyNavigationBarScreenOn();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000262 mOverviewProxyService.addCallback(mOverviewProxyListener);
Matthew Ng761562d2018-09-17 11:13:21 -0700263
264 RotationContextButton rotationButton = mNavigationBarView.getRotateSuggestionButton();
265 rotationButton.setListener(mRotationButtonListener);
266 rotationButton.addRotationCallback(mRotationWatcher);
267
268 // Reset user rotation pref to match that of the WindowManager if starting in locked mode
269 // This will automatically happen when switching from auto-rotate to locked mode
270 if (rotationButton.isRotationLocked()) {
271 final int winRotation = mWindowManager.getDefaultDisplay().getRotation();
272 rotationButton.setRotationLockedAtAngle(winRotation);
273 }
Jason Monk49fa0162017-01-11 09:21:56 -0500274 }
275
276 @Override
277 public void onDestroyView() {
278 super.onDestroyView();
Winson Chungb03d44d2018-09-18 12:42:45 -0700279 if (mNavigationBarView != null) {
280 mNavigationBarView.getBarTransitions().destroy();
281 mNavigationBarView.getLightTransitionsController().destroy(getContext());
282 }
Matthew Ng9c3bce52018-02-01 22:00:31 +0000283 mOverviewProxyService.removeCallback(mOverviewProxyListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500284 getContext().unregisterReceiver(mBroadcastReceiver);
285 }
286
287 @Override
288 public void onSaveInstanceState(Bundle outState) {
289 super.onSaveInstanceState(outState);
290 outState.putInt(EXTRA_DISABLE_STATE, mDisabledFlags1);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700291 outState.putInt(EXTRA_DISABLE2_STATE, mDisabledFlags2);
Jason Monk49fa0162017-01-11 09:21:56 -0500292 if (mNavigationBarView != null) {
293 mNavigationBarView.getLightTransitionsController().saveState(outState);
294 }
295 }
296
297 @Override
298 public void onConfigurationChanged(Configuration newConfig) {
299 super.onConfigurationChanged(newConfig);
300 final Locale locale = getContext().getResources().getConfiguration().locale;
301 final int ld = TextUtils.getLayoutDirectionFromLocale(locale);
302 if (!locale.equals(mLocale) || ld != mLayoutDirection) {
303 if (DEBUG) {
304 Log.v(TAG, String.format(
305 "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection,
306 locale, ld));
307 }
308 mLocale = locale;
309 mLayoutDirection = ld;
310 refreshLayout(ld);
311 }
312 repositionNavigationBar();
313 }
314
315 @Override
316 public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) {
317 if (mNavigationBarView != null) {
318 pw.print(" mNavigationBarWindowState=");
319 pw.println(windowStateToString(mNavigationBarWindowState));
320 pw.print(" mNavigationBarMode=");
321 pw.println(BarTransitions.modeToString(mNavigationBarMode));
322 dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions());
323 }
324
325 pw.print(" mNavigationBarView=");
326 if (mNavigationBarView == null) {
327 pw.println("null");
328 } else {
329 mNavigationBarView.dump(fd, pw, args);
330 }
331 }
332
333 // ----- CommandQueue Callbacks -----
334
335 @Override
336 public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
337 boolean showImeSwitcher) {
338 boolean imeShown = (vis & InputMethodService.IME_VISIBLE) != 0;
339 int hints = mNavigationIconHints;
Yohei Yukawa386f50e2018-03-14 13:03:42 -0700340 switch (backDisposition) {
341 case InputMethodService.BACK_DISPOSITION_DEFAULT:
342 case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS:
343 case InputMethodService.BACK_DISPOSITION_WILL_DISMISS:
344 if (imeShown) {
345 hints |= NAVIGATION_HINT_BACK_ALT;
346 } else {
347 hints &= ~NAVIGATION_HINT_BACK_ALT;
348 }
349 break;
350 case InputMethodService.BACK_DISPOSITION_ADJUST_NOTHING:
351 hints &= ~NAVIGATION_HINT_BACK_ALT;
352 break;
Jason Monk49fa0162017-01-11 09:21:56 -0500353 }
354 if (showImeSwitcher) {
355 hints |= NAVIGATION_HINT_IME_SHOWN;
356 } else {
357 hints &= ~NAVIGATION_HINT_IME_SHOWN;
358 }
359 if (hints == mNavigationIconHints) return;
360
361 mNavigationIconHints = hints;
362
363 if (mNavigationBarView != null) {
364 mNavigationBarView.setNavigationIconHints(hints);
365 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500366 mStatusBar.checkBarModes();
Jason Monk49fa0162017-01-11 09:21:56 -0500367 }
368
369 @Override
370 public void topAppWindowChanged(boolean showMenu) {
371 if (mNavigationBarView != null) {
372 mNavigationBarView.setMenuVisibility(showMenu);
373 }
374 }
375
376 @Override
377 public void setWindowState(int window, int state) {
378 if (mNavigationBarView != null
379 && window == StatusBarManager.WINDOW_NAVIGATION_BAR
380 && mNavigationBarWindowState != state) {
381 mNavigationBarWindowState = state;
382 if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state));
Mike Digman5aeca792018-03-05 11:14:39 -0800383
Matthew Ng761562d2018-09-17 11:13:21 -0700384 mNavigationBarView.getRotateSuggestionButton()
385 .onNavigationBarWindowVisibilityChange(state == WINDOW_STATE_SHOWING);
Jason Monk49fa0162017-01-11 09:21:56 -0500386 }
387 }
388
Mike Digman7d092772018-01-11 12:10:32 -0800389 @Override
Mike Digmane0777312018-01-19 12:41:51 -0800390 public void onRotationProposal(final int rotation, boolean isValid) {
Mike Digman3e33da62018-03-14 16:25:11 -0700391 final int winRotation = mWindowManager.getDefaultDisplay().getRotation();
Matthew Ng761562d2018-09-17 11:13:21 -0700392 final boolean rotateSuggestionsDisabled = RotationContextButton
393 .hasDisable2RotateSuggestionFlag(mDisabledFlags2);
394 if (RotationContextButton.DEBUG_ROTATION) {
Mike Digman3e33da62018-03-14 16:25:11 -0700395 Log.v(TAG, "onRotationProposal proposedRotation=" + Surface.rotationToString(rotation)
396 + ", winRotation=" + Surface.rotationToString(winRotation)
397 + ", isValid=" + isValid + ", mNavBarWindowState="
398 + StatusBarManager.windowStateToString(mNavigationBarWindowState)
Mike Digmandd2f49e2018-03-16 10:54:22 -0700399 + ", rotateSuggestionsDisabled=" + rotateSuggestionsDisabled
Mike Digman3e33da62018-03-14 16:25:11 -0700400 + ", isRotateButtonVisible=" + (mNavigationBarView == null ? "null" :
Matthew Ng761562d2018-09-17 11:13:21 -0700401 mNavigationBarView.getRotateSuggestionButton().isVisible()));
Mike Digman3e33da62018-03-14 16:25:11 -0700402 }
403
Mike Digmandd2f49e2018-03-16 10:54:22 -0700404 // Respect the disabled flag, no need for action as flag change callback will handle hiding
405 if (rotateSuggestionsDisabled) return;
406
Matthew Ng761562d2018-09-17 11:13:21 -0700407 mNavigationBarView.getRotateSuggestionButton()
408 .onRotationProposal(rotation, winRotation, isValid);
Mike Digman50752642018-02-15 13:36:09 -0800409 }
410
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500411 // Injected from StatusBar at creation.
Jason Monk49fa0162017-01-11 09:21:56 -0500412 public void setCurrentSysuiVisibility(int systemUiVisibility) {
413 mSystemUiVisibility = systemUiVisibility;
Matthew Ng5a250202018-10-09 16:09:27 -0700414 final int barMode = mStatusBar.computeBarMode(0, mSystemUiVisibility,
Jason Monk49fa0162017-01-11 09:21:56 -0500415 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
416 View.NAVIGATION_BAR_TRANSPARENT);
Matthew Ng5a250202018-10-09 16:09:27 -0700417 if (barMode != -1) {
418 mNavigationBarMode = barMode;
419 }
Jason Monk49fa0162017-01-11 09:21:56 -0500420 checkNavBarModes();
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500421 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500422 mLightBarController.onNavigationVisibilityChanged(mSystemUiVisibility, 0 /* mask */,
423 true /* nbModeChanged */, mNavigationBarMode);
424 }
425
426 @Override
427 public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis,
428 int mask, Rect fullscreenStackBounds, Rect dockedStackBounds) {
429 final int oldVal = mSystemUiVisibility;
430 final int newVal = (oldVal & ~mask) | (vis & mask);
431 final int diff = newVal ^ oldVal;
432 boolean nbModeChanged = false;
433 if (diff != 0) {
434 mSystemUiVisibility = newVal;
435
436 // update navigation bar mode
437 final int nbMode = getView() == null
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500438 ? -1 : mStatusBar.computeBarMode(oldVal, newVal,
Jason Monk49fa0162017-01-11 09:21:56 -0500439 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
440 View.NAVIGATION_BAR_TRANSPARENT);
441 nbModeChanged = nbMode != -1;
442 if (nbModeChanged) {
443 if (mNavigationBarMode != nbMode) {
Tracy Zhou1ac592c2018-07-25 13:47:37 -0700444 if (mNavigationBarMode == MODE_TRANSPARENT
445 || mNavigationBarMode == MODE_LIGHTS_OUT_TRANSPARENT) {
446 mNavigationBarView.hideRecentsOnboarding();
447 }
Jason Monk49fa0162017-01-11 09:21:56 -0500448 mNavigationBarMode = nbMode;
449 checkNavBarModes();
450 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500451 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500452 }
453 }
454
455 mLightBarController.onNavigationVisibilityChanged(vis, mask, nbModeChanged,
456 mNavigationBarMode);
457 }
458
459 @Override
460 public void disable(int state1, int state2, boolean animate) {
Mike Digmandd2f49e2018-03-16 10:54:22 -0700461 // Navigation bar flags are in both state1 and state2.
462 final int masked = state1 & (StatusBarManager.DISABLE_HOME
Jason Monk49fa0162017-01-11 09:21:56 -0500463 | StatusBarManager.DISABLE_RECENT
464 | StatusBarManager.DISABLE_BACK
465 | StatusBarManager.DISABLE_SEARCH);
466 if (masked != mDisabledFlags1) {
467 mDisabledFlags1 = masked;
468 if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state1);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000469 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500470 }
Mike Digmandd2f49e2018-03-16 10:54:22 -0700471
472 final int masked2 = state2 & (StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS);
473 if (masked2 != mDisabledFlags2) {
474 mDisabledFlags2 = masked2;
475 setDisabled2Flags(masked2);
476 }
477 }
478
479 private void setDisabled2Flags(int state2) {
480 // Method only called on change of disable2 flags
Evan Lairdb8b717f2018-10-25 14:08:32 -0400481 if (mNavigationBarView != null) {
482 mNavigationBarView.getRotateSuggestionButton().onDisable2FlagChanged(state2);
483 }
Jason Monk49fa0162017-01-11 09:21:56 -0500484 }
485
486 // ----- Internal stuffz -----
487
488 private void refreshLayout(int layoutDirection) {
489 if (mNavigationBarView != null) {
490 mNavigationBarView.setLayoutDirection(layoutDirection);
491 }
492 }
493
494 private boolean shouldDisableNavbarGestures() {
Jason Monk297c04e2018-08-23 17:16:59 -0400495 return !mDeviceProvisionedController.isDeviceProvisioned()
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800496 || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0;
Jason Monk49fa0162017-01-11 09:21:56 -0500497 }
498
499 private void repositionNavigationBar() {
500 if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return;
501
502 prepareNavigationBarView();
503
504 mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(),
505 ((View) mNavigationBarView.getParent()).getLayoutParams());
506 }
507
Matthew Ng9c3bce52018-02-01 22:00:31 +0000508 private void updateScreenPinningGestures() {
509 if (mNavigationBarView == null) {
510 return;
511 }
512
513 // Change the cancel pin gesture to home and back if recents button is invisible
514 boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000515 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
516 if (recentsVisible) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000517 backButton.setOnLongClickListener(this::onLongPressBackRecents);
518 } else {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000519 backButton.setOnLongClickListener(this::onLongPressBackHome);
520 }
521 }
522
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100523 private void notifyNavigationBarScreenOn() {
Matthew Ngd0a73e72018-03-02 15:16:03 -0800524 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500525 }
526
527 private void prepareNavigationBarView() {
528 mNavigationBarView.reorient();
529
530 ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton();
531 recentsButton.setOnClickListener(this::onRecentsClick);
532 recentsButton.setOnTouchListener(this::onRecentsTouch);
533 recentsButton.setLongClickable(true);
534 recentsButton.setOnLongClickListener(this::onLongPressBackRecents);
535
536 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
537 backButton.setLongClickable(true);
Jason Monk49fa0162017-01-11 09:21:56 -0500538
539 ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
540 homeButton.setOnTouchListener(this::onHomeTouch);
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800541 homeButton.setOnLongClickListener(this::onHomeLongClick);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800542
543 ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton();
544 accessibilityButton.setOnClickListener(this::onAccessibilityClick);
545 accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick);
Phil Weaverdb9a7742017-04-18 08:15:06 -0700546 updateAccessibilityServicesState(mAccessibilityManager);
Mike Digman7d092772018-01-11 12:10:32 -0800547
Matthew Ng9c3bce52018-02-01 22:00:31 +0000548 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500549 }
550
551 private boolean onHomeTouch(View v, MotionEvent event) {
552 if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) {
553 return true;
554 }
555 // If an incoming call is ringing, HOME is totally disabled.
556 // (The user is already on the InCallUI at this point,
557 // and his ONLY options are to answer or reject the call.)
558 switch (event.getAction()) {
559 case MotionEvent.ACTION_DOWN:
560 mHomeBlockedThisTouch = false;
561 TelecomManager telecomManager =
562 getContext().getSystemService(TelecomManager.class);
563 if (telecomManager != null && telecomManager.isRinging()) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500564 if (mStatusBar.isKeyguardShowing()) {
Jason Monk49fa0162017-01-11 09:21:56 -0500565 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " +
566 "No heads up");
567 mHomeBlockedThisTouch = true;
568 return true;
569 }
570 }
571 break;
572 case MotionEvent.ACTION_UP:
573 case MotionEvent.ACTION_CANCEL:
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500574 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500575 break;
576 }
577 return false;
578 }
579
580 private void onVerticalChanged(boolean isVertical) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500581 mStatusBar.setQsScrimEnabled(!isVertical);
Jason Monk49fa0162017-01-11 09:21:56 -0500582 }
583
584 private boolean onNavigationTouch(View v, MotionEvent event) {
Eliot Courtneycb5d3162017-08-09 16:53:15 +0900585 mStatusBar.checkUserAutohide(event);
Jason Monk49fa0162017-01-11 09:21:56 -0500586 return false;
587 }
588
Jason Monk865246d2017-01-19 08:27:01 -0500589 @VisibleForTesting
590 boolean onHomeLongClick(View v) {
Matthew Ng6ff33b72018-02-27 13:47:38 -0800591 if (!mNavigationBarView.isRecentsButtonVisible()
592 && ActivityManagerWrapper.getInstance().isScreenPinningActive()) {
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800593 return onLongPressBackHome(v);
594 }
Jason Monk49fa0162017-01-11 09:21:56 -0500595 if (shouldDisableNavbarGestures()) {
596 return false;
597 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000598 mNavigationBarView.onNavigationButtonLongPress(v);
Mike Digmanc94759d2018-01-23 11:01:21 -0800599 mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS);
Jason Monk49fa0162017-01-11 09:21:56 -0500600 mAssistManager.startAssist(new Bundle() /* args */);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500601 mStatusBar.awakenDreams();
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800602
Jason Monk49fa0162017-01-11 09:21:56 -0500603 if (mNavigationBarView != null) {
604 mNavigationBarView.abortCurrentGesture();
605 }
606 return true;
607 }
608
609 // additional optimization when we have software system buttons - start loading the recent
610 // tasks on touch down
611 private boolean onRecentsTouch(View v, MotionEvent event) {
612 int action = event.getAction() & MotionEvent.ACTION_MASK;
613 if (action == MotionEvent.ACTION_DOWN) {
614 mCommandQueue.preloadRecentApps();
615 } else if (action == MotionEvent.ACTION_CANCEL) {
616 mCommandQueue.cancelPreloadRecentApps();
617 } else if (action == MotionEvent.ACTION_UP) {
618 if (!v.isPressed()) {
619 mCommandQueue.cancelPreloadRecentApps();
620 }
621 }
622 return false;
623 }
624
625 private void onRecentsClick(View v) {
626 if (LatencyTracker.isEnabled(getContext())) {
627 LatencyTracker.getInstance(getContext()).onActionStart(
628 LatencyTracker.ACTION_TOGGLE_RECENTS);
629 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500630 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500631 mCommandQueue.toggleRecentApps();
632 }
633
Matthew Ng9c3bce52018-02-01 22:00:31 +0000634 private boolean onLongPressBackHome(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000635 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000636 return onLongPressNavigationButtons(v, R.id.back, R.id.home);
637 }
638
639 private boolean onLongPressBackRecents(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000640 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000641 return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps);
642 }
643
Jason Monk49fa0162017-01-11 09:21:56 -0500644 /**
Matthew Ng9c3bce52018-02-01 22:00:31 +0000645 * This handles long-press of both back and recents/home. Back is the common button with
646 * combination of recents if it is visible or home if recents is invisible.
647 * They are handled together to capture them both being long-pressed
Jason Monk49fa0162017-01-11 09:21:56 -0500648 * at the same time to exit screen pinning (lock task).
649 *
Matthew Ng9c3bce52018-02-01 22:00:31 +0000650 * When accessibility mode is on, only a long-press from recents/home
Jason Monk49fa0162017-01-11 09:21:56 -0500651 * is required to exit.
652 *
653 * In all other circumstances we try to pass through long-press events
654 * for Back, so that apps can still use it. Which can be from two things.
655 * 1) Not currently in screen pinning (lock task).
Matthew Ng9c3bce52018-02-01 22:00:31 +0000656 * 2) Back is long-pressed without recents/home.
Jason Monk49fa0162017-01-11 09:21:56 -0500657 */
Matthew Ng9c3bce52018-02-01 22:00:31 +0000658 private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) {
Jason Monk49fa0162017-01-11 09:21:56 -0500659 try {
660 boolean sendBackLongPress = false;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700661 IActivityTaskManager activityManager = ActivityTaskManager.getService();
Jason Monk49fa0162017-01-11 09:21:56 -0500662 boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled();
663 boolean inLockTaskMode = activityManager.isInLockTaskMode();
664 if (inLockTaskMode && !touchExplorationEnabled) {
665 long time = System.currentTimeMillis();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000666
Jason Monk49fa0162017-01-11 09:21:56 -0500667 // If we recently long-pressed the other button then they were
668 // long-pressed 'together'
669 if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) {
Benjamin Franza83859f2017-07-03 16:34:14 +0100670 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500671 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800672 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500673 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000674 } else if (v.getId() == btnId1) {
675 ButtonDispatcher button = btnId2 == R.id.recent_apps
676 ? mNavigationBarView.getRecentsButton()
677 : mNavigationBarView.getHomeButton();
678 if (!button.getCurrentView().isPressed()) {
679 // If we aren't pressing recents/home right now then they presses
680 // won't be together, so send the standard long-press action.
681 sendBackLongPress = true;
682 }
Jason Monk49fa0162017-01-11 09:21:56 -0500683 }
684 mLastLockToAppLongPress = time;
685 } else {
686 // If this is back still need to handle sending the long-press event.
Matthew Ng9c3bce52018-02-01 22:00:31 +0000687 if (v.getId() == btnId1) {
Jason Monk49fa0162017-01-11 09:21:56 -0500688 sendBackLongPress = true;
689 } else if (touchExplorationEnabled && inLockTaskMode) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000690 // When in accessibility mode a long press that is recents/home (not back)
Jason Monk49fa0162017-01-11 09:21:56 -0500691 // should stop lock task.
Benjamin Franza83859f2017-07-03 16:34:14 +0100692 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500693 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800694 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500695 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000696 } else if (v.getId() == btnId2) {
697 return btnId2 == R.id.recent_apps
698 ? onLongPressRecents()
699 : onHomeLongClick(mNavigationBarView.getHomeButton().getCurrentView());
Jason Monk49fa0162017-01-11 09:21:56 -0500700 }
701 }
702 if (sendBackLongPress) {
703 KeyButtonView keyButtonView = (KeyButtonView) v;
704 keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
705 keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
706 return true;
707 }
708 } catch (RemoteException e) {
709 Log.d(TAG, "Unable to reach activity manager", e);
710 }
711 return false;
712 }
713
714 private boolean onLongPressRecents() {
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700715 if (mRecents == null || !ActivityTaskManager.supportsMultiWindow(getContext())
Matthew Ng43db6d22017-06-27 15:29:39 -0700716 || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible()
Winson Chung67f5c8b2018-09-24 12:09:19 -0700717 || ActivityManager.isLowRamDeviceStatic()
Winson Chung074c4342018-03-26 17:27:19 -0700718 // If we are connected to the overview service, then disable the recents button
719 || mOverviewProxyService.getProxy() != null) {
Jason Monk49fa0162017-01-11 09:21:56 -0500720 return false;
721 }
722
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500723 return mStatusBar.toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS,
Jason Monk49fa0162017-01-11 09:21:56 -0500724 MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS);
725 }
726
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800727 private void onAccessibilityClick(View v) {
728 mAccessibilityManager.notifyAccessibilityButtonClicked();
729 }
730
731 private boolean onAccessibilityLongClick(View v) {
Casey Burkhardt5e8b9802017-03-24 10:07:20 -0700732 Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON);
733 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Casey Burkhardt5d614402017-04-06 13:46:50 -0700734 v.getContext().startActivityAsUser(intent, UserHandle.CURRENT);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800735 return true;
736 }
737
Phil Weaverdb9a7742017-04-18 08:15:06 -0700738 private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800739 int requestingServices = 0;
740 try {
Casey Burkhardt5d614402017-04-06 13:46:50 -0700741 if (Settings.Secure.getIntForUser(mContentResolver,
742 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
743 UserHandle.USER_CURRENT) == 1) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800744 requestingServices++;
745 }
746 } catch (Settings.SettingNotFoundException e) {
747 }
748
Mike Digman90402952018-01-22 16:05:51 -0800749 boolean feedbackEnabled = false;
Casey Burkhardt5d614402017-04-06 13:46:50 -0700750 // AccessibilityManagerService resolves services for the current user since the local
751 // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800752 final List<AccessibilityServiceInfo> services =
Phil Weaverdb9a7742017-04-18 08:15:06 -0700753 accessibilityManager.getEnabledAccessibilityServiceList(
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800754 AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800755 for (int i = services.size() - 1; i >= 0; --i) {
756 AccessibilityServiceInfo info = services.get(i);
757 if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) {
758 requestingServices++;
759 }
Mike Digman90402952018-01-22 16:05:51 -0800760
761 if (info.feedbackType != 0 && info.feedbackType !=
762 AccessibilityServiceInfo.FEEDBACK_GENERIC) {
763 feedbackEnabled = true;
764 }
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800765 }
766
Matthew Ng761562d2018-09-17 11:13:21 -0700767 mNavigationBarView.getRotateSuggestionButton()
768 .setAccessibilityFeedbackEnabled(feedbackEnabled);
Mike Digman90402952018-01-22 16:05:51 -0800769
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800770 final boolean showAccessibilityButton = requestingServices >= 1;
771 final boolean targetSelection = requestingServices >= 2;
772 mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection);
773 }
774
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500775 // ----- Methods that StatusBar talks to (should be minimized) -----
Jason Monk49fa0162017-01-11 09:21:56 -0500776
Jason Monk49fa0162017-01-11 09:21:56 -0500777 public void setLightBarController(LightBarController lightBarController) {
778 mLightBarController = lightBarController;
779 mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController());
780 }
781
782 public boolean isSemiTransparent() {
783 return mNavigationBarMode == MODE_SEMI_TRANSPARENT;
784 }
785
Jason Monk49fa0162017-01-11 09:21:56 -0500786 public void disableAnimationsDuringHide(long delay) {
787 mNavigationBarView.setLayoutTransitionsEnabled(false);
788 mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true),
789 delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE);
790 }
791
Jason Monk49fa0162017-01-11 09:21:56 -0500792 public BarTransitions getBarTransitions() {
793 return mNavigationBarView.getBarTransitions();
794 }
795
796 public void checkNavBarModes() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500797 mStatusBar.checkBarMode(mNavigationBarMode,
Jason Monk49fa0162017-01-11 09:21:56 -0500798 mNavigationBarWindowState, mNavigationBarView.getBarTransitions());
799 }
800
801 public void finishBarAnimations() {
802 mNavigationBarView.getBarTransitions().finishAnimations();
803 }
804
Jason Monk91e587e2017-04-13 13:41:23 -0400805 private final AccessibilityServicesStateChangeListener mAccessibilityListener =
806 this::updateAccessibilityServicesState;
807
Casey Burkhardt74922c62017-02-13 12:43:16 -0800808 private class MagnificationContentObserver extends ContentObserver {
809
810 public MagnificationContentObserver(Handler handler) {
811 super(handler);
812 }
813
814 @Override
815 public void onChange(boolean selfChange) {
Phil Weaverdb9a7742017-04-18 08:15:06 -0700816 NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager);
Casey Burkhardt74922c62017-02-13 12:43:16 -0800817 }
818 }
819
Matthew Ng761562d2018-09-17 11:13:21 -0700820 private final Consumer<Integer> mRotationWatcher = rotation -> {
821 if (mNavigationBarView != null
822 && mNavigationBarView.needsReorient(rotation)) {
823 repositionNavigationBar();
Mike Digman85ff7fa2018-01-23 14:59:52 -0800824 }
Jason Monk49fa0162017-01-11 09:21:56 -0500825 };
826
827 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
828 @Override
829 public void onReceive(Context context, Intent intent) {
830 String action = intent.getAction();
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100831 if (Intent.ACTION_SCREEN_OFF.equals(action)
832 || Intent.ACTION_SCREEN_ON.equals(action)) {
833 notifyNavigationBarScreenOn();
Jason Monk49fa0162017-01-11 09:21:56 -0500834 }
Phil Weavera858c5f2018-04-26 13:27:30 -0700835 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
836 // The accessibility settings may be different for the new user
837 updateAccessibilityServicesState(mAccessibilityManager);
838 };
Jason Monk49fa0162017-01-11 09:21:56 -0500839 }
840 };
841
842 public static View create(Context context, FragmentListener listener) {
843 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
844 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
845 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
846 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
847 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
848 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
849 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
850 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
851 | WindowManager.LayoutParams.FLAG_SLIPPERY,
852 PixelFormat.TRANSLUCENT);
853 lp.token = new Binder();
Jason Monk49fa0162017-01-11 09:21:56 -0500854 lp.setTitle("NavigationBar");
Phil Weaver8583ae82018-02-13 11:01:24 -0800855 lp.accessibilityTitle = context.getString(R.string.nav_bar);
Jason Monk49fa0162017-01-11 09:21:56 -0500856 lp.windowAnimations = 0;
857
858 View navigationBarView = LayoutInflater.from(context).inflate(
859 R.layout.navigation_bar_window, null);
860
861 if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView);
862 if (navigationBarView == null) return null;
863
864 context.getSystemService(WindowManager.class).addView(navigationBarView, lp);
865 FragmentHostManager fragmentHost = FragmentHostManager.get(navigationBarView);
866 NavigationBarFragment fragment = new NavigationBarFragment();
867 fragmentHost.getFragmentManager().beginTransaction()
868 .replace(R.id.navigation_bar_frame, fragment, TAG)
869 .commit();
870 fragmentHost.addTagListener(TAG, listener);
871 return navigationBarView;
872 }
873}