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; |
| 19 | import static android.app.StatusBarManager.WINDOW_STATE_SHOWING; |
| 20 | import static android.app.StatusBarManager.windowStateToString; |
| 21 | |
| 22 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 23 | import static com.android.systemui.statusbar.phone.StatusBar.DEBUG_WINDOW_STATE; |
| 24 | import static com.android.systemui.statusbar.phone.StatusBar.dumpBarTransitions; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 25 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 26 | import android.accessibilityservice.AccessibilityServiceInfo; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 27 | import android.animation.Animator; |
| 28 | import android.animation.AnimatorListenerAdapter; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 29 | import android.animation.ObjectAnimator; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 30 | import android.annotation.Nullable; |
| 31 | import android.app.ActivityManager; |
| 32 | import android.app.ActivityManagerNative; |
| 33 | import android.app.Fragment; |
| 34 | import android.app.IActivityManager; |
| 35 | import android.app.StatusBarManager; |
| 36 | import android.content.BroadcastReceiver; |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 37 | import android.content.ContentResolver; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 38 | import android.content.Context; |
| 39 | import android.content.Intent; |
| 40 | import android.content.IntentFilter; |
| 41 | import android.content.res.Configuration; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 42 | import android.database.ContentObserver; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 43 | import android.graphics.PixelFormat; |
| 44 | import android.graphics.Rect; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 45 | import android.graphics.drawable.AnimatedVectorDrawable; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 46 | import android.inputmethodservice.InputMethodService; |
| 47 | import android.os.Binder; |
| 48 | import android.os.Bundle; |
| 49 | import android.os.Handler; |
| 50 | import android.os.IBinder; |
| 51 | import android.os.Message; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 52 | import android.os.RemoteException; |
| 53 | import android.os.UserHandle; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 54 | import android.provider.Settings; |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 55 | import android.support.annotation.VisibleForTesting; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 56 | import android.telecom.TelecomManager; |
| 57 | import android.text.TextUtils; |
| 58 | import android.util.Log; |
| 59 | import android.view.IRotationWatcher.Stub; |
| 60 | import android.view.KeyEvent; |
| 61 | import android.view.LayoutInflater; |
| 62 | import android.view.MotionEvent; |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame^] | 63 | import android.view.Surface; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 64 | import android.view.View; |
| 65 | import android.view.ViewGroup; |
| 66 | import android.view.WindowManager; |
| 67 | import android.view.WindowManager.LayoutParams; |
| 68 | import android.view.WindowManagerGlobal; |
| 69 | import android.view.accessibility.AccessibilityEvent; |
| 70 | import android.view.accessibility.AccessibilityManager; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 71 | import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 72 | |
| 73 | import com.android.internal.logging.MetricsLogger; |
| 74 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | ea03be1 | 2017-12-04 11:08:41 -0500 | [diff] [blame] | 75 | import com.android.internal.util.LatencyTracker; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 76 | import com.android.systemui.Dependency; |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 77 | import com.android.systemui.OverviewProxyService; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 78 | import com.android.systemui.Interpolators; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 79 | import com.android.systemui.R; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 80 | import com.android.systemui.SysUiServiceProvider; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 81 | import com.android.systemui.assist.AssistManager; |
| 82 | import com.android.systemui.fragments.FragmentHostManager; |
| 83 | import com.android.systemui.fragments.FragmentHostManager.FragmentListener; |
| 84 | import com.android.systemui.recents.Recents; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 85 | import com.android.systemui.recents.misc.SysUiTaskStackChangeListener; |
| 86 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 87 | import com.android.systemui.stackdivider.Divider; |
| 88 | import com.android.systemui.statusbar.CommandQueue; |
| 89 | import com.android.systemui.statusbar.CommandQueue.Callbacks; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 90 | import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 91 | import com.android.systemui.statusbar.policy.KeyButtonDrawable; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 92 | import com.android.systemui.statusbar.policy.KeyButtonView; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 93 | import com.android.systemui.statusbar.policy.RotationLockController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 94 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
| 95 | |
| 96 | import java.io.FileDescriptor; |
| 97 | import java.io.PrintWriter; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 98 | import java.util.List; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 99 | import java.util.Locale; |
| 100 | |
| 101 | /** |
| 102 | * Fragment containing the NavigationBarFragment. Contains logic for what happens |
| 103 | * on clicks and view states of the nav bar. |
| 104 | */ |
| 105 | public class NavigationBarFragment extends Fragment implements Callbacks { |
| 106 | |
Jason Monk | d4afe15 | 2017-05-01 15:37:43 -0400 | [diff] [blame] | 107 | public static final String TAG = "NavigationBar"; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 108 | private static final boolean DEBUG = false; |
| 109 | private static final String EXTRA_DISABLE_STATE = "disabled_state"; |
| 110 | |
| 111 | /** Allow some time inbetween the long press for back and recents. */ |
| 112 | private static final int LOCK_TO_APP_GESTURE_TOLERENCE = 200; |
| 113 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 114 | private static final int BUTTON_FADE_IN_OUT_DURATION_MS = 100; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 115 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 116 | protected NavigationBarView mNavigationBarView = null; |
| 117 | protected AssistManager mAssistManager; |
| 118 | |
| 119 | private int mNavigationBarWindowState = WINDOW_STATE_SHOWING; |
| 120 | |
| 121 | private int mNavigationIconHints = 0; |
| 122 | private int mNavigationBarMode; |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 123 | private boolean mAccessibilityFeedbackEnabled; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 124 | private AccessibilityManager mAccessibilityManager; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 125 | private MagnificationContentObserver mMagnificationObserver; |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 126 | private ContentResolver mContentResolver; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 127 | |
| 128 | private int mDisabledFlags1; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 129 | private StatusBar mStatusBar; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 130 | private Recents mRecents; |
| 131 | private Divider mDivider; |
| 132 | private WindowManager mWindowManager; |
| 133 | private CommandQueue mCommandQueue; |
| 134 | private long mLastLockToAppLongPress; |
| 135 | |
| 136 | private Locale mLocale; |
| 137 | private int mLayoutDirection; |
| 138 | |
| 139 | private int mSystemUiVisibility; |
| 140 | private LightBarController mLightBarController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 141 | |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 142 | private OverviewProxyService mOverviewProxyService; |
| 143 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 144 | public boolean mHomeBlockedThisTouch; |
| 145 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 146 | private int mLastRotationSuggestion; |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 147 | private boolean mHoveringRotationSuggestion; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 148 | private RotationLockController mRotationLockController; |
| 149 | private TaskStackListenerImpl mTaskStackListener; |
| 150 | |
| 151 | private final Runnable mRemoveRotationProposal = () -> setRotateSuggestionButtonState(false); |
| 152 | private Animator mRotateShowAnimator; |
| 153 | private Animator mRotateHideAnimator; |
| 154 | |
| 155 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 156 | // ----- Fragment Lifecycle Callbacks ----- |
| 157 | |
| 158 | @Override |
| 159 | public void onCreate(@Nullable Bundle savedInstanceState) { |
| 160 | super.onCreate(savedInstanceState); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 161 | mCommandQueue = SysUiServiceProvider.getComponent(getContext(), CommandQueue.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 162 | mCommandQueue.addCallbacks(this); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 163 | mStatusBar = SysUiServiceProvider.getComponent(getContext(), StatusBar.class); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 164 | mRecents = SysUiServiceProvider.getComponent(getContext(), Recents.class); |
| 165 | mDivider = SysUiServiceProvider.getComponent(getContext(), Divider.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 166 | mWindowManager = getContext().getSystemService(WindowManager.class); |
| 167 | mAccessibilityManager = getContext().getSystemService(AccessibilityManager.class); |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 168 | Dependency.get(AccessibilityManagerWrapper.class).addCallback( |
| 169 | mAccessibilityListener); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 170 | mContentResolver = getContext().getContentResolver(); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 171 | mMagnificationObserver = new MagnificationContentObserver( |
| 172 | getContext().getMainThreadHandler()); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 173 | mContentResolver.registerContentObserver(Settings.Secure.getUriFor( |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 174 | Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED), false, |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 175 | mMagnificationObserver, UserHandle.USER_ALL); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 176 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 177 | if (savedInstanceState != null) { |
| 178 | mDisabledFlags1 = savedInstanceState.getInt(EXTRA_DISABLE_STATE, 0); |
| 179 | } |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 180 | mAssistManager = Dependency.get(AssistManager.class); |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 181 | mOverviewProxyService = Dependency.get(OverviewProxyService.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 182 | |
| 183 | try { |
| 184 | WindowManagerGlobal.getWindowManagerService() |
Andrii Kulian | 35fa3c2 | 2017-03-11 09:37:28 -0800 | [diff] [blame] | 185 | .watchRotation(mRotationWatcher, getContext().getDisplay().getDisplayId()); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 186 | } catch (RemoteException e) { |
| 187 | throw e.rethrowFromSystemServer(); |
| 188 | } |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 189 | |
| 190 | mRotationLockController = Dependency.get(RotationLockController.class); |
| 191 | |
| 192 | // Register the task stack listener |
| 193 | mTaskStackListener = new TaskStackListenerImpl(); |
| 194 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public void onDestroy() { |
| 199 | super.onDestroy(); |
| 200 | mCommandQueue.removeCallbacks(this); |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 201 | Dependency.get(AccessibilityManagerWrapper.class).removeCallback( |
| 202 | mAccessibilityListener); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 203 | mContentResolver.unregisterContentObserver(mMagnificationObserver); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 204 | try { |
| 205 | WindowManagerGlobal.getWindowManagerService() |
| 206 | .removeRotationWatcher(mRotationWatcher); |
| 207 | } catch (RemoteException e) { |
| 208 | throw e.rethrowFromSystemServer(); |
| 209 | } |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 210 | |
| 211 | // Unregister the task stack listener |
| 212 | ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | @Override |
| 216 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, |
| 217 | Bundle savedInstanceState) { |
| 218 | return inflater.inflate(R.layout.navigation_bar, container, false); |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 223 | super.onViewCreated(view, savedInstanceState); |
| 224 | mNavigationBarView = (NavigationBarView) view; |
| 225 | |
| 226 | mNavigationBarView.setDisabledFlags(mDisabledFlags1); |
| 227 | mNavigationBarView.setComponents(mRecents, mDivider); |
| 228 | mNavigationBarView.setOnVerticalChangedListener(this::onVerticalChanged); |
| 229 | mNavigationBarView.setOnTouchListener(this::onNavigationTouch); |
| 230 | if (savedInstanceState != null) { |
| 231 | mNavigationBarView.getLightTransitionsController().restoreState(savedInstanceState); |
| 232 | } |
| 233 | |
| 234 | prepareNavigationBarView(); |
| 235 | checkNavBarModes(); |
| 236 | |
| 237 | IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); |
| 238 | filter.addAction(Intent.ACTION_SCREEN_ON); |
| 239 | getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null); |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 240 | notifyNavigationBarScreenOn(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public void onDestroyView() { |
| 245 | super.onDestroyView(); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 246 | mNavigationBarView.getLightTransitionsController().destroy(getContext()); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 247 | getContext().unregisterReceiver(mBroadcastReceiver); |
| 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public void onSaveInstanceState(Bundle outState) { |
| 252 | super.onSaveInstanceState(outState); |
| 253 | outState.putInt(EXTRA_DISABLE_STATE, mDisabledFlags1); |
| 254 | if (mNavigationBarView != null) { |
| 255 | mNavigationBarView.getLightTransitionsController().saveState(outState); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public void onConfigurationChanged(Configuration newConfig) { |
| 261 | super.onConfigurationChanged(newConfig); |
| 262 | final Locale locale = getContext().getResources().getConfiguration().locale; |
| 263 | final int ld = TextUtils.getLayoutDirectionFromLocale(locale); |
| 264 | if (!locale.equals(mLocale) || ld != mLayoutDirection) { |
| 265 | if (DEBUG) { |
| 266 | Log.v(TAG, String.format( |
| 267 | "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection, |
| 268 | locale, ld)); |
| 269 | } |
| 270 | mLocale = locale; |
| 271 | mLayoutDirection = ld; |
| 272 | refreshLayout(ld); |
| 273 | } |
| 274 | repositionNavigationBar(); |
| 275 | } |
| 276 | |
| 277 | @Override |
| 278 | public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) { |
| 279 | if (mNavigationBarView != null) { |
| 280 | pw.print(" mNavigationBarWindowState="); |
| 281 | pw.println(windowStateToString(mNavigationBarWindowState)); |
| 282 | pw.print(" mNavigationBarMode="); |
| 283 | pw.println(BarTransitions.modeToString(mNavigationBarMode)); |
| 284 | dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions()); |
| 285 | } |
| 286 | |
| 287 | pw.print(" mNavigationBarView="); |
| 288 | if (mNavigationBarView == null) { |
| 289 | pw.println("null"); |
| 290 | } else { |
| 291 | mNavigationBarView.dump(fd, pw, args); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | // ----- CommandQueue Callbacks ----- |
| 296 | |
| 297 | @Override |
| 298 | public void setImeWindowStatus(IBinder token, int vis, int backDisposition, |
| 299 | boolean showImeSwitcher) { |
| 300 | boolean imeShown = (vis & InputMethodService.IME_VISIBLE) != 0; |
| 301 | int hints = mNavigationIconHints; |
| 302 | if ((backDisposition == InputMethodService.BACK_DISPOSITION_WILL_DISMISS) || imeShown) { |
| 303 | hints |= NAVIGATION_HINT_BACK_ALT; |
| 304 | } else { |
| 305 | hints &= ~NAVIGATION_HINT_BACK_ALT; |
| 306 | } |
| 307 | if (showImeSwitcher) { |
| 308 | hints |= NAVIGATION_HINT_IME_SHOWN; |
| 309 | } else { |
| 310 | hints &= ~NAVIGATION_HINT_IME_SHOWN; |
| 311 | } |
| 312 | if (hints == mNavigationIconHints) return; |
| 313 | |
| 314 | mNavigationIconHints = hints; |
| 315 | |
| 316 | if (mNavigationBarView != null) { |
| 317 | mNavigationBarView.setNavigationIconHints(hints); |
| 318 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 319 | mStatusBar.checkBarModes(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | @Override |
| 323 | public void topAppWindowChanged(boolean showMenu) { |
| 324 | if (mNavigationBarView != null) { |
| 325 | mNavigationBarView.setMenuVisibility(showMenu); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | @Override |
| 330 | public void setWindowState(int window, int state) { |
| 331 | if (mNavigationBarView != null |
| 332 | && window == StatusBarManager.WINDOW_NAVIGATION_BAR |
| 333 | && mNavigationBarWindowState != state) { |
| 334 | mNavigationBarWindowState = state; |
| 335 | if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state)); |
| 336 | } |
| 337 | } |
| 338 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 339 | @Override |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 340 | public void onRotationProposal(final int rotation, boolean isValid) { |
| 341 | // This method will be called on rotation suggestion changes even if the proposed rotation |
| 342 | // is not valid for the top app. Use invalid rotation choices as a signal to remove the |
| 343 | // rotate button if shown. |
| 344 | |
| 345 | if (!isValid) { |
| 346 | setRotateSuggestionButtonState(false); |
| 347 | return; |
| 348 | } |
| 349 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 350 | if (rotation == mWindowManager.getDefaultDisplay().getRotation()) { |
| 351 | // Use this as a signal to remove any current suggestions |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 352 | getView().getHandler().removeCallbacks(mRemoveRotationProposal); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 353 | setRotateSuggestionButtonState(false); |
| 354 | } else { |
| 355 | mLastRotationSuggestion = rotation; // Remember rotation for click |
| 356 | setRotateSuggestionButtonState(true); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 357 | rescheduleRotationTimeout(false); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 361 | private void rescheduleRotationTimeout(final boolean reasonHover) { |
| 362 | // May be called due to a new rotation proposal or a change in hover state |
| 363 | if (reasonHover) { |
| 364 | // Don't reschedule if a hide animator is running |
| 365 | if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) { |
| 366 | return; |
| 367 | } |
| 368 | // Don't reschedule if not visible |
| 369 | if (mNavigationBarView.getRotateSuggestionButton().getVisibility() != View.VISIBLE) { |
| 370 | return; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | Handler h = getView().getHandler(); |
| 375 | h.removeCallbacks(mRemoveRotationProposal); // Stop any pending removal |
| 376 | h.postDelayed(mRemoveRotationProposal, |
| 377 | computeRotationProposalTimeout()); // Schedule timeout |
| 378 | } |
| 379 | |
| 380 | private int computeRotationProposalTimeout() { |
| 381 | if (mAccessibilityFeedbackEnabled) return 20000; |
| 382 | if (mHoveringRotationSuggestion) return 16000; |
| 383 | return 6000; |
| 384 | } |
| 385 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 386 | public void setRotateSuggestionButtonState(final boolean visible) { |
| 387 | setRotateSuggestionButtonState(visible, false); |
| 388 | } |
| 389 | |
| 390 | public void setRotateSuggestionButtonState(final boolean visible, final boolean skipAnim) { |
| 391 | ButtonDispatcher rotBtn = mNavigationBarView.getRotateSuggestionButton(); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 392 | final boolean currentlyVisible = rotBtn.getVisibility() == View.VISIBLE; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 393 | |
| 394 | // Rerun a show animation to indicate change but don't rerun a hide animation |
| 395 | if (!visible && !currentlyVisible) return; |
| 396 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 397 | View currentView = rotBtn.getCurrentView(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 398 | if (currentView == null) return; |
| 399 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 400 | KeyButtonDrawable kbd = rotBtn.getImageDrawable(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 401 | if (kbd == null) return; |
| 402 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 403 | AnimatedVectorDrawable animIcon = null; |
| 404 | if (kbd.getDrawable(0) instanceof AnimatedVectorDrawable) { |
| 405 | animIcon = (AnimatedVectorDrawable) kbd.getDrawable(0); |
| 406 | } |
| 407 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 408 | if (visible) { // Appear and change |
| 409 | rotBtn.setVisibility(View.VISIBLE); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 410 | mNavigationBarView.notifyAccessibilitySubtreeChanged(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 411 | |
| 412 | if (skipAnim) { |
| 413 | currentView.setAlpha(1f); |
| 414 | return; |
| 415 | } |
| 416 | |
| 417 | // Start a new animation if running |
| 418 | if (mRotateShowAnimator != null) mRotateShowAnimator.pause(); |
| 419 | if (mRotateHideAnimator != null) mRotateHideAnimator.pause(); |
| 420 | |
| 421 | ObjectAnimator appearFade = ObjectAnimator.ofFloat(currentView, "alpha", |
| 422 | 0f, 1f); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 423 | appearFade.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 424 | appearFade.setInterpolator(Interpolators.LINEAR); |
| 425 | mRotateShowAnimator = appearFade; |
| 426 | appearFade.start(); |
| 427 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 428 | // Run the rotate icon's animation if it has one |
| 429 | if (animIcon != null) { |
| 430 | animIcon.reset(); |
| 431 | animIcon.start(); |
| 432 | } |
| 433 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 434 | } else { // Hide |
| 435 | |
| 436 | if (skipAnim) { |
| 437 | rotBtn.setVisibility(View.INVISIBLE); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 438 | mNavigationBarView.notifyAccessibilitySubtreeChanged(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 439 | return; |
| 440 | } |
| 441 | |
| 442 | // Don't start any new hide animations if one is running |
| 443 | if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return; |
| 444 | // Pause any active show animations but don't reset the AVD to avoid jumps |
| 445 | if (mRotateShowAnimator != null) mRotateShowAnimator.pause(); |
| 446 | |
| 447 | ObjectAnimator fadeOut = ObjectAnimator.ofFloat(currentView, "alpha", |
| 448 | 0f); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 449 | fadeOut.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 450 | fadeOut.setInterpolator(Interpolators.LINEAR); |
| 451 | fadeOut.addListener(new AnimatorListenerAdapter() { |
| 452 | @Override |
| 453 | public void onAnimationEnd(Animator animation) { |
| 454 | rotBtn.setVisibility(View.INVISIBLE); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 455 | mNavigationBarView.notifyAccessibilitySubtreeChanged(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 456 | } |
| 457 | }); |
| 458 | |
| 459 | mRotateHideAnimator = fadeOut; |
| 460 | fadeOut.start(); |
| 461 | } |
| 462 | } |
| 463 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 464 | // Injected from StatusBar at creation. |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 465 | public void setCurrentSysuiVisibility(int systemUiVisibility) { |
| 466 | mSystemUiVisibility = systemUiVisibility; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 467 | mNavigationBarMode = mStatusBar.computeBarMode(0, mSystemUiVisibility, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 468 | View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT, |
| 469 | View.NAVIGATION_BAR_TRANSPARENT); |
| 470 | checkNavBarModes(); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 471 | mStatusBar.touchAutoHide(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 472 | mLightBarController.onNavigationVisibilityChanged(mSystemUiVisibility, 0 /* mask */, |
| 473 | true /* nbModeChanged */, mNavigationBarMode); |
| 474 | } |
| 475 | |
| 476 | @Override |
| 477 | public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis, |
| 478 | int mask, Rect fullscreenStackBounds, Rect dockedStackBounds) { |
| 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 |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 488 | ? -1 : mStatusBar.computeBarMode(oldVal, newVal, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 489 | View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT, |
| 490 | View.NAVIGATION_BAR_TRANSPARENT); |
| 491 | nbModeChanged = nbMode != -1; |
| 492 | if (nbModeChanged) { |
| 493 | if (mNavigationBarMode != nbMode) { |
| 494 | mNavigationBarMode = nbMode; |
| 495 | checkNavBarModes(); |
| 496 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 497 | mStatusBar.touchAutoHide(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
| 501 | mLightBarController.onNavigationVisibilityChanged(vis, mask, nbModeChanged, |
| 502 | mNavigationBarMode); |
| 503 | } |
| 504 | |
| 505 | @Override |
| 506 | public void disable(int state1, int state2, boolean animate) { |
| 507 | // All navigation bar flags are in state1. |
| 508 | int masked = state1 & (StatusBarManager.DISABLE_HOME |
| 509 | | StatusBarManager.DISABLE_RECENT |
| 510 | | StatusBarManager.DISABLE_BACK |
| 511 | | StatusBarManager.DISABLE_SEARCH); |
| 512 | if (masked != mDisabledFlags1) { |
| 513 | mDisabledFlags1 = masked; |
| 514 | if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state1); |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | // ----- Internal stuffz ----- |
| 519 | |
| 520 | private void refreshLayout(int layoutDirection) { |
| 521 | if (mNavigationBarView != null) { |
| 522 | mNavigationBarView.setLayoutDirection(layoutDirection); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | private boolean shouldDisableNavbarGestures() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 527 | return !mStatusBar.isDeviceProvisioned() |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 528 | || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0 |
| 529 | || mOverviewProxyService.getProxy() != null; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | private void repositionNavigationBar() { |
| 533 | if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return; |
| 534 | |
| 535 | prepareNavigationBarView(); |
| 536 | |
| 537 | mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(), |
| 538 | ((View) mNavigationBarView.getParent()).getLayoutParams()); |
| 539 | } |
| 540 | |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 541 | private void notifyNavigationBarScreenOn() { |
| 542 | mNavigationBarView.notifyScreenOn(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | private void prepareNavigationBarView() { |
| 546 | mNavigationBarView.reorient(); |
| 547 | |
| 548 | ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton(); |
| 549 | recentsButton.setOnClickListener(this::onRecentsClick); |
| 550 | recentsButton.setOnTouchListener(this::onRecentsTouch); |
| 551 | recentsButton.setLongClickable(true); |
| 552 | recentsButton.setOnLongClickListener(this::onLongPressBackRecents); |
| 553 | |
| 554 | ButtonDispatcher backButton = mNavigationBarView.getBackButton(); |
| 555 | backButton.setLongClickable(true); |
| 556 | backButton.setOnLongClickListener(this::onLongPressBackRecents); |
| 557 | |
| 558 | ButtonDispatcher homeButton = mNavigationBarView.getHomeButton(); |
| 559 | homeButton.setOnTouchListener(this::onHomeTouch); |
| 560 | homeButton.setOnLongClickListener(this::onHomeLongClick); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 561 | |
| 562 | ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton(); |
| 563 | accessibilityButton.setOnClickListener(this::onAccessibilityClick); |
| 564 | accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick); |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 565 | updateAccessibilityServicesState(mAccessibilityManager); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 566 | |
| 567 | ButtonDispatcher rotateSuggestionButton = mNavigationBarView.getRotateSuggestionButton(); |
| 568 | rotateSuggestionButton.setOnClickListener(this::onRotateSuggestionClick); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 569 | rotateSuggestionButton.setOnHoverListener(this::onRotateSuggestionHover); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | private boolean onHomeTouch(View v, MotionEvent event) { |
| 573 | if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) { |
| 574 | return true; |
| 575 | } |
| 576 | // If an incoming call is ringing, HOME is totally disabled. |
| 577 | // (The user is already on the InCallUI at this point, |
| 578 | // and his ONLY options are to answer or reject the call.) |
| 579 | switch (event.getAction()) { |
| 580 | case MotionEvent.ACTION_DOWN: |
| 581 | mHomeBlockedThisTouch = false; |
| 582 | TelecomManager telecomManager = |
| 583 | getContext().getSystemService(TelecomManager.class); |
| 584 | if (telecomManager != null && telecomManager.isRinging()) { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 585 | if (mStatusBar.isKeyguardShowing()) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 586 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " + |
| 587 | "No heads up"); |
| 588 | mHomeBlockedThisTouch = true; |
| 589 | return true; |
| 590 | } |
| 591 | } |
| 592 | break; |
| 593 | case MotionEvent.ACTION_UP: |
| 594 | case MotionEvent.ACTION_CANCEL: |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 595 | mStatusBar.awakenDreams(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 596 | break; |
| 597 | } |
| 598 | return false; |
| 599 | } |
| 600 | |
| 601 | private void onVerticalChanged(boolean isVertical) { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 602 | mStatusBar.setQsScrimEnabled(!isVertical); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | private boolean onNavigationTouch(View v, MotionEvent event) { |
Eliot Courtney | cb5d316 | 2017-08-09 16:53:15 +0900 | [diff] [blame] | 606 | mStatusBar.checkUserAutohide(event); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 607 | return false; |
| 608 | } |
| 609 | |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 610 | @VisibleForTesting |
| 611 | boolean onHomeLongClick(View v) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 612 | if (shouldDisableNavbarGestures()) { |
| 613 | return false; |
| 614 | } |
| 615 | MetricsLogger.action(getContext(), MetricsEvent.ACTION_ASSIST_LONG_PRESS); |
| 616 | mAssistManager.startAssist(new Bundle() /* args */); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 617 | mStatusBar.awakenDreams(); |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 618 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 619 | if (mNavigationBarView != null) { |
| 620 | mNavigationBarView.abortCurrentGesture(); |
| 621 | } |
| 622 | return true; |
| 623 | } |
| 624 | |
| 625 | // additional optimization when we have software system buttons - start loading the recent |
| 626 | // tasks on touch down |
| 627 | private boolean onRecentsTouch(View v, MotionEvent event) { |
| 628 | int action = event.getAction() & MotionEvent.ACTION_MASK; |
| 629 | if (action == MotionEvent.ACTION_DOWN) { |
| 630 | mCommandQueue.preloadRecentApps(); |
| 631 | } else if (action == MotionEvent.ACTION_CANCEL) { |
| 632 | mCommandQueue.cancelPreloadRecentApps(); |
| 633 | } else if (action == MotionEvent.ACTION_UP) { |
| 634 | if (!v.isPressed()) { |
| 635 | mCommandQueue.cancelPreloadRecentApps(); |
| 636 | } |
| 637 | } |
| 638 | return false; |
| 639 | } |
| 640 | |
| 641 | private void onRecentsClick(View v) { |
| 642 | if (LatencyTracker.isEnabled(getContext())) { |
| 643 | LatencyTracker.getInstance(getContext()).onActionStart( |
| 644 | LatencyTracker.ACTION_TOGGLE_RECENTS); |
| 645 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 646 | mStatusBar.awakenDreams(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 647 | mCommandQueue.toggleRecentApps(); |
| 648 | } |
| 649 | |
| 650 | /** |
| 651 | * This handles long-press of both back and recents. They are |
| 652 | * handled together to capture them both being long-pressed |
| 653 | * at the same time to exit screen pinning (lock task). |
| 654 | * |
| 655 | * When accessibility mode is on, only a long-press from recents |
| 656 | * is required to exit. |
| 657 | * |
| 658 | * In all other circumstances we try to pass through long-press events |
| 659 | * for Back, so that apps can still use it. Which can be from two things. |
| 660 | * 1) Not currently in screen pinning (lock task). |
| 661 | * 2) Back is long-pressed without recents. |
| 662 | */ |
| 663 | private boolean onLongPressBackRecents(View v) { |
| 664 | try { |
| 665 | boolean sendBackLongPress = false; |
| 666 | IActivityManager activityManager = ActivityManagerNative.getDefault(); |
| 667 | boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled(); |
| 668 | boolean inLockTaskMode = activityManager.isInLockTaskMode(); |
| 669 | if (inLockTaskMode && !touchExplorationEnabled) { |
| 670 | long time = System.currentTimeMillis(); |
| 671 | // If we recently long-pressed the other button then they were |
| 672 | // long-pressed 'together' |
| 673 | if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 674 | activityManager.stopSystemLockTaskMode(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 675 | // When exiting refresh disabled flags. |
| 676 | mNavigationBarView.setDisabledFlags(mDisabledFlags1, true); |
| 677 | return true; |
| 678 | } else if ((v.getId() == R.id.back) |
| 679 | && !mNavigationBarView.getRecentsButton().getCurrentView().isPressed()) { |
| 680 | // If we aren't pressing recents right now then they presses |
| 681 | // won't be together, so send the standard long-press action. |
| 682 | sendBackLongPress = true; |
| 683 | } |
| 684 | mLastLockToAppLongPress = time; |
| 685 | } else { |
| 686 | // If this is back still need to handle sending the long-press event. |
| 687 | if (v.getId() == R.id.back) { |
| 688 | sendBackLongPress = true; |
| 689 | } else if (touchExplorationEnabled && inLockTaskMode) { |
| 690 | // When in accessibility mode a long press that is recents (not back) |
| 691 | // should stop lock task. |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 692 | activityManager.stopSystemLockTaskMode(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 693 | // When exiting refresh disabled flags. |
| 694 | mNavigationBarView.setDisabledFlags(mDisabledFlags1, true); |
| 695 | return true; |
| 696 | } else if (v.getId() == R.id.recent_apps) { |
| 697 | return onLongPressRecents(); |
| 698 | } |
| 699 | } |
| 700 | if (sendBackLongPress) { |
| 701 | KeyButtonView keyButtonView = (KeyButtonView) v; |
| 702 | keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS); |
| 703 | keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 704 | return true; |
| 705 | } |
| 706 | } catch (RemoteException e) { |
| 707 | Log.d(TAG, "Unable to reach activity manager", e); |
| 708 | } |
| 709 | return false; |
| 710 | } |
| 711 | |
| 712 | private boolean onLongPressRecents() { |
Erik Wolsheimer | 9be3a06 | 2017-05-31 14:59:57 -0700 | [diff] [blame] | 713 | if (mRecents == null || !ActivityManager.supportsMultiWindow(getContext()) |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 714 | || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible() |
| 715 | || Recents.getConfiguration().isLowRamDevice) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 716 | return false; |
| 717 | } |
| 718 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 719 | return mStatusBar.toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 720 | MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS); |
| 721 | } |
| 722 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 723 | private void onAccessibilityClick(View v) { |
| 724 | mAccessibilityManager.notifyAccessibilityButtonClicked(); |
| 725 | } |
| 726 | |
| 727 | private boolean onAccessibilityLongClick(View v) { |
Casey Burkhardt | 5e8b980 | 2017-03-24 10:07:20 -0700 | [diff] [blame] | 728 | Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON); |
| 729 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 730 | v.getContext().startActivityAsUser(intent, UserHandle.CURRENT); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 731 | return true; |
| 732 | } |
| 733 | |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 734 | private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) { |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 735 | int requestingServices = 0; |
| 736 | try { |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 737 | if (Settings.Secure.getIntForUser(mContentResolver, |
| 738 | Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, |
| 739 | UserHandle.USER_CURRENT) == 1) { |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 740 | requestingServices++; |
| 741 | } |
| 742 | } catch (Settings.SettingNotFoundException e) { |
| 743 | } |
| 744 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 745 | boolean feedbackEnabled = false; |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 746 | // AccessibilityManagerService resolves services for the current user since the local |
| 747 | // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 748 | final List<AccessibilityServiceInfo> services = |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 749 | accessibilityManager.getEnabledAccessibilityServiceList( |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 750 | AccessibilityServiceInfo.FEEDBACK_ALL_MASK); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 751 | for (int i = services.size() - 1; i >= 0; --i) { |
| 752 | AccessibilityServiceInfo info = services.get(i); |
| 753 | if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) { |
| 754 | requestingServices++; |
| 755 | } |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 756 | |
| 757 | if (info.feedbackType != 0 && info.feedbackType != |
| 758 | AccessibilityServiceInfo.FEEDBACK_GENERIC) { |
| 759 | feedbackEnabled = true; |
| 760 | } |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 761 | } |
| 762 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 763 | mAccessibilityFeedbackEnabled = feedbackEnabled; |
| 764 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 765 | final boolean showAccessibilityButton = requestingServices >= 1; |
| 766 | final boolean targetSelection = requestingServices >= 2; |
| 767 | mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection); |
| 768 | } |
| 769 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 770 | private void onRotateSuggestionClick(View v) { |
| 771 | mRotationLockController.setRotationLockedAtAngle(true, mLastRotationSuggestion); |
| 772 | } |
| 773 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 774 | private boolean onRotateSuggestionHover(View v, MotionEvent event) { |
| 775 | final int action = event.getActionMasked(); |
| 776 | mHoveringRotationSuggestion = (action == MotionEvent.ACTION_HOVER_ENTER) |
| 777 | || (action == MotionEvent.ACTION_HOVER_MOVE); |
| 778 | rescheduleRotationTimeout(true); |
| 779 | return false; // Must return false so a11y hover events are dispatched correctly. |
| 780 | } |
| 781 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 782 | // ----- Methods that StatusBar talks to (should be minimized) ----- |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 783 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 784 | public void setLightBarController(LightBarController lightBarController) { |
| 785 | mLightBarController = lightBarController; |
| 786 | mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController()); |
| 787 | } |
| 788 | |
| 789 | public boolean isSemiTransparent() { |
| 790 | return mNavigationBarMode == MODE_SEMI_TRANSPARENT; |
| 791 | } |
| 792 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 793 | public void disableAnimationsDuringHide(long delay) { |
| 794 | mNavigationBarView.setLayoutTransitionsEnabled(false); |
| 795 | mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true), |
| 796 | delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE); |
| 797 | } |
| 798 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 799 | public BarTransitions getBarTransitions() { |
| 800 | return mNavigationBarView.getBarTransitions(); |
| 801 | } |
| 802 | |
| 803 | public void checkNavBarModes() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 804 | mStatusBar.checkBarMode(mNavigationBarMode, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 805 | mNavigationBarWindowState, mNavigationBarView.getBarTransitions()); |
| 806 | } |
| 807 | |
| 808 | public void finishBarAnimations() { |
| 809 | mNavigationBarView.getBarTransitions().finishAnimations(); |
| 810 | } |
| 811 | |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 812 | private final AccessibilityServicesStateChangeListener mAccessibilityListener = |
| 813 | this::updateAccessibilityServicesState; |
| 814 | |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 815 | private class MagnificationContentObserver extends ContentObserver { |
| 816 | |
| 817 | public MagnificationContentObserver(Handler handler) { |
| 818 | super(handler); |
| 819 | } |
| 820 | |
| 821 | @Override |
| 822 | public void onChange(boolean selfChange) { |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 823 | NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 824 | } |
| 825 | } |
| 826 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 827 | private final Stub mRotationWatcher = new Stub() { |
| 828 | @Override |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 829 | public void onRotationChanged(final int rotation) throws RemoteException { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 830 | // We need this to be scheduled as early as possible to beat the redrawing of |
| 831 | // window in response to the orientation change. |
| 832 | Handler h = getView().getHandler(); |
| 833 | Message msg = Message.obtain(h, () -> { |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame^] | 834 | |
| 835 | // If the screen rotation changes while locked, potentially update lock to flow with |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 836 | // new screen rotation and hide any showing suggestions. |
| 837 | if (mRotationLockController.isRotationLocked()) { |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame^] | 838 | if (shouldOverrideUserLockPrefs(rotation)) { |
| 839 | mRotationLockController.setRotationLockedAtAngle(true, rotation); |
| 840 | } |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 841 | setRotateSuggestionButtonState(false, true); |
| 842 | } |
| 843 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 844 | if (mNavigationBarView != null |
| 845 | && mNavigationBarView.needsReorient(rotation)) { |
| 846 | repositionNavigationBar(); |
| 847 | } |
| 848 | }); |
| 849 | msg.setAsynchronous(true); |
| 850 | h.sendMessageAtFrontOfQueue(msg); |
| 851 | } |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame^] | 852 | |
| 853 | private boolean shouldOverrideUserLockPrefs(final int rotation) { |
| 854 | // Only override user prefs when returning to portrait. |
| 855 | // Don't let apps that force landscape or 180 alter user lock. |
| 856 | return rotation == Surface.ROTATION_0; |
| 857 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 858 | }; |
| 859 | |
| 860 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 861 | @Override |
| 862 | public void onReceive(Context context, Intent intent) { |
| 863 | String action = intent.getAction(); |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 864 | if (Intent.ACTION_SCREEN_OFF.equals(action) |
| 865 | || Intent.ACTION_SCREEN_ON.equals(action)) { |
| 866 | notifyNavigationBarScreenOn(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 867 | } |
| 868 | } |
| 869 | }; |
| 870 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 871 | class TaskStackListenerImpl extends SysUiTaskStackChangeListener { |
| 872 | // Invalidate any rotation suggestion on task change or activity orientation change |
| 873 | // Note: all callbacks happen on main thread |
| 874 | |
| 875 | @Override |
| 876 | public void onTaskStackChanged() { |
| 877 | setRotateSuggestionButtonState(false); |
| 878 | } |
| 879 | |
| 880 | @Override |
| 881 | public void onTaskRemoved(int taskId) { |
| 882 | setRotateSuggestionButtonState(false); |
| 883 | } |
| 884 | |
| 885 | @Override |
| 886 | public void onTaskMovedToFront(int taskId) { |
| 887 | setRotateSuggestionButtonState(false); |
| 888 | } |
| 889 | |
| 890 | @Override |
| 891 | public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation) { |
| 892 | setRotateSuggestionButtonState(false); |
| 893 | } |
| 894 | } |
| 895 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 896 | public static View create(Context context, FragmentListener listener) { |
| 897 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 898 | LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, |
| 899 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, |
| 900 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING |
| 901 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 902 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 903 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 904 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH |
| 905 | | WindowManager.LayoutParams.FLAG_SLIPPERY, |
| 906 | PixelFormat.TRANSLUCENT); |
| 907 | lp.token = new Binder(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 908 | lp.setTitle("NavigationBar"); |
| 909 | lp.windowAnimations = 0; |
| 910 | |
| 911 | View navigationBarView = LayoutInflater.from(context).inflate( |
| 912 | R.layout.navigation_bar_window, null); |
| 913 | |
| 914 | if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView); |
| 915 | if (navigationBarView == null) return null; |
| 916 | |
| 917 | context.getSystemService(WindowManager.class).addView(navigationBarView, lp); |
| 918 | FragmentHostManager fragmentHost = FragmentHostManager.get(navigationBarView); |
| 919 | NavigationBarFragment fragment = new NavigationBarFragment(); |
| 920 | fragmentHost.getFragmentManager().beginTransaction() |
| 921 | .replace(R.id.navigation_bar_frame, fragment, TAG) |
| 922 | .commit(); |
| 923 | fragmentHost.addTagListener(TAG, listener); |
| 924 | return navigationBarView; |
| 925 | } |
| 926 | } |