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

Commit 6c6a688d authored by wilsonshih's avatar wilsonshih Committed by Wei Sheng Shih
Browse files

Reland "Remove Dependency.get from NavigationBar."

This reverts commit be525911.

The original CL fixed the SystemUI crash when create dependency for
DumpManager.

Two more modify from the original CL:

- NavigationBar should create for each display, so there cannot use the
injected WindowManager to add/remove view.
- The LightBarController is also create for each display, so the
DumpManager should only register for default display, otherwise the
registerDumpable will throw exception when creating for non-default
display.

Bug: 199481992
Test: atest MultiDisplaySystemDecorationTests
Test: atest SystemUITests
Change-Id: I2be879f85fcc9f5f83cb33a564a3a25d8d9a3254
parent 3aef7134
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -372,6 +372,12 @@ public class FrameworkServicesModule {
        return context.getSystemService(TelecomManager.class);
    }

    @Provides
    @Singleton
    static Optional<TelecomManager> provideOptionalTelecomManager(Context context) {
        return Optional.ofNullable(context.getSystemService(TelecomManager.class));
    }

    @Provides
    @Singleton
    static TelephonyManager provideTelephonyManager(Context context) {
+149 −26
Original line number Diff line number Diff line
@@ -93,7 +93,6 @@ import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.IWindowManager;
import android.view.InsetsState.InternalInsetsType;
import android.view.InsetsVisibilities;
import android.view.KeyEvent;
@@ -118,20 +117,17 @@ import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.util.LatencyTracker;
import com.android.internal.view.AppearanceRegion;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.accessibility.AccessibilityButtonModeObserver;
import com.android.systemui.accessibility.SystemActions;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.model.SysUiState;
import com.android.systemui.navigationbar.buttons.ButtonDispatcher;
import com.android.systemui.navigationbar.buttons.KeyButtonView;
import com.android.systemui.navigationbar.buttons.RotationContextButton;
import com.android.systemui.navigationbar.gestural.QuickswitchOrientedNavHandle;
import com.android.systemui.plugins.DarkIconDispatcher;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.recents.Recents;
@@ -151,8 +147,6 @@ import com.android.systemui.statusbar.phone.BarTransitions;
import com.android.systemui.statusbar.phone.LightBarController;
import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.wm.shell.legacysplitscreen.LegacySplitScreen;
import com.android.wm.shell.pip.Pip;
@@ -162,6 +156,8 @@ import java.util.Locale;
import java.util.Optional;
import java.util.function.Consumer;

import javax.inject.Inject;

import dagger.Lazy;

/**
@@ -243,7 +239,13 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
    private boolean mTransientShown;
    private int mNavBarMode = NAV_BAR_MODE_3BUTTON;
    private LightBarController mLightBarController;
    private final LightBarController mMainLightBarController;
    private final LightBarController.Factory mLightBarControllerFactory;
    private AutoHideController mAutoHideController;
    private final AutoHideController mMainAutoHideController;
    private final AutoHideController.Factory mAutoHideControllerFactory;
    private final Optional<TelecomManager> mTelecomManagerOptional;
    private final InputMethodManager mInputMethodManager;

    @VisibleForTesting
    public int mDisplayId;
@@ -267,6 +269,7 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
    private ViewTreeObserver.OnGlobalLayoutListener mOrientationHandleGlobalLayoutListener;
    private boolean mShowOrientedHandleForImmersiveMode;


    @com.android.internal.annotations.VisibleForTesting
    public enum NavBarActionEvent implements UiEventLogger.UiEventEnum {

@@ -478,11 +481,10 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
                }
            };

    public NavigationBar(Context context,
    private NavigationBar(Context context,
            WindowManager windowManager,
            Lazy<AssistManager> assistManagerLazy,
            AccessibilityManager accessibilityManager,
            AccessibilityManagerWrapper accessibilityManagerWrapper,
            DeviceProvisionedController deviceProvisionedController,
            MetricsLogger metricsLogger,
            OverviewProxyService overviewProxyService,
@@ -504,7 +506,13 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
            NavigationBarOverlayController navbarOverlayController,
            UiEventLogger uiEventLogger,
            NavigationBarA11yHelper navigationBarA11yHelper,
            UserTracker userTracker) {
            UserTracker userTracker,
            LightBarController mainLightBarController,
            LightBarController.Factory lightBarControllerFactory,
            AutoHideController mainAutoHideController,
            AutoHideController.Factory autoHideControllerFactory,
            Optional<TelecomManager> telecomManagerOptional,
            InputMethodManager inputMethodManager) {
        mContext = context;
        mWindowManager = windowManager;
        mAccessibilityManager = accessibilityManager;
@@ -531,6 +539,12 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
        mNavigationBarA11yHelper = navigationBarA11yHelper;
        mUserTracker = userTracker;
        mNotificationShadeDepthController = notificationShadeDepthController;
        mMainLightBarController = mainLightBarController;
        mLightBarControllerFactory = lightBarControllerFactory;
        mMainAutoHideController = mainAutoHideController;
        mAutoHideControllerFactory = autoHideControllerFactory;
        mTelecomManagerOptional = telecomManagerOptional;
        mInputMethodManager = inputMethodManager;

        mNavBarMode = mNavigationModeController.addListener(this);
    }
@@ -548,7 +562,7 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
        mNavigationBarView = barView.findViewById(R.id.navigation_bar_view);

        if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + barView);
        mContext.getSystemService(WindowManager.class).addView(mFrame,
        mWindowManager.addView(mFrame,
                getBarLayoutParams(mContext.getResources().getConfiguration().windowConfiguration
                        .getRotation()));
        mDisplayId = mContext.getDisplayId();
@@ -606,8 +620,7 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
    public void destroyView() {
        setAutoHideController(/* autoHideController */ null);
        mCommandQueue.removeCallback(this);
        mContext.getSystemService(WindowManager.class).removeViewImmediate(
                mNavigationBarView.getRootView());
        mWindowManager.removeViewImmediate(mNavigationBarView.getRootView());
        mNavigationModeController.removeListener(this);

        mNavigationBarA11yHelper.removeA11yEventListener(mAccessibilityListener);
