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

Commit 617777eb authored by Dave Mankoff's avatar Dave Mankoff
Browse files

1/N Add Controllers for most KeyguardBouncer related views.

This adds Controllers to most of the KeyguardBouncer related views,
though it does not move much (or any) functionality into them.

This is the first step of a few to get View Injection out of the
KeyguardMessageArea. The CL was growing large, and I wanted to find
a good check-in point before continuing.

I also added a "ViewController" utility class in this CL that
simplifies some of the repetetive work I've been finding myself
writing when implementing other Controllers. It is intentionally
left simple, existing only to hook into view lifecycle events.

More work to follow.

Bug: 166448040
Test: manual && atest SystemUITests
Change-Id: Ie59f62e97d979fb753e4a103d37ceca02e327238
parent 55689cf7
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import androidx.annotation.VisibleForTesting;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardViewController;
import com.android.keyguard.ViewMediatorCallback;
import com.android.keyguard.dagger.KeyguardBouncerComponent;
import com.android.systemui.R;
import com.android.systemui.car.CarServiceProvider;
import com.android.systemui.car.navigationbar.CarNavigationBarController;
@@ -40,6 +39,7 @@ import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.statusbar.phone.BiometricUnlockController;
import com.android.systemui.statusbar.phone.KeyguardBouncer;
import com.android.systemui.statusbar.phone.KeyguardBouncer.Factory;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.phone.NotificationPanelViewController;
import com.android.systemui.statusbar.phone.StatusBar;
@@ -66,7 +66,7 @@ public class CarKeyguardViewController extends OverlayViewController implements
    private final Lazy<BiometricUnlockController> mBiometricUnlockControllerLazy;
    private final ViewMediatorCallback mViewMediatorCallback;
    private final CarNavigationBarController mCarNavigationBarController;
    private final KeyguardBouncerComponent.Factory mKeyguardBouncerComponentFactory;
    private final Factory mKeyguardBouncerFactory;
    // Needed to instantiate mBouncer.
    private final KeyguardBouncer.BouncerExpansionCallback
            mExpansionCallback = new KeyguardBouncer.BouncerExpansionCallback() {
@@ -107,7 +107,7 @@ public class CarKeyguardViewController extends OverlayViewController implements
            Lazy<BiometricUnlockController> biometricUnlockControllerLazy,
            ViewMediatorCallback viewMediatorCallback,
            CarNavigationBarController carNavigationBarController,
            KeyguardBouncerComponent.Factory keyguardBouncerComponentFactory) {
            KeyguardBouncer.Factory keyguardBouncerFactory) {

        super(R.id.keyguard_stub, overlayViewGlobalStateController);

@@ -118,7 +118,7 @@ public class CarKeyguardViewController extends OverlayViewController implements
        mBiometricUnlockControllerLazy = biometricUnlockControllerLazy;
        mViewMediatorCallback = viewMediatorCallback;
        mCarNavigationBarController = carNavigationBarController;
        mKeyguardBouncerComponentFactory = keyguardBouncerComponentFactory;
        mKeyguardBouncerFactory = keyguardBouncerFactory;

        registerUserSwitchedListener();
    }
@@ -130,9 +130,8 @@ public class CarKeyguardViewController extends OverlayViewController implements

    @Override
    public void onFinishInflate() {
        mBouncer = mKeyguardBouncerComponentFactory
                .build(getLayout().findViewById(R.id.keyguard_container), mExpansionCallback)
                .createKeyguardBouncer();
        mBouncer = mKeyguardBouncerFactory
                .create(getLayout().findViewById(R.id.keyguard_container), mExpansionCallback);
        mBiometricUnlockControllerLazy.get().setKeyguardViewController(this);
    }

+4 −8
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import androidx.test.filters.SmallTest;

