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

Commit 09f2defc authored by Matt Pietal's avatar Matt Pietal
Browse files

[DO NOT MERGE] Migrate clock and lock icon to flows

Use transition repository to begin replacing doze amount
listeners. Since a lot of this code will be in Java, provide an
adapter to collect this flows.

For testing with Java code, create two test files. The Java one that
tests with the flag turned off, and a new Kotlin one with the flag
turned on, in order to test with coroutines. Create a base class in
order for both to work.

Use flags to test in teamfood first.

Test: atest LockIconViewControllerTest ClockEventControllerTest
LockIconViewControllerWithCoroutinesTest
Bug: 195430376

Change-Id: Ia5d440e1a6d7c4f526aa508c89e04b4a01abe35e
parent a52c7538
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags.DOZING_MIGRATION_1
import com.android.systemui.flags.Flags.REGION_SAMPLING
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
@@ -217,8 +218,11 @@ open class ClockEventController @Inject constructor(
        disposableHandle = parent.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                listenForDozing(this)
                listenForDozeAmount(this)
                if (featureFlags.isEnabled(DOZING_MIGRATION_1)) {
                    listenForDozeAmountTransition(this)
                } else {
                    listenForDozeAmount(this)
                }
            }
        }
    }
@@ -261,10 +265,9 @@ open class ClockEventController @Inject constructor(
    @VisibleForTesting
    internal fun listenForDozeAmountTransition(scope: CoroutineScope): Job {
        return scope.launch {
            keyguardTransitionInteractor.aodToLockscreenTransition.collect {
                // Would eventually run this:
                // dozeAmount = it.value
                // clock?.animations?.doze(dozeAmount)
            keyguardTransitionInteractor.dozeAmountTransition.collect {
                dozeAmount = it.value
                clock?.animations?.doze(dozeAmount)
            }
        }
    }
+59 −15
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import static com.android.keyguard.LockIconView.ICON_LOCK;
import static com.android.keyguard.LockIconView.ICON_UNLOCK;
import static com.android.systemui.classifier.Classifier.LOCK_ICON;
import static com.android.systemui.doze.util.BurnInHelperKt.getBurnInOffset;
import static com.android.systemui.flags.Flags.DOZING_MIGRATION_1;
import static com.android.systemui.util.kotlin.JavaAdapterKt.collectFlow;

import android.content.res.Configuration;
import android.content.res.Resources;
@@ -44,6 +46,7 @@ import android.view.accessibility.AccessibilityNodeInfo;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;

import com.android.systemui.Dumpable;
@@ -53,6 +56,10 @@ import com.android.systemui.biometrics.AuthRippleController;
import com.android.systemui.biometrics.UdfpsController;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor;
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor;
import com.android.systemui.keyguard.shared.model.TransitionStep;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.StatusBarState;
@@ -65,6 +72,7 @@ import com.android.systemui.util.concurrency.DelayableExecutor;

import java.io.PrintWriter;
import java.util.Objects;
import java.util.function.Consumer;

import javax.inject.Inject;

@@ -101,6 +109,9 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
    @NonNull private CharSequence mLockedLabel;
    @NonNull private final VibratorHelper mVibrator;
    @Nullable private final AuthRippleController mAuthRippleController;
    @NonNull private final FeatureFlags mFeatureFlags;
    @NonNull private final KeyguardTransitionInteractor mTransitionInteractor;
    @NonNull private final KeyguardInteractor mKeyguardInteractor;

    // Tracks the velocity of a touch to help filter out the touches that move too fast.
    private VelocityTracker mVelocityTracker;
@@ -137,6 +148,20 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
    private boolean mDownDetected;
    private final Rect mSensorTouchLocation = new Rect();

    @VisibleForTesting
    final Consumer<TransitionStep> mDozeTransitionCallback = (TransitionStep step) -> {
        mInterpolatedDarkAmount = step.getValue();
        mView.setDozeAmount(step.getValue());
        updateBurnInOffsets();
    };

    @VisibleForTesting
    final Consumer<Boolean> mIsDozingCallback = (Boolean isDozing) -> {
        mIsDozing = isDozing;
        updateBurnInOffsets();
        updateVisibility();
    };

    @Inject
    public LockIconViewController(
            @Nullable LockIconView view,
@@ -152,7 +177,10 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
            @NonNull @Main DelayableExecutor executor,
            @NonNull VibratorHelper vibrator,
            @Nullable AuthRippleController authRippleController,
            @NonNull @Main Resources resources
            @NonNull @Main Resources resources,
            @NonNull KeyguardTransitionInteractor transitionInteractor,
            @NonNull KeyguardInteractor keyguardInteractor,
            @NonNull FeatureFlags featureFlags
    ) {
        super(view);
        mStatusBarStateController = statusBarStateController;
@@ -166,6 +194,9 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
        mExecutor = executor;
        mVibrator = vibrator;
        mAuthRippleController = authRippleController;
        mTransitionInteractor = transitionInteractor;
        mKeyguardInteractor = keyguardInteractor;
        mFeatureFlags = featureFlags;

        mMaxBurnInOffsetX = resources.getDimensionPixelSize(R.dimen.udfps_burn_in_offset_x);
        mMaxBurnInOffsetY = resources.getDimensionPixelSize(R.dimen.udfps_burn_in_offset_y);
@@ -182,6 +213,12 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
    @Override
    protected void onInit() {
        mView.setAccessibilityDelegate(mAccessibilityDelegate);

        if (mFeatureFlags.isEnabled(DOZING_MIGRATION_1)) {
            collectFlow(mView, mTransitionInteractor.getDozeAmountTransition(),
                    mDozeTransitionCallback);
            collectFlow(mView, mKeyguardInteractor.isDozing(), mIsDozingCallback);
        }
    }

    @Override
@@ -377,7 +414,10 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
        pw.println(" mShowUnlockIcon: " + mShowUnlockIcon);
        pw.println(" mShowLockIcon: " + mShowLockIcon);
        pw.println(" mShowAodUnlockedIcon: " + mShowAodUnlockedIcon);
        pw.println();
        pw.println(" mIsDozing: " + mIsDozing);
        pw.println(" isFlagEnabled(DOZING_MIGRATION_1): "
                + mFeatureFlags.isEnabled(DOZING_MIGRATION_1));
        pw.println(" mIsBouncerShowing: " + mIsBouncerShowing);
        pw.println(" mUserUnlockedWithBiometric: " + mUserUnlockedWithBiometric);
        pw.println(" mRunningFPS: " + mRunningFPS);
@@ -425,17 +465,21 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
            new StatusBarStateController.StateListener() {
                @Override
                public void onDozeAmountChanged(float linear, float eased) {
                    if (!mFeatureFlags.isEnabled(DOZING_MIGRATION_1)) {
                        mInterpolatedDarkAmount = eased;
                        mView.setDozeAmount(eased);
                        updateBurnInOffsets();
                    }
                }

                @Override
                public void onDozingChanged(boolean isDozing) {
                    if (!mFeatureFlags.isEnabled(DOZING_MIGRATION_1)) {
                        mIsDozing = isDozing;
                        updateBurnInOffsets();
                        updateVisibility();
                    }
                }

                @Override
                public void onStateChanged(int statusBarState) {
+6 −0
Original line number Diff line number Diff line
@@ -120,6 +120,12 @@ object Flags {
     */
    @JvmField val STEP_CLOCK_ANIMATION = UnreleasedFlag(212)

    /**
     * Migration from the legacy isDozing/dozeAmount paths to the new KeyguardTransitionRepository
     * will occur in stages. This is one stage of many to come.
     */
    @JvmField val DOZING_MIGRATION_1 = UnreleasedFlag(213, teamfood = true)

    // 300 - power menu
    // TODO(b/254512600): Tracking Bug
    @JvmField val POWER_MENU_LITE = ReleasedFlag(300)
+15 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
import com.android.systemui.keyguard.shared.model.TransitionStep
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge

/** Encapsulates business-logic related to the keyguard transitions. */
@SysUISingleton
@@ -34,4 +36,17 @@ constructor(
) {
    /** AOD->LOCKSCREEN transition information. */
    val aodToLockscreenTransition: Flow<TransitionStep> = repository.transition(AOD, LOCKSCREEN)

    /** LOCKSCREEN->AOD transition information. */
    val lockscreenToAodTransition: Flow<TransitionStep> = repository.transition(LOCKSCREEN, AOD)

    /**
     * AOD<->LOCKSCREEN transition information, mapped to dozeAmount range of AOD (1f) <->
     * Lockscreen (0f).
     */
    val dozeAmountTransition: Flow<TransitionStep> =
        merge(
            aodToLockscreenTransition.map { step -> step.copy(value = 1f - step.value) },
            lockscreenToAodTransition,
        )
}
+40 −0
Original line number Diff line number Diff line
/*
 *  Copyright (C) 2022 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.util.kotlin

import android.view.View
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.systemui.lifecycle.repeatWhenAttached
import java.util.function.Consumer
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect

/**
 * Collect information for the given [flow], calling [consumer] for each emitted event. Defaults to
 * [LifeCycle.State.CREATED] to better align with legacy ViewController usage of attaching listeners
 * during onViewAttached() and removing during onViewRemoved()
 */
@JvmOverloads
fun <T> collectFlow(
    view: View,
    flow: Flow<T>,
    consumer: Consumer<T>,
    state: Lifecycle.State = Lifecycle.State.CREATED,
) {
    view.repeatWhenAttached { repeatOnLifecycle(state) { flow.collect { consumer.accept(it) } } }
}
Loading