1 /* 2 * Copyright (C) 2017 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.compat.WallpaperManagerCompat; 21 import com.android.wallpaper.network.Requester; 22 import com.android.wallpaper.network.WallpaperRequester; 23 import com.android.wallpaper.picker.individual.IndividualPickerFragment; 24 25 /** 26 * Base implementation of Injector. 27 */ 28 public abstract class BaseWallpaperInjector implements Injector { 29 private BitmapCropper mBitmapCropper; 30 private PartnerProvider mPartnerProvider; 31 private WallpaperPersister mWallpaperPersister; 32 private WallpaperPreferences mPrefs; 33 private WallpaperRefresher mWallpaperRefresher; 34 private Requester mRequester; 35 private WallpaperManagerCompat mWallpaperManagerCompat; 36 private CurrentWallpaperInfoFactory mCurrentWallpaperFactory; 37 private NetworkStatusNotifier mNetworkStatusNotifier; 38 private AlarmManagerWrapper mAlarmManagerWrapper; 39 private ExploreIntentChecker mExploreIntentChecker; 40 private SystemFeatureChecker mSystemFeatureChecker; 41 private FormFactorChecker mFormFactorChecker; 42 private PackageStatusNotifier mPackageStatusNotifier; 43 private LiveWallpaperInfoFactory mLiveWallpaperInfoFactory; 44 private DrawableLayerResolver mDrawableLayerResolver; 45 46 @Override getBitmapCropper()47 public synchronized BitmapCropper getBitmapCropper() { 48 if (mBitmapCropper == null) { 49 mBitmapCropper = new DefaultBitmapCropper(); 50 } 51 return mBitmapCropper; 52 } 53 54 @Override getPartnerProvider(Context context)55 public synchronized PartnerProvider getPartnerProvider(Context context) { 56 if (mPartnerProvider == null) { 57 mPartnerProvider = new DefaultPartnerProvider(context.getApplicationContext()); 58 } 59 return mPartnerProvider; 60 } 61 62 @Override getPreferences(Context context)63 public synchronized WallpaperPreferences getPreferences(Context context) { 64 if (mPrefs == null) { 65 mPrefs = new DefaultWallpaperPreferences(context.getApplicationContext()); 66 } 67 return mPrefs; 68 } 69 70 @Override getWallpaperPersister(Context context)71 public synchronized WallpaperPersister getWallpaperPersister(Context context) { 72 if (mWallpaperPersister == null) { 73 mWallpaperPersister = new DefaultWallpaperPersister(context.getApplicationContext()); 74 } 75 return mWallpaperPersister; 76 } 77 78 @Override getWallpaperRefresher(Context context)79 public synchronized WallpaperRefresher getWallpaperRefresher(Context context) { 80 if (mWallpaperRefresher == null) { 81 mWallpaperRefresher = new DefaultWallpaperRefresher(context.getApplicationContext()); 82 } 83 return mWallpaperRefresher; 84 } 85 86 @Override getRequester(Context context)87 public synchronized Requester getRequester(Context context) { 88 if (mRequester == null) { 89 mRequester = new WallpaperRequester(context.getApplicationContext()); 90 } 91 return mRequester; 92 } 93 94 @Override getWallpaperManagerCompat(Context context)95 public synchronized WallpaperManagerCompat getWallpaperManagerCompat(Context context) { 96 if (mWallpaperManagerCompat == null) { 97 mWallpaperManagerCompat = WallpaperManagerCompat.getInstance(context); 98 } 99 return mWallpaperManagerCompat; 100 } 101 102 @Override getCurrentWallpaperFactory(Context context)103 public synchronized CurrentWallpaperInfoFactory getCurrentWallpaperFactory(Context context) { 104 if (mCurrentWallpaperFactory == null) { 105 mCurrentWallpaperFactory = 106 new DefaultCurrentWallpaperInfoFactory(context.getApplicationContext()); 107 } 108 return mCurrentWallpaperFactory; 109 } 110 111 @Override getNetworkStatusNotifier(Context context)112 public synchronized NetworkStatusNotifier getNetworkStatusNotifier(Context context) { 113 if (mNetworkStatusNotifier == null) { 114 mNetworkStatusNotifier = new DefaultNetworkStatusNotifier(context.getApplicationContext()); 115 } 116 return mNetworkStatusNotifier; 117 } 118 119 @Override getPackageStatusNotifier(Context context)120 public synchronized PackageStatusNotifier getPackageStatusNotifier(Context context) { 121 if (mPackageStatusNotifier == null) { 122 mPackageStatusNotifier = new DefaultPackageStatusNotifier( 123 context.getApplicationContext()); 124 } 125 return mPackageStatusNotifier; 126 } 127 128 @Override getAlarmManagerWrapper(Context context)129 public synchronized AlarmManagerWrapper getAlarmManagerWrapper(Context context) { 130 if (mAlarmManagerWrapper == null) { 131 mAlarmManagerWrapper = new DefaultAlarmManagerWrapper(context.getApplicationContext()); 132 } 133 return mAlarmManagerWrapper; 134 } 135 136 @Override getExploreIntentChecker(Context context)137 public synchronized ExploreIntentChecker getExploreIntentChecker(Context context) { 138 if (mExploreIntentChecker == null) { 139 mExploreIntentChecker = new DefaultExploreIntentChecker(context.getApplicationContext()); 140 } 141 return mExploreIntentChecker; 142 } 143 144 @Override getSystemFeatureChecker()145 public synchronized SystemFeatureChecker getSystemFeatureChecker() { 146 if (mSystemFeatureChecker == null) { 147 mSystemFeatureChecker = new DefaultSystemFeatureChecker(); 148 } 149 return mSystemFeatureChecker; 150 } 151 152 @Override getFormFactorChecker(Context context)153 public synchronized FormFactorChecker getFormFactorChecker(Context context) { 154 if (mFormFactorChecker == null) { 155 mFormFactorChecker = new DefaultFormFactorChecker(context.getApplicationContext()); 156 } 157 return mFormFactorChecker; 158 } 159 160 @Override getIndividualPickerFragment(String collectionId)161 public synchronized IndividualPickerFragment getIndividualPickerFragment(String collectionId) { 162 return IndividualPickerFragment.newInstance(collectionId); 163 } 164 165 @Override getLiveWallpaperInfoFactory(Context context)166 public LiveWallpaperInfoFactory getLiveWallpaperInfoFactory(Context context) { 167 if (mLiveWallpaperInfoFactory == null) { 168 mLiveWallpaperInfoFactory = new DefaultLiveWallpaperInfoFactory(); 169 } 170 return mLiveWallpaperInfoFactory; 171 } 172 173 @Override getDrawableLayerResolver()174 public DrawableLayerResolver getDrawableLayerResolver() { 175 if (mDrawableLayerResolver == null) { 176 mDrawableLayerResolver = new DefaultDrawableLayerResolver(); 177 } 178 return mDrawableLayerResolver; 179 } 180 } 181