Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5f0ceb3a authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Generalize AutoHideController to be shared" into rvc-dev am: dfb1fe98 am: b1eec61c

Change-Id: I58abc3fc85b10db06a78ab2f2779a55af7901d21
parents 45433b25 b1eec61c
Loading
Loading
Loading
Loading
+83 −0
Original line number Diff line number Diff line
@@ -16,6 +16,12 @@

package com.android.systemui.navigationbar.car;

import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
import static android.view.InsetsState.containsType;

import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT;
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_TRANSPARENT;

import android.content.Context;
import android.graphics.PixelFormat;
import android.inputmethodservice.InputMethodService;
@@ -37,9 +43,12 @@ import com.android.systemui.car.CarDeviceProvisionedController;
import com.android.systemui.car.CarDeviceProvisionedListener;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.statusbar.AutoHideUiElement;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.NavigationBarController;
import com.android.systemui.statusbar.SuperStatusBarViewFactory;
import com.android.systemui.statusbar.phone.AutoHideController;
import com.android.systemui.statusbar.phone.BarTransitions;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.KeyguardStateController;

@@ -57,6 +66,7 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
    private final WindowManager mWindowManager;
    private final CarDeviceProvisionedController mCarDeviceProvisionedController;
    private final CommandQueue mCommandQueue;
    private final AutoHideController mAutoHideController;
    private final ButtonSelectionStateListener mButtonSelectionStateListener;
    private final Handler mMainHandler;
    private final Lazy<KeyguardStateController> mKeyguardStateControllerLazy;
@@ -64,6 +74,8 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
    private final SuperStatusBarViewFactory mSuperStatusBarViewFactory;
    private final ButtonSelectionStateController mButtonSelectionStateController;

    private final int mDisplayId;

    private IStatusBarService mBarService;
    private ActivityManagerWrapper mActivityManagerWrapper;

@@ -86,12 +98,16 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
    private boolean mDeviceIsSetUpForUser = true;
    private boolean mIsUserSetupInProgress = false;

    private @BarTransitions.TransitionMode int mNavigationBarMode;
    private boolean mTransientShown;

    @Inject
    public CarNavigationBar(Context context,
            CarNavigationBarController carNavigationBarController,
            WindowManager windowManager,
            DeviceProvisionedController deviceProvisionedController,
            CommandQueue commandQueue,
            AutoHideController autoHideController,
            ButtonSelectionStateListener buttonSelectionStateListener,
            @Main Handler mainHandler,
            Lazy<KeyguardStateController> keyguardStateControllerLazy,
@@ -104,12 +120,15 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
        mCarDeviceProvisionedController = (CarDeviceProvisionedController)
                deviceProvisionedController;
        mCommandQueue = commandQueue;
        mAutoHideController = autoHideController;
        mButtonSelectionStateListener = buttonSelectionStateListener;
        mMainHandler = mainHandler;
        mKeyguardStateControllerLazy = keyguardStateControllerLazy;
        mNavigationBarControllerLazy = navigationBarControllerLazy;
        mSuperStatusBarViewFactory = superStatusBarViewFactory;
        mButtonSelectionStateController = buttonSelectionStateController;

        mDisplayId = mWindowManager.getDefaultDisplay().getDisplayId();
    }

    @Override
