Add Glance preview module

Move glance preview annotation from a surface specific to a single common
glance annotation following the discussion in
go/glance-preview-indication.

Bug: 228423246
Fixes: 239427638
Relnote: new api for Glance preview
Test: all tests should pass
Change-Id: I75666dc249be014257d6c1f557d7ebcfb9cb2cfd
diff --git a/glance/glance-appwidget-preview/api/public_plus_experimental_current.txt b/glance/glance-appwidget-preview/api/public_plus_experimental_current.txt
index fd15726..873473c 100644
--- a/glance/glance-appwidget-preview/api/public_plus_experimental_current.txt
+++ b/glance/glance-appwidget-preview/api/public_plus_experimental_current.txt
@@ -4,12 +4,5 @@
   public final class GlanceAppWidgetViewAdapterKt {
   }
 
-  @androidx.glance.appwidget.ExperimentalGlanceRemoteViewsApi @kotlin.annotation.Repeatable @kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.SOURCE) @kotlin.annotation.Target(allowedTargets={kotlin.annotation.AnnotationTarget.ANNOTATION_CLASS, kotlin.annotation.AnnotationTarget.FUNCTION}) public @interface PreviewGlance {
-  }
-
-  @androidx.glance.appwidget.ExperimentalGlanceRemoteViewsApi @kotlin.annotation.Repeatable @kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.SOURCE) @kotlin.annotation.Target(allowedTargets={kotlin.annotation.AnnotationTarget.ANNOTATION_CLASS, kotlin.annotation.AnnotationTarget.FUNCTION}) public static @interface PreviewGlance.Container {
-    method public abstract androidx.glance.appwidget.preview.PreviewGlance[] value();
-  }
-
 }
 
diff --git a/glance/glance-preview/api/current.txt b/glance/glance-preview/api/current.txt
new file mode 100644
index 0000000..42fa5e3
--- /dev/null
+++ b/glance/glance-preview/api/current.txt
@@ -0,0 +1,11 @@
+// Signature format: 4.0
+package androidx.glance.preview {
+
+  public final class Surfaces {
+    field public static final String APP_WIDGET = "AppWidget";
+    field public static final androidx.glance.preview.Surfaces INSTANCE;
+    field public static final String TILE = "Tile";
+  }
+
+}
+
diff --git a/glance/glance-preview/api/public_plus_experimental_current.txt b/glance/glance-preview/api/public_plus_experimental_current.txt
new file mode 100644
index 0000000..b70d5c3
--- /dev/null
+++ b/glance/glance-preview/api/public_plus_experimental_current.txt
@@ -0,0 +1,23 @@
+// Signature format: 4.0
+package androidx.glance.preview {
+
+  @kotlin.RequiresOptIn(message="This API is experimental and is likely to change in the future.") public @interface ExperimentalGlancePreviewApi {
+  }
+
+  @androidx.glance.preview.ExperimentalGlancePreviewApi @kotlin.annotation.Repeatable @kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.SOURCE) @kotlin.annotation.Target(allowedTargets={kotlin.annotation.AnnotationTarget.ANNOTATION_CLASS, kotlin.annotation.AnnotationTarget.FUNCTION}) public @interface GlancePreview {
+    method public abstract String surface();
+    property public abstract String surface;
+  }
+
+  @androidx.glance.preview.ExperimentalGlancePreviewApi @kotlin.annotation.Repeatable @kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.SOURCE) @kotlin.annotation.Target(allowedTargets={kotlin.annotation.AnnotationTarget.ANNOTATION_CLASS, kotlin.annotation.AnnotationTarget.FUNCTION}) public static @interface GlancePreview.Container {
+    method public abstract androidx.glance.preview.GlancePreview[] value();
+  }
+
+  public final class Surfaces {
+    field public static final String APP_WIDGET = "AppWidget";
+    field public static final androidx.glance.preview.Surfaces INSTANCE;
+    field public static final String TILE = "Tile";
+  }
+
+}
+
diff --git a/glance/glance-preview/api/res-current.txt b/glance/glance-preview/api/res-current.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/glance/glance-preview/api/res-current.txt
diff --git a/glance/glance-preview/api/restricted_current.txt b/glance/glance-preview/api/restricted_current.txt
new file mode 100644
index 0000000..42fa5e3
--- /dev/null
+++ b/glance/glance-preview/api/restricted_current.txt
@@ -0,0 +1,11 @@
+// Signature format: 4.0
+package androidx.glance.preview {
+
+  public final class Surfaces {
+    field public static final String APP_WIDGET = "AppWidget";
+    field public static final androidx.glance.preview.Surfaces INSTANCE;
+    field public static final String TILE = "Tile";
+  }
+
+}
+
diff --git a/glance/glance-preview/build.gradle b/glance/glance-preview/build.gradle
new file mode 100644
index 0000000..ce67185
--- /dev/null
+++ b/glance/glance-preview/build.gradle
@@ -0,0 +1,33 @@
+import androidx.build.AndroidXComposePlugin
+import androidx.build.LibraryType
+
+plugins {
+    id("AndroidXComposePlugin")
+    id("AndroidXPlugin")
+    id("com.android.library")
+}
+
+// Disable multi-platform; this will only be used on Android.
+AndroidXComposePlugin.applyAndConfigureKotlinPlugin(project, /* isMultiplatformEnabled= */false)
+
+dependencies {
+    implementation(libs.kotlinStdlib)
+    api("androidx.annotation:annotation:1.4.0")
+    api("androidx.compose.runtime:runtime:1.1.1")
+}
+
+android {
+    defaultConfig {
+        minSdkVersion 21
+    }
+    namespace "androidx.glance.preview"
+}
+
+androidx {
+    name = "Android Glance Preview"
+    type = LibraryType.PUBLISHED_LIBRARY
+    mavenGroup = LibraryGroups.GLANCE
+    inceptionYear = "2022"
+    description = "Glance preview library. This library provides the API required for marking the" +
+            "glance @Composable components that should have preview in the Android Studio."
+}
diff --git a/glance/glance-appwidget-preview/src/androidMain/kotlin/androidx/glance/appwidget/preview/PreviewGlance.kt b/glance/glance-preview/src/androidMain/kotlin/androidx/glance/preview/ExperimentalGlancePreviewApi.kt
similarity index 66%
copy from glance/glance-appwidget-preview/src/androidMain/kotlin/androidx/glance/appwidget/preview/PreviewGlance.kt
copy to glance/glance-preview/src/androidMain/kotlin/androidx/glance/preview/ExperimentalGlancePreviewApi.kt
index 8aed834..b21e9d3 100644
--- a/glance/glance-appwidget-preview/src/androidMain/kotlin/androidx/glance/appwidget/preview/PreviewGlance.kt
+++ b/glance/glance-preview/src/androidMain/kotlin/androidx/glance/preview/ExperimentalGlancePreviewApi.kt
@@ -14,15 +14,7 @@
  * limitations under the License.
  */
 
