Initial skeleton for the Compose Layout Inspector

Bug: 170895806
Test: N/A
Change-Id: If1dd239c41cb77b3e1cc30e7ba814c2053d70930
diff --git a/compose/ui/ui-inspection/build.gradle b/compose/ui/ui-inspection/build.gradle
new file mode 100644
index 0000000..9c4b9f5
--- /dev/null
+++ b/compose/ui/ui-inspection/build.gradle
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+import androidx.build.LibraryGroups
+import androidx.build.LibraryType
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+
+import static androidx.build.dependencies.DependenciesKt.*
+
+plugins {
+    id("AndroidXPlugin")
+    id("com.android.library")
+    id("kotlin-android")
+    id("androidx.inspection")
+}
+
+dependencies {
+    implementation("androidx.annotation:annotation:1.1.0")
+    implementation(KOTLIN_STDLIB)
+    compileOnly(projectOrArtifact(":inspection:inspection"))
+    compileOnly(project(":compose:runtime:runtime"))
+    compileOnly(project(":compose:ui:ui"))
+    compileOnly(project(":compose:ui:ui-tooling"))
+}
+
+androidx {
+    name = "Android Compose Layout Inspector"
+    type = LibraryType.IDE_PLUGIN
+    mavenGroup = LibraryGroups.Compose.UI
+    inceptionYear = "2021"
+    description = "Compose layout inspector. Exposes information to our tools for better IDE support."
+}
+
+android {
+    defaultConfig {
+        // layout inspection supported starting on Android Q
+        minSdkVersion 29
+    }
+
+    sourceSets {
+        main.resources.srcDirs += "src/main/proto"
+    }
+}
+
+tasks.withType(KotlinCompile).configureEach {
+    kotlinOptions {
+        useIR = true
+        freeCompilerArgs += [
+                "-Xopt-in=kotlin.RequiresOptIn",
+                "-P", "plugin:androidx.compose.compiler.plugins.kotlin:sourceInformation=true"
+        ]
+    }
+}
diff --git a/compose/ui/ui-inspection/lint-baseline.xml b/compose/ui/ui-inspection/lint-baseline.xml
new file mode 100644
index 0000000..8f1aa4b
--- /dev/null
+++ b/compose/ui/ui-inspection/lint-baseline.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<issues format="5" by="lint 4.2.0-beta02" client="gradle" variant="debug" version="4.2.0-beta02">
+
+</issues>
diff --git a/compose/ui/ui-inspection/src/main/AndroidManifest.xml b/compose/ui/ui-inspection/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..5f27d96
--- /dev/null
+++ b/compose/ui/ui-inspection/src/main/AndroidManifest.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 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 package="androidx.compose.ui.inspection" />
\ No newline at end of file
diff --git a/compose/ui/ui-inspection/src/main/java/androidx/compose/ui/inspection/ComposeLayoutInspector.kt b/compose/ui/ui-inspection/src/main/java/androidx/compose/ui/inspection/ComposeLayoutInspector.kt
new file mode 100644
index 0000000..133e045
--- /dev/null
+++ b/compose/ui/ui-inspection/src/main/java/androidx/compose/ui/inspection/ComposeLayoutInspector.kt
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2021 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.compose.ui.inspection
+
+import androidx.inspection.Connection
+import androidx.inspection.Inspector
+import androidx.inspection.InspectorEnvironment
+import androidx.inspection.InspectorFactory
+import layoutinspector.compose.inspection.LayoutInspectorComposeProtocol
+
+private const val LAYOUT_INSPECTION_ID = "layoutinspector.compose.inspection"
+
+// created by java.util.ServiceLoader
+class ComposeLayoutInspectorFactory :
+    InspectorFactory<ComposeLayoutInspector>(LAYOUT_INSPECTION_ID) {
+    override fun createInspector(
+        connection: Connection,
+        environment: InspectorEnvironment
+    ): ComposeLayoutInspector {
+        return ComposeLayoutInspector(connection)
+    }
+}
+
+class ComposeLayoutInspector(
+    connection: Connection,
+) : Inspector(connection) {
+
+    override fun onReceiveCommand(data: ByteArray, callback: CommandCallback) {
+        // TODO: Actually reply with a real response
+        callback.reply(LayoutInspectorComposeProtocol.Response.getDefaultInstance().toByteArray())
+    }
+}
\ No newline at end of file
diff --git a/compose/ui/ui-inspection/src/main/proto/compose_layout_inspection.proto b/compose/ui/ui-inspection/src/main/proto/compose_layout_inspection.proto
new file mode 100644
index 0000000..c6df549
--- /dev/null
+++ b/compose/ui/ui-inspection/src/main/proto/compose_layout_inspection.proto
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2021 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.
+ */
+syntax = "proto3";
+package layoutinspector.compose.inspection;
+option java_package = "layoutinspector.compose.inspection";
+option java_outer_classname = "LayoutInspectorComposeProtocol";
+
+// ======= MESSAGES =======
+
+// ======= COMMANDS, RESPONSES, AND EVENTS =======
+
+message Command {
+}
+
+message Response {
+}
diff --git a/compose/ui/ui-inspection/src/main/resources/META-INF/services/androidx.inspection.InspectorFactory b/compose/ui/ui-inspection/src/main/resources/META-INF/services/androidx.inspection.InspectorFactory
new file mode 100644
index 0000000..e13fa9c
--- /dev/null
+++ b/compose/ui/ui-inspection/src/main/resources/META-INF/services/androidx.inspection.InspectorFactory
@@ -0,0 +1 @@
+androidx.compose.ui.inspection.ComposeLayoutInspectorFactory
diff --git a/settings.gradle b/settings.gradle
index a7f2b13..d48b67b 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -255,6 +255,7 @@
 includeProject(":compose:ui:ui-geometry", "compose/ui/ui-geometry", [BuildType.COMPOSE])
 includeProject(":compose:ui:ui-graphics", "compose/ui/ui-graphics", [BuildType.COMPOSE])
 includeProject(":compose:ui:ui-graphics:ui-graphics-samples", "compose/ui/ui-graphics/samples", [BuildType.COMPOSE])
+includeProject(":compose:ui:ui-inspection", "compose/ui/ui-inspection", [BuildType.COMPOSE])
 includeProject(":compose:ui:ui-lint", "compose/ui/ui-lint", [BuildType.COMPOSE])
 includeProject(":compose:ui:ui-test", "compose/ui/ui-test", [BuildType.COMPOSE])
 includeProject(":compose:ui:ui-test-font", "compose/ui/ui-test-font", [BuildType.COMPOSE])
@@ -326,7 +327,7 @@
 includeProject(":hilt:hilt-work", "hilt/hilt-work", [BuildType.MAIN])
 includeProject(":hilt:integration-tests:hilt-testapp-viewmodel", "hilt/integration-tests/viewmodelapp", [BuildType.MAIN])
 includeProject(":hilt:integration-tests:hilt-testapp-worker", "hilt/integration-tests/workerapp", [BuildType.MAIN])
-includeProject(":inspection:inspection", "inspection/inspection", [BuildType.MAIN])
+includeProject(":inspection:inspection", "inspection/inspection", [BuildType.MAIN, BuildType.COMPOSE])
 includeProject(":inspection:inspection-gradle-plugin", "inspection/inspection-gradle-plugin", [BuildType.MAIN])
 includeProject(":inspection:inspection-testing", "inspection/inspection-testing", [BuildType.MAIN])
 includeProject(":interpolator:interpolator", "interpolator/interpolator", [BuildType.MAIN])