1 /* 2 * Copyright (C) 2018 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.module; 17 18 import android.content.Context; 19 20 import com.android.wallpaper.model.CategoryProvider; 21 import com.android.wallpaper.model.WallpaperInfo; 22 import com.android.wallpaper.monitor.PerformanceMonitor; 23 import com.android.wallpaper.picker.PreviewFragment; 24 25 import androidx.fragment.app.Fragment; 26 27 /** 28 * A concrete, real implementation of the dependency provider. 29 */ 30 public class WallpapersInjector extends BaseWallpaperInjector { 31 private CategoryProvider mCategoryProvider; 32 private UserEventLogger mUserEventLogger; 33 private WallpaperRotationRefresher mWallpaperRotationRefresher; 34 private PerformanceMonitor mPerformanceMonitor; 35 36 @Override getCategoryProvider(Context context)37 public synchronized CategoryProvider getCategoryProvider(Context context) { 38 if (mCategoryProvider == null) { 39 mCategoryProvider = new DefaultCategoryProvider(context.getApplicationContext()); 40 } 41 return mCategoryProvider; 42 } 43 44 @Override getUserEventLogger(Context context)45 public synchronized UserEventLogger getUserEventLogger(Context context) { 46 if (mUserEventLogger == null) { 47 mUserEventLogger = new NoOpUserEventLogger(); 48 } 49 return mUserEventLogger; 50 } 51 52 @Override getWallpaperRotationRefresher()53 public synchronized WallpaperRotationRefresher getWallpaperRotationRefresher() { 54 if (mWallpaperRotationRefresher == null) { 55 mWallpaperRotationRefresher = new WallpaperRotationRefresher() { 56 @Override 57 public void refreshWallpaper(Context context, Listener listener) { 58 // Not implemented 59 listener.onError(); 60 } 61 }; 62 } 63 return mWallpaperRotationRefresher; 64 } 65 66 @Override getPreviewFragment( Context context, WallpaperInfo wallpaperInfo, int mode, boolean testingModeEnabled)67 public Fragment getPreviewFragment( 68 Context context, 69 WallpaperInfo wallpaperInfo, 70 int mode, 71 boolean testingModeEnabled) { 72 return PreviewFragment.newInstance(wallpaperInfo, mode, testingModeEnabled); 73 } 74 75 @Override getPerformanceMonitor()76 public synchronized PerformanceMonitor getPerformanceMonitor() { 77 if (mPerformanceMonitor == null) { 78 mPerformanceMonitor = new PerformanceMonitor() { 79 @Override 80 public void recordFullResPreviewLoadedMemorySnapshot() { 81 // No Op 82 } 83 }; 84 } 85 return mPerformanceMonitor; 86 } 87 88 @Override getLoggingOptInStatusProvider(Context context)89 public synchronized LoggingOptInStatusProvider getLoggingOptInStatusProvider(Context context) { 90 return null; 91 } 92 } 93