2010-08-27 20:22:57 +00:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
2010-06-02 21:55:28 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Android code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009-2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
2010-11-12 23:58:29 +00:00
|
|
|
* Matt Brubeck <mbrubeck@mozilla.com>
|
|
|
|
* Vivien Nicolas <vnicolas@mozilla.com>
|
2010-06-02 21:55:28 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.zip.*;
|
|
|
|
import java.nio.*;
|
2010-09-14 01:16:24 +00:00
|
|
|
import java.nio.channels.FileChannel;
|
2010-09-30 15:37:36 +00:00
|
|
|
import java.util.concurrent.*;
|
2011-09-16 21:34:31 +00:00
|
|
|
import java.lang.reflect.*;
|
2010-06-02 21:55:28 +00:00
|
|
|
|
|
|
|
import android.os.*;
|
|
|
|
import android.app.*;
|
|
|
|
import android.text.*;
|
|
|
|
import android.view.*;
|
|
|
|
import android.view.inputmethod.*;
|
|
|
|
import android.content.*;
|
2011-02-27 15:50:56 +00:00
|
|
|
import android.content.res.*;
|
2010-06-02 21:55:28 +00:00
|
|
|
import android.graphics.*;
|
|
|
|
import android.widget.*;
|
|
|
|
import android.hardware.*;
|
|
|
|
|
|
|
|
import android.util.*;
|
2010-09-30 15:37:36 +00:00
|
|
|
import android.net.*;
|
2011-06-02 00:40:38 +00:00
|
|
|
import android.database.*;
|
|
|
|
import android.provider.*;
|
2011-09-16 21:34:31 +00:00
|
|
|
import android.content.pm.*;
|
|
|
|
import android.content.pm.PackageManager.*;
|
|
|
|
import dalvik.system.*;
|
2010-06-02 21:55:28 +00:00
|
|
|
|
|
|
|
abstract public class GeckoApp
|
|
|
|
extends Activity
|
|
|
|
{
|
2011-08-19 02:27:41 +00:00
|
|
|
private static final String LOG_FILE_NAME = "GeckoApp";
|
|
|
|
|
2010-06-15 02:17:37 +00:00
|
|
|
public static final String ACTION_ALERT_CLICK = "org.mozilla.gecko.ACTION_ALERT_CLICK";
|
|
|
|
public static final String ACTION_ALERT_CLEAR = "org.mozilla.gecko.ACTION_ALERT_CLEAR";
|
2011-08-08 03:30:32 +00:00
|
|
|
public static final String ACTION_WEBAPP = "org.mozilla.gecko.WEBAPP";
|
|
|
|
public static final String ACTION_DEBUG = "org.mozilla.gecko.DEBUG";
|
2011-08-09 02:37:57 +00:00
|
|
|
public static final String ACTION_BOOKMARK = "org.mozilla.gecko.BOOKMARK";
|
2010-06-15 02:17:37 +00:00
|
|
|
|
2011-09-16 21:34:31 +00:00
|
|
|
public static AbsoluteLayout mainLayout;
|
2010-06-02 21:55:28 +00:00
|
|
|
public static GeckoSurfaceView surfaceView;
|
2011-10-11 18:21:27 +00:00
|
|
|
public static SurfaceView cameraView;
|
2010-06-02 21:55:28 +00:00
|
|
|
public static GeckoApp mAppContext;
|
2010-11-09 02:11:13 +00:00
|
|
|
public static boolean mFullscreen = false;
|
2011-02-08 04:40:42 +00:00
|
|
|
public static File sGREDir = null;
|
2011-01-11 05:48:35 +00:00
|
|
|
static Thread mLibLoadThread = null;
|
2011-03-31 04:13:35 +00:00
|
|
|
public Handler mMainHandler;
|
2011-05-09 19:58:55 +00:00
|
|
|
private IntentFilter mConnectivityFilter;
|
|
|
|
private BroadcastReceiver mConnectivityReceiver;
|
2011-11-02 15:36:44 +00:00
|
|
|
private BroadcastReceiver mBatteryReceiver;
|
2010-06-02 21:55:28 +00:00
|
|
|
|
2011-10-03 16:00:36 +00:00
|
|
|
enum LaunchState {PreLaunch, Launching, WaitForDebugger,
|
2011-09-13 06:25:01 +00:00
|
|
|
Launched, GeckoRunning, GeckoExiting};
|
2010-11-24 22:51:41 +00:00
|
|
|
private static LaunchState sLaunchState = LaunchState.PreLaunch;
|
2011-07-26 16:12:36 +00:00
|
|
|
private static boolean sTryCatchAttached = false;
|
2010-11-24 22:51:41 +00:00
|
|
|
|
2011-02-27 15:50:56 +00:00
|
|
|
|
2010-11-24 22:51:41 +00:00
|
|
|
static boolean checkLaunchState(LaunchState checkState) {
|
|
|
|
synchronized(sLaunchState) {
|
|
|
|
return sLaunchState == checkState;
|
|
|
|
}
|
|
|
|
}
|
2011-02-27 15:50:56 +00:00
|
|
|
|
2010-11-24 22:51:41 +00:00
|
|
|
static void setLaunchState(LaunchState setState) {
|
|
|
|
synchronized(sLaunchState) {
|
|
|
|
sLaunchState = setState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if mLaunchState is equal to checkState this sets mLaunchState to setState
|
|
|
|
// and return true. Otherwise we return false.
|
|
|
|
static boolean checkAndSetLaunchState(LaunchState checkState, LaunchState setState) {
|
|
|
|
synchronized(sLaunchState) {
|
|
|
|
if (sLaunchState != checkState)
|
|
|
|
return false;
|
|
|
|
sLaunchState = setState;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-28 01:08:55 +00:00
|
|
|
void showErrorDialog(String message)
|
|
|
|
{
|
|
|
|
new AlertDialog.Builder(this)
|
|
|
|
.setMessage(message)
|
|
|
|
.setCancelable(false)
|
2011-02-11 22:35:50 +00:00
|
|
|
.setPositiveButton(R.string.exit_label,
|
2010-09-28 01:08:55 +00:00
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int id)
|
|
|
|
{
|
|
|
|
GeckoApp.this.finish();
|
2011-02-11 22:35:50 +00:00
|
|
|
System.exit(0);
|
2010-09-28 01:08:55 +00:00
|
|
|
}
|
|
|
|
}).show();
|
|
|
|
}
|
|
|
|
|
2011-09-16 21:34:31 +00:00
|
|
|
public static final String PLUGIN_ACTION = "android.webkit.PLUGIN";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A plugin that wish to be loaded in the WebView must provide this permission
|
|
|
|
* in their AndroidManifest.xml.
|
|
|
|
*/
|
|
|
|
public static final String PLUGIN_PERMISSION = "android.webkit.permission.PLUGIN";
|
|
|
|
|
|
|
|
private static final String LOGTAG = "PluginManager";
|
|
|
|
|
|
|
|
private static final String PLUGIN_SYSTEM_LIB = "/system/lib/plugins/";
|
|
|
|
|
|
|
|
private static final String PLUGIN_TYPE = "type";
|
|
|
|
private static final String TYPE_NATIVE = "native";
|
|
|
|
public ArrayList<PackageInfo> mPackageInfoCache = new ArrayList<PackageInfo>();
|
|
|
|
|
|
|
|
String[] getPluginDirectories() {
|
2011-09-30 00:29:11 +00:00
|
|
|
|
2011-09-16 21:34:31 +00:00
|
|
|
ArrayList<String> directories = new ArrayList<String>();
|
|
|
|
PackageManager pm = this.mAppContext.getPackageManager();
|
|
|
|
List<ResolveInfo> plugins = pm.queryIntentServices(new Intent(PLUGIN_ACTION),
|
|
|
|
PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);
|
|
|
|
|
|
|
|
synchronized(mPackageInfoCache) {
|
2011-09-30 00:29:11 +00:00
|
|
|
|
2011-09-16 21:34:31 +00:00
|
|
|
// clear the list of existing packageInfo objects
|
|
|
|
mPackageInfoCache.clear();
|
|
|
|
|
2011-09-30 00:29:11 +00:00
|
|
|
|
2011-09-16 21:34:31 +00:00
|
|
|
for (ResolveInfo info : plugins) {
|
|
|
|
|
|
|
|
// retrieve the plugin's service information
|
|
|
|
ServiceInfo serviceInfo = info.serviceInfo;
|
|
|
|
if (serviceInfo == null) {
|
|
|
|
Log.w(LOGTAG, "Ignore bad plugin");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName);
|
|
|
|
|
2011-09-30 00:29:11 +00:00
|
|
|
|
2011-09-16 21:34:31 +00:00
|
|
|
// retrieve information from the plugin's manifest
|
|
|
|
PackageInfo pkgInfo;
|
|
|
|
try {
|
|
|
|
pkgInfo = pm.getPackageInfo(serviceInfo.packageName,
|
|
|
|
PackageManager.GET_PERMISSIONS
|
|
|
|
| PackageManager.GET_SIGNATURES);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.w(LOGTAG, "Can't find plugin: " + serviceInfo.packageName);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pkgInfo == null) {
|
|
|
|
Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Could not load package information.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* find the location of the plugin's shared library. The default
|
|
|
|
* is to assume the app is either a user installed app or an
|
|
|
|
* updated system app. In both of these cases the library is
|
|
|
|
* stored in the app's data directory.
|
|
|
|
*/
|
|
|
|
String directory = pkgInfo.applicationInfo.dataDir + "/lib";
|
|
|
|
final int appFlags = pkgInfo.applicationInfo.flags;
|
|
|
|
final int updatedSystemFlags = ApplicationInfo.FLAG_SYSTEM |
|
|
|
|
ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
|
|
|
|
// preloaded system app with no user updates
|
|
|
|
if ((appFlags & updatedSystemFlags) == ApplicationInfo.FLAG_SYSTEM) {
|
|
|
|
directory = PLUGIN_SYSTEM_LIB + pkgInfo.packageName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the plugin has the required permissions
|
|
|
|
String permissions[] = pkgInfo.requestedPermissions;
|
|
|
|
if (permissions == null) {
|
|
|
|
Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Does not have required permission.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
boolean permissionOk = false;
|
|
|
|
for (String permit : permissions) {
|
|
|
|
if (PLUGIN_PERMISSION.equals(permit)) {
|
|
|
|
permissionOk = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!permissionOk) {
|
|
|
|
Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Does not have required permission (2).");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check to ensure the plugin is properly signed
|
|
|
|
Signature signatures[] = pkgInfo.signatures;
|
|
|
|
if (signatures == null) {
|
|
|
|
Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Not signed.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine the type of plugin from the manifest
|
|
|
|
if (serviceInfo.metaData == null) {
|
|
|
|
Log.e(LOGTAG, "The plugin '" + serviceInfo.name + "' has no type defined");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
String pluginType = serviceInfo.metaData.getString(PLUGIN_TYPE);
|
|
|
|
if (!TYPE_NATIVE.equals(pluginType)) {
|
|
|
|
Log.e(LOGTAG, "Unrecognized plugin type: " + pluginType);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Class<?> cls = getPluginClass(serviceInfo.packageName, serviceInfo.name);
|
|
|
|
|
|
|
|
//TODO implement any requirements of the plugin class here!
|
|
|
|
boolean classFound = true;
|
|
|
|
|
|
|
|
if (!classFound) {
|
|
|
|
Log.e(LOGTAG, "The plugin's class' " + serviceInfo.name + "' does not extend the appropriate class.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (NameNotFoundException e) {
|
|
|
|
Log.e(LOGTAG, "Can't find plugin: " + serviceInfo.packageName);
|
|
|
|
continue;
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
Log.e(LOGTAG, "Can't find plugin's class: " + serviceInfo.name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if all checks have passed then make the plugin available
|
|
|
|
mPackageInfoCache.add(pkgInfo);
|
|
|
|
directories.add(directory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return directories.toArray(new String[directories.size()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Class<?> getPluginClass(String packageName, String className)
|
|
|
|
throws NameNotFoundException, ClassNotFoundException {
|
|
|
|
Context pluginContext = this.mAppContext.createPackageContext(packageName,
|
|
|
|
Context.CONTEXT_INCLUDE_CODE |
|
|
|
|
Context.CONTEXT_IGNORE_SECURITY);
|
|
|
|
ClassLoader pluginCL = pluginContext.getClassLoader();
|
|
|
|
return pluginCL.loadClass(className);
|
|
|
|
}
|
|
|
|
|
2010-11-24 22:51:41 +00:00
|
|
|
// Returns true when the intent is going to be handled by gecko launch
|
2011-01-11 05:48:35 +00:00
|
|
|
boolean launch(Intent intent)
|
2010-06-02 21:55:28 +00:00
|
|
|
{
|
2010-11-24 22:51:41 +00:00
|
|
|
if (!checkAndSetLaunchState(LaunchState.Launching, LaunchState.Launched))
|
|
|
|
return false;
|
|
|
|
|
2011-01-11 05:48:35 +00:00
|
|
|
if (intent == null)
|
|
|
|
intent = getIntent();
|
|
|
|
final Intent i = intent;
|
2011-02-27 15:50:56 +00:00
|
|
|
new Thread() {
|
2011-01-11 05:48:35 +00:00
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
if (mLibLoadThread != null)
|
|
|
|
mLibLoadThread.join();
|
|
|
|
} catch (InterruptedException ie) {}
|
2011-09-21 19:19:44 +00:00
|
|
|
|
|
|
|
// Show the URL we are about to load, if the intent has one
|
|
|
|
if (Intent.ACTION_VIEW.equals(i.getAction())) {
|
|
|
|
surfaceView.mSplashURL = i.getDataString();
|
|
|
|
}
|
2011-01-11 05:48:35 +00:00
|
|
|
surfaceView.drawSplashScreen();
|
2011-09-21 19:19:44 +00:00
|
|
|
|
2011-01-11 05:48:35 +00:00
|
|
|
// unpack files in the components directory
|
|
|
|
try {
|
|
|
|
unpackComponents();
|
|
|
|
} catch (FileNotFoundException fnfe) {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.e(LOG_FILE_NAME, "error unpacking components", fnfe);
|
2011-01-11 05:48:35 +00:00
|
|
|
Looper.prepare();
|
|
|
|
showErrorDialog(getString(R.string.error_loading_file));
|
|
|
|
Looper.loop();
|
|
|
|
return;
|
|
|
|
} catch (IOException ie) {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.e(LOG_FILE_NAME, "error unpacking components", ie);
|
2011-01-11 05:48:35 +00:00
|
|
|
String msg = ie.getMessage();
|
|
|
|
Looper.prepare();
|
2011-03-01 04:24:42 +00:00
|
|
|
if (msg != null && msg.equalsIgnoreCase("No space left on device"))
|
2011-01-11 05:48:35 +00:00
|
|
|
showErrorDialog(getString(R.string.no_space_to_start_error));
|
|
|
|
else
|
|
|
|
showErrorDialog(getString(R.string.error_loading_file));
|
|
|
|
Looper.loop();
|
|
|
|
return;
|
|
|
|
}
|
2011-02-27 15:50:56 +00:00
|
|
|
|
2011-01-11 05:48:35 +00:00
|
|
|
// and then fire us up
|
2011-06-01 17:54:53 +00:00
|
|
|
try {
|
|
|
|
String env = i.getStringExtra("env0");
|
|
|
|
GeckoAppShell.runGecko(getApplication().getPackageResourcePath(),
|
|
|
|
i.getStringExtra("args"),
|
|
|
|
i.getDataString());
|
|
|
|
} catch (Exception e) {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.e(LOG_FILE_NAME, "top level exception", e);
|
2011-06-01 17:54:53 +00:00
|
|
|
StringWriter sw = new StringWriter();
|
2011-10-28 14:05:06 +00:00
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
|
e.printStackTrace(pw);
|
|
|
|
pw.flush();
|
2011-06-01 17:54:53 +00:00
|
|
|
GeckoAppShell.reportJavaCrash(sw.toString());
|
|
|
|
}
|
2011-01-11 05:48:35 +00:00
|
|
|
}
|
|
|
|
}.start();
|
2010-11-24 22:51:41 +00:00
|
|
|
return true;
|
2010-06-02 21:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Called when the activity is first created. */
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
2011-02-27 15:50:56 +00:00
|
|
|
mAppContext = this;
|
2011-03-31 04:13:35 +00:00
|
|
|
mMainHandler = new Handler();
|
2011-02-27 15:50:56 +00:00
|
|
|
|
2011-07-26 16:12:36 +00:00
|
|
|
if (!sTryCatchAttached) {
|
|
|
|
sTryCatchAttached = true;
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
Looper.loop();
|
|
|
|
} catch (Exception e) {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.e(LOG_FILE_NAME, "top level exception", e);
|
2011-07-26 16:12:36 +00:00
|
|
|
StringWriter sw = new StringWriter();
|
2011-11-08 21:41:50 +00:00
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
|
e.printStackTrace(pw);
|
|
|
|
pw.flush();
|
2011-07-26 16:12:36 +00:00
|
|
|
GeckoAppShell.reportJavaCrash(sw.toString());
|
|
|
|
}
|
|
|
|
// resetting this is kinda pointless, but oh well
|
|
|
|
sTryCatchAttached = false;
|
2011-06-01 17:54:53 +00:00
|
|
|
}
|
2011-07-26 16:12:36 +00:00
|
|
|
});
|
|
|
|
}
|
2011-06-01 17:54:53 +00:00
|
|
|
|
2011-02-27 15:50:56 +00:00
|
|
|
SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
|
|
|
|
String localeCode = settings.getString(getPackageName() + ".locale", "");
|
|
|
|
if (localeCode != null && localeCode.length() > 0)
|
|
|
|
GeckoAppShell.setSelectedLocale(localeCode);
|
|
|
|
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "create");
|
2010-06-02 21:55:28 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2011-02-08 08:39:15 +00:00
|
|
|
if (sGREDir == null)
|
|
|
|
sGREDir = new File(this.getApplicationInfo().dataDir);
|
2011-02-08 04:40:42 +00:00
|
|
|
|
2010-11-09 02:11:13 +00:00
|
|
|
getWindow().setFlags(mFullscreen ?
|
|
|
|
WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,
|
|
|
|
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
2010-06-02 21:55:28 +00:00
|
|
|
|
2011-10-11 18:21:27 +00:00
|
|
|
if (cameraView == null) {
|
|
|
|
cameraView = new SurfaceView(this);
|
|
|
|
cameraView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
|
|
|
}
|
|
|
|
|
2010-11-09 02:11:13 +00:00
|
|
|
if (surfaceView == null)
|
|
|
|
surfaceView = new GeckoSurfaceView(this);
|
|
|
|
else
|
2011-09-16 21:34:31 +00:00
|
|
|
mainLayout.removeAllViews();
|
2010-09-14 01:16:24 +00:00
|
|
|
|
2011-09-16 21:34:31 +00:00
|
|
|
mainLayout = new AbsoluteLayout(this);
|
2010-06-02 21:55:28 +00:00
|
|
|
mainLayout.addView(surfaceView,
|
2011-09-16 21:34:31 +00:00
|
|
|
new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.MATCH_PARENT, // level 8
|
|
|
|
AbsoluteLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
0,
|
|
|
|
0));
|
2011-10-11 18:21:27 +00:00
|
|
|
|
2010-06-02 21:55:28 +00:00
|
|
|
setContentView(mainLayout,
|
|
|
|
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
|
|
|
ViewGroup.LayoutParams.FILL_PARENT));
|
2010-11-24 22:51:41 +00:00
|
|
|
|
2011-05-10 16:14:05 +00:00
|
|
|
mConnectivityFilter = new IntentFilter();
|
|
|
|
mConnectivityFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
|
|
|
mConnectivityReceiver = new GeckoConnectivityReceiver();
|
|
|
|
|
2011-11-22 09:35:53 +00:00
|
|
|
IntentFilter batteryFilter = new IntentFilter();
|
|
|
|
batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
2011-11-02 15:36:44 +00:00
|
|
|
mBatteryReceiver = new GeckoBatteryManager();
|
2011-11-22 09:35:53 +00:00
|
|
|
registerReceiver(mBatteryReceiver, batteryFilter);
|
2011-11-02 15:36:44 +00:00
|
|
|
|
2012-01-17 18:38:04 +00:00
|
|
|
if (SmsManager.getInstance() != null) {
|
2012-01-24 16:06:47 +00:00
|
|
|
SmsManager.getInstance().start();
|
2012-01-17 18:38:04 +00:00
|
|
|
}
|
2011-12-19 10:16:39 +00:00
|
|
|
|
2012-01-16 17:17:34 +00:00
|
|
|
GeckoNetworkManager.getInstance().init();
|
2012-01-17 18:40:39 +00:00
|
|
|
|
2010-11-24 22:51:41 +00:00
|
|
|
if (!checkAndSetLaunchState(LaunchState.PreLaunch,
|
|
|
|
LaunchState.Launching))
|
|
|
|
return;
|
|
|
|
|
|
|
|
checkAndLaunchUpdate();
|
2011-02-27 15:50:56 +00:00
|
|
|
mLibLoadThread = new Thread(new Runnable() {
|
2011-01-11 05:48:35 +00:00
|
|
|
public void run() {
|
2011-02-27 15:50:56 +00:00
|
|
|
// 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();
|
2011-01-11 05:48:35 +00:00
|
|
|
GeckoAppShell.loadGeckoLibs(
|
|
|
|
getApplication().getPackageResourcePath());
|
2011-02-27 15:50:56 +00:00
|
|
|
Locale.setDefault(locale);
|
|
|
|
Resources res = getBaseContext().getResources();
|
|
|
|
Configuration config = res.getConfiguration();
|
|
|
|
config.locale = locale;
|
|
|
|
res.updateConfiguration(config, res.getDisplayMetrics());
|
2011-01-11 05:48:35 +00:00
|
|
|
}});
|
2011-01-20 06:14:12 +00:00
|
|
|
mLibLoadThread.start();
|
2010-11-24 22:51:41 +00:00
|
|
|
}
|
|
|
|
|
2011-11-04 23:46:34 +00:00
|
|
|
public void enableCameraView() {
|
|
|
|
// Some phones (eg. nexus S) need at least a 8x16 preview size
|
|
|
|
mainLayout.addView(cameraView, new AbsoluteLayout.LayoutParams(8, 16, 0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void disableCameraView() {
|
|
|
|
mainLayout.removeView(cameraView);
|
|
|
|
}
|
|
|
|
|
2010-06-18 17:42:51 +00:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
2010-11-24 22:51:41 +00:00
|
|
|
if (checkLaunchState(LaunchState.GeckoExiting)) {
|
|
|
|
// We're exiting and shouldn't try to do anything else just incase
|
|
|
|
// we're hung for some reason we'll force the process to exit
|
|
|
|
System.exit(0);
|
|
|
|
return;
|
|
|
|
}
|
2010-06-18 17:42:51 +00:00
|
|
|
final String action = intent.getAction();
|
2011-09-13 06:25:01 +00:00
|
|
|
if (ACTION_DEBUG.equals(action) &&
|
2011-10-03 16:00:36 +00:00
|
|
|
checkAndSetLaunchState(LaunchState.Launching, LaunchState.WaitForDebugger)) {
|
|
|
|
|
|
|
|
mMainHandler.postDelayed(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
Log.i(LOG_FILE_NAME, "Launching from debug intent after 5s wait");
|
2011-09-13 06:25:01 +00:00
|
|
|
setLaunchState(LaunchState.Launching);
|
|
|
|
launch(null);
|
|
|
|
}
|
2011-10-03 16:00:36 +00:00
|
|
|
}, 1000 * 5 /* 5 seconds */);
|
|
|
|
Log.i(LOG_FILE_NAME, "Intent : ACTION_DEBUG - waiting 5s before launching");
|
2011-09-13 06:25:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-10-03 16:00:36 +00:00
|
|
|
if (checkLaunchState(LaunchState.WaitForDebugger) || launch(intent))
|
2011-09-13 06:25:01 +00:00
|
|
|
return;
|
2010-11-24 22:51:41 +00:00
|
|
|
|
2011-08-09 02:37:57 +00:00
|
|
|
if (Intent.ACTION_MAIN.equals(action)) {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "Intent : ACTION_MAIN");
|
2011-08-09 02:37:57 +00:00
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(""));
|
|
|
|
}
|
2011-09-13 06:25:01 +00:00
|
|
|
else if (Intent.ACTION_VIEW.equals(action)) {
|
2010-06-18 17:42:51 +00:00
|
|
|
String uri = intent.getDataString();
|
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME,"onNewIntent: "+uri);
|
2010-06-18 17:42:51 +00:00
|
|
|
}
|
2011-09-13 06:25:01 +00:00
|
|
|
else if (ACTION_WEBAPP.equals(action)) {
|
2010-10-15 18:16:45 +00:00
|
|
|
String uri = intent.getStringExtra("args");
|
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME,"Intent : WEBAPP - " + uri);
|
2010-10-15 18:16:45 +00:00
|
|
|
}
|
2011-09-13 06:25:01 +00:00
|
|
|
else if (ACTION_BOOKMARK.equals(action)) {
|
2011-08-09 02:37:57 +00:00
|
|
|
String args = intent.getStringExtra("args");
|
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(args));
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME,"Intent : BOOKMARK - " + args);
|
2011-08-09 02:37:57 +00:00
|
|
|
}
|
2010-06-18 17:42:51 +00:00
|
|
|
}
|
|
|
|
|
2010-06-02 21:55:28 +00:00
|
|
|
@Override
|
|
|
|
public void onPause()
|
|
|
|
{
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "pause");
|
2010-06-17 21:33:15 +00:00
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_PAUSING));
|
2010-06-02 21:55:28 +00:00
|
|
|
// The user is navigating away from this activity, but nothing
|
|
|
|
// has come to the foreground yet; for Gecko, we may want to
|
|
|
|
// stop repainting, for example.
|
|
|
|
|
|
|
|
// Whatever we do here should be fast, because we're blocking
|
|
|
|
// the next activity from showing up until we finish.
|
|
|
|
|
|
|
|
// onPause will be followed by either onResume or onStop.
|
|
|
|
super.onPause();
|
2011-05-09 19:58:55 +00:00
|
|
|
|
|
|
|
unregisterReceiver(mConnectivityReceiver);
|
2012-01-16 17:17:34 +00:00
|
|
|
GeckoNetworkManager.getInstance().stop();
|
2010-06-02 21:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume()
|
|
|
|
{
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "resume");
|
2010-11-24 22:51:41 +00:00
|
|
|
if (checkLaunchState(LaunchState.GeckoRunning))
|
2011-02-02 06:34:12 +00:00
|
|
|
GeckoAppShell.onResume();
|
2010-06-02 21:55:28 +00:00
|
|
|
// After an onPause, the activity is back in the foreground.
|
|
|
|
// Undo whatever we did in onPause.
|
|
|
|
super.onResume();
|
2010-11-24 22:51:41 +00:00
|
|
|
|
|
|
|
// Just in case. Normally we start in onNewIntent
|
|
|
|
if (checkLaunchState(LaunchState.PreLaunch) ||
|
|
|
|
checkLaunchState(LaunchState.Launching))
|
|
|
|
onNewIntent(getIntent());
|
2011-05-09 19:58:55 +00:00
|
|
|
|
|
|
|
registerReceiver(mConnectivityReceiver, mConnectivityFilter);
|
2012-01-16 17:17:34 +00:00
|
|
|
GeckoNetworkManager.getInstance().start();
|
2011-02-02 06:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStop()
|
|
|
|
{
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "stop");
|
2011-02-02 06:34:12 +00:00
|
|
|
// We're about to be stopped, potentially in preparation for
|
|
|
|
// being destroyed. We're killable after this point -- as I
|
|
|
|
// understand it, in extreme cases the process can be terminated
|
|
|
|
// without going through onDestroy.
|
|
|
|
//
|
|
|
|
// We might also get an onRestart after this; not sure what
|
|
|
|
// that would mean for Gecko if we were to kill it here.
|
|
|
|
// Instead, what we should do here is save prefs, session,
|
|
|
|
// etc., and generally mark the profile as 'clean', and then
|
|
|
|
// dirty it again if we get an onResume.
|
|
|
|
|
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_STOPPING));
|
|
|
|
super.onStop();
|
2011-07-28 06:25:11 +00:00
|
|
|
GeckoAppShell.putChildInBackground();
|
2011-02-02 06:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRestart()
|
|
|
|
{
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "restart");
|
2011-07-28 06:25:11 +00:00
|
|
|
GeckoAppShell.putChildInForeground();
|
2011-02-02 06:34:12 +00:00
|
|
|
super.onRestart();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStart()
|
|
|
|
{
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "start");
|
2011-08-21 19:11:31 +00:00
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_START));
|
2011-02-02 06:34:12 +00:00
|
|
|
super.onStart();
|
2010-06-24 19:00:42 +00:00
|
|
|
}
|
|
|
|
|
2010-06-02 21:55:28 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy()
|
|
|
|
{
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "destroy");
|
2011-11-24 13:10:20 +00:00
|
|
|
|
2010-06-02 21:55:28 +00:00
|
|
|
// Tell Gecko to shutting down; we'll end up calling System.exit()
|
|
|
|
// in onXreExit.
|
2010-11-09 02:11:18 +00:00
|
|
|
if (isFinishing())
|
2010-12-11 22:36:11 +00:00
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_SHUTDOWN));
|
2010-06-02 21:55:28 +00:00
|
|
|
|
2012-01-17 18:38:04 +00:00
|
|
|
if (SmsManager.getInstance() != null) {
|
2012-01-24 16:06:47 +00:00
|
|
|
SmsManager.getInstance().stop();
|
|
|
|
if (isFinishing())
|
|
|
|
SmsManager.getInstance().shutdown();
|
2012-01-17 18:38:04 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 17:17:34 +00:00
|
|
|
GeckoNetworkManager.getInstance().stop();
|
|
|
|
|
2010-06-02 21:55:28 +00:00
|
|
|
super.onDestroy();
|
2011-11-22 09:35:53 +00:00
|
|
|
|
|
|
|
unregisterReceiver(mBatteryReceiver);
|
2010-06-02 21:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig)
|
|
|
|
{
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "configuration changed");
|
2010-06-02 21:55:28 +00:00
|
|
|
// nothing, just ignore
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLowMemory()
|
|
|
|
{
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.e(LOG_FILE_NAME, "low memory");
|
2010-11-24 22:51:41 +00:00
|
|
|
if (checkLaunchState(LaunchState.GeckoRunning))
|
2010-08-31 17:37:54 +00:00
|
|
|
GeckoAppShell.onLowMemory();
|
2010-06-02 21:55:28 +00:00
|
|
|
super.onLowMemory();
|
|
|
|
}
|
|
|
|
|
2010-12-21 20:02:14 +00:00
|
|
|
abstract public String getPackageName();
|
2010-06-25 20:12:03 +00:00
|
|
|
abstract public String getContentProcessName();
|
2010-06-02 21:55:28 +00:00
|
|
|
|
|
|
|
protected void unpackComponents()
|
2010-09-30 15:53:42 +00:00
|
|
|
throws IOException, FileNotFoundException
|
2010-06-02 21:55:28 +00:00
|
|
|
{
|
2011-09-02 12:32:38 +00:00
|
|
|
File applicationPackage = new File(getApplication().getPackageResourcePath());
|
2011-02-08 04:40:42 +00:00
|
|
|
File componentsDir = new File(sGREDir, "components");
|
2011-09-02 12:32:38 +00:00
|
|
|
if (componentsDir.lastModified() == applicationPackage.lastModified())
|
|
|
|
return;
|
|
|
|
|
2010-09-30 15:53:42 +00:00
|
|
|
componentsDir.mkdir();
|
2011-09-02 12:32:38 +00:00
|
|
|
componentsDir.setLastModified(applicationPackage.lastModified());
|
|
|
|
|
2011-09-05 14:09:05 +00:00
|
|
|
GeckoAppShell.killAnyZombies();
|
|
|
|
|
2011-09-02 12:32:38 +00:00
|
|
|
ZipFile zip = new ZipFile(applicationPackage);
|
2010-09-02 01:35:46 +00:00
|
|
|
|
2011-09-05 14:09:05 +00:00
|
|
|
byte[] buf = new byte[32768];
|
2011-03-18 15:50:19 +00:00
|
|
|
try {
|
|
|
|
if (unpackFile(zip, buf, null, "removed-files"))
|
|
|
|
removeFiles();
|
|
|
|
} catch (Exception ex) {
|
|
|
|
// This file may not be there, so just log any errors and move on
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.w(LOG_FILE_NAME, "error removing files", ex);
|
2011-03-18 15:50:19 +00:00
|
|
|
}
|
2010-06-02 21:55:28 +00:00
|
|
|
|
2010-09-30 17:19:05 +00:00
|
|
|
// copy any .xpi file into an extensions/ directory
|
|
|
|
Enumeration<? extends ZipEntry> zipEntries = zip.entries();
|
|
|
|
while (zipEntries.hasMoreElements()) {
|
2011-09-15 17:43:59 +00:00
|
|
|
ZipEntry entry = zipEntries.nextElement();
|
|
|
|
if (entry.getName().startsWith("extensions/") && entry.getName().endsWith(".xpi")) {
|
|
|
|
Log.i("GeckoAppJava", "installing extension : " + entry.getName());
|
|
|
|
unpackFile(zip, buf, entry, entry.getName());
|
|
|
|
}
|
2011-05-05 15:03:01 +00:00
|
|
|
}
|
2010-06-02 21:55:28 +00:00
|
|
|
}
|
|
|
|
|
2011-03-18 15:50:19 +00:00
|
|
|
void removeFiles() throws IOException {
|
|
|
|
BufferedReader reader = new BufferedReader(
|
|
|
|
new FileReader(new File(sGREDir, "removed-files")));
|
|
|
|
try {
|
|
|
|
for (String removedFileName = reader.readLine();
|
|
|
|
removedFileName != null; removedFileName = reader.readLine()) {
|
|
|
|
File removedFile = new File(sGREDir, removedFileName);
|
|
|
|
if (removedFile.exists())
|
|
|
|
removedFile.delete();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
reader.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean unpackFile(ZipFile zip, byte[] buf, ZipEntry fileEntry,
|
2010-09-30 15:53:42 +00:00
|
|
|
String name)
|
|
|
|
throws IOException, FileNotFoundException
|
2010-06-02 21:55:28 +00:00
|
|
|
{
|
|
|
|
if (fileEntry == null)
|
|
|
|
fileEntry = zip.getEntry(name);
|
2010-09-30 15:53:42 +00:00
|
|
|
if (fileEntry == null)
|
|
|
|
throw new FileNotFoundException("Can't find " + name + " in " +
|
|
|
|
zip.getName());
|
2010-06-02 21:55:28 +00:00
|
|
|
|
2011-02-08 04:40:42 +00:00
|
|
|
File outFile = new File(sGREDir, name);
|
2011-09-05 14:09:05 +00:00
|
|
|
if (outFile.lastModified() == fileEntry.getTime() &&
|
2010-06-02 21:55:28 +00:00
|
|
|
outFile.length() == fileEntry.getSize())
|
2011-03-18 15:50:19 +00:00
|
|
|
return false;
|
2010-06-02 21:55:28 +00:00
|
|
|
|
2010-09-30 15:53:42 +00:00
|
|
|
File dir = outFile.getParentFile();
|
2011-09-05 14:09:05 +00:00
|
|
|
if (!dir.exists())
|
2010-09-30 15:53:42 +00:00
|
|
|
dir.mkdirs();
|
2010-06-02 21:55:28 +00:00
|
|
|
|
|
|
|
InputStream fileStream;
|
2010-09-30 15:53:42 +00:00
|
|
|
fileStream = zip.getInputStream(fileEntry);
|
2010-06-02 21:55:28 +00:00
|
|
|
|
2010-09-30 15:53:42 +00:00
|
|
|
OutputStream outStream = new FileOutputStream(outFile);
|
2010-06-02 21:55:28 +00:00
|
|
|
|
2010-09-30 15:53:42 +00:00
|
|
|
while (fileStream.available() > 0) {
|
|
|
|
int read = fileStream.read(buf, 0, buf.length);
|
|
|
|
outStream.write(buf, 0, read);
|
2010-06-02 21:55:28 +00:00
|
|
|
}
|
2010-09-18 00:37:28 +00:00
|
|
|
|
2010-09-30 15:53:42 +00:00
|
|
|
fileStream.close();
|
|
|
|
outStream.close();
|
2010-09-18 00:37:28 +00:00
|
|
|
outFile.setLastModified(fileEntry.getTime());
|
2011-03-18 15:50:19 +00:00
|
|
|
return true;
|
2010-06-02 21:55:28 +00:00
|
|
|
}
|
2010-09-30 15:53:42 +00:00
|
|
|
|
2010-10-24 20:26:19 +00:00
|
|
|
public void addEnvToIntent(Intent intent) {
|
2010-06-02 21:55:28 +00:00
|
|
|
Map<String,String> envMap = System.getenv();
|
|
|
|
Set<Map.Entry<String,String>> envSet = envMap.entrySet();
|
|
|
|
Iterator<Map.Entry<String,String>> envIter = envSet.iterator();
|
|
|
|
int c = 0;
|
|
|
|
while (envIter.hasNext()) {
|
|
|
|
Map.Entry<String,String> entry = envIter.next();
|
2011-02-27 15:50:56 +00:00
|
|
|
intent.putExtra("env" + c, entry.getKey() + "="
|
2010-10-24 20:26:19 +00:00
|
|
|
+ entry.getValue());
|
|
|
|
c++;
|
2010-06-02 21:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void doRestart() {
|
|
|
|
try {
|
2010-12-21 20:02:14 +00:00
|
|
|
String action = "org.mozilla.gecko.restart";
|
2010-10-24 20:26:19 +00:00
|
|
|
Intent intent = new Intent(action);
|
2010-12-21 20:02:14 +00:00
|
|
|
intent.setClassName(getPackageName(),
|
|
|
|
getPackageName() + ".Restarter");
|
2010-10-24 20:26:19 +00:00
|
|
|
addEnvToIntent(intent);
|
2010-12-02 16:46:22 +00:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
|
|
|
|
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, intent.toString());
|
2011-03-04 23:00:52 +00:00
|
|
|
GeckoAppShell.killAnyZombies();
|
2010-10-27 01:57:29 +00:00
|
|
|
startActivity(intent);
|
2010-06-02 21:55:28 +00:00
|
|
|
} catch (Exception e) {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "error doing restart", e);
|
2010-06-02 21:55:28 +00:00
|
|
|
}
|
2010-10-24 20:26:19 +00:00
|
|
|
finish();
|
2011-02-28 22:10:40 +00:00
|
|
|
// Give the restart process time to start before we die
|
2011-03-04 23:00:52 +00:00
|
|
|
GeckoAppShell.waitForAnotherGeckoProc();
|
2010-06-02 21:55:28 +00:00
|
|
|
}
|
2010-06-15 02:17:37 +00:00
|
|
|
|
|
|
|
public void handleNotification(String action, String alertName, String alertCookie) {
|
|
|
|
GeckoAppShell.handleNotification(action, alertName, alertCookie);
|
|
|
|
}
|
2010-09-14 01:16:24 +00:00
|
|
|
|
|
|
|
private void checkAndLaunchUpdate() {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "Checking for an update");
|
2010-09-14 01:16:24 +00:00
|
|
|
|
|
|
|
int statusCode = 8; // UNEXPECTED_ERROR
|
2011-02-09 23:22:35 +00:00
|
|
|
File baseUpdateDir = null;
|
2011-01-03 22:32:57 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= 8)
|
2011-02-09 23:22:35 +00:00
|
|
|
baseUpdateDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
|
2011-01-03 22:32:57 +00:00
|
|
|
else
|
2011-02-09 23:22:35 +00:00
|
|
|
baseUpdateDir = new File(Environment.getExternalStorageDirectory().getPath(), "download");
|
2011-01-03 22:32:57 +00:00
|
|
|
|
2011-02-09 23:22:35 +00:00
|
|
|
File updateDir = new File(new File(baseUpdateDir, "updates"),"0");
|
2010-09-14 01:16:24 +00:00
|
|
|
|
2011-01-03 22:32:57 +00:00
|
|
|
File updateFile = new File(updateDir, "update.apk");
|
|
|
|
File statusFile = new File(updateDir, "update.status");
|
2010-11-18 22:13:31 +00:00
|
|
|
|
|
|
|
if (!statusFile.exists() || !readUpdateStatus(statusFile).equals("pending"))
|
|
|
|
return;
|
2010-09-14 01:16:24 +00:00
|
|
|
|
|
|
|
if (!updateFile.exists())
|
|
|
|
return;
|
|
|
|
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "Update is available!");
|
2010-09-14 01:16:24 +00:00
|
|
|
|
|
|
|
// Launch APK
|
2011-06-08 21:33:49 +00:00
|
|
|
File updateFileToRun = new File(updateDir, getPackageName() + "-update.apk");
|
2010-09-14 01:16:24 +00:00
|
|
|
try {
|
2010-09-17 18:03:43 +00:00
|
|
|
if (updateFile.renameTo(updateFileToRun)) {
|
2010-09-14 01:16:24 +00:00
|
|
|
String amCmd = "/system/bin/am start -a android.intent.action.VIEW " +
|
|
|
|
"-n com.android.packageinstaller/.PackageInstallerActivity -d file://" +
|
|
|
|
updateFileToRun.getPath();
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, amCmd);
|
2010-09-14 01:16:24 +00:00
|
|
|
Runtime.getRuntime().exec(amCmd);
|
|
|
|
statusCode = 0; // OK
|
|
|
|
} else {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "Cannot rename the update file!");
|
2010-09-14 01:16:24 +00:00
|
|
|
statusCode = 7; // WRITE_ERROR
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "error launching installer to update", e);
|
2010-09-14 01:16:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the status file
|
|
|
|
String status = statusCode == 0 ? "succeeded\n" : "failed: "+ statusCode + "\n";
|
|
|
|
|
|
|
|
OutputStream outStream;
|
|
|
|
try {
|
|
|
|
byte[] buf = status.getBytes("UTF-8");
|
|
|
|
outStream = new FileOutputStream(statusFile);
|
|
|
|
outStream.write(buf, 0, buf.length);
|
|
|
|
outStream.close();
|
|
|
|
} catch (Exception e) {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "error writing status file", e);
|
2010-09-14 01:16:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (statusCode == 0)
|
|
|
|
System.exit(0);
|
|
|
|
}
|
2010-09-30 15:37:36 +00:00
|
|
|
|
2010-11-18 22:13:31 +00:00
|
|
|
private String readUpdateStatus(File statusFile) {
|
|
|
|
String status = "";
|
|
|
|
try {
|
|
|
|
BufferedReader reader = new BufferedReader(new FileReader(statusFile));
|
|
|
|
status = reader.readLine();
|
|
|
|
reader.close();
|
|
|
|
} catch (Exception e) {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "error reading update status", e);
|
2010-11-18 22:13:31 +00:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2010-09-30 15:37:36 +00:00
|
|
|
static final int FILE_PICKER_REQUEST = 1;
|
|
|
|
|
|
|
|
private SynchronousQueue<String> mFilePickerResult = new SynchronousQueue();
|
2010-11-05 17:43:12 +00:00
|
|
|
public String showFilePicker(String aMimeType) {
|
2010-09-30 15:37:36 +00:00
|
|
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
2010-11-05 17:43:12 +00:00
|
|
|
intent.setType(aMimeType);
|
2010-09-30 15:37:36 +00:00
|
|
|
GeckoApp.this.
|
|
|
|
startActivityForResult(
|
2011-08-02 01:17:14 +00:00
|
|
|
Intent.createChooser(intent, getString(R.string.choose_file)),
|
2010-09-30 15:37:36 +00:00
|
|
|
FILE_PICKER_REQUEST);
|
|
|
|
String filePickerResult = "";
|
2011-08-19 02:30:22 +00:00
|
|
|
|
2010-09-30 15:37:36 +00:00
|
|
|
try {
|
2011-08-19 02:30:22 +00:00
|
|
|
while (null == (filePickerResult = mFilePickerResult.poll(1, TimeUnit.MILLISECONDS))) {
|
|
|
|
Log.i("GeckoApp", "processing events from showFilePicker ");
|
|
|
|
GeckoAppShell.processNextNativeEvent();
|
|
|
|
}
|
2010-09-30 15:37:36 +00:00
|
|
|
} catch (InterruptedException e) {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "showing file picker ", e);
|
2010-09-30 15:37:36 +00:00
|
|
|
}
|
2011-02-27 15:50:56 +00:00
|
|
|
|
2010-09-30 15:37:36 +00:00
|
|
|
return filePickerResult;
|
|
|
|
}
|
2011-02-27 15:50:56 +00:00
|
|
|
|
2010-09-30 15:37:36 +00:00
|
|
|
@Override
|
2011-02-27 15:50:56 +00:00
|
|
|
protected void onActivityResult(int requestCode, int resultCode,
|
2010-09-30 15:37:36 +00:00
|
|
|
Intent data) {
|
|
|
|
String filePickerResult = "";
|
|
|
|
if (data != null && resultCode == RESULT_OK) {
|
|
|
|
try {
|
|
|
|
ContentResolver cr = getContentResolver();
|
|
|
|
Uri uri = data.getData();
|
2011-06-02 00:40:38 +00:00
|
|
|
Cursor cursor = GeckoApp.mAppContext.getContentResolver().query(
|
|
|
|
uri,
|
|
|
|
new String[] { OpenableColumns.DISPLAY_NAME },
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null);
|
|
|
|
String name = null;
|
|
|
|
if (cursor != null) {
|
|
|
|
try {
|
|
|
|
if (cursor.moveToNext()) {
|
|
|
|
name = cursor.getString(0);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String fileName = "tmp_";
|
|
|
|
String fileExt = null;
|
|
|
|
int period;
|
|
|
|
if (name == null || (period = name.lastIndexOf('.')) == -1) {
|
|
|
|
String mimeType = cr.getType(uri);
|
|
|
|
fileExt = "." + GeckoAppShell.getExtensionFromMimeType(mimeType);
|
|
|
|
} else {
|
|
|
|
fileExt = name.substring(period);
|
|
|
|
fileName = name.substring(0, period);
|
|
|
|
}
|
|
|
|
File file = File.createTempFile(fileName, fileExt, sGREDir);
|
2011-02-27 15:50:56 +00:00
|
|
|
|
2010-09-30 15:37:36 +00:00
|
|
|
FileOutputStream fos = new FileOutputStream(file);
|
|
|
|
InputStream is = cr.openInputStream(uri);
|
|
|
|
byte[] buf = new byte[4096];
|
|
|
|
int len = is.read(buf);
|
|
|
|
while (len != -1) {
|
|
|
|
fos.write(buf, 0, len);
|
|
|
|
len = is.read(buf);
|
|
|
|
}
|
|
|
|
fos.close();
|
|
|
|
filePickerResult = file.getAbsolutePath();
|
|
|
|
}catch (Exception e) {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.e(LOG_FILE_NAME, "showing file picker", e);
|
2010-09-30 15:37:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
mFilePickerResult.put(filePickerResult);
|
|
|
|
} catch (InterruptedException e) {
|
2011-08-19 02:27:41 +00:00
|
|
|
Log.i(LOG_FILE_NAME, "error returning file picker result", e);
|
2010-09-30 15:37:36 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-02 21:55:28 +00:00
|
|
|
}
|