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; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 24 | import static android.view.InsetsState.TYPE_NAVIGATION_BAR; |
| 25 | import static android.view.InsetsState.containsType; |
| 26 | import static android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS; |
| 27 | import static android.view.WindowInsetsController.APPEARANCE_OPAQUE_SIDE_BARS; |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 28 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 29 | |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 30 | import static com.android.systemui.recents.OverviewProxyService.OverviewProxyListener; |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 31 | import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_A11Y_BUTTON_CLICKABLE; |
| 32 | 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] | 33 | 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] | 34 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT; |
Tracy Zhou | 1ac592c | 2018-07-25 13:47:37 -0700 | [diff] [blame] | 35 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT_TRANSPARENT; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 36 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_OPAQUE; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 37 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT; |
Tracy Zhou | 1ac592c | 2018-07-25 13:47:37 -0700 | [diff] [blame] | 38 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_TRANSPARENT; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 39 | import static com.android.systemui.statusbar.phone.BarTransitions.TransitionMode; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 40 | import static com.android.systemui.statusbar.phone.StatusBar.DEBUG_WINDOW_STATE; |
| 41 | import static com.android.systemui.statusbar.phone.StatusBar.dumpBarTransitions; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 42 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 43 | import android.accessibilityservice.AccessibilityServiceInfo; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 44 | import android.annotation.IdRes; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 45 | import android.annotation.Nullable; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 46 | import android.app.ActivityManager; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 47 | import android.app.ActivityTaskManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 48 | import android.app.IActivityTaskManager; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 49 | import android.app.StatusBarManager; |
| 50 | import android.content.BroadcastReceiver; |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 51 | import android.content.ContentResolver; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 52 | import android.content.Context; |
| 53 | import android.content.Intent; |
| 54 | import android.content.IntentFilter; |
| 55 | import android.content.res.Configuration; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 56 | import android.database.ContentObserver; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 57 | import android.graphics.PixelFormat; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 58 | import android.inputmethodservice.InputMethodService; |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 59 | import android.net.Uri; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 60 | import android.os.Binder; |
| 61 | import android.os.Bundle; |
| 62 | import android.os.Handler; |
| 63 | import android.os.IBinder; |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 64 | import android.os.Looper; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 65 | import android.os.RemoteException; |
| 66 | import android.os.UserHandle; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 67 | import android.provider.Settings; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 68 | import android.telecom.TelecomManager; |
| 69 | import android.text.TextUtils; |
| 70 | import android.util.Log; |
Andrii Kulian | 3ddd7de | 2018-10-10 00:33:19 -0700 | [diff] [blame] | 71 | import android.view.Display; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 72 | import android.view.InsetsState.InternalInsetType; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 73 | import android.view.KeyEvent; |
| 74 | import android.view.LayoutInflater; |
| 75 | import android.view.MotionEvent; |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 76 | import android.view.Surface; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 77 | import android.view.View; |
| 78 | import android.view.ViewGroup; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 79 | import android.view.WindowInsetsController.Appearance; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 80 | import android.view.WindowManager; |
| 81 | import android.view.WindowManager.LayoutParams; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 82 | import android.view.accessibility.AccessibilityEvent; |
| 83 | import android.view.accessibility.AccessibilityManager; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 84 | import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 85 | |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 86 | import androidx.annotation.VisibleForTesting; |
| 87 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 88 | import com.android.internal.logging.MetricsLogger; |
| 89 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | ea03be1 | 2017-12-04 11:08:41 -0500 | [diff] [blame] | 90 | import com.android.internal.util.LatencyTracker; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 91 | import com.android.internal.view.AppearanceRegion; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 92 | import com.android.systemui.R; |
shawnlin | 87af538 | 2019-09-13 14:13:13 +0800 | [diff] [blame] | 93 | import com.android.systemui.assist.AssistHandleViewController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 94 | import com.android.systemui.assist.AssistManager; |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 95 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Dave Mankoff | ea1953c | 2019-11-19 20:23:31 -0500 | [diff] [blame] | 96 | import com.android.systemui.dagger.qualifiers.MainHandler; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 97 | import com.android.systemui.fragments.FragmentHostManager; |
| 98 | import com.android.systemui.fragments.FragmentHostManager.FragmentListener; |
Vinit Nayak | 59b114e6 | 2019-08-12 11:50:00 -0700 | [diff] [blame] | 99 | import com.android.systemui.model.SysUiState; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 100 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Andrii Kulian | 3ddd7de | 2018-10-10 00:33:19 -0700 | [diff] [blame] | 101 | import com.android.systemui.recents.OverviewProxyService; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 102 | import com.android.systemui.recents.Recents; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 103 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Sunny Goyal | a6a5812 | 2019-04-02 10:20:29 -0700 | [diff] [blame] | 104 | import com.android.systemui.shared.system.QuickStepContract; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 105 | import com.android.systemui.stackdivider.Divider; |
| 106 | import com.android.systemui.statusbar.CommandQueue; |
| 107 | import com.android.systemui.statusbar.CommandQueue.Callbacks; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 108 | import com.android.systemui.statusbar.StatusBarState; |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 109 | import com.android.systemui.statusbar.notification.stack.StackStateAnimator; |
| 110 | import com.android.systemui.statusbar.phone.ContextualButton.ContextButtonListener; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 111 | import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 112 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 113 | import com.android.systemui.statusbar.policy.KeyButtonView; |
Jason Monk | 8e4e4cb | 2018-12-04 11:10:24 -0500 | [diff] [blame] | 114 | import com.android.systemui.util.LifecycleFragment; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 115 | |
| 116 | import java.io.FileDescriptor; |
| 117 | import java.io.PrintWriter; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 118 | import java.util.List; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 119 | import java.util.Locale; |
Dave Mankoff | ae3b432 | 2019-11-05 19:48:24 -0500 | [diff] [blame] | 120 | import java.util.Optional; |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 121 | import java.util.function.Consumer; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 122 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 123 | import javax.inject.Inject; |
| 124 | |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 125 | import dagger.Lazy; |
| 126 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 127 | /** |
| 128 | * Fragment containing the NavigationBarFragment. Contains logic for what happens |
| 129 | * on clicks and view states of the nav bar. |
| 130 | */ |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 131 | public class NavigationBarFragment extends LifecycleFragment implements Callbacks, |
| 132 | NavigationModeController.ModeChangedListener { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 133 | |
Jason Monk | d4afe15 | 2017-05-01 15:37:43 -0400 | [diff] [blame] | 134 | public static final String TAG = "NavigationBar"; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 135 | private static final boolean DEBUG = false; |
| 136 | private static final String EXTRA_DISABLE_STATE = "disabled_state"; |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 137 | private static final String EXTRA_DISABLE2_STATE = "disabled2_state"; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 138 | private static final String EXTRA_APPEARANCE = "appearance"; |
| 139 | private static final String EXTRA_TRANSIENT_STATE = "transient_state"; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 140 | |
| 141 | /** Allow some time inbetween the long press for back and recents. */ |
| 142 | private static final int LOCK_TO_APP_GESTURE_TOLERENCE = 200; |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 143 | private static final long AUTODIM_TIMEOUT_MS = 2250; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 144 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 145 | private final AccessibilityManagerWrapper mAccessibilityManagerWrapper; |
| 146 | protected final AssistManager mAssistManager; |
Vinit Nayak | 59b114e6 | 2019-08-12 11:50:00 -0700 | [diff] [blame] | 147 | private SysUiState mSysUiFlagsContainer; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 148 | private final MetricsLogger mMetricsLogger; |
| 149 | private final DeviceProvisionedController mDeviceProvisionedController; |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 150 | private final StatusBarStateController mStatusBarStateController; |
Winson Chung | 52d938d | 2019-09-25 16:50:05 -0700 | [diff] [blame] | 151 | private final NavigationModeController mNavigationModeController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 152 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 153 | protected NavigationBarView mNavigationBarView = null; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 154 | |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 155 | private @WindowVisibleState int mNavigationBarWindowState = WINDOW_STATE_SHOWING; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 156 | |
| 157 | private int mNavigationIconHints = 0; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 158 | private @TransitionMode int mNavigationBarMode; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 159 | private AccessibilityManager mAccessibilityManager; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 160 | private MagnificationContentObserver mMagnificationObserver; |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 161 | private ContentResolver mContentResolver; |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 162 | private boolean mAssistantAvailable; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 163 | |
| 164 | private int mDisabledFlags1; |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 165 | private int mDisabledFlags2; |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 166 | private final Lazy<StatusBar> mStatusBarLazy; |
| 167 | private Recents mRecents; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 168 | private StatusBar mStatusBar; |
Dave Mankoff | 613c7c6 | 2019-11-04 11:46:36 -0500 | [diff] [blame] | 169 | private final Divider mDivider; |
Dave Mankoff | ae3b432 | 2019-11-05 19:48:24 -0500 | [diff] [blame] | 170 | private final Optional<Recents> mRecentsOptional; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 171 | private WindowManager mWindowManager; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 172 | private final CommandQueue mCommandQueue; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 173 | private long mLastLockToAppLongPress; |
| 174 | |
| 175 | private Locale mLocale; |
| 176 | private int mLayoutDirection; |
| 177 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 178 | /** @see android.view.WindowInsetsController#setSystemBarsAppearance(int) */ |
| 179 | private @Appearance int mAppearance; |
| 180 | |
| 181 | private boolean mTransientShown; |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 182 | private int mNavBarMode = NAV_BAR_MODE_3BUTTON; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 183 | private LightBarController mLightBarController; |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 184 | private AutoHideController mAutoHideController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 185 | |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 186 | private OverviewProxyService mOverviewProxyService; |
| 187 | |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 188 | private final BroadcastDispatcher mBroadcastDispatcher; |
| 189 | |
Charles Chen | 54fce2c | 2019-03-13 18:17:29 +0800 | [diff] [blame] | 190 | @VisibleForTesting |
| 191 | public int mDisplayId; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 192 | private boolean mIsOnDefaultDisplay; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 193 | public boolean mHomeBlockedThisTouch; |
shawnlin | 87af538 | 2019-09-13 14:13:13 +0800 | [diff] [blame] | 194 | |
| 195 | /** Only for default display */ |
| 196 | @Nullable |
| 197 | private AssistHandleViewController mAssistHandlerViewController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 198 | |
Dave Mankoff | ea1953c | 2019-11-19 20:23:31 -0500 | [diff] [blame] | 199 | private final Handler mHandler; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 200 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 201 | private final OverviewProxyListener mOverviewProxyListener = new OverviewProxyListener() { |
| 202 | @Override |
| 203 | public void onConnectionChanged(boolean isConnected) { |
Winson Chung | f9e3027 | 2018-03-26 17:25:36 -0700 | [diff] [blame] | 204 | mNavigationBarView.updateStates(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 205 | updateScreenPinningGestures(); |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 206 | |
| 207 | // Send the assistant availability upon connection |
| 208 | if (isConnected) { |
Matthew Ng | cf71ead | 2019-04-19 14:24:59 -0700 | [diff] [blame] | 209 | sendAssistantAvailability(mAssistantAvailable); |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 210 | } |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | @Override |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 214 | public void onQuickStepStarted() { |
Mike Digman | 85a9bea | 2018-02-23 15:08:53 -0800 | [diff] [blame] | 215 | // Use navbar dragging as a signal to hide the rotate button |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 216 | mNavigationBarView.getRotationButtonController().setRotateSuggestionButtonState(false); |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 217 | |
| 218 | // Hide the notifications panel when quick step starts |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 219 | mStatusBarLazy.get().collapsePanel(true /* animate */); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 220 | } |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 221 | |
| 222 | @Override |
Matthew Ng | 42025e3 | 2019-02-20 15:02:58 -0800 | [diff] [blame] | 223 | public void startAssistant(Bundle bundle) { |
| 224 | mAssistManager.startAssist(bundle); |
| 225 | } |
| 226 | |
| 227 | @Override |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 228 | public void onNavBarButtonAlphaChanged(float alpha, boolean animate) { |
| 229 | ButtonDispatcher buttonDispatcher = null; |
| 230 | if (QuickStepContract.isSwipeUpMode(mNavBarMode)) { |
| 231 | buttonDispatcher = mNavigationBarView.getBackButton(); |
| 232 | } else if (QuickStepContract.isGesturalMode(mNavBarMode)) { |
| 233 | buttonDispatcher = mNavigationBarView.getHomeHandle(); |
| 234 | } |
| 235 | if (buttonDispatcher != null) { |
| 236 | buttonDispatcher.setVisibility(alpha > 0 ? View.VISIBLE : View.INVISIBLE); |
| 237 | buttonDispatcher.setAlpha(alpha, animate); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 238 | } |
Matthew Ng | 96985e7 | 2018-05-08 15:46:13 -0700 | [diff] [blame] | 239 | } |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 240 | }; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 241 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 242 | private final ContextButtonListener mRotationButtonListener = (button, visible) -> { |
| 243 | if (visible) { |
| 244 | // If the button will actually become visible and the navbar is about to hide, |
| 245 | // tell the statusbar to keep it around for longer |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 246 | mAutoHideController.touchAutoHide(); |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 247 | } |
| 248 | }; |
| 249 | |
| 250 | private final Runnable mAutoDim = () -> getBarTransitions().setAutoDim(true); |
| 251 | |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 252 | private final ContentObserver mAssistContentObserver = new ContentObserver( |
| 253 | new Handler(Looper.getMainLooper())) { |
| 254 | @Override |
| 255 | public void onChange(boolean selfChange, Uri uri) { |
| 256 | boolean available = mAssistManager |
| 257 | .getAssistInfoForUser(UserHandle.USER_CURRENT) != null; |
| 258 | if (mAssistantAvailable != available) { |
Matthew Ng | cf71ead | 2019-04-19 14:24:59 -0700 | [diff] [blame] | 259 | sendAssistantAvailability(available); |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 260 | mAssistantAvailable = available; |
| 261 | } |
| 262 | } |
| 263 | }; |
| 264 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 265 | @Inject |
| 266 | public NavigationBarFragment(AccessibilityManagerWrapper accessibilityManagerWrapper, |
| 267 | DeviceProvisionedController deviceProvisionedController, MetricsLogger metricsLogger, |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 268 | AssistManager assistManager, OverviewProxyService overviewProxyService, |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 269 | NavigationModeController navigationModeController, |
Vinit Nayak | 59b114e6 | 2019-08-12 11:50:00 -0700 | [diff] [blame] | 270 | StatusBarStateController statusBarStateController, |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 271 | SysUiState sysUiFlagsContainer, |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 272 | BroadcastDispatcher broadcastDispatcher, |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 273 | CommandQueue commandQueue, Divider divider, |
Dave Mankoff | ea1953c | 2019-11-19 20:23:31 -0500 | [diff] [blame] | 274 | Optional<Recents> recentsOptional, Lazy<StatusBar> statusBarLazy, |
| 275 | @MainHandler Handler mainHandler) { |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 276 | mAccessibilityManagerWrapper = accessibilityManagerWrapper; |
| 277 | mDeviceProvisionedController = deviceProvisionedController; |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 278 | mStatusBarStateController = statusBarStateController; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 279 | mMetricsLogger = metricsLogger; |
| 280 | mAssistManager = assistManager; |
Vinit Nayak | 59b114e6 | 2019-08-12 11:50:00 -0700 | [diff] [blame] | 281 | mSysUiFlagsContainer = sysUiFlagsContainer; |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 282 | mStatusBarLazy = statusBarLazy; |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 283 | mAssistantAvailable = mAssistManager.getAssistInfoForUser(UserHandle.USER_CURRENT) != null; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 284 | mOverviewProxyService = overviewProxyService; |
Winson Chung | 52d938d | 2019-09-25 16:50:05 -0700 | [diff] [blame] | 285 | mNavigationModeController = navigationModeController; |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 286 | mNavBarMode = navigationModeController.addListener(this); |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 287 | mBroadcastDispatcher = broadcastDispatcher; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 288 | mCommandQueue = commandQueue; |
Dave Mankoff | 613c7c6 | 2019-11-04 11:46:36 -0500 | [diff] [blame] | 289 | mDivider = divider; |
Dave Mankoff | ae3b432 | 2019-11-05 19:48:24 -0500 | [diff] [blame] | 290 | mRecentsOptional = recentsOptional; |
Dave Mankoff | ea1953c | 2019-11-19 20:23:31 -0500 | [diff] [blame] | 291 | mHandler = mainHandler; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 292 | } |
| 293 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 294 | // ----- Fragment Lifecycle Callbacks ----- |
| 295 | |
| 296 | @Override |
| 297 | public void onCreate(@Nullable Bundle savedInstanceState) { |
| 298 | super.onCreate(savedInstanceState); |
Jason Monk | 8e4e4cb | 2018-12-04 11:10:24 -0500 | [diff] [blame] | 299 | mCommandQueue.observe(getLifecycle(), this); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 300 | mWindowManager = getContext().getSystemService(WindowManager.class); |
| 301 | mAccessibilityManager = getContext().getSystemService(AccessibilityManager.class); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 302 | mContentResolver = getContext().getContentResolver(); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 303 | mMagnificationObserver = new MagnificationContentObserver( |
| 304 | getContext().getMainThreadHandler()); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 305 | mContentResolver.registerContentObserver(Settings.Secure.getUriFor( |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 306 | Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED), false, |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 307 | mMagnificationObserver, UserHandle.USER_ALL); |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 308 | mContentResolver.registerContentObserver( |
| 309 | Settings.Secure.getUriFor(Settings.Secure.ASSISTANT), |
| 310 | false /* notifyForDescendants */, mAssistContentObserver, UserHandle.USER_ALL); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 311 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 312 | if (savedInstanceState != null) { |
| 313 | mDisabledFlags1 = savedInstanceState.getInt(EXTRA_DISABLE_STATE, 0); |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 314 | mDisabledFlags2 = savedInstanceState.getInt(EXTRA_DISABLE2_STATE, 0); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 315 | mAppearance = savedInstanceState.getInt(EXTRA_APPEARANCE, 0); |
| 316 | mTransientShown = savedInstanceState.getBoolean(EXTRA_TRANSIENT_STATE, false); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 317 | } |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 318 | mAccessibilityManagerWrapper.addCallback(mAccessibilityListener); |
Tetsutoki Shiozawa | e294e49 | 2019-01-11 18:46:28 +0900 | [diff] [blame] | 319 | |
| 320 | // Respect the latest disabled-flags. |
| 321 | mCommandQueue.recomputeDisableFlags(mDisplayId, false); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | @Override |
| 325 | public void onDestroy() { |
| 326 | super.onDestroy(); |
Winson Chung | 52d938d | 2019-09-25 16:50:05 -0700 | [diff] [blame] | 327 | mNavigationModeController.removeListener(this); |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 328 | mAccessibilityManagerWrapper.removeCallback(mAccessibilityListener); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 329 | mContentResolver.unregisterContentObserver(mMagnificationObserver); |
Matthew Ng | add4c39 | 2019-03-01 16:02:31 -0800 | [diff] [blame] | 330 | mContentResolver.unregisterContentObserver(mAssistContentObserver); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | @Override |
| 334 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, |
| 335 | Bundle savedInstanceState) { |
| 336 | return inflater.inflate(R.layout.navigation_bar, container, false); |
| 337 | } |
| 338 | |
| 339 | @Override |
| 340 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 341 | super.onViewCreated(view, savedInstanceState); |
| 342 | mNavigationBarView = (NavigationBarView) view; |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 343 | final Display display = view.getDisplay(); |
| 344 | // It may not have display when running unit test. |
| 345 | if (display != null) { |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 346 | mDisplayId = display.getDisplayId(); |
| 347 | mIsOnDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY; |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 348 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 349 | |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 350 | mNavigationBarView.setComponents(mStatusBarLazy.get().getPanel(), mAssistManager); |
Matthew Ng | f0f8454 | 2018-10-15 11:53:22 -0700 | [diff] [blame] | 351 | mNavigationBarView.setDisabledFlags(mDisabledFlags1); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 352 | mNavigationBarView.setOnVerticalChangedListener(this::onVerticalChanged); |
| 353 | mNavigationBarView.setOnTouchListener(this::onNavigationTouch); |
| 354 | if (savedInstanceState != null) { |
| 355 | mNavigationBarView.getLightTransitionsController().restoreState(savedInstanceState); |
| 356 | } |
Matthew Ng | 9438065 | 2019-04-08 13:43:07 -0700 | [diff] [blame] | 357 | mNavigationBarView.setNavigationIconHints(mNavigationIconHints); |
Winson Chung | 2102ae8 | 2019-06-19 13:15:24 -0700 | [diff] [blame] | 358 | mNavigationBarView.setWindowVisible(isNavBarWindowVisible()); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 359 | |
| 360 | prepareNavigationBarView(); |
| 361 | checkNavBarModes(); |
| 362 | |
| 363 | IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); |
| 364 | filter.addAction(Intent.ACTION_SCREEN_ON); |
Phil Weaver | a858c5f | 2018-04-26 13:27:30 -0700 | [diff] [blame] | 365 | filter.addAction(Intent.ACTION_USER_SWITCHED); |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 366 | mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter, Handler.getMain(), |
| 367 | UserHandle.ALL); |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 368 | notifyNavigationBarScreenOn(); |
Winson Chung | 7e48691 | 2019-04-30 11:11:47 -0700 | [diff] [blame] | 369 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 370 | mOverviewProxyService.addCallback(mOverviewProxyListener); |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 371 | updateSystemUiStateFlags(-1); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 372 | |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 373 | // Currently there is no accelerometer sensor on non-default display. |
| 374 | if (mIsOnDefaultDisplay) { |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 375 | mNavigationBarView.getRotateSuggestionButton().setListener(mRotationButtonListener); |
| 376 | |
| 377 | final RotationButtonController rotationButtonController = |
| 378 | mNavigationBarView.getRotationButtonController(); |
| 379 | rotationButtonController.addRotationCallback(mRotationWatcher); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 380 | |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 381 | // Reset user rotation pref to match that of the WindowManager if starting in locked |
| 382 | // 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] | 383 | if (display != null && rotationButtonController.isRotationLocked()) { |
| 384 | rotationButtonController.setRotationLockedAtAngle(display.getRotation()); |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 385 | } |
| 386 | } else { |
| 387 | mDisabledFlags2 |= StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS; |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 388 | } |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 389 | setDisabled2Flags(mDisabledFlags2); |
shawnlin | 87af538 | 2019-09-13 14:13:13 +0800 | [diff] [blame] | 390 | if (mIsOnDefaultDisplay) { |
| 391 | mAssistHandlerViewController = |
| 392 | new AssistHandleViewController(mHandler, mNavigationBarView); |
| 393 | getBarTransitions().addDarkIntensityListener(mAssistHandlerViewController); |
| 394 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | @Override |
| 398 | public void onDestroyView() { |
| 399 | super.onDestroyView(); |
Winson Chung | b03d44d | 2018-09-18 12:42:45 -0700 | [diff] [blame] | 400 | if (mNavigationBarView != null) { |
shawnlin | 87af538 | 2019-09-13 14:13:13 +0800 | [diff] [blame] | 401 | if (mIsOnDefaultDisplay) { |
| 402 | mNavigationBarView.getBarTransitions() |
| 403 | .removeDarkIntensityListener(mAssistHandlerViewController); |
| 404 | mAssistHandlerViewController = null; |
| 405 | } |
Winson Chung | b03d44d | 2018-09-18 12:42:45 -0700 | [diff] [blame] | 406 | mNavigationBarView.getBarTransitions().destroy(); |
| 407 | mNavigationBarView.getLightTransitionsController().destroy(getContext()); |
| 408 | } |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 409 | mOverviewProxyService.removeCallback(mOverviewProxyListener); |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 410 | mBroadcastDispatcher.unregisterReceiver(mBroadcastReceiver); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | @Override |
| 414 | public void onSaveInstanceState(Bundle outState) { |
| 415 | super.onSaveInstanceState(outState); |
| 416 | outState.putInt(EXTRA_DISABLE_STATE, mDisabledFlags1); |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 417 | outState.putInt(EXTRA_DISABLE2_STATE, mDisabledFlags2); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 418 | outState.putInt(EXTRA_APPEARANCE, mAppearance); |
| 419 | outState.putBoolean(EXTRA_TRANSIENT_STATE, mTransientShown); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 420 | if (mNavigationBarView != null) { |
| 421 | mNavigationBarView.getLightTransitionsController().saveState(outState); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | @Override |
| 426 | public void onConfigurationChanged(Configuration newConfig) { |
| 427 | super.onConfigurationChanged(newConfig); |
| 428 | final Locale locale = getContext().getResources().getConfiguration().locale; |
| 429 | final int ld = TextUtils.getLayoutDirectionFromLocale(locale); |
| 430 | if (!locale.equals(mLocale) || ld != mLayoutDirection) { |
| 431 | if (DEBUG) { |
| 432 | Log.v(TAG, String.format( |
| 433 | "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection, |
| 434 | locale, ld)); |
| 435 | } |
| 436 | mLocale = locale; |
| 437 | mLayoutDirection = ld; |
| 438 | refreshLayout(ld); |
| 439 | } |
| 440 | repositionNavigationBar(); |
| 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) { |
| 445 | if (mNavigationBarView != null) { |
| 446 | pw.print(" mNavigationBarWindowState="); |
| 447 | pw.println(windowStateToString(mNavigationBarWindowState)); |
| 448 | pw.print(" mNavigationBarMode="); |
| 449 | pw.println(BarTransitions.modeToString(mNavigationBarMode)); |
| 450 | dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions()); |
| 451 | } |
| 452 | |
| 453 | pw.print(" mNavigationBarView="); |
| 454 | if (mNavigationBarView == null) { |
| 455 | pw.println("null"); |
| 456 | } else { |
| 457 | mNavigationBarView.dump(fd, pw, args); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | // ----- CommandQueue Callbacks ----- |
| 462 | |
| 463 | @Override |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 464 | public void setImeWindowStatus(int displayId, IBinder token, int vis, int backDisposition, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 465 | boolean showImeSwitcher) { |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 466 | if (displayId != mDisplayId) { |
| 467 | return; |
| 468 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 469 | boolean imeShown = (vis & InputMethodService.IME_VISIBLE) != 0; |
| 470 | int hints = mNavigationIconHints; |
Yohei Yukawa | 386f50e | 2018-03-14 13:03:42 -0700 | [diff] [blame] | 471 | switch (backDisposition) { |
| 472 | case InputMethodService.BACK_DISPOSITION_DEFAULT: |
| 473 | case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS: |
| 474 | case InputMethodService.BACK_DISPOSITION_WILL_DISMISS: |
| 475 | if (imeShown) { |
| 476 | hints |= NAVIGATION_HINT_BACK_ALT; |
| 477 | } else { |
| 478 | hints &= ~NAVIGATION_HINT_BACK_ALT; |
| 479 | } |
| 480 | break; |
| 481 | case InputMethodService.BACK_DISPOSITION_ADJUST_NOTHING: |
| 482 | hints &= ~NAVIGATION_HINT_BACK_ALT; |
| 483 | break; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 484 | } |
| 485 | if (showImeSwitcher) { |
| 486 | hints |= NAVIGATION_HINT_IME_SHOWN; |
| 487 | } else { |
| 488 | hints &= ~NAVIGATION_HINT_IME_SHOWN; |
| 489 | } |
| 490 | if (hints == mNavigationIconHints) return; |
| 491 | |
| 492 | mNavigationIconHints = hints; |
| 493 | |
| 494 | if (mNavigationBarView != null) { |
| 495 | mNavigationBarView.setNavigationIconHints(hints); |
| 496 | } |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 497 | checkBarModes(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | @Override |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 501 | public void setWindowState( |
| 502 | int displayId, @WindowType int window, @WindowVisibleState int state) { |
| 503 | if (displayId == mDisplayId |
| 504 | && mNavigationBarView != null |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 505 | && window == StatusBarManager.WINDOW_NAVIGATION_BAR |
| 506 | && mNavigationBarWindowState != state) { |
| 507 | mNavigationBarWindowState = state; |
| 508 | if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state)); |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 509 | |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 510 | updateSystemUiStateFlags(-1); |
Winson Chung | 2102ae8 | 2019-06-19 13:15:24 -0700 | [diff] [blame] | 511 | mNavigationBarView.setWindowVisible(isNavBarWindowVisible()); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 515 | @Override |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 516 | public void onRotationProposal(final int rotation, boolean isValid) { |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 517 | final int winRotation = mNavigationBarView.getDisplay().getRotation(); |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 518 | final boolean rotateSuggestionsDisabled = RotationButtonController |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 519 | .hasDisable2RotateSuggestionFlag(mDisabledFlags2); |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 520 | final RotationButtonController rotationButtonController = |
| 521 | mNavigationBarView.getRotationButtonController(); |
| 522 | final RotationButton rotationButton = rotationButtonController.getRotationButton(); |
| 523 | |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 524 | if (RotationContextButton.DEBUG_ROTATION) { |
Mike Digman | 3e33da6 | 2018-03-14 16:25:11 -0700 | [diff] [blame] | 525 | Log.v(TAG, "onRotationProposal proposedRotation=" + Surface.rotationToString(rotation) |
| 526 | + ", winRotation=" + Surface.rotationToString(winRotation) |
| 527 | + ", isValid=" + isValid + ", mNavBarWindowState=" |
| 528 | + StatusBarManager.windowStateToString(mNavigationBarWindowState) |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 529 | + ", rotateSuggestionsDisabled=" + rotateSuggestionsDisabled |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 530 | + ", isRotateButtonVisible=" + (mNavigationBarView == null ? "null" |
| 531 | : rotationButton.isVisible())); |
Mike Digman | 3e33da6 | 2018-03-14 16:25:11 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 534 | // Respect the disabled flag, no need for action as flag change callback will handle hiding |
| 535 | if (rotateSuggestionsDisabled) return; |
| 536 | |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 537 | rotationButtonController.onRotationProposal(rotation, winRotation, isValid); |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 540 | /** Restores the appearance and the transient saved state to {@link NavigationBarFragment}. */ |
| 541 | public void restoreAppearanceAndTransientState() { |
| 542 | final int barMode = barMode(mTransientShown, mAppearance); |
| 543 | mNavigationBarMode = barMode; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 544 | checkNavBarModes(); |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 545 | mAutoHideController.touchAutoHide(); |
Andrii Kulian | 3ddd7de | 2018-10-10 00:33:19 -0700 | [diff] [blame] | 546 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 547 | mLightBarController.onNavigationBarAppearanceChanged(mAppearance, true /* nbModeChanged */, |
| 548 | barMode, false /* navbarColorManagedByIme */); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | @Override |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 552 | public void onSystemBarAppearanceChanged(int displayId, @Appearance int appearance, |
| 553 | AppearanceRegion[] appearanceRegions, boolean navbarColorManagedByIme) { |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 554 | if (displayId != mDisplayId) { |
| 555 | return; |
| 556 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 557 | boolean nbModeChanged = false; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 558 | if (mAppearance != appearance) { |
| 559 | mAppearance = appearance; |
| 560 | if (getView() == null) { |
| 561 | return; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 562 | } |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 563 | nbModeChanged = updateBarMode(barMode(mTransientShown, appearance)); |
Jorim Jaggi | cb1b848 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 564 | } |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 565 | mLightBarController.onNavigationBarAppearanceChanged(appearance, nbModeChanged, |
| 566 | mNavigationBarMode, navbarColorManagedByIme); |
Jorim Jaggi | cb1b848 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 567 | } |
| 568 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 569 | @Override |
| 570 | public void showTransient(int displayId, @InternalInsetType int[] types) { |
| 571 | if (displayId != mDisplayId) { |
| 572 | return; |
Ioannis Ilkos | 8cca141 | 2019-10-17 09:38:00 +0000 | [diff] [blame] | 573 | } |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 574 | if (!containsType(types, TYPE_NAVIGATION_BAR)) { |
| 575 | return; |
| 576 | } |
| 577 | if (!mTransientShown) { |
| 578 | mTransientShown = true; |
| 579 | handleTransientChanged(); |
| 580 | } |
Ioannis Ilkos | 8cca141 | 2019-10-17 09:38:00 +0000 | [diff] [blame] | 581 | } |
| 582 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 583 | @Override |
| 584 | public void abortTransient(int displayId, @InternalInsetType int[] types) { |
| 585 | if (displayId != mDisplayId) { |
| 586 | return; |
| 587 | } |
| 588 | if (!containsType(types, TYPE_NAVIGATION_BAR)) { |
| 589 | return; |
| 590 | } |
| 591 | clearTransient(); |
| 592 | } |
| 593 | |
| 594 | void clearTransient() { |
| 595 | if (mTransientShown) { |
| 596 | mTransientShown = false; |
| 597 | handleTransientChanged(); |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | private void handleTransientChanged() { |
| 602 | if (getView() == null) { |
| 603 | return; |
| 604 | } |
| 605 | if (mNavigationBarView != null) { |
| 606 | mNavigationBarView.onTransientStateChanged(mTransientShown); |
| 607 | } |
| 608 | final int barMode = barMode(mTransientShown, mAppearance); |
| 609 | if (updateBarMode(barMode)) { |
| 610 | mLightBarController.onNavigationBarModeChanged(barMode); |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | // Returns true if the bar mode is changed. |
| 615 | private boolean updateBarMode(int barMode) { |
| 616 | if (mNavigationBarMode != barMode) { |
| 617 | if (mNavigationBarMode == MODE_TRANSPARENT |
| 618 | || mNavigationBarMode == MODE_LIGHTS_OUT_TRANSPARENT) { |
| 619 | mNavigationBarView.hideRecentsOnboarding(); |
| 620 | } |
| 621 | mNavigationBarMode = barMode; |
| 622 | checkNavBarModes(); |
| 623 | mAutoHideController.touchAutoHide(); |
| 624 | return true; |
| 625 | } |
| 626 | return false; |
| 627 | } |
| 628 | |
| 629 | private static @TransitionMode int barMode(boolean isTransient, int appearance) { |
| 630 | final int lightsOutOpaque = APPEARANCE_LOW_PROFILE_BARS | APPEARANCE_OPAQUE_SIDE_BARS; |
| 631 | if (isTransient) { |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 632 | return MODE_SEMI_TRANSPARENT; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 633 | } else if ((appearance & lightsOutOpaque) == lightsOutOpaque) { |
Ioannis Ilkos | 8cca141 | 2019-10-17 09:38:00 +0000 | [diff] [blame] | 634 | return MODE_LIGHTS_OUT; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 635 | } else if ((appearance & APPEARANCE_LOW_PROFILE_BARS) != 0) { |
| 636 | return MODE_LIGHTS_OUT_TRANSPARENT; |
| 637 | } else if ((appearance & APPEARANCE_OPAQUE_SIDE_BARS) != 0) { |
Ioannis Ilkos | 8cca141 | 2019-10-17 09:38:00 +0000 | [diff] [blame] | 638 | return MODE_OPAQUE; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 639 | } else { |
| 640 | return MODE_TRANSPARENT; |
Andrii Kulian | 3ddd7de | 2018-10-10 00:33:19 -0700 | [diff] [blame] | 641 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | @Override |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 645 | public void disable(int displayId, int state1, int state2, boolean animate) { |
| 646 | if (displayId != mDisplayId) { |
| 647 | return; |
| 648 | } |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 649 | // Navigation bar flags are in both state1 and state2. |
| 650 | final int masked = state1 & (StatusBarManager.DISABLE_HOME |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 651 | | StatusBarManager.DISABLE_RECENT |
| 652 | | StatusBarManager.DISABLE_BACK |
| 653 | | StatusBarManager.DISABLE_SEARCH); |
| 654 | if (masked != mDisabledFlags1) { |
| 655 | mDisabledFlags1 = masked; |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 656 | if (mNavigationBarView != null) { |
| 657 | mNavigationBarView.setDisabledFlags(state1); |
| 658 | } |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 659 | updateScreenPinningGestures(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 660 | } |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 661 | |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 662 | // Only default display supports rotation suggestions. |
| 663 | if (mIsOnDefaultDisplay) { |
| 664 | final int masked2 = state2 & (StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS); |
| 665 | if (masked2 != mDisabledFlags2) { |
| 666 | mDisabledFlags2 = masked2; |
| 667 | setDisabled2Flags(masked2); |
| 668 | } |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | |
| 672 | private void setDisabled2Flags(int state2) { |
| 673 | // Method only called on change of disable2 flags |
Evan Laird | b8b717f | 2018-10-25 14:08:32 -0400 | [diff] [blame] | 674 | if (mNavigationBarView != null) { |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 675 | mNavigationBarView.getRotationButtonController().onDisable2FlagChanged(state2); |
Evan Laird | b8b717f | 2018-10-25 14:08:32 -0400 | [diff] [blame] | 676 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 677 | } |
| 678 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 679 | // ----- Internal stuff ----- |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 680 | |
| 681 | private void refreshLayout(int layoutDirection) { |
| 682 | if (mNavigationBarView != null) { |
| 683 | mNavigationBarView.setLayoutDirection(layoutDirection); |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | private boolean shouldDisableNavbarGestures() { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 688 | return !mDeviceProvisionedController.isDeviceProvisioned() |
Matthew Ng | fee0b5b | 2018-02-21 15:38:21 -0800 | [diff] [blame] | 689 | || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | private void repositionNavigationBar() { |
| 693 | if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return; |
| 694 | |
| 695 | prepareNavigationBarView(); |
| 696 | |
| 697 | mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(), |
| 698 | ((View) mNavigationBarView.getParent()).getLayoutParams()); |
| 699 | } |
| 700 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 701 | private void updateScreenPinningGestures() { |
| 702 | if (mNavigationBarView == null) { |
| 703 | return; |
| 704 | } |
| 705 | |
| 706 | // Change the cancel pin gesture to home and back if recents button is invisible |
| 707 | boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 708 | ButtonDispatcher backButton = mNavigationBarView.getBackButton(); |
| 709 | if (recentsVisible) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 710 | backButton.setOnLongClickListener(this::onLongPressBackRecents); |
| 711 | } else { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 712 | backButton.setOnLongClickListener(this::onLongPressBackHome); |
| 713 | } |
| 714 | } |
| 715 | |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 716 | private void notifyNavigationBarScreenOn() { |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 717 | mNavigationBarView.updateNavButtonIcons(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | private void prepareNavigationBarView() { |
| 721 | mNavigationBarView.reorient(); |
| 722 | |
| 723 | ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton(); |
| 724 | recentsButton.setOnClickListener(this::onRecentsClick); |
| 725 | recentsButton.setOnTouchListener(this::onRecentsTouch); |
| 726 | recentsButton.setLongClickable(true); |
| 727 | recentsButton.setOnLongClickListener(this::onLongPressBackRecents); |
| 728 | |
| 729 | ButtonDispatcher backButton = mNavigationBarView.getBackButton(); |
| 730 | backButton.setLongClickable(true); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 731 | |
| 732 | ButtonDispatcher homeButton = mNavigationBarView.getHomeButton(); |
| 733 | homeButton.setOnTouchListener(this::onHomeTouch); |
Matthew Ng | fee0b5b | 2018-02-21 15:38:21 -0800 | [diff] [blame] | 734 | homeButton.setOnLongClickListener(this::onHomeLongClick); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 735 | |
| 736 | ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton(); |
| 737 | accessibilityButton.setOnClickListener(this::onAccessibilityClick); |
| 738 | accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick); |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 739 | updateAccessibilityServicesState(mAccessibilityManager); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 740 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 741 | updateScreenPinningGestures(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | private boolean onHomeTouch(View v, MotionEvent event) { |
| 745 | if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) { |
| 746 | return true; |
| 747 | } |
| 748 | // If an incoming call is ringing, HOME is totally disabled. |
| 749 | // (The user is already on the InCallUI at this point, |
| 750 | // and his ONLY options are to answer or reject the call.) |
| 751 | switch (event.getAction()) { |
| 752 | case MotionEvent.ACTION_DOWN: |
| 753 | mHomeBlockedThisTouch = false; |
| 754 | TelecomManager telecomManager = |
| 755 | getContext().getSystemService(TelecomManager.class); |
| 756 | if (telecomManager != null && telecomManager.isRinging()) { |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 757 | if (mStatusBarLazy.get().isKeyguardShowing()) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 758 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " + |
| 759 | "No heads up"); |
| 760 | mHomeBlockedThisTouch = true; |
| 761 | return true; |
| 762 | } |
| 763 | } |
| 764 | break; |
| 765 | case MotionEvent.ACTION_UP: |
| 766 | case MotionEvent.ACTION_CANCEL: |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 767 | mStatusBarLazy.get().awakenDreams(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 768 | break; |
| 769 | } |
| 770 | return false; |
| 771 | } |
| 772 | |
| 773 | private void onVerticalChanged(boolean isVertical) { |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 774 | mStatusBarLazy.get().setQsScrimEnabled(!isVertical); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | private boolean onNavigationTouch(View v, MotionEvent event) { |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 778 | mAutoHideController.checkUserAutoHide(event); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 779 | return false; |
| 780 | } |
| 781 | |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 782 | @VisibleForTesting |
| 783 | boolean onHomeLongClick(View v) { |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 784 | if (!mNavigationBarView.isRecentsButtonVisible() |
| 785 | && ActivityManagerWrapper.getInstance().isScreenPinningActive()) { |
Matthew Ng | fee0b5b | 2018-02-21 15:38:21 -0800 | [diff] [blame] | 786 | return onLongPressBackHome(v); |
| 787 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 788 | if (shouldDisableNavbarGestures()) { |
| 789 | return false; |
| 790 | } |
Mike Digman | c94759d | 2018-01-23 11:01:21 -0800 | [diff] [blame] | 791 | mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS); |
Govinda Wasserman | 24ff306 | 2019-04-19 09:42:53 -0400 | [diff] [blame] | 792 | Bundle args = new Bundle(); |
| 793 | args.putInt( |
| 794 | AssistManager.INVOCATION_TYPE_KEY, AssistManager.INVOCATION_HOME_BUTTON_LONG_PRESS); |
| 795 | mAssistManager.startAssist(args); |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 796 | mStatusBarLazy.get().awakenDreams(); |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 797 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 798 | if (mNavigationBarView != null) { |
| 799 | mNavigationBarView.abortCurrentGesture(); |
| 800 | } |
| 801 | return true; |
| 802 | } |
| 803 | |
| 804 | // additional optimization when we have software system buttons - start loading the recent |
| 805 | // tasks on touch down |
| 806 | private boolean onRecentsTouch(View v, MotionEvent event) { |
| 807 | int action = event.getAction() & MotionEvent.ACTION_MASK; |
| 808 | if (action == MotionEvent.ACTION_DOWN) { |
| 809 | mCommandQueue.preloadRecentApps(); |
| 810 | } else if (action == MotionEvent.ACTION_CANCEL) { |
| 811 | mCommandQueue.cancelPreloadRecentApps(); |
| 812 | } else if (action == MotionEvent.ACTION_UP) { |
| 813 | if (!v.isPressed()) { |
| 814 | mCommandQueue.cancelPreloadRecentApps(); |
| 815 | } |
| 816 | } |
| 817 | return false; |
| 818 | } |
| 819 | |
| 820 | private void onRecentsClick(View v) { |
| 821 | if (LatencyTracker.isEnabled(getContext())) { |
| 822 | LatencyTracker.getInstance(getContext()).onActionStart( |
| 823 | LatencyTracker.ACTION_TOGGLE_RECENTS); |
| 824 | } |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 825 | mStatusBarLazy.get().awakenDreams(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 826 | mCommandQueue.toggleRecentApps(); |
| 827 | } |
| 828 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 829 | private boolean onLongPressBackHome(View v) { |
| 830 | return onLongPressNavigationButtons(v, R.id.back, R.id.home); |
| 831 | } |
| 832 | |
| 833 | private boolean onLongPressBackRecents(View v) { |
| 834 | return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps); |
| 835 | } |
| 836 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 837 | /** |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 838 | * This handles long-press of both back and recents/home. Back is the common button with |
| 839 | * combination of recents if it is visible or home if recents is invisible. |
| 840 | * They are handled together to capture them both being long-pressed |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 841 | * at the same time to exit screen pinning (lock task). |
| 842 | * |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 843 | * When accessibility mode is on, only a long-press from recents/home |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 844 | * is required to exit. |
| 845 | * |
| 846 | * In all other circumstances we try to pass through long-press events |
| 847 | * for Back, so that apps can still use it. Which can be from two things. |
| 848 | * 1) Not currently in screen pinning (lock task). |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 849 | * 2) Back is long-pressed without recents/home. |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 850 | */ |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 851 | private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 852 | try { |
| 853 | boolean sendBackLongPress = false; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 854 | IActivityTaskManager activityManager = ActivityTaskManager.getService(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 855 | boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled(); |
| 856 | boolean inLockTaskMode = activityManager.isInLockTaskMode(); |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 857 | boolean stopLockTaskMode = false; |
| 858 | try { |
| 859 | if (inLockTaskMode && !touchExplorationEnabled) { |
| 860 | long time = System.currentTimeMillis(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 861 | |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 862 | // If we recently long-pressed the other button then they were |
| 863 | // long-pressed 'together' |
| 864 | if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) { |
| 865 | stopLockTaskMode = true; |
| 866 | return true; |
| 867 | } else if (v.getId() == btnId1) { |
| 868 | ButtonDispatcher button = btnId2 == R.id.recent_apps |
| 869 | ? mNavigationBarView.getRecentsButton() |
| 870 | : mNavigationBarView.getHomeButton(); |
| 871 | if (!button.getCurrentView().isPressed()) { |
| 872 | // If we aren't pressing recents/home right now then they presses |
| 873 | // won't be together, so send the standard long-press action. |
| 874 | sendBackLongPress = true; |
| 875 | } |
| 876 | } |
| 877 | mLastLockToAppLongPress = time; |
| 878 | } else { |
| 879 | // If this is back still need to handle sending the long-press event. |
| 880 | if (v.getId() == btnId1) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 881 | sendBackLongPress = true; |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 882 | } else if (touchExplorationEnabled && inLockTaskMode) { |
| 883 | // When in accessibility mode a long press that is recents/home (not back) |
| 884 | // should stop lock task. |
| 885 | stopLockTaskMode = true; |
| 886 | return true; |
| 887 | } else if (v.getId() == btnId2) { |
| 888 | return btnId2 == R.id.recent_apps |
| 889 | ? onLongPressRecents() |
| 890 | : onHomeLongClick( |
| 891 | mNavigationBarView.getHomeButton().getCurrentView()); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 892 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 893 | } |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 894 | } finally { |
| 895 | if (stopLockTaskMode) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 896 | activityManager.stopSystemLockTaskMode(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 897 | // When exiting refresh disabled flags. |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 898 | mNavigationBarView.updateNavButtonIcons(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 899 | } |
| 900 | } |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 901 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 902 | if (sendBackLongPress) { |
| 903 | KeyButtonView keyButtonView = (KeyButtonView) v; |
| 904 | keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS); |
| 905 | keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 906 | return true; |
| 907 | } |
| 908 | } catch (RemoteException e) { |
| 909 | Log.d(TAG, "Unable to reach activity manager", e); |
| 910 | } |
| 911 | return false; |
| 912 | } |
| 913 | |
| 914 | private boolean onLongPressRecents() { |
Dave Mankoff | ae3b432 | 2019-11-05 19:48:24 -0500 | [diff] [blame] | 915 | if (mRecentsOptional.isPresent() || !ActivityTaskManager.supportsMultiWindow(getContext()) |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 916 | || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible() |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 917 | || ActivityManager.isLowRamDeviceStatic() |
Winson Chung | 074c434 | 2018-03-26 17:27:19 -0700 | [diff] [blame] | 918 | // If we are connected to the overview service, then disable the recents button |
| 919 | || mOverviewProxyService.getProxy() != null) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 920 | return false; |
| 921 | } |
| 922 | |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 923 | return mStatusBarLazy.get().toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 924 | MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS); |
| 925 | } |
| 926 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 927 | private void onAccessibilityClick(View v) { |
Jackal Guo | 8b72993 | 2018-10-19 18:02:51 +0800 | [diff] [blame] | 928 | final Display display = v.getDisplay(); |
| 929 | mAccessibilityManager.notifyAccessibilityButtonClicked( |
| 930 | display != null ? display.getDisplayId() : Display.DEFAULT_DISPLAY); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | private boolean onAccessibilityLongClick(View v) { |
Casey Burkhardt | 5e8b980 | 2017-03-24 10:07:20 -0700 | [diff] [blame] | 934 | Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON); |
| 935 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 936 | v.getContext().startActivityAsUser(intent, UserHandle.CURRENT); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 937 | return true; |
| 938 | } |
| 939 | |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 940 | private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) { |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 941 | boolean[] feedbackEnabled = new boolean[1]; |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 942 | int a11yFlags = getA11yButtonState(feedbackEnabled); |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 943 | |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 944 | boolean clickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_CLICKABLE) != 0; |
| 945 | boolean longClickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE) != 0; |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 946 | mNavigationBarView.setAccessibilityButtonState(clickable, longClickable); |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 947 | |
| 948 | updateSystemUiStateFlags(a11yFlags); |
| 949 | } |
| 950 | |
| 951 | public void updateSystemUiStateFlags(int a11yFlags) { |
| 952 | if (a11yFlags < 0) { |
| 953 | a11yFlags = getA11yButtonState(null); |
| 954 | } |
| 955 | boolean clickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_CLICKABLE) != 0; |
| 956 | boolean longClickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE) != 0; |
Vinit Nayak | 59b114e6 | 2019-08-12 11:50:00 -0700 | [diff] [blame] | 957 | |
| 958 | mSysUiFlagsContainer.setFlag(SYSUI_STATE_A11Y_BUTTON_CLICKABLE, clickable) |
| 959 | .setFlag(SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE, longClickable) |
| 960 | .setFlag(SYSUI_STATE_NAV_BAR_HIDDEN, !isNavBarWindowVisible()) |
| 961 | .commitUpdate(mDisplayId); |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | /** |
| 965 | * Returns the system UI flags corresponding the the current accessibility button state |
| 966 | * @param outFeedbackEnabled if non-null, sets it to true if accessibility feedback is enabled. |
| 967 | */ |
| 968 | public int getA11yButtonState(@Nullable boolean[] outFeedbackEnabled) { |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 969 | int requestingServices = 0; |
| 970 | try { |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 971 | if (Settings.Secure.getIntForUser(mContentResolver, |
| 972 | Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, |
| 973 | UserHandle.USER_CURRENT) == 1) { |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 974 | requestingServices++; |
| 975 | } |
| 976 | } catch (Settings.SettingNotFoundException e) { |
| 977 | } |
| 978 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 979 | boolean feedbackEnabled = false; |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 980 | // AccessibilityManagerService resolves services for the current user since the local |
| 981 | // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 982 | final List<AccessibilityServiceInfo> services = |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 983 | mAccessibilityManager.getEnabledAccessibilityServiceList( |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 984 | AccessibilityServiceInfo.FEEDBACK_ALL_MASK); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 985 | for (int i = services.size() - 1; i >= 0; --i) { |
| 986 | AccessibilityServiceInfo info = services.get(i); |
| 987 | if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) { |
| 988 | requestingServices++; |
| 989 | } |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 990 | |
| 991 | if (info.feedbackType != 0 && info.feedbackType != |
| 992 | AccessibilityServiceInfo.FEEDBACK_GENERIC) { |
| 993 | feedbackEnabled = true; |
| 994 | } |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 995 | } |
| 996 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 997 | if (outFeedbackEnabled != null) { |
| 998 | outFeedbackEnabled[0] = feedbackEnabled; |
| 999 | } |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 1000 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 1001 | return (requestingServices >= 1 ? SYSUI_STATE_A11Y_BUTTON_CLICKABLE : 0) |
| 1002 | | (requestingServices >= 2 ? SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE : 0); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1003 | } |
| 1004 | |
Matthew Ng | cf71ead | 2019-04-19 14:24:59 -0700 | [diff] [blame] | 1005 | private void sendAssistantAvailability(boolean available) { |
| 1006 | if (mOverviewProxyService.getProxy() != null) { |
| 1007 | try { |
| 1008 | mOverviewProxyService.getProxy().onAssistantAvailable(available |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 1009 | && QuickStepContract.isGesturalMode(mNavBarMode)); |
Matthew Ng | cf71ead | 2019-04-19 14:24:59 -0700 | [diff] [blame] | 1010 | } catch (RemoteException e) { |
| 1011 | Log.w(TAG, "Unable to send assistant availability data to launcher"); |
| 1012 | } |
| 1013 | } |
| 1014 | } |
| 1015 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1016 | // ----- Methods that DisplayNavigationBarController talks to ----- |
| 1017 | |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 1018 | /** Applies auto dimming animation on navigation bar when touched. */ |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1019 | public void touchAutoDim() { |
| 1020 | getBarTransitions().setAutoDim(false); |
| 1021 | mHandler.removeCallbacks(mAutoDim); |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 1022 | int state = mStatusBarStateController.getState(); |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1023 | if (state != StatusBarState.KEYGUARD && state != StatusBarState.SHADE_LOCKED) { |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 1024 | mHandler.postDelayed(mAutoDim, AUTODIM_TIMEOUT_MS); |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1025 | } |
| 1026 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1027 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1028 | public void setLightBarController(LightBarController lightBarController) { |
| 1029 | mLightBarController = lightBarController; |
| 1030 | mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController()); |
| 1031 | } |
| 1032 | |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 1033 | /** Sets {@link AutoHideController} to the navigation bar. */ |
| 1034 | public void setAutoHideController(AutoHideController autoHideController) { |
| 1035 | mAutoHideController = autoHideController; |
| 1036 | mAutoHideController.setNavigationBar(this); |
| 1037 | } |
| 1038 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 1039 | boolean isTransientShown() { |
| 1040 | return mTransientShown; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1041 | } |
| 1042 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1043 | private void checkBarModes() { |
| 1044 | // We only have status bar on default display now. |
| 1045 | if (mIsOnDefaultDisplay) { |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 1046 | mStatusBarLazy.get().checkBarModes(); |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1047 | } else { |
| 1048 | checkNavBarModes(); |
| 1049 | } |
| 1050 | } |
| 1051 | |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 1052 | public boolean isNavBarWindowVisible() { |
| 1053 | return mNavigationBarWindowState == WINDOW_STATE_SHOWING; |
| 1054 | } |
| 1055 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1056 | /** |
| 1057 | * Checks current navigation bar mode and make transitions. |
| 1058 | */ |
| 1059 | public void checkNavBarModes() { |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 1060 | final boolean anim = mStatusBarLazy.get().isDeviceInteractive() |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1061 | && mNavigationBarWindowState != WINDOW_STATE_HIDDEN; |
| 1062 | mNavigationBarView.getBarTransitions().transitionTo(mNavigationBarMode, anim); |
| 1063 | } |
| 1064 | |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 1065 | @Override |
| 1066 | public void onNavigationModeChanged(int mode) { |
| 1067 | mNavBarMode = mode; |
Winson Chung | 30c6260 | 2019-05-09 13:34:48 -0700 | [diff] [blame] | 1068 | updateScreenPinningGestures(); |
Winson Chung | 46d10aa | 2019-05-16 12:05:04 -0700 | [diff] [blame] | 1069 | |
| 1070 | // Workaround for b/132825155, for secondary users, we currently don't receive configuration |
| 1071 | // changes on overlay package change since SystemUI runs for the system user. In this case, |
| 1072 | // trigger a new configuration change to ensure that the nav bar is updated in the same way. |
| 1073 | int userId = ActivityManagerWrapper.getInstance().getCurrentUserId(); |
| 1074 | if (userId != UserHandle.USER_SYSTEM) { |
| 1075 | mHandler.post(() -> { |
| 1076 | FragmentHostManager fragmentHost = FragmentHostManager.get(mNavigationBarView); |
| 1077 | fragmentHost.reloadFragments(); |
| 1078 | }); |
| 1079 | } |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1082 | public void disableAnimationsDuringHide(long delay) { |
| 1083 | mNavigationBarView.setLayoutTransitionsEnabled(false); |
| 1084 | mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true), |
| 1085 | delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE); |
| 1086 | } |
| 1087 | |
shawnlin | 87af538 | 2019-09-13 14:13:13 +0800 | [diff] [blame] | 1088 | @Nullable |
| 1089 | public AssistHandleViewController getAssistHandlerViewController() { |
| 1090 | return mAssistHandlerViewController; |
| 1091 | } |
| 1092 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1093 | /** |
| 1094 | * Performs transitions on navigation bar. |
| 1095 | * |
| 1096 | * @param barMode transition bar mode. |
| 1097 | * @param animate shows animations if {@code true}. |
| 1098 | */ |
| 1099 | public void transitionTo(@TransitionMode int barMode, boolean animate) { |
| 1100 | getBarTransitions().transitionTo(barMode, animate); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1101 | } |
| 1102 | |
James O'Leary | 4335c70 | 2019-05-29 12:38:51 -0400 | [diff] [blame] | 1103 | public NavigationBarTransitions getBarTransitions() { |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1104 | return mNavigationBarView.getBarTransitions(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | public void finishBarAnimations() { |
| 1108 | mNavigationBarView.getBarTransitions().finishAnimations(); |
| 1109 | } |
| 1110 | |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 1111 | private final AccessibilityServicesStateChangeListener mAccessibilityListener = |
| 1112 | this::updateAccessibilityServicesState; |
| 1113 | |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 1114 | private class MagnificationContentObserver extends ContentObserver { |
| 1115 | |
| 1116 | public MagnificationContentObserver(Handler handler) { |
| 1117 | super(handler); |
| 1118 | } |
| 1119 | |
| 1120 | @Override |
| 1121 | public void onChange(boolean selfChange) { |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 1122 | NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 1126 | private final Consumer<Integer> mRotationWatcher = rotation -> { |
| 1127 | if (mNavigationBarView != null |
| 1128 | && mNavigationBarView.needsReorient(rotation)) { |
| 1129 | repositionNavigationBar(); |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 1130 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1131 | }; |
| 1132 | |
| 1133 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 1134 | @Override |
| 1135 | public void onReceive(Context context, Intent intent) { |
| 1136 | String action = intent.getAction(); |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 1137 | if (Intent.ACTION_SCREEN_OFF.equals(action) |
| 1138 | || Intent.ACTION_SCREEN_ON.equals(action)) { |
| 1139 | notifyNavigationBarScreenOn(); |
Vinit Nayak | 3f35db5 | 2019-08-08 17:31:48 -0700 | [diff] [blame] | 1140 | mNavigationBarView.onScreenStateChanged(Intent.ACTION_SCREEN_ON.equals(action)); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1141 | } |
Phil Weaver | a858c5f | 2018-04-26 13:27:30 -0700 | [diff] [blame] | 1142 | if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
| 1143 | // The accessibility settings may be different for the new user |
| 1144 | updateAccessibilityServicesState(mAccessibilityManager); |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1145 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1146 | } |
| 1147 | }; |
| 1148 | |
| 1149 | public static View create(Context context, FragmentListener listener) { |
| 1150 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
Charles Chen | b6aff43 | 2018-11-16 20:25:46 +0800 | [diff] [blame] | 1151 | LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, |
| 1152 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1153 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING |
| 1154 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1155 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 1156 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 1157 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH |
| 1158 | | WindowManager.LayoutParams.FLAG_SLIPPERY, |
| 1159 | PixelFormat.TRANSLUCENT); |
| 1160 | lp.token = new Binder(); |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 1161 | lp.setTitle("NavigationBar" + context.getDisplayId()); |
Phil Weaver | 8583ae8 | 2018-02-13 11:01:24 -0800 | [diff] [blame] | 1162 | lp.accessibilityTitle = context.getString(R.string.nav_bar); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1163 | lp.windowAnimations = 0; |
Peiyong Lin | 7504538 | 2019-03-04 19:22:33 -0800 | [diff] [blame] | 1164 | lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1165 | |
| 1166 | View navigationBarView = LayoutInflater.from(context).inflate( |
| 1167 | R.layout.navigation_bar_window, null); |
| 1168 | |
| 1169 | if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView); |
| 1170 | if (navigationBarView == null) return null; |
| 1171 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 1172 | final NavigationBarFragment fragment = FragmentHostManager.get(navigationBarView) |
| 1173 | .create(NavigationBarFragment.class); |
Riddle Hsu | 1960777 | 2018-11-01 18:11:26 +0800 | [diff] [blame] | 1174 | navigationBarView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { |
| 1175 | @Override |
| 1176 | public void onViewAttachedToWindow(View v) { |
| 1177 | final FragmentHostManager fragmentHost = FragmentHostManager.get(v); |
| 1178 | fragmentHost.getFragmentManager().beginTransaction() |
| 1179 | .replace(R.id.navigation_bar_frame, fragment, TAG) |
| 1180 | .commit(); |
| 1181 | fragmentHost.addTagListener(TAG, listener); |
| 1182 | } |
| 1183 | |
| 1184 | @Override |
| 1185 | public void onViewDetachedFromWindow(View v) { |
| 1186 | FragmentHostManager.removeAndDestroy(v); |
| 1187 | } |
| 1188 | }); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1189 | context.getSystemService(WindowManager.class).addView(navigationBarView, lp); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1190 | return navigationBarView; |
| 1191 | } |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 1192 | |
| 1193 | @VisibleForTesting |
| 1194 | int getNavigationIconHints() { |
| 1195 | return mNavigationIconHints; |
| 1196 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1197 | } |