/* * 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.statusbar.policy import android.app.admin.DeviceAdminInfo import android.content.ComponentName import android.graphics.drawable.Drawable import com.android.systemui.supervision.data.model.SupervisionModel import java.io.PrintWriter /** A fake [SecurityController] to be used in tests. */ class FakeSecurityController(private val fakeState: FakeState = FakeState()) : SecurityController { private val callbacks = LinkedHashSet() override fun addCallback(callback: SecurityController.SecurityControllerCallback) { callbacks.add(callback) } override fun removeCallback(callback: SecurityController.SecurityControllerCallback) { callbacks.remove(callback) } /** Update [fakeState], then notify the callbacks. */ fun updateState(f: FakeState.() -> Unit) { fakeState.f() callbacks.forEach { it.onStateChanged() } } override fun dump(pw: PrintWriter, args: Array) {} override fun isDeviceManaged(): Boolean = fakeState.isDeviceManaged override fun hasProfileOwner(): Boolean = fakeState.hasProfileOwner override fun hasWorkProfile(): Boolean = fakeState.hasWorkProfile override fun isWorkProfileOn(): Boolean = fakeState.isWorkProfileOn override fun isProfileOwnerOfOrganizationOwnedDevice(): Boolean = fakeState.isProfileOwnerOfOrganizationOwnedDevice override fun getDeviceOwnerName(): String? = fakeState.deviceOwnerName override fun getProfileOwnerName(): String? = fakeState.profileOwnerName override fun getDeviceOwnerOrganizationName(): String? = fakeState.deviceOwnerOrganizationName override fun getWorkProfileOrganizationName(): String? = fakeState.workProfileOrganizationName override fun getDeviceOwnerComponentOnAnyUser(): ComponentName? = fakeState.deviceOwnerComponentOnAnyUser override fun isFinancedDevice(): Boolean = false override fun isNetworkLoggingEnabled(): Boolean = fakeState.isNetworkLoggingEnabled override fun isVpnEnabled(): Boolean = fakeState.isVpnEnabled override fun isVpnRestricted(): Boolean = fakeState.isVpnRestricted override fun isVpnBranded(): Boolean = fakeState.isVpnBranded override fun isVpnValidated(): Boolean = fakeState.isVpnValidated override fun getPrimaryVpnName(): String? = fakeState.primaryVpnName override fun getWorkProfileVpnName(): String? = fakeState.workProfileVpnName override fun hasCACertInCurrentUser(): Boolean = fakeState.hasCACertInCurrentUser override fun hasCACertInWorkProfile(): Boolean = fakeState.hasCACertInWorkProfile override fun onUserSwitched(newUserId: Int) {} override fun isParentalControlsEnabled(): Boolean = fakeState.isParentalControlsEnabled override fun getDeviceAdminInfo(): DeviceAdminInfo? = null override fun getIcon(info: DeviceAdminInfo?): Drawable? = null override fun getIcon(): Drawable? = null override fun getLabel(info: DeviceAdminInfo?): CharSequence? = null override fun getLabel(): CharSequence? = null override fun getSupervisionModel(): SupervisionModel? = fakeState.supervisionModel override fun setSupervisionModel(supervisionModel: SupervisionModel?) { fakeState.supervisionModel = supervisionModel } class FakeState( var isDeviceManaged: Boolean = false, var hasProfileOwner: Boolean = false, var hasWorkProfile: Boolean = false, var isWorkProfileOn: Boolean = false, var isProfileOwnerOfOrganizationOwnedDevice: Boolean = false, var deviceOwnerName: String? = null, var profileOwnerName: String? = null, var deviceOwnerOrganizationName: String? = null, var workProfileOrganizationName: String? = null, var deviceOwnerComponentOnAnyUser: ComponentName? = null, var isNetworkLoggingEnabled: Boolean = false, var isVpnEnabled: Boolean = false, var isVpnRestricted: Boolean = false, var isVpnBranded: Boolean = false, var isVpnValidated: Boolean = false, var primaryVpnName: String? = null, var workProfileVpnName: String? = null, var hasCACertInCurrentUser: Boolean = false, var hasCACertInWorkProfile: Boolean = false, var isParentalControlsEnabled: Boolean = false, var supervisionModel: SupervisionModel? = null, ) }