Move shared test code into separate directory

Bug: b/289394860
Test: atest ThemePicker
Test: run ThemePicker tests in Studio
Change-Id: Ie53d037f6db727040ed7342966b1f736e9155f40
diff --git a/tests/common/Android.bp b/tests/common/Android.bp
new file mode 100644
index 0000000..2904fad
--- /dev/null
+++ b/tests/common/Android.bp
@@ -0,0 +1,39 @@
+// Copyright (C) 2023 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.
+//
+
+//
+// Build rule for WallpaperPicker2 tests
+//
+package {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_library {
+    name: "ThemePickerTestLib",
+
+    defaults: ["ThemePicker_defaults"],
+    srcs: [
+        "src/com/android/customization/testing/**/*.java",
+        "src/com/android/customization/testing/**/*.kt",
+    ],
+    static_libs: [
+        "WallpaperPicker2TestLib",
+        "androidx.annotation_annotation",
+        "kotlinx_coroutines_test",
+        "truth-prebuilt",
+    ],
+
+    platform_apis: true,
+}
diff --git a/tests/common/AndroidManifest.xml b/tests/common/AndroidManifest.xml
new file mode 100644
index 0000000..81a2f03
--- /dev/null
+++ b/tests/common/AndroidManifest.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2023 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.wallpaper">
+
+  <application>
+  </application>
+</manifest>
diff --git a/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.java b/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.java
new file mode 100644
index 0000000..81890f0
--- /dev/null
+++ b/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.java
@@ -0,0 +1,56 @@
+/*
+ * 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.customization.testing;
+
+import android.content.Context;
+
+import com.android.customization.module.DefaultCustomizationPreferences;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Test implementation of {@link DefaultCustomizationPreferences}.
+ */
+public class TestDefaultCustomizationPreferences extends DefaultCustomizationPreferences {
+
+    private String mCustomThemes;
+    private final Set<String> mTabVisited = new HashSet<>();
+
+    public TestDefaultCustomizationPreferences(Context context) {
+        super(context);
+    }
+
+    @Override
+    public String getSerializedCustomThemes() {
+        return mCustomThemes;
+    }
+
+    @Override
+    public void storeCustomThemes(String serializedCustomThemes) {
+        mCustomThemes = serializedCustomThemes;
+    }
+
+    @Override
+    public boolean getTabVisited(String id) {
+        return mTabVisited.contains(id);
+    }
+
+    @Override
+    public void setTabVisited(String id) {
+        mTabVisited.add(id);
+    }
+}
diff --git a/tests/common/src/com/android/customization/testing/TestDrawableLayerResolver.java b/tests/common/src/com/android/customization/testing/TestDrawableLayerResolver.java
new file mode 100644
index 0000000..8b16299
--- /dev/null
+++ b/tests/common/src/com/android/customization/testing/TestDrawableLayerResolver.java
@@ -0,0 +1,31 @@
+/*
+ * 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.customization.testing;
+
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.LayerDrawable;
+
+import com.android.wallpaper.module.DrawableLayerResolver;
+
+/**
+ * Test implementation of {@link DrawableLayerResolver}.
+ */
+public class TestDrawableLayerResolver implements DrawableLayerResolver {
+    @Override
+    public Drawable resolveLayer(LayerDrawable layerDrawable) {
+        return layerDrawable.getDrawable(0);
+    }
+}
diff --git a/tests/common/src/com/android/customization/testing/TestPackageStatusNotifier.java b/tests/common/src/com/android/customization/testing/TestPackageStatusNotifier.java
new file mode 100644
index 0000000..2aadae8
--- /dev/null
+++ b/tests/common/src/com/android/customization/testing/TestPackageStatusNotifier.java
@@ -0,0 +1,33 @@
+/*
+ * 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.customization.testing;
+
+import com.android.wallpaper.module.PackageStatusNotifier;
+
+/**
+ * Test implementation of {@link PackageStatusNotifier}.
+ */
+public class TestPackageStatusNotifier implements PackageStatusNotifier {
+    @Override
+    public void addListener(Listener listener, String action) {
+        // Do nothing
+    }
+
+    @Override
+    public void removeListener(Listener listener) {
+        // Do nothing
+    }
+}
diff --git a/tests/common/src/com/android/customization/testing/TestPluginManager.kt b/tests/common/src/com/android/customization/testing/TestPluginManager.kt
new file mode 100644
index 0000000..167d8dd
--- /dev/null
+++ b/tests/common/src/com/android/customization/testing/TestPluginManager.kt
@@ -0,0 +1,36 @@
+package com.android.customization.testing
+
+import com.android.systemui.plugins.Plugin
+import com.android.systemui.plugins.PluginListener
+import com.android.systemui.plugins.PluginManager
+
+class TestPluginManager : PluginManager {
+    override fun getPrivilegedPlugins(): Array<String> {
+        return emptyArray()
+    }
+
+    override fun <T : Plugin?> addPluginListener(listener: PluginListener<T>, cls: Class<T>) {}
+    override fun <T : Plugin?> addPluginListener(
+        listener: PluginListener<T>,
+        cls: Class<T>,
+        allowMultiple: Boolean
+    ) {}
+
+    override fun <T : Plugin?> addPluginListener(
+        action: String,
+        listener: PluginListener<T>,
+        cls: Class<T>
+    ) {}
+
+    override fun <T : Plugin?> addPluginListener(
+        action: String,
+        listener: PluginListener<T>,
+        cls: Class<T>,
+        allowMultiple: Boolean
+    ) {}
+
+    override fun removePluginListener(listener: PluginListener<*>?) {}
+    override fun <T> dependsOn(p: Plugin, cls: Class<T>): Boolean {
+        return false
+    }
+}
diff --git a/tests/common/src/com/android/customization/testing/TestThemeManager.java b/tests/common/src/com/android/customization/testing/TestThemeManager.java
new file mode 100644
index 0000000..5175b24
--- /dev/null
+++ b/tests/common/src/com/android/customization/testing/TestThemeManager.java
@@ -0,0 +1,48 @@
+/*
+ * 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.customization.testing;
+
+import androidx.fragment.app.FragmentActivity;
+
+import com.android.customization.model.theme.OverlayManagerCompat;
+import com.android.customization.model.theme.ThemeBundleProvider;
+import com.android.customization.model.theme.ThemeManager;
+import com.android.customization.module.ThemesUserEventLogger;
+
+/**
+ * Test implementation of {@link ThemeManager}.
+ */
+public class TestThemeManager extends ThemeManager {
+
+    private static boolean sIsAvailable;
+
+    public TestThemeManager(
+            ThemeBundleProvider provider,
+            FragmentActivity activity,
+            OverlayManagerCompat overlayManagerCompat,
+            ThemesUserEventLogger logger) {
+        super(provider, activity, overlayManagerCompat, logger);
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return sIsAvailable;
+    }
+
+    public static void setAvailable(boolean available) {
+        sIsAvailable = available;
+    }
+}
diff --git a/tests/common/src/com/android/customization/testing/TestThemesUserEventLogger.java b/tests/common/src/com/android/customization/testing/TestThemesUserEventLogger.java
new file mode 100644
index 0000000..22a5b94
--- /dev/null
+++ b/tests/common/src/com/android/customization/testing/TestThemesUserEventLogger.java
@@ -0,0 +1,53 @@
+/*
+ * 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.customization.testing;
+
+import com.android.customization.model.color.ColorOption;
+import com.android.customization.model.grid.GridOption;
+import com.android.customization.model.theme.ThemeBundle;
+import com.android.customization.module.ThemesUserEventLogger;
+import com.android.wallpaper.testing.TestUserEventLogger;
+
+/**
+ * Test implementation of {@link ThemesUserEventLogger}.
+ */
+public class TestThemesUserEventLogger extends TestUserEventLogger
+        implements ThemesUserEventLogger {
+    @Override
+    public void logThemeSelected(ThemeBundle theme, boolean isCustomTheme) {
+        // Do nothing.
+    }
+
+    @Override
+    public void logThemeApplied(ThemeBundle theme, boolean isCustomTheme) {
+        // Do nothing.
+    }
+
+    @Override
+    public void logColorApplied(int action, ColorOption colorOption) {
+        // Do nothing.
+    }
+
+    @Override
+    public void logGridSelected(GridOption grid) {
+        // Do nothing.
+    }
+
+    @Override
+    public void logGridApplied(GridOption grid) {
+        // Do nothing.
+    }
+}