1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.bouncer.data.repository 18 19 import android.content.Context 20 import android.provider.Settings.Global.ONE_HANDED_KEYGUARD_SIDE 21 import com.android.systemui.authentication.shared.model.BouncerInputSide 22 import com.android.systemui.authentication.shared.model.toBouncerInputSide 23 import com.android.systemui.dagger.SysUISingleton 24 import com.android.systemui.dagger.qualifiers.Application 25 import com.android.systemui.flags.FeatureFlagsClassic 26 import com.android.systemui.flags.Flags 27 import com.android.systemui.res.R 28 import com.android.systemui.util.settings.GlobalSettings 29 import javax.inject.Inject 30 import kotlinx.coroutines.flow.MutableStateFlow 31 32 /** Provides access to bouncer-related application state. */ 33 @SysUISingleton 34 class BouncerRepository 35 @Inject 36 constructor( 37 @Application private val applicationContext: Context, 38 private val globalSettings: GlobalSettings, 39 private val flags: FeatureFlagsClassic, 40 ) { 41 val scale: MutableStateFlow<Float> = MutableStateFlow(1.0f) 42 43 /** Whether the user switcher should be displayed within the bouncer UI on large screens. */ 44 val isUserSwitcherEnabledInConfig: Boolean 45 get() = 46 applicationContext.resources.getBoolean(R.bool.config_enableBouncerUserSwitcher) && 47 flags.isEnabled(Flags.FULL_SCREEN_USER_SWITCHER) 48 49 /** Whether the one handed bouncer is supported for this device. */ 50 val isOneHandedBouncerSupportedInConfig: Boolean 51 get() = applicationContext.resources.getBoolean(R.bool.can_use_one_handed_bouncer) 52 53 /** 54 * Preferred side of the screen where the input area on the bouncer should be. This is 55 * applicable for large screen devices (foldables and tablets). 56 */ 57 val preferredBouncerInputSide: MutableStateFlow<BouncerInputSide?> = 58 MutableStateFlow(getPreferredInputSideSetting()) 59 60 /** X coordinate of the last recorded touch position on the lockscreen. */ 61 val lastRecordedLockscreenTouchPosition = MutableStateFlow<Float?>(null) 62 63 /** Save the preferred bouncer input side. */ setPreferredBouncerInputSidenull64 fun setPreferredBouncerInputSide(inputSide: BouncerInputSide) { 65 globalSettings.putInt(ONE_HANDED_KEYGUARD_SIDE, inputSide.settingValue) 66 // used to only trigger another emission on the flow. 67 preferredBouncerInputSide.value = inputSide 68 } 69 70 /** 71 * Record the x coordinate of the last touch position on the lockscreen. This will be used to 72 * determine which side of the bouncer the input area should be shown. 73 */ recordLockscreenTouchPositionnull74 fun recordLockscreenTouchPosition(x: Float) { 75 lastRecordedLockscreenTouchPosition.value = x 76 } 77 getPreferredInputSideSettingnull78 fun getPreferredInputSideSetting(): BouncerInputSide? { 79 return globalSettings.getInt(ONE_HANDED_KEYGUARD_SIDE, -1).toBouncerInputSide() 80 } 81 } 82