@@ -133,6 +152,23 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
            ex.rethrowFromSystemServer();
        }

        mAutoHideController.addAutoHideUiElement(new AutoHideUiElement() {
            @Override
            public void synchronizeState() {
                // No op.
            }

            @Override
            public boolean isVisible() {
                return mTransientShown;
            }

            @Override
            public void hide() {
                clearTransient();
            }
        });

        mDeviceIsSetUpForUser = mCarDeviceProvisionedController.isCurrentUserSetup();
        mIsUserSetupInProgress = mCarDeviceProvisionedController.isCurrentUserSetupInProgress();
        mCarDeviceProvisionedController.addCallback(
@@ -340,6 +376,39 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
                isKeyboardVisible ? View.GONE : View.VISIBLE);
    }

    @Override
    public void showTransient(int displayId, int[] types) {
        if (displayId != mDisplayId) {
            return;
        }
        if (!containsType(types, ITYPE_NAVIGATION_BAR)) {
            return;
        }

        if (!mTransientShown) {
            mTransientShown = true;
            handleTransientChanged();
        }
    }

    @Override
    public void abortTransient(int displayId, int[] types) {
        if (displayId != mDisplayId) {
            return;
        }
        if (!containsType(types, ITYPE_NAVIGATION_BAR)) {
            return;
        }
        clearTransient();
    }

    private void clearTransient() {
        if (mTransientShown) {
            mTransientShown = false;
            handleTransientChanged();
        }
    }

    @Override
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.print("  mTaskStackListener=");
@@ -347,4 +416,18 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
        pw.print("  mBottomNavigationBarView=");
        pw.println(mBottomNavigationBarView);
    }

    private void handleTransientChanged() {
        updateBarMode(mTransientShown ? MODE_SEMI_TRANSPARENT : MODE_TRANSPARENT);
    }

    // Returns true if the bar mode is changed.
    private boolean updateBarMode(int barMode) {
        if (mNavigationBarMode != barMode) {
            mNavigationBarMode = barMode;
            mAutoHideController.touchAutoHide();
            return true;
        }
        return false;
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.HandlerThread;
import android.os.ServiceManager;
import android.util.DisplayMetrics;
import android.view.Choreographer;
import android.view.IWindowManager;
import android.view.LayoutInflater;
import android.view.WindowManager;

@@ -47,6 +48,7 @@ import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.DevicePolicyManagerWrapper;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.NavigationBarController;
import com.android.systemui.statusbar.phone.AutoHideController;
import com.android.systemui.statusbar.phone.ConfigurationControllerImpl;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.DataSaverController;
@@ -166,6 +168,14 @@ public class DependencyProvider {
        return new ConfigurationControllerImpl(context);
    }

    /** */
    @Singleton
    @Provides
    public AutoHideController provideAutoHideController(Context context,
            @Main Handler mainHandler, IWindowManager iWindowManager) {
        return new AutoHideController(context, mainHandler, iWindowManager);
    }

    @Singleton
    @Provides
    public ActivityManagerWrapper provideActivityManagerWrapper() {
+53 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar;

/**
 * Common interface for a UI element controlled by
 * {@link com.android.systemui.statusbar.phone.AutoHideController}. These UI elements  automatically
 * hidden by {@link com.android.systemui.statusbar.phone.AutoHideController} when in some transient
 * state.
 */
public interface AutoHideUiElement {

    /**
     * Ensures that the {@link AutoHideUiElement} reflects the current expected state. This
     * method will be posted as a {@link Runnable} in the main thread.
     */
    void synchronizeState();

    /**
     * The {@link com.android.systemui.statusbar.phone.AutoHideController} is responsible for
     * automatically hiding ui elements that are only shown transiently. This method determines
     * whether a manual touch should also hide the ui elements that are temporarily visible.
     *
     * Note that all {@link AutoHideUiElement} instances should return true for a manual touch to
     * trigger {@link #hide()} on the ui elements.
     */
    default boolean shouldHideOnTouch() {
        return true;
    }

    /** Returns true if the {@link AutoHideUiElement} is visible. */
    boolean isVisible();

    /**
     * Called to hide the {@link AutoHideUiElement} through the
     * {@link com.android.systemui.statusbar.phone.AutoHideController}.
     */
    void hide();
}
+0 −1
Original line number Diff line number Diff line
@@ -149,7 +149,6 @@ public class NavigationBarController implements Callbacks {
            AutoHideController autoHideController = isOnDefaultDisplay
                    ? Dependency.get(AutoHideController.class)
                    : new AutoHideController(context, mHandler,
                            Dependency.get(NotificationRemoteInputManager.class),
                            Dependency.get(IWindowManager.class));
            navBar.setAutoHideController(autoHideController);
            navBar.restoreAppearanceAndTransientState();
+50 −36
Original line number Diff line number Diff line
@@ -19,56 +19,64 @@ package com.android.systemui.statusbar.phone;
import android.content.Context;
import android.os.Handler;
import android.os.RemoteException;
import android.util.ArraySet;
import android.util.Log;
import android.view.IWindowManager;
import android.view.MotionEvent;

import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.phone.dagger.StatusBarPhoneModule;
import com.android.systemui.statusbar.AutoHideUiElement;

/** A controller to control all auto-hide things. */
import java.util.Set;

import javax.inject.Inject;

/** A controller to control all auto-hide things. Also see {@link AutoHideUiElement}. */
public class AutoHideController {
    private static final String TAG = "AutoHideController";
    private static final long AUTO_HIDE_TIMEOUT_MS = 2250;

    private final IWindowManager mWindowManagerService;

    private final Handler mHandler;
    private final NotificationRemoteInputManager mRemoteInputManager;
    private StatusBar mStatusBar;
    private NavigationBarFragment mNavigationBar;
    private final Set<AutoHideUiElement> mElements;

    private int mDisplayId;

    private boolean mAutoHideSuspended;

    private static final long AUTO_HIDE_TIMEOUT_MS = 2250;

    private final Runnable mAutoHide = () -> {
        if (isAnyTransientBarShown()) {
            hideTransientBars();
        }
    };

    /**
     * Injected constructor. See {@link StatusBarPhoneModule}.
     */
    @Inject
    public AutoHideController(Context context, @Main Handler handler,
            NotificationRemoteInputManager notificationRemoteInputManager,
            IWindowManager iWindowManager) {
        mHandler = handler;
        mRemoteInputManager = notificationRemoteInputManager;
        mWindowManagerService = iWindowManager;
        mElements = new ArraySet<>();

        mDisplayId = context.getDisplayId();
    }

    void setStatusBar(StatusBar statusBar) {
        mStatusBar = statusBar;
    /**
     * Adds an {@link AutoHideUiElement} whose behavior should be controlled by the
     * {@link AutoHideController}.
     */
    public void addAutoHideUiElement(AutoHideUiElement element) {
        if (element != null) {
            mElements.add(element);
        }
    }

    void setNavigationBar(NavigationBarFragment navigationBar) {
        mNavigationBar = navigationBar;
    /**
     * Remove an {@link AutoHideUiElement} that was previously added.
     */
    public void removeAutoHideUiElement(AutoHideUiElement element) {
        if (element != null) {
            mElements.remove(element);
        }
    }

    private void hideTransientBars() {
@@ -77,11 +85,9 @@ public class AutoHideController {
        } catch (RemoteException ex) {
            Log.w(TAG, "Cannot get WindowManager");
        }
        if (mStatusBar != null) {
            mStatusBar.clearTransient();
        }
        if (mNavigationBar != null) {
            mNavigationBar.clearTransient();

        for (AutoHideUiElement element : mElements) {
            element.hide();
        }
    }

@@ -104,7 +110,8 @@ public class AutoHideController {
        mAutoHideSuspended = isAnyTransientBarShown();
    }

    void touchAutoHide() {
    /** Schedules or cancels auto hide behavior based on current system bar state. */
    public void touchAutoHide() {
        // update transient bar auto hide
        if (isAnyTransientBarShown()) {
            scheduleAutoHide();
@@ -114,13 +121,15 @@ public class AutoHideController {
    }

    private Runnable getCheckBarModesRunnable() {
        if (mStatusBar != null) {
            return () -> mStatusBar.checkBarModes();
        } else if (mNavigationBar != null) {
            return () -> mNavigationBar.checkNavBarModes();
        } else {
        if (mElements.isEmpty()) {
            return null;
        }

        return () -> {
            for (AutoHideUiElement element : mElements) {
                element.synchronizeState();
            }
        };
    }

    private void cancelAutoHide() {
@@ -134,14 +143,15 @@ public class AutoHideController {
    }

    void checkUserAutoHide(MotionEvent event) {
        boolean shouldAutoHide = isAnyTransientBarShown()
        boolean shouldHide = isAnyTransientBarShown()
                && event.getAction() == MotionEvent.ACTION_OUTSIDE // touch outside the source bar.
                && event.getX() == 0 && event.getY() == 0;
        if (mStatusBar != null) {
            // a touch outside both bars
            shouldAutoHide &= !mRemoteInputManager.getController().isRemoteInputActive();

        for (AutoHideUiElement element : mElements) {
            shouldHide &= element.shouldHideOnTouch();
        }
        if (shouldAutoHide) {

        if (shouldHide) {
            userAutoHide();
        }
    }
@@ -152,7 +162,11 @@ public class AutoHideController {
    }

    private boolean isAnyTransientBarShown() {
        return (mStatusBar != null && mStatusBar.isTransientShown())
                || mNavigationBar != null && mNavigationBar.isTransientShown();
        for (AutoHideUiElement element : mElements) {
            if (element.isVisible()) {
                return true;
            }
        }
        return false;
    }
}
Loading