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