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