Snap for 6290619 from 595041b399969b67059d842056955b25003413bd to sdk-release

Change-Id: I06fd7a444eaaca22bcc5ff49a9d2d769b122286f
diff --git a/bridge/src/libcore/icu/ICU_Delegate.java b/bridge/src/libcore/icu/ICU_Delegate.java
index 2ba7f92..fb547df 100644
--- a/bridge/src/libcore/icu/ICU_Delegate.java
+++ b/bridge/src/libcore/icu/ICU_Delegate.java
@@ -182,72 +182,6 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean initLocaleDataNative(String locale, LocaleData result) {
-
-        // Used by Calendar.
-        result.firstDayOfWeek = 1;
-        result.minimalDaysInFirstWeek = 1;
-
-        // Used by DateFormatSymbols.
-        result.amPm = new String[] { "AM", "PM" };
-        result.eras = new String[] { "BC", "AD" };
-
-        result.longMonthNames = new String[] { "January", "February", "March", "April", "May",
-                "June", "July", "August", "September", "October", "November", "December" };
-        result.shortMonthNames = new String[] { "Jan", "Feb", "Mar", "Apr", "May",
-                "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
-        result.longStandAloneMonthNames = result.longMonthNames;
-        result.shortStandAloneMonthNames = result.shortMonthNames;
-
-        // The platform code expects this to begin at index 1, rather than 0. It maps it directly to
-        // the constants from java.util.Calendar.<weekday>
-        result.longWeekdayNames = new String[] {
-                "", "Sunday", "Monday" ,"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
-        result.shortWeekdayNames = new String[] {
-                "", "Sun", "Mon" ,"Tue", "Wed", "Thu", "Fri", "Sat" };
-        result.tinyWeekdayNames = new String[] {
-                "", "S", "M", "T", "W", "T", "F", "S" };
-
-        result.longStandAloneWeekdayNames = result.longWeekdayNames;
-        result.shortStandAloneWeekdayNames = result.shortWeekdayNames;
-        result.tinyStandAloneWeekdayNames = result.tinyWeekdayNames;
-
-        result.fullTimeFormat = "";
-        result.longTimeFormat = "";
-        result.mediumTimeFormat = "";
-        result.shortTimeFormat = "";
-
-        result.fullDateFormat = "";
-        result.longDateFormat = "";
-        result.mediumDateFormat = "";
-        result.shortDateFormat = "";
-
-        // Used by DecimalFormatSymbols.
-        result.zeroDigit = '0';
-        result.decimalSeparator = '.';
-        result.groupingSeparator = ',';
-        result.patternSeparator = ' ';
-        result.percent = "%";
-        result.perMill = "\u2030";
-        result.monetarySeparator = ' ';
-        result.minusSign = "-";
-        result.exponentSeparator = "e";
-        result.infinity = "\u221E";
-        result.NaN = "NaN";
-        // Also used by Currency.
-        result.currencySymbol = "$";
-        result.internationalCurrencySymbol = "USD";
-
-        // Used by DecimalFormat and NumberFormat.
-        result.numberPattern = "%f";
-        result.integerPattern = "%d";
-        result.currencyPattern = "%s";
-        result.percentPattern = "%f";
-
-        return true;
-    }
-
-    @LayoutlibDelegate
     /*package*/ static void setDefaultLocale(String locale) {
         ICU.setDefaultLocale(locale);
     }
diff --git a/rename_font/build_font.py b/rename_font/build_font.py
index 9713a4c..db0c98a 100755
--- a/rename_font/build_font.py
+++ b/rename_font/build_font.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (C) 2014 The Android Open Source Project
 #
@@ -96,14 +96,14 @@
 
 def convert_font(input_path):
   filename = os.path.basename(input_path)
-  print 'Converting font: ' + filename
+  print('Converting font: ' + filename)
   # the path to the output file. The file name is the fontfilename.ttx
   ttx_path = os.path.join(dest_dir, filename)
   ttx_path = ttx_path[:-1] + 'x'
   try:
     # run ttx to generate an xml file in the output folder which represents all
     # its info
-    ttx_args = ['-q', '-d', dest_dir, input_path]
+    ttx_args = ['--no-recalc-timestamp', '-q', '-d', dest_dir, input_path]
     ttx.main(ttx_args)
     # now parse the xml file to change its PS name.
     tree = etree.parse(ttx_path)
@@ -116,11 +116,11 @@
     ttx.main(ttx_args)
   except InvalidFontException:
     # In case of invalid fonts, we exit.
-    print filename + ' is not a valid font'
+    print(filename + ' is not a valid font')
     raise
   except Exception as e:
-    print 'Error converting font: ' + filename
-    print e
+    print('Error converting font: ' + filename)
+    print(e)
     # Some fonts are too big to be handled by the ttx library.
     # Just copy paste them.
     shutil.copy(input_path, dest_dir)
@@ -136,7 +136,7 @@
       found in the name table of the font. """
   fonts = []
   font = None
-  last_name_id = sys.maxint
+  last_name_id = sys.maxsize
   for namerecord in tag.iter('namerecord'):
     if 'nameID' in namerecord.attrib:
       name_id = int(namerecord.attrib['nameID'])
@@ -164,14 +164,14 @@
 
 
 def update_tag(tag, fonts):
-  last_name_id = sys.maxint
+  last_name_id = sys.maxsize
   fonts_iterator = fonts.__iter__()
   font = None
   for namerecord in tag.iter('namerecord'):
     if 'nameID' in namerecord.attrib:
       name_id = int(namerecord.attrib['nameID'])
       if name_id <= last_name_id:
-        font = fonts_iterator.next()
+        font = next(fonts_iterator)
         font = update_font_name(font)
       last_name_id = name_id
       if name_id == NAMEID_FAMILY:
@@ -192,7 +192,7 @@
     new_family = font.family + font.version
   else:
     new_family = font.family
-  if font.style is 'Regular' and not font.ends_in_regular:
+  if font.style == 'Regular' and not font.ends_in_regular:
     font.fullname = new_family
   else:
     font.fullname = new_family + ' ' + font.style
@@ -205,7 +205,7 @@
       'Regular' for plain fonts. However, some fonts don't obey this rule. We
       keep the style info, to minimize the diff. """
   string = string.strip().split()[-1]
-  return string is 'Regular'
+  return string == 'Regular'
 
 
 def get_version(string):
diff --git a/rename_font/build_font_single.py b/rename_font/build_font_single.py
index 4678a4f..b254072 100755
--- a/rename_font/build_font_single.py
+++ b/rename_font/build_font_single.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (C) 2014 The Android Open Source Project
 #
@@ -62,12 +62,16 @@
 NAMEID_FULLNAME = 4
 NAMEID_VERSION = 5
 
+NAMEID_LIST = [NAMEID_FAMILY, NAMEID_STYLE, NAMEID_FULLNAME, NAMEID_VERSION]
+NAMEID_LIST_MIN = min(NAMEID_LIST)
+NAMEID_LIST_MAX = max(NAMEID_LIST)
+
 # A list of extensions to process.
 EXTENSIONS = ['.ttf', '.ttc', '.otf', '.xml']
 
 def main(argv):
   if len(argv) < 2:
-    print 'Incorrect usage: ' + str(argv)
+    print('Incorrect usage: ' + str(argv))
     sys.exit('Usage: build_font_single.py /path/to/input/font.ttf /path/to/out/font.ttf')
   dest_path = argv[-1]
   input_path = argv[0]
@@ -81,13 +85,13 @@
 
 def convert_font(input_path, dest_path):
   filename = os.path.basename(input_path)
-  print 'Converting font: ' + filename
+  print('Converting font: ' + filename)
   # the path to the output file. The file name is the fontfilename.ttx
   ttx_path = dest_path[:-1] + 'x'
   try:
     # run ttx to generate an xml file in the output folder which represents all
     # its info
-    ttx_args = ['-q', '-o', ttx_path, input_path]
+    ttx_args = ['--no-recalc-timestamp', '-q', '-o', ttx_path, input_path]
     ttx.main(ttx_args)
     # now parse the xml file to change its PS name.
     tree = etree.parse(ttx_path)
@@ -99,12 +103,12 @@
     ttx_args = ['-q', '-o', dest_path, ttx_path]
     ttx.main(ttx_args)
   except InvalidFontException:
-    # In case of invalid fonts, we exit.
-    print filename + ' is not a valid font'
-    raise
+    # assume, like for .ttc and .otf that font might be valid, but warn.
+    print('Family and/or Style nameIDs not found in '+ filename)
+    shutil.copy(input_path, dest_path)
   except Exception as e:
-    print 'Error converting font: ' + filename
-    print e
+    print('Error converting font: ' + filename)
+    print(e)
     # Some fonts are too big to be handled by the ttx library.
     # Just copy paste them.
     shutil.copy(input_path, dest_path)
@@ -120,10 +124,13 @@
       found in the name table of the font. """
   fonts = []
   font = None
-  last_name_id = sys.maxint
+  last_name_id = sys.maxsize
   for namerecord in tag.iter('namerecord'):
     if 'nameID' in namerecord.attrib:
       name_id = int(namerecord.attrib['nameID'])
+      # skip irrelevant records
+      if name_id < NAMEID_LIST_MIN or name_id > NAMEID_LIST_MAX:
+        continue
       # A new font should be created for each platform, encoding and language
       # id. But, since the nameIDs are sorted, we use the easy approach of
       # creating a new one when the nameIDs reset.
@@ -148,14 +155,17 @@
 
 
 def update_tag(tag, fonts):
-  last_name_id = sys.maxint
+  last_name_id = sys.maxsize
   fonts_iterator = fonts.__iter__()
   font = None
   for namerecord in tag.iter('namerecord'):
     if 'nameID' in namerecord.attrib:
       name_id = int(namerecord.attrib['nameID'])
+      # skip irrelevant records
+      if name_id < NAMEID_LIST_MIN or name_id > NAMEID_LIST_MAX:
+        continue
       if name_id <= last_name_id:
-        font = fonts_iterator.next()
+        font = next(fonts_iterator)
         font = update_font_name(font)
       last_name_id = name_id
       if name_id == NAMEID_FAMILY:
@@ -176,7 +186,7 @@
     new_family = font.family + font.version
   else:
     new_family = font.family
-  if font.style is 'Regular' and not font.ends_in_regular:
+  if font.style == 'Regular' and not font.ends_in_regular:
     font.fullname = new_family
   else:
     font.fullname = new_family + ' ' + font.style
@@ -189,7 +199,7 @@
       'Regular' for plain fonts. However, some fonts don't obey this rule. We
       keep the style info, to minimize the diff. """
   string = string.strip().split()[-1]
-  return string is 'Regular'
+  return string == 'Regular'
 
 
 def get_version(string):
diff --git a/rename_font/test.py b/rename_font/test.py
index 2ffddf4..cf26ee9 100755
--- a/rename_font/test.py
+++ b/rename_font/test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 """Tests build_font.py by renaming a font.
 
@@ -22,10 +22,10 @@
   def test(self):
     font_name = "Roboto-Regular.ttf"
     srcdir = tempfile.mkdtemp()
-    print "srcdir: " + srcdir
+    print("srcdir: " + srcdir)
     shutil.copy(font_name, srcdir)
     destdir = tempfile.mkdtemp()
-    print "destdir: " + destdir
+    print("destdir: " + destdir)
     self.assertTrue(build_font.main([srcdir, destdir]) is None)
     out_path = os.path.join(destdir, font_name)
     ttx.main([out_path])