Merge "Use currentTimeMillis instead of epoch seconds" into sc-dev
This commit is contained in:
@@ -172,7 +172,7 @@ public class Typeface {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
public long native_instance;
|
public final long native_instance;
|
||||||
|
|
||||||
private Runnable mCleaner;
|
private Runnable mCleaner;
|
||||||
|
|
||||||
@@ -207,6 +207,7 @@ public class Typeface {
|
|||||||
private static final int STYLE_NORMAL = 0;
|
private static final int STYLE_NORMAL = 0;
|
||||||
private static final int STYLE_ITALIC = 1;
|
private static final int STYLE_ITALIC = 1;
|
||||||
|
|
||||||
|
@GuardedBy("this")
|
||||||
private int[] mSupportedAxes;
|
private int[] mSupportedAxes;
|
||||||
private static final int[] EMPTY_AXES = {};
|
private static final int[] EMPTY_AXES = {};
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import java.util.Set;
|
|||||||
private static final String ATTR_VALUE = "value";
|
private static final String ATTR_VALUE = "value";
|
||||||
|
|
||||||
/* package */ static class Config {
|
/* package */ static class Config {
|
||||||
public long lastModifiedDate;
|
public long lastModifiedMillis;
|
||||||
public final Set<String> updatedFontDirs = new ArraySet<>();
|
public final Set<String> updatedFontDirs = new ArraySet<>();
|
||||||
public final List<FontConfig.FontFamily> fontFamilies = new ArrayList<>();
|
public final List<FontConfig.FontFamily> fontFamilies = new ArrayList<>();
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ import java.util.Set;
|
|||||||
} else if (depth == 2) {
|
} else if (depth == 2) {
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case TAG_LAST_MODIFIED_DATE:
|
case TAG_LAST_MODIFIED_DATE:
|
||||||
out.lastModifiedDate = parseLongAttribute(parser, ATTR_VALUE, 0);
|
out.lastModifiedMillis = parseLongAttribute(parser, ATTR_VALUE, 0);
|
||||||
break;
|
break;
|
||||||
case TAG_UPDATED_FONT_DIR:
|
case TAG_UPDATED_FONT_DIR:
|
||||||
out.updatedFontDirs.add(getAttribute(parser, ATTR_VALUE));
|
out.updatedFontDirs.add(getAttribute(parser, ATTR_VALUE));
|
||||||
@@ -101,7 +101,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
out.startTag(null, TAG_ROOT);
|
out.startTag(null, TAG_ROOT);
|
||||||
out.startTag(null, TAG_LAST_MODIFIED_DATE);
|
out.startTag(null, TAG_LAST_MODIFIED_DATE);
|
||||||
out.attribute(null, ATTR_VALUE, Long.toString(config.lastModifiedDate));
|
out.attribute(null, ATTR_VALUE, Long.toString(config.lastModifiedMillis));
|
||||||
out.endTag(null, TAG_LAST_MODIFIED_DATE);
|
out.endTag(null, TAG_LAST_MODIFIED_DATE);
|
||||||
for (String dir : config.updatedFontDirs) {
|
for (String dir : config.updatedFontDirs) {
|
||||||
out.startTag(null, TAG_UPDATED_FONT_DIR);
|
out.startTag(null, TAG_UPDATED_FONT_DIR);
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ final class UpdatableFontDir {
|
|||||||
private final File mConfigFile;
|
private final File mConfigFile;
|
||||||
private final File mTmpConfigFile;
|
private final File mTmpConfigFile;
|
||||||
|
|
||||||
private long mLastModifiedDate;
|
private long mLastModifiedMillis;
|
||||||
private int mConfigVersion = 1;
|
private int mConfigVersion = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,7 +147,7 @@ final class UpdatableFontDir {
|
|||||||
/* package */ void loadFontFileMap() {
|
/* package */ void loadFontFileMap() {
|
||||||
mFontFileInfoMap.clear();
|
mFontFileInfoMap.clear();
|
||||||
mFontFamilyMap.clear();
|
mFontFamilyMap.clear();
|
||||||
mLastModifiedDate = 0;
|
mLastModifiedMillis = 0;
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config();
|
PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config();
|
||||||
@@ -157,7 +157,7 @@ final class UpdatableFontDir {
|
|||||||
Slog.e(TAG, "Failed to load config xml file", e);
|
Slog.e(TAG, "Failed to load config xml file", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mLastModifiedDate = config.lastModifiedDate;
|
mLastModifiedMillis = config.lastModifiedMillis;
|
||||||
|
|
||||||
File[] dirs = mFilesDir.listFiles();
|
File[] dirs = mFilesDir.listFiles();
|
||||||
if (dirs == null) return;
|
if (dirs == null) return;
|
||||||
@@ -200,7 +200,7 @@ final class UpdatableFontDir {
|
|||||||
if (!success) {
|
if (!success) {
|
||||||
mFontFileInfoMap.clear();
|
mFontFileInfoMap.clear();
|
||||||
mFontFamilyMap.clear();
|
mFontFamilyMap.clear();
|
||||||
mLastModifiedDate = 0;
|
mLastModifiedMillis = 0;
|
||||||
FileUtils.deleteContents(mFilesDir);
|
FileUtils.deleteContents(mFilesDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,7 +211,7 @@ final class UpdatableFontDir {
|
|||||||
FileUtils.deleteContents(mFilesDir);
|
FileUtils.deleteContents(mFilesDir);
|
||||||
mFontFamilyMap.clear();
|
mFontFamilyMap.clear();
|
||||||
|
|
||||||
mLastModifiedDate = Instant.now().getEpochSecond();
|
mLastModifiedMillis = System.currentTimeMillis();
|
||||||
try (FileOutputStream fos = new FileOutputStream(mConfigFile)) {
|
try (FileOutputStream fos = new FileOutputStream(mConfigFile)) {
|
||||||
PersistentSystemFontConfig.writeToXml(fos, createPersistentConfig());
|
PersistentSystemFontConfig.writeToXml(fos, createPersistentConfig());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -231,7 +231,7 @@ final class UpdatableFontDir {
|
|||||||
// Backup the mapping for rollback.
|
// Backup the mapping for rollback.
|
||||||
ArrayMap<String, FontFileInfo> backupMap = new ArrayMap<>(mFontFileInfoMap);
|
ArrayMap<String, FontFileInfo> backupMap = new ArrayMap<>(mFontFileInfoMap);
|
||||||
ArrayMap<String, FontConfig.FontFamily> backupFamilies = new ArrayMap<>(mFontFamilyMap);
|
ArrayMap<String, FontConfig.FontFamily> backupFamilies = new ArrayMap<>(mFontFamilyMap);
|
||||||
long backupLastModifiedDate = mLastModifiedDate;
|
long backupLastModifiedDate = mLastModifiedMillis;
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
for (FontUpdateRequest request : requests) {
|
for (FontUpdateRequest request : requests) {
|
||||||
@@ -247,7 +247,7 @@ final class UpdatableFontDir {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write config file.
|
// Write config file.
|
||||||
mLastModifiedDate = Instant.now().getEpochSecond();
|
mLastModifiedMillis = Instant.now().getEpochSecond();
|
||||||
try (FileOutputStream fos = new FileOutputStream(mTmpConfigFile)) {
|
try (FileOutputStream fos = new FileOutputStream(mTmpConfigFile)) {
|
||||||
PersistentSystemFontConfig.writeToXml(fos, createPersistentConfig());
|
PersistentSystemFontConfig.writeToXml(fos, createPersistentConfig());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -269,7 +269,7 @@ final class UpdatableFontDir {
|
|||||||
mFontFileInfoMap.putAll(backupMap);
|
mFontFileInfoMap.putAll(backupMap);
|
||||||
mFontFamilyMap.clear();
|
mFontFamilyMap.clear();
|
||||||
mFontFamilyMap.putAll(backupFamilies);
|
mFontFamilyMap.putAll(backupFamilies);
|
||||||
mLastModifiedDate = backupLastModifiedDate;
|
mLastModifiedMillis = backupLastModifiedDate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -527,7 +527,7 @@ final class UpdatableFontDir {
|
|||||||
|
|
||||||
private PersistentSystemFontConfig.Config createPersistentConfig() {
|
private PersistentSystemFontConfig.Config createPersistentConfig() {
|
||||||
PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config();
|
PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config();
|
||||||
config.lastModifiedDate = mLastModifiedDate;
|
config.lastModifiedMillis = mLastModifiedMillis;
|
||||||
for (FontFileInfo info : mFontFileInfoMap.values()) {
|
for (FontFileInfo info : mFontFileInfoMap.values()) {
|
||||||
config.updatedFontDirs.add(info.getRandomizedFontDir().getName());
|
config.updatedFontDirs.add(info.getRandomizedFontDir().getName());
|
||||||
}
|
}
|
||||||
@@ -560,7 +560,7 @@ final class UpdatableFontDir {
|
|||||||
// which will be used as a fallback font without being overridden.
|
// which will be used as a fallback font without being overridden.
|
||||||
mergedFamilies.addAll(mFontFamilyMap.values());
|
mergedFamilies.addAll(mFontFamilyMap.values());
|
||||||
return new FontConfig(
|
return new FontConfig(
|
||||||
mergedFamilies, config.getAliases(), mLastModifiedDate, mConfigVersion);
|
mergedFamilies, config.getAliases(), mLastModifiedMillis, mConfigVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ int getConfigVersion() {
|
/* package */ int getConfigVersion() {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public final class PersistentSystemFontConfigTest {
|
|||||||
public void testWriteRead() throws Exception {
|
public void testWriteRead() throws Exception {
|
||||||
long expectedModifiedDate = 1234567890;
|
long expectedModifiedDate = 1234567890;
|
||||||
PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config();
|
PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config();
|
||||||
config.lastModifiedDate = expectedModifiedDate;
|
config.lastModifiedMillis = expectedModifiedDate;
|
||||||
config.updatedFontDirs.add("~~abc");
|
config.updatedFontDirs.add("~~abc");
|
||||||
config.updatedFontDirs.add("~~def");
|
config.updatedFontDirs.add("~~def");
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ public final class PersistentSystemFontConfigTest {
|
|||||||
PersistentSystemFontConfig.Config another = new PersistentSystemFontConfig.Config();
|
PersistentSystemFontConfig.Config another = new PersistentSystemFontConfig.Config();
|
||||||
PersistentSystemFontConfig.loadFromXml(bais, another);
|
PersistentSystemFontConfig.loadFromXml(bais, another);
|
||||||
|
|
||||||
assertThat(another.lastModifiedDate).isEqualTo(expectedModifiedDate);
|
assertThat(another.lastModifiedMillis).isEqualTo(expectedModifiedDate);
|
||||||
assertThat(another.updatedFontDirs).containsExactly("~~abc", "~~def");
|
assertThat(another.updatedFontDirs).containsExactly("~~abc", "~~def");
|
||||||
assertThat(another.fontFamilies).containsExactly(fontFamily);
|
assertThat(another.fontFamilies).containsExactly(fontFamily);
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ public final class PersistentSystemFontConfigTest {
|
|||||||
new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))) {
|
new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))) {
|
||||||
PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config();
|
PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config();
|
||||||
PersistentSystemFontConfig.loadFromXml(bais, config);
|
PersistentSystemFontConfig.loadFromXml(bais, config);
|
||||||
assertThat(config.lastModifiedDate).isEqualTo(0);
|
assertThat(config.lastModifiedMillis).isEqualTo(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config();
|
PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config();
|
||||||
config.lastModifiedDate = expectedModifiedDate;
|
config.lastModifiedMillis = expectedModifiedDate;
|
||||||
writeConfig(config, mConfigFile);
|
writeConfig(config, mConfigFile);
|
||||||
UpdatableFontDir dirForPreparation = new UpdatableFontDir(
|
UpdatableFontDir dirForPreparation = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
||||||
@@ -507,7 +507,7 @@ public final class UpdatableFontDirTest {
|
|||||||
File readonlyFile = new File(readonlyDir, "readonly_config.xml");
|
File readonlyFile = new File(readonlyDir, "readonly_config.xml");
|
||||||
|
|
||||||
PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config();
|
PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config();
|
||||||
config.lastModifiedDate = expectedModifiedDate;
|
config.lastModifiedMillis = expectedModifiedDate;
|
||||||
writeConfig(config, readonlyFile);
|
writeConfig(config, readonlyFile);
|
||||||
|
|
||||||
assertThat(readonlyDir.setWritable(false, false)).isTrue();
|
assertThat(readonlyDir.setWritable(false, false)).isTrue();
|
||||||
|
|||||||
Reference in New Issue
Block a user