@@ -673,22 +686,16 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
        // before notifications creation. We cannot directly use getLightBarController()
        // from NavigationBarFragment directly.
        LightBarController lightBarController = mIsOnDefaultDisplay
                ? Dependency.get(LightBarController.class)
                : new LightBarController(mContext,
                        Dependency.get(DarkIconDispatcher.class),
                        Dependency.get(BatteryController.class),
                        Dependency.get(NavigationModeController.class),
                        Dependency.get(DumpManager.class));
                ? mMainLightBarController : mLightBarControllerFactory.create(mContext);
        setLightBarController(lightBarController);

        // TODO(b/118592525): to support multi-display, we start to add something which is
        //                    per-display, while others may be global. I think it's time to
        //                    add a new class maybe named DisplayDependency to solve
        //                    per-display Dependency problem.
        // Alternative: this is a good case for a Dagger subcomponent. Same with LightBarController.
        AutoHideController autoHideController = mIsOnDefaultDisplay
                ? Dependency.get(AutoHideController.class)
                : new AutoHideController(mContext, mHandler,
                        Dependency.get(IWindowManager.class));
                ? mMainAutoHideController : mAutoHideControllerFactory.create(mContext);
        setAutoHideController(autoHideController);
        restoreAppearanceAndTransientState();
    }
