Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.statusbar.phone; |
| 16 | |
| 17 | import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_ALT; |
| 18 | import static android.app.StatusBarManager.NAVIGATION_HINT_IME_SHOWN; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 19 | import static android.app.StatusBarManager.WINDOW_STATE_HIDDEN; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 20 | import static android.app.StatusBarManager.WINDOW_STATE_SHOWING; |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 21 | import static android.app.StatusBarManager.WindowType; |
| 22 | import static android.app.StatusBarManager.WindowVisibleState; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 23 | import static android.app.StatusBarManager.windowStateToString; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 24 | import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 25 | import static android.view.InsetsState.containsType; |
| 26 | import static android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 27 | import static android.view.WindowInsetsController.APPEARANCE_OPAQUE_NAVIGATION_BARS; |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 28 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON; |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 29 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 30 | |
Peter_Liang | 0589ab0 | 2020-04-08 22:18:43 +0800 | [diff] [blame] | 31 | import static com.android.internal.accessibility.common.ShortcutConstants.CHOOSER_PACKAGE_NAME; |
Govinda Wasserman | 8b04546 | 2020-01-15 16:46:17 -0500 | [diff] [blame] | 32 | import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.NAV_BAR_HANDLE_FORCE_OPAQUE; |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 33 | import static com.android.systemui.recents.OverviewProxyService.OverviewProxyListener; |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 34 | import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_A11Y_BUTTON_CLICKABLE; |
| 35 | import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE; |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 36 | import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NAV_BAR_HIDDEN; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 37 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT; |
Tracy Zhou | 1ac592c | 2018-07-25 13:47:37 -0700 | [diff] [blame] | 38 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT_TRANSPARENT; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 39 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_OPAQUE; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 40 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT; |
Tracy Zhou | 1ac592c | 2018-07-25 13:47:37 -0700 | [diff] [blame] | 41 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_TRANSPARENT; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 42 | import static com.android.systemui.statusbar.phone.BarTransitions.TransitionMode; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 43 | import static com.android.systemui.statusbar.phone.StatusBar.DEBUG_WINDOW_STATE; |
| 44 | import static com.android.systemui.statusbar.phone.StatusBar.dumpBarTransitions; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 45 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 46 | import android.accessibilityservice.AccessibilityServiceInfo; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 47 | import android.annotation.IdRes; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 48 | import android.annotation.Nullable; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 49 | import android.app.ActivityManager; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 50 | import android.app.ActivityTaskManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 51 | import android.app.IActivityTaskManager; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 52 | import android.app.StatusBarManager; |
| 53 | import android.content.BroadcastReceiver; |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 54 | import android.content.ContentResolver; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 55 | import android.content.Context; |
| 56 | import android.content.Intent; |
| 57 | import android.content.IntentFilter; |
| 58 | import android.content.res.Configuration; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 59 | import android.database.ContentObserver; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 60 | import android.graphics.PixelFormat; |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 61 | import android.graphics.Rect; |
Vinit Nayak | d2fe92f | 2020-06-04 13:12:02 -0700 | [diff] [blame] | 62 | import android.graphics.RectF; |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 63 | import android.hardware.display.DisplayManager; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 64 | import android.inputmethodservice.InputMethodService; |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 65 | import android.net.Uri; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 66 | import android.os.Binder; |
| 67 | import android.os.Bundle; |
| 68 | import android.os.Handler; |
| 69 | import android.os.IBinder; |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 70 | import android.os.Looper; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 71 | import android.os.RemoteException; |
| 72 | import android.os.UserHandle; |
Govinda Wasserman | 8b04546 | 2020-01-15 16:46:17 -0500 | [diff] [blame] | 73 | import android.provider.DeviceConfig; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 74 | import android.provider.Settings; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 75 | import android.telecom.TelecomManager; |
| 76 | import android.text.TextUtils; |
| 77 | import android.util.Log; |
Andrii Kulian | 3ddd7de | 2018-10-10 00:33:19 -0700 | [diff] [blame] | 78 | import android.view.Display; |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 79 | import android.view.Gravity; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 80 | import android.view.InsetsState.InternalInsetsType; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 81 | import android.view.KeyEvent; |
| 82 | import android.view.LayoutInflater; |
| 83 | import android.view.MotionEvent; |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 84 | import android.view.Surface; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 85 | import android.view.View; |
| 86 | import android.view.ViewGroup; |
Vinit Nayak | d2fe92f | 2020-06-04 13:12:02 -0700 | [diff] [blame] | 87 | import android.view.ViewTreeObserver; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 88 | import android.view.WindowInsetsController.Appearance; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 89 | import android.view.WindowManager; |
| 90 | import android.view.WindowManager.LayoutParams; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 91 | import android.view.accessibility.AccessibilityEvent; |
| 92 | import android.view.accessibility.AccessibilityManager; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 93 | import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 94 | |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 95 | import androidx.annotation.VisibleForTesting; |
| 96 | |
Peter_Liang | 0589ab0 | 2020-04-08 22:18:43 +0800 | [diff] [blame] | 97 | import com.android.internal.accessibility.dialog.AccessibilityButtonChooserActivity; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 98 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | 119913a | 2020-06-08 14:27:37 -0400 | [diff] [blame] | 99 | import com.android.internal.logging.UiEvent; |
| 100 | import com.android.internal.logging.UiEventLogger; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 101 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | ea03be1 | 2017-12-04 11:08:41 -0500 | [diff] [blame] | 102 | import com.android.internal.util.LatencyTracker; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 103 | import com.android.internal.view.AppearanceRegion; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 104 | import com.android.systemui.R; |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 105 | import com.android.systemui.accessibility.SystemActions; |
shawnlin | 87af538 | 2019-09-13 14:13:13 +0800 | [diff] [blame] | 106 | import com.android.systemui.assist.AssistHandleViewController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 107 | import com.android.systemui.assist.AssistManager; |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 108 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Dave Mankoff | 00e8a2f | 2019-12-18 16:59:49 -0500 | [diff] [blame] | 109 | import com.android.systemui.dagger.qualifiers.Main; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 110 | import com.android.systemui.fragments.FragmentHostManager; |
| 111 | import com.android.systemui.fragments.FragmentHostManager.FragmentListener; |
Vinit Nayak | 59b114e6 | 2019-08-12 11:50:00 -0700 | [diff] [blame] | 112 | import com.android.systemui.model.SysUiState; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 113 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Andrii Kulian | 3ddd7de | 2018-10-10 00:33:19 -0700 | [diff] [blame] | 114 | import com.android.systemui.recents.OverviewProxyService; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 115 | import com.android.systemui.recents.Recents; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 116 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Sunny Goyal | a6a5812 | 2019-04-02 10:20:29 -0700 | [diff] [blame] | 117 | import com.android.systemui.shared.system.QuickStepContract; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 118 | import com.android.systemui.stackdivider.Divider; |
Heemin Seog | e67cefea | 2020-01-28 12:02:50 -0800 | [diff] [blame] | 119 | import com.android.systemui.statusbar.AutoHideUiElement; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 120 | import com.android.systemui.statusbar.CommandQueue; |
| 121 | import com.android.systemui.statusbar.CommandQueue.Callbacks; |
Heemin Seog | e67cefea | 2020-01-28 12:02:50 -0800 | [diff] [blame] | 122 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 123 | import com.android.systemui.statusbar.StatusBarState; |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 124 | import com.android.systemui.statusbar.notification.stack.StackStateAnimator; |
| 125 | import com.android.systemui.statusbar.phone.ContextualButton.ContextButtonListener; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 126 | import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 127 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 128 | import com.android.systemui.statusbar.policy.KeyButtonView; |
Jason Monk | 8e4e4cb | 2018-12-04 11:10:24 -0500 | [diff] [blame] | 129 | import com.android.systemui.util.LifecycleFragment; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 130 | |
| 131 | import java.io.FileDescriptor; |
| 132 | import java.io.PrintWriter; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 133 | import java.util.List; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 134 | import java.util.Locale; |
Dave Mankoff | ae3b432 | 2019-11-05 19:48:24 -0500 | [diff] [blame] | 135 | import java.util.Optional; |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 136 | import java.util.function.Consumer; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 137 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 138 | import javax.inject.Inject; |
| 139 | |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 140 | import dagger.Lazy; |
| 141 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 142 | /** |
| 143 | * Fragment containing the NavigationBarFragment. Contains logic for what happens |
| 144 | * on clicks and view states of the nav bar. |
| 145 | */ |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 146 | public class NavigationBarFragment extends LifecycleFragment implements Callbacks, |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 147 | NavigationModeController.ModeChangedListener, DisplayManager.DisplayListener { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 148 | |
Jason Monk | d4afe15 | 2017-05-01 15:37:43 -0400 | [diff] [blame] | 149 | public static final String TAG = "NavigationBar"; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 150 | private static final boolean DEBUG = false; |
| 151 | private static final String EXTRA_DISABLE_STATE = "disabled_state"; |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 152 | private static final String EXTRA_DISABLE2_STATE = "disabled2_state"; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 153 | private static final String EXTRA_APPEARANCE = "appearance"; |
| 154 | private static final String EXTRA_TRANSIENT_STATE = "transient_state"; |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 155 | private static final String FIXED_ROTATION_TRANSFORM_SETTING_NAME = "fixed_rotation_transform"; |
| 156 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 157 | |
| 158 | /** Allow some time inbetween the long press for back and recents. */ |
| 159 | private static final int LOCK_TO_APP_GESTURE_TOLERENCE = 200; |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 160 | private static final long AUTODIM_TIMEOUT_MS = 2250; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 161 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 162 | private final AccessibilityManagerWrapper mAccessibilityManagerWrapper; |
| 163 | protected final AssistManager mAssistManager; |
Vinit Nayak | 59b114e6 | 2019-08-12 11:50:00 -0700 | [diff] [blame] | 164 | private SysUiState mSysUiFlagsContainer; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 165 | private final MetricsLogger mMetricsLogger; |
| 166 | private final DeviceProvisionedController mDeviceProvisionedController; |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 167 | private final StatusBarStateController mStatusBarStateController; |
Winson Chung | 52d938d | 2019-09-25 16:50:05 -0700 | [diff] [blame] | 168 | private final NavigationModeController mNavigationModeController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 169 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 170 | protected NavigationBarView mNavigationBarView = null; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 171 | |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 172 | private @WindowVisibleState int mNavigationBarWindowState = WINDOW_STATE_SHOWING; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 173 | |
| 174 | private int mNavigationIconHints = 0; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 175 | private @TransitionMode int mNavigationBarMode; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 176 | private AccessibilityManager mAccessibilityManager; |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 177 | private ContentResolver mContentResolver; |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 178 | private boolean mAssistantAvailable; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 179 | |
| 180 | private int mDisabledFlags1; |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 181 | private int mDisabledFlags2; |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 182 | private final Lazy<StatusBar> mStatusBarLazy; |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 183 | private final ShadeController mShadeController; |
Heemin Seog | e67cefea | 2020-01-28 12:02:50 -0800 | [diff] [blame] | 184 | private final NotificationRemoteInputManager mNotificationRemoteInputManager; |
Dave Mankoff | 613c7c6 | 2019-11-04 11:46:36 -0500 | [diff] [blame] | 185 | private final Divider mDivider; |
Dave Mankoff | ae3b432 | 2019-11-05 19:48:24 -0500 | [diff] [blame] | 186 | private final Optional<Recents> mRecentsOptional; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 187 | private WindowManager mWindowManager; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 188 | private final CommandQueue mCommandQueue; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 189 | private long mLastLockToAppLongPress; |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 190 | private final SystemActions mSystemActions; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 191 | |
| 192 | private Locale mLocale; |
| 193 | private int mLayoutDirection; |
| 194 | |
Govinda Wasserman | 8b04546 | 2020-01-15 16:46:17 -0500 | [diff] [blame] | 195 | private boolean mForceNavBarHandleOpaque; |
| 196 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 197 | /** @see android.view.WindowInsetsController#setSystemBarsAppearance(int) */ |
| 198 | private @Appearance int mAppearance; |
| 199 | |
| 200 | private boolean mTransientShown; |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 201 | private int mNavBarMode = NAV_BAR_MODE_3BUTTON; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 202 | private LightBarController mLightBarController; |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 203 | private AutoHideController mAutoHideController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 204 | |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 205 | private OverviewProxyService mOverviewProxyService; |
| 206 | |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 207 | private final BroadcastDispatcher mBroadcastDispatcher; |
| 208 | |
Charles Chen | 54fce2c | 2019-03-13 18:17:29 +0800 | [diff] [blame] | 209 | @VisibleForTesting |
| 210 | public int mDisplayId; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 211 | private boolean mIsOnDefaultDisplay; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 212 | public boolean mHomeBlockedThisTouch; |
shawnlin | 87af538 | 2019-09-13 14:13:13 +0800 | [diff] [blame] | 213 | |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 214 | /** |
| 215 | * When user is QuickSwitching between apps of different orientations, we'll draw a fake |
| 216 | * home handle on the orientation they originally touched down to start their swipe |
| 217 | * gesture to indicate to them that they can continue in that orientation without having to |
| 218 | * rotate the phone |
| 219 | * The secondary handle will show when we get |
| 220 | * {@link OverviewProxyListener#onQuickSwitchToNewTask(int)} callback with the |
| 221 | * original handle hidden and we'll flip the visibilities once the |
| 222 | * {@link #mTasksFrozenListener} fires |
| 223 | */ |
Vinit Nayak | d2fe92f | 2020-06-04 13:12:02 -0700 | [diff] [blame] | 224 | private VerticalNavigationHandle mOrientationHandle; |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 225 | private WindowManager.LayoutParams mOrientationParams; |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 226 | private int mStartingQuickSwitchRotation; |
| 227 | private int mCurrentRotation; |
| 228 | private boolean mFixedRotationEnabled; |
Vinit Nayak | d2fe92f | 2020-06-04 13:12:02 -0700 | [diff] [blame] | 229 | private ViewTreeObserver.OnGlobalLayoutListener mOrientationHandleGlobalLayoutListener; |
Chris Wren | 119913a | 2020-06-08 14:27:37 -0400 | [diff] [blame] | 230 | private UiEventLogger mUiEventLogger; |
| 231 | |
| 232 | @com.android.internal.annotations.VisibleForTesting |
| 233 | public enum NavBarActionEvent implements UiEventLogger.UiEventEnum { |
| 234 | |
| 235 | @UiEvent(doc = "Assistant invoked via home button long press.") |
| 236 | NAVBAR_ASSIST_LONGPRESS(550); |
| 237 | |
| 238 | private final int mId; |
| 239 | |
| 240 | NavBarActionEvent(int id) { |
| 241 | mId = id; |
| 242 | } |
| 243 | |
| 244 | @Override |
| 245 | public int getId() { |
| 246 | return mId; |
| 247 | } |
| 248 | } |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 249 | |
shawnlin | 87af538 | 2019-09-13 14:13:13 +0800 | [diff] [blame] | 250 | /** Only for default display */ |
| 251 | @Nullable |
| 252 | private AssistHandleViewController mAssistHandlerViewController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 253 | |
Dave Mankoff | ea1953c | 2019-11-19 20:23:31 -0500 | [diff] [blame] | 254 | private final Handler mHandler; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 255 | |
Heemin Seog | 8cfe6c5 | 2020-03-06 15:01:08 -0800 | [diff] [blame] | 256 | private final AutoHideUiElement mAutoHideUiElement = new AutoHideUiElement() { |
| 257 | @Override |
| 258 | public void synchronizeState() { |
| 259 | checkNavBarModes(); |
| 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public boolean shouldHideOnTouch() { |
| 264 | return !mNotificationRemoteInputManager.getController().isRemoteInputActive(); |
| 265 | } |
| 266 | |
| 267 | @Override |
| 268 | public boolean isVisible() { |
| 269 | return isTransientShown(); |
| 270 | } |
| 271 | |
| 272 | @Override |
| 273 | public void hide() { |
| 274 | clearTransient(); |
| 275 | } |
| 276 | }; |
| 277 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 278 | private final OverviewProxyListener mOverviewProxyListener = new OverviewProxyListener() { |
| 279 | @Override |
| 280 | public void onConnectionChanged(boolean isConnected) { |
Winson Chung | f9e3027 | 2018-03-26 17:25:36 -0700 | [diff] [blame] | 281 | mNavigationBarView.updateStates(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 282 | updateScreenPinningGestures(); |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 283 | |
| 284 | // Send the assistant availability upon connection |
| 285 | if (isConnected) { |
Matthew Ng | cf71ead | 2019-04-19 14:24:59 -0700 | [diff] [blame] | 286 | sendAssistantAvailability(mAssistantAvailable); |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 287 | } |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | @Override |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 291 | public void onQuickStepStarted() { |
Mike Digman | 85a9bea | 2018-02-23 15:08:53 -0800 | [diff] [blame] | 292 | // Use navbar dragging as a signal to hide the rotate button |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 293 | mNavigationBarView.getRotationButtonController().setRotateSuggestionButtonState(false); |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 294 | |
| 295 | // Hide the notifications panel when quick step starts |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 296 | mShadeController.collapsePanel(true /* animate */); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 297 | } |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 298 | |
| 299 | @Override |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 300 | public void onQuickSwitchToNewTask(@Surface.Rotation int rotation) { |
| 301 | mStartingQuickSwitchRotation = rotation; |
| 302 | orientSecondaryHomeHandle(); |
| 303 | } |
| 304 | |
| 305 | @Override |
Matthew Ng | 42025e3 | 2019-02-20 15:02:58 -0800 | [diff] [blame] | 306 | public void startAssistant(Bundle bundle) { |
| 307 | mAssistManager.startAssist(bundle); |
| 308 | } |
| 309 | |
| 310 | @Override |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 311 | public void onNavBarButtonAlphaChanged(float alpha, boolean animate) { |
| 312 | ButtonDispatcher buttonDispatcher = null; |
Govinda Wasserman | 8b04546 | 2020-01-15 16:46:17 -0500 | [diff] [blame] | 313 | boolean forceVisible = false; |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 314 | if (QuickStepContract.isSwipeUpMode(mNavBarMode)) { |
| 315 | buttonDispatcher = mNavigationBarView.getBackButton(); |
| 316 | } else if (QuickStepContract.isGesturalMode(mNavBarMode)) { |
Govinda Wasserman | 8b04546 | 2020-01-15 16:46:17 -0500 | [diff] [blame] | 317 | forceVisible = mForceNavBarHandleOpaque; |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 318 | buttonDispatcher = mNavigationBarView.getHomeHandle(); |
| 319 | } |
| 320 | if (buttonDispatcher != null) { |
Govinda Wasserman | 8b04546 | 2020-01-15 16:46:17 -0500 | [diff] [blame] | 321 | buttonDispatcher.setVisibility( |
| 322 | (forceVisible || alpha > 0) ? View.VISIBLE : View.INVISIBLE); |
| 323 | buttonDispatcher.setAlpha(forceVisible ? 1f : alpha, animate); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 324 | } |
Matthew Ng | 96985e7 | 2018-05-08 15:46:13 -0700 | [diff] [blame] | 325 | } |
Riddle Hsu | 95cb52a | 2020-06-12 00:44:02 +0800 | [diff] [blame] | 326 | |
| 327 | @Override |
| 328 | public void onOverviewShown(boolean fromHome) { |
| 329 | // If the overview has fixed orientation that may change display to natural rotation, |
| 330 | // we don't want the user rotation to be reset. So after user returns to application, |
| 331 | // it can keep in the original rotation. |
| 332 | mNavigationBarView.getRotationButtonController().setSkipOverrideUserLockPrefsOnce(); |
| 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public void onToggleRecentApps() { |
| 337 | // The same case as onOverviewShown but only for 3-button navigation. |
| 338 | mNavigationBarView.getRotationButtonController().setSkipOverrideUserLockPrefsOnce(); |
| 339 | } |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 340 | }; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 341 | |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 342 | private NavigationBarTransitions.DarkIntensityListener mOrientationHandleIntensityListener = |
| 343 | new NavigationBarTransitions.DarkIntensityListener() { |
| 344 | @Override |
| 345 | public void onDarkIntensity(float darkIntensity) { |
| 346 | mOrientationHandle.setDarkIntensity(darkIntensity); |
| 347 | } |
| 348 | }; |
| 349 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 350 | private final ContextButtonListener mRotationButtonListener = (button, visible) -> { |
| 351 | if (visible) { |
| 352 | // If the button will actually become visible and the navbar is about to hide, |
| 353 | // tell the statusbar to keep it around for longer |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 354 | mAutoHideController.touchAutoHide(); |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 355 | } |
| 356 | }; |
| 357 | |
| 358 | private final Runnable mAutoDim = () -> getBarTransitions().setAutoDim(true); |
| 359 | |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 360 | private final ContentObserver mAssistContentObserver = new ContentObserver( |
| 361 | new Handler(Looper.getMainLooper())) { |
| 362 | @Override |
| 363 | public void onChange(boolean selfChange, Uri uri) { |
| 364 | boolean available = mAssistManager |
| 365 | .getAssistInfoForUser(UserHandle.USER_CURRENT) != null; |
| 366 | if (mAssistantAvailable != available) { |
Matthew Ng | cf71ead | 2019-04-19 14:24:59 -0700 | [diff] [blame] | 367 | sendAssistantAvailability(available); |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 368 | mAssistantAvailable = available; |
| 369 | } |
| 370 | } |
| 371 | }; |
| 372 | |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 373 | private final ContentObserver mFixedRotationObserver = new ContentObserver( |
| 374 | new Handler(Looper.getMainLooper())) { |
| 375 | @Override |
| 376 | public void onChange(boolean selfChange, Uri uri) { |
| 377 | updatedFixedRotation(); |
| 378 | } |
| 379 | }; |
| 380 | |
Govinda Wasserman | 1b7d610 | 2020-02-10 16:52:59 -0500 | [diff] [blame] | 381 | private final DeviceConfig.OnPropertiesChangedListener mOnPropertiesChangedListener = |
| 382 | new DeviceConfig.OnPropertiesChangedListener() { |
| 383 | @Override |
| 384 | public void onPropertiesChanged(DeviceConfig.Properties properties) { |
| 385 | if (properties.getKeyset().contains(NAV_BAR_HANDLE_FORCE_OPAQUE)) { |
| 386 | mForceNavBarHandleOpaque = properties.getBoolean( |
| 387 | NAV_BAR_HANDLE_FORCE_OPAQUE, /* defaultValue = */ true); |
| 388 | } |
| 389 | } |
| 390 | }; |
| 391 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 392 | @Inject |
| 393 | public NavigationBarFragment(AccessibilityManagerWrapper accessibilityManagerWrapper, |
| 394 | DeviceProvisionedController deviceProvisionedController, MetricsLogger metricsLogger, |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 395 | AssistManager assistManager, OverviewProxyService overviewProxyService, |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 396 | NavigationModeController navigationModeController, |
Vinit Nayak | 59b114e6 | 2019-08-12 11:50:00 -0700 | [diff] [blame] | 397 | StatusBarStateController statusBarStateController, |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 398 | SysUiState sysUiFlagsContainer, |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 399 | BroadcastDispatcher broadcastDispatcher, |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 400 | CommandQueue commandQueue, Divider divider, |
Dave Mankoff | ea1953c | 2019-11-19 20:23:31 -0500 | [diff] [blame] | 401 | Optional<Recents> recentsOptional, Lazy<StatusBar> statusBarLazy, |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 402 | ShadeController shadeController, |
Heemin Seog | e67cefea | 2020-01-28 12:02:50 -0800 | [diff] [blame] | 403 | NotificationRemoteInputManager notificationRemoteInputManager, |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 404 | SystemActions systemActions, |
Chris Wren | 119913a | 2020-06-08 14:27:37 -0400 | [diff] [blame] | 405 | @Main Handler mainHandler, |
| 406 | UiEventLogger uiEventLogger) { |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 407 | mAccessibilityManagerWrapper = accessibilityManagerWrapper; |
| 408 | mDeviceProvisionedController = deviceProvisionedController; |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 409 | mStatusBarStateController = statusBarStateController; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 410 | mMetricsLogger = metricsLogger; |
| 411 | mAssistManager = assistManager; |
Vinit Nayak | 59b114e6 | 2019-08-12 11:50:00 -0700 | [diff] [blame] | 412 | mSysUiFlagsContainer = sysUiFlagsContainer; |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 413 | mStatusBarLazy = statusBarLazy; |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 414 | mShadeController = shadeController; |
Heemin Seog | e67cefea | 2020-01-28 12:02:50 -0800 | [diff] [blame] | 415 | mNotificationRemoteInputManager = notificationRemoteInputManager; |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 416 | mAssistantAvailable = mAssistManager.getAssistInfoForUser(UserHandle.USER_CURRENT) != null; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 417 | mOverviewProxyService = overviewProxyService; |
Winson Chung | 52d938d | 2019-09-25 16:50:05 -0700 | [diff] [blame] | 418 | mNavigationModeController = navigationModeController; |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 419 | mNavBarMode = navigationModeController.addListener(this); |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 420 | mBroadcastDispatcher = broadcastDispatcher; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 421 | mCommandQueue = commandQueue; |
Dave Mankoff | 613c7c6 | 2019-11-04 11:46:36 -0500 | [diff] [blame] | 422 | mDivider = divider; |
Dave Mankoff | ae3b432 | 2019-11-05 19:48:24 -0500 | [diff] [blame] | 423 | mRecentsOptional = recentsOptional; |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 424 | mSystemActions = systemActions; |
Dave Mankoff | ea1953c | 2019-11-19 20:23:31 -0500 | [diff] [blame] | 425 | mHandler = mainHandler; |
Chris Wren | 119913a | 2020-06-08 14:27:37 -0400 | [diff] [blame] | 426 | mUiEventLogger = uiEventLogger; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 427 | } |
| 428 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 429 | // ----- Fragment Lifecycle Callbacks ----- |
| 430 | |
| 431 | @Override |
| 432 | public void onCreate(@Nullable Bundle savedInstanceState) { |
| 433 | super.onCreate(savedInstanceState); |
Jason Monk | 8e4e4cb | 2018-12-04 11:10:24 -0500 | [diff] [blame] | 434 | mCommandQueue.observe(getLifecycle(), this); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 435 | mWindowManager = getContext().getSystemService(WindowManager.class); |
| 436 | mAccessibilityManager = getContext().getSystemService(AccessibilityManager.class); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 437 | mContentResolver = getContext().getContentResolver(); |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 438 | mContentResolver.registerContentObserver( |
| 439 | Settings.Secure.getUriFor(Settings.Secure.ASSISTANT), |
| 440 | false /* notifyForDescendants */, mAssistContentObserver, UserHandle.USER_ALL); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 441 | |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 442 | mContentResolver.registerContentObserver( |
| 443 | Settings.Global.getUriFor(FIXED_ROTATION_TRANSFORM_SETTING_NAME), |
| 444 | false /* notifyForDescendants */, mFixedRotationObserver, UserHandle.USER_ALL); |
| 445 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 446 | if (savedInstanceState != null) { |
| 447 | mDisabledFlags1 = savedInstanceState.getInt(EXTRA_DISABLE_STATE, 0); |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 448 | mDisabledFlags2 = savedInstanceState.getInt(EXTRA_DISABLE2_STATE, 0); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 449 | mAppearance = savedInstanceState.getInt(EXTRA_APPEARANCE, 0); |
| 450 | mTransientShown = savedInstanceState.getBoolean(EXTRA_TRANSIENT_STATE, false); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 451 | } |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 452 | mAccessibilityManagerWrapper.addCallback(mAccessibilityListener); |
Tetsutoki Shiozawa | e294e49 | 2019-01-11 18:46:28 +0900 | [diff] [blame] | 453 | |
| 454 | // Respect the latest disabled-flags. |
| 455 | mCommandQueue.recomputeDisableFlags(mDisplayId, false); |
Govinda Wasserman | 1b7d610 | 2020-02-10 16:52:59 -0500 | [diff] [blame] | 456 | |
| 457 | mForceNavBarHandleOpaque = DeviceConfig.getBoolean( |
| 458 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 459 | NAV_BAR_HANDLE_FORCE_OPAQUE, |
| 460 | /* defaultValue = */ true); |
| 461 | DeviceConfig.addOnPropertiesChangedListener( |
| 462 | DeviceConfig.NAMESPACE_SYSTEMUI, mHandler::post, mOnPropertiesChangedListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | @Override |
| 466 | public void onDestroy() { |
| 467 | super.onDestroy(); |
Winson Chung | 52d938d | 2019-09-25 16:50:05 -0700 | [diff] [blame] | 468 | mNavigationModeController.removeListener(this); |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 469 | mAccessibilityManagerWrapper.removeCallback(mAccessibilityListener); |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 470 | mContentResolver.unregisterContentObserver(mAssistContentObserver); |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 471 | mContentResolver.unregisterContentObserver(mFixedRotationObserver); |
Govinda Wasserman | 1b7d610 | 2020-02-10 16:52:59 -0500 | [diff] [blame] | 472 | |
| 473 | DeviceConfig.removeOnPropertiesChangedListener(mOnPropertiesChangedListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | @Override |
| 477 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, |
| 478 | Bundle savedInstanceState) { |
| 479 | return inflater.inflate(R.layout.navigation_bar, container, false); |
| 480 | } |
| 481 | |
| 482 | @Override |
| 483 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 484 | super.onViewCreated(view, savedInstanceState); |
| 485 | mNavigationBarView = (NavigationBarView) view; |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 486 | final Display display = view.getDisplay(); |
| 487 | // It may not have display when running unit test. |
| 488 | if (display != null) { |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 489 | mDisplayId = display.getDisplayId(); |
| 490 | mIsOnDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY; |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 491 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 492 | |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 493 | mNavigationBarView.setComponents(mStatusBarLazy.get().getPanelController()); |
Matthew Ng | f0f8454 | 2018-10-15 11:53:22 -0700 | [diff] [blame] | 494 | mNavigationBarView.setDisabledFlags(mDisabledFlags1); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 495 | mNavigationBarView.setOnVerticalChangedListener(this::onVerticalChanged); |
| 496 | mNavigationBarView.setOnTouchListener(this::onNavigationTouch); |
| 497 | if (savedInstanceState != null) { |
| 498 | mNavigationBarView.getLightTransitionsController().restoreState(savedInstanceState); |
| 499 | } |
Matthew Ng | 9438065 | 2019-04-08 13:43:07 -0700 | [diff] [blame] | 500 | mNavigationBarView.setNavigationIconHints(mNavigationIconHints); |
Winson Chung | 2102ae8 | 2019-06-19 13:15:24 -0700 | [diff] [blame] | 501 | mNavigationBarView.setWindowVisible(isNavBarWindowVisible()); |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 502 | updatedFixedRotation(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 503 | |
| 504 | prepareNavigationBarView(); |
| 505 | checkNavBarModes(); |
| 506 | |
| 507 | IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); |
| 508 | filter.addAction(Intent.ACTION_SCREEN_ON); |
Phil Weaver | a858c5f | 2018-04-26 13:27:30 -0700 | [diff] [blame] | 509 | filter.addAction(Intent.ACTION_USER_SWITCHED); |
Fabian Kozynski | 5e92c6f | 2020-01-03 13:56:17 -0500 | [diff] [blame] | 510 | mBroadcastDispatcher.registerReceiverWithHandler(mBroadcastReceiver, filter, |
| 511 | Handler.getMain(), UserHandle.ALL); |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 512 | notifyNavigationBarScreenOn(); |
Winson Chung | 7e48691 | 2019-04-30 11:11:47 -0700 | [diff] [blame] | 513 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 514 | mOverviewProxyService.addCallback(mOverviewProxyListener); |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 515 | updateSystemUiStateFlags(-1); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 516 | |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 517 | // Currently there is no accelerometer sensor on non-default display. |
| 518 | if (mIsOnDefaultDisplay) { |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 519 | mNavigationBarView.getRotateSuggestionButton().setListener(mRotationButtonListener); |
| 520 | |
| 521 | final RotationButtonController rotationButtonController = |
| 522 | mNavigationBarView.getRotationButtonController(); |
| 523 | rotationButtonController.addRotationCallback(mRotationWatcher); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 524 | |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 525 | // Reset user rotation pref to match that of the WindowManager if starting in locked |
| 526 | // mode. This will automatically happen when switching from auto-rotate to locked mode. |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 527 | if (display != null && rotationButtonController.isRotationLocked()) { |
| 528 | rotationButtonController.setRotationLockedAtAngle(display.getRotation()); |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 529 | } |
| 530 | } else { |
| 531 | mDisabledFlags2 |= StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS; |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 532 | } |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 533 | setDisabled2Flags(mDisabledFlags2); |
shawnlin | 87af538 | 2019-09-13 14:13:13 +0800 | [diff] [blame] | 534 | if (mIsOnDefaultDisplay) { |
| 535 | mAssistHandlerViewController = |
| 536 | new AssistHandleViewController(mHandler, mNavigationBarView); |
| 537 | getBarTransitions().addDarkIntensityListener(mAssistHandlerViewController); |
| 538 | } |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 539 | |
| 540 | initSecondaryHomeHandleForRotation(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | @Override |
| 544 | public void onDestroyView() { |
| 545 | super.onDestroyView(); |
Winson Chung | b03d44d | 2018-09-18 12:42:45 -0700 | [diff] [blame] | 546 | if (mNavigationBarView != null) { |
shawnlin | 87af538 | 2019-09-13 14:13:13 +0800 | [diff] [blame] | 547 | if (mIsOnDefaultDisplay) { |
| 548 | mNavigationBarView.getBarTransitions() |
| 549 | .removeDarkIntensityListener(mAssistHandlerViewController); |
| 550 | mAssistHandlerViewController = null; |
| 551 | } |
Winson Chung | b03d44d | 2018-09-18 12:42:45 -0700 | [diff] [blame] | 552 | mNavigationBarView.getBarTransitions().destroy(); |
| 553 | mNavigationBarView.getLightTransitionsController().destroy(getContext()); |
| 554 | } |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 555 | mOverviewProxyService.removeCallback(mOverviewProxyListener); |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 556 | mBroadcastDispatcher.unregisterReceiver(mBroadcastReceiver); |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 557 | if (mOrientationHandle != null) { |
| 558 | resetSecondaryHandle(); |
| 559 | getContext().getSystemService(DisplayManager.class).unregisterDisplayListener(this); |
| 560 | getBarTransitions().removeDarkIntensityListener(mOrientationHandleIntensityListener); |
| 561 | mWindowManager.removeView(mOrientationHandle); |
Vinit Nayak | d2fe92f | 2020-06-04 13:12:02 -0700 | [diff] [blame] | 562 | mOrientationHandle.getViewTreeObserver().removeOnGlobalLayoutListener( |
| 563 | mOrientationHandleGlobalLayoutListener); |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 564 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | @Override |
| 568 | public void onSaveInstanceState(Bundle outState) { |
| 569 | super.onSaveInstanceState(outState); |
| 570 | outState.putInt(EXTRA_DISABLE_STATE, mDisabledFlags1); |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 571 | outState.putInt(EXTRA_DISABLE2_STATE, mDisabledFlags2); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 572 | outState.putInt(EXTRA_APPEARANCE, mAppearance); |
| 573 | outState.putBoolean(EXTRA_TRANSIENT_STATE, mTransientShown); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 574 | if (mNavigationBarView != null) { |
| 575 | mNavigationBarView.getLightTransitionsController().saveState(outState); |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | @Override |
| 580 | public void onConfigurationChanged(Configuration newConfig) { |
| 581 | super.onConfigurationChanged(newConfig); |
| 582 | final Locale locale = getContext().getResources().getConfiguration().locale; |
| 583 | final int ld = TextUtils.getLayoutDirectionFromLocale(locale); |
| 584 | if (!locale.equals(mLocale) || ld != mLayoutDirection) { |
| 585 | if (DEBUG) { |
| 586 | Log.v(TAG, String.format( |
| 587 | "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection, |
| 588 | locale, ld)); |
| 589 | } |
| 590 | mLocale = locale; |
| 591 | mLayoutDirection = ld; |
| 592 | refreshLayout(ld); |
| 593 | } |
| 594 | repositionNavigationBar(); |
| 595 | } |
| 596 | |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 597 | private void initSecondaryHomeHandleForRotation() { |
| 598 | if (!canShowSecondaryHandle()) { |
| 599 | return; |
| 600 | } |
| 601 | |
| 602 | getContext().getSystemService(DisplayManager.class) |
| 603 | .registerDisplayListener(this, new Handler(Looper.getMainLooper())); |
| 604 | |
| 605 | mOrientationHandle = new VerticalNavigationHandle(getContext()); |
| 606 | |
| 607 | getBarTransitions().addDarkIntensityListener(mOrientationHandleIntensityListener); |
| 608 | mOrientationParams = new WindowManager.LayoutParams(0, 0, |
| 609 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL, |
| 610 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 611 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 612 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
| 613 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH |
| 614 | | WindowManager.LayoutParams.FLAG_SLIPPERY, |
| 615 | PixelFormat.TRANSLUCENT); |
| 616 | mWindowManager.addView(mOrientationHandle, mOrientationParams); |
| 617 | mOrientationHandle.setVisibility(View.GONE); |
Vinit Nayak | d2fe92f | 2020-06-04 13:12:02 -0700 | [diff] [blame] | 618 | mOrientationHandleGlobalLayoutListener = |
| 619 | () -> { |
| 620 | if (mStartingQuickSwitchRotation == -1) { |
| 621 | return; |
| 622 | } |
| 623 | |
| 624 | RectF boundsOnScreen = mOrientationHandle.computeHomeHandleBounds(); |
| 625 | mOrientationHandle.mapRectFromViewToScreenCoords(boundsOnScreen, true); |
| 626 | Rect boundsRounded = new Rect(); |
| 627 | boundsOnScreen.roundOut(boundsRounded); |
| 628 | mNavigationBarView.setOrientedHandleSamplingRegion(boundsRounded); |
| 629 | }; |
| 630 | mOrientationHandle.getViewTreeObserver().addOnGlobalLayoutListener( |
| 631 | mOrientationHandleGlobalLayoutListener); |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | private void orientSecondaryHomeHandle() { |
| 635 | if (!canShowSecondaryHandle()) { |
| 636 | return; |
| 637 | } |
| 638 | |
Winson Chung | c4f637c | 2020-05-28 15:25:25 -0700 | [diff] [blame] | 639 | if (mStartingQuickSwitchRotation == -1 || mDivider.isDividerVisible()) { |
| 640 | // Hide the secondary home handle if we are in multiwindow since apps in multiwindow |
| 641 | // aren't allowed to set the display orientation |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 642 | resetSecondaryHandle(); |
| 643 | } else { |
| 644 | int deltaRotation = deltaRotation(mCurrentRotation, mStartingQuickSwitchRotation); |
Vinit Nayak | 4bf7327 | 2020-06-11 12:23:30 -0700 | [diff] [blame] | 645 | if (mStartingQuickSwitchRotation == -1 || deltaRotation == -1) { |
| 646 | // Curious if starting quickswitch can change between the if check and our delta |
| 647 | Log.d(TAG, "secondary nav delta rotation: " + deltaRotation |
| 648 | + " current: " + mCurrentRotation |
| 649 | + " starting: " + mStartingQuickSwitchRotation); |
| 650 | } |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 651 | int height = 0; |
| 652 | int width = 0; |
| 653 | Rect dispSize = mWindowManager.getCurrentWindowMetrics().getBounds(); |
| 654 | switch (deltaRotation) { |
| 655 | case Surface.ROTATION_90: |
| 656 | case Surface.ROTATION_270: |
| 657 | height = dispSize.height(); |
| 658 | width = getResources() |
| 659 | .getDimensionPixelSize(R.dimen.navigation_bar_height); |
| 660 | break; |
| 661 | case Surface.ROTATION_180: |
| 662 | case Surface.ROTATION_0: |
| 663 | // TODO(b/152683657): Need to determine best UX for this |
| 664 | resetSecondaryHandle(); |
| 665 | return; |
| 666 | } |
| 667 | |
| 668 | mOrientationParams.gravity = |
| 669 | deltaRotation == Surface.ROTATION_90 ? Gravity.LEFT : Gravity.RIGHT; |
| 670 | mOrientationParams.height = height; |
| 671 | mOrientationParams.width = width; |
| 672 | mWindowManager.updateViewLayout(mOrientationHandle, mOrientationParams); |
| 673 | mNavigationBarView.setVisibility(View.GONE); |
| 674 | mOrientationHandle.setVisibility(View.VISIBLE); |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | private void resetSecondaryHandle() { |
| 679 | if (mOrientationHandle != null) { |
| 680 | // Case where nav mode is changed w/o ever invoking a quickstep |
| 681 | // mOrientedHandle is initialized lazily |
| 682 | mOrientationHandle.setVisibility(View.GONE); |
| 683 | } |
Vinit Nayak | d19ef55 | 2020-04-06 15:36:58 -0700 | [diff] [blame] | 684 | if (mNavigationBarView != null) { |
| 685 | mNavigationBarView.setVisibility(View.VISIBLE); |
Vinit Nayak | d2fe92f | 2020-06-04 13:12:02 -0700 | [diff] [blame] | 686 | mNavigationBarView.setOrientedHandleSamplingRegion(null); |
Vinit Nayak | d19ef55 | 2020-04-06 15:36:58 -0700 | [diff] [blame] | 687 | } |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | private int deltaRotation(int oldRotation, int newRotation) { |
| 691 | int delta = newRotation - oldRotation; |
| 692 | if (delta < 0) delta += 4; |
| 693 | return delta; |
| 694 | } |
| 695 | |
| 696 | private void updatedFixedRotation() { |
Vinit Nayak | 50c8027 | 2020-04-06 12:01:13 -0700 | [diff] [blame] | 697 | mFixedRotationEnabled = Settings.Global.getInt(mContentResolver, |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 698 | FIXED_ROTATION_TRANSFORM_SETTING_NAME, 0) != 0; |
| 699 | if (!canShowSecondaryHandle()) { |
| 700 | resetSecondaryHandle(); |
| 701 | } |
| 702 | } |
| 703 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 704 | @Override |
| 705 | public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) { |
| 706 | if (mNavigationBarView != null) { |
| 707 | pw.print(" mNavigationBarWindowState="); |
| 708 | pw.println(windowStateToString(mNavigationBarWindowState)); |
| 709 | pw.print(" mNavigationBarMode="); |
| 710 | pw.println(BarTransitions.modeToString(mNavigationBarMode)); |
| 711 | dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions()); |
| 712 | } |
| 713 | |
Vinit Nayak | 4bf7327 | 2020-06-11 12:23:30 -0700 | [diff] [blame] | 714 | pw.print(" mStartingQuickSwitchRotation=" + mStartingQuickSwitchRotation); |
| 715 | pw.print(" mCurrentRotation=" + mCurrentRotation); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 716 | pw.print(" mNavigationBarView="); |
| 717 | if (mNavigationBarView == null) { |
| 718 | pw.println("null"); |
| 719 | } else { |
| 720 | mNavigationBarView.dump(fd, pw, args); |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | // ----- CommandQueue Callbacks ----- |
| 725 | |
| 726 | @Override |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 727 | public void setImeWindowStatus(int displayId, IBinder token, int vis, int backDisposition, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 728 | boolean showImeSwitcher) { |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 729 | if (displayId != mDisplayId) { |
| 730 | return; |
| 731 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 732 | boolean imeShown = (vis & InputMethodService.IME_VISIBLE) != 0; |
| 733 | int hints = mNavigationIconHints; |
Yohei Yukawa | 386f50e | 2018-03-14 13:03:42 -0700 | [diff] [blame] | 734 | switch (backDisposition) { |
| 735 | case InputMethodService.BACK_DISPOSITION_DEFAULT: |
| 736 | case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS: |
| 737 | case InputMethodService.BACK_DISPOSITION_WILL_DISMISS: |
| 738 | if (imeShown) { |
| 739 | hints |= NAVIGATION_HINT_BACK_ALT; |
| 740 | } else { |
| 741 | hints &= ~NAVIGATION_HINT_BACK_ALT; |
| 742 | } |
| 743 | break; |
| 744 | case InputMethodService.BACK_DISPOSITION_ADJUST_NOTHING: |
| 745 | hints &= ~NAVIGATION_HINT_BACK_ALT; |
| 746 | break; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 747 | } |
| 748 | if (showImeSwitcher) { |
| 749 | hints |= NAVIGATION_HINT_IME_SHOWN; |
| 750 | } else { |
| 751 | hints &= ~NAVIGATION_HINT_IME_SHOWN; |
| 752 | } |
| 753 | if (hints == mNavigationIconHints) return; |
| 754 | |
| 755 | mNavigationIconHints = hints; |
| 756 | |
| 757 | if (mNavigationBarView != null) { |
| 758 | mNavigationBarView.setNavigationIconHints(hints); |
| 759 | } |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 760 | checkBarModes(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | @Override |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 764 | public void setWindowState( |
| 765 | int displayId, @WindowType int window, @WindowVisibleState int state) { |
| 766 | if (displayId == mDisplayId |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 767 | && window == StatusBarManager.WINDOW_NAVIGATION_BAR |
| 768 | && mNavigationBarWindowState != state) { |
| 769 | mNavigationBarWindowState = state; |
Winson Chung | a06e04b | 2020-03-04 13:11:18 -0800 | [diff] [blame] | 770 | updateSystemUiStateFlags(-1); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 771 | if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state)); |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 772 | |
Winson Chung | a06e04b | 2020-03-04 13:11:18 -0800 | [diff] [blame] | 773 | if (mNavigationBarView != null) { |
| 774 | mNavigationBarView.setWindowVisible(isNavBarWindowVisible()); |
| 775 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 779 | @Override |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 780 | public void onRotationProposal(final int rotation, boolean isValid) { |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 781 | final int winRotation = mNavigationBarView.getDisplay().getRotation(); |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 782 | final boolean rotateSuggestionsDisabled = RotationButtonController |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 783 | .hasDisable2RotateSuggestionFlag(mDisabledFlags2); |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 784 | final RotationButtonController rotationButtonController = |
| 785 | mNavigationBarView.getRotationButtonController(); |
| 786 | final RotationButton rotationButton = rotationButtonController.getRotationButton(); |
| 787 | |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 788 | if (RotationContextButton.DEBUG_ROTATION) { |
Mike Digman | 3e33da6 | 2018-03-14 16:25:11 -0700 | [diff] [blame] | 789 | Log.v(TAG, "onRotationProposal proposedRotation=" + Surface.rotationToString(rotation) |
| 790 | + ", winRotation=" + Surface.rotationToString(winRotation) |
| 791 | + ", isValid=" + isValid + ", mNavBarWindowState=" |
| 792 | + StatusBarManager.windowStateToString(mNavigationBarWindowState) |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 793 | + ", rotateSuggestionsDisabled=" + rotateSuggestionsDisabled |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 794 | + ", isRotateButtonVisible=" + (mNavigationBarView == null ? "null" |
| 795 | : rotationButton.isVisible())); |
Mike Digman | 3e33da6 | 2018-03-14 16:25:11 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 798 | // Respect the disabled flag, no need for action as flag change callback will handle hiding |
| 799 | if (rotateSuggestionsDisabled) return; |
| 800 | |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 801 | rotationButtonController.onRotationProposal(rotation, winRotation, isValid); |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 802 | } |
| 803 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 804 | /** Restores the appearance and the transient saved state to {@link NavigationBarFragment}. */ |
| 805 | public void restoreAppearanceAndTransientState() { |
| 806 | final int barMode = barMode(mTransientShown, mAppearance); |
| 807 | mNavigationBarMode = barMode; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 808 | checkNavBarModes(); |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 809 | mAutoHideController.touchAutoHide(); |
Andrii Kulian | 3ddd7de | 2018-10-10 00:33:19 -0700 | [diff] [blame] | 810 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 811 | mLightBarController.onNavigationBarAppearanceChanged(mAppearance, true /* nbModeChanged */, |
| 812 | barMode, false /* navbarColorManagedByIme */); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | @Override |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 816 | public void onSystemBarAppearanceChanged(int displayId, @Appearance int appearance, |
| 817 | AppearanceRegion[] appearanceRegions, boolean navbarColorManagedByIme) { |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 818 | if (displayId != mDisplayId) { |
| 819 | return; |
| 820 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 821 | boolean nbModeChanged = false; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 822 | if (mAppearance != appearance) { |
| 823 | mAppearance = appearance; |
| 824 | if (getView() == null) { |
| 825 | return; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 826 | } |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 827 | nbModeChanged = updateBarMode(barMode(mTransientShown, appearance)); |
Jorim Jaggi | cb1b848 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 828 | } |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 829 | mLightBarController.onNavigationBarAppearanceChanged(appearance, nbModeChanged, |
| 830 | mNavigationBarMode, navbarColorManagedByIme); |
Jorim Jaggi | cb1b848 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 831 | } |
| 832 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 833 | @Override |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 834 | public void showTransient(int displayId, @InternalInsetsType int[] types) { |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 835 | if (displayId != mDisplayId) { |
| 836 | return; |
Ioannis Ilkos | 8cca141 | 2019-10-17 09:38:00 +0000 | [diff] [blame] | 837 | } |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 838 | if (!containsType(types, ITYPE_NAVIGATION_BAR)) { |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 839 | return; |
| 840 | } |
| 841 | if (!mTransientShown) { |
| 842 | mTransientShown = true; |
| 843 | handleTransientChanged(); |
| 844 | } |
Ioannis Ilkos | 8cca141 | 2019-10-17 09:38:00 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 847 | @Override |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 848 | public void abortTransient(int displayId, @InternalInsetsType int[] types) { |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 849 | if (displayId != mDisplayId) { |
| 850 | return; |
| 851 | } |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 852 | if (!containsType(types, ITYPE_NAVIGATION_BAR)) { |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 853 | return; |
| 854 | } |
| 855 | clearTransient(); |
| 856 | } |
| 857 | |
Heemin Seog | e67cefea | 2020-01-28 12:02:50 -0800 | [diff] [blame] | 858 | private void clearTransient() { |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 859 | if (mTransientShown) { |
| 860 | mTransientShown = false; |
| 861 | handleTransientChanged(); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | private void handleTransientChanged() { |
| 866 | if (getView() == null) { |
| 867 | return; |
| 868 | } |
| 869 | if (mNavigationBarView != null) { |
| 870 | mNavigationBarView.onTransientStateChanged(mTransientShown); |
| 871 | } |
| 872 | final int barMode = barMode(mTransientShown, mAppearance); |
| 873 | if (updateBarMode(barMode)) { |
| 874 | mLightBarController.onNavigationBarModeChanged(barMode); |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | // Returns true if the bar mode is changed. |
| 879 | private boolean updateBarMode(int barMode) { |
| 880 | if (mNavigationBarMode != barMode) { |
| 881 | if (mNavigationBarMode == MODE_TRANSPARENT |
| 882 | || mNavigationBarMode == MODE_LIGHTS_OUT_TRANSPARENT) { |
| 883 | mNavigationBarView.hideRecentsOnboarding(); |
| 884 | } |
| 885 | mNavigationBarMode = barMode; |
| 886 | checkNavBarModes(); |
| 887 | mAutoHideController.touchAutoHide(); |
| 888 | return true; |
| 889 | } |
| 890 | return false; |
| 891 | } |
| 892 | |
| 893 | private static @TransitionMode int barMode(boolean isTransient, int appearance) { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 894 | final int lightsOutOpaque = APPEARANCE_LOW_PROFILE_BARS | APPEARANCE_OPAQUE_NAVIGATION_BARS; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 895 | if (isTransient) { |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 896 | return MODE_SEMI_TRANSPARENT; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 897 | } else if ((appearance & lightsOutOpaque) == lightsOutOpaque) { |
Ioannis Ilkos | 8cca141 | 2019-10-17 09:38:00 +0000 | [diff] [blame] | 898 | return MODE_LIGHTS_OUT; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 899 | } else if ((appearance & APPEARANCE_LOW_PROFILE_BARS) != 0) { |
| 900 | return MODE_LIGHTS_OUT_TRANSPARENT; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 901 | } else if ((appearance & APPEARANCE_OPAQUE_NAVIGATION_BARS) != 0) { |
Ioannis Ilkos | 8cca141 | 2019-10-17 09:38:00 +0000 | [diff] [blame] | 902 | return MODE_OPAQUE; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 903 | } else { |
| 904 | return MODE_TRANSPARENT; |
Andrii Kulian | 3ddd7de | 2018-10-10 00:33:19 -0700 | [diff] [blame] | 905 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | @Override |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 909 | public void disable(int displayId, int state1, int state2, boolean animate) { |
| 910 | if (displayId != mDisplayId) { |
| 911 | return; |
| 912 | } |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 913 | // Navigation bar flags are in both state1 and state2. |
| 914 | final int masked = state1 & (StatusBarManager.DISABLE_HOME |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 915 | | StatusBarManager.DISABLE_RECENT |
| 916 | | StatusBarManager.DISABLE_BACK |
| 917 | | StatusBarManager.DISABLE_SEARCH); |
| 918 | if (masked != mDisabledFlags1) { |
| 919 | mDisabledFlags1 = masked; |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 920 | if (mNavigationBarView != null) { |
| 921 | mNavigationBarView.setDisabledFlags(state1); |
| 922 | } |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 923 | updateScreenPinningGestures(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 924 | } |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 925 | |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 926 | // Only default display supports rotation suggestions. |
| 927 | if (mIsOnDefaultDisplay) { |
| 928 | final int masked2 = state2 & (StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS); |
| 929 | if (masked2 != mDisabledFlags2) { |
| 930 | mDisabledFlags2 = masked2; |
| 931 | setDisabled2Flags(masked2); |
| 932 | } |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | |
| 936 | private void setDisabled2Flags(int state2) { |
| 937 | // Method only called on change of disable2 flags |
Evan Laird | b8b717f | 2018-10-25 14:08:32 -0400 | [diff] [blame] | 938 | if (mNavigationBarView != null) { |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 939 | mNavigationBarView.getRotationButtonController().onDisable2FlagChanged(state2); |
Evan Laird | b8b717f | 2018-10-25 14:08:32 -0400 | [diff] [blame] | 940 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 941 | } |
| 942 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 943 | // ----- Internal stuff ----- |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 944 | |
| 945 | private void refreshLayout(int layoutDirection) { |
| 946 | if (mNavigationBarView != null) { |
| 947 | mNavigationBarView.setLayoutDirection(layoutDirection); |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | private boolean shouldDisableNavbarGestures() { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 952 | return !mDeviceProvisionedController.isDeviceProvisioned() |
Matthew Ng | fee0b5b | 2018-02-21 15:38:21 -0800 | [diff] [blame] | 953 | || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | private void repositionNavigationBar() { |
| 957 | if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return; |
| 958 | |
| 959 | prepareNavigationBarView(); |
| 960 | |
| 961 | mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(), |
| 962 | ((View) mNavigationBarView.getParent()).getLayoutParams()); |
| 963 | } |
| 964 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 965 | private void updateScreenPinningGestures() { |
| 966 | if (mNavigationBarView == null) { |
| 967 | return; |
| 968 | } |
| 969 | |
| 970 | // Change the cancel pin gesture to home and back if recents button is invisible |
| 971 | boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 972 | ButtonDispatcher backButton = mNavigationBarView.getBackButton(); |
| 973 | if (recentsVisible) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 974 | backButton.setOnLongClickListener(this::onLongPressBackRecents); |
| 975 | } else { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 976 | backButton.setOnLongClickListener(this::onLongPressBackHome); |
| 977 | } |
| 978 | } |
| 979 | |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 980 | private void notifyNavigationBarScreenOn() { |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 981 | mNavigationBarView.updateNavButtonIcons(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | private void prepareNavigationBarView() { |
| 985 | mNavigationBarView.reorient(); |
| 986 | |
| 987 | ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton(); |
| 988 | recentsButton.setOnClickListener(this::onRecentsClick); |
| 989 | recentsButton.setOnTouchListener(this::onRecentsTouch); |
| 990 | recentsButton.setLongClickable(true); |
| 991 | recentsButton.setOnLongClickListener(this::onLongPressBackRecents); |
| 992 | |
| 993 | ButtonDispatcher backButton = mNavigationBarView.getBackButton(); |
| 994 | backButton.setLongClickable(true); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 995 | |
| 996 | ButtonDispatcher homeButton = mNavigationBarView.getHomeButton(); |
| 997 | homeButton.setOnTouchListener(this::onHomeTouch); |
Matthew Ng | fee0b5b | 2018-02-21 15:38:21 -0800 | [diff] [blame] | 998 | homeButton.setOnLongClickListener(this::onHomeLongClick); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 999 | |
| 1000 | ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton(); |
| 1001 | accessibilityButton.setOnClickListener(this::onAccessibilityClick); |
| 1002 | accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick); |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 1003 | updateAccessibilityServicesState(mAccessibilityManager); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 1004 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 1005 | updateScreenPinningGestures(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | private boolean onHomeTouch(View v, MotionEvent event) { |
| 1009 | if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) { |
| 1010 | return true; |
| 1011 | } |
| 1012 | // If an incoming call is ringing, HOME is totally disabled. |
| 1013 | // (The user is already on the InCallUI at this point, |
| 1014 | // and his ONLY options are to answer or reject the call.) |
| 1015 | switch (event.getAction()) { |
| 1016 | case MotionEvent.ACTION_DOWN: |
| 1017 | mHomeBlockedThisTouch = false; |
| 1018 | TelecomManager telecomManager = |
| 1019 | getContext().getSystemService(TelecomManager.class); |
| 1020 | if (telecomManager != null && telecomManager.isRinging()) { |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 1021 | if (mStatusBarLazy.get().isKeyguardShowing()) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1022 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " + |
| 1023 | "No heads up"); |
| 1024 | mHomeBlockedThisTouch = true; |
| 1025 | return true; |
| 1026 | } |
| 1027 | } |
| 1028 | break; |
| 1029 | case MotionEvent.ACTION_UP: |
| 1030 | case MotionEvent.ACTION_CANCEL: |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 1031 | mStatusBarLazy.get().awakenDreams(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1032 | break; |
| 1033 | } |
| 1034 | return false; |
| 1035 | } |
| 1036 | |
| 1037 | private void onVerticalChanged(boolean isVertical) { |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 1038 | mStatusBarLazy.get().setQsScrimEnabled(!isVertical); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | private boolean onNavigationTouch(View v, MotionEvent event) { |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 1042 | mAutoHideController.checkUserAutoHide(event); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1043 | return false; |
| 1044 | } |
| 1045 | |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 1046 | @VisibleForTesting |
| 1047 | boolean onHomeLongClick(View v) { |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 1048 | if (!mNavigationBarView.isRecentsButtonVisible() |
| 1049 | && ActivityManagerWrapper.getInstance().isScreenPinningActive()) { |
Matthew Ng | fee0b5b | 2018-02-21 15:38:21 -0800 | [diff] [blame] | 1050 | return onLongPressBackHome(v); |
| 1051 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1052 | if (shouldDisableNavbarGestures()) { |
| 1053 | return false; |
| 1054 | } |
Mike Digman | c94759d | 2018-01-23 11:01:21 -0800 | [diff] [blame] | 1055 | mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS); |
Chris Wren | 119913a | 2020-06-08 14:27:37 -0400 | [diff] [blame] | 1056 | mUiEventLogger.log(NavBarActionEvent.NAVBAR_ASSIST_LONGPRESS); |
Govinda Wasserman | 24ff306 | 2019-04-19 09:42:53 -0400 | [diff] [blame] | 1057 | Bundle args = new Bundle(); |
| 1058 | args.putInt( |
| 1059 | AssistManager.INVOCATION_TYPE_KEY, AssistManager.INVOCATION_HOME_BUTTON_LONG_PRESS); |
| 1060 | mAssistManager.startAssist(args); |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 1061 | mStatusBarLazy.get().awakenDreams(); |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 1062 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1063 | if (mNavigationBarView != null) { |
| 1064 | mNavigationBarView.abortCurrentGesture(); |
| 1065 | } |
| 1066 | return true; |
| 1067 | } |
| 1068 | |
| 1069 | // additional optimization when we have software system buttons - start loading the recent |
| 1070 | // tasks on touch down |
| 1071 | private boolean onRecentsTouch(View v, MotionEvent event) { |
| 1072 | int action = event.getAction() & MotionEvent.ACTION_MASK; |
| 1073 | if (action == MotionEvent.ACTION_DOWN) { |
| 1074 | mCommandQueue.preloadRecentApps(); |
| 1075 | } else if (action == MotionEvent.ACTION_CANCEL) { |
| 1076 | mCommandQueue.cancelPreloadRecentApps(); |
| 1077 | } else if (action == MotionEvent.ACTION_UP) { |
| 1078 | if (!v.isPressed()) { |
| 1079 | mCommandQueue.cancelPreloadRecentApps(); |
| 1080 | } |
| 1081 | } |
| 1082 | return false; |
| 1083 | } |
| 1084 | |
| 1085 | private void onRecentsClick(View v) { |
| 1086 | if (LatencyTracker.isEnabled(getContext())) { |
| 1087 | LatencyTracker.getInstance(getContext()).onActionStart( |
| 1088 | LatencyTracker.ACTION_TOGGLE_RECENTS); |
| 1089 | } |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 1090 | mStatusBarLazy.get().awakenDreams(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1091 | mCommandQueue.toggleRecentApps(); |
| 1092 | } |
| 1093 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 1094 | private boolean onLongPressBackHome(View v) { |
| 1095 | return onLongPressNavigationButtons(v, R.id.back, R.id.home); |
| 1096 | } |
| 1097 | |
| 1098 | private boolean onLongPressBackRecents(View v) { |
| 1099 | return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps); |
| 1100 | } |
| 1101 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1102 | /** |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 1103 | * This handles long-press of both back and recents/home. Back is the common button with |
| 1104 | * combination of recents if it is visible or home if recents is invisible. |
| 1105 | * They are handled together to capture them both being long-pressed |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1106 | * at the same time to exit screen pinning (lock task). |
| 1107 | * |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 1108 | * When accessibility mode is on, only a long-press from recents/home |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1109 | * is required to exit. |
| 1110 | * |
| 1111 | * In all other circumstances we try to pass through long-press events |
| 1112 | * for Back, so that apps can still use it. Which can be from two things. |
| 1113 | * 1) Not currently in screen pinning (lock task). |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 1114 | * 2) Back is long-pressed without recents/home. |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1115 | */ |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 1116 | private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1117 | try { |
| 1118 | boolean sendBackLongPress = false; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1119 | IActivityTaskManager activityManager = ActivityTaskManager.getService(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1120 | boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled(); |
| 1121 | boolean inLockTaskMode = activityManager.isInLockTaskMode(); |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 1122 | boolean stopLockTaskMode = false; |
| 1123 | try { |
| 1124 | if (inLockTaskMode && !touchExplorationEnabled) { |
| 1125 | long time = System.currentTimeMillis(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 1126 | |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 1127 | // If we recently long-pressed the other button then they were |
| 1128 | // long-pressed 'together' |
| 1129 | if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) { |
| 1130 | stopLockTaskMode = true; |
| 1131 | return true; |
| 1132 | } else if (v.getId() == btnId1) { |
| 1133 | ButtonDispatcher button = btnId2 == R.id.recent_apps |
| 1134 | ? mNavigationBarView.getRecentsButton() |
| 1135 | : mNavigationBarView.getHomeButton(); |
| 1136 | if (!button.getCurrentView().isPressed()) { |
| 1137 | // If we aren't pressing recents/home right now then they presses |
| 1138 | // won't be together, so send the standard long-press action. |
| 1139 | sendBackLongPress = true; |
| 1140 | } |
| 1141 | } |
| 1142 | mLastLockToAppLongPress = time; |
| 1143 | } else { |
| 1144 | // If this is back still need to handle sending the long-press event. |
| 1145 | if (v.getId() == btnId1) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 1146 | sendBackLongPress = true; |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 1147 | } else if (touchExplorationEnabled && inLockTaskMode) { |
| 1148 | // When in accessibility mode a long press that is recents/home (not back) |
| 1149 | // should stop lock task. |
| 1150 | stopLockTaskMode = true; |
| 1151 | return true; |
| 1152 | } else if (v.getId() == btnId2) { |
| 1153 | return btnId2 == R.id.recent_apps |
| 1154 | ? onLongPressRecents() |
| 1155 | : onHomeLongClick( |
| 1156 | mNavigationBarView.getHomeButton().getCurrentView()); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 1157 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1158 | } |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 1159 | } finally { |
| 1160 | if (stopLockTaskMode) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 1161 | activityManager.stopSystemLockTaskMode(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1162 | // When exiting refresh disabled flags. |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 1163 | mNavigationBarView.updateNavButtonIcons(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1164 | } |
| 1165 | } |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 1166 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1167 | if (sendBackLongPress) { |
| 1168 | KeyButtonView keyButtonView = (KeyButtonView) v; |
| 1169 | keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS); |
| 1170 | keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 1171 | return true; |
| 1172 | } |
| 1173 | } catch (RemoteException e) { |
| 1174 | Log.d(TAG, "Unable to reach activity manager", e); |
| 1175 | } |
| 1176 | return false; |
| 1177 | } |
| 1178 | |
| 1179 | private boolean onLongPressRecents() { |
Dave Mankoff | ae3b432 | 2019-11-05 19:48:24 -0500 | [diff] [blame] | 1180 | if (mRecentsOptional.isPresent() || !ActivityTaskManager.supportsMultiWindow(getContext()) |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 1181 | || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible() |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 1182 | || ActivityManager.isLowRamDeviceStatic() |
Winson Chung | 074c434 | 2018-03-26 17:27:19 -0700 | [diff] [blame] | 1183 | // If we are connected to the overview service, then disable the recents button |
| 1184 | || mOverviewProxyService.getProxy() != null) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1185 | return false; |
| 1186 | } |
| 1187 | |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 1188 | return mStatusBarLazy.get().toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1189 | MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS); |
| 1190 | } |
| 1191 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1192 | private void onAccessibilityClick(View v) { |
Jackal Guo | 8b72993 | 2018-10-19 18:02:51 +0800 | [diff] [blame] | 1193 | final Display display = v.getDisplay(); |
| 1194 | mAccessibilityManager.notifyAccessibilityButtonClicked( |
| 1195 | display != null ? display.getDisplayId() : Display.DEFAULT_DISPLAY); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | private boolean onAccessibilityLongClick(View v) { |
Peter_Liang | 0589ab0 | 2020-04-08 22:18:43 +0800 | [diff] [blame] | 1199 | final Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON); |
Casey Burkhardt | 5e8b980 | 2017-03-24 10:07:20 -0700 | [diff] [blame] | 1200 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
Peter_Liang | 0589ab0 | 2020-04-08 22:18:43 +0800 | [diff] [blame] | 1201 | final String chooserClassName = AccessibilityButtonChooserActivity.class.getName(); |
| 1202 | intent.setClassName(CHOOSER_PACKAGE_NAME, chooserClassName); |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 1203 | v.getContext().startActivityAsUser(intent, UserHandle.CURRENT); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1204 | return true; |
| 1205 | } |
| 1206 | |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 1207 | private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) { |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 1208 | boolean[] feedbackEnabled = new boolean[1]; |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 1209 | int a11yFlags = getA11yButtonState(feedbackEnabled); |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 1210 | |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 1211 | boolean clickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_CLICKABLE) != 0; |
| 1212 | boolean longClickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE) != 0; |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 1213 | mNavigationBarView.setAccessibilityButtonState(clickable, longClickable); |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 1214 | |
| 1215 | updateSystemUiStateFlags(a11yFlags); |
| 1216 | } |
| 1217 | |
| 1218 | public void updateSystemUiStateFlags(int a11yFlags) { |
| 1219 | if (a11yFlags < 0) { |
| 1220 | a11yFlags = getA11yButtonState(null); |
| 1221 | } |
| 1222 | boolean clickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_CLICKABLE) != 0; |
| 1223 | boolean longClickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE) != 0; |
Vinit Nayak | 59b114e6 | 2019-08-12 11:50:00 -0700 | [diff] [blame] | 1224 | |
| 1225 | mSysUiFlagsContainer.setFlag(SYSUI_STATE_A11Y_BUTTON_CLICKABLE, clickable) |
| 1226 | .setFlag(SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE, longClickable) |
| 1227 | .setFlag(SYSUI_STATE_NAV_BAR_HIDDEN, !isNavBarWindowVisible()) |
| 1228 | .commitUpdate(mDisplayId); |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 1229 | registerAction(clickable, SystemActions.SYSTEM_ACTION_ID_ACCESSIBILITY_BUTTON); |
| 1230 | registerAction(longClickable, SystemActions.SYSTEM_ACTION_ID_ACCESSIBILITY_BUTTON_CHOOSER); |
| 1231 | } |
| 1232 | |
| 1233 | private void registerAction(boolean register, int actionId) { |
| 1234 | if (register) { |
| 1235 | mSystemActions.register(actionId); |
| 1236 | } else { |
| 1237 | mSystemActions.unregister(actionId); |
| 1238 | } |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * Returns the system UI flags corresponding the the current accessibility button state |
| 1243 | * @param outFeedbackEnabled if non-null, sets it to true if accessibility feedback is enabled. |
| 1244 | */ |
| 1245 | public int getA11yButtonState(@Nullable boolean[] outFeedbackEnabled) { |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 1246 | boolean feedbackEnabled = false; |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 1247 | // AccessibilityManagerService resolves services for the current user since the local |
| 1248 | // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1249 | final List<AccessibilityServiceInfo> services = |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 1250 | mAccessibilityManager.getEnabledAccessibilityServiceList( |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1251 | AccessibilityServiceInfo.FEEDBACK_ALL_MASK); |
Rhed Jao | 59a40df | 2019-11-28 22:47:18 +0800 | [diff] [blame] | 1252 | final List<String> a11yButtonTargets = |
| 1253 | mAccessibilityManager.getAccessibilityShortcutTargets( |
| 1254 | AccessibilityManager.ACCESSIBILITY_BUTTON); |
| 1255 | final int requestingServices = a11yButtonTargets.size(); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1256 | for (int i = services.size() - 1; i >= 0; --i) { |
| 1257 | AccessibilityServiceInfo info = services.get(i); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 1258 | if (info.feedbackType != 0 && info.feedbackType != |
| 1259 | AccessibilityServiceInfo.FEEDBACK_GENERIC) { |
| 1260 | feedbackEnabled = true; |
| 1261 | } |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1262 | } |
| 1263 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 1264 | if (outFeedbackEnabled != null) { |
| 1265 | outFeedbackEnabled[0] = feedbackEnabled; |
| 1266 | } |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 1267 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 1268 | return (requestingServices >= 1 ? SYSUI_STATE_A11Y_BUTTON_CLICKABLE : 0) |
| 1269 | | (requestingServices >= 2 ? SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE : 0); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1270 | } |
| 1271 | |
Matthew Ng | cf71ead | 2019-04-19 14:24:59 -0700 | [diff] [blame] | 1272 | private void sendAssistantAvailability(boolean available) { |
| 1273 | if (mOverviewProxyService.getProxy() != null) { |
| 1274 | try { |
| 1275 | mOverviewProxyService.getProxy().onAssistantAvailable(available |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 1276 | && QuickStepContract.isGesturalMode(mNavBarMode)); |
Matthew Ng | cf71ead | 2019-04-19 14:24:59 -0700 | [diff] [blame] | 1277 | } catch (RemoteException e) { |
| 1278 | Log.w(TAG, "Unable to send assistant availability data to launcher"); |
| 1279 | } |
| 1280 | } |
| 1281 | } |
| 1282 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1283 | // ----- Methods that DisplayNavigationBarController talks to ----- |
| 1284 | |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 1285 | /** Applies auto dimming animation on navigation bar when touched. */ |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1286 | public void touchAutoDim() { |
| 1287 | getBarTransitions().setAutoDim(false); |
| 1288 | mHandler.removeCallbacks(mAutoDim); |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 1289 | int state = mStatusBarStateController.getState(); |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1290 | if (state != StatusBarState.KEYGUARD && state != StatusBarState.SHADE_LOCKED) { |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 1291 | mHandler.postDelayed(mAutoDim, AUTODIM_TIMEOUT_MS); |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1292 | } |
| 1293 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1294 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1295 | public void setLightBarController(LightBarController lightBarController) { |
| 1296 | mLightBarController = lightBarController; |
| 1297 | mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController()); |
| 1298 | } |
| 1299 | |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 1300 | /** Sets {@link AutoHideController} to the navigation bar. */ |
| 1301 | public void setAutoHideController(AutoHideController autoHideController) { |
| 1302 | mAutoHideController = autoHideController; |
Heemin Seog | 8cfe6c5 | 2020-03-06 15:01:08 -0800 | [diff] [blame] | 1303 | if (mAutoHideController != null) { |
Heemin Seog | a8983af | 2020-03-31 13:16:48 -0700 | [diff] [blame] | 1304 | mAutoHideController.setNavigationBar(mAutoHideUiElement); |
Heemin Seog | 8cfe6c5 | 2020-03-06 15:01:08 -0800 | [diff] [blame] | 1305 | } |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 1306 | } |
| 1307 | |
Heemin Seog | e67cefea | 2020-01-28 12:02:50 -0800 | [diff] [blame] | 1308 | private boolean isTransientShown() { |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 1309 | return mTransientShown; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1310 | } |
| 1311 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1312 | private void checkBarModes() { |
| 1313 | // We only have status bar on default display now. |
| 1314 | if (mIsOnDefaultDisplay) { |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 1315 | mStatusBarLazy.get().checkBarModes(); |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1316 | } else { |
| 1317 | checkNavBarModes(); |
| 1318 | } |
| 1319 | } |
| 1320 | |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 1321 | public boolean isNavBarWindowVisible() { |
| 1322 | return mNavigationBarWindowState == WINDOW_STATE_SHOWING; |
| 1323 | } |
| 1324 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1325 | /** |
| 1326 | * Checks current navigation bar mode and make transitions. |
| 1327 | */ |
| 1328 | public void checkNavBarModes() { |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 1329 | final boolean anim = mStatusBarLazy.get().isDeviceInteractive() |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1330 | && mNavigationBarWindowState != WINDOW_STATE_HIDDEN; |
| 1331 | mNavigationBarView.getBarTransitions().transitionTo(mNavigationBarMode, anim); |
| 1332 | } |
| 1333 | |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 1334 | @Override |
| 1335 | public void onNavigationModeChanged(int mode) { |
| 1336 | mNavBarMode = mode; |
Winson Chung | 30c6260 | 2019-05-09 13:34:48 -0700 | [diff] [blame] | 1337 | updateScreenPinningGestures(); |
Winson Chung | 46d10aa | 2019-05-16 12:05:04 -0700 | [diff] [blame] | 1338 | |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 1339 | if (!canShowSecondaryHandle()) { |
| 1340 | resetSecondaryHandle(); |
| 1341 | } |
| 1342 | |
Winson Chung | 46d10aa | 2019-05-16 12:05:04 -0700 | [diff] [blame] | 1343 | // Workaround for b/132825155, for secondary users, we currently don't receive configuration |
| 1344 | // changes on overlay package change since SystemUI runs for the system user. In this case, |
| 1345 | // trigger a new configuration change to ensure that the nav bar is updated in the same way. |
| 1346 | int userId = ActivityManagerWrapper.getInstance().getCurrentUserId(); |
| 1347 | if (userId != UserHandle.USER_SYSTEM) { |
| 1348 | mHandler.post(() -> { |
| 1349 | FragmentHostManager fragmentHost = FragmentHostManager.get(mNavigationBarView); |
| 1350 | fragmentHost.reloadFragments(); |
| 1351 | }); |
| 1352 | } |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1355 | public void disableAnimationsDuringHide(long delay) { |
| 1356 | mNavigationBarView.setLayoutTransitionsEnabled(false); |
| 1357 | mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true), |
| 1358 | delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE); |
| 1359 | } |
| 1360 | |
shawnlin | 87af538 | 2019-09-13 14:13:13 +0800 | [diff] [blame] | 1361 | @Nullable |
| 1362 | public AssistHandleViewController getAssistHandlerViewController() { |
| 1363 | return mAssistHandlerViewController; |
| 1364 | } |
| 1365 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1366 | /** |
| 1367 | * Performs transitions on navigation bar. |
| 1368 | * |
| 1369 | * @param barMode transition bar mode. |
| 1370 | * @param animate shows animations if {@code true}. |
| 1371 | */ |
| 1372 | public void transitionTo(@TransitionMode int barMode, boolean animate) { |
| 1373 | getBarTransitions().transitionTo(barMode, animate); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1374 | } |
| 1375 | |
James O'Leary | 4335c70 | 2019-05-29 12:38:51 -0400 | [diff] [blame] | 1376 | public NavigationBarTransitions getBarTransitions() { |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1377 | return mNavigationBarView.getBarTransitions(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | public void finishBarAnimations() { |
| 1381 | mNavigationBarView.getBarTransitions().finishAnimations(); |
| 1382 | } |
| 1383 | |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 1384 | private final AccessibilityServicesStateChangeListener mAccessibilityListener = |
| 1385 | this::updateAccessibilityServicesState; |
| 1386 | |
Vinit Nayak | 63e92bc | 2020-03-28 20:43:33 -0700 | [diff] [blame] | 1387 | @Override |
| 1388 | public void onDisplayAdded(int displayId) { |
| 1389 | |
| 1390 | } |
| 1391 | |
| 1392 | @Override |
| 1393 | public void onDisplayRemoved(int displayId) { |
| 1394 | |
| 1395 | } |
| 1396 | |
| 1397 | @Override |
| 1398 | public void onDisplayChanged(int displayId) { |
| 1399 | if (!canShowSecondaryHandle()) { |
| 1400 | return; |
| 1401 | } |
| 1402 | |
| 1403 | int rotation = getContext().getResources().getConfiguration() |
| 1404 | .windowConfiguration.getRotation(); |
| 1405 | if (rotation != mCurrentRotation) { |
| 1406 | mCurrentRotation = rotation; |
| 1407 | orientSecondaryHomeHandle(); |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | private boolean canShowSecondaryHandle() { |
| 1412 | return mFixedRotationEnabled && mNavBarMode == NAV_BAR_MODE_GESTURAL; |
| 1413 | } |
| 1414 | |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 1415 | private final Consumer<Integer> mRotationWatcher = rotation -> { |
| 1416 | if (mNavigationBarView != null |
| 1417 | && mNavigationBarView.needsReorient(rotation)) { |
| 1418 | repositionNavigationBar(); |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 1419 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1420 | }; |
| 1421 | |
| 1422 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 1423 | @Override |
| 1424 | public void onReceive(Context context, Intent intent) { |
| 1425 | String action = intent.getAction(); |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 1426 | if (Intent.ACTION_SCREEN_OFF.equals(action) |
| 1427 | || Intent.ACTION_SCREEN_ON.equals(action)) { |
| 1428 | notifyNavigationBarScreenOn(); |
Vinit Nayak | 3f35db5 | 2019-08-08 17:31:48 -0700 | [diff] [blame] | 1429 | mNavigationBarView.onScreenStateChanged(Intent.ACTION_SCREEN_ON.equals(action)); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1430 | } |
Phil Weaver | a858c5f | 2018-04-26 13:27:30 -0700 | [diff] [blame] | 1431 | if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
| 1432 | // The accessibility settings may be different for the new user |
| 1433 | updateAccessibilityServicesState(mAccessibilityManager); |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1434 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1435 | } |
| 1436 | }; |
| 1437 | |
| 1438 | public static View create(Context context, FragmentListener listener) { |
| 1439 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
Charles Chen | b6aff43 | 2018-11-16 20:25:46 +0800 | [diff] [blame] | 1440 | LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, |
| 1441 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1442 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING |
| 1443 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1444 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 1445 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 1446 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH |
| 1447 | | WindowManager.LayoutParams.FLAG_SLIPPERY, |
| 1448 | PixelFormat.TRANSLUCENT); |
| 1449 | lp.token = new Binder(); |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1450 | lp.setTitle("NavigationBar" + context.getDisplayId()); |
Phil Weaver | 8583ae8 | 2018-02-13 11:01:24 -0800 | [diff] [blame] | 1451 | lp.accessibilityTitle = context.getString(R.string.nav_bar); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1452 | lp.windowAnimations = 0; |
Peiyong Lin | 7504538 | 2019-03-04 19:22:33 -0800 | [diff] [blame] | 1453 | lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1454 | |
| 1455 | View navigationBarView = LayoutInflater.from(context).inflate( |
| 1456 | R.layout.navigation_bar_window, null); |
| 1457 | |
| 1458 | if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView); |
| 1459 | if (navigationBarView == null) return null; |
| 1460 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 1461 | final NavigationBarFragment fragment = FragmentHostManager.get(navigationBarView) |
| 1462 | .create(NavigationBarFragment.class); |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 1463 | navigationBarView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { |
| 1464 | @Override |
| 1465 | public void onViewAttachedToWindow(View v) { |
| 1466 | final FragmentHostManager fragmentHost = FragmentHostManager.get(v); |
| 1467 | fragmentHost.getFragmentManager().beginTransaction() |
| 1468 | .replace(R.id.navigation_bar_frame, fragment, TAG) |
| 1469 | .commit(); |
| 1470 | fragmentHost.addTagListener(TAG, listener); |
| 1471 | } |
| 1472 | |
| 1473 | @Override |
| 1474 | public void onViewDetachedFromWindow(View v) { |
| 1475 | FragmentHostManager.removeAndDestroy(v); |
Winson Chung | a06e04b | 2020-03-04 13:11:18 -0800 | [diff] [blame] | 1476 | navigationBarView.removeOnAttachStateChangeListener(this); |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 1477 | } |
| 1478 | }); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1479 | context.getSystemService(WindowManager.class).addView(navigationBarView, lp); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1480 | return navigationBarView; |
| 1481 | } |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 1482 | |
| 1483 | @VisibleForTesting |
| 1484 | int getNavigationIconHints() { |
| 1485 | return mNavigationIconHints; |
| 1486 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1487 | } |