Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 15c340df authored by Jin Dong's avatar Jin Dong Committed by android-build-merger
Browse files

Merge "Add vendor notice header at the top of Third-party licenses" am: 05e75be6

am: cb476f5f

Change-Id: If6683d31403f75765acef1e2b431f681391af5eb
parents 25db19c7 cb476f5f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1125,4 +1125,7 @@

    <!-- time label for event have that happened very recently [CHAR LIMIT=60] -->
    <string name="time_unit_just_now">Just now</string>

    <!-- The notice header of Third-party licenses. not translatable -->
    <string name="notice_header" translatable="false"></string>
</resources>
+12 −5
Original line number Diff line number Diff line
@@ -106,12 +106,13 @@ class LicenseHtmlGeneratorFromXml {
        mXmlFiles = xmlFiles;
    }

    public static boolean generateHtml(List<File> xmlFiles, File outputFile) {
    public static boolean generateHtml(List<File> xmlFiles, File outputFile,
            String noticeHeader) {
        LicenseHtmlGeneratorFromXml genertor = new LicenseHtmlGeneratorFromXml(xmlFiles);
        return genertor.generateHtml(outputFile);
        return genertor.generateHtml(outputFile, noticeHeader);
    }

    private boolean generateHtml(File outputFile) {
    private boolean generateHtml(File outputFile, String noticeHeader) {
        for (File xmlFile : mXmlFiles) {
            parse(xmlFile);
        }
@@ -124,7 +125,8 @@ class LicenseHtmlGeneratorFromXml {
        try {
            writer = new PrintWriter(outputFile);

            generateHtml(mFileNameToContentIdMap, mContentIdToFileContentMap, writer);
            generateHtml(mFileNameToContentIdMap, mContentIdToFileContentMap, writer,
                noticeHeader);

            writer.flush();
            writer.close();
@@ -238,13 +240,18 @@ class LicenseHtmlGeneratorFromXml {

    @VisibleForTesting
    static void generateHtml(Map<String, String> fileNameToContentIdMap,
            Map<String, String> contentIdToFileContentMap, PrintWriter writer) {
            Map<String, String> contentIdToFileContentMap, PrintWriter writer,
            String noticeHeader) {
        List<String> fileNameList = new ArrayList();
        fileNameList.addAll(fileNameToContentIdMap.keySet());
        Collections.sort(fileNameList);

        writer.println(HTML_HEAD_STRING);

        if (!TextUtils.isEmpty(noticeHeader)) {
            writer.println(noticeHeader);
        }

        int count = 0;
        Map<String, Integer> contentIdToOrderMap = new HashMap();
        List<ContentIdAndFileNames> contentIdAndFileNamesList = new ArrayList();
+3 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import androidx.annotation.VisibleForTesting;
import android.util.Log;

import com.android.settingslib.R;
import com.android.settingslib.utils.AsyncLoader;

import java.io.File;
@@ -107,6 +108,7 @@ public class LicenseHtmlLoader extends AsyncLoader<File> {

    @VisibleForTesting
    boolean generateHtmlFile(List<File> xmlFiles, File htmlFile) {
        return LicenseHtmlGeneratorFromXml.generateHtml(xmlFiles, htmlFile);
        return LicenseHtmlGeneratorFromXml.generateHtml(xmlFiles, htmlFile,
                    mContext.getString(R.string.notice_header));
    }
}
+29 −4
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ public class LicenseHtmlGeneratorFromXmlTest {
            + "<file-content contentId=\"0\"><![CDATA[license content #0]]></file-content>\n"
            + "</licenses2>";

    private static final String EXPECTED_HTML_STRING =
    private static final String HTML_HEAD_STRING =
            "<html><head>\n"
            + "<style type=\"text/css\">\n"
            + "body { padding: 0; font-family: sans-serif; }\n"
@@ -63,8 +63,12 @@ public class LicenseHtmlGeneratorFromXmlTest {
            + "</head>"
            + "<body topmargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\">\n"
            + "<div class=\"toc\">\n"
            + "<ul>\n"
            + "<li><a href=\"#id0\">/file0</a></li>\n"
            + "<ul>\n";

    private static final String HTML_CUSTOM_HEADING = "Custom heading";

    private static final String HTML_BODY_STRING =
            "<li><a href=\"#id0\">/file0</a></li>\n"
            + "<li><a href=\"#id0\">/file1</a></li>\n"
            + "</ul>\n"
            + "</div><!-- table of contents -->\n"
@@ -81,6 +85,11 @@ public class LicenseHtmlGeneratorFromXmlTest {
            + "</td></tr><!-- same-license -->\n"
            + "</table></body></html>\n";

    private static final String EXPECTED_HTML_STRING = HTML_HEAD_STRING + HTML_BODY_STRING;

    private static final String EXPECTED_HTML_STRING_WITH_CUSTOM_HEADING =
            HTML_HEAD_STRING + HTML_CUSTOM_HEADING + "\n" + HTML_BODY_STRING;

    @Test
    public void testParseValidXmlStream() throws XmlPullParserException, IOException {
        Map<String, String> fileNameToContentIdMap = new HashMap<String, String>();
@@ -117,7 +126,23 @@ public class LicenseHtmlGeneratorFromXmlTest {

        StringWriter output = new StringWriter();
        LicenseHtmlGeneratorFromXml.generateHtml(
                fileNameToContentIdMap, contentIdToFileContentMap, new PrintWriter(output));
                fileNameToContentIdMap, contentIdToFileContentMap, new PrintWriter(output), "");
        assertThat(output.toString()).isEqualTo(EXPECTED_HTML_STRING);
    }

    @Test
    public void testGenerateHtmlWithCustomHeading() {
        Map<String, String> fileNameToContentIdMap = new HashMap<String, String>();
        Map<String, String> contentIdToFileContentMap = new HashMap<String, String>();

        fileNameToContentIdMap.put("/file0", "0");
        fileNameToContentIdMap.put("/file1", "0");
        contentIdToFileContentMap.put("0", "license content #0");

        StringWriter output = new StringWriter();
        LicenseHtmlGeneratorFromXml.generateHtml(
                fileNameToContentIdMap, contentIdToFileContentMap, new PrintWriter(output),
                HTML_CUSTOM_HEADING);
        assertThat(output.toString()).isEqualTo(EXPECTED_HTML_STRING_WITH_CUSTOM_HEADING);
    }
}