summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-11-18 05:15:31 +0100
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-11-18 05:15:31 +0100
commitf315c0b649e08ab0243bbcedf21bad532b7fee9b (patch)
treea371c132c47a76202958efff5a9abf16fad25bdc
parentSnap for 5132890 from b0950538c62ad29bb7b4fc842b4a4f5de8082f4b to qt-release (diff)
parentMerge "logical -> dynamic partitions." am: b22bd959e5 am: 5f16d61150 (diff)
downloadandroid_bootable_recovery-f315c0b649e08ab0243bbcedf21bad532b7fee9b.tar
android_bootable_recovery-f315c0b649e08ab0243bbcedf21bad532b7fee9b.tar.gz
android_bootable_recovery-f315c0b649e08ab0243bbcedf21bad532b7fee9b.tar.bz2
android_bootable_recovery-f315c0b649e08ab0243bbcedf21bad532b7fee9b.tar.lz
android_bootable_recovery-f315c0b649e08ab0243bbcedf21bad532b7fee9b.tar.xz
android_bootable_recovery-f315c0b649e08ab0243bbcedf21bad532b7fee9b.tar.zst
android_bootable_recovery-f315c0b649e08ab0243bbcedf21bad532b7fee9b.zip
-rw-r--r--minadbd/Android.bp1
-rw-r--r--recovery_main.cpp4
-rw-r--r--tests/component/applypatch_modes_test.cpp1
-rw-r--r--tests/component/bootloader_message_test.cpp2
-rw-r--r--tests/component/imgdiff_test.cpp1
-rw-r--r--tests/component/install_test.cpp1
-rw-r--r--tests/component/resources_test.cpp2
-rw-r--r--tests/component/sideload_test.cpp1
-rw-r--r--tests/component/uncrypt_test.cpp1
-rw-r--r--tests/component/update_verifier_test.cpp1
-rw-r--r--tests/component/updater_test.cpp1
-rw-r--r--tests/component/verifier_test.cpp1
-rw-r--r--tests/unit/applypatch_test.cpp1
-rw-r--r--tests/unit/dirutil_test.cpp2
-rw-r--r--tests/unit/parse_install_logs_test.cpp1
-rw-r--r--tests/unit/screen_ui_test.cpp2
-rw-r--r--tests/unit/sysutil_test.cpp1
-rw-r--r--tests/unit/zip_test.cpp1
-rw-r--r--tools/image_generator/ImageGenerator.java107
19 files changed, 88 insertions, 44 deletions
diff --git a/minadbd/Android.bp b/minadbd/Android.bp
index 370232b3f..7e33261eb 100644
--- a/minadbd/Android.bp
+++ b/minadbd/Android.bp
@@ -15,6 +15,7 @@
cc_defaults {
name: "minadbd_defaults",
+ cpp_std: "gnu++17",
cflags: [
"-DADB_HOST=0",
"-Wall",
diff --git a/recovery_main.cpp b/recovery_main.cpp
index 19ef4f3d0..6f5080238 100644
--- a/recovery_main.cpp
+++ b/recovery_main.cpp
@@ -365,7 +365,7 @@ int main(int argc, char** argv) {
if (option == "locale") {
locale = optarg;
} else if (option == "fastboot" &&
- android::base::GetBoolProperty("ro.boot.logical_partitions", false)) {
+ android::base::GetBoolProperty("ro.boot.dynamic_partitions", false)) {
fastboot = true;
}
break;
@@ -426,7 +426,7 @@ int main(int argc, char** argv) {
device->RemoveMenuItemForAction(Device::WIPE_CACHE);
}
- if (!android::base::GetBoolProperty("ro.boot.logical_partitions", false)) {
+ if (!android::base::GetBoolProperty("ro.boot.dynamic_partitions", false)) {
device->RemoveMenuItemForAction(Device::ENTER_FASTBOOT);
}
diff --git a/tests/component/applypatch_modes_test.cpp b/tests/component/applypatch_modes_test.cpp
index ce01f4fd5..08414b796 100644
--- a/tests/component/applypatch_modes_test.cpp
+++ b/tests/component/applypatch_modes_test.cpp
@@ -23,7 +23,6 @@
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/strings.h>
-#include <android-base/test_utils.h>
#include <bsdiff/bsdiff.h>
#include <gtest/gtest.h>
#include <openssl/sha.h>
diff --git a/tests/component/bootloader_message_test.cpp b/tests/component/bootloader_message_test.cpp
index 6cc59a495..b005d199c 100644
--- a/tests/component/bootloader_message_test.cpp
+++ b/tests/component/bootloader_message_test.cpp
@@ -17,8 +17,8 @@
#include <string>
#include <vector>
+#include <android-base/file.h>
#include <android-base/strings.h>
-#include <android-base/test_utils.h>
#include <bootloader_message/bootloader_message.h>
#include <gtest/gtest.h>
diff --git a/tests/component/imgdiff_test.cpp b/tests/component/imgdiff_test.cpp
index cb4868a4a..e76ccbdfb 100644
--- a/tests/component/imgdiff_test.cpp
+++ b/tests/component/imgdiff_test.cpp
@@ -25,7 +25,6 @@
#include <android-base/memory.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
-#include <android-base/test_utils.h>
#include <applypatch/imgdiff.h>
#include <applypatch/imgdiff_image.h>
#include <applypatch/imgpatch.h>
diff --git a/tests/component/install_test.cpp b/tests/component/install_test.cpp
index 5c6d58472..27a01cb32 100644
--- a/tests/component/install_test.cpp
+++ b/tests/component/install_test.cpp
@@ -27,7 +27,6 @@
#include <android-base/file.h>
#include <android-base/properties.h>
#include <android-base/strings.h>
-#include <android-base/test_utils.h>
#include <gtest/gtest.h>
#include <vintf/VintfObjectRecovery.h>
#include <ziparchive/zip_archive.h>
diff --git a/tests/component/resources_test.cpp b/tests/component/resources_test.cpp
index 54329db22..d7fdb8fa0 100644
--- a/tests/component/resources_test.cpp
+++ b/tests/component/resources_test.cpp
@@ -101,7 +101,7 @@ TEST_P(ResourcesTest, ValidateLocale) {
EXPECT_LT(0, len) << "Locale string should be non-empty.";
EXPECT_NE(0, row[5]) << "Locale string is missing.";
- ASSERT_GT(png_->height(), y + 1 + h) << "Locale: " << kLocale << " is not found in the file.";
+ ASSERT_GE(png_->height(), y + 1 + h) << "Locale: " << kLocale << " is not found in the file.";
char* loc = reinterpret_cast<char*>(&row[5]);
if (matches_locale(loc, kLocale.c_str())) {
EXPECT_TRUE(android::base::StartsWith(loc, kLocale));
diff --git a/tests/component/sideload_test.cpp b/tests/component/sideload_test.cpp
index b7109fcc2..d5e074c63 100644
--- a/tests/component/sideload_test.cpp
+++ b/tests/component/sideload_test.cpp
@@ -21,7 +21,6 @@
#include <android-base/file.h>
#include <android-base/strings.h>
-#include <android-base/test_utils.h>
#include <gtest/gtest.h>
#include "fuse_sideload.h"
diff --git a/tests/component/uncrypt_test.cpp b/tests/component/uncrypt_test.cpp
index 55baca2e3..e97d589a6 100644
--- a/tests/component/uncrypt_test.cpp
+++ b/tests/component/uncrypt_test.cpp
@@ -26,7 +26,6 @@
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/properties.h>
-#include <android-base/test_utils.h>
#include <android-base/unique_fd.h>
#include <bootloader_message/bootloader_message.h>
#include <gtest/gtest.h>
diff --git a/tests/component/update_verifier_test.cpp b/tests/component/update_verifier_test.cpp
index 2420c27fe..0a594037c 100644
--- a/tests/component/update_verifier_test.cpp
+++ b/tests/component/update_verifier_test.cpp
@@ -24,7 +24,6 @@
#include <android-base/file.h>
#include <android-base/properties.h>
#include <android-base/strings.h>
-#include <android-base/test_utils.h>
#include <google/protobuf/repeated_field.h>
#include <gtest/gtest.h>
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index 32fec3808..a0a7b66ab 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -33,7 +33,6 @@
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
-#include <android-base/test_utils.h>
#include <bootloader_message/bootloader_message.h>
#include <brotli/encode.h>
#include <bsdiff/bsdiff.h>
diff --git a/tests/component/verifier_test.cpp b/tests/component/verifier_test.cpp
index 480f3c96c..9fcaa0b73 100644
--- a/tests/component/verifier_test.cpp
+++ b/tests/component/verifier_test.cpp
@@ -27,7 +27,6 @@
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
-#include <android-base/test_utils.h>
#include <android-base/unique_fd.h>
#include <gtest/gtest.h>
#include <openssl/bn.h>
diff --git a/tests/unit/applypatch_test.cpp b/tests/unit/applypatch_test.cpp
index 066f981b4..794f2c103 100644
--- a/tests/unit/applypatch_test.cpp
+++ b/tests/unit/applypatch_test.cpp
@@ -32,7 +32,6 @@
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
-#include <android-base/test_utils.h>
#include <android-base/unique_fd.h>
#include <gtest/gtest.h>
diff --git a/tests/unit/dirutil_test.cpp b/tests/unit/dirutil_test.cpp
index 1ca786c28..4dd111a70 100644
--- a/tests/unit/dirutil_test.cpp
+++ b/tests/unit/dirutil_test.cpp
@@ -20,7 +20,7 @@
#include <string>
-#include <android-base/test_utils.h>
+#include <android-base/file.h>
#include <gtest/gtest.h>
#include "otautil/dirutil.h"
diff --git a/tests/unit/parse_install_logs_test.cpp b/tests/unit/parse_install_logs_test.cpp
index 8061f3be1..72169a0c6 100644
--- a/tests/unit/parse_install_logs_test.cpp
+++ b/tests/unit/parse_install_logs_test.cpp
@@ -20,7 +20,6 @@
#include <android-base/file.h>
#include <android-base/strings.h>
-#include <android-base/test_utils.h>
#include <gtest/gtest.h>
#include "otautil/parse_install_logs.h"
diff --git a/tests/unit/screen_ui_test.cpp b/tests/unit/screen_ui_test.cpp
index b780af430..09c49977f 100644
--- a/tests/unit/screen_ui_test.cpp
+++ b/tests/unit/screen_ui_test.cpp
@@ -23,9 +23,9 @@
#include <string>
#include <vector>
+#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
-#include <android-base/test_utils.h>
#include <gtest/gtest.h>
#include <gtest/gtest_prod.h>
diff --git a/tests/unit/sysutil_test.cpp b/tests/unit/sysutil_test.cpp
index de8ff7065..77625dbe9 100644
--- a/tests/unit/sysutil_test.cpp
+++ b/tests/unit/sysutil_test.cpp
@@ -17,7 +17,6 @@
#include <string>
#include <android-base/file.h>
-#include <android-base/test_utils.h>
#include <gtest/gtest.h>
#include "otautil/sysutil.h"
diff --git a/tests/unit/zip_test.cpp b/tests/unit/zip_test.cpp
index 47f33d9ea..dfe617ebe 100644
--- a/tests/unit/zip_test.cpp
+++ b/tests/unit/zip_test.cpp
@@ -21,7 +21,6 @@
#include <vector>
#include <android-base/file.h>
-#include <android-base/test_utils.h>
#include <gtest/gtest.h>
#include <ziparchive/zip_archive.h>
diff --git a/tools/image_generator/ImageGenerator.java b/tools/image_generator/ImageGenerator.java
index a011f10e4..8730945b5 100644
--- a/tools/image_generator/ImageGenerator.java
+++ b/tools/image_generator/ImageGenerator.java
@@ -60,8 +60,9 @@ public class ImageGenerator {
// This is the canvas we used to draw texts.
private BufferedImage mBufferedImage;
- // The width in pixels of our image. Once set, its value won't change.
- private final int mImageWidth;
+ // The width in pixels of our image. The value will be adjusted once when we calculate the
+ // maximum width to fit the wrapped text strings.
+ private int mImageWidth;
// The current height in pixels of our image. We will adjust the value when drawing more texts.
private int mImageHeight;
@@ -79,6 +80,9 @@ public class ImageGenerator {
// The directory that contains all the needed font files (e.g. ttf, otf, ttc files).
private final String mFontDirPath;
+ // Align the text in the center of the image.
+ private final boolean mCenterAlignment;
+
// An explicit map from language to the font name to use.
// The map is extracted from frameworks/base/data/fonts/fonts.xml.
// And the language-subtag-registry is found in:
@@ -130,7 +134,9 @@ public class ImageGenerator {
};
// Languages that breaks on arbitrary characters.
- // TODO(xunchang) switch to icu library if possible.
+ // TODO(xunchang) switch to icu library if possible. For example, for Thai and Khmer, there is
+ // no space between words; and word breaking is based on grammatical analysis and on word
+ // matching in dictionaries.
private static final Set<String> LOGOGRAM_LANGUAGE =
new HashSet<String>() {
{
@@ -138,6 +144,7 @@ public class ImageGenerator {
add("km"); // Khmer
add("ko"); // Korean
add("lo"); // Lao
+ add("th"); // Thai
add("zh"); // Chinese
}
};
@@ -154,8 +161,13 @@ public class ImageGenerator {
}
/** Initailizes the fields of the image image. */
- public ImageGenerator(int imageWidth, String textName, float fontSize, String fontDirPath) {
- mImageWidth = imageWidth;
+ public ImageGenerator(
+ int initialImageWidth,
+ String textName,
+ float fontSize,
+ String fontDirPath,
+ boolean centerAlignment) {
+ mImageWidth = initialImageWidth;
mImageHeight = INITIAL_HEIGHT;
mVerticalOffset = 0;
@@ -165,6 +177,8 @@ public class ImageGenerator {
mTextName = textName;
mFontSize = fontSize;
mFontDirPath = fontDirPath;
+
+ mCenterAlignment = centerAlignment;
}
/**
@@ -299,8 +313,6 @@ public class ImageGenerator {
List<String> wrappedText = new ArrayList<>();
StringTokenizer st = new StringTokenizer(text, " \n");
- // TODO(xunchang). We assume that all words can fit on the screen. Raise an
- // IllegalStateException if the word is wider than the image width.
StringBuilder line = new StringBuilder();
while (st.hasMoreTokens()) {
String token = st.nextToken();
@@ -373,6 +385,43 @@ public class ImageGenerator {
return info;
}
+ /** Returns Graphics2D object that uses the given locale. */
+ private Graphics2D createGraphics(Locale locale) throws IOException, FontFormatException {
+ Graphics2D graphics = mBufferedImage.createGraphics();
+ graphics.setColor(Color.WHITE);
+ graphics.setRenderingHint(
+ RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
+ graphics.setFont(loadFontsByLocale(locale.getLanguage()));
+
+ return graphics;
+ }
+
+ /** Returns the maximum screen width needed to fit the given text after wrapping. */
+ private int measureTextWidth(String text, Locale locale)
+ throws IOException, FontFormatException {
+ Graphics2D graphics = createGraphics(locale);
+ FontMetrics fontMetrics = graphics.getFontMetrics();
+ List<String> wrappedText = wrapText(text, fontMetrics, locale.getLanguage());
+
+ int textWidth = 0;
+ for (String line : wrappedText) {
+ textWidth = Math.max(textWidth, fontMetrics.stringWidth(line));
+ }
+
+ // This may happen if one single word is larger than the image width.
+ if (textWidth > mImageWidth) {
+ throw new IllegalStateException(
+ "Wrapped text width "
+ + textWidth
+ + " is larger than image width "
+ + mImageWidth
+ + " for locale: "
+ + locale);
+ }
+
+ return textWidth;
+ }
+
/**
* Draws the text string on the canvas for given locale.
*
@@ -381,16 +430,11 @@ public class ImageGenerator {
* @throws IOException if we cannot find the corresponding font file for the given locale.
* @throws FontFormatException if we failed to load the font file for the given locale.
*/
- private void drawText(String text, Locale locale, String languageTag, boolean centralAlignment)
+ private void drawText(String text, Locale locale, String languageTag)
throws IOException, FontFormatException {
- Graphics2D graphics = mBufferedImage.createGraphics();
- graphics.setColor(Color.WHITE);
- graphics.setRenderingHint(
- RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
- graphics.setFont(loadFontsByLocale(locale.getLanguage()));
-
System.out.println("Encoding \"" + locale + "\" as \"" + languageTag + "\": " + text);
+ Graphics2D graphics = createGraphics(locale);
FontMetrics fontMetrics = graphics.getFontMetrics();
List<String> wrappedText = wrapText(text, fontMetrics, locale.getLanguage());
@@ -402,7 +446,7 @@ public class ImageGenerator {
int lineHeight = fontMetrics.getHeight();
// Doubles the height of the image if we are short of space.
if (mVerticalOffset + lineHeight >= mImageHeight) {
- resizeHeight(mImageHeight * 2);
+ resize(mImageWidth, mImageHeight * 2);
}
// Draws the text at mVerticalOffset and increments the offset with line space.
@@ -410,7 +454,7 @@ public class ImageGenerator {
// Draws from right if it's an RTL language.
int x =
- centralAlignment
+ mCenterAlignment
? (mImageWidth - fontMetrics.stringWidth(line)) / 2
: RTL_LANGUAGE.contains(languageTag)
? mImageWidth - fontMetrics.stringWidth(line)
@@ -431,18 +475,19 @@ public class ImageGenerator {
}
/**
- * Redraws the image with the new height.
+ * Redraws the image with the new width and new height.
*
+ * @param width the new width of the image in pixels.
* @param height the new height of the image in pixels.
*/
- private void resizeHeight(int height) {
- BufferedImage resizedImage =
- new BufferedImage(mImageWidth, height, BufferedImage.TYPE_BYTE_GRAY);
+ private void resize(int width, int height) {
+ BufferedImage resizedImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
Graphics2D graphic = resizedImage.createGraphics();
graphic.drawImage(mBufferedImage, 0, 0, null);
graphic.dispose();
mBufferedImage = resizedImage;
+ mImageWidth = width;
mImageHeight = height;
}
@@ -458,11 +503,16 @@ public class ImageGenerator {
public void generateImage(Map<Locale, String> localizedTextMap, String outputPath)
throws FontFormatException, IOException {
Map<String, Integer> languageCount = new TreeMap<>();
+ int textWidth = 0;
for (Locale locale : localizedTextMap.keySet()) {
String language = locale.getLanguage();
languageCount.put(language, languageCount.getOrDefault(language, 0) + 1);
+ textWidth = Math.max(textWidth, measureTextWidth(localizedTextMap.get(locale), locale));
}
+ // Removes the black margins to reduce the size of the image.
+ resize(textWidth, mImageHeight);
+
for (Locale locale : localizedTextMap.keySet()) {
Integer count = languageCount.get(locale.getLanguage());
// Recovery expects en-US instead of en_US.
@@ -475,12 +525,10 @@ public class ImageGenerator {
languageCount.put(locale.getLanguage(), count - 1);
}
- drawText(localizedTextMap.get(locale), locale, languageTag, false);
+ drawText(localizedTextMap.get(locale), locale, languageTag);
}
- // TODO(xunchang) adjust the width to save some space if all texts are smaller than
- // imageWidth.
- resizeHeight(mVerticalOffset);
+ resize(mImageWidth, mVerticalOffset);
ImageIO.write(mBufferedImage, "png", new File(outputPath));
}
@@ -528,11 +576,17 @@ public class ImageGenerator {
options.addOption(
OptionBuilder.withLongOpt("output_file")
- .withDescription("Path to the generated image")
+ .withDescription("Path to the generated image.")
.hasArgs(1)
.isRequired()
.create());
+ options.addOption(
+ OptionBuilder.withLongOpt("center_alignment")
+ .withDescription("Align the text in the center of the screen.")
+ .hasArg(false)
+ .create());
+
return options;
}
@@ -557,7 +611,8 @@ public class ImageGenerator {
imageWidth,
cmd.getOptionValue("text_name"),
DEFAULT_FONT_SIZE,
- cmd.getOptionValue("font_dir"));
+ cmd.getOptionValue("font_dir"),
+ cmd.hasOption("center_alignment"));
Map<Locale, String> localizedStringMap =
imageGenerator.readLocalizedStringFromXmls(cmd.getOptionValue("resource_dir"));