Merge "Add vendor notice header at the top of Third-party licenses"
am: 05e75be642
Change-Id: Ibfa8d796d67017dffab15faefd223721980b6921
This commit is contained in:
@@ -1125,4 +1125,7 @@
|
|||||||
|
|
||||||
<!-- time label for event have that happened very recently [CHAR LIMIT=60] -->
|
<!-- time label for event have that happened very recently [CHAR LIMIT=60] -->
|
||||||
<string name="time_unit_just_now">Just now</string>
|
<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>
|
</resources>
|
||||||
|
|||||||
@@ -106,12 +106,13 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
mXmlFiles = xmlFiles;
|
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);
|
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) {
|
for (File xmlFile : mXmlFiles) {
|
||||||
parse(xmlFile);
|
parse(xmlFile);
|
||||||
}
|
}
|
||||||
@@ -124,7 +125,8 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
try {
|
try {
|
||||||
writer = new PrintWriter(outputFile);
|
writer = new PrintWriter(outputFile);
|
||||||
|
|
||||||
generateHtml(mFileNameToContentIdMap, mContentIdToFileContentMap, writer);
|
generateHtml(mFileNameToContentIdMap, mContentIdToFileContentMap, writer,
|
||||||
|
noticeHeader);
|
||||||
|
|
||||||
writer.flush();
|
writer.flush();
|
||||||
writer.close();
|
writer.close();
|
||||||
@@ -238,13 +240,18 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static void generateHtml(Map<String, String> fileNameToContentIdMap,
|
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();
|
List<String> fileNameList = new ArrayList();
|
||||||
fileNameList.addAll(fileNameToContentIdMap.keySet());
|
fileNameList.addAll(fileNameToContentIdMap.keySet());
|
||||||
Collections.sort(fileNameList);
|
Collections.sort(fileNameList);
|
||||||
|
|
||||||
writer.println(HTML_HEAD_STRING);
|
writer.println(HTML_HEAD_STRING);
|
||||||
|
|
||||||
|
if (!TextUtils.isEmpty(noticeHeader)) {
|
||||||
|
writer.println(noticeHeader);
|
||||||
|
}
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
Map<String, Integer> contentIdToOrderMap = new HashMap();
|
Map<String, Integer> contentIdToOrderMap = new HashMap();
|
||||||
List<ContentIdAndFileNames> contentIdAndFileNamesList = new ArrayList();
|
List<ContentIdAndFileNames> contentIdAndFileNamesList = new ArrayList();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import android.content.Context;
|
|||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.settingslib.R;
|
||||||
import com.android.settingslib.utils.AsyncLoader;
|
import com.android.settingslib.utils.AsyncLoader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -107,6 +108,7 @@ public class LicenseHtmlLoader extends AsyncLoader<File> {
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean generateHtmlFile(List<File> xmlFiles, File htmlFile) {
|
boolean generateHtmlFile(List<File> xmlFiles, File htmlFile) {
|
||||||
return LicenseHtmlGeneratorFromXml.generateHtml(xmlFiles, htmlFile);
|
return LicenseHtmlGeneratorFromXml.generateHtml(xmlFiles, htmlFile,
|
||||||
|
mContext.getString(R.string.notice_header));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
+ "<file-content contentId=\"0\"><![CDATA[license content #0]]></file-content>\n"
|
+ "<file-content contentId=\"0\"><![CDATA[license content #0]]></file-content>\n"
|
||||||
+ "</licenses2>";
|
+ "</licenses2>";
|
||||||
|
|
||||||
private static final String EXPECTED_HTML_STRING =
|
private static final String HTML_HEAD_STRING =
|
||||||
"<html><head>\n"
|
"<html><head>\n"
|
||||||
+ "<style type=\"text/css\">\n"
|
+ "<style type=\"text/css\">\n"
|
||||||
+ "body { padding: 0; font-family: sans-serif; }\n"
|
+ "body { padding: 0; font-family: sans-serif; }\n"
|
||||||
@@ -63,8 +63,12 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
+ "</head>"
|
+ "</head>"
|
||||||
+ "<body topmargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\">\n"
|
+ "<body topmargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\">\n"
|
||||||
+ "<div class=\"toc\">\n"
|
+ "<div class=\"toc\">\n"
|
||||||
+ "<ul>\n"
|
+ "<ul>\n";
|
||||||
+ "<li><a href=\"#id0\">/file0</a></li>\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"
|
+ "<li><a href=\"#id0\">/file1</a></li>\n"
|
||||||
+ "</ul>\n"
|
+ "</ul>\n"
|
||||||
+ "</div><!-- table of contents -->\n"
|
+ "</div><!-- table of contents -->\n"
|
||||||
@@ -81,6 +85,11 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
+ "</td></tr><!-- same-license -->\n"
|
+ "</td></tr><!-- same-license -->\n"
|
||||||
+ "</table></body></html>\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
|
@Test
|
||||||
public void testParseValidXmlStream() throws XmlPullParserException, IOException {
|
public void testParseValidXmlStream() throws XmlPullParserException, IOException {
|
||||||
Map<String, String> fileNameToContentIdMap = new HashMap<String, String>();
|
Map<String, String> fileNameToContentIdMap = new HashMap<String, String>();
|
||||||
@@ -117,7 +126,23 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
|
|
||||||
StringWriter output = new StringWriter();
|
StringWriter output = new StringWriter();
|
||||||
LicenseHtmlGeneratorFromXml.generateHtml(
|
LicenseHtmlGeneratorFromXml.generateHtml(
|
||||||
fileNameToContentIdMap, contentIdToFileContentMap, new PrintWriter(output));
|
fileNameToContentIdMap, contentIdToFileContentMap, new PrintWriter(output), "");
|
||||||
assertThat(output.toString()).isEqualTo(EXPECTED_HTML_STRING);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user