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 android.app; 17 18 import android.annotation.NonNull; 19 import android.content.ComponentName; 20 import android.content.Intent; 21 import android.graphics.Bitmap; 22 import android.graphics.Rect; 23 import android.graphics.drawable.Drawable; 24 import android.net.Uri; 25 import android.os.Bundle; 26 import android.os.Handler; 27 import android.os.IBinder; 28 import android.os.ParcelFileDescriptor; 29 import android.util.Log; 30 31 import java.io.IOException; 32 import java.io.InputStream; 33 34 /** 35 * A no-op implementation of {@link WallpaperManager}. 36 */ 37 final class DisabledWallpaperManager extends WallpaperManager { 38 39 private static final String TAG = DisabledWallpaperManager.class.getSimpleName(); 40 41 // Don't need to worry about synchronization 42 private static DisabledWallpaperManager sInstance; 43 44 private static final boolean DEBUG = false; 45 46 @NonNull getInstance()47 static DisabledWallpaperManager getInstance() { 48 if (sInstance == null) { 49 sInstance = new DisabledWallpaperManager(); 50 } 51 return sInstance; 52 } 53 DisabledWallpaperManager()54 private DisabledWallpaperManager() { 55 } 56 57 @Override isWallpaperSupported()58 public boolean isWallpaperSupported() { 59 return false; 60 } 61 62 @Override isSetWallpaperAllowed()63 public boolean isSetWallpaperAllowed() { 64 return false; 65 } 66 unsupported()67 private static <T> T unsupported() { 68 if (DEBUG) Log.w(TAG, "unsupported method called; returning null", new Exception()); 69 return null; 70 } 71 unsupportedBoolean()72 private static boolean unsupportedBoolean() { 73 if (DEBUG) Log.w(TAG, "unsupported method called; returning false", new Exception()); 74 return false; 75 } 76 unsupportedInt()77 private static int unsupportedInt() { 78 if (DEBUG) Log.w(TAG, "unsupported method called; returning -1", new Exception()); 79 return -1; 80 } 81 82 @Override getDrawable()83 public Drawable getDrawable() { 84 return unsupported(); 85 } 86 87 @Override getBuiltInDrawable()88 public Drawable getBuiltInDrawable() { 89 return unsupported(); 90 } 91 92 @Override getBuiltInDrawable(int which)93 public Drawable getBuiltInDrawable(int which) { 94 return unsupported(); 95 } 96 97 @Override getBuiltInDrawable(int outWidth, int outHeight, boolean scaleToFit, float horizontalAlignment, float verticalAlignment)98 public Drawable getBuiltInDrawable(int outWidth, int outHeight, boolean scaleToFit, 99 float horizontalAlignment, float verticalAlignment) { 100 return unsupported(); 101 } 102 103 @Override getBuiltInDrawable(int outWidth, int outHeight, boolean scaleToFit, float horizontalAlignment, float verticalAlignment, int which)104 public Drawable getBuiltInDrawable(int outWidth, int outHeight, boolean scaleToFit, 105 float horizontalAlignment, float verticalAlignment, int which) { 106 return unsupported(); 107 } 108 109 @Override peekDrawable()110 public Drawable peekDrawable() { 111 return unsupported(); 112 } 113 114 @Override getFastDrawable()115 public Drawable getFastDrawable() { 116 return unsupported(); 117 } 118 119 @Override peekFastDrawable()120 public Drawable peekFastDrawable() { 121 return unsupported(); 122 } 123 124 @Override getBitmap()125 public Bitmap getBitmap() { 126 return unsupported(); 127 } 128 129 @Override getBitmap(boolean hardware)130 public Bitmap getBitmap(boolean hardware) { 131 return unsupported(); 132 } 133 134 @Override getBitmapAsUser(int userId, boolean hardware)135 public Bitmap getBitmapAsUser(int userId, boolean hardware) { 136 return unsupported(); 137 } 138 139 @Override getWallpaperFile(int which)140 public ParcelFileDescriptor getWallpaperFile(int which) { 141 return unsupported(); 142 } 143 144 @Override addOnColorsChangedListener(OnColorsChangedListener listener, Handler handler)145 public void addOnColorsChangedListener(OnColorsChangedListener listener, Handler handler) { 146 unsupported(); 147 } 148 149 @Override addOnColorsChangedListener(OnColorsChangedListener listener, Handler handler, int userId)150 public void addOnColorsChangedListener(OnColorsChangedListener listener, Handler handler, 151 int userId) { 152 unsupported(); 153 } 154 155 @Override removeOnColorsChangedListener(OnColorsChangedListener callback)156 public void removeOnColorsChangedListener(OnColorsChangedListener callback) { 157 unsupported(); 158 } 159 160 @Override removeOnColorsChangedListener(OnColorsChangedListener callback, int userId)161 public void removeOnColorsChangedListener(OnColorsChangedListener callback, int userId) { 162 unsupported(); 163 } 164 165 @Override getWallpaperColors(int which)166 public WallpaperColors getWallpaperColors(int which) { 167 return unsupported(); 168 } 169 170 @Override getWallpaperColors(int which, int userId)171 public WallpaperColors getWallpaperColors(int which, int userId) { 172 return unsupported(); 173 } 174 175 @Override getWallpaperFile(int which, int userId)176 public ParcelFileDescriptor getWallpaperFile(int which, int userId) { 177 return unsupported(); 178 } 179 180 @Override getWallpaperFile(int which, boolean getCropped)181 public ParcelFileDescriptor getWallpaperFile(int which, boolean getCropped) { 182 return unsupported(); 183 } 184 185 @Override forgetLoadedWallpaper()186 public void forgetLoadedWallpaper() { 187 unsupported(); 188 } 189 190 @Override getWallpaperInfo()191 public WallpaperInfo getWallpaperInfo() { 192 return unsupported(); 193 } 194 195 @Override getWallpaperInfoFile()196 public ParcelFileDescriptor getWallpaperInfoFile() { 197 return unsupported(); 198 } 199 200 @Override getWallpaperInfoForUser(int userId)201 public WallpaperInfo getWallpaperInfoForUser(int userId) { 202 return unsupported(); 203 } 204 205 @Override getWallpaperInfo(@etWallpaperFlags int which)206 public WallpaperInfo getWallpaperInfo(@SetWallpaperFlags int which) { 207 return unsupported(); 208 } 209 210 @Override getWallpaperInfo(@etWallpaperFlags int which, int userId)211 public WallpaperInfo getWallpaperInfo(@SetWallpaperFlags int which, int userId) { 212 return unsupported(); 213 } 214 215 @Override getWallpaperId(int which)216 public int getWallpaperId(int which) { 217 return unsupportedInt(); 218 } 219 220 @Override getWallpaperIdForUser(int which, int userId)221 public int getWallpaperIdForUser(int which, int userId) { 222 return unsupportedInt(); 223 } 224 225 @Override getCropAndSetWallpaperIntent(Uri imageUri)226 public Intent getCropAndSetWallpaperIntent(Uri imageUri) { 227 return unsupported(); 228 } 229 230 @Override setResource(int resid)231 public void setResource(int resid) throws IOException { 232 unsupported(); 233 } 234 235 @Override setResource(int resid, int which)236 public int setResource(int resid, int which) throws IOException { 237 unsupported(); 238 return 0; 239 } 240 241 @Override setBitmap(Bitmap bitmap)242 public void setBitmap(Bitmap bitmap) throws IOException { 243 unsupported(); 244 } 245 246 @Override setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup)247 public int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup) 248 throws IOException { 249 unsupported(); 250 return 0; 251 } 252 253 @Override setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup, int which)254 public int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup, int which) 255 throws IOException { 256 unsupported(); 257 return 0; 258 } 259 260 @Override setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup, int which, int userId)261 public int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup, int which, 262 int userId) throws IOException { 263 unsupported(); 264 return 0; 265 } 266 267 @Override setStream(InputStream bitmapData)268 public void setStream(InputStream bitmapData) throws IOException { 269 unsupported(); 270 } 271 272 @Override setStream(InputStream bitmapData, Rect visibleCropHint, boolean allowBackup)273 public int setStream(InputStream bitmapData, Rect visibleCropHint, boolean allowBackup) 274 throws IOException { 275 unsupported(); 276 return 0; 277 } 278 279 @Override setStream(InputStream bitmapData, Rect visibleCropHint, boolean allowBackup, int which)280 public int setStream(InputStream bitmapData, Rect visibleCropHint, boolean allowBackup, 281 int which) throws IOException { 282 unsupported(); 283 return 0; 284 } 285 286 @Override hasResourceWallpaper(int resid)287 public boolean hasResourceWallpaper(int resid) { 288 return unsupportedBoolean(); 289 } 290 291 @Override getDesiredMinimumWidth()292 public int getDesiredMinimumWidth() { 293 return unsupportedInt(); 294 } 295 296 @Override getDesiredMinimumHeight()297 public int getDesiredMinimumHeight() { 298 return unsupportedInt(); 299 } 300 301 @Override suggestDesiredDimensions(int minimumWidth, int minimumHeight)302 public void suggestDesiredDimensions(int minimumWidth, int minimumHeight) { 303 unsupported(); 304 } 305 306 @Override setDisplayPadding(Rect padding)307 public void setDisplayPadding(Rect padding) { 308 unsupported(); 309 } 310 311 @Override setDisplayOffset(IBinder windowToken, int x, int y)312 public void setDisplayOffset(IBinder windowToken, int x, int y) { 313 unsupported(); 314 } 315 316 @Override clearWallpaper()317 public void clearWallpaper() { 318 unsupported(); 319 } 320 321 @Override clearWallpaper(int which, int userId)322 public void clearWallpaper(int which, int userId) { 323 unsupported(); 324 } 325 326 @Override setWallpaperComponent(ComponentName name)327 public boolean setWallpaperComponent(ComponentName name) { 328 return unsupportedBoolean(); 329 } 330 331 @Override setWallpaperComponent(ComponentName name, int userId)332 public boolean setWallpaperComponent(ComponentName name, int userId) { 333 return unsupportedBoolean(); 334 } 335 336 @Override setWallpaperOffsets(IBinder windowToken, float xOffset, float yOffset)337 public void setWallpaperOffsets(IBinder windowToken, float xOffset, float yOffset) { 338 unsupported(); 339 } 340 341 @Override setWallpaperOffsetSteps(float xStep, float yStep)342 public void setWallpaperOffsetSteps(float xStep, float yStep) { 343 unsupported(); 344 } 345 346 @Override sendWallpaperCommand(IBinder windowToken, String action, int x, int y, int z, Bundle extras)347 public void sendWallpaperCommand(IBinder windowToken, String action, int x, int y, int z, 348 Bundle extras) { 349 unsupported(); 350 } 351 352 @Override clearWallpaperOffsets(IBinder windowToken)353 public void clearWallpaperOffsets(IBinder windowToken) { 354 unsupported(); 355 } 356 357 @Override clear()358 public void clear() throws IOException { 359 unsupported(); 360 } 361 362 @Override clear(int which)363 public void clear(int which) throws IOException { 364 unsupported(); 365 } 366 367 @Override isWallpaperBackupEligible(int which)368 public boolean isWallpaperBackupEligible(int which) { 369 return unsupportedBoolean(); 370 } 371 372 @Override wallpaperSupportsWcg(int which)373 public boolean wallpaperSupportsWcg(int which) { 374 return unsupportedBoolean(); 375 } 376 } 377