import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.ViewMediatorCallback;
import com.android.keyguard.dagger.KeyguardBouncerComponent;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.car.CarServiceProvider;
@@ -67,9 +66,7 @@ public class CarKeyguardViewControllerTest extends SysuiTestCase {
    @Mock
    private CarKeyguardViewController.OnKeyguardCancelClickedListener mCancelClickedListener;
    @Mock
    private KeyguardBouncerComponent.Factory mKeyguardBouncerComponentFactory;
    @Mock
    private KeyguardBouncerComponent mKeyguardBouncerComponent;
    private KeyguardBouncer.Factory mKeyguardBouncerFactory;
    @Mock
    private KeyguardBouncer mBouncer;

@@ -77,11 +74,10 @@ public class CarKeyguardViewControllerTest extends SysuiTestCase {
    public void setUp() {
        MockitoAnnotations.initMocks(this);

        when(mKeyguardBouncerComponentFactory.build(
        when(mKeyguardBouncerFactory.create(
                any(ViewGroup.class),
                any(KeyguardBouncer.BouncerExpansionCallback.class)))
                .thenReturn(mKeyguardBouncerComponent);
        when(mKeyguardBouncerComponent.createKeyguardBouncer()).thenReturn(mBouncer);
                .thenReturn(mBouncer);

        mCarKeyguardViewController = new CarKeyguardViewController(
                Handler.getMain(),
@@ -92,7 +88,7 @@ public class CarKeyguardViewControllerTest extends SysuiTestCase {
                () -> mock(BiometricUnlockController.class),
                mock(ViewMediatorCallback.class),
                mock(CarNavigationBarController.class),
                mKeyguardBouncerComponentFactory
                mKeyguardBouncerFactory
        );
        mCarKeyguardViewController.inflate((ViewGroup) LayoutInflater.from(mContext).inflate(
                R.layout.sysui_overlay_window, /* root= */ null));
+0 −7
Original line number Diff line number Diff line
@@ -306,13 +306,6 @@ public class KeyguardHostView extends FrameLayout implements SecurityCallback {
        }
    }

    /**
     * Called before this view is being removed.
     */
    public void cleanUp() {
        getSecurityContainer().onPause();
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (interceptMediaKey(event)) {
+69 −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.keyguard;

import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.dagger.KeyguardBouncerScope;
import com.android.systemui.util.ViewController;

import javax.inject.Inject;

/** Controller for a {@link KeyguardHostView}. */
@KeyguardBouncerScope
public class KeyguardHostViewController extends ViewController {
    private final KeyguardHostView mView;
    private final KeyguardSecurityContainerController mKeyguardSecurityContainerController;
    private final LockPatternUtils mLockPatternUtils;
    private final ViewMediatorCallback mViewMediatorCallback;

    @Inject
    public KeyguardHostViewController(KeyguardHostView view,
            KeyguardSecurityContainerController keyguardSecurityContainerController,
            LockPatternUtils lockPatternUtils,
            ViewMediatorCallback viewMediatorCallback) {
        super(view);
        mView = view;
        mKeyguardSecurityContainerController = keyguardSecurityContainerController;
        mLockPatternUtils = lockPatternUtils;
        mViewMediatorCallback = viewMediatorCallback;
    }

    /** Initialize the Controller. */
    public void init() {
        super.init();
        mView.setLockPatternUtils(mLockPatternUtils);
        mView.setViewMediatorCallback(mViewMediatorCallback);
        mKeyguardSecurityContainerController.init();
    }

    @Override
    protected void onViewAttached() {
    }

    @Override
    protected void onViewDetached() {
    }

    public KeyguardHostView getView() {
        return mView;
    }

     /** Called before this view is being removed. */
    public void cleanUp() {
        mKeyguardSecurityContainerController.onPause();
    }
}
+70 −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.keyguard;

import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.util.ViewController;

import javax.inject.Inject;

/** Controller for a {@link KeyguardMessageAreaController}. */
public class KeyguardMessageAreaController extends ViewController {
    private final KeyguardMessageArea mView;
    private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
    private final ConfigurationController mConfigurationController;

    private KeyguardMessageAreaController(KeyguardMessageArea view,
            KeyguardUpdateMonitor keyguardUpdateMonitor,
            ConfigurationController configurationController) {
        super(view);

        mView = view;
        mKeyguardUpdateMonitor = keyguardUpdateMonitor;
        mConfigurationController = configurationController;
    }

    @Override
    protected void onViewAttached() {
        //mConfigurationController.addCallback();
        //mKeyguardUpdateMonitor.registerCallback();
    }

    @Override
    protected void onViewDetached() {
        //mConfigurationController.removeCallback();
        //mKeyguardUpdateMonitor.removeCallback();
    }

    /** Factory for createing {@link com.android.keyguard.KeyguardMessageAreaController}. */
    public static class Factory {
        private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
        private final ConfigurationController mConfigurationController;

        @Inject
        public Factory(KeyguardUpdateMonitor keyguardUpdateMonitor,
                ConfigurationController configurationController) {
            mKeyguardUpdateMonitor = keyguardUpdateMonitor;
            mConfigurationController = configurationController;
        }

        /** Build a new {@link KeyguardMessageAreaController}. */
        public KeyguardMessageAreaController create(KeyguardMessageArea view) {
            return new KeyguardMessageAreaController(
                    view, mKeyguardUpdateMonitor, mConfigurationController);
        }
    }
}
Loading