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.wallpaper.testing
18 
19 import android.content.Context
20 import android.net.Uri
21 import com.android.wallpaper.model.LiveWallpaperInfo
22 import com.android.wallpaper.model.WallpaperInfo
23 import com.android.wallpaper.picker.data.WallpaperModel
24 import com.android.wallpaper.util.converter.WallpaperModelFactory
25 import javax.inject.Inject
26 import javax.inject.Singleton
27 
28 @Singleton
29 class FakeDefaultWallpaperModelFactory @Inject constructor() : WallpaperModelFactory {
30 
31     private var staticWallpaperModel: WallpaperModel? = null
32     private var liveWallpaperModel: WallpaperModel? = null
33 
getWallpaperModelnull34     override fun getWallpaperModel(context: Context, wallpaperInfo: WallpaperInfo): WallpaperModel {
35         return when (wallpaperInfo) {
36             is LiveWallpaperInfo -> {
37                 liveWallpaperModel
38                     ?: WallpaperModelUtils.getLiveWallpaperModel(
39                             wallpaperId = "testWallpaperId",
40                             collectionId = "testCollectionId",
41                             systemWallpaperInfo = wallpaperInfo.info,
42                         )
43                         .also { liveWallpaperModel = it }
44             }
45             else -> {
46                 staticWallpaperModel
47                     ?: WallpaperModelUtils.getStaticWallpaperModel(
48                             wallpaperId = "testWallpaperId",
49                             collectionId = "testCollection",
50                             imageWallpaperUri = Uri.parse("content://com.test/image")
51                         )
52                         .also { staticWallpaperModel = it }
53             }
54         }
55     }
56 
getStaticWallpaperModelnull57     fun getStaticWallpaperModel(): WallpaperModel? {
58         return staticWallpaperModel
59     }
60 
setStaticWallpaperModelnull61     fun setStaticWallpaperModel(model: WallpaperModel) {
62         staticWallpaperModel = model
63     }
64 
getLiveWallpaperModelnull65     fun getLiveWallpaperModel(): WallpaperModel? {
66         return liveWallpaperModel
67     }
68 
setLiveWallpaperModelnull69     fun setLiveWallpaperModel(model: WallpaperModel) {
70         liveWallpaperModel = model
71     }
72 }
73