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

Commit ee7b8a36 authored by Aaron Liu's avatar Aaron Liu
Browse files

Make KeyguardStatusView accessible.

Ensure that keyguardstatusview is not null. Also break up update view
controllers so that we can update the keyguardstatusview controller if
it changes.

Bug: 295555276
Test: test to see that status view can be set later than view
inflation.

Change-Id: I1db08a33a98f2523bbca2ebad2bbc115d66b65f5
parent 49f82e12
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -17,9 +17,12 @@

package com.android.systemui.keyguard

import android.content.Context
import android.content.res.Configuration
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.android.keyguard.KeyguardStatusView
import com.android.keyguard.KeyguardStatusViewController
import com.android.keyguard.dagger.KeyguardStatusViewComponent
import com.android.systemui.CoreStartable
@@ -92,6 +95,7 @@ constructor(
    private val communalWidgetViewModel: CommunalWidgetViewModel,
    private val communalWidgetViewAdapter: CommunalWidgetViewAdapter,
    private val notificationStackScrollerLayoutController: NotificationStackScrollLayoutController,
    private val context: Context,
) : CoreStartable {

    private var rootViewHandle: DisposableHandle? = null
@@ -100,7 +104,22 @@ constructor(
    private var rightShortcutHandle: KeyguardQuickAffordanceViewBinder.Binding? = null
    private var ambientIndicationAreaHandle: KeyguardAmbientIndicationAreaViewBinder.Binding? = null
    private var settingsPopupMenuHandle: DisposableHandle? = null
    private var keyguardStatusViewController: KeyguardStatusViewController? = null
    var keyguardStatusViewController: KeyguardStatusViewController? = null
        get() {
            if (field == null) {
                val statusViewComponent =
                    keyguardStatusViewComponentFactory.build(
                        LayoutInflater.from(context).inflate(R.layout.keyguard_status_view, null)
                            as KeyguardStatusView
                    )
                val controller = statusViewComponent.keyguardStatusViewController
                controller.init()
                field = controller
            }

            return field
        }
        private set

    override fun start() {
        bindKeyguardRootView()
@@ -307,6 +326,5 @@ constructor(
     * Temporary, to allow NotificationPanelViewController to use the same instance while code is
     * migrated: b/288242803
     */
    fun getKeyguardStatusViewController() = keyguardStatusViewController
    fun getKeyguardRootView() = keyguardRootView
}
+34 −30
Original line number Diff line number Diff line
@@ -1226,6 +1226,38 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
    private void updateViewControllers(
            FrameLayout userAvatarView,
            KeyguardUserSwitcherView keyguardUserSwitcherView) {
        updateStatusBarViewController();
        if (mKeyguardUserSwitcherController != null) {
            // Try to close the switcher so that callbacks are triggered if necessary.
            // Otherwise, NPV can get into a state where some of the views are still hidden
            mKeyguardUserSwitcherController.closeSwitcherIfOpenAndNotSimple(false);
        }

        mKeyguardQsUserSwitchController = null;
        mKeyguardUserSwitcherController = null;

        // Re-associate the KeyguardUserSwitcherController
        if (userAvatarView != null) {
            KeyguardQsUserSwitchComponent userSwitcherComponent =
                    mKeyguardQsUserSwitchComponentFactory.build(userAvatarView);
            mKeyguardQsUserSwitchController =
                    userSwitcherComponent.getKeyguardQsUserSwitchController();
            mKeyguardQsUserSwitchController.init();
            mKeyguardStatusBarViewController.setKeyguardUserSwitcherEnabled(true);
        } else if (keyguardUserSwitcherView != null) {
            KeyguardUserSwitcherComponent userSwitcherComponent =
                    mKeyguardUserSwitcherComponentFactory.build(keyguardUserSwitcherView);
            mKeyguardUserSwitcherController =
                    userSwitcherComponent.getKeyguardUserSwitcherController();
            mKeyguardUserSwitcherController.init();
            mKeyguardStatusBarViewController.setKeyguardUserSwitcherEnabled(true);
        } else {
            mKeyguardStatusBarViewController.setKeyguardUserSwitcherEnabled(false);
        }
    }

    /** Updates the StatusBarViewController and updates any that depend on it. */
    public void updateStatusBarViewController() {
        // Re-associate the KeyguardStatusViewController
        if (mKeyguardStatusViewController != null) {
            mKeyguardStatusViewController.onDestroy();
@@ -1235,7 +1267,6 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
            // Need a shared controller until mKeyguardStatusViewController can be removed from
            // here, due to important state being set in that controller. Rebind in order to pick
            // up config changes
            mKeyguardViewConfigurator.bindKeyguardStatusView(mView);
            mKeyguardStatusViewController =
                    mKeyguardViewConfigurator.getKeyguardStatusViewController();
        } else {
@@ -1246,6 +1277,7 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
            mKeyguardStatusViewController = statusViewComponent.getKeyguardStatusViewController();
            mKeyguardStatusViewController.init();
        }

        mKeyguardStatusViewController.setSplitShadeEnabled(mSplitShadeEnabled);
        mKeyguardStatusViewController.getView().addOnLayoutChangeListener(
                (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
@@ -1256,34 +1288,6 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
                });

        updateClockAppearance();

        if (mKeyguardUserSwitcherController != null) {
            // Try to close the switcher so that callbacks are triggered if necessary.
            // Otherwise, NPV can get into a state where some of the views are still hidden
            mKeyguardUserSwitcherController.closeSwitcherIfOpenAndNotSimple(false);
        }

        mKeyguardQsUserSwitchController = null;
        mKeyguardUserSwitcherController = null;

        // Re-associate the KeyguardUserSwitcherController
        if (userAvatarView != null) {
            KeyguardQsUserSwitchComponent userSwitcherComponent =
                    mKeyguardQsUserSwitchComponentFactory.build(userAvatarView);
            mKeyguardQsUserSwitchController =
                    userSwitcherComponent.getKeyguardQsUserSwitchController();
            mKeyguardQsUserSwitchController.init();
            mKeyguardStatusBarViewController.setKeyguardUserSwitcherEnabled(true);
        } else if (keyguardUserSwitcherView != null) {
            KeyguardUserSwitcherComponent userSwitcherComponent =
                    mKeyguardUserSwitcherComponentFactory.build(keyguardUserSwitcherView);
            mKeyguardUserSwitcherController =
                    userSwitcherComponent.getKeyguardUserSwitcherController();
            mKeyguardUserSwitcherController.init();
            mKeyguardStatusBarViewController.setKeyguardUserSwitcherEnabled(true);
        } else {
            mKeyguardStatusBarViewController.setKeyguardUserSwitcherEnabled(false);
        }
    }

    @Override