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