summaryrefslogtreecommitdiff
path: root/src/com/android/wallpaper/module/DefaultWallpaperRefresher.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/wallpaper/module/DefaultWallpaperRefresher.java')
-rwxr-xr-xsrc/com/android/wallpaper/module/DefaultWallpaperRefresher.java180
1 files changed, 113 insertions, 67 deletions
diff --git a/src/com/android/wallpaper/module/DefaultWallpaperRefresher.java b/src/com/android/wallpaper/module/DefaultWallpaperRefresher.java
index 3363d8ea..3c870280 100755
--- a/src/com/android/wallpaper/module/DefaultWallpaperRefresher.java
+++ b/src/com/android/wallpaper/module/DefaultWallpaperRefresher.java
@@ -15,6 +15,9 @@
*/
package com.android.wallpaper.module;
+import static com.android.wallpaper.compat.WallpaperManagerCompat.FLAG_LOCK;
+import static com.android.wallpaper.compat.WallpaperManagerCompat.FLAG_SYSTEM;
+
import android.annotation.SuppressLint;
import android.app.WallpaperManager;
import android.content.Context;
@@ -29,6 +32,7 @@ import android.util.Log;
import com.android.wallpaper.R;
import com.android.wallpaper.asset.BitmapUtils;
import com.android.wallpaper.compat.WallpaperManagerCompat;
+import com.android.wallpaper.model.LiveWallpaperMetadata;
import com.android.wallpaper.model.WallpaperMetadata;
import java.io.FileInputStream;
@@ -44,6 +48,7 @@ import java.util.List;
*/
@SuppressLint("ServiceCast")
public class DefaultWallpaperRefresher implements WallpaperRefresher {
+
private static final String TAG = "DefaultWPRefresher";
private final Context mAppContext;
@@ -77,12 +82,13 @@ public class DefaultWallpaperRefresher implements WallpaperRefresher {
*/
private class GetWallpaperMetadataAsyncTask extends
AsyncTask<Void, Void, List<WallpaperMetadata>> {
+
private final RefreshListener mListener;
private final WallpaperManagerCompat mWallpaperManagerCompat;
private long mCurrentHomeWallpaperHashCode;
private long mCurrentLockWallpaperHashCode;
- private String mSystemWallpaperPackageName;
+ private String mSystemWallpaperServiceName;
@SuppressLint("ServiceCast")
public GetWallpaperMetadataAsyncTask(RefreshListener listener) {
@@ -95,18 +101,17 @@ public class DefaultWallpaperRefresher implements WallpaperRefresher {
protected List<WallpaperMetadata> doInBackground(Void... unused) {
List<WallpaperMetadata> wallpaperMetadatas = new ArrayList<>();
- if (!isHomeScreenMetadataCurrent() || isHomeScreenAttributionsEmpty()) {
+ boolean isHomeScreenStatic = mWallpaperManager.getWallpaperInfo(FLAG_SYSTEM) == null;
+ if (!isHomeScreenMetadataCurrent() || (isHomeScreenStatic
+ && isHomeScreenAttributionsEmpty())) {
mWallpaperPreferences.clearHomeWallpaperMetadata();
setFallbackHomeScreenWallpaperMetadata();
}
- boolean isLockScreenWallpaperCurrentlySet = mWallpaperStatusChecker.isLockWallpaperSet(
- mAppContext);
+ boolean isLockScreenWallpaperCurrentlySet =
+ mWallpaperStatusChecker.isLockWallpaperSet(mAppContext);
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N
- || !isLockScreenWallpaperCurrentlySet) {
-
- // Return only home metadata if pre-N device or lock screen wallpaper is not explicitly set.
+ if (mWallpaperManager.getWallpaperInfo() == null) {
wallpaperMetadatas.add(new WallpaperMetadata(
mWallpaperPreferences.getHomeWallpaperAttributions(),
mWallpaperPreferences.getHomeWallpaperActionUrl(),
@@ -114,32 +119,40 @@ public class DefaultWallpaperRefresher implements WallpaperRefresher {
mWallpaperPreferences.getHomeWallpaperActionIconRes(),
mWallpaperPreferences.getHomeWallpaperCollectionId(),
mWallpaperPreferences.getHomeWallpaperBackingFileName(),
- mWallpaperManager.getWallpaperInfo()));
+ null));
+ } else {
+ wallpaperMetadatas.add(
+ new LiveWallpaperMetadata(mWallpaperManager.getWallpaperInfo()));
+ }
+
+ // Return only home metadata if pre-N device or lock screen wallpaper is not explicitly
+ // set.
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N
+ || !isLockScreenWallpaperCurrentlySet) {
return wallpaperMetadatas;
}
- if (!isLockScreenMetadataCurrent() || isLockScreenAttributionsEmpty()) {
+ boolean isLockScreenStatic = mWallpaperManager.getWallpaperInfo(FLAG_LOCK) == null;
+ if (!isLockScreenMetadataCurrent() || (isLockScreenStatic
+ && isLockScreenAttributionsEmpty())) {
mWallpaperPreferences.clearLockWallpaperMetadata();
setFallbackLockScreenWallpaperMetadata();
}
- wallpaperMetadatas.add(new WallpaperMetadata(
- mWallpaperPreferences.getHomeWallpaperAttributions(),
- mWallpaperPreferences.getHomeWallpaperActionUrl(),
- mWallpaperPreferences.getHomeWallpaperActionLabelRes(),
- mWallpaperPreferences.getHomeWallpaperActionIconRes(),
- mWallpaperPreferences.getHomeWallpaperCollectionId(),
- mWallpaperPreferences.getHomeWallpaperBackingFileName(),
- mWallpaperManager.getWallpaperInfo()));
-
- wallpaperMetadatas.add(new WallpaperMetadata(
- mWallpaperPreferences.getLockWallpaperAttributions(),
- mWallpaperPreferences.getLockWallpaperActionUrl(),
- mWallpaperPreferences.getLockWallpaperActionLabelRes(),
- mWallpaperPreferences.getLockWallpaperActionIconRes(),
- mWallpaperPreferences.getLockWallpaperCollectionId(),
- mWallpaperPreferences.getLockWallpaperBackingFileName(),
- null /* wallpaperComponent */));
+ if (mWallpaperManager.getWallpaperInfo(FLAG_LOCK) == null
+ || !mWallpaperManager.isLockscreenLiveWallpaperEnabled()) {
+ wallpaperMetadatas.add(new WallpaperMetadata(
+ mWallpaperPreferences.getLockWallpaperAttributions(),
+ mWallpaperPreferences.getLockWallpaperActionUrl(),
+ mWallpaperPreferences.getLockWallpaperActionLabelRes(),
+ mWallpaperPreferences.getLockWallpaperActionIconRes(),
+ mWallpaperPreferences.getLockWallpaperCollectionId(),
+ mWallpaperPreferences.getLockWallpaperBackingFileName(),
+ null));
+ } else {
+ wallpaperMetadatas.add(new LiveWallpaperMetadata(
+ mWallpaperManager.getWallpaperInfo(FLAG_LOCK)));
+ }
return wallpaperMetadatas;
}
@@ -147,8 +160,9 @@ public class DefaultWallpaperRefresher implements WallpaperRefresher {
@Override
protected void onPostExecute(List<WallpaperMetadata> metadatas) {
if (metadatas.size() > 2) {
- Log.e(TAG, "Got more than 2 WallpaperMetadata objects - only home and (optionally) lock "
- + "are permitted.");
+ Log.e(TAG,
+ "Got more than 2 WallpaperMetadata objects - only home and (optionally) "
+ + "lock are permitted.");
return;
}
@@ -157,27 +171,30 @@ public class DefaultWallpaperRefresher implements WallpaperRefresher {
}
/**
- * Sets fallback wallpaper attributions to WallpaperPreferences when the saved metadata did not
- * match the system wallpaper. For live wallpapers, loads the label (title) but for image
- * wallpapers loads a generic title string.
+ * Sets fallback wallpaper attributions to WallpaperPreferences when the saved metadata did
+ * not match the system wallpaper. For live wallpapers, loads the label (title) but for
+ * image wallpapers loads a generic title string.
*/
private void setFallbackHomeScreenWallpaperMetadata() {
android.app.WallpaperInfo wallpaperComponent = mWallpaperManager.getWallpaperInfo();
if (wallpaperComponent == null) { // Image wallpaper
mWallpaperPreferences.setHomeWallpaperAttributions(
- Arrays.asList(mAppContext.getResources().getString(R.string.fallback_wallpaper_title)));
+ Arrays.asList(mAppContext.getResources()
+ .getString(R.string.fallback_wallpaper_title)));
- // Set wallpaper ID if at least N or set a hash code if an earlier version of Android.
+ // Set wallpaper ID if at least N or set a hash code if an earlier version of
+ // Android.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- mWallpaperPreferences.setHomeWallpaperManagerId(mWallpaperManagerCompat.getWallpaperId(
- WallpaperManagerCompat.FLAG_SYSTEM));
+ mWallpaperPreferences.setHomeWallpaperManagerId(
+ mWallpaperManagerCompat.getWallpaperId(FLAG_SYSTEM));
} else {
- mWallpaperPreferences.setHomeWallpaperHashCode(getCurrentHomeWallpaperHashCode());
+ mWallpaperPreferences.setHomeWallpaperHashCode(
+ getCurrentHomeWallpaperHashCode());
}
} else { // Live wallpaper
mWallpaperPreferences.setHomeWallpaperAttributions(Arrays.asList(
wallpaperComponent.loadLabel(mAppContext.getPackageManager()).toString()));
- mWallpaperPreferences.setHomeWallpaperPackageName(mSystemWallpaperPackageName);
+ mWallpaperPreferences.setHomeWallpaperServiceName(mSystemWallpaperServiceName);
}
mWallpaperPreferences.setWallpaperPresentationMode(
WallpaperPreferences.PRESENTATION_MODE_STATIC);
@@ -185,14 +202,15 @@ public class DefaultWallpaperRefresher implements WallpaperRefresher {
/**
* Sets fallback lock screen wallpaper attributions to WallpaperPreferences. This should be
- * called when the saved lock screen wallpaper metadata does not match the currently set lock
- * screen wallpaper.
+ * called when the saved lock screen wallpaper metadata does not match the currently set
+ * lock screen wallpaper.
*/
private void setFallbackLockScreenWallpaperMetadata() {
mWallpaperPreferences.setLockWallpaperAttributions(
- Arrays.asList(mAppContext.getResources().getString(R.string.fallback_wallpaper_title)));
+ Arrays.asList(mAppContext.getResources()
+ .getString(R.string.fallback_wallpaper_title)));
mWallpaperPreferences.setLockWallpaperId(mWallpaperManagerCompat.getWallpaperId(
- WallpaperManagerCompat.FLAG_LOCK));
+ FLAG_LOCK));
}
/**
@@ -209,7 +227,8 @@ public class DefaultWallpaperRefresher implements WallpaperRefresher {
* Returns whether the home screen attributions saved in WallpaperPreferences is empty.
*/
private boolean isHomeScreenAttributionsEmpty() {
- List<String> homeScreenAttributions = mWallpaperPreferences.getHomeWallpaperAttributions();
+ List<String> homeScreenAttributions =
+ mWallpaperPreferences.getHomeWallpaperAttributions();
return homeScreenAttributions.get(0) == null
&& homeScreenAttributions.get(1) == null
&& homeScreenAttributions.get(2) == null;
@@ -217,13 +236,15 @@ public class DefaultWallpaperRefresher implements WallpaperRefresher {
private long getCurrentHomeWallpaperHashCode() {
if (mCurrentHomeWallpaperHashCode == 0) {
- BitmapDrawable wallpaperDrawable = (BitmapDrawable) mWallpaperManagerCompat.getDrawable();
- Bitmap wallpaperBitmap = wallpaperDrawable.getBitmap();
- mCurrentHomeWallpaperHashCode = BitmapUtils.generateHashCode(wallpaperBitmap);
-
- // Manually request that WallpaperManager loses its reference to the current wallpaper
- // bitmap, which can occupy a large memory allocation for the lifetime of the app.
- mWallpaperManager.forgetLoadedWallpaper();
+ BitmapDrawable wallpaperDrawable = (BitmapDrawable)
+ mWallpaperManagerCompat.getDrawable();
+ Bitmap wallpaperBitmap = wallpaperDrawable.getBitmap();
+ mCurrentHomeWallpaperHashCode = BitmapUtils.generateHashCode(wallpaperBitmap);
+
+ // Manually request that WallpaperManager loses its reference to the current
+ // wallpaper bitmap, which can occupy a large memory allocation for the lifetime of
+ // the app.
+ mWallpaperManager.forgetLoadedWallpaper();
}
return mCurrentHomeWallpaperHashCode;
}
@@ -245,7 +266,7 @@ public class DefaultWallpaperRefresher implements WallpaperRefresher {
Bitmap lockBitmap = null;
ParcelFileDescriptor pfd = mWallpaperManagerCompat.getWallpaperFile(
- WallpaperManagerCompat.FLAG_LOCK);
+ FLAG_LOCK);
// getWallpaperFile returns null if the lock screen isn't explicitly set, so need this
// check.
if (pfd != null) {
@@ -262,7 +283,8 @@ public class DefaultWallpaperRefresher implements WallpaperRefresher {
try {
fileStream.close();
} catch (IOException e) {
- Log.e(TAG, "IO exception when closing input stream for lock screen WP.");
+ Log.e(TAG,
+ "IO exception when closing input stream for lock screen WP.");
}
}
}
@@ -278,25 +300,25 @@ public class DefaultWallpaperRefresher implements WallpaperRefresher {
private boolean isHomeScreenImageWallpaperCurrent() {
long savedBitmapHash = mWallpaperPreferences.getHomeWallpaperHashCode();
- // Use WallpaperManager IDs to check same-ness of image wallpaper on N+ versions of Android
- // only when there is no saved bitmap hash code (which could be leftover from a previous build
- // of the app that did not use wallpaper IDs).
+ // Use WallpaperManager IDs to check same-ness of image wallpaper on N+ versions of
+ // Android only when there is no saved bitmap hash code (which could be leftover from a
+ // previous build of the app that did not use wallpaper IDs).
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && savedBitmapHash == 0) {
return mWallpaperPreferences.getHomeWallpaperManagerId()
- == mWallpaperManagerCompat.getWallpaperId(WallpaperManagerCompat.FLAG_SYSTEM);
+ == mWallpaperManagerCompat.getWallpaperId(FLAG_SYSTEM);
}
return savedBitmapHash == getCurrentHomeWallpaperHashCode();
}
/**
- * Returns whether the live wallpaper set to the system's home screen matches the metadata in
- * WallpaperPreferences.
+ * Returns whether the live wallpaper set to the system's home screen matches the metadata
+ * in WallpaperPreferences.
*/
private boolean isHomeScreenLiveWallpaperCurrent() {
- mSystemWallpaperPackageName = mWallpaperManager.getWallpaperInfo().getPackageName();
- String homeWallpaperPackageName = mWallpaperPreferences.getHomeWallpaperPackageName();
- return mSystemWallpaperPackageName.equals(homeWallpaperPackageName);
+ mSystemWallpaperServiceName = mWallpaperManager.getWallpaperInfo().getServiceName();
+ String homeWallpaperServiceName = mWallpaperPreferences.getHomeWallpaperServiceName();
+ return mSystemWallpaperServiceName.equals(homeWallpaperServiceName);
}
/**
@@ -304,18 +326,42 @@ public class DefaultWallpaperRefresher implements WallpaperRefresher {
* current lock screen wallpaper.
*/
private boolean isLockScreenMetadataCurrent() {
- // Check for lock wallpaper image same-ness only when there is no stored lock wallpaper hash
- // code. Otherwise if there is a lock wallpaper hash code stored in
+ return (mWallpaperManager.getWallpaperInfo(FLAG_LOCK) == null)
+ ? isLockScreenImageWallpaperCurrent()
+ : isLockScreenLiveWallpaperCurrent();
+ }
+
+ /**
+ * Returns whether the image wallpaper set for the lock screen matches the metadata in
+ * WallpaperPreferences.
+ */
+ private boolean isLockScreenImageWallpaperCurrent() {
+ // Check for lock wallpaper image same-ness only when there is no stored lock wallpaper
+ // hash code. Otherwise if there is a lock wallpaper hash code stored in
// {@link WallpaperPreferences}, then check hash codes.
long savedLockWallpaperHash = mWallpaperPreferences.getLockWallpaperHashCode();
- return (savedLockWallpaperHash == 0)
- ? mWallpaperPreferences.getLockWallpaperId()
- == mWallpaperManagerCompat.getWallpaperId(WallpaperManagerCompat.FLAG_LOCK)
- : savedLockWallpaperHash == getCurrentLockWallpaperHashCode();
+ if (savedLockWallpaperHash == 0) {
+ return mWallpaperPreferences.getLockWallpaperId()
+ == mWallpaperManagerCompat.getWallpaperId(FLAG_LOCK);
+ } else {
+ return savedLockWallpaperHash == getCurrentLockWallpaperHashCode();
+ }
}
/**
+ * Returns whether the live wallpaper for the home screen matches the metadata in
+ * WallpaperPreferences.
+ */
+ private boolean isLockScreenLiveWallpaperCurrent() {
+ String currentServiceName = mWallpaperManager.getWallpaperInfo(FLAG_LOCK)
+ .getServiceName();
+ String storedServiceName = mWallpaperPreferences.getLockWallpaperServiceName();
+ return currentServiceName.equals(storedServiceName);
+ }
+
+
+ /**
* Returns whether the lock screen attributions saved in WallpaperPreferences are empty.
*/
private boolean isLockScreenAttributionsEmpty() {