1 /* 2 * Copyright (C) 2024 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.settings 18 19 import android.content.ContentResolver 20 import com.android.systemui.Flags 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.dagger.qualifiers.Background 23 import com.android.systemui.shared.settings.data.repository.SecureSettingsRepository 24 import com.android.systemui.shared.settings.data.repository.SecureSettingsRepositoryImpl 25 import com.android.systemui.shared.settings.data.repository.SystemSettingsRepository 26 import com.android.systemui.shared.settings.data.repository.SystemSettingsRepositoryImpl 27 import com.android.systemui.user.data.repository.UserRepository 28 import com.android.systemui.util.settings.SecureSettings 29 import com.android.systemui.util.settings.SystemSettings 30 import com.android.systemui.util.settings.repository.UserAwareSecureSettingsRepository 31 import com.android.systemui.util.settings.repository.UserAwareSystemSettingsRepository 32 import dagger.Lazy 33 import dagger.Module 34 import dagger.Provides 35 import kotlin.coroutines.CoroutineContext 36 import kotlinx.coroutines.CoroutineDispatcher 37 38 @Module 39 object UserSettingsRepositoryModule { 40 @JvmStatic 41 @Provides 42 @SysUISingleton provideSecureSettingsRepositorynull43 fun provideSecureSettingsRepository( 44 secureSettings: Lazy<SecureSettings>, 45 userRepository: Lazy<UserRepository>, 46 contentResolver: Lazy<ContentResolver>, 47 @Background backgroundDispatcher: CoroutineDispatcher, 48 @Background backgroundContext: CoroutineContext, 49 ): SecureSettingsRepository { 50 return if (Flags.userAwareSettingsRepositories()) { 51 UserAwareSecureSettingsRepository( 52 secureSettings.get(), 53 userRepository.get(), 54 backgroundDispatcher, 55 backgroundContext, 56 ) 57 } else { 58 SecureSettingsRepositoryImpl(contentResolver.get(), backgroundDispatcher) 59 } 60 } 61 62 @JvmStatic 63 @Provides 64 @SysUISingleton provideSystemSettingsRepositorynull65 fun provideSystemSettingsRepository( 66 systemSettings: Lazy<SystemSettings>, 67 userRepository: Lazy<UserRepository>, 68 contentResolver: Lazy<ContentResolver>, 69 @Background backgroundDispatcher: CoroutineDispatcher, 70 @Background backgroundContext: CoroutineContext, 71 ): SystemSettingsRepository { 72 return if (Flags.userAwareSettingsRepositories()) { 73 UserAwareSystemSettingsRepository( 74 systemSettings.get(), 75 userRepository.get(), 76 backgroundDispatcher, 77 backgroundContext, 78 ) 79 } else { 80 SystemSettingsRepositoryImpl(contentResolver.get(), backgroundDispatcher) 81 } 82 } 83 } 84