-package androidx.glance.appwidget.preview
+package androidx.glance.preview
 
-import androidx.glance.appwidget.ExperimentalGlanceRemoteViewsApi
-
-@Retention(AnnotationRetention.SOURCE)
-@Target(
-    AnnotationTarget.ANNOTATION_CLASS,
-    AnnotationTarget.FUNCTION
-)
-@ExperimentalGlanceRemoteViewsApi
-@Repeatable
-annotation class PreviewGlance
\ No newline at end of file
+@RequiresOptIn("This API is experimental and is likely to change in the future.")
+annotation class ExperimentalGlancePreviewApi
\ No newline at end of file
diff --git a/glance/glance-appwidget-preview/src/androidMain/kotlin/androidx/glance/appwidget/preview/PreviewGlance.kt b/glance/glance-preview/src/androidMain/kotlin/androidx/glance/preview/GlancePreview.kt
similarity index 76%
rename from glance/glance-appwidget-preview/src/androidMain/kotlin/androidx/glance/appwidget/preview/PreviewGlance.kt
rename to glance/glance-preview/src/androidMain/kotlin/androidx/glance/preview/GlancePreview.kt
index 8aed834..cdc9027 100644
--- a/glance/glance-appwidget-preview/src/androidMain/kotlin/androidx/glance/appwidget/preview/PreviewGlance.kt
+++ b/glance/glance-preview/src/androidMain/kotlin/androidx/glance/preview/GlancePreview.kt
@@ -14,15 +14,16 @@
  * limitations under the License.
  */
 
-package androidx.glance.appwidget.preview
+package androidx.glance.preview
 
-import androidx.glance.appwidget.ExperimentalGlanceRemoteViewsApi
-
+/**
+ * The annotation that marks glance components (functions) that should have visual preview.
+ */
 @Retention(AnnotationRetention.SOURCE)
 @Target(
     AnnotationTarget.ANNOTATION_CLASS,
     AnnotationTarget.FUNCTION
 )
-@ExperimentalGlanceRemoteViewsApi
+@ExperimentalGlancePreviewApi
 @Repeatable
-annotation class PreviewGlance
\ No newline at end of file
+annotation class GlancePreview(@Surface val surface: String)
diff --git a/glance/glance-preview/src/androidMain/kotlin/androidx/glance/preview/Surface.kt b/glance/glance-preview/src/androidMain/kotlin/androidx/glance/preview/Surface.kt
new file mode 100644
index 0000000..5fb0353
--- /dev/null
+++ b/glance/glance-preview/src/androidMain/kotlin/androidx/glance/preview/Surface.kt
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2022 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 androidx.glance.preview
+
+import androidx.annotation.RestrictTo
+import androidx.annotation.StringDef
+
+/**
+ * The list of glance surfaces that have preview available. The list will grow as more glance
+ * surfaces will are added and allow the preview functionality.
+ */
+object Surfaces {
+    const val APP_WIDGET = "AppWidget"
+    const val TILE = "Tile"
+}
+
+/**
+ * The annotation that ensures that the variable value is strictly a recognized glance surface.
+ */
+@Retention(AnnotationRetention.SOURCE)
+@StringDef(value = [Surfaces.APP_WIDGET, Surfaces.TILE])
+@RestrictTo(RestrictTo.Scope.LIBRARY)
+annotation class Surface
diff --git a/settings.gradle b/settings.gradle
index d3d7d62..f74ad54 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -649,6 +649,7 @@
 includeProject(":glance:glance-appwidget:integration-tests:demos", [BuildType.GLANCE])
 includeProject(":glance:glance-appwidget:integration-tests:template-demos", [BuildType.GLANCE])
 includeProject(":glance:glance-appwidget:glance-layout-generator", [BuildType.GLANCE])
+includeProject(":glance:glance-preview", [BuildType.GLANCE])
 includeProject(":glance:glance-wear-tiles:integration-tests:demos", [BuildType.GLANCE])
 includeProject(":glance:glance-wear-tiles:integration-tests:template-demos", [BuildType.GLANCE])
 includeProject(":glance:glance-wear-tiles", [BuildType.GLANCE])