blob: 558c3cb7e9bd49ec08e9aa44008acac65a256f5b [file] [log] [blame]
Santiago Etchebehere8cad0dd2019-10-17 10:52:39 -07001/*
2 * Copyright (C) 2019 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 */
16package com.android.wallpaper.testing;
17
18
19import android.app.WallpaperManager;
20import android.content.Context;
Colin Cross1b7f2082021-05-21 11:15:20 -070021import android.os.Build;
Santiago Etchebehere8cad0dd2019-10-17 10:52:39 -070022
Santiago Etchebehere8cad0dd2019-10-17 10:52:39 -070023import com.android.wallpaper.model.WallpaperMetadata;
24import com.android.wallpaper.module.InjectorProvider;
25import com.android.wallpaper.module.WallpaperPreferences;
26import com.android.wallpaper.module.WallpaperRefresher;
27
28/**
29 * Test implementation of {@link WallpaperRefresher} which simply provides whatever metadata is
30 * saved in WallpaperPreferences and the image wallpaper set to {@link WallpaperManager}.
31 */
32public class TestWallpaperRefresher implements WallpaperRefresher {
33
34 private final Context mAppContext;
35
36 /**
37 * @param context The application's context.
38 */
39 public TestWallpaperRefresher(Context context) {
40 mAppContext = context.getApplicationContext();
41 }
42
43 @Override
44 public void refresh(RefreshListener listener) {
45
46 WallpaperPreferences prefs = InjectorProvider.getInjector().getPreferences(mAppContext);
47
Colin Cross1b7f2082021-05-21 11:15:20 -070048 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && prefs.getLockWallpaperId() > 0) {
Santiago Etchebehere8cad0dd2019-10-17 10:52:39 -070049 listener.onRefreshed(
50 new WallpaperMetadata(
51 prefs.getHomeWallpaperAttributions(),
52 prefs.getHomeWallpaperActionUrl(),
53 prefs.getHomeWallpaperActionLabelRes(),
54 prefs.getHomeWallpaperActionIconRes(),
55 prefs.getHomeWallpaperCollectionId(),
56 prefs.getHomeWallpaperBackingFileName(),
57 null /* wallpaperComponent */),
58 new WallpaperMetadata(
59 prefs.getLockWallpaperAttributions(),
60 prefs.getLockWallpaperActionUrl(),
61 prefs.getLockWallpaperActionLabelRes(),
62 prefs.getLockWallpaperActionIconRes(),
63 prefs.getLockWallpaperCollectionId(),
64 prefs.getLockWallpaperBackingFileName(),
65 null /* wallpaperComponent */),
66 prefs.getWallpaperPresentationMode());
67 } else {
68 listener.onRefreshed(
69 new WallpaperMetadata(
70 prefs.getHomeWallpaperAttributions(),
71 prefs.getHomeWallpaperActionUrl(),
72 prefs.getHomeWallpaperActionLabelRes(),
73 prefs.getHomeWallpaperActionIconRes(),
74 prefs.getHomeWallpaperCollectionId(),
75 prefs.getHomeWallpaperBackingFileName(),
76 null /* wallpaperComponent */),
77 null,
78 prefs.getWallpaperPresentationMode());
79 }
80 }
81}