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 import android.content.Intent; 20 import android.net.Uri; 21 22 import androidx.fragment.app.Fragment; 23 import androidx.fragment.app.FragmentActivity; 24 25 import com.android.customization.model.theme.OverlayManagerCompat; 26 import com.android.customization.model.theme.ThemeBundleProvider; 27 import com.android.customization.model.theme.ThemeManager; 28 import com.android.wallpaper.model.CategoryProvider; 29 import com.android.wallpaper.model.WallpaperInfo; 30 import com.android.wallpaper.module.BaseWallpaperInjector; 31 import com.android.wallpaper.module.CustomizationSections; 32 import com.android.wallpaper.module.DefaultCategoryProvider; 33 import com.android.wallpaper.module.LoggingOptInStatusProvider; 34 import com.android.wallpaper.module.WallpaperPreferences; 35 import com.android.wallpaper.module.WallpaperRotationRefresher; 36 import com.android.wallpaper.monitor.PerformanceMonitor; 37 import com.android.wallpaper.picker.CustomizationPickerActivity; 38 import com.android.wallpaper.picker.PreviewFragment; 39 40 public class DefaultCustomizationInjector extends BaseWallpaperInjector 41 implements CustomizationInjector { 42 private CategoryProvider mCategoryProvider; 43 private ThemesUserEventLogger mUserEventLogger; 44 private WallpaperRotationRefresher mWallpaperRotationRefresher; 45 private PerformanceMonitor mPerformanceMonitor; 46 private WallpaperPreferences mPrefs; 47 private CustomizationSections mCustomizationSections; 48 49 @Override getPreferences(Context context)50 public synchronized WallpaperPreferences getPreferences(Context context) { 51 if (mPrefs == null) { 52 mPrefs = new DefaultCustomizationPreferences(context.getApplicationContext()); 53 } 54 return mPrefs; 55 } 56 57 @Override getCustomizationPreferences(Context context)58 public CustomizationPreferences getCustomizationPreferences(Context context) { 59 return (CustomizationPreferences) getPreferences(context); 60 } 61 62 @Override getCategoryProvider(Context context)63 public synchronized CategoryProvider getCategoryProvider(Context context) { 64 if (mCategoryProvider == null) { 65 mCategoryProvider = new DefaultCategoryProvider(context.getApplicationContext()); 66 } 67 return mCategoryProvider; 68 } 69 70 @Override getUserEventLogger(Context context)71 public synchronized ThemesUserEventLogger getUserEventLogger(Context context) { 72 if (mUserEventLogger == null) { 73 mUserEventLogger = new StatsLogUserEventLogger(); 74 } 75 return mUserEventLogger; 76 } 77 78 @Override getWallpaperRotationRefresher()79 public synchronized WallpaperRotationRefresher getWallpaperRotationRefresher() { 80 if (mWallpaperRotationRefresher == null) { 81 mWallpaperRotationRefresher = new WallpaperRotationRefresher() { 82 @Override 83 public void refreshWallpaper(Context context, Listener listener) { 84 // Not implemented 85 listener.onError(); 86 } 87 }; 88 } 89 return mWallpaperRotationRefresher; 90 } 91 92 @Override getPreviewFragment( Context context, WallpaperInfo wallpaperInfo, int mode, boolean viewAsHome, boolean viewFullScreen, boolean testingModeEnabled)93 public Fragment getPreviewFragment( 94 Context context, 95 WallpaperInfo wallpaperInfo, 96 int mode, 97 boolean viewAsHome, 98 boolean viewFullScreen, 99 boolean testingModeEnabled) { 100 return PreviewFragment.newInstance(wallpaperInfo, mode, viewAsHome, viewFullScreen, 101 testingModeEnabled); 102 } 103 104 @Override getDeepLinkRedirectIntent(Context context, Uri uri)105 public Intent getDeepLinkRedirectIntent(Context context, Uri uri) { 106 Intent intent = new Intent(); 107 intent.setClass(context, CustomizationPickerActivity.class); 108 intent.setData(uri); 109 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 110 return intent; 111 } 112 113 @Override getDownloadableIntentAction()114 public String getDownloadableIntentAction() { 115 return null; 116 } 117 118 @Override getPerformanceMonitor()119 public synchronized PerformanceMonitor getPerformanceMonitor() { 120 if (mPerformanceMonitor == null) { 121 mPerformanceMonitor = new PerformanceMonitor() { 122 @Override 123 public void recordFullResPreviewLoadedMemorySnapshot() { 124 // No Op 125 } 126 }; 127 } 128 return mPerformanceMonitor; 129 } 130 131 @Override getLoggingOptInStatusProvider(Context context)132 public synchronized LoggingOptInStatusProvider getLoggingOptInStatusProvider(Context context) { 133 return null; 134 } 135 136 @Override getThemeManager(ThemeBundleProvider provider, FragmentActivity activity, OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger)137 public ThemeManager getThemeManager(ThemeBundleProvider provider, FragmentActivity activity, 138 OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger) { 139 return new ThemeManager(provider, activity, overlayManagerCompat, logger); 140 } 141 142 @Override getCustomizationSections()143 public CustomizationSections getCustomizationSections() { 144 if (mCustomizationSections == null) { 145 mCustomizationSections = new DefaultCustomizationSections(); 146 } 147 return mCustomizationSections; 148 } 149 } 150