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