Notice support for APEX

Notice file for an APEX is created by merging notice files for the
modules included in it (plus the notice file for the APEX itself if
specified).

Notice files having the same content are not duplicated; it is emitted
only once.

Bug: 128701495
Test: m (apex_test is amended)
Test: m and inspect $(PRODUCT_OUT)/obj/NOTICE.txt to check there are
license entries for /system/apex/*.apex files

Change-Id: I169d91038291a6c71615de97cf5b03174afab5d4
diff --git a/apex/apex_test.go b/apex/apex_test.go
index f221cf2..ac2701f 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -159,6 +159,8 @@
 		"testkey.override.pk8":                 nil,
 		"vendor/foo/devkeys/testkey.avbpubkey": nil,
 		"vendor/foo/devkeys/testkey.pem":       nil,
+		"NOTICE":                               nil,
+		"custom_notice":                        nil,
 	})
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	android.FailIfErrored(t, errs)
@@ -280,6 +282,7 @@
 			srcs: ["mylib.cpp"],
 			system_shared_libs: [],
 			stl: "none",
+			notice: "custom_notice",
 		}
 	`)
 
@@ -319,6 +322,14 @@
 	if !good {
 		t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
 	}
+
+	apexMergeNoticeRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexMergeNoticeRule")
+	noticeInputs := strings.Split(apexMergeNoticeRule.Args["inputs"], " ")
+	if len(noticeInputs) != 3 {
+		t.Errorf("number of input notice files: expected = 3, actual = %d", len(noticeInputs))
+	}
+	ensureListContains(t, noticeInputs, "NOTICE")
+	ensureListContains(t, noticeInputs, "custom_notice")
 }
 
 func TestBasicZipApex(t *testing.T) {