Refactor vendor snapshot to use LinkableInterface.

Refactors the vendor snapshot support to use the LinkableInterface
so that support can be extended to Rust. This CL does not add
vendor snapshot support for Rust; that is left for a follow-on CL.

Bug: 184042776
Test: m nothing
Change-Id: Id0c4970ca00053484a52677d182153cbc454c301
diff --git a/cc/cc.go b/cc/cc.go
index 16a49d3..2520705 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -841,6 +841,10 @@
 	c.Properties.HideFromMake = true
 }
 
+func (c *Module) HiddenFromMake() bool {
+	return c.Properties.HideFromMake
+}
+
 func (c *Module) Toc() android.OptionalPath {
 	if c.linker != nil {
 		if library, ok := c.linker.(libraryInterface); ok {
@@ -1088,12 +1092,6 @@
 	return false
 }
 
-// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
-// "product" and "vendor" variant modules return true for this function.
-// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
-// "soc_specific: true" and more vendor installed modules are included here.
-// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "product_available: true" or
-// "product_specific: true" modules are included here.
 func (c *Module) UseVndk() bool {
 	return c.Properties.VndkVersion != ""
 }
@@ -1141,6 +1139,18 @@
 	return c.VendorProperties.IsVendorPublicLibrary
 }
 
+func (c *Module) HasLlndkStubs() bool {
+	lib := moduleLibraryInterface(c)
+	return lib != nil && lib.hasLLNDKStubs()
+}
+
+func (c *Module) StubsVersion() string {
+	if lib, ok := c.linker.(versionedInterface); ok {
+		return lib.stubsVersion()
+	}
+	panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", c.BaseModuleName()))
+}
+
 // isImplementationForLLNDKPublic returns true for any variant of a cc_library that has LLNDK stubs
 // and does not set llndk.vendor_available: false.
 func (c *Module) isImplementationForLLNDKPublic() bool {
@@ -1185,7 +1195,7 @@
 	return false
 }
 
-func (c *Module) isVndkSp() bool {
+func (c *Module) IsVndkSp() bool {
 	if vndkdep := c.vndkdep; vndkdep != nil {
 		return vndkdep.isVndkSp()
 	}
@@ -1204,7 +1214,7 @@
 }
 
 func (c *Module) MustUseVendorVariant() bool {
-	return c.isVndkSp() || c.Properties.MustUseVendorVariant
+	return c.IsVndkSp() || c.Properties.MustUseVendorVariant
 }
 
 func (c *Module) getVndkExtendsModuleName() string {
@@ -1343,11 +1353,11 @@
 }
 
 func (ctx *moduleContextImpl) binary() bool {
-	return ctx.mod.binary()
+	return ctx.mod.Binary()
 }
 
 func (ctx *moduleContextImpl) object() bool {
-	return ctx.mod.object()
+	return ctx.mod.Object()
 }
 
 func (ctx *moduleContextImpl) canUseSdk() bool {
@@ -1445,7 +1455,7 @@
 }
 
 func (ctx *moduleContextImpl) isVndkSp() bool {
-	return ctx.mod.isVndkSp()
+	return ctx.mod.IsVndkSp()
 }
 
 func (ctx *moduleContextImpl) IsVndkExt() bool {
@@ -1786,7 +1796,7 @@
 		// glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or
 		// RECOVERY_SNAPSHOT_VERSION is current.
 		if i, ok := c.linker.(snapshotLibraryInterface); ok {
-			if shouldCollectHeadersForSnapshot(ctx, c, apexInfo) {
+			if ShouldCollectHeadersForSnapshot(ctx, c, apexInfo) {
 				i.collectHeadersForSnapshot(ctx)
 			}
 		}
@@ -1799,7 +1809,7 @@
 		// modules can be hidden from make as some are needed for resolving make side
 		// dependencies.
 		c.HideFromMake()
-	} else if !c.installable(apexInfo) {
+	} else if !installable(c, apexInfo) {
 		c.SkipInstall()
 	}
 
@@ -2451,7 +2461,7 @@
 			return true
 		}
 
-		if to.isVndkSp() || to.IsLlndk() {
+		if to.IsVndkSp() || to.IsLlndk() {
 			return false
 		}
 
@@ -3064,7 +3074,7 @@
 	return false
 }
 
-func (c *Module) binary() bool {
+func (c *Module) Binary() bool {
 	if b, ok := c.linker.(interface {
 		binary() bool
 	}); ok {
@@ -3073,7 +3083,7 @@
 	return false
 }
 
-func (c *Module) object() bool {
+func (c *Module) Object() bool {
 	if o, ok := c.linker.(interface {
 		object() bool
 	}); ok {
@@ -3155,18 +3165,25 @@
 	}
 }
 
-// Return true if the module is ever installable.
 func (c *Module) EverInstallable() bool {
 	return c.installer != nil &&
 		// Check to see whether the module is actually ever installable.
 		c.installer.everInstallable()
 }
 
-func (c *Module) installable(apexInfo android.ApexInfo) bool {
+func (c *Module) PreventInstall() bool {
+	return c.Properties.PreventInstall
+}
+
+func (c *Module) Installable() *bool {
+	return c.Properties.Installable
+}
+
+func installable(c LinkableInterface, apexInfo android.ApexInfo) bool {
 	ret := c.EverInstallable() &&
 		// Check to see whether the module has been configured to not be installed.
-		proptools.BoolDefault(c.Properties.Installable, true) &&
-		!c.Properties.PreventInstall && c.outputFile.Valid()
+		proptools.BoolDefault(c.Installable(), true) &&
+		!c.PreventInstall() && c.OutputFile().Valid()
 
 	// The platform variant doesn't need further condition. Apex variants however might not
 	// be installable because it will likely to be included in the APEX and won't appear
diff --git a/cc/cc_test.go b/cc/cc_test.go
index e9daf33..d82619a 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -381,8 +381,8 @@
 	if !mod.IsVndk() {
 		t.Errorf("%q IsVndk() must equal to true", name)
 	}
-	if mod.isVndkSp() != isVndkSp {
-		t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
+	if mod.IsVndkSp() != isVndkSp {
+		t.Errorf("%q IsVndkSp() must equal to %t", name, isVndkSp)
 	}
 
 	// Check VNDK extension properties.
diff --git a/cc/coverage.go b/cc/coverage.go
index 5b5ccf2..b2788ec 100644
--- a/cc/coverage.go
+++ b/cc/coverage.go
@@ -203,7 +203,7 @@
 type Coverage interface {
 	android.Module
 	IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool
-	PreventInstall()
+	SetPreventInstall()
 	HideFromMake()
 	MarkAsCoverageVariant(bool)
 	EnableCoverageIfNeeded()
@@ -236,7 +236,7 @@
 		// to an APEX via 'data' property.
 		m := mctx.CreateVariations("", "cov")
 		m[0].(Coverage).MarkAsCoverageVariant(false)
-		m[0].(Coverage).PreventInstall()
+		m[0].(Coverage).SetPreventInstall()
 		m[0].(Coverage).HideFromMake()
 
 		m[1].(Coverage).MarkAsCoverageVariant(true)
diff --git a/cc/linkable.go b/cc/linkable.go
index 40a9d8b..b583b69 100644
--- a/cc/linkable.go
+++ b/cc/linkable.go
@@ -48,6 +48,20 @@
 	// SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
 	SanitizerSupported(t SanitizerType) bool
 
+	// MinimalRuntimeDep returns true if this module needs to link the minimal UBSan runtime,
+	// either because it requires it or because a dependent module which requires it to be linked in this module.
+	MinimalRuntimeDep() bool
+
+	// UbsanRuntimeDep returns true if this module needs to link the full UBSan runtime,
+	// either because it requires it or because a dependent module which requires it to be linked in this module.
+	UbsanRuntimeDep() bool
+
+	// UbsanRuntimeNeeded returns true if the full UBSan runtime is required by this module.
+	UbsanRuntimeNeeded() bool
+
+	// MinimalRuntimeNeeded returns true if the minimal UBSan runtime is required by this module
+	MinimalRuntimeNeeded() bool
+
 	// SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
 	SanitizableDepTagChecker() SantizableDependencyTagChecker
 }
@@ -60,14 +74,42 @@
 // implementation should handle tags from both.
 type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
 
+// Snapshottable defines those functions necessary for handling module snapshots.
+type Snapshottable interface {
+	// SnapshotHeaders returns a list of header paths provided by this module.
+	SnapshotHeaders() android.Paths
+
+	// ExcludeFromVendorSnapshot returns true if this module should be otherwise excluded from the vendor snapshot.
+	ExcludeFromVendorSnapshot() bool
+
+	// ExcludeFromRecoverySnapshot returns true if this module should be otherwise excluded from the recovery snapshot.
+	ExcludeFromRecoverySnapshot() bool
+
+	// SnapshotLibrary returns true if this module is a snapshot library.
+	IsSnapshotLibrary() bool
+
+	// SnapshotRuntimeLibs returns a list of libraries needed by this module at runtime but which aren't build dependencies.
+	SnapshotRuntimeLibs() []string
+
+	// SnapshotSharedLibs returns the list of shared library dependencies for this module.
+	SnapshotSharedLibs() []string
+
+	// IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
+	IsSnapshotPrebuilt() bool
+}
+
 // LinkableInterface is an interface for a type of module that is linkable in a C++ library.
 type LinkableInterface interface {
 	android.Module
+	Snapshottable
 
 	Module() android.Module
 	CcLibrary() bool
 	CcLibraryInterface() bool
 
+	// BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
+	BaseModuleName() string
+
 	OutputFile() android.OptionalPath
 	CoverageFiles() android.Paths
 
@@ -79,9 +121,6 @@
 	BuildSharedVariant() bool
 	SetStatic()
 	SetShared()
-	Static() bool
-	Shared() bool
-	Header() bool
 	IsPrebuilt() bool
 	Toc() android.OptionalPath
 
@@ -106,13 +145,29 @@
 	// IsLlndkPublic returns true only for LLNDK (public) libs.
 	IsLlndkPublic() bool
 
+	// HasLlndkStubs returns true if this library has a variant that will build LLNDK stubs.
+	HasLlndkStubs() bool
+
 	// NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
 	NeedsLlndkVariants() bool
 
 	// NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
 	NeedsVendorPublicLibraryVariants() bool
 
+	//StubsVersion returns the stubs version for this module.
+	StubsVersion() string
+
+	// UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
+	// "product" and "vendor" variant modules return true for this function.
+	// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
+	// "soc_specific: true" and more vendor installed modules are included here.
+	// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
+	// "product_specific: true" modules are included here.
 	UseVndk() bool
+
+	// IsVndkSp returns true if this is a VNDK-SP module.
+	IsVndkSp() bool
+
 	MustUseVendorVariant() bool
 	IsVndk() bool
 	IsVndkExt() bool
@@ -140,6 +195,51 @@
 	// KernelHeadersDecorator returns true if this is a kernel headers decorator module.
 	// This is specific to cc and should always return false for all other packages.
 	KernelHeadersDecorator() bool
+
+	// HiddenFromMake returns true if this module is hidden from Make.
+	HiddenFromMake() bool
+
+	// RelativeInstallPath returns the relative install path for this module.
+	RelativeInstallPath() string
+
+	// Binary returns true if this is a binary module.
+	Binary() bool
+
+	// Object returns true if this is an object module.
+	Object() bool
+
+	// Rlib returns true if this is an rlib module.
+	Rlib() bool
+
+	// Dylib returns true if this is an dylib module.
+	Dylib() bool
+
+	// Static returns true if this is a static library module.
+	Static() bool
+
+	// Shared returns true if this is a shared library module.
+	Shared() bool
+
+	// Header returns true if this is a library headers module.
+	Header() bool
+
+	// EverInstallable returns true if the module is ever installable
+	EverInstallable() bool
+
+	// PreventInstall returns true if this module is prevented from installation.
+	PreventInstall() bool
+
+	// InstallInData returns true if this module is installed in data.
+	InstallInData() bool
+
+	// Installable returns a bool pointer to the module installable property.
+	Installable() *bool
+
+	// Symlinks returns a list of symlinks that should be created for this module.
+	Symlinks() []string
+
+	// VndkVersion returns the VNDK version string for this module.
+	VndkVersion() string
 }
 
 var (
diff --git a/cc/sabi.go b/cc/sabi.go
index c0eb57c..384dcc1 100644
--- a/cc/sabi.go
+++ b/cc/sabi.go
@@ -84,7 +84,7 @@
 		return "LLNDK"
 	}
 	if m.UseVndk() && m.IsVndk() && !m.IsVndkPrivate() {
-		if m.isVndkSp() {
+		if m.IsVndkSp() {
 			if m.IsVndkExt() {
 				return "VNDK-SP-ext"
 			} else {
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 397121e..605a8d0 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -1075,7 +1075,7 @@
 			sanitizers = append(sanitizers, "shadow-call-stack")
 		}
 
-		if Bool(c.sanitize.Properties.Sanitize.Memtag_heap) && c.binary() {
+		if Bool(c.sanitize.Properties.Sanitize.Memtag_heap) && c.Binary() {
 			noteDep := "note_memtag_heap_async"
 			if Bool(c.sanitize.Properties.Sanitize.Diag.Memtag_heap) {
 				noteDep = "note_memtag_heap_sync"
@@ -1208,6 +1208,14 @@
 	AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string)
 }
 
+func (c *Module) MinimalRuntimeDep() bool {
+	return c.sanitize.Properties.MinimalRuntimeDep
+}
+
+func (c *Module) UbsanRuntimeDep() bool {
+	return c.sanitize.Properties.UbsanRuntimeDep
+}
+
 func (c *Module) SanitizePropDefined() bool {
 	return c.sanitize != nil
 }
@@ -1441,6 +1449,14 @@
 	return false
 }
 
+func (m *Module) UbsanRuntimeNeeded() bool {
+	return enableUbsanRuntime(m.sanitize)
+}
+
+func (m *Module) MinimalRuntimeNeeded() bool {
+	return enableMinimalRuntime(m.sanitize)
+}
+
 func enableUbsanRuntime(sanitize *sanitize) bool {
 	return Bool(sanitize.Properties.Sanitize.Diag.Integer_overflow) ||
 		Bool(sanitize.Properties.Sanitize.Diag.Undefined) ||
diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go
index 885a0ce..0b1147e 100644
--- a/cc/snapshot_prebuilt.go
+++ b/cc/snapshot_prebuilt.go
@@ -35,12 +35,12 @@
 	// Function that returns true if the module is included in this image.
 	// Using a function return instead of a value to prevent early
 	// evalution of a function that may be not be defined.
-	inImage(m *Module) func() bool
+	inImage(m LinkableInterface) func() bool
 
 	// Returns true if the module is private and must not be included in the
 	// snapshot. For example VNDK-private modules must return true for the
 	// vendor snapshots. But false for the recovery snapshots.
-	private(m *Module) bool
+	private(m LinkableInterface) bool
 
 	// Returns true if a dir under source tree is an SoC-owned proprietary
 	// directory, such as device/, vendor/, etc.
@@ -56,7 +56,7 @@
 	// Whether a given module has been explicitly excluded from the
 	// snapshot, e.g., using the exclude_from_vendor_snapshot or
 	// exclude_from_recovery_snapshot properties.
-	excludeFromSnapshot(m *Module) bool
+	excludeFromSnapshot(m LinkableInterface) bool
 
 	// Returns true if the build is using a snapshot for this image.
 	isUsingSnapshot(cfg android.DeviceConfig) bool
@@ -125,11 +125,11 @@
 	return ctx.DeviceConfig().VndkVersion() == "current"
 }
 
-func (vendorSnapshotImage) inImage(m *Module) func() bool {
+func (vendorSnapshotImage) inImage(m LinkableInterface) func() bool {
 	return m.InVendor
 }
 
-func (vendorSnapshotImage) private(m *Module) bool {
+func (vendorSnapshotImage) private(m LinkableInterface) bool {
 	return m.IsVndkPrivate()
 }
 
@@ -159,7 +159,7 @@
 	return true
 }
 
-func (vendorSnapshotImage) excludeFromSnapshot(m *Module) bool {
+func (vendorSnapshotImage) excludeFromSnapshot(m LinkableInterface) bool {
 	return m.ExcludeFromVendorSnapshot()
 }
 
@@ -206,12 +206,12 @@
 	return ctx.DeviceConfig().RecoverySnapshotVersion() == "current"
 }
 
-func (recoverySnapshotImage) inImage(m *Module) func() bool {
+func (recoverySnapshotImage) inImage(m LinkableInterface) func() bool {
 	return m.InRecovery
 }
 
 // recovery snapshot does not have private libraries.
-func (recoverySnapshotImage) private(m *Module) bool {
+func (recoverySnapshotImage) private(m LinkableInterface) bool {
 	return false
 }
 
@@ -224,7 +224,7 @@
 	return false
 }
 
-func (recoverySnapshotImage) excludeFromSnapshot(m *Module) bool {
+func (recoverySnapshotImage) excludeFromSnapshot(m LinkableInterface) bool {
 	return m.ExcludeFromRecoverySnapshot()
 }
 
diff --git a/cc/snapshot_utils.go b/cc/snapshot_utils.go
index c32fa36..8eb6164 100644
--- a/cc/snapshot_utils.go
+++ b/cc/snapshot_utils.go
@@ -23,6 +23,36 @@
 	headerExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"}
 )
 
+func (m *Module) IsSnapshotLibrary() bool {
+	if _, ok := m.linker.(snapshotLibraryInterface); ok {
+		return true
+	}
+	return false
+}
+
+func (m *Module) SnapshotHeaders() android.Paths {
+	if m.IsSnapshotLibrary() {
+		return m.linker.(snapshotLibraryInterface).snapshotHeaders()
+	}
+	return android.Paths{}
+}
+
+func (m *Module) Dylib() bool {
+	return false
+}
+
+func (m *Module) Rlib() bool {
+	return false
+}
+
+func (m *Module) SnapshotRuntimeLibs() []string {
+	return m.Properties.SnapshotRuntimeLibs
+}
+
+func (m *Module) SnapshotSharedLibs() []string {
+	return m.Properties.SnapshotSharedLibs
+}
+
 // snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots.
 type snapshotLibraryInterface interface {
 	libraryInterface
@@ -68,14 +98,14 @@
 	return snapshot, found
 }
 
-// shouldCollectHeadersForSnapshot determines if the module is a possible candidate for snapshot.
+// ShouldCollectHeadersForSnapshot determines if the module is a possible candidate for snapshot.
 // If it's true, collectHeadersForSnapshot will be called in GenerateAndroidBuildActions.
-func shouldCollectHeadersForSnapshot(ctx android.ModuleContext, m *Module, apexInfo android.ApexInfo) bool {
+func ShouldCollectHeadersForSnapshot(ctx android.ModuleContext, m LinkableInterface, apexInfo android.ApexInfo) bool {
 	if ctx.DeviceConfig().VndkVersion() != "current" &&
 		ctx.DeviceConfig().RecoverySnapshotVersion() != "current" {
 		return false
 	}
-	if _, _, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo); ok {
+	if _, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo); ok {
 		return ctx.Config().VndkSnapshotBuildArtifacts()
 	}
 
diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go
index 9ad51ad..4e59a95 100644
--- a/cc/vendor_snapshot.go
+++ b/cc/vendor_snapshot.go
@@ -115,7 +115,7 @@
 	// still be a vendor proprietary module. This happens for cc modules
 	// that are excluded from the vendor snapshot, and it means that the
 	// vendor has assumed control of the framework-provided module.
-	if c, ok := ctx.Module().(*Module); ok {
+	if c, ok := ctx.Module().(LinkableInterface); ok {
 		if c.ExcludeFromVendorSnapshot() {
 			return true
 		}
@@ -137,7 +137,7 @@
 	// that are excluded from the recovery snapshot, and it means that the
 	// vendor has assumed control of the framework-provided module.
 
-	if c, ok := ctx.Module().(*Module); ok {
+	if c, ok := ctx.Module().(LinkableInterface); ok {
 		if c.ExcludeFromRecoverySnapshot() {
 			return true
 		}
@@ -147,8 +147,8 @@
 }
 
 // Determines if the module is a candidate for snapshot.
-func isSnapshotAware(cfg android.DeviceConfig, m *Module, inProprietaryPath bool, apexInfo android.ApexInfo, image snapshotImage) bool {
-	if !m.Enabled() || m.Properties.HideFromMake {
+func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietaryPath bool, apexInfo android.ApexInfo, image snapshotImage) bool {
+	if !m.Enabled() || m.HiddenFromMake() {
 		return false
 	}
 	// When android/prebuilt.go selects between source and prebuilt, it sets
@@ -177,51 +177,51 @@
 		return false
 	}
 	// skip kernel_headers which always depend on vendor
-	if _, ok := m.linker.(*kernelHeadersDecorator); ok {
+	if m.KernelHeadersDecorator() {
 		return false
 	}
-	// skip LLNDK libraries which are backward compatible
+
 	if m.IsLlndk() {
 		return false
 	}
 
 	// Libraries
-	if l, ok := m.linker.(snapshotLibraryInterface); ok {
-		if m.sanitize != nil {
+	if sanitizable, ok := m.(PlatformSanitizeable); ok && sanitizable.IsSnapshotLibrary() {
+		if sanitizable.SanitizePropDefined() {
 			// scs and hwasan export both sanitized and unsanitized variants for static and header
 			// Always use unsanitized variants of them.
 			for _, t := range []SanitizerType{scs, Hwasan} {
-				if !l.shared() && m.sanitize.isSanitizerEnabled(t) {
+				if !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(t) {
 					return false
 				}
 			}
 			// cfi also exports both variants. But for static, we capture both.
 			// This is because cfi static libraries can't be linked from non-cfi modules,
 			// and vice versa. This isn't the case for scs and hwasan sanitizers.
-			if !l.static() && !l.shared() && m.sanitize.isSanitizerEnabled(cfi) {
+			if !sanitizable.Static() && !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(cfi) {
 				return false
 			}
 		}
-		if l.static() {
-			return m.outputFile.Valid() && !image.private(m)
+		if sanitizable.Static() {
+			return sanitizable.OutputFile().Valid() && !image.private(m)
 		}
-		if l.shared() {
-			if !m.outputFile.Valid() {
+		if sanitizable.Shared() {
+			if !sanitizable.OutputFile().Valid() {
 				return false
 			}
 			if image.includeVndk() {
-				if !m.IsVndk() {
+				if !sanitizable.IsVndk() {
 					return true
 				}
-				return m.IsVndkExt()
+				return sanitizable.IsVndkExt()
 			}
 		}
 		return true
 	}
 
 	// Binaries and Objects
-	if m.binary() || m.object() {
-		return m.outputFile.Valid()
+	if m.Binary() || m.Object() {
+		return m.OutputFile().Valid()
 	}
 
 	return false
@@ -323,7 +323,7 @@
 
 	// installSnapshot function copies prebuilt file (.so, .a, or executable) and json flag file.
 	// For executables, init_rc and vintf_fragments files are also copied.
-	installSnapshot := func(m *Module, fake bool) android.Paths {
+	installSnapshot := func(m LinkableInterface, fake bool) android.Paths {
 		targetArch := "arch-" + m.Target().Arch.ArchType.String()
 		if m.Target().Arch.ArchVariant != "" {
 			targetArch += "-" + m.Target().Arch.ArchVariant
@@ -337,7 +337,7 @@
 		prop.ModuleName = ctx.ModuleName(m)
 		if c.supportsVndkExt && m.IsVndkExt() {
 			// vndk exts are installed to /vendor/lib(64)?/vndk(-sp)?
-			if m.isVndkSp() {
+			if m.IsVndkSp() {
 				prop.RelativeInstallPath = "vndk-sp"
 			} else {
 				prop.RelativeInstallPath = "vndk"
@@ -345,7 +345,7 @@
 		} else {
 			prop.RelativeInstallPath = m.RelativeInstallPath()
 		}
-		prop.RuntimeLibs = m.Properties.SnapshotRuntimeLibs
+		prop.RuntimeLibs = m.SnapshotRuntimeLibs()
 		prop.Required = m.RequiredModuleNames()
 		for _, path := range m.InitRc() {
 			prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base()))
@@ -365,8 +365,8 @@
 
 		var propOut string
 
-		if l, ok := m.linker.(snapshotLibraryInterface); ok {
-			exporterInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
+		if m.IsSnapshotLibrary() {
+			exporterInfo := ctx.ModuleProvider(m.Module(), FlagExporterInfoProvider).(FlagExporterInfo)
 
 			// library flags
 			prop.ExportedFlags = exporterInfo.Flags
@@ -376,19 +376,22 @@
 			for _, dir := range exporterInfo.SystemIncludeDirs {
 				prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String()))
 			}
+
 			// shared libs dependencies aren't meaningful on static or header libs
-			if l.shared() {
-				prop.SharedLibs = m.Properties.SnapshotSharedLibs
+			if m.Shared() {
+				prop.SharedLibs = m.SnapshotSharedLibs()
 			}
-			if l.static() && m.sanitize != nil {
-				prop.SanitizeMinimalDep = m.sanitize.Properties.MinimalRuntimeDep || enableMinimalRuntime(m.sanitize)
-				prop.SanitizeUbsanDep = m.sanitize.Properties.UbsanRuntimeDep || enableUbsanRuntime(m.sanitize)
+			if sanitizable, ok := m.(PlatformSanitizeable); ok {
+				if sanitizable.Static() && sanitizable.SanitizePropDefined() {
+					prop.SanitizeMinimalDep = sanitizable.MinimalRuntimeDep() || sanitizable.MinimalRuntimeNeeded()
+					prop.SanitizeUbsanDep = sanitizable.UbsanRuntimeDep() || sanitizable.UbsanRuntimeNeeded()
+				}
 			}
 
 			var libType string
-			if l.static() {
+			if m.Static() {
 				libType = "static"
-			} else if l.shared() {
+			} else if m.Shared() {
 				libType = "shared"
 			} else {
 				libType = "header"
@@ -398,16 +401,18 @@
 
 			// install .a or .so
 			if libType != "header" {
-				libPath := m.outputFile.Path()
+				libPath := m.OutputFile().Path()
 				stem = libPath.Base()
-				if l.static() && m.sanitize != nil && m.sanitize.isSanitizerEnabled(cfi) {
-					// both cfi and non-cfi variant for static libraries can exist.
-					// attach .cfi to distinguish between cfi and non-cfi.
-					// e.g. libbase.a -> libbase.cfi.a
-					ext := filepath.Ext(stem)
-					stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
-					prop.Sanitize = "cfi"
-					prop.ModuleName += ".cfi"
+				if sanitizable, ok := m.(PlatformSanitizeable); ok {
+					if sanitizable.Static() && sanitizable.SanitizePropDefined() && sanitizable.IsSanitizerEnabled(cfi) {
+						// both cfi and non-cfi variant for static libraries can exist.
+						// attach .cfi to distinguish between cfi and non-cfi.
+						// e.g. libbase.a -> libbase.cfi.a
+						ext := filepath.Ext(stem)
+						stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
+						prop.Sanitize = "cfi"
+						prop.ModuleName += ".cfi"
+					}
 				}
 				snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem)
 				ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake))
@@ -416,20 +421,20 @@
 			}
 
 			propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json")
-		} else if m.binary() {
+		} else if m.Binary() {
 			// binary flags
 			prop.Symlinks = m.Symlinks()
-			prop.SharedLibs = m.Properties.SnapshotSharedLibs
+			prop.SharedLibs = m.SnapshotSharedLibs()
 
 			// install bin
-			binPath := m.outputFile.Path()
+			binPath := m.OutputFile().Path()
 			snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base())
 			ret = append(ret, copyFile(ctx, binPath, snapshotBinOut, fake))
 			propOut = snapshotBinOut + ".json"
-		} else if m.object() {
+		} else if m.Object() {
 			// object files aren't installed to the device, so their names can conflict.
 			// Use module name as stem.
-			objPath := m.outputFile.Path()
+			objPath := m.OutputFile().Path()
 			snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object",
 				ctx.ModuleName(m)+filepath.Ext(objPath.Base()))
 			ret = append(ret, copyFile(ctx, objPath, snapshotObjOut, fake))
@@ -450,7 +455,7 @@
 	}
 
 	ctx.VisitAllModules(func(module android.Module) {
-		m, ok := module.(*Module)
+		m, ok := module.(LinkableInterface)
 		if !ok {
 			return
 		}
@@ -484,8 +489,8 @@
 		// installSnapshot installs prebuilts and json flag files
 		snapshotOutputs = append(snapshotOutputs, installSnapshot(m, installAsFake)...)
 		// just gather headers and notice files here, because they are to be deduplicated
-		if l, ok := m.linker.(snapshotLibraryInterface); ok {
-			headers = append(headers, l.snapshotHeaders()...)
+		if m.IsSnapshotLibrary() {
+			headers = append(headers, m.SnapshotHeaders()...)
 		}
 
 		if len(m.NoticeFiles()) > 0 {
diff --git a/cc/vndk.go b/cc/vndk.go
index 8b3788b..0254edc 100644
--- a/cc/vndk.go
+++ b/cc/vndk.go
@@ -372,7 +372,7 @@
 			if mctx.ModuleName() == "libz" {
 				return false
 			}
-			return m.ImageVariation().Variation == android.CoreVariation && lib.shared() && m.isVndkSp()
+			return m.ImageVariation().Variation == android.CoreVariation && lib.shared() && m.IsVndkSp()
 		}
 
 		useCoreVariant := m.VndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
@@ -574,38 +574,37 @@
 	vndkSnapshotZipFile android.OptionalPath
 }
 
-func isVndkSnapshotAware(config android.DeviceConfig, m *Module,
-	apexInfo android.ApexInfo) (i snapshotLibraryInterface, vndkType string, isVndkSnapshotLib bool) {
+func isVndkSnapshotAware(config android.DeviceConfig, m LinkableInterface,
+	apexInfo android.ApexInfo) (vndkType string, isVndkSnapshotLib bool) {
 
 	if m.Target().NativeBridge == android.NativeBridgeEnabled {
-		return nil, "", false
+		return "", false
 	}
 	// !inVendor: There's product/vendor variants for VNDK libs. We only care about vendor variants.
 	// !installable: Snapshot only cares about "installable" modules.
 	// !m.IsLlndk: llndk stubs are required for building against snapshots.
 	// IsSnapshotPrebuilt: Snapshotting a snapshot doesn't make sense.
 	// !outputFile.Valid: Snapshot requires valid output file.
-	if !m.InVendor() || (!m.installable(apexInfo) && !m.IsLlndk()) || m.IsSnapshotPrebuilt() || !m.outputFile.Valid() {
-		return nil, "", false
+	if !m.InVendor() || (!installable(m, apexInfo) && !m.IsLlndk()) || m.IsSnapshotPrebuilt() || !m.OutputFile().Valid() {
+		return "", false
 	}
-	l, ok := m.linker.(snapshotLibraryInterface)
-	if !ok || !l.shared() {
-		return nil, "", false
+	if !m.IsSnapshotLibrary() || !m.Shared() {
+		return "", false
 	}
 	if m.VndkVersion() == config.PlatformVndkVersion() {
 		if m.IsVndk() && !m.IsVndkExt() {
-			if m.isVndkSp() {
-				return l, "vndk-sp", true
+			if m.IsVndkSp() {
+				return "vndk-sp", true
 			} else {
-				return l, "vndk-core", true
+				return "vndk-core", true
 			}
-		} else if l.hasLLNDKStubs() && l.stubsVersion() == "" {
+		} else if m.HasLlndkStubs() && m.StubsVersion() == "" {
 			// Use default version for the snapshot.
-			return l, "llndk-stub", true
+			return "llndk-stub", true
 		}
 	}
 
-	return nil, "", false
+	return "", false
 }
 
 func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
@@ -722,7 +721,7 @@
 
 		apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
 
-		l, vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
+		vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
 		if !ok {
 			return
 		}
@@ -761,7 +760,7 @@
 		}
 
 		if ctx.Config().VndkSnapshotBuildArtifacts() {
-			headers = append(headers, l.snapshotHeaders()...)
+			headers = append(headers, m.SnapshotHeaders()...)
 		}
 	})