Merge "Fix broken anchor tags." am: 008ca223c7 am: df27d18f17 am: 69665af664 am: ffd4d10a6c
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2181757
Change-Id: If4e0af6dd4675dd27ec3ec9ac31c396ef9be556f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/packages/SettingsLib/src/com/android/settingslib/license/LicenseHtmlGeneratorFromXml.java b/packages/SettingsLib/src/com/android/settingslib/license/LicenseHtmlGeneratorFromXml.java
index c7eb682..aaa6dd5 100644
--- a/packages/SettingsLib/src/com/android/settingslib/license/LicenseHtmlGeneratorFromXml.java
+++ b/packages/SettingsLib/src/com/android/settingslib/license/LicenseHtmlGeneratorFromXml.java
@@ -361,10 +361,15 @@
writer.println(HTML_MIDDLE_STRING);
- count = 0;
// Prints all contents of the license files in order of id.
for (ContentIdAndFileNames contentIdAndFileNames : contentIdAndFileNamesList) {
- writer.format("<tr id=\"id%d\"><td class=\"same-license\">\n", count);
+ // Assigns an id to a newly referred license file content (should never happen here)
+ if (!contentIdToOrderMap.containsKey(contentIdAndFileNames.mContentId)) {
+ contentIdToOrderMap.put(contentIdAndFileNames.mContentId, count);
+ count++;
+ }
+ int id = contentIdToOrderMap.get(contentIdAndFileNames.mContentId);
+ writer.format("<tr id=\"id%d\"><td class=\"same-license\">\n", id);
for (Map.Entry<String, List<String>> libraryFiles :
contentIdAndFileNames.mLibraryToFileNameMap.entrySet()) {
String libraryName = libraryFiles.getKey();
@@ -379,7 +384,6 @@
writer.format("%s <br/>\n", fileName);
}
writer.println("</div><!-- file-list -->");
- count++;
}
writer.println("<pre class=\"license-text\">");
writer.println(contentIdToFileContentMap.get(
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/license/LicenseHtmlGeneratorFromXmlTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/license/LicenseHtmlGeneratorFromXmlTest.java
index 09b0d7f..7ce04f9 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/license/LicenseHtmlGeneratorFromXmlTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/license/LicenseHtmlGeneratorFromXmlTest.java
@@ -116,6 +116,7 @@
+ "<li><a href=\"#id0\">/file0 - libA</a></li>\n"
+ "<li><a href=\"#id1\">/file0 - libB</a></li>\n"
+ "<li><a href=\"#id0\">/file1 - libA</a></li>\n"
+ + "<li><a href=\"#id0\">/file2 - libC</a></li>\n"
+ "</ul>\n"
+ "</div><!-- table of contents -->\n"
+ "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n"
@@ -125,6 +126,10 @@
+ "/file0 <br/>\n"
+ "/file1 <br/>\n"
+ "</div><!-- file-list -->\n"
+ + "<div class=\"label\"><strong>libC</strong> used by:</div>\n"
+ + "<div class=\"file-list\">\n"
+ + "/file2 <br/>\n"
+ + "</div><!-- file-list -->\n"
+ "<pre class=\"license-text\">\n"
+ "license content #0\n"
+ "</pre><!-- license-text -->\n"
@@ -224,13 +229,16 @@
Map<String, String> contentIdToFileContentMap = new HashMap<>();
Map<String, Set<String>> toBoth = new HashMap<>();
Map<String, Set<String>> toOne = new HashMap<>();
+ Map<String, Set<String>> toOther = new HashMap<>();
toBoth.put("libA", new HashSet<String>(Arrays.asList("0")));
toBoth.put("libB", new HashSet<String>(Arrays.asList("1")));
toOne.put("libA", new HashSet<String>(Arrays.asList("0")));
+ toOther.put("libC", new HashSet<String>(Arrays.asList("0")));
fileNameToLibraryToContentIdMap.put("/file0", toBoth);
fileNameToLibraryToContentIdMap.put("/file1", toOne);
+ fileNameToLibraryToContentIdMap.put("/file2", toOther);
contentIdToFileContentMap.put("0", "license content #0");
contentIdToFileContentMap.put("1", "license content #1");
@@ -249,7 +257,7 @@
Map<String, Set<String>> toOne = new HashMap<>();
toBoth.put("", new HashSet<String>(Arrays.asList("0", "1")));
- toOne.put("", new HashSet<String>(Arrays.asList("0")));
+ toOne.put("", new HashSet<String>(Arrays.asList("0", "1")));
fileNameToLibraryToContentIdMap.put("/file0", toBoth);
fileNameToLibraryToContentIdMap.put("/file1", toOne);
@@ -269,13 +277,16 @@
Map<String, String> contentIdToFileContentMap = new HashMap<>();
Map<String, Set<String>> toBoth = new HashMap<>();
Map<String, Set<String>> toOne = new HashMap<>();
+ Map<String, Set<String>> toOther = new HashMap<>();
toBoth.put("libA", new HashSet<String>(Arrays.asList("0")));
toBoth.put("libB", new HashSet<String>(Arrays.asList("1")));
toOne.put("libA", new HashSet<String>(Arrays.asList("0")));
+ toOther.put("libC", new HashSet<String>(Arrays.asList("0")));
fileNameToLibraryToContentIdMap.put("/file0", toBoth);
fileNameToLibraryToContentIdMap.put("/file1", toOne);
+ fileNameToLibraryToContentIdMap.put("/file2", toOther);
contentIdToFileContentMap.put("0", "license content #0");
contentIdToFileContentMap.put("1", "license content #1");