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

Commit 05e75be6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add vendor notice header at the top of Third-party licenses"

parents 23a73be4 16c8c0ae
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
@@ -107,12 +107,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);
        }
@@ -125,7 +126,8 @@ class LicenseHtmlGeneratorFromXml {
        try {
            writer = new PrintWriter(outputFile);

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

            writer.flush();
            writer.close();
@@ -239,13 +241,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
@@ -21,6 +21,7 @@ import android.util.Log;

import androidx.annotation.VisibleForTesting;

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

import java.io.File;
@@ -108,6 +109,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);
    }
}