@@ -1183,9 +1190,8 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mHomeBlockedThisTouch = false;
                TelecomManager telecomManager =
                        mContext.getSystemService(TelecomManager.class);
                if (telecomManager != null && telecomManager.isRinging()) {
                if (mTelecomManagerOptional.isPresent()
                        && mTelecomManagerOptional.get().isRinging()) {
                    if (statusBarOptional.map(StatusBar::isKeyguardShowing).orElse(false)) {
                        Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " +
                                "No heads up");
@@ -1267,7 +1273,7 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
    }

    private void onImeSwitcherClick(View v) {
        mContext.getSystemService(InputMethodManager.class).showInputMethodPickerFromSystem(
        mInputMethodManager.showInputMethodPickerFromSystem(
                true /* showAuxiliarySubtypes */, mDisplayId);
    };

@@ -1702,4 +1708,121 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
    int getNavigationIconHints() {
        return mNavigationIconHints;
    }

    /**
     * Injectable factory for construction a {@link NavigationBar}.
     */
    public static class Factory {
        private final Lazy<AssistManager> mAssistManagerLazy;
        private final AccessibilityManager mAccessibilityManager;
        private final DeviceProvisionedController mDeviceProvisionedController;
        private final MetricsLogger mMetricsLogger;
        private final OverviewProxyService mOverviewProxyService;
        private final NavigationModeController mNavigationModeController;
        private final AccessibilityButtonModeObserver mAccessibilityButtonModeObserver;
        private final StatusBarStateController mStatusBarStateController;
        private final SysUiState mSysUiFlagsContainer;
        private final BroadcastDispatcher mBroadcastDispatcher;
        private final CommandQueue mCommandQueue;
        private final Optional<Pip> mPipOptional;
        private final Optional<LegacySplitScreen> mSplitScreenOptional;
        private final Optional<Recents> mRecentsOptional;
        private final Lazy<Optional<StatusBar>> mStatusBarOptionalLazy;
        private final ShadeController mShadeController;
        private final NotificationRemoteInputManager mNotificationRemoteInputManager;
        private final NotificationShadeDepthController mNotificationShadeDepthController;
        private final SystemActions mSystemActions;
        private final Handler mMainHandler;
        private final NavigationBarOverlayController mNavbarOverlayController;
        private final UiEventLogger mUiEventLogger;
        private final NavigationBarA11yHelper mNavigationBarA11yHelper;
        private final UserTracker mUserTracker;
        private final LightBarController mMainLightBarController;
        private final LightBarController.Factory mLightBarControllerFactory;
        private final AutoHideController mMainAutoHideController;
        private final AutoHideController.Factory mAutoHideControllerFactory;
        private final Optional<TelecomManager> mTelecomManagerOptional;
        private final InputMethodManager mInputMethodManager;

        @Inject
        public Factory(
                Lazy<AssistManager> assistManagerLazy,
                AccessibilityManager accessibilityManager,
                DeviceProvisionedController deviceProvisionedController,
                MetricsLogger metricsLogger,
                OverviewProxyService overviewProxyService,
                NavigationModeController navigationModeController,
                AccessibilityButtonModeObserver accessibilityButtonModeObserver,
                StatusBarStateController statusBarStateController,
                SysUiState sysUiFlagsContainer,
                BroadcastDispatcher broadcastDispatcher,
                CommandQueue commandQueue,
                Optional<Pip> pipOptional,
                Optional<LegacySplitScreen> splitScreenOptional,
                Optional<Recents> recentsOptional,
                Lazy<Optional<StatusBar>> statusBarOptionalLazy,
                ShadeController shadeController,
                NotificationRemoteInputManager notificationRemoteInputManager,
                NotificationShadeDepthController notificationShadeDepthController,
                SystemActions systemActions,
                @Main Handler mainHandler,
                NavigationBarOverlayController navbarOverlayController,
                UiEventLogger uiEventLogger,
                NavigationBarA11yHelper navigationBarA11yHelper,
                UserTracker userTracker,
                LightBarController mainLightBarController,
                LightBarController.Factory lightBarControllerFactory,
                AutoHideController mainAutoHideController,
                AutoHideController.Factory autoHideControllerFactory,
                Optional<TelecomManager> telecomManagerOptional,
                InputMethodManager inputMethodManager) {
            mAssistManagerLazy = assistManagerLazy;
            mAccessibilityManager = accessibilityManager;
            mDeviceProvisionedController = deviceProvisionedController;
            mMetricsLogger = metricsLogger;
            mOverviewProxyService = overviewProxyService;
            mNavigationModeController = navigationModeController;
            mAccessibilityButtonModeObserver = accessibilityButtonModeObserver;
            mStatusBarStateController = statusBarStateController;
            mSysUiFlagsContainer = sysUiFlagsContainer;
            mBroadcastDispatcher = broadcastDispatcher;
            mCommandQueue = commandQueue;
            mPipOptional = pipOptional;
            mSplitScreenOptional = splitScreenOptional;
            mRecentsOptional = recentsOptional;
            mStatusBarOptionalLazy = statusBarOptionalLazy;
            mShadeController = shadeController;
            mNotificationRemoteInputManager = notificationRemoteInputManager;
            mNotificationShadeDepthController = notificationShadeDepthController;
            mSystemActions = systemActions;
            mMainHandler = mainHandler;
            mNavbarOverlayController = navbarOverlayController;
            mUiEventLogger = uiEventLogger;
            mNavigationBarA11yHelper = navigationBarA11yHelper;
            mUserTracker = userTracker;
            mMainLightBarController = mainLightBarController;
            mLightBarControllerFactory = lightBarControllerFactory;
            mMainAutoHideController = mainAutoHideController;
            mAutoHideControllerFactory = autoHideControllerFactory;
            mTelecomManagerOptional = telecomManagerOptional;
            mInputMethodManager = inputMethodManager;
        }

        /** Construct a {@link NavigationBar} */
        public NavigationBar create(Context context) {
            final WindowManager wm = context.getSystemService(WindowManager.class);
            return new NavigationBar(context, wm, mAssistManagerLazy,
                    mAccessibilityManager, mDeviceProvisionedController, mMetricsLogger,
                    mOverviewProxyService, mNavigationModeController,
                    mAccessibilityButtonModeObserver, mStatusBarStateController,
                    mSysUiFlagsContainer, mBroadcastDispatcher, mCommandQueue, mPipOptional,
                    mSplitScreenOptional, mRecentsOptional, mStatusBarOptionalLazy,
                    mShadeController, mNotificationRemoteInputManager,
                    mNotificationShadeDepthController, mSystemActions, mMainHandler,
                    mNavbarOverlayController, mUiEventLogger, mNavigationBarA11yHelper,
                    mUserTracker, mMainLightBarController, mLightBarControllerFactory,
                    mMainAutoHideController, mAutoHideControllerFactory, mTelecomManagerOptional,
                    mInputMethodManager);
        }
    }
}
 No newline at end of file
+6 −122

File changed.

Preview size limit exceeded, changes collapsed.

+19 −0
Original line number Diff line number Diff line
@@ -172,4 +172,23 @@ public class AutoHideController {

        return false;
    }

    /**
     * Injectable factory for creating a {@link AutoHideController}.
     */
    public static class Factory {
        private final Handler mHandler;
        private final IWindowManager mIWindowManager;

        @Inject
        public Factory(@Main Handler handler, IWindowManager iWindowManager) {
            mHandler = handler;
            mIWindowManager = iWindowManager;
        }

        /** Create an {@link AutoHideController} */
        public AutoHideController create(Context context) {
            return new AutoHideController(context, mHandler, mIWindowManager);
        }
    }
}
+33 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.phone;

