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 LiveWallpaperStatusChecker mLiveWallpaperStatusChecker; 38 private NetworkStatusNotifier mNetworkStatusNotifier; 39 private AlarmManagerWrapper mAlarmManagerWrapper; 40 private ExploreIntentChecker mExploreIntentChecker; 41 private SystemFeatureChecker mSystemFeatureChecker; 42 private RotatingWallpaperComponentChecker mRotatingWallpaperComponentChecker; 43 private FormFactorChecker mFormFactorChecker; 44 private PackageStatusNotifier mPackageStatusNotifier; 45 private LiveWallpaperInfoFactory mLiveWallpaperInfoFactory; 46 47 @Override getBitmapCropper()48 public synchronized BitmapCropper getBitmapCropper() { 49 if (mBitmapCropper == null) { 50 mBitmapCropper = new DefaultBitmapCropper(); 51 } 52 return mBitmapCropper; 53 } 54 55 @Override getPartnerProvider(Context context)56 public synchronized PartnerProvider getPartnerProvider(Context context) { 57 if (mPartnerProvider == null) { 58 mPartnerProvider = new DefaultPartnerProvider(context.getApplicationContext()); 59 } 60 return mPartnerProvider; 61 } 62 63 @Override getPreferences(Context context)64 public synchronized WallpaperPreferences getPreferences(Context context) { 65 if (mPrefs == null) { 66 mPrefs = new DefaultWallpaperPreferences(context.getApplicationContext()); 67 } 68 return mPrefs; 69 } 70 71 @Override getWallpaperPersister(Context context)72 public synchronized WallpaperPersister getWallpaperPersister(Context context) { 73 if (mWallpaperPersister == null) { 74 mWallpaperPersister = new DefaultWallpaperPersister(context.getApplicationContext()); 75 } 76 return mWallpaperPersister; 77 } 78 79 @Override getWallpaperRefresher(Context context)80 public synchronized WallpaperRefresher getWallpaperRefresher(Context context) { 81 if (mWallpaperRefresher == null) { 82 mWallpaperRefresher = new DefaultWallpaperRefresher(context.getApplicationContext()); 83 } 84 return mWallpaperRefresher; 85 } 86 87 @Override getRequester(Context context)88 public synchronized Requester getRequester(Context context) { 89 if (mRequester == null) { 90 mRequester = new WallpaperRequester(context.getApplicationContext()); 91 } 92 return mRequester; 93 } 94 95 @Override getWallpaperManagerCompat(Context context)96 public synchronized WallpaperManagerCompat getWallpaperManagerCompat(Context context) { 97 if (mWallpaperManagerCompat == null) { 98 mWallpaperManagerCompat = WallpaperManagerCompat.getInstance(context); 99 } 100 return mWallpaperManagerCompat; 101 } 102 103 @Override getCurrentWallpaperFactory(Context context)104 public synchronized CurrentWallpaperInfoFactory getCurrentWallpaperFactory(Context context) { 105 if (mCurrentWallpaperFactory == null) { 106 mCurrentWallpaperFactory = 107 new DefaultCurrentWallpaperInfoFactory(context.getApplicationContext()); 108 } 109 return mCurrentWallpaperFactory; 110 } 111 112 @Override getLiveWallpaperStatusChecker(Context context)113 public synchronized LiveWallpaperStatusChecker getLiveWallpaperStatusChecker(Context context) { 114 if (mLiveWallpaperStatusChecker == null) { 115 mLiveWallpaperStatusChecker = 116 new DefaultLiveWallpaperStatusChecker(context.getApplicationContext()); 117 } 118 return mLiveWallpaperStatusChecker; 119 } 120 121 @Override getNetworkStatusNotifier(Context context)122 public synchronized NetworkStatusNotifier getNetworkStatusNotifier(Context context) { 123 if (mNetworkStatusNotifier == null) { 124 mNetworkStatusNotifier = new DefaultNetworkStatusNotifier(context.getApplicationContext()); 125 } 126 return mNetworkStatusNotifier; 127 } 128 129 @Override getPackageStatusNotifier(Context context)130 public synchronized PackageStatusNotifier getPackageStatusNotifier(Context context) { 131 if (mPackageStatusNotifier == null) { 132 mPackageStatusNotifier = new DefaultPackageStatusNotifier( 133 context.getApplicationContext()); 134 } 135 return mPackageStatusNotifier; 136 } 137 138 @Override getAlarmManagerWrapper(Context context)139 public synchronized AlarmManagerWrapper getAlarmManagerWrapper(Context context) { 140 if (mAlarmManagerWrapper == null) { 141 mAlarmManagerWrapper = new DefaultAlarmManagerWrapper(context.getApplicationContext()); 142 } 143 return mAlarmManagerWrapper; 144 } 145 146 @Override getExploreIntentChecker(Context context)147 public synchronized ExploreIntentChecker getExploreIntentChecker(Context context) { 148 if (mExploreIntentChecker == null) { 149 mExploreIntentChecker = new DefaultExploreIntentChecker(context.getApplicationContext()); 150 } 151 return mExploreIntentChecker; 152 } 153 154 @Override getSystemFeatureChecker()155 public synchronized SystemFeatureChecker getSystemFeatureChecker() { 156 if (mSystemFeatureChecker == null) { 157 mSystemFeatureChecker = new DefaultSystemFeatureChecker(); 158 } 159 return mSystemFeatureChecker; 160 } 161 162 @Override getRotatingWallpaperComponentChecker()163 public synchronized RotatingWallpaperComponentChecker getRotatingWallpaperComponentChecker() { 164 if (mRotatingWallpaperComponentChecker == null) { 165 mRotatingWallpaperComponentChecker = new DefaultRotatingWallpaperComponentChecker(); 166 } 167 return mRotatingWallpaperComponentChecker; 168 } 169 170 @Override getFormFactorChecker(Context context)171 public synchronized FormFactorChecker getFormFactorChecker(Context context) { 172 if (mFormFactorChecker == null) { 173 mFormFactorChecker = new DefaultFormFactorChecker(context.getApplicationContext()); 174 } 175 return mFormFactorChecker; 176 } 177 178 @Override getIndividualPickerFragment(String collectionId)179 public synchronized IndividualPickerFragment getIndividualPickerFragment(String collectionId) { 180 return IndividualPickerFragment.newInstance(collectionId); 181 } 182 183 @Override getLiveWallpaperInfoFactory(Context context)184 public LiveWallpaperInfoFactory getLiveWallpaperInfoFactory(Context context) { 185 if (mLiveWallpaperInfoFactory == null) { 186 mLiveWallpaperInfoFactory = new DefaultLiveWallpaperInfoFactory(); 187 } 188 return mLiveWallpaperInfoFactory; 189 } 190 } 191