Limit visibility of ART libraries, binaries, and headers.

This simply records the visibilities necessary to keep things working - more
work is required to vet them.

Test: m
Bug: 133140750
Change-Id: I776d6b79c4c2b214556070c850ae5321d5f8b949
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..818fcfb
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,5 @@
+// If you're looking for ART global stuff, please see build/Android.bp.
+
+package {
+    default_visibility: ["//art:__subpackages__"],
+}
diff --git a/adbconnection/Android.bp b/adbconnection/Android.bp
index fbc8afe..da73619 100644
--- a/adbconnection/Android.bp
+++ b/adbconnection/Android.bp
@@ -57,6 +57,10 @@
 
 cc_library {
     name: "libadbconnection_server",
+    visibility: [
+        // TODO(b/133140750): Clean this up.
+        "//system/core/adb",
+    ],
     srcs: ["adbconnection_server.cc"],
     export_include_dirs: ["include"],
     shared_libs: ["libbase"],
diff --git a/build/Android.bp b/build/Android.bp
index 605d468..45564f4 100644
--- a/build/Android.bp
+++ b/build/Android.bp
@@ -58,6 +58,12 @@
     // Additional flags are computed by art.go
 
     name: "art_defaults",
+
+    // This is the default visibility for the //art package, but we repeat it
+    // here so that it gets merged with other visibility rules in modules
+    // extending these defaults.
+    visibility: ["//art:__subpackages__"],
+
     cflags: [
         // Base set of cflags used by all things ART.
         "-fno-rtti",
@@ -221,6 +227,7 @@
 
 art_debug_defaults {
     name: "art_debug_defaults",
+    visibility: ["//art:__subpackages__"],
     cflags: [
         "-DDYNAMIC_ANNOTATIONS_ENABLED=1",
         "-DVIXL_DEBUG",
diff --git a/dex2oat/Android.bp b/dex2oat/Android.bp
index cb59bc2..14bca00 100644
--- a/dex2oat/Android.bp
+++ b/dex2oat/Android.bp
@@ -165,6 +165,10 @@
 
 cc_library_headers {
     name: "dex2oat_headers",
+    visibility: [
+        // TODO(b/133140750): Clean this up.
+        "//frameworks/native/cmds/installd",
+    ],
     host_supported: true,
     export_include_dirs: ["include"],
 }
@@ -192,6 +196,10 @@
 
 cc_defaults {
     name: "dex2oat-pgo-defaults",
+    defaults_visibility: [
+        "//art:__subpackages__",
+        "//external/vixl",
+    ],
     pgo: {
         instrumentation: true,
         benchmarks: ["dex2oat"],
diff --git a/libartbase/Android.bp b/libartbase/Android.bp
index 4fb0f76..cb0721b 100644
--- a/libartbase/Android.bp
+++ b/libartbase/Android.bp
@@ -166,6 +166,15 @@
 art_cc_library {
     name: "libartbase",
     defaults: ["libartbase_defaults"],
+    visibility: [
+        // TODO(b/133140750): Clean this up.
+        "//cts/tests/tests/appop",
+        "//frameworks/base/startop/view_compiler",
+        "//frameworks/base/tests/net:__subpackages__",
+        "//packages/modules/NetworkStack/tests:__subpackages__",
+        "//system/extras/simpleperf",
+    ],
+
     // Leave the symbols in the shared library so that stack unwinders can
     // produce meaningful name resolution.
     strip: {
diff --git a/libartimagevalues/Android.bp b/libartimagevalues/Android.bp
index c47dd72..80f58b7 100644
--- a/libartimagevalues/Android.bp
+++ b/libartimagevalues/Android.bp
@@ -6,6 +6,10 @@
 cc_library_static {
     name: "libartimagevalues",
     defaults: ["libartimagevalues_defaults"],
+    visibility: [
+        // TODO(b/133140750): Clean this up.
+        "//frameworks/native/cmds/installd",
+    ],
     srcs: ["art_image_values.cpp"],
     export_include_dirs: ["."],
     cflags: ["-Wconversion"],
diff --git a/libartpalette/Android.bp b/libartpalette/Android.bp
index 0a45b88..f6c7ac1 100644
--- a/libartpalette/Android.bp
+++ b/libartpalette/Android.bp
@@ -63,6 +63,11 @@
 art_cc_library {
     name: "libartpalette",
     defaults: ["libartpalette_defaults"],
+    visibility: [
+        // TODO(b/133140750): Clean this up.
+        "//frameworks/base/startop/view_compiler",
+        "//system/extras/simpleperf",
+    ],
     required: ["libartpalette-system"], // libartpalette.so dlopen()'s libartpalette-system.
     header_libs: ["libbase_headers"],
     target: {
diff --git a/libdexfile/Android.bp b/libdexfile/Android.bp
index c740f7b..d4aead0 100644
--- a/libdexfile/Android.bp
+++ b/libdexfile/Android.bp
@@ -108,6 +108,12 @@
         "libartbase_static_defaults",
         "libdexfile_static_base_defaults",
     ],
+    defaults_visibility: [
+        "//art:__subpackages__",
+        // TODO(b/133140750): Clean this up.
+        "//frameworks/base/startop/view_compiler",
+        "//system/extras/simpleperf",
+    ],
     static_libs: ["libdexfile"],
 }
 
@@ -138,6 +144,13 @@
 art_cc_library {
     name: "libdexfile",
     defaults: ["libdexfile_defaults"],
+    visibility: [
+        // TODO(b/133140750): Clean this up.
+        "//cts/tests/tests/appop",
+        "//frameworks/base/startop/view_compiler",
+        "//frameworks/base/tests/net:__subpackages__",
+        "//system/extras/simpleperf",
+    ],
     // Leave the symbols in the shared library so that stack unwinders can
     // produce meaningful name resolution.
     strip: {
@@ -242,6 +255,7 @@
 
 cc_library_headers {
     name: "libdexfile_external_headers",
+    visibility: ["//visibility:public"],
     host_supported: true,
     vendor_available: true,
     recovery_available: true,
@@ -287,6 +301,7 @@
         "art_defaults",
         "libdexfile_external-defaults",
     ],
+    visibility: ["//visibility:public"],
     target: {
         darwin: {
             enabled: true,
@@ -332,6 +347,7 @@
 // stack frames.
 cc_library {
     name: "libdexfile_support",
+    visibility: ["//visibility:public"],
     host_supported: true,
     vendor_available: true,
     recovery_available: true,
@@ -374,6 +390,7 @@
 
 cc_library_static {
     name: "libdexfile_support_static",
+    visibility: ["//visibility:public"],
     host_supported: true,
     defaults: ["libdexfile_static_defaults"],
     srcs: [
diff --git a/openjdkjvm/Android.bp b/openjdkjvm/Android.bp
index 907315e..a5350f9 100644
--- a/openjdkjvm/Android.bp
+++ b/openjdkjvm/Android.bp
@@ -16,6 +16,7 @@
 cc_defaults {
     name: "libopenjdkjvm_defaults",
     defaults: ["art_defaults"],
+    visibility: ["//libcore"],
     host_supported: true,
     srcs: ["OpenjdkJvm.cc"],
     shared_libs: [
diff --git a/openjdkjvmti/Android.bp b/openjdkjvmti/Android.bp
index 7621d48..e7306ba 100644
--- a/openjdkjvmti/Android.bp
+++ b/openjdkjvmti/Android.bp
@@ -15,6 +15,7 @@
 
 cc_library_headers {
     name: "libopenjdkjvmti_headers",
+    visibility: ["//visibility:public"],
     host_supported: true,
     export_include_dirs: ["include"],
     sdk_version: "current",
diff --git a/sigchainlib/Android.bp b/sigchainlib/Android.bp
index 31a8f3d..a94daf3 100644
--- a/sigchainlib/Android.bp
+++ b/sigchainlib/Android.bp
@@ -16,9 +16,13 @@
 
 cc_library {
     name: "libsigchain",
+    defaults: ["art_defaults"],
+    visibility: [
+        // TODO(b/133140750): Clean this up.
+        "//frameworks/base/cmds/app_process",
+    ],
 
     host_supported: true,
-    defaults: ["art_defaults"],
     target: {
         linux: {
             shared: {
@@ -69,10 +73,18 @@
 
 filegroup {
     name: "art_sigchain_version_script32.txt",
+    visibility: [
+        // TODO(b/133140750): Clean this up.
+        "//frameworks/base/cmds/app_process",
+    ],
     srcs: ["version-script32.txt"],
 }
 
 filegroup {
     name: "art_sigchain_version_script64.txt",
+    visibility: [
+        // TODO(b/133140750): Clean this up.
+        "//frameworks/base/cmds/app_process",
+    ],
     srcs: ["version-script64.txt"],
 }
diff --git a/test/Android.bp b/test/Android.bp
index 86d1857..66a08e9 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -372,6 +372,9 @@
 cc_library_static {
     name: "libctstiagent",
     defaults: ["libtiagent-base-defaults"],
+    visibility: [
+        "//cts/hostsidetests/jvmti:__subpackages__",
+    ],
     host_supported: false,
     srcs: [
         "983-source-transform-verify/source_transform_slicer.cc",
@@ -579,6 +582,9 @@
 
 filegroup {
     name: "art_cts_jvmti_test_library",
+    visibility: [
+        "//cts/hostsidetests/jvmti:__subpackages__",
+    ],
     srcs: [
         // shim classes. We use one that exposes the common functionality.
         "jvmti-common/Redefinition.java",
@@ -710,6 +716,9 @@
 // Copy+rename them them to a temporary directory and them zip them.
 java_genrule {
     name: "expected_cts_outputs",
+    visibility: [
+        "//cts/hostsidetests/jvmti:__subpackages__",
+    ],
     srcs: [
         "901-hello-ti-agent/expected.txt",
         "902-hello-transformation/expected.txt",
diff --git a/tools/ahat/Android.bp b/tools/ahat/Android.bp
index 3b75dd2..a08a03d 100644
--- a/tools/ahat/Android.bp
+++ b/tools/ahat/Android.bp
@@ -33,6 +33,9 @@
 // --- ahat.jar ----------------
 java_binary_host {
     name: "ahat",
+    visibility: [
+        "//libcore/metrictests/memory/host",
+    ],
     wrapper: "ahat",
     srcs: ["src/main/**/*.java"],
     manifest: "etc/ahat.mf",