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

Commit 279d6e19 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Setup secure lock device repository and interactor" into main

parents f202aae8 250b588c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
        <permission name="android.permission.LOCATION_HARDWARE"/>
        <permission name="android.permission.MANAGE_DEBUGGING"/>
        <permission name="android.permission.MANAGE_GAME_MODE" />
        <permission name="android.permission.MANAGE_SECURE_LOCK_DEVICE"/>
        <permission name="android.permission.MANAGE_SENSOR_PRIVACY"/>
        <permission name="android.permission.MANAGE_USB"/>
        <permission name="android.permission.MANAGE_USERS"/>
+74 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.securelockdevice.data.repository

import android.platform.test.annotations.EnableFlags
import android.security.Flags.FLAG_SECURE_LOCK_DEVICE
import android.security.authenticationpolicy.AuthenticationPolicyManager
import android.security.authenticationpolicy.authenticationPolicyManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.withArgCaptor
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.verify
import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoRule
import org.mockito.kotlin.any

@SmallTest
@RunWith(AndroidJUnit4::class)
@EnableFlags(FLAG_SECURE_LOCK_DEVICE)
class SecureLockDeviceRepositoryTest : SysuiTestCase() {
    @JvmField @Rule var mockitoRule: MockitoRule = MockitoJUnit.rule()

    private val kosmos = testKosmos()
    private val underTest: SecureLockDeviceRepository = kosmos.realSecureLockDeviceRepository

    @Test
    fun updatesSecureLockDeviceEnabledStatus_fromAuthenticationPolicyManager() =
        kosmos.testScope.runTest {
            val isSecureLockDeviceEnabled by collectLastValue(underTest.isSecureLockDeviceEnabled)
            runCurrent()

            val listener = kosmos.authenticationPolicyManager.captureListener()
            runCurrent()

            assertThat(isSecureLockDeviceEnabled).isEqualTo(false)

            listener.onSecureLockDeviceEnabledStatusChanged(true)

            assertThat(isSecureLockDeviceEnabled).isEqualTo(true)

            listener.onSecureLockDeviceEnabledStatusChanged(false)

            assertThat(isSecureLockDeviceEnabled).isEqualTo(false)
        }
}

private fun AuthenticationPolicyManager.captureListener() =
    withArgCaptor<AuthenticationPolicyManager.SecureLockDeviceStatusListener> {
        verify(this@captureListener).registerSecureLockDeviceStatusListener(any(), capture())
    }
+8 −0
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ import android.os.Vibrator;
import android.os.storage.StorageManager;
import android.permission.PermissionManager;
import android.safetycenter.SafetyCenterManager;
import android.security.authenticationpolicy.AuthenticationPolicyManager;
import android.service.dreams.DreamService;
import android.service.dreams.IDreamManager;
import android.service.vr.IVrManager;
@@ -194,6 +195,13 @@ public class FrameworkServicesModule {
        return context.getSystemService(AudioManager.class);
    }

    @Provides
    @Singleton
    @Nullable
    static AuthenticationPolicyManager provideAuthenticationPolicyManager(Context context) {
        return context.getSystemService(AuthenticationPolicyManager.class);
    }

    @Provides
    @Singleton
    static CaptioningManager provideCaptioningManager(Context context) {
+2 −0
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ import com.android.systemui.scene.ui.view.WindowRootViewComponent;
import com.android.systemui.screencapture.common.ScreenCaptureModule;
import com.android.systemui.screenrecord.ScreenRecordModule;
import com.android.systemui.screenshot.dagger.ScreenshotModule;
import com.android.systemui.securelockdevice.dagger.SecureLockDeviceModule;
import com.android.systemui.security.data.repository.SecurityRepositoryModule;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.shade.ShadeController;
@@ -272,6 +273,7 @@ import javax.inject.Named;
        RetailModeModule.class,
        ScreenBrightnessModule.class,
        ScreenshotModule.class,
        SecureLockDeviceModule.class,
        SensorModule.class,
        SecurityRepositoryModule.class,
        ScreenCaptureModule.class,
+59 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.securelockdevice.dagger

import android.security.authenticationpolicy.AuthenticationPolicyManager
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.keyguard.data.repository.BiometricSettingsRepository
import com.android.systemui.securelockdevice.data.repository.SecureLockDeviceRepository
import com.android.systemui.securelockdevice.data.repository.SecureLockDeviceRepositoryImpl
import com.android.systemui.securelockdevice.domain.interactor.SecureLockDeviceInteractor
import dagger.Module
import dagger.Provides
import java.util.concurrent.Executor
import kotlinx.coroutines.CoroutineScope

@Module
interface SecureLockDeviceModule {

    companion object {
        @Provides
        @SysUISingleton
        fun providesSecureLockDeviceRepository(
            @Background backgroundExecutor: Executor,
            authenticationPolicyManager: AuthenticationPolicyManager?,
        ): SecureLockDeviceRepository {
            return SecureLockDeviceRepositoryImpl(
                backgroundExecutor = backgroundExecutor,
                authenticationPolicyManager = authenticationPolicyManager,
            )
        }

        @Provides
        @SysUISingleton
        fun providesSecureLockDeviceInteractor(
            @Application applicationScope: CoroutineScope,
            secureLockDeviceRepository: SecureLockDeviceRepository,
        ): SecureLockDeviceInteractor {
            return SecureLockDeviceInteractor(
                applicationScope = applicationScope,
                secureLockDeviceRepository = secureLockDeviceRepository,
            )
        }
    }
}
Loading