Delete WallpaparManagerCompat
WallpaparManagerCompat is no longer in use. Delete it.
Test: Built and manually tested that setting wallpaper works
Bug: 292275263
Change-Id: I2b1cb220edc7d57c974db7754abfe2e57b71d284
diff --git a/src/com/android/wallpaper/compat/WallpaperManagerCompat.java b/src/com/android/wallpaper/compat/WallpaperManagerCompat.java
deleted file mode 100755
index 438b98d..0000000
--- a/src/com/android/wallpaper/compat/WallpaperManagerCompat.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.wallpaper.compat;
-
-import android.app.WallpaperManager;
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
-import android.os.ParcelFileDescriptor;
-
-import androidx.annotation.IntDef;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * An abstraction over WallpaperManager to allow for the transitional state in which the N SDK
- * is not yet ready but we need to use new N API methods. Provides wrapper methods for the new
- * N API methods.
- */
-public abstract class WallpaperManagerCompat {
- public static final int FLAG_SYSTEM = WallpaperManager.FLAG_SYSTEM;
- public static final int FLAG_LOCK = WallpaperManager.FLAG_LOCK;
- private static final Object sInstanceLock = new Object();
- private static WallpaperManagerCompat sInstance;
-
- public static WallpaperManagerCompat getInstance(Context context) {
- synchronized (sInstanceLock) {
- if (sInstance == null) {
- sInstance = new WallpaperManagerCompatVN(context.getApplicationContext());
- }
- return sInstance;
- }
- }
-
- /**
- * Sets the static instance of {@link WallpaperManagerCompat} as the provided object. Used for
- * testing.
- */
- public static void setInstance(WallpaperManagerCompat wallpaperManagerCompat) {
- synchronized (sInstanceLock) {
- sInstance = wallpaperManagerCompat;
- }
- }
-
- /**
- * Thin wrapper around WallpaperManager's setStream method as defined in the N API.
- */
- public abstract int setStream(InputStream stream, Rect visibleCropHint, boolean allowBackup,
- int whichWallpaper) throws IOException;
-
- /**
- * Thin wrapper around WallpaperManager's setBitmap method as defined in the N API.
- */
- public abstract int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup,
- int whichWallpaper) throws IOException;
-
- /**
- * Thin wrapper around WallpaperManager's getWallpaperId method as defined in the N API.
- */
- public abstract int getWallpaperId(@WallpaperLocation int whichWallpaper);
-
- /**
- * Thin wrapper around WallpaperManager's getWallpaperFile method as defined ONLY in the N API.
- * This method must only be called when N is detected on the device as there is no pre-N fallback
- * counterpart! On pre-N devices, null is always returned.
- */
- public abstract ParcelFileDescriptor getWallpaperFile(int whichWallpaper);
-
- /**
- * Thin wrapper around WallpaperManager's getDrawable method. Needed to work around issue on
- * certain Samsung devices where a SecurityException is thrown if this is called when the
- * device had never changed from its default wallpaper.
- */
- public abstract Drawable getDrawable();
-
- /**
- * Possible locations to which a wallpaper may be set.
- */
- @IntDef({
- FLAG_SYSTEM,
- FLAG_LOCK})
- public @interface WallpaperLocation {
- }
-}
diff --git a/src/com/android/wallpaper/compat/WallpaperManagerCompatV16.java b/src/com/android/wallpaper/compat/WallpaperManagerCompatV16.java
deleted file mode 100755
index 8058c28..0000000
--- a/src/com/android/wallpaper/compat/WallpaperManagerCompatV16.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.wallpaper.compat;
-
-import android.annotation.SuppressLint;
-import android.app.WallpaperManager;
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
-import android.os.ParcelFileDescriptor;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * The pre-N implementation of {@link WallpaperManagerCompat} which implements its methods by
- * delegating to the standard pre-N equivalent methods.
- */
-public class WallpaperManagerCompatV16 extends WallpaperManagerCompat {
- protected WallpaperManager mWallpaperManager;
-
- @SuppressLint("ServiceCast")
- public WallpaperManagerCompatV16(Context context) {
- // Retrieve WallpaperManager using Context#getSystemService instead of
- // WallpaperManager#getInstance so it can be mocked out in test.
- mWallpaperManager = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
- }
-
- @Override
- public int setStream(InputStream data, Rect visibleCropHint, boolean allowBackup,
- int whichWallpaper) throws IOException {
- mWallpaperManager.setStream(data);
- // Return a value greater than zero to indicate success.
- return 1;
- }
-
- @Override
- public int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup,
- int whichWallpaper) throws IOException {
- mWallpaperManager.setBitmap(fullImage);
- // Return a value greater than zero to indicate success.
- return 1;
- }
-
- @Override
- public int getWallpaperId(@WallpaperLocation int whichWallpaper) {
- throw new UnsupportedOperationException("This method should not be called on pre-N versions "
- + "of Android.");
- }
-
- @Override
- public ParcelFileDescriptor getWallpaperFile(int whichWallpaper) {
- return null;
- }
-
- @Override
- public Drawable getDrawable() {
- Drawable drawable;
- try {
- drawable = mWallpaperManager.getDrawable();
- } catch (java.lang.Exception e) {
- // Work around Samsung bug where SecurityException is thrown if device is still using its
- // default wallpaper, and around Android 7.0 bug where SELinux issues can cause a perfectly
- // valid access of the current wallpaper to cause a failed Binder transaction manifest here as
- // a RuntimeException.
- drawable = mWallpaperManager.getBuiltInDrawable();
- }
- return drawable;
- }
-}
diff --git a/src/com/android/wallpaper/compat/WallpaperManagerCompatVN.java b/src/com/android/wallpaper/compat/WallpaperManagerCompatVN.java
deleted file mode 100755
index cf50a81..0000000
--- a/src/com/android/wallpaper/compat/WallpaperManagerCompatVN.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.wallpaper.compat;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Rect;
-import android.os.ParcelFileDescriptor;
-import android.util.Log;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * The Android N implementation of {@link WallpaperManagerCompat} which uses the new N API methods
- * if available and delegates back to older implementations if not.
- */
-public class WallpaperManagerCompatVN extends WallpaperManagerCompatV16 {
-
- private static final String TAG = "WallpaperMgrCompatVN";
-
- public WallpaperManagerCompatVN(Context context) {
- super(context);
- }
-
- @Override
- public int setStream(final InputStream data, Rect visibleCropHint, boolean allowBackup,
- int whichWallpaper) throws IOException {
- return mWallpaperManager.setStream(data, visibleCropHint, allowBackup, whichWallpaper);
- }
-
- @Override
- public int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup,
- int whichWallpaper) throws IOException {
- return mWallpaperManager.setBitmap(fullImage, visibleCropHint, allowBackup, whichWallpaper);
- }
-
- @Override
- public int getWallpaperId(@WallpaperLocation int whichWallpaper) {
- return mWallpaperManager.getWallpaperId(whichWallpaper);
- }
-
- @Override
- public ParcelFileDescriptor getWallpaperFile(int whichWallpaper) {
- ParcelFileDescriptor parcelFd = null;
- try {
- parcelFd = mWallpaperManager.getWallpaperFile(whichWallpaper);
- } catch (Exception e) {
- // Note: We put a catch-all exception handler here to handle RemoteException /
- // DeadSystemException that can happen due to an Android N framework bug manifesting if a user
- // had restored their device from a previous device backup.
- Log.e(TAG, "Exception on getWallpaperFile", e);
- }
- return parcelFd;
- }
-}
diff --git a/tests/common/src/com/android/wallpaper/testing/TestWallpaperManagerCompat.java b/tests/common/src/com/android/wallpaper/testing/TestWallpaperManagerCompat.java
deleted file mode 100644
index 69f6839..0000000
--- a/tests/common/src/com/android/wallpaper/testing/TestWallpaperManagerCompat.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.wallpaper.testing;
-
-import android.app.WallpaperManager;
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
-import android.os.ParcelFileDescriptor;
-import android.util.Log;
-
-import com.android.wallpaper.compat.WallpaperManagerCompat;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/** Test double for {@link WallpaperManagerCompat}. */
-public class TestWallpaperManagerCompat extends WallpaperManagerCompat {
- private static final String TAG = "TestWPManagerCompat";
-
- ParcelFileDescriptor mSystemParcelFd;
- ParcelFileDescriptor mLockParcelFd;
- int mHomeWallpaperId = 0;
- int mLockWallpaperId = 0;
-
- private boolean mAllowBackup;
- private Context mAppContext;
- private Drawable mTestDrawable;
-
- public TestWallpaperManagerCompat(Context appContext) {
- mAppContext = appContext;
- mAllowBackup = true;
- }
-
- @Override
- public int setStream(InputStream stream, Rect visibleCropHint, boolean allowBackup,
- int whichWallpaper) throws IOException {
- mAllowBackup = allowBackup;
- return ++mHomeWallpaperId;
- }
-
- @Override
- public int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup,
- int whichWallpaper) throws IOException {
- mAllowBackup = allowBackup;
- return ++mLockWallpaperId;
- }
-
- @Override
- public ParcelFileDescriptor getWallpaperFile(int whichWallpaper) {
- if (whichWallpaper == WallpaperManagerCompat.FLAG_SYSTEM) {
- return mSystemParcelFd;
- } else if (whichWallpaper == WallpaperManagerCompat.FLAG_LOCK) {
- return mLockParcelFd;
- } else {
- // :(
- return null;
- }
- }
-
- @Override
- public Drawable getDrawable() {
- if (mTestDrawable != null) {
- return mTestDrawable;
- }
-
- // Retrieve WallpaperManager using Context#getSystemService instead of
- // WallpaperManager#getInstance so it can be mocked out in test.
- WallpaperManager wallpaperManager =
- (WallpaperManager) mAppContext.getSystemService(Context.WALLPAPER_SERVICE);
- return wallpaperManager.getDrawable();
- }
-
- @Override
- public int getWallpaperId(@WallpaperLocation int whichWallpaper) {
- switch (whichWallpaper) {
- case WallpaperManagerCompat.FLAG_SYSTEM:
- return mHomeWallpaperId;
- case WallpaperManagerCompat.FLAG_LOCK:
- return mLockWallpaperId;
- default:
- throw new IllegalArgumentException(
- "Wallpaper location must be one of FLAG_SYSTEM or "
- + "FLAG_LOCK but the value " + whichWallpaper + " was provided.");
- }
- }
-
- public void setWallpaperFile(int whichWallpaper, ParcelFileDescriptor file) {
- if (whichWallpaper == WallpaperManagerCompat.FLAG_SYSTEM) {
- mSystemParcelFd = file;
- } else if (whichWallpaper == WallpaperManagerCompat.FLAG_LOCK) {
- mLockParcelFd = file;
- } else {
- Log.e(TAG, "Called setWallpaperFile without a valid distinct 'which' argument.");
- }
- }
-
- public void setWallpaperId(@WallpaperLocation int whichWallpaper, int wallpaperId) {
- switch (whichWallpaper) {
- case WallpaperManagerCompat.FLAG_SYSTEM:
- mHomeWallpaperId = wallpaperId;
- break;
- case WallpaperManagerCompat.FLAG_LOCK:
- mLockWallpaperId = wallpaperId;
- break;
- default:
- throw new IllegalArgumentException(
- "Wallpaper location must be one of FLAG_SYSTEM or "
- + "FLAG_LOCK but the value " + whichWallpaper + " was provided.");
- }
- }
-
- public void setDrawable(Drawable drawable) {
- mTestDrawable = drawable;
- }
-
- /** Returns whether backup is allowed for the last set wallpaper. */
- public boolean isBackupAllowed() {
- return mAllowBackup;
- }
-}