• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.wallpaper.testing
17 
18 import android.app.WallpaperManager
19 import android.content.Context
20 import android.net.Uri
21 import com.android.wallpaper.asset.Asset
22 import com.android.wallpaper.model.CurrentWallpaperInfo
23 import java.util.concurrent.atomic.AtomicReference
24 
25 /**
26  * Minimal fake of [CurrentWallpaperInfo] for testing, initially created for use in
27  * DefaultGoogleWallpaperPreferencesTest.
28  */
29 class FakeCurrentWallpaperInfo(
30     attributions: List<String?>?,
31     actionUrl: String?,
32     collectionId: String?,
33     @WallpaperManager.SetWallpaperFlags wallpaperManagerFlag: Int,
34     private val pixelColor: Int,
35     private val id: String,
36     imageWallpaperUri: Uri? = null,
37 ) :
38     CurrentWallpaperInfo(
39         attributions,
40         actionUrl,
41         collectionId,
42         wallpaperManagerFlag,
43         imageWallpaperUri,
44     ) {
45     private var asset = AtomicReference<TestAsset>()
46 
47     constructor(
48         pixelColor: Int,
49         id: String,
50     ) : this(emptyList(), "", "", WallpaperManager.FLAG_SYSTEM, pixelColor, id)
51 
getAssetnull52     override fun getAsset(context: Context): Asset {
53         return asset.updateAndGet { it ?: TestAsset(pixelColor, false) }
54     }
55 
getWallpaperIdnull56     override fun getWallpaperId(): String {
57         return id
58     }
59 }
60