import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;

@@ -101,8 +102,10 @@ public class LightBarController implements BatteryController.BatteryStateChangeC
            mNavigationMode = mode;
        });

        if (ctx.getDisplayId() == DEFAULT_DISPLAY) {
            dumpManager.registerDumpable(getClass().getSimpleName(), this);
        }
    }

    public void setNavigationBar(LightBarTransitionsController navigationBar) {
        mNavigationBarController = navigationBar;
@@ -298,4 +301,33 @@ public class LightBarController implements BatteryController.BatteryStateChangeC
            pw.println();
        }
    }

    /**
     * Injectable factory for creating a {@link LightBarController}.
     */
    public static class Factory {
        private final DarkIconDispatcher mDarkIconDispatcher;
        private final BatteryController mBatteryController;
        private final NavigationModeController mNavModeController;
        private final DumpManager mDumpManager;

        @Inject
        public Factory(
                DarkIconDispatcher darkIconDispatcher,
                BatteryController batteryController,
                NavigationModeController navModeController,
                DumpManager dumpManager) {

            mDarkIconDispatcher = darkIconDispatcher;
            mBatteryController = batteryController;
            mNavModeController = navModeController;
            mDumpManager = dumpManager;
        }

        /** Create an {@link LightBarController} */
        public LightBarController create(Context context) {
            return new LightBarController(context, mDarkIconDispatcher, mBatteryController,
                    mNavModeController, mDumpManager);
        }
    }
}
Loading