Bug 731341 - LoadLibs should take a context. r=blassey

This commit is contained in:
Wes Johnston 2012-03-08 10:25:44 -08:00
parent e6b5d5e506
commit 7648bbecb7
5 changed files with 103 additions and 73 deletions

View File

@ -121,7 +121,6 @@ abstract public class GeckoApp
public static SurfaceView cameraView;
public static GeckoApp mAppContext;
public static boolean mDOMFullScreen = false;
public static File sGREDir = null;
public static Menu sMenu;
private static GeckoThread sGeckoThread = null;
public GeckoAppHandler mMainHandler;
@ -1616,7 +1615,7 @@ abstract public class GeckoApp
enableStrictMode();
}
System.loadLibrary("mozglue");
GeckoAppShell.loadMozGlue();
mMainHandler = new GeckoAppHandler();
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onCreate");
if (savedInstanceState != null) {
@ -1687,9 +1686,6 @@ abstract public class GeckoApp
mBrowserToolbar.updateTabCount(1);
}
if (sGREDir == null)
sGREDir = new File(this.getApplicationInfo().dataDir);
Uri data = intent.getData();
if (data != null && "http".equals(data.getScheme()) &&
isHostOnPrefetchWhitelist(data.getHost())) {
@ -2513,7 +2509,7 @@ abstract public class GeckoApp
fileExt = name.substring(period);
fileName = name.substring(0, period);
}
File file = File.createTempFile(fileName, fileExt, sGREDir);
File file = File.createTempFile(fileName, fileExt, GeckoAppShell.getGREDir(GeckoApp.mAppContext));
FileOutputStream fos = new FileOutputStream(file);
InputStream is = cr.openInputStream(uri);

View File

