summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Poultney <poultney@google.com>2023-03-07 14:43:50 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2023-03-07 14:43:50 +0000
commite84806c791baefddf845f3d095a8b09a284a84d8 (patch)
tree84fa65d31f60d624ea8ffdaacdcc58f5a6329290
parentbf0a87de404d656f62d49df6c254873236ba0dc1 (diff)
parentaae32d8f6bbb3414c7c98f111867c0eee4b1ed21 (diff)
downloadWallpaperPicker2-e84806c791baefddf845f3d095a8b09a284a84d8.tar.gz
Merge "Improves updating of persisted live wallpaper metadata" into tm-qpr-dev
-rw-r--r--src/com/android/wallpaper/model/SetWallpaperViewModel.java2
-rwxr-xr-xsrc/com/android/wallpaper/module/DefaultWallpaperPersister.java50
-rwxr-xr-xsrc/com/android/wallpaper/module/WallpaperPersister.java32
-rw-r--r--src/com/android/wallpaper/module/WallpaperSetter.java11
-rw-r--r--src/com/android/wallpaper/picker/WallpaperPickerDelegate.java2
-rw-r--r--tests/src/com/android/wallpaper/testing/TestWallpaperPersister.java12
6 files changed, 74 insertions, 35 deletions
diff --git a/src/com/android/wallpaper/model/SetWallpaperViewModel.java b/src/com/android/wallpaper/model/SetWallpaperViewModel.java
index efd55d39..fcba06ee 100644
--- a/src/com/android/wallpaper/model/SetWallpaperViewModel.java
+++ b/src/com/android/wallpaper/model/SetWallpaperViewModel.java
@@ -47,7 +47,7 @@ public class SetWallpaperViewModel extends ViewModel {
SetWallpaperViewModel viewModel = provider.get(SetWallpaperViewModel.class);
return new SetWallpaperCallback() {
@Override
- public void onSuccess(WallpaperInfo wallpaperInfo) {
+ public void onSuccess(WallpaperInfo wallpaperInfo, @Destination int destination) {
Log.d(TAG, "SetWallpaperCallback success");
viewModel.mStatus.setValue(SetWallpaperStatus.SUCCESS);
}
diff --git a/src/com/android/wallpaper/module/DefaultWallpaperPersister.java b/src/com/android/wallpaper/module/DefaultWallpaperPersister.java
index 4d2aface..fdfc9be7 100755
--- a/src/com/android/wallpaper/module/DefaultWallpaperPersister.java
+++ b/src/com/android/wallpaper/module/DefaultWallpaperPersister.java
@@ -536,7 +536,7 @@ public class DefaultWallpaperPersister implements WallpaperPersister {
}
@Override
- public void onLiveWallpaperSet() {
+ public void onLiveWallpaperSet(@Destination int destination) {
android.app.WallpaperInfo currentWallpaperComponent = mWallpaperManager.getWallpaperInfo();
android.app.WallpaperInfo previewedWallpaperComponent = mWallpaperInfoInPreview != null
? mWallpaperInfoInPreview.getWallpaperComponent() : null;
@@ -551,7 +551,8 @@ public class DefaultWallpaperPersister implements WallpaperPersister {
return;
}
- setLiveWallpaperMetadata();
+ setLiveWallpaperMetadata(mWallpaperInfoInPreview, mWallpaperInfoInPreview.getEffectNames(),
+ destination);
}
/**
@@ -576,28 +577,29 @@ public class DefaultWallpaperPersister implements WallpaperPersister {
return isLockWallpaperSet;
}
- /**
- * Sets the live wallpaper's metadata on SharedPreferences.
- */
- private void setLiveWallpaperMetadata() {
- android.app.WallpaperInfo previewedWallpaperComponent =
- mWallpaperInfoInPreview.getWallpaperComponent();
+ @Override
+ public void setLiveWallpaperMetadata(WallpaperInfo wallpaperInfo, String effects,
+ @Destination int destination) {
+ android.app.WallpaperInfo component = wallpaperInfo.getWallpaperComponent();
+
+ if (destination == WallpaperPersister.DEST_HOME_SCREEN
+ || destination == WallpaperPersister.DEST_BOTH) {
+ mWallpaperPreferences.clearHomeWallpaperMetadata();
+ mWallpaperPreferences.setHomeWallpaperServiceName(component.getServiceName());
+ mWallpaperPreferences.setHomeWallpaperEffects(effects);
+
+ // Since rotation affects home screen only, disable it when setting home live wp
+ mWallpaperPreferences.setWallpaperPresentationMode(
+ WallpaperPreferences.PRESENTATION_MODE_STATIC);
+ mWallpaperPreferences.clearDailyRotations();
+ }
- mWallpaperPreferences.clearHomeWallpaperMetadata();
- // NOTE: We explicitly do not also clear the lock wallpaper metadata. Since the user may
- // have set the live wallpaper on the home screen only, we leave the lock wallpaper metadata
- // intact. If the user has set the live wallpaper for both home and lock screens, then the
- // WallpaperRefresher will pick up on that and update the preferences later.
- mWallpaperPreferences
- .setHomeWallpaperAttributions(mWallpaperInfoInPreview.getAttributions(mAppContext));
- mWallpaperPreferences.setHomeWallpaperServiceName(
- previewedWallpaperComponent.getServiceName());
- mWallpaperPreferences.setHomeWallpaperCollectionId(
- mWallpaperInfoInPreview.getCollectionId(mAppContext));
- mWallpaperPreferences.setWallpaperPresentationMode(
- WallpaperPreferences.PRESENTATION_MODE_STATIC);
- mWallpaperPreferences.clearDailyRotations();
- mWallpaperPreferences.setHomeWallpaperEffects(mWallpaperInfoInPreview.getEffectNames());
+ if (destination == WallpaperPersister.DEST_LOCK_SCREEN
+ || destination == WallpaperPersister.DEST_BOTH) {
+ mWallpaperPreferences.clearLockWallpaperMetadata();
+ mWallpaperPreferences.setLockWallpaperServiceName(component.getServiceName());
+ mWallpaperPreferences.setLockWallpaperEffects(effects);
+ }
}
private class SetWallpaperTask extends AsyncTask<Void, Void, Boolean> {
@@ -727,7 +729,7 @@ public class DefaultWallpaperPersister implements WallpaperPersister {
}
if (isSuccess) {
- mCallback.onSuccess(mWallpaper);
+ mCallback.onSuccess(mWallpaper, mDestination);
mWallpaperChangedNotifier.notifyWallpaperChanged();
} else {
mCallback.onError(null /* throwable */);
diff --git a/src/com/android/wallpaper/module/WallpaperPersister.java b/src/com/android/wallpaper/module/WallpaperPersister.java
index cfb3cab9..9b5cae82 100755
--- a/src/com/android/wallpaper/module/WallpaperPersister.java
+++ b/src/com/android/wallpaper/module/WallpaperPersister.java
@@ -167,14 +167,26 @@ public interface WallpaperPersister {
* Saves attributions to WallpaperPreferences for the last previewed wallpaper if it has an
* {@link android.app.WallpaperInfo} component matching the one currently set to the
* {@link android.app.WallpaperManager}.
+ *
+ * @param destination Live wallpaper destination (home/lock/both)
+ */
+ void onLiveWallpaperSet(@Destination int destination);
+
+ /**
+ * Updates lie wallpaper metadata by persisting them to SharedPreferences.
+ *
+ * @param wallpaperInfo Wallpaper model for the live wallpaper
+ * @param effects Comma-separate list of effect (see {@link WallpaperInfo#getEffectNames})
+ * @param destination Live wallpaper destination (home/lock/both)
*/
- void onLiveWallpaperSet();
+ void setLiveWallpaperMetadata(WallpaperInfo wallpaperInfo, String effects,
+ @Destination int destination);
/**
* Interface for tracking success or failure of set wallpaper operations.
*/
interface SetWallpaperCallback {
- void onSuccess(WallpaperInfo wallpaperInfo);
+ void onSuccess(WallpaperInfo wallpaperInfo, @Destination int destination);
void onError(@Nullable Throwable throwable);
}
@@ -215,4 +227,20 @@ public interface WallpaperPersister {
throw new AssertionError("Unknown @Destination");
}
}
+
+ /**
+ * Converts a set of {@link SetWallpaperFlags} to the corresponding {@link Destination}.
+ */
+ @Destination
+ static int flagsToDestination(@SetWallpaperFlags int flags) {
+ if (flags == (FLAG_SYSTEM | FLAG_LOCK)) {
+ return DEST_BOTH;
+ } else if (flags == FLAG_SYSTEM) {
+ return DEST_HOME_SCREEN;
+ } else if (flags == FLAG_LOCK) {
+ return DEST_LOCK_SCREEN;
+ } else {
+ throw new AssertionError("Unknown @SetWallpaperFlags value");
+ }
+ }
}
diff --git a/src/com/android/wallpaper/module/WallpaperSetter.java b/src/com/android/wallpaper/module/WallpaperSetter.java
index 14b47f70..b52cfd90 100644
--- a/src/com/android/wallpaper/module/WallpaperSetter.java
+++ b/src/com/android/wallpaper/module/WallpaperSetter.java
@@ -172,10 +172,11 @@ public class WallpaperSetter {
wallpaper, wallpaperAsset, cropRect,
wallpaperScale, destination, new SetWallpaperCallback() {
@Override
- public void onSuccess(WallpaperInfo wallpaperInfo) {
+ public void onSuccess(WallpaperInfo wallpaperInfo,
+ @Destination int destination) {
onWallpaperApplied(wallpaper, containerActivity);
if (callback != null) {
- callback.onSuccess(wallpaper);
+ callback.onSuccess(wallpaper, destination);
}
}
@@ -213,8 +214,9 @@ public class WallpaperSetter {
wallpaper.getWallpaperId(), wallpaper, colors);
onWallpaperApplied(wallpaper, activity);
if (callback != null) {
- callback.onSuccess(wallpaper);
+ callback.onSuccess(wallpaper, destination);
}
+ mWallpaperPersister.onLiveWallpaperSet(destination);
} catch (RuntimeException | IOException e) {
onWallpaperApplyError(e, activity);
if (callback != null) {
@@ -268,8 +270,9 @@ public class WallpaperSetter {
.getLowResBitmap(context)));
// Not call onWallpaperApplied() as no UI is presented.
if (callback != null) {
- callback.onSuccess(wallpaper);
+ callback.onSuccess(wallpaper, destination);
}
+ mWallpaperPersister.onLiveWallpaperSet(destination);
} catch (RuntimeException | IOException e) {
// Not call onWallpaperApplyError() as no UI is presented.
if (callback != null) {
diff --git a/src/com/android/wallpaper/picker/WallpaperPickerDelegate.java b/src/com/android/wallpaper/picker/WallpaperPickerDelegate.java
index 5b60c064..3c788ef4 100644
--- a/src/com/android/wallpaper/picker/WallpaperPickerDelegate.java
+++ b/src/com/android/wallpaper/picker/WallpaperPickerDelegate.java
@@ -467,7 +467,6 @@ public class WallpaperPickerDelegate implements MyPhotosStarter {
PREVIEW_WALLPAPER_REQUEST_CODE);
return false;
case PREVIEW_LIVE_WALLPAPER_REQUEST_CODE:
- mWallpaperPersister.onLiveWallpaperSet();
populateCategories(/* forceRefresh= */ true);
return true;
case VIEW_ONLY_PREVIEW_WALLPAPER_REQUEST_CODE:
@@ -475,7 +474,6 @@ public class WallpaperPickerDelegate implements MyPhotosStarter {
case PREVIEW_WALLPAPER_REQUEST_CODE:
// User previewed and selected a wallpaper, so finish this activity.
if (data != null && data.getBooleanExtra(IS_LIVE_WALLPAPER, false)) {
- mWallpaperPersister.onLiveWallpaperSet();
populateCategories(/* forceRefresh= */ true);
}
return true;
diff --git a/tests/src/com/android/wallpaper/testing/TestWallpaperPersister.java b/tests/src/com/android/wallpaper/testing/TestWallpaperPersister.java
index e5ea0be1..1ead2601 100644
--- a/tests/src/com/android/wallpaper/testing/TestWallpaperPersister.java
+++ b/tests/src/com/android/wallpaper/testing/TestWallpaperPersister.java
@@ -201,7 +201,7 @@ public class TestWallpaperPersister implements WallpaperPersister {
mCurrentLockWallpaper = mPendingLockWallpaper;
mPendingLockWallpaper = null;
}
- mCallback.onSuccess(mWallpaperInfo);
+ mCallback.onSuccess(mWallpaperInfo, mDestination);
mWallpaperChangedNotifier.notifyWallpaperChanged();
}
}
@@ -211,7 +211,12 @@ public class TestWallpaperPersister implements WallpaperPersister {
}
@Override
- public void onLiveWallpaperSet() {
+ public void onLiveWallpaperSet(@Destination int destination) {
+ }
+
+ @Override
+ public void setLiveWallpaperMetadata(WallpaperInfo wallpaperInfo, String effects,
+ @Destination int destination) {
}
/** Returns the last requested wallpaper bitmap scale. */
@@ -230,15 +235,18 @@ public class TestWallpaperPersister implements WallpaperPersister {
return mWallpaperPosition;
}
+ @Override
public boolean saveStaticWallpaperMetadata(List<String> attributions, String actionUrl,
int actionLabelRes, int actionIconRes, String collectionId, int wallpaperId) {
return false;
}
+ @Override
public int getDefaultWhichWallpaper() {
return 0;
}
+ @Override
public int setBitmapToWallpaperManagerCompat(Bitmap wallpaperBitmap, boolean allowBackup,
int whichWallpaper) {
return 0;