Bug 872737 - Support distribution bookmarks from a /system location. r=mfinkle

This commit is contained in:
Margaret Leibovic 2013-05-15 15:31:27 -07:00
Родитель b0c7748743
Коммит 1824d45b21
1 изменённых файлов: 29 добавлений и 7 удалений

Просмотреть файл

@ -155,18 +155,40 @@ public final class Distribution {
InputStream inputStream = null;
try {
if (state == STATE_UNKNOWN) {
// If the distribution hasn't been set yet, get bookmarks.json out of the APK
// If the distribution hasn't been set yet, first look for bookmarks.json in the APK.
File applicationPackage = new File(context.getPackageResourcePath());
zip = new ZipFile(applicationPackage);
ZipEntry zipEntry = zip.getEntry("distribution/bookmarks.json");
if (zipEntry == null) {
return null;
if (zipEntry != null) {
inputStream = zip.getInputStream(zipEntry);
} else {
// If there's no bookmarks.json in the APK, but there is a preferences.json,
// don't create any distribution bookmarks.
zipEntry = zip.getEntry("distribution/preferences.json");
if (zipEntry != null) {
return null;
}
// Otherwise, look for bookmarks.json in the /system directory.
File systemFile = new File("/system/" + context.getPackageName() + "/distribution/bookmarks.json");
if (!systemFile.exists()) {
return null;
}
inputStream = new FileInputStream(systemFile);
}
inputStream = zip.getInputStream(zipEntry);
} else {
// Otherwise, get bookmarks.json out of the data directory
File dataDir = new File(context.getApplicationInfo().dataDir);
File file = new File(dataDir, "distribution/bookmarks.json");
// Otherwise, look for bookmarks.json in the stored distribution path,
// or in the data directory if that pref doesn't exist.
String pathKeyName = context.getPackageName() + ".distribution_path";
String distPath = settings.getString(pathKeyName, null);
File distDir = null;
if (distPath != null) {
distDir = new File(distPath);
} else {
distDir = new File(context.getApplicationInfo().dataDir, "distribution");
}
File file = new File(distDir, "bookmarks.json");
inputStream = new FileInputStream(file);
}