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. 15 */ 16 package com.android.customization.module; 17 18 import android.content.Context; 19 20 import androidx.fragment.app.Fragment; 21 import androidx.fragment.app.FragmentActivity; 22 23 import com.android.customization.model.theme.OverlayManagerCompat; 24 import com.android.customization.model.theme.ThemeBundleProvider; 25 import com.android.customization.model.theme.ThemeManager; 26 import com.android.wallpaper.model.CategoryProvider; 27 import com.android.wallpaper.model.WallpaperInfo; 28 import com.android.wallpaper.module.BaseWallpaperInjector; 29 import com.android.wallpaper.module.DefaultCategoryProvider; 30 import com.android.wallpaper.module.LoggingOptInStatusProvider; 31 import com.android.wallpaper.module.WallpaperPreferences; 32 import com.android.wallpaper.module.WallpaperRotationRefresher; 33 import com.android.wallpaper.module.WallpaperSetter; 34 import com.android.wallpaper.monitor.PerformanceMonitor; 35 import com.android.wallpaper.picker.PreviewFragment; 36 37 public class DefaultCustomizationInjector extends BaseWallpaperInjector 38 implements CustomizationInjector { 39 private CategoryProvider mCategoryProvider; 40 private ThemesUserEventLogger mUserEventLogger; 41 private WallpaperRotationRefresher mWallpaperRotationRefresher; 42 private PerformanceMonitor mPerformanceMonitor; 43 private WallpaperPreferences mPrefs; 44 45 @Override getPreferences(Context context)46 public synchronized WallpaperPreferences getPreferences(Context context) { 47 if (mPrefs == null) { 48 mPrefs = new DefaultCustomizationPreferences(context.getApplicationContext()); 49 } 50 return mPrefs; 51 } 52 53 54 @Override getCustomizationPreferences(Context context)55 public CustomizationPreferences getCustomizationPreferences(Context context) { 56 return (CustomizationPreferences) getPreferences(context); 57 } 58 59 @Override getCategoryProvider(Context context)60 public synchronized CategoryProvider getCategoryProvider(Context context) { 61 if (mCategoryProvider == null) { 62 mCategoryProvider = new DefaultCategoryProvider(context.getApplicationContext()); 63 } 64 return mCategoryProvider; 65 } 66 67 @Override getUserEventLogger(Context context)68 public synchronized ThemesUserEventLogger getUserEventLogger(Context context) { 69 if (mUserEventLogger == null) { 70 mUserEventLogger = new StatsLogUserEventLogger(); 71 } 72 return mUserEventLogger; 73 } 74 75 @Override getWallpaperRotationRefresher()76 public synchronized WallpaperRotationRefresher getWallpaperRotationRefresher() { 77 if (mWallpaperRotationRefresher == null) { 78 mWallpaperRotationRefresher = new WallpaperRotationRefresher() { 79 @Override 80 public void refreshWallpaper(Context context, Listener listener) { 81 // Not implemented 82 listener.onError(); 83 } 84 }; 85 } 86 return mWallpaperRotationRefresher; 87 } 88 89 @Override getPreviewFragment( Context context, WallpaperInfo wallpaperInfo, int mode, boolean testingModeEnabled)90 public Fragment getPreviewFragment( 91 Context context, 92 WallpaperInfo wallpaperInfo, 93 int mode, 94 boolean testingModeEnabled) { 95 return PreviewFragment.newInstance(wallpaperInfo, mode, testingModeEnabled); 96 } 97 98 @Override getPerformanceMonitor()99 public synchronized PerformanceMonitor getPerformanceMonitor() { 100 if (mPerformanceMonitor == null) { 101 mPerformanceMonitor = new PerformanceMonitor() { 102 @Override 103 public void recordFullResPreviewLoadedMemorySnapshot() { 104 // No Op 105 } 106 }; 107 } 108 return mPerformanceMonitor; 109 } 110 111 @Override getLoggingOptInStatusProvider(Context context)112 public synchronized LoggingOptInStatusProvider getLoggingOptInStatusProvider(Context context) { 113 return null; 114 } 115 116 @Override getThemeManager(ThemeBundleProvider provider, FragmentActivity activity, WallpaperSetter wallpaperSetter, OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger)117 public ThemeManager getThemeManager(ThemeBundleProvider provider, FragmentActivity activity, 118 WallpaperSetter wallpaperSetter, OverlayManagerCompat overlayManagerCompat, 119 ThemesUserEventLogger logger) { 120 return new ThemeManager(provider, activity, wallpaperSetter, overlayManagerCompat, logger); 121 } 122 123 } 124