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

Commit 5c886588 authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

KeyguardBottomAreaView new impl. - domain layer

- In this second CL in the series, we create the domain layer that will power
the new implementation of KeyguardBottomAreaView
- On its own, this CL doesn't do anything and nothing is using it
- The domain layer contains both the use-cases and models for them
- Use-cases serve as reusable pieces of business logic
- Most use-cases are trivial

Bug: 235403546
Test: Unit tests are included for non-trivial use-cases only. Also manually verified that the bottom area behaves as expected once the
entire CL chain is compiled together

Change-Id: I21434e24f562d7f974ac32e7b72284b2b9c3051f
parent 39fcf4f8
Loading
Loading
Loading
Loading
+34 −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.common.domain.model

import com.android.systemui.common.data.model.Position as DataLayerPosition

/** Models a two-dimensional position */
data class Position(
    val x: Int,
    val y: Int,
) {
    companion object {
        fun DataLayerPosition.toDomainLayer(): Position {
            return Position(
                x = x,
                y = y,
            )
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import com.android.systemui.keyguard.DismissCallbackRegistry;
import com.android.systemui.keyguard.KeyguardUnlockAnimationController;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.keyguard.data.repository.KeyguardRepositoryModule;
import com.android.systemui.keyguard.domain.usecase.KeyguardUseCaseModule;
import com.android.systemui.navigationbar.NavigationModeController;
import com.android.systemui.statusbar.NotificationShadeDepthController;
import com.android.systemui.statusbar.NotificationShadeWindowController;
@@ -70,6 +71,7 @@ import dagger.Provides;
        includes = {
            FalsingModule.class,
            KeyguardRepositoryModule.class,
            KeyguardUseCaseModule.class,
        })
public class KeyguardModule {
    /**
+29 −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.keyguard.domain.usecase

import dagger.Binds
import dagger.Module

@Module
interface KeyguardUseCaseModule {

    @Binds
    fun launchQuickAffordance(
        impl: LaunchKeyguardQuickAffordanceUseCaseImpl
    ): LaunchKeyguardQuickAffordanceUseCase
}
+76 −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.keyguard.domain.usecase

import android.content.Intent
import com.android.internal.widget.LockPatternUtils
import com.android.internal.widget.LockPatternUtils.StrongAuthTracker.StrongAuthFlags
import com.android.systemui.animation.ActivityLaunchAnimator
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.settings.UserTracker
import com.android.systemui.statusbar.policy.KeyguardStateController
import javax.inject.Inject

/** Defines interface for classes that can launch a quick affordance. */
interface LaunchKeyguardQuickAffordanceUseCase {
    operator fun invoke(
        intent: Intent,
        canShowWhileLocked: Boolean,
        animationController: ActivityLaunchAnimator.Controller?,
    )
}

/** Real implementation of [LaunchKeyguardQuickAffordanceUseCase] */
class LaunchKeyguardQuickAffordanceUseCaseImpl
@Inject
constructor(
    private val lockPatternUtils: LockPatternUtils,
    private val keyguardStateController: KeyguardStateController,
    private val userTracker: UserTracker,
    private val activityStarter: ActivityStarter,
) : LaunchKeyguardQuickAffordanceUseCase {
    override operator fun invoke(
        intent: Intent,
        canShowWhileLocked: Boolean,
        animationController: ActivityLaunchAnimator.Controller?,
    ) {
        @StrongAuthFlags
        val strongAuthFlags =
            lockPatternUtils.getStrongAuthForUser(userTracker.userHandle.identifier)
        val needsToUnlockFirst =
            when {
                strongAuthFlags ==
                    LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT -> true
                !canShowWhileLocked && !keyguardStateController.isUnlocked -> true
                else -> false
            }
        if (needsToUnlockFirst) {
            activityStarter.postStartActivityDismissingKeyguard(
                intent,
                0 /* delay */,
                animationController
            )
        } else {
            activityStarter.startActivity(
                intent,
                true /* dismissShade */,
                animationController,
                true /* showOverLockscreenWhenLocked */,
            )
        }
    }
}
+32 −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.keyguard.domain.usecase

import com.android.systemui.keyguard.data.repository.KeyguardRepository
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow

/** Use-case for observing whether doze state transitions should animate the bottom area */
class ObserveAnimateBottomAreaTransitionsUseCase
@Inject
constructor(
    private val repository: KeyguardRepository,
) {
    operator fun invoke(): Flow<Boolean> {
        return repository.animateBottomAreaDozingTransitions
    }
}
Loading