summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/BrowserActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/browser/BrowserActivity.java')
-rw-r--r--src/com/android/browser/BrowserActivity.java366
1 files changed, 0 insertions, 366 deletions
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 5c2764b..244a903 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -274,371 +274,6 @@ public class BrowserActivity extends Activity
mGlsConnection, Context.BIND_AUTO_CREATE);
}
- /**
- * This class is in charge of installing pre-packaged plugins
- * from the Browser assets directory to the user's data partition.
- * Plugins are loaded from the "plugins" directory in the assets;
- * Anything that is in this directory will be copied over to the
- * user data partition in app_plugins.
- */
- private static class CopyPlugins implements Runnable {
- final static String TAG = "PluginsInstaller";
- final static String ZIP_FILTER = "assets/plugins/";
- final static String APK_PATH = "/system/app/Browser.apk";
- final static String PLUGIN_EXTENSION = ".so";
- final static String TEMPORARY_EXTENSION = "_temp";
- final static String BUILD_INFOS_FILE = "build.prop";
- final static String SYSTEM_BUILD_INFOS_FILE = "/system/"
- + BUILD_INFOS_FILE;
- final static int BUFSIZE = 4096;
- boolean mDoOverwrite = false;
- String pluginsPath;
- Context mContext;
-
- public CopyPlugins (boolean overwrite, Context context) {
- mDoOverwrite = overwrite;
- mContext = context;
- }
-
- /**
- * Returned a filtered list of ZipEntry.
- * We list all the files contained in the zip and
- * only returns the ones starting with the ZIP_FILTER
- * path.
- *
- * @param zip the zip file used.
- */
- public Vector<ZipEntry> pluginsFilesFromZip(ZipFile zip) {
- Vector<ZipEntry> list = new Vector<ZipEntry>();
- Enumeration entries = zip.entries();
- while (entries.hasMoreElements()) {
- ZipEntry entry = (ZipEntry) entries.nextElement();
- if (entry.getName().startsWith(ZIP_FILTER)) {
- list.add(entry);
- }
- }
- return list;
- }
-
- /**
- * Utility method to copy the content from an inputstream
- * to a file output stream.
- */
- public void copyStreams(InputStream is, FileOutputStream fos) {
- BufferedOutputStream os = null;
- try {
- byte data[] = new byte[BUFSIZE];
- int count;
- os = new BufferedOutputStream(fos, BUFSIZE);
- while ((count = is.read(data, 0, BUFSIZE)) != -1) {
- os.write(data, 0, count);
- }
- os.flush();
- } catch (IOException e) {
- Log.e(TAG, "Exception while copying: " + e);
- } finally {
- try {
- if (os != null) {
- os.close();
- }
- } catch (IOException e2) {
- Log.e(TAG, "Exception while closing the stream: " + e2);
- }
- }
- }
-
- /**
- * Returns a string containing the contents of a file
- *
- * @param file the target file
- */
- private String contentsOfFile(File file) {
- String ret = null;
- FileInputStream is = null;
- try {
- byte[] buffer = new byte[BUFSIZE];
- int count;
- is = new FileInputStream(file);
- StringBuffer out = new StringBuffer();
-
- while ((count = is.read(buffer, 0, BUFSIZE)) != -1) {
- out.append(new String(buffer, 0, count));
- }
- ret = out.toString();
- } catch (IOException e) {
- Log.e(TAG, "Exception getting contents of file " + e);
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e2) {
- Log.e(TAG, "Exception while closing the file: " + e2);
- }
- }
- }
- return ret;
- }
-
- /**
- * Utility method to initialize the user data plugins path.
- */
- public void initPluginsPath() {
- BrowserSettings s = BrowserSettings.getInstance();
- pluginsPath = s.getPluginsPath();
- if (pluginsPath == null) {
- s.loadFromDb(mContext);
- pluginsPath = s.getPluginsPath();
- }
- if (LOGV_ENABLED) {
- Log.v(TAG, "Plugin path: " + pluginsPath);
- }
- }
-
- /**
- * Utility method to delete a file or a directory
- *
- * @param file the File to delete
- */
- public void deleteFile(File file) {
- File[] files = file.listFiles();
- if ((files != null) && files.length > 0) {
- for (int i=0; i< files.length; i++) {
- deleteFile(files[i]);
- }
- }
- if (!file.delete()) {
- Log.e(TAG, file.getPath() + " could not get deleted");
- }
- }
-
- /**
- * Clean the content of the plugins directory.
- * We delete the directory, then recreate it.
- */
- public void cleanPluginsDirectory() {
- if (LOGV_ENABLED) {
- Log.v(TAG, "delete plugins directory: " + pluginsPath);
- }
- File pluginsDirectory = new File(pluginsPath);
- deleteFile(pluginsDirectory);
- pluginsDirectory.mkdir();
- }
-
-
- /**
- * Copy the SYSTEM_BUILD_INFOS_FILE file containing the
- * informations about the system build to the
- * BUILD_INFOS_FILE in the plugins directory.
- */
- public void copyBuildInfos() {
- FileInputStream iStream = null;
- FileOutputStream oStream = null;
- try {
- if (LOGV_ENABLED) {
- Log.v(TAG, "Copy build infos to the plugins directory");
- }
- File buildInfoFile = new File(SYSTEM_BUILD_INFOS_FILE);
- File buildInfoPlugins = new File(pluginsPath, BUILD_INFOS_FILE);
- iStream = new FileInputStream(buildInfoFile);
- oStream = new FileOutputStream(buildInfoPlugins);
- copyStreams(iStream, oStream);
- } catch (IOException e) {
- Log.e(TAG, "Exception while copying the build infos: " + e);
- } finally {
- try {
- if (iStream != null) {
- iStream.close();
- }
- } catch (IOException e2) {
- Log.e(TAG, "Exception while closing the input stream: " + e2);
- }
- try {
- if (oStream != null) {
- oStream.close();
- }
- } catch (IOException e3) {
- Log.e(TAG, "Exception while closing the output stream: " + e3);
- }
- }
- }
-
- /**
- * Returns true if the current system is newer than the
- * system that installed the plugins.
- * We determinate this by checking the build number of the system.
- *
- * At the end of the plugins copy operation, we copy the
- * SYSTEM_BUILD_INFOS_FILE to the BUILD_INFOS_FILE.
- * We then just have to load both and compare them -- if they
- * are different the current system is newer.
- *
- * Loading and comparing the strings should be faster than
- * creating a hash, the files being rather small. Extracting the
- * version number would require some parsing which may be more
- * brittle.
- */
- public boolean newSystemImage() {
- try {
- File buildInfoFile = new File(SYSTEM_BUILD_INFOS_FILE);
- File buildInfoPlugins = new File(pluginsPath, BUILD_INFOS_FILE);
- if (!buildInfoPlugins.exists()) {
- if (LOGV_ENABLED) {
- Log.v(TAG, "build.prop in plugins directory " + pluginsPath
- + " does not exist, therefore it's a new system image");
- }
- return true;
- } else {
- String buildInfo = contentsOfFile(buildInfoFile);
- String buildInfoPlugin = contentsOfFile(buildInfoPlugins);
- if (buildInfo == null || buildInfoPlugin == null
- || buildInfo.compareTo(buildInfoPlugin) != 0) {
- if (LOGV_ENABLED) {
- Log.v(TAG, "build.prop are different, "
- + " therefore it's a new system image");
- }
- return true;
- }
- }
- } catch (Exception e) {
- Log.e(TAG, "Exc in newSystemImage(): " + e);
- }
- return false;
- }
-
- /**
- * Check if the version of the plugins contained in the
- * Browser assets is the same as the version of the plugins
- * in the plugins directory.
- * We simply iterate on every file in the assets/plugins
- * and return false if a file listed in the assets does
- * not exist in the plugins directory.
- */
- private boolean checkIsDifferentVersions() {
- try {
- ZipFile zip = new ZipFile(APK_PATH);
- Vector<ZipEntry> files = pluginsFilesFromZip(zip);
- int zipFilterLength = ZIP_FILTER.length();
-
- Enumeration entries = files.elements();
- while (entries.hasMoreElements()) {
- ZipEntry entry = (ZipEntry) entries.nextElement();
- String path = entry.getName().substring(zipFilterLength);
- File outputFile = new File(pluginsPath, path);
- if (!outputFile.exists()) {
- if (LOGV_ENABLED) {
- Log.v(TAG, "checkIsDifferentVersions(): extracted file "
- + path + " does not exist, we have a different version");
- }
- return true;
- }
- }
- } catch (IOException e) {
- Log.e(TAG, "Exception in checkDifferentVersions(): " + e);
- }
- return false;
- }
-
- /**
- * Copy every files from the assets/plugins directory
- * to the app_plugins directory in the data partition.
- * Once copied, we copy over the SYSTEM_BUILD_INFOS file
- * in the plugins directory.
- *
- * NOTE: we directly access the content from the Browser
- * package (it's a zip file) and do not use AssetManager
- * as there is a limit of 1Mb (see Asset.h)
- */
- public void run() {
- // Lower the priority
- Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
- try {
- if (pluginsPath == null) {
- Log.e(TAG, "No plugins path found!");
- return;
- }
-
- ZipFile zip = new ZipFile(APK_PATH);
- Vector<ZipEntry> files = pluginsFilesFromZip(zip);
- Vector<File> plugins = new Vector<File>();
- int zipFilterLength = ZIP_FILTER.length();
-
- Enumeration entries = files.elements();
- while (entries.hasMoreElements()) {
- ZipEntry entry = (ZipEntry) entries.nextElement();
- String path = entry.getName().substring(zipFilterLength);
- File outputFile = new File(pluginsPath, path);
- outputFile.getParentFile().mkdirs();
-
- if (outputFile.exists() && !mDoOverwrite) {
- if (LOGV_ENABLED) {
- Log.v(TAG, path + " already extracted.");
- }
- } else {
- if (path.endsWith(PLUGIN_EXTENSION)) {
- // We rename plugins to be sure a half-copied
- // plugin is not loaded by the browser.
- plugins.add(outputFile);
- outputFile = new File(pluginsPath,
- path + TEMPORARY_EXTENSION);
- }
- FileOutputStream fos = new FileOutputStream(outputFile);
- if (LOGV_ENABLED) {
- Log.v(TAG, "copy " + entry + " to "
- + pluginsPath + "/" + path);
- }
- copyStreams(zip.getInputStream(entry), fos);
- }
- }
-
- // We now rename the .so we copied, once all their resources
- // are safely copied over to the user data partition.
- Enumeration elems = plugins.elements();
- while (elems.hasMoreElements()) {
- File renamedFile = (File) elems.nextElement();
- File sourceFile = new File(renamedFile.getPath()
- + TEMPORARY_EXTENSION);
- if (LOGV_ENABLED) {
- Log.v(TAG, "rename " + sourceFile.getPath()
- + " to " + renamedFile.getPath());
- }
- sourceFile.renameTo(renamedFile);
- }
-
- copyBuildInfos();
- } catch (IOException e) {
- Log.e(TAG, "IO Exception: " + e);
- }
- }
- };
-
- /**
- * Copy the content of assets/plugins/ to the app_plugins directory
- * in the data partition.
- *
- * This function is called every time the browser is started.
- * We first check if the system image is newer than the one that
- * copied the plugins (if there's plugins in the data partition).
- * If this is the case, we then check if the versions are different.
- * If they are different, we clean the plugins directory in the
- * data partition, then start a thread to copy the plugins while
- * the browser continue to load.
- *
- * @param overwrite if true overwrite the files even if they are
- * already present (to let the user "reset" the plugins if needed).
- */
- private void copyPlugins(boolean overwrite) {
- CopyPlugins copyPluginsFromAssets = new CopyPlugins(overwrite, this);
- copyPluginsFromAssets.initPluginsPath();
- if (copyPluginsFromAssets.newSystemImage()) {
- if (copyPluginsFromAssets.checkIsDifferentVersions()) {
- copyPluginsFromAssets.cleanPluginsDirectory();
- Thread copyplugins = new Thread(copyPluginsFromAssets);
- copyplugins.setName("CopyPlugins");
- copyplugins.start();
- }
- }
- }
-
private static class ClearThumbnails extends AsyncTask<File, Void, Void> {
@Override
public Void doInBackground(File... files) {
@@ -845,7 +480,6 @@ public class BrowserActivity extends Activity
&& !mSettings.isLoginInitialized()) {
setupHomePage();
}
- copyPlugins(true);
if (urlData.isEmpty()) {
if (mSettings.isLoginInitialized()) {