Refactor sdk update mechanism

Creates a SnapshotBuilder and GeneratedSnapshotFile interfaces to allow
the java library snapshot work to be moved into the java package.

Test: m -j60 checkbuild
Change-Id: I857167616026149d5e85885621b53876b419ba9b
diff --git a/android/sdk.go b/android/sdk.go
index 8e1e106..d66816d 100644
--- a/android/sdk.go
+++ b/android/sdk.go
@@ -31,6 +31,9 @@
 	MemberName() string
 	BuildWithSdks(sdks SdkRefs)
 	RequiredSdks() SdkRefs
+
+	// Build a snapshot of the module.
+	BuildSnapshot(sdkModuleContext ModuleContext, builder SnapshotBuilder)
 }
 
 // SdkRef refers to a version of an SDK
@@ -103,6 +106,7 @@
 // interface. InitSdkAwareModule should be called to initialize this struct.
 type SdkBase struct {
 	properties sdkProperties
+	module     SdkAware
 }
 
 func (s *SdkBase) sdkBase() *SdkBase {
@@ -142,9 +146,34 @@
 	return s.properties.RequiredSdks
 }
 
+func (s *SdkBase) BuildSnapshot(sdkModuleContext ModuleContext, builder SnapshotBuilder) {
+	sdkModuleContext.ModuleErrorf("module type " + sdkModuleContext.OtherModuleType(s.module) + " cannot be used in an sdk")
+}
+
 // InitSdkAwareModule initializes the SdkBase struct. This must be called by all modules including
 // SdkBase.
 func InitSdkAwareModule(m SdkAware) {
 	base := m.sdkBase()
+	base.module = m
 	m.AddProperties(&base.properties)
 }
+
+// Provide support for generating the build rules which will build the snapshot.
+type SnapshotBuilder interface {
+	// Copy src to the dest (which is a snapshot relative path) and add the dest
+	// to the zip
+	CopyToSnapshot(src Path, dest string)
+
+	// Get the AndroidBpFile for the snapshot.
+	AndroidBpFile() GeneratedSnapshotFile
+
+	// Get a versioned name appropriate for the SDK snapshot version being taken.
+	VersionedSdkMemberName(unversionedName string) interface{}
+}
+
+// Provides support for generating a file, e.g. the Android.bp file.
+type GeneratedSnapshotFile interface {
+	Printfln(format string, args ...interface{})
+	Indent()
+	Dedent()
+}