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