1 /*
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.O
15  */
16 package com.android.wallpaper.testing;
17 
18 
19 import android.app.WallpaperManager;
20 import android.content.Context;
21 
22 import com.android.wallpaper.model.WallpaperMetadata;
23 import com.android.wallpaper.module.InjectorProvider;
24 import com.android.wallpaper.module.WallpaperPreferences;
25 import com.android.wallpaper.module.WallpaperRefresher;
26 
27 /**
28  * Test implementation of {@link WallpaperRefresher} which simply provides whatever metadata is
29  * saved in WallpaperPreferences and the image wallpaper set to {@link WallpaperManager}.
30  */
31 public class TestWallpaperRefresher implements WallpaperRefresher {
32 
33     private final Context mAppContext;
34 
35     /**
36      * @param context The application's context.
37      */
TestWallpaperRefresher(Context context)38     public TestWallpaperRefresher(Context context) {
39         mAppContext = context.getApplicationContext();
40     }
41 
42     @Override
refresh(RefreshListener listener)43     public void refresh(RefreshListener listener) {
44 
45         WallpaperPreferences prefs = InjectorProvider.getInjector().getPreferences(mAppContext);
46 
47         if (prefs.getLockWallpaperManagerId() > 0) {
48             listener.onRefreshed(
49                     new WallpaperMetadata(
50                             prefs.getHomeWallpaperAttributions(),
51                             prefs.getHomeWallpaperActionUrl(),
52                             prefs.getHomeWallpaperCollectionId(),
53                             /* wallpaperComponent */ null,
54                             /* cropHints= */ null),
55                     new WallpaperMetadata(
56                             prefs.getLockWallpaperAttributions(),
57                             prefs.getLockWallpaperActionUrl(),
58                             prefs.getLockWallpaperCollectionId(),
59                             /* wallpaperComponent */ null,
60                             /* cropHints= */ null),
61                     prefs.getWallpaperPresentationMode());
62         } else {
63             listener.onRefreshed(
64                     new WallpaperMetadata(
65                             prefs.getHomeWallpaperAttributions(),
66                             prefs.getHomeWallpaperActionUrl(),
67                             prefs.getHomeWallpaperCollectionId(),
68                             /* wallpaperComponent */ null,
69                             /* cropHints= */ null),
70                     null,
71                     prefs.getWallpaperPresentationMode());
72         }
73     }
74 }
75