Add package module to sdk snapshot that contains licenses

This ensures that the LSC license tool does not attempt to add a
package module to an sdk snapshot Android.bp.

Bug: 181569894
Test: m nothing
Change-Id: I37b66e0df56c5b9ec255f66cb4f2a066ea96a738
diff --git a/sdk/update.go b/sdk/update.go
index deac0ec..85dfc4a 100644
--- a/sdk/update.go
+++ b/sdk/update.go
@@ -228,6 +228,7 @@
 
 	allMembersByName := make(map[string]struct{})
 	exportedMembersByName := make(map[string]struct{})
+	hasLicenses := false
 	var memberVariantDeps []sdkMemberVariantDep
 	for _, sdkVariant := range sdkVariants {
 		memberVariantDeps = append(memberVariantDeps, sdkVariant.memberVariantDeps...)
@@ -241,6 +242,10 @@
 			if memberVariantDep.export {
 				exportedMembersByName[name] = struct{}{}
 			}
+
+			if memberVariantDep.memberType == android.LicenseModuleSdkMemberType {
+				hasLicenses = true
+			}
 		}
 	}
 
@@ -266,6 +271,22 @@
 	}
 	s.builderForTests = builder
 
+	// If the sdk snapshot includes any license modules then add a package module which has a
+	// default_applicable_licenses property. That will prevent the LSC license process from updating
+	// the generated Android.bp file to add a package module that includes all licenses used by all
+	// the modules in that package. That would be unnecessary as every module in the sdk should have
+	// their own licenses property specified.
+	if hasLicenses {
+		pkg := bpFile.newModule("package")
+		property := "default_applicable_licenses"
+		pkg.AddCommentForProperty(property, `
+A default list here prevents the license LSC from adding its own list which would
+be unnecessary as every module in the sdk already has its own licenses property.
+`)
+		pkg.AddProperty(property, []string{"Android-Apache-2.0"})
+		bpFile.AddModule(pkg)
+	}
+
 	// Group the variants for each member module together and then group the members of each member
 	// type together.
 	members := s.groupMemberVariantsByMemberThenType(ctx, memberVariantDeps)