@ -112,6 +112,8 @@ public class GeckoAppShell
static File sHomeDir = null;
static private int sDensityDpi = 0;
private static Boolean sSQLiteLibsLoaded = false;
private static Boolean sLibsSetup = false;
private static File sGREDir = null;
private static HashMap<String, ArrayList<GeckoEventListener>> mEventListeners;
@ -212,16 +214,16 @@ public class GeckoAppShell
return GeckoBackgroundThread.getHandler();
}
public static File getCacheDir() {
public static File getCacheDir(Context context) {
if (sCacheFile == null)
sCacheFile = GeckoApp.mAppContext.getCacheDir();
sCacheFile = context.getCacheDir();
return sCacheFile;
}
public static long getFreeSpace() {
public static long getFreeSpace(Context context) {
try {
if (sFreeSpace == -1) {
File cacheDir = getCacheDir();
File cacheDir = getCacheDir(context);
if (cacheDir != null) {
StatFs cacheStats = new StatFs(cacheDir.getPath());
sFreeSpace = cacheStats.getFreeBlocks() *
@ -236,17 +238,46 @@ public class GeckoAppShell
return sFreeSpace;
}
public static File getGREDir(Context context) {
if (sGREDir == null)
sGREDir = new File(context.getApplicationInfo().dataDir);
return sGREDir;
}
// java-side stuff
public static boolean loadLibsSetup(String apkName) {
public static void loadLibsSetup(Context context) {
if (sLibsSetup)
return;
// The package data lib directory isn't placed in ld.so's
// search path, so we have to manually load libraries that
// libxul will depend on. Not ideal.
GeckoApp geckoApp = GeckoApp.mAppContext;
GeckoProfile profile = geckoApp.getProfile();
profile.moveProfilesToAppInstallLocation();
GeckoProfile profile = GeckoProfile.get(context);
File cacheFile = getCacheDir(context);
putenv("GRE_HOME=" + getGREDir(context).getPath());
File[] files = cacheFile.listFiles();
if (files != null) {
Iterator<File> cacheFiles = Arrays.asList(files).iterator();
while (cacheFiles.hasNext()) {
File libFile = cacheFiles.next();
if (libFile.getName().endsWith(".so"))
libFile.delete();
}
}
// setup the libs cache
String linkerCache = System.getenv("MOZ_LINKER_CACHE");
if (System.getenv("MOZ_LINKER_CACHE") == null) {
GeckoAppShell.putenv("MOZ_LINKER_CACHE=" + cacheFile.getPath());
}
sLibsSetup = true;
}
private static void setupPluginEnvironment(GeckoApp context) {
// setup plugin path directories
try {
String[] dirs = GeckoApp.mAppContext.getPluginDirectories();
String[] dirs = context.getPluginDirectories();
StringBuffer pluginSearchPath = new StringBuffer();
for (int i = 0; i < dirs.length; i++) {
Log.i(LOGTAG, "dir: " + dirs[i]);
@ -254,49 +285,22 @@ public class GeckoAppShell
pluginSearchPath.append(":");
}
GeckoAppShell.putenv("MOZ_PLUGIN_PATH="+pluginSearchPath);
File pluginDataDir = context.getDir("plugins", 0);
GeckoAppShell.putenv("ANDROID_PLUGIN_DATADIR=" + pluginDataDir.getPath());
} catch (Exception ex) {
Log.i(LOGTAG, "exception getting plugin dirs", ex);
}
}
GeckoAppShell.putenv("HOME=" + profile.getFilesDir().getPath());
GeckoAppShell.putenv("GRE_HOME=" + GeckoApp.sGREDir.getPath());
Intent i = geckoApp.getIntent();
String env = i.getStringExtra("env0");
Log.i(LOGTAG, "env0: "+ env);
for (int c = 1; env != null; c++) {
GeckoAppShell.putenv(env);
env = i.getStringExtra("env" + c);
Log.i(LOGTAG, "env"+ c +": "+ env);
}
File f = geckoApp.getDir("tmp", Context.MODE_WORLD_READABLE |
Context.MODE_WORLD_WRITEABLE );
if (!f.exists())
f.mkdirs();
GeckoAppShell.putenv("TMPDIR=" + f.getPath());
f = Environment.getDownloadCacheDirectory();
GeckoAppShell.putenv("EXTERNAL_STORAGE=" + f.getPath());
File cacheFile = getCacheDir();
String linkerCache = System.getenv("MOZ_LINKER_CACHE");
if (System.getenv("MOZ_LINKER_CACHE") == null) {
GeckoAppShell.putenv("MOZ_LINKER_CACHE=" + cacheFile.getPath());
}
File pluginDataDir = GeckoApp.mAppContext.getDir("plugins", 0);
GeckoAppShell.putenv("ANDROID_PLUGIN_DATADIR=" + pluginDataDir.getPath());
// gingerbread introduces File.getUsableSpace(). We should use that.
long freeSpace = getFreeSpace();
private static void setupDownloadEnvironment(GeckoApp context) {
try {
File downloadDir = null;
File updatesDir = null;
if (Build.VERSION.SDK_INT >= 8) {
downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
updatesDir = GeckoApp.mAppContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
updatesDir = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
} else {
updatesDir = downloadDir = new File(Environment.getExternalStorageDirectory().getPath(), "download");
}
@ -306,38 +310,63 @@ public class GeckoAppShell
catch (Exception e) {
Log.i(LOGTAG, "No download directory has been found: " + e);
}
putLocaleEnv();
boolean extractLibs = GeckoApp.ACTION_DEBUG.equals(i.getAction());
if (!extractLibs) {
// remove any previously extracted libs
File[] files = cacheFile.listFiles();
if (files != null) {
Iterator<File> cacheFiles = Arrays.asList(files).iterator();
while (cacheFiles.hasNext()) {
File libFile = cacheFiles.next();
if (libFile.getName().endsWith(".so"))
libFile.delete();
}
}
}
return extractLibs;
}
public static void ensureSQLiteLibsLoaded(String apkName) {
public static void setupGeckoEnvironment(Context context) {
GeckoProfile profile = GeckoProfile.get(context);
profile.moveProfilesToAppInstallLocation();
setupPluginEnvironment((GeckoApp) context);
setupDownloadEnvironment((GeckoApp) context);
// profile home path
GeckoAppShell.putenv("HOME=" + profile.getFilesDir().getPath());
Intent i = null;
i = ((Activity)context).getIntent();
// if we have an intent (we're being launched by an activity)
// read in any environmental variables from it here
String env = i.getStringExtra("env0");
Log.i(LOGTAG, "env0: "+ env);
for (int c = 1; env != null; c++) {
GeckoAppShell.putenv(env);
env = i.getStringExtra("env" + c);
Log.i(LOGTAG, "env"+ c +": "+ env);
}
// setup the tmp path
File f = context.getDir("tmp", Context.MODE_WORLD_READABLE |
Context.MODE_WORLD_WRITEABLE );
if (!f.exists())
f.mkdirs();
GeckoAppShell.putenv("TMPDIR=" + f.getPath());
// setup the downloads path
f = Environment.getDownloadCacheDirectory();
GeckoAppShell.putenv("EXTERNAL_STORAGE=" + f.getPath());
putLocaleEnv();
}
public static void loadSQLiteLibs(Context context, String apkName) {
if (sSQLiteLibsLoaded)
return;
synchronized(sSQLiteLibsLoaded) {
if (sSQLiteLibsLoaded)
return;
loadSQLiteLibsNative(apkName, loadLibsSetup(apkName));
loadMozGlue();
// the extract libs parameter is being removed in bug 732069
loadSQLiteLibsNative(apkName, false);
sSQLiteLibsLoaded = true;
}
}
public static void loadMozGlue() {
System.loadLibrary("mozglue");
}
public static void loadGeckoLibs(String apkName) {
boolean extractLibs = loadLibsSetup(apkName);
loadLibsSetup(GeckoApp.mAppContext);
loadGeckoLibsNative(apkName);
}

View File

@ -66,7 +66,7 @@ public class GeckoThread extends Thread {
public void run() {
final GeckoApp app = GeckoApp.mAppContext;
File cacheFile = GeckoAppShell.getCacheDir();
File cacheFile = GeckoAppShell.getCacheDir(app);
File libxulFile = new File(cacheFile, "libxul.so");
if ((!libxulFile.exists() ||
@ -86,9 +86,12 @@ public class GeckoThread extends Thread {
// At some point while loading the gecko libs our default locale gets set
// so just save it to locale here and reset it as default after the join
Locale locale = Locale.getDefault();
String resourcePath = app.getApplication().getPackageResourcePath();
GeckoAppShell.ensureSQLiteLibsLoaded(resourcePath);
GeckoAppShell.setupGeckoEnvironment(app);
GeckoAppShell.loadSQLiteLibs(app, resourcePath);
GeckoAppShell.loadGeckoLibs(resourcePath);
Locale.setDefault(locale);
Resources res = app.getBaseContext().getResources();
Configuration config = res.getConfiguration();

View File

@ -640,7 +640,7 @@ public class ProfileMigrator {
File dbFileShm = new File(dbPathShm);
SQLiteBridge db = null;
GeckoAppShell.ensureSQLiteLibsLoaded(GeckoApp.mAppContext.getApplication().getPackageResourcePath());
GeckoAppShell.loadSQLiteLibs(GeckoApp.mAppContext, GeckoApp.mAppContext.getApplication().getPackageResourcePath());
try {
db = new SQLiteBridge(dbPath);
calculateReroot(db);
@ -664,7 +664,7 @@ public class ProfileMigrator {
}
protected void cleanupXULLibCache() {
File cacheFile = GeckoAppShell.getCacheDir();
File cacheFile = GeckoAppShell.getCacheDir(GeckoApp.mAppContext);
File[] files = cacheFile.listFiles();
if (files != null) {
Iterator<File> cacheFiles = Arrays.asList(files).iterator();

View File

@ -88,6 +88,8 @@ public abstract class GeckoProvider extends ContentProvider {
boolean dbNeedsSetup = true;
try {
String resourcePath = context.getPackageResourcePath();
GeckoAppShell.loadSQLiteLibs(context, resourcePath);
bridge = new SQLiteBridge(databasePath);
int version = bridge.getVersion();
Log.i(mLogTag, version + " == " + mDBVersion);