summaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/wallpaper/testing
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/com/android/wallpaper/testing')
-rw-r--r--tests/src/com/android/wallpaper/testing/TestAlarmManagerWrapper.java71
-rw-r--r--tests/src/com/android/wallpaper/testing/TestAsset.java99
-rw-r--r--tests/src/com/android/wallpaper/testing/TestBitmapCropper.java58
-rw-r--r--tests/src/com/android/wallpaper/testing/TestCategoryProvider.java94
-rw-r--r--tests/src/com/android/wallpaper/testing/TestCurrentWallpaperInfoFactory.java70
-rw-r--r--tests/src/com/android/wallpaper/testing/TestExploreIntentChecker.java44
-rw-r--r--tests/src/com/android/wallpaper/testing/TestFormFactorChecker.java41
-rw-r--r--tests/src/com/android/wallpaper/testing/TestInjector.java244
-rw-r--r--tests/src/com/android/wallpaper/testing/TestLoggingOptInStatusProvider.java27
-rw-r--r--tests/src/com/android/wallpaper/testing/TestNetworkStatusNotifier.java61
-rw-r--r--tests/src/com/android/wallpaper/testing/TestPartnerProvider.java58
-rw-r--r--tests/src/com/android/wallpaper/testing/TestPerformanceMonitor.java28
-rw-r--r--tests/src/com/android/wallpaper/testing/TestSystemFeatureChecker.java41
-rw-r--r--tests/src/com/android/wallpaper/testing/TestUserEventLogger.java289
-rw-r--r--tests/src/com/android/wallpaper/testing/TestWallpaperCategory.java59
-rw-r--r--tests/src/com/android/wallpaper/testing/TestWallpaperInfo.java228
-rw-r--r--tests/src/com/android/wallpaper/testing/TestWallpaperManagerCompat.java135
-rw-r--r--tests/src/com/android/wallpaper/testing/TestWallpaperPersister.java223
-rw-r--r--tests/src/com/android/wallpaper/testing/TestWallpaperPreferences.java457
-rw-r--r--tests/src/com/android/wallpaper/testing/TestWallpaperRefresher.java81
-rw-r--r--tests/src/com/android/wallpaper/testing/TestWallpaperRotationInitializer.java133
21 files changed, 2541 insertions, 0 deletions
diff --git a/tests/src/com/android/wallpaper/testing/TestAlarmManagerWrapper.java b/tests/src/com/android/wallpaper/testing/TestAlarmManagerWrapper.java
new file mode 100644
index 0000000..c9bbdd2
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestAlarmManagerWrapper.java
@@ -0,0 +1,71 @@
+/*
+ * 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.PendingIntent;
+
+import com.android.wallpaper.module.AlarmManagerWrapper;
+
+/**
+ * Mock of {@link AlarmManagerWrapper}.
+ */
+public class TestAlarmManagerWrapper implements AlarmManagerWrapper {
+
+ private int mExactAlarmSetCount;
+ private int mInexactAlarmSetCount;
+ private int mAlarmCanceledCount;
+
+ private long mLastInexactTriggerAtMillis;
+
+ @Override
+ public void set(int type, long triggerAtMillis, PendingIntent operation) {
+ mExactAlarmSetCount++;
+ }
+
+ @Override
+ public void setWindow(int type, long windowStartMillis, long windowLengthMillis,
+ PendingIntent operation) {
+ mExactAlarmSetCount++;
+ }
+
+ @Override
+ public void setInexactRepeating(int type, long triggerAtMillis, long intervalMillis,
+ PendingIntent operation) {
+ mInexactAlarmSetCount++;
+ mLastInexactTriggerAtMillis = triggerAtMillis;
+ }
+
+ @Override
+ public void cancel(PendingIntent operation) {
+ mAlarmCanceledCount++;
+ }
+
+ public int getExactAlarmSetCount() {
+ return mExactAlarmSetCount;
+ }
+
+ public int getInexactAlarmSetCount() {
+ return mInexactAlarmSetCount;
+ }
+
+ public int getAlarmCanceledCount() {
+ return mAlarmCanceledCount;
+ }
+
+ public long getLastInexactTriggerAtMillis() {
+ return mLastInexactTriggerAtMillis;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestAsset.java b/tests/src/com/android/wallpaper/testing/TestAsset.java
new file mode 100644
index 0000000..368919a
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestAsset.java
@@ -0,0 +1,99 @@
+/*
+ * 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.Activity;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Bitmap.Config;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.widget.ImageView;
+
+import androidx.annotation.Nullable;
+
+import com.android.wallpaper.asset.Asset;
+
+
+/**
+ * Test implementation of Asset which blocks on Bitmap decoding operations.
+ */
+public final class TestAsset extends Asset {
+
+ private Bitmap mBitmap;
+ private boolean mIsCorrupt;
+
+ /**
+ * Constructs an asset underpinned by a 1x1 bitmap uniquely identifiable by the given pixel
+ * color.
+ *
+ * @param pixelColor Color of the asset's single pixel.
+ * @param isCorrupt Whether or not the asset is corrupt and fails to validly decode bitmaps and
+ * dimensions.
+ */
+ public TestAsset(int pixelColor, boolean isCorrupt) {
+ mIsCorrupt = isCorrupt;
+
+ if (!mIsCorrupt) {
+ mBitmap = Bitmap.createBitmap(1, 1, Config.ARGB_8888);
+ mBitmap.setPixel(0, 0, pixelColor);
+ } else {
+ mBitmap = null;
+ }
+ }
+
+ @Override
+ public void decodeBitmap(int targetWidth, int targetHeight, BitmapReceiver receiver) {
+ receiver.onBitmapDecoded(mBitmap);
+ }
+
+ @Override
+ public void decodeBitmapRegion(Rect unused, int targetWidth, int targetHeight,
+ BitmapReceiver receiver) {
+ receiver.onBitmapDecoded(mBitmap);
+ }
+
+ @Override
+ public void decodeRawDimensions(Activity unused, DimensionsReceiver receiver) {
+ receiver.onDimensionsDecoded(mIsCorrupt ? null : new Point(1, 1));
+ }
+
+ @Override
+ public boolean supportsTiling() {
+ return false;
+ }
+
+ @Override
+ public void loadDrawableWithTransition(
+ Context context,
+ ImageView imageView,
+ int transitionDurationMillis,
+ @Nullable DrawableLoadedListener drawableLoadedListener,
+ int placeholderColor) {
+ if (drawableLoadedListener != null) {
+ drawableLoadedListener.onDrawableLoaded();
+ }
+ }
+
+ /** Returns the bitmap synchronously. Convenience method for tests. */
+ public Bitmap getBitmap() {
+ return mBitmap;
+ }
+
+ public void setBitmap(Bitmap bitmap) {
+ mBitmap = bitmap;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestBitmapCropper.java b/tests/src/com/android/wallpaper/testing/TestBitmapCropper.java
new file mode 100644
index 0000000..7daeeab
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestBitmapCropper.java
@@ -0,0 +1,58 @@
+/*
+ * 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.graphics.Bitmap;
+import android.graphics.Rect;
+
+import com.android.wallpaper.asset.Asset;
+import com.android.wallpaper.asset.Asset.BitmapReceiver;
+import com.android.wallpaper.module.BitmapCropper;
+
+/**
+ * Test double for BitmapCropper.
+ */
+public class TestBitmapCropper implements BitmapCropper {
+
+ private boolean mFailNextCall;
+
+ public TestBitmapCropper() {
+ mFailNextCall = false;
+ }
+
+ @Override
+ public void cropAndScaleBitmap(Asset asset, float scale, Rect cropRect,
+ Callback callback) {
+ if (mFailNextCall) {
+ callback.onError(null /* throwable */);
+ return;
+ }
+ // Crop rect in pixels of source image.
+ Rect scaledCropRect = new Rect(
+ Math.round((float) cropRect.left / scale),
+ Math.round((float) cropRect.top / scale),
+ Math.round((float) cropRect.right / scale),
+ Math.round((float) cropRect.bottom / scale));
+
+ asset.decodeBitmapRegion(scaledCropRect, cropRect.width(), cropRect.height(),
+ new BitmapReceiver() {
+ @Override
+ public void onBitmapDecoded(Bitmap bitmap) {
+ callback.onBitmapCropped(bitmap);
+ }
+ });
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestCategoryProvider.java b/tests/src/com/android/wallpaper/testing/TestCategoryProvider.java
new file mode 100644
index 0000000..310840c
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestCategoryProvider.java
@@ -0,0 +1,94 @@
+/*
+ * 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.os.Handler;
+
+import com.android.wallpaper.model.Category;
+import com.android.wallpaper.model.CategoryProvider;
+import com.android.wallpaper.model.CategoryReceiver;
+import com.android.wallpaper.model.ImageCategory;
+import com.android.wallpaper.model.WallpaperInfo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Test implementation of {@link CategoryProvider}.
+ */
+public class TestCategoryProvider implements CategoryProvider {
+ private final List<Category> mCategories;
+
+ public TestCategoryProvider() {
+ Category category1 = new ImageCategory(
+ "My photos" /* title */,
+ "image_wallpapers" /* collection */,
+ 0 /* priority */);
+
+ ArrayList<WallpaperInfo> wallpapers = new ArrayList<>();
+ WallpaperInfo wallpaperInfo = new com.android.wallpaper.testing.TestWallpaperInfo(0);
+ wallpapers.add(wallpaperInfo);
+ Category category2 = new com.android.wallpaper.testing.TestWallpaperCategory(
+ "Test category", "init_collection", wallpapers,
+ 1 /* priority */);
+
+ mCategories = new ArrayList<>();
+ mCategories.add(category1);
+ mCategories.add(category2);
+ }
+
+ @Override
+ public void fetchCategories(CategoryReceiver receiver, boolean forceRefresh) {
+ // Mimic real behavior by fetching asynchronously.
+ new Handler().post(new Runnable() {
+ @Override
+ public void run() {
+ List<Category> categories = getTestCategories();
+ for (Category category : categories) {
+ receiver.onCategoryReceived(category);
+ }
+ receiver.doneFetchingCategories();
+ }
+ });
+ }
+
+ @Override
+ public int getSize() {
+ return mCategories == null ? 0 : mCategories.size();
+ }
+
+ @Override
+ public Category getCategory(int index) {
+ return mCategories == null ? null : mCategories.get(index);
+ }
+
+ @Override
+ public Category getCategory(String collectionId) {
+ Category category;
+ for (int i = 0; i < mCategories.size(); i++) {
+ category = mCategories.get(i);
+ if (category.getCollectionId().equals(collectionId)) {
+ return category;
+ }
+ }
+ return null;
+ }
+
+ /** Returns a list of test Category objects used by this TestCategoryProvider. */
+ public List<Category> getTestCategories() {
+ return mCategories;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestCurrentWallpaperInfoFactory.java b/tests/src/com/android/wallpaper/testing/TestCurrentWallpaperInfoFactory.java
new file mode 100644
index 0000000..3e8c665
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestCurrentWallpaperInfoFactory.java
@@ -0,0 +1,70 @@
+/*
+ * 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.content.Context;
+
+import com.android.wallpaper.compat.BuildCompat;
+import com.android.wallpaper.model.WallpaperInfo;
+import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
+import com.android.wallpaper.module.InjectorProvider;
+import com.android.wallpaper.module.WallpaperRefresher;
+
+import java.util.List;
+
+/**
+ * Test double of {@link CurrentWallpaperInfoFactory}.
+ */
+public class TestCurrentWallpaperInfoFactory implements CurrentWallpaperInfoFactory {
+
+ private WallpaperRefresher mRefresher;
+
+ public TestCurrentWallpaperInfoFactory(Context context) {
+ mRefresher = InjectorProvider.getInjector().getWallpaperRefresher(
+ context.getApplicationContext());
+ }
+
+ @Override
+ public void createCurrentWallpaperInfos(final WallpaperInfoCallback callback,
+ boolean forceRefresh) {
+ mRefresher.refresh((homeWallpaperMetadata, lockWallpaperMetadata, presentationMode) -> {
+
+ WallpaperInfo homeWallpaper = createTestWallpaperInfo(
+ homeWallpaperMetadata.getAttributions(),
+ homeWallpaperMetadata.getActionUrl(),
+ homeWallpaperMetadata.getCollectionId());
+
+ WallpaperInfo lockWallpaper = null;
+ if (lockWallpaperMetadata != null && BuildCompat.isAtLeastN()) {
+ lockWallpaper = createTestWallpaperInfo(
+ lockWallpaperMetadata.getAttributions(),
+ lockWallpaperMetadata.getActionUrl(),
+ lockWallpaperMetadata.getCollectionId());
+ }
+
+ callback.onWallpaperInfoCreated(homeWallpaper, lockWallpaper, presentationMode);
+ });
+ }
+
+ private static WallpaperInfo createTestWallpaperInfo(List<String> attributions,
+ String actionUrl, String collectionId) {
+ TestWallpaperInfo wallpaper = new TestWallpaperInfo(TestWallpaperInfo.COLOR_BLACK);
+ wallpaper.setAttributions(attributions);
+ wallpaper.setActionUrl(actionUrl);
+ wallpaper.setCollectionId(collectionId);
+ return wallpaper;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestExploreIntentChecker.java b/tests/src/com/android/wallpaper/testing/TestExploreIntentChecker.java
new file mode 100644
index 0000000..dc1f1a8
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestExploreIntentChecker.java
@@ -0,0 +1,44 @@
+/*
+ * 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.content.Intent;
+import android.net.Uri;
+
+import com.android.wallpaper.module.ExploreIntentChecker;
+
+/**
+ * Test implementation of ExploreIntentChecker.
+ */
+public class TestExploreIntentChecker implements ExploreIntentChecker {
+
+ private boolean mViewHandlerExists;
+
+ public TestExploreIntentChecker() {
+ // True by default.
+ mViewHandlerExists = true;
+ }
+
+ @Override
+ public void fetchValidActionViewIntent(Uri uri, IntentReceiver receiver) {
+ Intent intent = mViewHandlerExists ? new Intent(Intent.ACTION_VIEW, uri) : null;
+ receiver.onIntentReceived(intent);
+ }
+
+ public void setViewHandlerExists(boolean exists) {
+ mViewHandlerExists = exists;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestFormFactorChecker.java b/tests/src/com/android/wallpaper/testing/TestFormFactorChecker.java
new file mode 100644
index 0000000..ba77172
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestFormFactorChecker.java
@@ -0,0 +1,41 @@
+/*
+ * 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 com.android.wallpaper.module.FormFactorChecker;
+
+/**
+ * Test implementation of {@code FormFactorChecker}.
+ */
+public class TestFormFactorChecker implements FormFactorChecker {
+
+ @FormFactor
+ private int mFormFactor;
+
+ public TestFormFactorChecker() {
+ mFormFactor = FORM_FACTOR_MOBILE;
+ }
+
+ @FormFactor
+ @Override
+ public int getFormFactor() {
+ return mFormFactor;
+ }
+
+ public void setFormFactor(@FormFactor int formFactor) {
+ mFormFactor = formFactor;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestInjector.java b/tests/src/com/android/wallpaper/testing/TestInjector.java
new file mode 100644
index 0000000..0da755e
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestInjector.java
@@ -0,0 +1,244 @@
+/*
+ * 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.content.Context;
+
+import androidx.fragment.app.Fragment;
+
+import com.android.wallpaper.compat.WallpaperManagerCompat;
+import com.android.wallpaper.model.CategoryProvider;
+import com.android.wallpaper.model.WallpaperInfo;
+import com.android.wallpaper.module.AlarmManagerWrapper;
+import com.android.wallpaper.module.BitmapCropper;
+import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
+import com.android.wallpaper.module.DefaultLiveWallpaperInfoFactory;
+import com.android.wallpaper.module.DrawableLayerResolver;
+import com.android.wallpaper.module.ExploreIntentChecker;
+import com.android.wallpaper.module.FormFactorChecker;
+import com.android.wallpaper.module.Injector;
+import com.android.wallpaper.module.LiveWallpaperInfoFactory;
+import com.android.wallpaper.module.LoggingOptInStatusProvider;
+import com.android.wallpaper.module.NetworkStatusNotifier;
+import com.android.wallpaper.module.PackageStatusNotifier;
+import com.android.wallpaper.module.PartnerProvider;
+import com.android.wallpaper.module.SystemFeatureChecker;
+import com.android.wallpaper.module.UserEventLogger;
+import com.android.wallpaper.module.WallpaperPersister;
+import com.android.wallpaper.module.WallpaperPreferences;
+import com.android.wallpaper.module.WallpaperRefresher;
+import com.android.wallpaper.module.WallpaperRotationRefresher;
+import com.android.wallpaper.monitor.PerformanceMonitor;
+import com.android.wallpaper.network.Requester;
+import com.android.wallpaper.picker.ImagePreviewFragment;
+import com.android.wallpaper.picker.individual.IndividualPickerFragment;
+
+/**
+ * Test implementation of the dependency injector.
+ */
+public class TestInjector implements Injector {
+
+ private BitmapCropper mBitmapCropper;
+ private CategoryProvider mCategoryProvider;
+ private PartnerProvider mPartnerProvider;
+ private WallpaperPreferences mPrefs;
+ private WallpaperPersister mWallpaperPersister;
+ private WallpaperRefresher mWallpaperRefresher;
+ private Requester mRequester;
+ private WallpaperManagerCompat mWallpaperManagerCompat;
+ private CurrentWallpaperInfoFactory mCurrentWallpaperInfoFactory;
+ private NetworkStatusNotifier mNetworkStatusNotifier;
+ private AlarmManagerWrapper mAlarmManagerWrapper;
+ private UserEventLogger mUserEventLogger;
+ private ExploreIntentChecker mExploreIntentChecker;
+ private SystemFeatureChecker mSystemFeatureChecker;
+ private FormFactorChecker mFormFactorChecker;
+ private WallpaperRotationRefresher mWallpaperRotationRefresher;
+ private PerformanceMonitor mPerformanceMonitor;
+ private LoggingOptInStatusProvider mLoggingOptInStatusProvider;
+
+ @Override
+ public BitmapCropper getBitmapCropper() {
+ if (mBitmapCropper == null) {
+ mBitmapCropper = new com.android.wallpaper.testing.TestBitmapCropper();
+ }
+ return mBitmapCropper;
+ }
+
+ @Override
+ public CategoryProvider getCategoryProvider(Context context) {
+ if (mCategoryProvider == null) {
+ mCategoryProvider = new TestCategoryProvider();
+ }
+ return mCategoryProvider;
+ }
+
+ @Override
+ public PartnerProvider getPartnerProvider(Context context) {
+ if (mPartnerProvider == null) {
+ mPartnerProvider = new TestPartnerProvider();
+ }
+ return mPartnerProvider;
+ }
+
+ @Override
+ public WallpaperPreferences getPreferences(Context context) {
+ if (mPrefs == null) {
+ mPrefs = new TestWallpaperPreferences();
+ }
+ return mPrefs;
+ }
+
+ @Override
+ public WallpaperPersister getWallpaperPersister(Context context) {
+ if (mWallpaperPersister == null) {
+ mWallpaperPersister = new TestWallpaperPersister(context.getApplicationContext());
+ }
+ return mWallpaperPersister;
+ }
+
+ @Override
+ public WallpaperRefresher getWallpaperRefresher(Context context) {
+ if (mWallpaperRefresher == null) {
+ mWallpaperRefresher = new TestWallpaperRefresher(context.getApplicationContext());
+ }
+ return mWallpaperRefresher;
+ }
+
+ @Override
+ public Requester getRequester(Context unused) {
+ return null;
+ }
+
+ @Override
+ public WallpaperManagerCompat getWallpaperManagerCompat(Context context) {
+ if (mWallpaperManagerCompat == null) {
+ mWallpaperManagerCompat = new com.android.wallpaper.testing.TestWallpaperManagerCompat(
+ context.getApplicationContext());
+ }
+ return mWallpaperManagerCompat;
+ }
+
+ @Override
+ public CurrentWallpaperInfoFactory getCurrentWallpaperFactory(Context context) {
+ if (mCurrentWallpaperInfoFactory == null) {
+ mCurrentWallpaperInfoFactory =
+ new TestCurrentWallpaperInfoFactory(context.getApplicationContext());
+ }
+ return mCurrentWallpaperInfoFactory;
+ }
+
+ @Override
+ public LoggingOptInStatusProvider getLoggingOptInStatusProvider(Context context) {
+ if (mLoggingOptInStatusProvider == null) {
+ mLoggingOptInStatusProvider = new TestLoggingOptInStatusProvider();
+ }
+ return mLoggingOptInStatusProvider;
+ }
+
+ @Override
+ public NetworkStatusNotifier getNetworkStatusNotifier(Context context) {
+ if (mNetworkStatusNotifier == null) {
+ mNetworkStatusNotifier = new TestNetworkStatusNotifier();
+ }
+ return mNetworkStatusNotifier;
+ }
+
+ @Override
+ public AlarmManagerWrapper getAlarmManagerWrapper(Context unused) {
+ if (mAlarmManagerWrapper == null) {
+ mAlarmManagerWrapper = new TestAlarmManagerWrapper();
+ }
+ return mAlarmManagerWrapper;
+ }
+
+ @Override
+ public UserEventLogger getUserEventLogger(Context unused) {
+ if (mUserEventLogger == null) {
+ mUserEventLogger = new com.android.wallpaper.testing.TestUserEventLogger();
+ }
+ return mUserEventLogger;
+ }
+
+ @Override
+ public ExploreIntentChecker getExploreIntentChecker(Context unused) {
+ if (mExploreIntentChecker == null) {
+ mExploreIntentChecker = new TestExploreIntentChecker();
+ }
+ return mExploreIntentChecker;
+ }
+
+ @Override
+ public SystemFeatureChecker getSystemFeatureChecker() {
+ if (mSystemFeatureChecker == null) {
+ mSystemFeatureChecker = new com.android.wallpaper.testing.TestSystemFeatureChecker();
+ }
+ return mSystemFeatureChecker;
+ }
+
+ @Override
+ public FormFactorChecker getFormFactorChecker(Context unused) {
+ if (mFormFactorChecker == null) {
+ mFormFactorChecker = new TestFormFactorChecker();
+ }
+ return mFormFactorChecker;
+ }
+
+ @Override
+ public WallpaperRotationRefresher getWallpaperRotationRefresher() {
+ if (mWallpaperRotationRefresher == null) {
+ mWallpaperRotationRefresher = (context, listener) -> {
+ // Not implemented
+ listener.onError();
+ };
+ }
+ return mWallpaperRotationRefresher;
+ }
+
+ @Override
+ public Fragment getPreviewFragment(Context context, WallpaperInfo wallpaperInfo, int mode,
+ boolean testingModeEnabled) {
+ return ImagePreviewFragment.newInstance(wallpaperInfo, mode, testingModeEnabled);
+ }
+
+ @Override
+ public PackageStatusNotifier getPackageStatusNotifier(Context context) {
+ return null;
+ }
+
+ @Override
+ public IndividualPickerFragment getIndividualPickerFragment(String collectionId) {
+ return IndividualPickerFragment.newInstance(collectionId);
+ }
+
+ @Override
+ public LiveWallpaperInfoFactory getLiveWallpaperInfoFactory(Context context) {
+ return new DefaultLiveWallpaperInfoFactory();
+ }
+
+ @Override
+ public DrawableLayerResolver getDrawableLayerResolver() {
+ return null;
+ }
+
+ @Override
+ public PerformanceMonitor getPerformanceMonitor() {
+ if (mPerformanceMonitor == null) {
+ mPerformanceMonitor = new TestPerformanceMonitor();
+ }
+ return mPerformanceMonitor;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestLoggingOptInStatusProvider.java b/tests/src/com/android/wallpaper/testing/TestLoggingOptInStatusProvider.java
new file mode 100644
index 0000000..f4434b1
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestLoggingOptInStatusProvider.java
@@ -0,0 +1,27 @@
+/*
+ * 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 com.android.wallpaper.module.LoggingOptInStatusProvider;
+
+/** Test implementation of {@link LoggingOptInStatusProvider}. */
+public class TestLoggingOptInStatusProvider implements LoggingOptInStatusProvider {
+
+ @Override
+ public void fetchOptInValue(OptInValueReceiver receiver) {
+ receiver.onOptInValueReady(true /* optedIn */);
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestNetworkStatusNotifier.java b/tests/src/com/android/wallpaper/testing/TestNetworkStatusNotifier.java
new file mode 100644
index 0000000..b09ee43
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestNetworkStatusNotifier.java
@@ -0,0 +1,61 @@
+/*
+ * 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 com.android.wallpaper.module.NetworkStatusNotifier;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Test implementation of {@link NetworkStatusNotifier} which enables clients to manually notify
+ * listeners of a network status change.
+ */
+public class TestNetworkStatusNotifier implements NetworkStatusNotifier {
+
+ private List<Listener> mListeners;
+ @NetworkStatus
+ private int mNetworkStatus;
+
+ public TestNetworkStatusNotifier() {
+ mListeners = new ArrayList<>();
+ mNetworkStatus = NETWORK_CONNECTED;
+ }
+
+ @Override
+ public int getNetworkStatus() {
+ return mNetworkStatus;
+ }
+
+ @Override
+ public void registerListener(Listener listener) {
+ mListeners.add(listener);
+ listener.onNetworkChanged(mNetworkStatus);
+ }
+
+ @Override
+ public void unregisterListener(Listener listener) {
+ mListeners.remove(listener);
+ }
+
+ public void setAndNotifyNetworkStatus(@NetworkStatus int networkStatus) {
+ mNetworkStatus = networkStatus;
+ for (Listener listener : mListeners) {
+ listener.onNetworkChanged(mNetworkStatus);
+ }
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestPartnerProvider.java b/tests/src/com/android/wallpaper/testing/TestPartnerProvider.java
new file mode 100644
index 0000000..fbdd0af
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestPartnerProvider.java
@@ -0,0 +1,58 @@
+/*
+ * 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.content.res.Resources;
+
+import com.android.wallpaper.module.PartnerProvider;
+
+import java.io.File;
+
+/**
+ * Test implementation for PartnerProvider.
+ */
+public class TestPartnerProvider implements PartnerProvider {
+ private File mLegacyWallpaperDirectory;
+
+ @Override
+ public Resources getResources() {
+ return null;
+ }
+
+ @Override
+ public File getLegacyWallpaperDirectory() {
+ return mLegacyWallpaperDirectory;
+ }
+
+ /**
+ * Sets the File to be returned by subsequent calls to getLegacyWallpaperDirectory().
+ *
+ * @param dir The legacy wallpaper directory.
+ */
+ public void setLegacyWallpaperDirectory(File dir) {
+ mLegacyWallpaperDirectory = dir;
+ }
+
+ @Override
+ public String getPackageName() {
+ return null;
+ }
+
+ @Override
+ public boolean shouldHideDefaultWallpaper() {
+ return false;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestPerformanceMonitor.java b/tests/src/com/android/wallpaper/testing/TestPerformanceMonitor.java
new file mode 100644
index 0000000..7fe3ade
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestPerformanceMonitor.java
@@ -0,0 +1,28 @@
+/*
+ * 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 com.android.wallpaper.monitor.PerformanceMonitor;
+
+/**
+ * No-op performance monitor for test.
+ */
+public class TestPerformanceMonitor implements PerformanceMonitor {
+
+ @Override
+ public void recordFullResPreviewLoadedMemorySnapshot() {
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestSystemFeatureChecker.java b/tests/src/com/android/wallpaper/testing/TestSystemFeatureChecker.java
new file mode 100644
index 0000000..775e693
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestSystemFeatureChecker.java
@@ -0,0 +1,41 @@
+/*
+ * 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.content.Context;
+
+import com.android.wallpaper.module.SystemFeatureChecker;
+
+/**
+ * Test implementation of {@link SystemFeatureChecker}.
+ */
+public class TestSystemFeatureChecker implements SystemFeatureChecker {
+
+ private boolean mHasTelephony;
+
+ public TestSystemFeatureChecker() {
+ mHasTelephony = true;
+ }
+
+ @Override
+ public boolean hasTelephony(Context context) {
+ return mHasTelephony;
+ }
+
+ public void setHasTelephony(boolean hasTelephony) {
+ mHasTelephony = hasTelephony;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestUserEventLogger.java b/tests/src/com/android/wallpaper/testing/TestUserEventLogger.java
new file mode 100644
index 0000000..9f0489e
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestUserEventLogger.java
@@ -0,0 +1,289 @@
+/*
+ * 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 com.android.wallpaper.module.UserEventLogger;
+import com.android.wallpaper.module.WallpaperPersister.WallpaperPosition;
+
+/**
+ * Test implementation of {@link UserEventLogger}.
+ */
+public class TestUserEventLogger implements UserEventLogger {
+
+ private int mNumDailyRefreshTurnedOnEvents;
+ private int mNumCurrentWallpaperPreviewedEvents;
+ private int mNumActionClickedEvents;
+ private int mNumIndividualWallpaperSelectedEvents;
+ private int mNumCategorySelectedEvents;
+ private int mNumWallpaperSetEvents;
+ private int mNumWallpaperSetResultEvents;
+ private String mLastCollectionId;
+ private String mLastWallpaperId;
+ @WallpaperSetResult
+ private int mLastWallpaperSetResult;
+ private int mLastDailyRotationHour;
+ private int mNum1DayActiveLogs;
+ private int mNum7DayActiveLogs;
+ private int mNum14DayActiveLogs;
+ private int mNum28DayActiveLogs;
+ private int mLastDailyWallpaperRotationStatus;
+ private int mNumDaysDailyRotationFailed;
+ private int mNumDaysDailyRotationNotAttempted;
+ private int mLastDailyWallpaperUpdateResult;
+ private int mStandalonePreviewLaunches;
+ private int mNumRestores;
+ @WallpaperPosition
+ private int mWallpaperPosition;
+
+ public TestUserEventLogger() {
+ mLastDailyRotationHour = -1;
+ mLastDailyWallpaperRotationStatus = -1;
+ mNumDaysDailyRotationFailed = -1;
+ mNumDaysDailyRotationNotAttempted = -1;
+ }
+
+ @Override
+ public void logResumed(boolean provisioned, boolean wallpaper) {
+
+ }
+
+ @Override
+ public void logStopped() {
+
+ }
+
+ @Override
+ public void logAppLaunched() {
+ // Do nothing.
+ }
+
+ @Override
+ public void logDailyRefreshTurnedOn() {
+ mNumDailyRefreshTurnedOnEvents++;
+ }
+
+ public int getNumDailyRefreshTurnedOnEvents() {
+ return mNumDailyRefreshTurnedOnEvents;
+ }
+
+ @Override
+ public void logCurrentWallpaperPreviewed() {
+ mNumCurrentWallpaperPreviewedEvents++;
+ }
+
+ @Override
+ public void logActionClicked(String collectionId, int actionLabelResId) {
+ mNumActionClickedEvents++;
+ mLastCollectionId = collectionId;
+ }
+
+ public int getNumCurrentWallpaperPreviewedEvents() {
+ return mNumCurrentWallpaperPreviewedEvents;
+ }
+
+ public int getNumActionClickedEvents() {
+ return mNumActionClickedEvents;
+ }
+
+ @Override
+ public void logIndividualWallpaperSelected(String collectionId) {
+ mNumIndividualWallpaperSelectedEvents++;
+ mLastCollectionId = collectionId;
+ }
+
+ public int getNumIndividualWallpaperSelectedEvents() {
+ return mNumIndividualWallpaperSelectedEvents;
+ }
+
+ @Override
+ public void logCategorySelected(String collectionId) {
+ mNumCategorySelectedEvents++;
+ mLastCollectionId = collectionId;
+ }
+
+ public int getNumCategorySelectedEvents() {
+ return mNumCategorySelectedEvents;
+ }
+
+ @Override
+ public void logWallpaperSet(String collectionId, String wallpaperId) {
+ mNumWallpaperSetEvents++;
+ mLastCollectionId = collectionId;
+ mLastWallpaperId = wallpaperId;
+ }
+
+ @Override
+ public void logWallpaperSetResult(@WallpaperSetResult int result) {
+ mNumWallpaperSetResultEvents++;
+ mLastWallpaperSetResult = result;
+ }
+
+ @Override
+ public void logWallpaperSetFailureReason(@WallpaperSetFailureReason int reason) {
+ // No-op
+ }
+
+
+ @Override
+ public void logNumDailyWallpaperRotationsInLastWeek() {
+ // No-op
+ }
+
+ @Override
+ public void logNumDailyWallpaperRotationsPreviousDay() {
+ // No-op
+ }
+
+ @Override
+ public void logDailyWallpaperRotationHour(int hour) {
+ mLastDailyRotationHour = hour;
+ }
+
+ @Override
+ public void logDailyWallpaperDecodes(boolean decodes) {
+ // No-op
+ }
+
+ @Override
+ public void logRefreshDailyWallpaperButtonClicked() {
+ // No-op
+ }
+
+ @Override
+ public void logDailyWallpaperRotationStatus(int status) {
+ mLastDailyWallpaperRotationStatus = status;
+ }
+
+ @Override
+ public void logDailyWallpaperSetNextWallpaperResult(@DailyWallpaperUpdateResult int result) {
+ mLastDailyWallpaperUpdateResult = result;
+ }
+
+ @Override
+ public void logDailyWallpaperSetNextWallpaperCrash(@DailyWallpaperUpdateCrash int crash) {
+ // No-op
+ }
+
+ @Override
+ public void logNumDaysDailyRotationFailed(int days) {
+ mNumDaysDailyRotationFailed = days;
+ }
+
+ @Override
+ public void logDailyWallpaperMetadataRequestFailure(
+ @DailyWallpaperMetadataFailureReason int reason) {
+ // No-op
+ }
+
+ @Override
+ public void logNumDaysDailyRotationNotAttempted(int days) {
+ mNumDaysDailyRotationNotAttempted = days;
+ }
+
+ @Override
+ public void logStandalonePreviewLaunched() {
+ mStandalonePreviewLaunches++;
+ }
+
+ @Override
+ public void logStandalonePreviewImageUriHasReadPermission(boolean isReadPermissionGranted) {
+ // No-op
+ }
+
+ @Override
+ public void logStandalonePreviewStorageDialogApproved(boolean isApproved) {
+ // No-op
+ }
+
+ @Override
+ public void logWallpaperPresentationMode() {
+ // No-op
+ }
+
+ @Override
+ public void logRestored() {
+ mNumRestores++;
+ }
+
+ public int getNumWallpaperSetEvents() {
+ return mNumWallpaperSetEvents;
+ }
+
+ public String getLastCollectionId() {
+ return mLastCollectionId;
+ }
+
+ public String getLastWallpaperId() {
+ return mLastWallpaperId;
+ }
+
+ public int getNumWallpaperSetResultEvents() {
+ return mNumWallpaperSetResultEvents;
+ }
+
+ @WallpaperSetResult
+ public int getLastWallpaperSetResult() {
+ return mLastWallpaperSetResult;
+ }
+
+ public int getLastDailyRotationHour() {
+ return mLastDailyRotationHour;
+ }
+
+ public int getNum1DayActiveLogs() {
+ return mNum1DayActiveLogs;
+ }
+
+ public int getNum7DayActiveLogs() {
+ return mNum7DayActiveLogs;
+ }
+
+ public int getNum14DayActiveLogs() {
+ return mNum14DayActiveLogs;
+ }
+
+ public int getNum28DayActiveLogs() {
+ return mNum28DayActiveLogs;
+ }
+
+ public int getLastDailyWallpaperRotationStatus() {
+ return mLastDailyWallpaperRotationStatus;
+ }
+
+ public int getNumDaysDailyRotationFailed() {
+ return mNumDaysDailyRotationFailed;
+ }
+
+ public int getNumDaysDailyRotationNotAttempted() {
+ return mNumDaysDailyRotationNotAttempted;
+ }
+
+ public int getLastDailyWallpaperUpdateResult() {
+ return mLastDailyWallpaperUpdateResult;
+ }
+
+ public int getStandalonePreviewLaunches() {
+ return mStandalonePreviewLaunches;
+ }
+
+ public int getNumRestores() {
+ return mNumRestores;
+ }
+
+ public int getWallpaperPosition() {
+ return mWallpaperPosition;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestWallpaperCategory.java b/tests/src/com/android/wallpaper/testing/TestWallpaperCategory.java
new file mode 100644
index 0000000..c69ecf8
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestWallpaperCategory.java
@@ -0,0 +1,59 @@
+/*
+ * 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 com.android.wallpaper.model.WallpaperCategory;
+import com.android.wallpaper.model.WallpaperInfo;
+import com.android.wallpaper.model.WallpaperRotationInitializer;
+import com.android.wallpaper.model.WallpaperRotationInitializer.RotationInitializationState;
+
+import java.util.List;
+
+/**
+ * Test-only subclass of {@link WallpaperCategory} which can be configured to provide a test double
+ * {@link WallpaperRotationInitializer}.
+ */
+public class TestWallpaperCategory extends WallpaperCategory {
+ private boolean mIsRotationEnabled;
+ private TestWallpaperRotationInitializer mWallpaperRotationInitializer;
+
+ public TestWallpaperCategory(String title, String collectionId, List<WallpaperInfo> wallpapers,
+ int priority) {
+ super(title, collectionId, wallpapers, priority);
+ mIsRotationEnabled = false;
+ mWallpaperRotationInitializer = new TestWallpaperRotationInitializer();
+ }
+
+ @Override
+ public WallpaperRotationInitializer getWallpaperRotationInitializer() {
+ return (mIsRotationEnabled) ? mWallpaperRotationInitializer : null;
+ }
+
+ @Override
+ public List<WallpaperInfo> getMutableWallpapers() {
+ return super.getMutableWallpapers();
+ }
+
+ /** Sets whether rotation is enabled on this category. */
+ public void setIsRotationEnabled(boolean isRotationEnabled) {
+ mIsRotationEnabled = isRotationEnabled;
+ }
+
+ public void setRotationInitializationState(@RotationInitializationState int rotationState) {
+ mWallpaperRotationInitializer.setRotationInitializationState(rotationState);
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestWallpaperInfo.java b/tests/src/com/android/wallpaper/testing/TestWallpaperInfo.java
new file mode 100644
index 0000000..c0ccee6
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestWallpaperInfo.java
@@ -0,0 +1,228 @@
+/*
+ * 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.Activity;
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.android.wallpaper.asset.Asset;
+import com.android.wallpaper.model.InlinePreviewIntentFactory;
+import com.android.wallpaper.model.WallpaperInfo;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Test model object for a wallpaper coming from local drawable resources.
+ */
+public class TestWallpaperInfo extends WallpaperInfo {
+ public static final int COLOR_BLACK = 0;
+ public static final Parcelable.Creator<TestWallpaperInfo> CREATOR =
+ new Parcelable.Creator<TestWallpaperInfo>() {
+ @Override
+ public TestWallpaperInfo createFromParcel(Parcel in) {
+ return new TestWallpaperInfo(in);
+ }
+
+ @Override
+ public TestWallpaperInfo[] newArray(int size) {
+ return new TestWallpaperInfo[size];
+ }
+ };
+ private int mPixelColor;
+ private TestAsset mAsset;
+ private TestAsset mThumbAsset;
+ private List<String> mAttributions;
+ private android.app.WallpaperInfo mWallpaperComponent;
+ private String mActionUrl;
+ private String mBaseImageUrl;
+ private String mCollectionId;
+ private String mWallpaperId;
+ private boolean mIsAssetCorrupt;
+ private int mBackupPermission;
+
+ /** Constructs a test WallpaperInfo object representing a 1x1 wallpaper of the given color. */
+ public TestWallpaperInfo(int pixelColor) {
+ this(pixelColor, "test-wallpaper");
+ }
+
+ /** Constructs a test WallpaperInfo object representing a 1x1 wallpaper of the given color. */
+ public TestWallpaperInfo(int pixelColor, String id) {
+ mPixelColor = pixelColor;
+ mAttributions = Arrays.asList("Test wallpaper");
+ mWallpaperComponent = null;
+ mIsAssetCorrupt = false;
+ mBackupPermission = BACKUP_ALLOWED;
+ mWallpaperId = id;
+ }
+
+ private TestWallpaperInfo(Parcel in) {
+ mPixelColor = in.readInt();
+ mAttributions = in.createStringArrayList();
+ mActionUrl = in.readString();
+ mBaseImageUrl = in.readString();
+ mCollectionId = in.readString();
+ mWallpaperId = in.readString();
+ mIsAssetCorrupt = in.readInt() == 1;
+ mBackupPermission = in.readInt();
+ }
+
+ @Override
+ public Drawable getOverlayIcon(Context context) {
+ return null;
+ }
+
+ @Override
+ public List<String> getAttributions(Context context) {
+ return mAttributions;
+ }
+
+ /**
+ * Override default "Test wallpaper" attributions for testing.
+ */
+ public void setAttributions(List<String> attributions) {
+ mAttributions = attributions;
+ }
+
+ @Override
+ public String getActionUrl(Context unused) {
+ return mActionUrl;
+ }
+
+ /** Sets the action URL for this wallpaper. */
+ public void setActionUrl(String actionUrl) {
+ mActionUrl = actionUrl;
+ }
+
+ @Override
+ public String getBaseImageUrl() {
+ return mBaseImageUrl;
+ }
+
+ /** Sets the base image URL for this wallpaper. */
+ public void setBaseImageUrl(String baseImageUrl) {
+ mBaseImageUrl = baseImageUrl;
+ }
+
+ @Override
+ public String getCollectionId(Context unused) {
+ return mCollectionId;
+ }
+
+ /** Sets the collection ID for this wallpaper. */
+ public void setCollectionId(String collectionId) {
+ mCollectionId = collectionId;
+ }
+
+ @Override
+ public String getWallpaperId() {
+ return mWallpaperId;
+ }
+
+ /** Sets the ID for this wallpaper. */
+ public void setWallpaperId(String wallpaperId) {
+ mWallpaperId = wallpaperId;
+ }
+
+ @Override
+ public Asset getAsset(Context context) {
+ if (mAsset == null) {
+ mAsset = new TestAsset(mPixelColor, mIsAssetCorrupt);
+ }
+ return mAsset;
+ }
+
+ @Override
+ public Asset getThumbAsset(Context context) {
+ if (mThumbAsset == null) {
+ mThumbAsset = new TestAsset(mPixelColor, mIsAssetCorrupt);
+ }
+ return mThumbAsset;
+ }
+
+ @Override
+ public void showPreview(Activity srcActivity,
+ InlinePreviewIntentFactory inlinePreviewIntentFactory, int requestCode) {
+ srcActivity.startActivityForResult(
+ inlinePreviewIntentFactory.newIntent(srcActivity, this), requestCode);
+ }
+
+ @Override
+ @BackupPermission
+ public int getBackupPermission() {
+ return mBackupPermission;
+ }
+
+ public void setBackupPermission(@BackupPermission int backupPermission) {
+ mBackupPermission = backupPermission;
+ }
+
+ @Override
+ public android.app.WallpaperInfo getWallpaperComponent() {
+ return mWallpaperComponent;
+ }
+
+ public void setWallpaperComponent(android.app.WallpaperInfo wallpaperComponent) {
+ mWallpaperComponent = wallpaperComponent;
+ }
+
+ /**
+ * Simulates that the {@link Asset} instances returned by calls to #getAsset and #getThumbAsset
+ * on
+ * this object are "corrupt" and will fail to perform decode operations such as #decodeBitmap,
+ * #decodeBitmapRegion, #decodeRawDimensions, etc (these methods will call their callbacks with
+ * null instead of meaningful objects).
+ */
+ public void corruptAssets() {
+ mIsAssetCorrupt = true;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel parcel, int i) {
+ parcel.writeInt(mPixelColor);
+ parcel.writeStringList(mAttributions);
+ parcel.writeString(mActionUrl);
+ parcel.writeString(mBaseImageUrl);
+ parcel.writeString(mCollectionId);
+ parcel.writeString(mWallpaperId);
+ parcel.writeInt(mIsAssetCorrupt ? 1 : 0);
+ parcel.writeInt(mBackupPermission);
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (object == this) {
+ return true;
+ }
+ if (object instanceof TestWallpaperInfo) {
+ return mPixelColor == ((TestWallpaperInfo) object).mPixelColor;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return mPixelColor;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestWallpaperManagerCompat.java b/tests/src/com/android/wallpaper/testing/TestWallpaperManagerCompat.java
new file mode 100644
index 0000000..69f6839
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestWallpaperManagerCompat.java
@@ -0,0 +1,135 @@
+/*
+ * 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;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestWallpaperPersister.java b/tests/src/com/android/wallpaper/testing/TestWallpaperPersister.java
new file mode 100644
index 0000000..5fc9421
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestWallpaperPersister.java
@@ -0,0 +1,223 @@
+/*
+ * 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.Activity;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Rect;
+
+import androidx.annotation.Nullable;
+
+import com.android.wallpaper.asset.Asset;
+import com.android.wallpaper.asset.Asset.BitmapReceiver;
+import com.android.wallpaper.model.WallpaperInfo;
+import com.android.wallpaper.module.InjectorProvider;
+import com.android.wallpaper.module.WallpaperChangedNotifier;
+import com.android.wallpaper.module.WallpaperPersister;
+import com.android.wallpaper.module.WallpaperPreferences;
+
+import java.util.List;
+
+/**
+ * Test double for {@link WallpaperPersister}.
+ */
+public class TestWallpaperPersister implements WallpaperPersister {
+
+ private Context mAppContext;
+ private WallpaperPreferences mPrefs;
+ private WallpaperChangedNotifier mWallpaperChangedNotifier;
+ private Bitmap mCurrentHomeWallpaper;
+ private Bitmap mCurrentLockWallpaper;
+ private Bitmap mPendingHomeWallpaper;
+ private Bitmap mPendingLockWallpaper;
+ private List<String> mHomeAttributions;
+ private String mHomeActionUrl;
+ @Destination
+ private int mDestination;
+ private WallpaperPersister.SetWallpaperCallback mCallback;
+ private boolean mFailNextCall;
+ private Rect mCropRect;
+ private float mScale;
+ @WallpaperPosition
+ private int mWallpaperPosition;
+
+ public TestWallpaperPersister(Context appContext) {
+ mAppContext = appContext;
+ mPrefs = InjectorProvider.getInjector().getPreferences(appContext);
+ mWallpaperChangedNotifier = WallpaperChangedNotifier.getInstance();
+
+ mCurrentHomeWallpaper = null;
+ mCurrentLockWallpaper = null;
+ mPendingHomeWallpaper = null;
+ mPendingLockWallpaper = null;
+ mFailNextCall = false;
+ mScale = -1.0f;
+ }
+
+ @Override
+ public void setIndividualWallpaper(final WallpaperInfo wallpaperInfo, Asset asset,
+ @Nullable final Rect cropRect, final float scale, final @Destination int destination,
+ final WallpaperPersister.SetWallpaperCallback callback) {
+ asset.decodeBitmap(50, 50, bitmap -> {
+ if (destination == DEST_HOME_SCREEN || destination == DEST_BOTH) {
+ mPendingHomeWallpaper = bitmap;
+ mPrefs.setHomeWallpaperAttributions(wallpaperInfo.getAttributions(mAppContext));
+ mPrefs.setWallpaperPresentationMode(
+ WallpaperPreferences.PRESENTATION_MODE_STATIC);
+ mPrefs.setHomeWallpaperRemoteId(wallpaperInfo.getWallpaperId());
+ }
+ if (destination == DEST_LOCK_SCREEN || destination == DEST_BOTH) {
+ mPendingLockWallpaper = bitmap;
+ mPrefs.setLockWallpaperAttributions(wallpaperInfo.getAttributions(mAppContext));
+ }
+ mDestination = destination;
+ mCallback = callback;
+ mCropRect = cropRect;
+ mScale = scale;
+ });
+ }
+
+ @Override
+ public void setIndividualWallpaperWithPosition(Activity activity, WallpaperInfo wallpaper,
+ @WallpaperPosition int wallpaperPosition, SetWallpaperCallback callback) {
+ wallpaper.getAsset(activity).decodeBitmap(50, 50, new BitmapReceiver() {
+ @Override
+ public void onBitmapDecoded(@Nullable Bitmap bitmap) {
+ mPendingHomeWallpaper = bitmap;
+ mPrefs.setHomeWallpaperAttributions(wallpaper.getAttributions(mAppContext));
+ mPrefs.setHomeWallpaperBaseImageUrl(wallpaper.getBaseImageUrl());
+ mPrefs.setHomeWallpaperActionUrl(wallpaper.getActionUrl(mAppContext));
+ mPrefs.setHomeWallpaperCollectionId(wallpaper.getCollectionId(mAppContext));
+ mPrefs.setHomeWallpaperRemoteId(wallpaper.getWallpaperId());
+ mPrefs.setWallpaperPresentationMode(WallpaperPreferences.PRESENTATION_MODE_STATIC);
+ mPendingLockWallpaper = bitmap;
+ mPrefs.setLockWallpaperAttributions(wallpaper.getAttributions(mAppContext));
+
+ mDestination = WallpaperPersister.DEST_BOTH;
+ mCallback = callback;
+ mWallpaperPosition = wallpaperPosition;
+ }
+ });
+ }
+
+ @Override
+ public boolean setWallpaperInRotation(Bitmap wallpaperBitmap, List<String> attributions,
+ int actionLabelRes, int actionIconRes, String actionUrl, String collectionId) {
+ if (mFailNextCall) {
+ return false;
+ }
+
+ mCurrentHomeWallpaper = wallpaperBitmap;
+ mCurrentLockWallpaper = wallpaperBitmap;
+ mHomeAttributions = attributions;
+ mHomeActionUrl = actionUrl;
+ return true;
+ }
+
+ @Override
+ public int setWallpaperBitmapInNextRotation(Bitmap wallpaperBitmap) {
+ mCurrentHomeWallpaper = wallpaperBitmap;
+ mCurrentLockWallpaper = wallpaperBitmap;
+ return 1;
+ }
+
+ @Override
+ public boolean finalizeWallpaperForNextRotation(List<String> attributions, String actionUrl,
+ int actionLabelRes, int actionIconRes, String collectionId, int wallpaperId) {
+ mHomeAttributions = attributions;
+ mHomeActionUrl = actionUrl;
+ return true;
+ }
+
+ /** Returns mock system wallpaper bitmap. */
+ public Bitmap getCurrentHomeWallpaper() {
+ return mCurrentHomeWallpaper;
+ }
+
+ /** Returns mock lock screen wallpaper bitmap. */
+ public Bitmap getCurrentLockWallpaper() {
+ return mCurrentLockWallpaper;
+ }
+
+ /** Returns mock home attributions. */
+ public List<String> getHomeAttributions() {
+ return mHomeAttributions;
+ }
+
+ /** Returns the home wallpaper action URL. */
+ public String getHomeActionUrl() {
+ return mHomeActionUrl;
+ }
+
+ /** Returns the Destination a wallpaper was most recently set on. */
+ @Destination
+ public int getLastDestination() {
+ return mDestination;
+ }
+
+ /**
+ * Sets whether the next "set wallpaper" operation should fail or succeed.
+ */
+ public void setFailNextCall(Boolean failNextCall) {
+ mFailNextCall = failNextCall;
+ }
+
+ /**
+ * Implemented so synchronous test methods can control the completion of what would otherwise be
+ * an asynchronous operation.
+ */
+ public void finishSettingWallpaper() {
+ if (mFailNextCall) {
+ mCallback.onError(null /* throwable */);
+ } else {
+ if (mDestination == DEST_HOME_SCREEN || mDestination == DEST_BOTH) {
+ mCurrentHomeWallpaper = mPendingHomeWallpaper;
+ mPendingHomeWallpaper = null;
+ }
+ if (mDestination == DEST_LOCK_SCREEN || mDestination == DEST_BOTH) {
+ mCurrentLockWallpaper = mPendingLockWallpaper;
+ mPendingLockWallpaper = null;
+ }
+ mCallback.onSuccess();
+ mWallpaperChangedNotifier.notifyWallpaperChanged();
+ }
+ }
+
+ @Override
+ public void setWallpaperInfoInPreview(WallpaperInfo wallpaperInfo) {
+ }
+
+ @Override
+ public void onLiveWallpaperSet() {
+ }
+
+ /** Returns the last requested wallpaper bitmap scale. */
+ public float getScale() {
+ return mScale;
+ }
+
+ /** Returns the last requested wallpaper crop. */
+ public Rect getCropRect() {
+ return mCropRect;
+ }
+
+ /** Returns the last selected wallpaper position option. */
+ @WallpaperPosition
+ public int getWallpaperPosition() {
+ return mWallpaperPosition;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestWallpaperPreferences.java b/tests/src/com/android/wallpaper/testing/TestWallpaperPreferences.java
new file mode 100644
index 0000000..715e81b
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestWallpaperPreferences.java
@@ -0,0 +1,457 @@
+/*
+ * 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 androidx.annotation.Nullable;
+
+import com.android.wallpaper.module.WallpaperPreferences;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Test implementation of the WallpaperPreferences interface. Just keeps prefs in memory.
+ */
+public class TestWallpaperPreferences implements WallpaperPreferences {
+
+ @PresentationMode
+ private int mWallpaperPresentationMode;
+
+ private List<String> mHomeScreenAttributions;
+ private long mHomeScreenBitmapHashCode;
+ private int mHomeWallpaperManagerId;
+ private String mHomeScreenPackageName;
+ private String mHomeActionUrl;
+ private String mHomeBaseImageUrl;
+ private String mHomeCollectionId;
+ private String mHomeWallpaperRemoteId;
+
+ private List<String> mLockScreenAttributions;
+ private long mLockScreenBitmapHashCode;
+ private int mLockWallpaperManagerId;
+ private String mLockActionUrl;
+ private String mLockCollectionId;
+
+ private List<Long> mDailyRotations;
+ private long mDailyWallpaperEnabledTimestamp;
+ private long mLastDailyLogTimestamp;
+ private long mLastAppActiveTimestamp;
+ private int mLastDailyWallpaperRotationStatus;
+ private long mLastDailyWallpaperRotationStatusTimestamp;
+ private long mLastSyncTimestamp;
+ @PendingWallpaperSetStatus
+ private int mPendingWallpaperSetStatus;
+ @PendingDailyWallpaperUpdateStatus
+ private int mPendingDailyWallpaperUpdateStatus;
+ private int mNumDaysDailyRotationFailed;
+ private int mNumDaysDailyRotationNotAttempted;
+ private int mHomeWallpaperActionLabelRes;
+ private int mHomeWallpaperActionIconRes;
+ private int mLockWallpaperActionLabelRes;
+ private int mLockWallpaperActionIconRes;
+
+ public TestWallpaperPreferences() {
+ mWallpaperPresentationMode = WallpaperPreferences.PRESENTATION_MODE_STATIC;
+ mHomeScreenAttributions = Arrays.asList("Android wallpaper");
+ mHomeScreenBitmapHashCode = 0;
+ mHomeWallpaperManagerId = 0;
+
+ mLockScreenAttributions = Arrays.asList("Android wallpaper");
+ mLockScreenBitmapHashCode = 0;
+ mLockWallpaperManagerId = 0;
+
+ mDailyRotations = new ArrayList<>();
+ mDailyWallpaperEnabledTimestamp = -1;
+ mLastDailyLogTimestamp = -1;
+ mLastDailyWallpaperRotationStatus = -1;
+ mLastDailyWallpaperRotationStatusTimestamp = 0;
+ mLastSyncTimestamp = 0;
+ mPendingWallpaperSetStatus = WALLPAPER_SET_NOT_PENDING;
+ }
+
+ @Override
+ public int getWallpaperPresentationMode() {
+ return mWallpaperPresentationMode;
+ }
+
+ @Override
+ public void setWallpaperPresentationMode(@PresentationMode int presentationMode) {
+ mWallpaperPresentationMode = presentationMode;
+ }
+
+ @Override
+ public List<String> getHomeWallpaperAttributions() {
+ return mHomeScreenAttributions;
+ }
+
+ @Override
+ public void setHomeWallpaperAttributions(List<String> attributions) {
+ mHomeScreenAttributions = attributions;
+ }
+
+ @Override
+ public String getHomeWallpaperActionUrl() {
+ return mHomeActionUrl;
+ }
+
+ @Override
+ public void setHomeWallpaperActionUrl(String actionUrl) {
+ mHomeActionUrl = actionUrl;
+ }
+
+ @Override
+ public int getHomeWallpaperActionLabelRes() {
+ return mHomeWallpaperActionLabelRes;
+ }
+
+ @Override
+ public void setHomeWallpaperActionLabelRes(int resId) {
+ mHomeWallpaperActionLabelRes = resId;
+ }
+
+ @Override
+ public int getHomeWallpaperActionIconRes() {
+ return mHomeWallpaperActionIconRes;
+ }
+
+ @Override
+ public void setHomeWallpaperActionIconRes(int resId) {
+ mHomeWallpaperActionIconRes = resId;
+ }
+
+ @Override
+ public String getHomeWallpaperBaseImageUrl() {
+ return mHomeBaseImageUrl;
+ }
+
+ @Override
+ public void setHomeWallpaperBaseImageUrl(String baseImageUrl) {
+ mHomeBaseImageUrl = baseImageUrl;
+ }
+
+ @Override
+ public String getHomeWallpaperCollectionId() {
+ return mHomeCollectionId;
+ }
+
+ @Override
+ public void setHomeWallpaperCollectionId(String collectionId) {
+ mHomeCollectionId = collectionId;
+ }
+
+ @Override
+ public String getHomeWallpaperBackingFileName() {
+ return null;
+ }
+
+ @Override
+ public void setHomeWallpaperBackingFileName(String fileName) {
+
+ }
+
+ @Override
+ public void clearHomeWallpaperMetadata() {
+ mHomeScreenAttributions = null;
+ mWallpaperPresentationMode = WallpaperPreferences.PRESENTATION_MODE_STATIC;
+ mHomeScreenBitmapHashCode = 0;
+ mHomeScreenPackageName = null;
+ mHomeWallpaperManagerId = 0;
+ }
+
+ @Override
+ public long getHomeWallpaperHashCode() {
+ return mHomeScreenBitmapHashCode;
+ }
+
+ @Override
+ public void setHomeWallpaperHashCode(long hashCode) {
+ mHomeScreenBitmapHashCode = hashCode;
+ }
+
+ @Override
+ public String getHomeWallpaperPackageName() {
+ return mHomeScreenPackageName;
+ }
+
+ @Override
+ public void setHomeWallpaperPackageName(String packageName) {
+ mHomeScreenPackageName = packageName;
+ }
+
+ @Override
+ public int getHomeWallpaperManagerId() {
+ return mHomeWallpaperManagerId;
+ }
+
+ @Override
+ public void setHomeWallpaperManagerId(int homeWallpaperId) {
+ mHomeWallpaperManagerId = homeWallpaperId;
+ }
+
+ @Override
+ public String getHomeWallpaperRemoteId() {
+ return mHomeWallpaperRemoteId;
+ }
+
+ @Override
+ public void setHomeWallpaperRemoteId(String wallpaperRemoteId) {
+ mHomeWallpaperRemoteId = wallpaperRemoteId;
+ }
+
+ @Override
+ public List<String> getLockWallpaperAttributions() {
+ return mLockScreenAttributions;
+ }
+
+ @Override
+ public void setLockWallpaperAttributions(List<String> attributions) {
+ mLockScreenAttributions = attributions;
+ }
+
+ @Override
+ public String getLockWallpaperActionUrl() {
+ return mLockActionUrl;
+ }
+
+ @Override
+ public void setLockWallpaperActionUrl(String actionUrl) {
+ mLockActionUrl = actionUrl;
+ }
+
+ @Override
+ public int getLockWallpaperActionLabelRes() {
+ return mLockWallpaperActionLabelRes;
+ }
+
+ @Override
+ public void setLockWallpaperActionLabelRes(int resId) {
+ mLockWallpaperActionLabelRes = resId;
+ }
+
+ @Override
+ public int getLockWallpaperActionIconRes() {
+ return mLockWallpaperActionIconRes;
+ }
+
+ @Override
+ public void setLockWallpaperActionIconRes(int resId) {
+ mLockWallpaperActionIconRes = resId;
+ }
+
+ @Override
+ public String getLockWallpaperCollectionId() {
+ return mLockCollectionId;
+ }
+
+ @Override
+ public void setLockWallpaperCollectionId(String collectionId) {
+ mLockCollectionId = collectionId;
+ }
+
+ @Override
+ public String getLockWallpaperBackingFileName() {
+ return null;
+ }
+
+ @Override
+ public void setLockWallpaperBackingFileName(String fileName) {
+
+ }
+
+ @Override
+ public void clearLockWallpaperMetadata() {
+ mLockScreenAttributions = null;
+ mLockScreenBitmapHashCode = 0;
+ mLockWallpaperManagerId = 0;
+ }
+
+ @Override
+ public long getLockWallpaperHashCode() {
+ return mLockScreenBitmapHashCode;
+ }
+
+ @Override
+ public void setLockWallpaperHashCode(long hashCode) {
+ mLockScreenBitmapHashCode = hashCode;
+ }
+
+ @Override
+ public int getLockWallpaperId() {
+ return mLockWallpaperManagerId;
+ }
+
+ @Override
+ public void setLockWallpaperId(int lockWallpaperId) {
+ mLockWallpaperManagerId = lockWallpaperId;
+ }
+
+ @Override
+ public void addDailyRotation(long timestamp) {
+ mDailyRotations.add(timestamp);
+ }
+
+ @Override
+ public long getLastDailyRotationTimestamp() {
+ if (mDailyRotations.size() == 0) {
+ return -1;
+ }
+
+ return mDailyRotations.get(mDailyRotations.size() - 1);
+ }
+
+ @Override
+ public List<Long> getDailyRotationsInLastWeek() {
+ return mDailyRotations;
+ }
+
+ @Nullable
+ @Override
+ public List<Long> getDailyRotationsPreviousDay() {
+ return null;
+ }
+
+ @Override
+ public long getDailyWallpaperEnabledTimestamp() {
+ return mDailyWallpaperEnabledTimestamp;
+ }
+
+ @Override
+ public void setDailyWallpaperEnabledTimestamp(long timestamp) {
+ mDailyWallpaperEnabledTimestamp = timestamp;
+ }
+
+ @Override
+ public void clearDailyRotations() {
+ mDailyRotations.clear();
+ }
+
+ @Override
+ public long getLastDailyLogTimestamp() {
+ return mLastDailyLogTimestamp;
+ }
+
+ @Override
+ public void setLastDailyLogTimestamp(long timestamp) {
+ mLastDailyLogTimestamp = timestamp;
+ }
+
+ @Override
+ public long getLastAppActiveTimestamp() {
+ return mLastAppActiveTimestamp;
+ }
+
+ @Override
+ public void setLastAppActiveTimestamp(long timestamp) {
+ mLastAppActiveTimestamp = timestamp;
+ }
+
+ @Override
+ public void setDailyWallpaperRotationStatus(int status, long timestamp) {
+ mLastDailyWallpaperRotationStatus = status;
+ mLastDailyWallpaperRotationStatusTimestamp = timestamp;
+ }
+
+ @Override
+ public int getDailyWallpaperLastRotationStatus() {
+ return mLastDailyWallpaperRotationStatus;
+ }
+
+ @Override
+ public long getDailyWallpaperLastRotationStatusTimestamp() {
+ return mLastDailyWallpaperRotationStatusTimestamp;
+ }
+
+ @Override
+ public long getLastSyncTimestamp() {
+ return mLastSyncTimestamp;
+ }
+
+ @Override
+ public void setLastSyncTimestamp(long timestamp) {
+ mLastSyncTimestamp = timestamp;
+ }
+
+ @Override
+ public void setPendingWallpaperSetStatusSync(@PendingWallpaperSetStatus int setStatus) {
+ mPendingWallpaperSetStatus = setStatus;
+ }
+
+ @Override
+ public int getPendingWallpaperSetStatus() {
+ return mPendingWallpaperSetStatus;
+ }
+
+ @Override
+ public void setPendingWallpaperSetStatus(@PendingWallpaperSetStatus int setStatus) {
+ mPendingWallpaperSetStatus = setStatus;
+ }
+
+ @Override
+ public void setPendingDailyWallpaperUpdateStatusSync(
+ @PendingDailyWallpaperUpdateStatus int updateStatus) {
+ mPendingDailyWallpaperUpdateStatus = updateStatus;
+ }
+
+ @Override
+ public int getPendingDailyWallpaperUpdateStatus() {
+ return mPendingDailyWallpaperUpdateStatus;
+ }
+
+ @Override
+ public void setPendingDailyWallpaperUpdateStatus(
+ @PendingDailyWallpaperUpdateStatus int updateStatus) {
+ mPendingDailyWallpaperUpdateStatus = updateStatus;
+ }
+
+ @Override
+ public void incrementNumDaysDailyRotationFailed() {
+ mNumDaysDailyRotationFailed++;
+ }
+
+ @Override
+ public int getNumDaysDailyRotationFailed() {
+ return mNumDaysDailyRotationFailed;
+ }
+
+ public void setNumDaysDailyRotationFailed(int days) {
+ mNumDaysDailyRotationFailed = days;
+ }
+
+ @Override
+ public void resetNumDaysDailyRotationFailed() {
+ mNumDaysDailyRotationFailed = 0;
+ }
+
+ @Override
+ public void incrementNumDaysDailyRotationNotAttempted() {
+ mNumDaysDailyRotationNotAttempted++;
+ }
+
+ @Override
+ public int getNumDaysDailyRotationNotAttempted() {
+ return mNumDaysDailyRotationNotAttempted;
+ }
+
+ public void setNumDaysDailyRotationNotAttempted(int days) {
+ mNumDaysDailyRotationNotAttempted = days;
+ }
+
+ @Override
+ public void resetNumDaysDailyRotationNotAttempted() {
+ mNumDaysDailyRotationNotAttempted = 0;
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestWallpaperRefresher.java b/tests/src/com/android/wallpaper/testing/TestWallpaperRefresher.java
new file mode 100644
index 0000000..97961fe
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestWallpaperRefresher.java
@@ -0,0 +1,81 @@
+/*
+ * 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 com.android.wallpaper.compat.BuildCompat;
+import com.android.wallpaper.model.WallpaperMetadata;
+import com.android.wallpaper.module.InjectorProvider;
+import com.android.wallpaper.module.WallpaperPreferences;
+import com.android.wallpaper.module.WallpaperRefresher;
+
+/**
+ * Test implementation of {@link WallpaperRefresher} which simply provides whatever metadata is
+ * saved in WallpaperPreferences and the image wallpaper set to {@link WallpaperManager}.
+ */
+public class TestWallpaperRefresher implements WallpaperRefresher {
+
+ private final Context mAppContext;
+
+ /**
+ * @param context The application's context.
+ */
+ public TestWallpaperRefresher(Context context) {
+ mAppContext = context.getApplicationContext();
+ }
+
+ @Override
+ public void refresh(RefreshListener listener) {
+
+ WallpaperPreferences prefs = InjectorProvider.getInjector().getPreferences(mAppContext);
+
+ if (BuildCompat.isAtLeastN() && prefs.getLockWallpaperId() > 0) {
+ listener.onRefreshed(
+ new WallpaperMetadata(
+ prefs.getHomeWallpaperAttributions(),
+ prefs.getHomeWallpaperActionUrl(),
+ prefs.getHomeWallpaperActionLabelRes(),
+ prefs.getHomeWallpaperActionIconRes(),
+ prefs.getHomeWallpaperCollectionId(),
+ prefs.getHomeWallpaperBackingFileName(),
+ null /* wallpaperComponent */),
+ new WallpaperMetadata(
+ prefs.getLockWallpaperAttributions(),
+ prefs.getLockWallpaperActionUrl(),
+ prefs.getLockWallpaperActionLabelRes(),
+ prefs.getLockWallpaperActionIconRes(),
+ prefs.getLockWallpaperCollectionId(),
+ prefs.getLockWallpaperBackingFileName(),
+ null /* wallpaperComponent */),
+ prefs.getWallpaperPresentationMode());
+ } else {
+ listener.onRefreshed(
+ new WallpaperMetadata(
+ prefs.getHomeWallpaperAttributions(),
+ prefs.getHomeWallpaperActionUrl(),
+ prefs.getHomeWallpaperActionLabelRes(),
+ prefs.getHomeWallpaperActionIconRes(),
+ prefs.getHomeWallpaperCollectionId(),
+ prefs.getHomeWallpaperBackingFileName(),
+ null /* wallpaperComponent */),
+ null,
+ prefs.getWallpaperPresentationMode());
+ }
+ }
+}
diff --git a/tests/src/com/android/wallpaper/testing/TestWallpaperRotationInitializer.java b/tests/src/com/android/wallpaper/testing/TestWallpaperRotationInitializer.java
new file mode 100644
index 0000000..9494d19
--- /dev/null
+++ b/tests/src/com/android/wallpaper/testing/TestWallpaperRotationInitializer.java
@@ -0,0 +1,133 @@
+/*
+ * 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.content.Context;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.android.wallpaper.model.WallpaperRotationInitializer;
+import com.android.wallpaper.module.InjectorProvider;
+import com.android.wallpaper.module.WallpaperPreferences;
+
+/**
+ * Test implementation of {@link WallpaperRotationInitializer}.
+ */
+public class TestWallpaperRotationInitializer implements WallpaperRotationInitializer {
+
+ private boolean mIsRotationInitialized;
+ @NetworkPreference
+ private int mNetworkPreference;
+ private Listener mListener;
+ @RotationInitializationState
+ private int mRotationInitializationState;
+
+ TestWallpaperRotationInitializer() {
+ mIsRotationInitialized = false;
+ mNetworkPreference = NETWORK_PREFERENCE_WIFI_ONLY;
+ mRotationInitializationState = WallpaperRotationInitializer.ROTATION_NOT_INITIALIZED;
+ }
+
+ TestWallpaperRotationInitializer(@RotationInitializationState int rotationState) {
+ mIsRotationInitialized = false;
+ mNetworkPreference = NETWORK_PREFERENCE_WIFI_ONLY;
+ mRotationInitializationState = rotationState;
+ }
+
+ private TestWallpaperRotationInitializer(Parcel unused) {
+ mIsRotationInitialized = false;
+ mNetworkPreference = NETWORK_PREFERENCE_WIFI_ONLY;
+ }
+
+ @Override
+ public void setFirstWallpaperInRotation(Context context,
+ @NetworkPreference int networkPreference,
+ Listener listener) {
+ mListener = listener;
+ mNetworkPreference = networkPreference;
+ }
+
+ @Override
+ public boolean startRotation(Context appContext) {
+ WallpaperPreferences wallpaperPreferences =
+ InjectorProvider.getInjector().getPreferences(appContext);
+ wallpaperPreferences.setWallpaperPresentationMode(
+ WallpaperPreferences.PRESENTATION_MODE_ROTATING);
+ return true;
+ }
+
+ @Override
+ public void fetchRotationInitializationState(Context context, RotationStateListener listener) {
+ listener.onRotationStateReceived(mRotationInitializationState);
+ }
+
+ @Override
+ public int getRotationInitializationStateDirty(Context context) {
+ return mRotationInitializationState;
+ }
+
+ /** Sets the mocked rotation initialization state. */
+ public void setRotationInitializationState(@RotationInitializationState int rotationState) {
+ mRotationInitializationState = rotationState;
+ }
+
+ /**
+ * Simulates completion of the asynchronous task to download the first wallpaper in a rotation..
+ *
+ * @param isSuccessful Whether the first wallpaper downloaded successfully.
+ */
+ public void finishDownloadingFirstWallpaper(boolean isSuccessful) {
+ if (isSuccessful) {
+ mIsRotationInitialized = true;
+ mListener.onFirstWallpaperInRotationSet();
+ } else {
+ mIsRotationInitialized = false;
+ mListener.onError();
+ }
+ }
+
+ /** Returns whether a wallpaper rotation is initialized. */
+ public boolean isRotationInitialized() {
+ return mIsRotationInitialized;
+ }
+
+ /** Returns whether a wallpaper rotation is enabled for WiFi-only. */
+ public boolean isWifiOnly() {
+ return mNetworkPreference == NETWORK_PREFERENCE_WIFI_ONLY;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ public static final Parcelable.Creator<TestWallpaperRotationInitializer> CREATOR =
+ new Parcelable.Creator<TestWallpaperRotationInitializer>() {
+ @Override
+ public TestWallpaperRotationInitializer createFromParcel(Parcel in) {
+ return new TestWallpaperRotationInitializer(in);
+ }
+
+ @Override
+ public TestWallpaperRotationInitializer[] newArray(int size) {
+ return new TestWallpaperRotationInitializer[size];
+ }
+ };
+}