2010-08-28 00:22:57 +04:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
2010-06-03 01:55:28 +04: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>
|
|
|
|
*
|
|
|
|
* 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 05:16:24 +04:00
|
|
|
import java.nio.channels.FileChannel;
|
2010-09-30 19:37:36 +04:00
|
|
|
import java.util.concurrent.*;
|
2010-06-03 01:55:28 +04:00
|
|
|
|
|
|
|
import android.os.*;
|
|
|
|
import android.app.*;
|
|
|
|
import android.text.*;
|
|
|
|
import android.view.*;
|
|
|
|
import android.view.inputmethod.*;
|
|
|
|
import android.content.*;
|
|
|
|
import android.graphics.*;
|
|
|
|
import android.widget.*;
|
|
|
|
import android.hardware.*;
|
|
|
|
|
|
|
|
import android.util.*;
|
2010-09-30 19:37:36 +04:00
|
|
|
import android.net.*;
|
2010-06-03 01:55:28 +04:00
|
|
|
|
|
|
|
abstract public class GeckoApp
|
|
|
|
extends Activity
|
|
|
|
{
|
2010-06-15 06:17:37 +04: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";
|
|
|
|
|
2010-06-03 01:55:28 +04:00
|
|
|
public static FrameLayout mainLayout;
|
|
|
|
public static GeckoSurfaceView surfaceView;
|
|
|
|
public static GeckoApp mAppContext;
|
2010-11-09 05:11:13 +03:00
|
|
|
public static boolean mFullscreen = false;
|
2010-08-28 00:22:57 +04:00
|
|
|
ProgressDialog mProgressDialog;
|
2010-06-03 01:55:28 +04:00
|
|
|
|
2010-09-28 05:08:55 +04:00
|
|
|
void showErrorDialog(String message)
|
|
|
|
{
|
|
|
|
new AlertDialog.Builder(this)
|
|
|
|
.setMessage(message)
|
|
|
|
.setCancelable(false)
|
|
|
|
.setPositiveButton("Exit",
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int id)
|
|
|
|
{
|
|
|
|
GeckoApp.this.finish();
|
|
|
|
}
|
|
|
|
}).show();
|
|
|
|
}
|
|
|
|
|
2010-06-03 01:55:28 +04:00
|
|
|
void launch()
|
|
|
|
{
|
|
|
|
// unpack files in the components directory
|
2010-09-30 19:53:42 +04:00
|
|
|
try {
|
|
|
|
unpackComponents();
|
|
|
|
} catch (FileNotFoundException fnfe) {
|
|
|
|
showErrorDialog(getString(R.string.error_loading_file));
|
|
|
|
return;
|
|
|
|
} catch (IOException ie) {
|
|
|
|
String msg = ie.getMessage();
|
|
|
|
if (msg.equalsIgnoreCase("No space left on device"))
|
|
|
|
showErrorDialog(getString(R.string.no_space_to_start_error));
|
|
|
|
else
|
|
|
|
showErrorDialog(getString(R.string.error_loading_file));
|
|
|
|
return;
|
|
|
|
}
|
2010-06-03 01:55:28 +04:00
|
|
|
// and then fire us up
|
|
|
|
Intent i = getIntent();
|
|
|
|
String env = i.getStringExtra("env0");
|
|
|
|
GeckoAppShell.runGecko(getApplication().getPackageResourcePath(),
|
|
|
|
i.getStringExtra("args"),
|
|
|
|
i.getDataString());
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Called when the activity is first created. */
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
2010-06-24 23:00:42 +04:00
|
|
|
Log.i("GeckoApp", "create");
|
2010-06-03 01:55:28 +04:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
mAppContext = this;
|
|
|
|
|
2010-11-09 05:11:13 +03:00
|
|
|
getWindow().setFlags(mFullscreen ?
|
|
|
|
WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,
|
|
|
|
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
2010-06-03 01:55:28 +04:00
|
|
|
|
2010-11-09 05:11:13 +03:00
|
|
|
if (surfaceView == null)
|
|
|
|
surfaceView = new GeckoSurfaceView(this);
|
|
|
|
else
|
|
|
|
mainLayout.removeView(surfaceView);
|
2010-09-14 05:16:24 +04:00
|
|
|
|
2010-06-03 01:55:28 +04:00
|
|
|
mainLayout = new FrameLayout(this);
|
|
|
|
mainLayout.addView(surfaceView,
|
|
|
|
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
|
|
|
|
FrameLayout.LayoutParams.FILL_PARENT));
|
|
|
|
|
|
|
|
boolean useLaunchButton = false;
|
|
|
|
|
|
|
|
String intentAction = getIntent().getAction();
|
|
|
|
if (intentAction != null && intentAction.equals("org.mozilla.gecko.DEBUG"))
|
|
|
|
useLaunchButton = true;
|
|
|
|
|
|
|
|
setContentView(mainLayout,
|
|
|
|
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
|
|
|
ViewGroup.LayoutParams.FILL_PARENT));
|
|
|
|
|
|
|
|
if (!GeckoAppShell.sGeckoRunning) {
|
2010-11-09 05:11:13 +03:00
|
|
|
checkAndLaunchUpdate();
|
|
|
|
|
2010-09-28 05:08:55 +04:00
|
|
|
try {
|
|
|
|
BufferedReader reader =
|
|
|
|
new BufferedReader(new FileReader("/proc/cpuinfo"));
|
|
|
|
String line;
|
|
|
|
while ((line = reader.readLine()) != null) {
|
2010-10-16 03:06:31 +04:00
|
|
|
int index = line.indexOf("Processor");
|
2010-09-28 05:08:55 +04:00
|
|
|
if (index == -1)
|
|
|
|
continue;
|
2010-10-16 03:06:31 +04:00
|
|
|
|
|
|
|
int version = 5;
|
|
|
|
if (line.indexOf("(v8l)") != -1)
|
|
|
|
version = 8;
|
|
|
|
if (line.indexOf("(v7l)") != -1)
|
|
|
|
version = 7;
|
|
|
|
if (line.indexOf("(v6l)") != -1)
|
|
|
|
version = 6;
|
2010-09-28 05:08:55 +04:00
|
|
|
|
|
|
|
if (version < getMinCPUVersion()) {
|
2010-09-28 22:59:22 +04:00
|
|
|
showErrorDialog(
|
|
|
|
getString(R.string.incompatable_cpu_error));
|
2010-09-28 05:08:55 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
// Not much we can do here, just continue assuming we're okay
|
|
|
|
Log.i("GeckoApp", "exception: " + ex);
|
|
|
|
}
|
|
|
|
|
2010-09-09 23:21:34 +04:00
|
|
|
if (!useLaunchButton)
|
|
|
|
mProgressDialog =
|
2010-09-28 22:59:22 +04:00
|
|
|
ProgressDialog.show(GeckoApp.this, "",
|
|
|
|
getString(R.string.splash_screen_label),
|
|
|
|
true);
|
2010-06-03 01:55:28 +04:00
|
|
|
// Load our JNI libs; we need to do this before launch() because
|
|
|
|
// setInitialSize will be called even before Gecko is actually up
|
|
|
|
// and running.
|
2010-10-15 22:28:03 +04:00
|
|
|
GeckoAppShell.loadGeckoLibs(getApplication().getPackageResourcePath());
|
2010-06-03 01:55:28 +04:00
|
|
|
|
|
|
|
if (useLaunchButton) {
|
|
|
|
final Button b = new Button(this);
|
2010-09-28 22:59:22 +04:00
|
|
|
b.setText("Launch"); // don't need to localize
|
2010-06-03 01:55:28 +04:00
|
|
|
b.setOnClickListener(new Button.OnClickListener() {
|
|
|
|
public void onClick (View v) {
|
|
|
|
// hide the button so we can't be launched again
|
|
|
|
mainLayout.removeView(b);
|
|
|
|
launch();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
mainLayout.addView(b, 300, 200);
|
|
|
|
} else {
|
|
|
|
launch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-18 21:42:51 +04:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
final String action = intent.getAction();
|
|
|
|
if (Intent.ACTION_VIEW.equals(action)) {
|
|
|
|
String uri = intent.getDataString();
|
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
|
|
|
|
Log.i("GeckoApp","onNewIntent: "+uri);
|
|
|
|
}
|
2010-10-15 22:16:45 +04:00
|
|
|
else if (Intent.ACTION_MAIN.equals(action)) {
|
|
|
|
Log.i("GeckoApp", "Intent : ACTION_MAIN");
|
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(""));
|
|
|
|
}
|
|
|
|
else if (action.equals("org.mozilla.fennec.WEBAPP")) {
|
|
|
|
String uri = intent.getStringExtra("args");
|
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
|
|
|
|
Log.i("GeckoApp","Intent : WEBAPP - " + uri);
|
|
|
|
}
|
2010-06-18 21:42:51 +04:00
|
|
|
}
|
|
|
|
|
2010-06-03 01:55:28 +04:00
|
|
|
@Override
|
|
|
|
public void onPause()
|
|
|
|
{
|
2010-06-22 19:22:31 +04:00
|
|
|
Log.i("GeckoApp", "pause");
|
2010-06-18 01:33:15 +04:00
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_PAUSING));
|
2010-06-03 01:55:28 +04: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();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume()
|
|
|
|
{
|
2010-06-22 19:22:31 +04:00
|
|
|
Log.i("GeckoApp", "resume");
|
2010-09-28 05:08:55 +04:00
|
|
|
if (GeckoAppShell.sGeckoRunning)
|
|
|
|
GeckoAppShell.onResume();
|
2010-06-03 01:55:28 +04:00
|
|
|
// After an onPause, the activity is back in the foreground.
|
|
|
|
// Undo whatever we did in onPause.
|
|
|
|
super.onResume();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStop()
|
|
|
|
{
|
2010-06-24 23:00:42 +04:00
|
|
|
Log.i("GeckoApp", "stop");
|
2010-06-03 01:55:28 +04: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.
|
|
|
|
|
|
|
|
// XXX do the above.
|
|
|
|
|
|
|
|
super.onStop();
|
|
|
|
}
|
|
|
|
|
2010-06-24 23:00:42 +04:00
|
|
|
@Override
|
|
|
|
public void onRestart()
|
|
|
|
{
|
|
|
|
Log.i("GeckoApp", "restart");
|
|
|
|
super.onRestart();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStart()
|
|
|
|
{
|
|
|
|
Log.i("GeckoApp", "start");
|
|
|
|
super.onStart();
|
|
|
|
}
|
|
|
|
|
2010-06-03 01:55:28 +04:00
|
|
|
@Override
|
|
|
|
public void onDestroy()
|
|
|
|
{
|
2010-06-24 23:00:42 +04:00
|
|
|
Log.i("GeckoApp", "destroy");
|
2010-06-03 01:55:28 +04:00
|
|
|
// Tell Gecko to shutting down; we'll end up calling System.exit()
|
|
|
|
// in onXreExit.
|
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_STOPPING));
|
|
|
|
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig)
|
|
|
|
{
|
2010-06-24 23:00:42 +04:00
|
|
|
Log.i("GeckoApp", "configuration changed");
|
2010-06-03 01:55:28 +04:00
|
|
|
// nothing, just ignore
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLowMemory()
|
|
|
|
{
|
2010-06-24 23:00:42 +04:00
|
|
|
Log.i("GeckoApp", "low memory");
|
2010-08-31 21:37:54 +04:00
|
|
|
if (GeckoAppShell.sGeckoRunning)
|
|
|
|
GeckoAppShell.onLowMemory();
|
2010-06-03 01:55:28 +04:00
|
|
|
super.onLowMemory();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
2010-06-03 01:57:45 +04:00
|
|
|
switch (keyCode) {
|
2010-07-30 01:44:33 +04:00
|
|
|
case KeyEvent.KEYCODE_BACK:
|
|
|
|
if (event.getRepeatCount() == 0) {
|
|
|
|
event.startTracking();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-03 01:57:45 +04:00
|
|
|
case KeyEvent.KEYCODE_VOLUME_UP:
|
|
|
|
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
2010-07-30 01:44:33 +04:00
|
|
|
case KeyEvent.KEYCODE_SEARCH:
|
2010-06-03 01:57:45 +04:00
|
|
|
return false;
|
2010-08-04 23:47:26 +04:00
|
|
|
case KeyEvent.KEYCODE_DEL:
|
|
|
|
// See comments in GeckoInputConnection.onKeyDel
|
|
|
|
if (surfaceView != null &&
|
|
|
|
surfaceView.inputConnection != null &&
|
|
|
|
surfaceView.inputConnection.onKeyDel()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2010-06-03 01:57:45 +04:00
|
|
|
default:
|
2010-07-30 01:44:33 +04:00
|
|
|
break;
|
2010-06-03 01:57:45 +04:00
|
|
|
}
|
2010-07-30 01:44:33 +04:00
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(event));
|
|
|
|
return true;
|
2010-06-03 01:55:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
2010-07-30 01:44:33 +04:00
|
|
|
switch(keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_BACK:
|
|
|
|
if (!event.isTracking() || event.isCanceled())
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-06-03 01:55:28 +04:00
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(event));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
|
|
|
|
GeckoAppShell.sendEventToGecko(new GeckoEvent(event));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract public String getAppName();
|
2010-06-26 00:12:03 +04:00
|
|
|
abstract public String getContentProcessName();
|
2010-09-28 05:08:55 +04:00
|
|
|
abstract public int getMinCPUVersion();
|
2010-06-03 01:55:28 +04:00
|
|
|
|
|
|
|
protected void unpackComponents()
|
2010-09-30 19:53:42 +04:00
|
|
|
throws IOException, FileNotFoundException
|
2010-06-03 01:55:28 +04:00
|
|
|
{
|
|
|
|
ZipFile zip;
|
|
|
|
InputStream listStream;
|
|
|
|
|
2010-09-30 19:53:42 +04:00
|
|
|
File componentsDir = new File("/data/data/org.mozilla." + getAppName() +
|
|
|
|
"/components");
|
|
|
|
componentsDir.mkdir();
|
|
|
|
zip = new ZipFile(getApplication().getPackageResourcePath());
|
2010-09-02 05:35:46 +04:00
|
|
|
|
|
|
|
byte[] buf = new byte[8192];
|
|
|
|
unpackFile(zip, buf, null, "application.ini");
|
|
|
|
unpackFile(zip, buf, null, getContentProcessName());
|
|
|
|
try {
|
2010-09-30 19:53:42 +04:00
|
|
|
unpackFile(zip, buf, null, "update.locale");
|
|
|
|
} catch (Exception e) {/* this is non-fatal */}
|
2010-06-03 01:55:28 +04:00
|
|
|
|
2010-09-30 21:19:05 +04:00
|
|
|
// copy any .xpi file into an extensions/ directory
|
|
|
|
Enumeration<? extends ZipEntry> zipEntries = zip.entries();
|
|
|
|
while (zipEntries.hasMoreElements()) {
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
2010-06-03 01:55:28 +04:00
|
|
|
}
|
|
|
|
|
2010-09-30 19:53:42 +04:00
|
|
|
private void unpackFile(ZipFile zip, byte[] buf, ZipEntry fileEntry,
|
|
|
|
String name)
|
|
|
|
throws IOException, FileNotFoundException
|
2010-06-03 01:55:28 +04:00
|
|
|
{
|
|
|
|
if (fileEntry == null)
|
|
|
|
fileEntry = zip.getEntry(name);
|
2010-09-30 19:53:42 +04:00
|
|
|
if (fileEntry == null)
|
|
|
|
throw new FileNotFoundException("Can't find " + name + " in " +
|
|
|
|
zip.getName());
|
2010-06-03 01:55:28 +04:00
|
|
|
|
2010-09-30 19:53:42 +04:00
|
|
|
File outFile = new File("/data/data/org.mozilla." + getAppName() +
|
|
|
|
"/" + name);
|
2010-06-03 01:55:28 +04:00
|
|
|
if (outFile.exists() &&
|
2010-10-06 03:48:33 +04:00
|
|
|
outFile.lastModified() == fileEntry.getTime() &&
|
2010-06-03 01:55:28 +04:00
|
|
|
outFile.length() == fileEntry.getSize())
|
|
|
|
return;
|
|
|
|
|
2010-09-30 19:53:42 +04:00
|
|
|
File dir = outFile.getParentFile();
|
|
|
|
if (!outFile.exists())
|
|
|
|
dir.mkdirs();
|
2010-06-03 01:55:28 +04:00
|
|
|
|
|
|
|
InputStream fileStream;
|
2010-09-30 19:53:42 +04:00
|
|
|
fileStream = zip.getInputStream(fileEntry);
|
2010-06-03 01:55:28 +04:00
|
|
|
|
2010-09-30 19:53:42 +04:00
|
|
|
OutputStream outStream = new FileOutputStream(outFile);
|
2010-06-03 01:55:28 +04:00
|
|
|
|
2010-09-30 19:53:42 +04:00
|
|
|
while (fileStream.available() > 0) {
|
|
|
|
int read = fileStream.read(buf, 0, buf.length);
|
|
|
|
outStream.write(buf, 0, read);
|
2010-06-03 01:55:28 +04:00
|
|
|
}
|
2010-09-18 04:37:28 +04:00
|
|
|
|
2010-09-30 19:53:42 +04:00
|
|
|
fileStream.close();
|
|
|
|
outStream.close();
|
2010-09-18 04:37:28 +04:00
|
|
|
outFile.setLastModified(fileEntry.getTime());
|
2010-06-03 01:55:28 +04:00
|
|
|
}
|
2010-09-30 19:53:42 +04:00
|
|
|
|
2010-10-25 00:26:19 +04:00
|
|
|
public void addEnvToIntent(Intent intent) {
|
2010-06-03 01:55:28 +04:00
|
|
|
Map<String,String> envMap = System.getenv();
|
|
|
|
Set<Map.Entry<String,String>> envSet = envMap.entrySet();
|
|
|
|
Iterator<Map.Entry<String,String>> envIter = envSet.iterator();
|
|
|
|
StringBuffer envstr = new StringBuffer();
|
|
|
|
int c = 0;
|
|
|
|
while (envIter.hasNext()) {
|
|
|
|
Map.Entry<String,String> entry = envIter.next();
|
2010-10-25 00:26:19 +04:00
|
|
|
intent.putExtra("env" + c, entry.getKey() + "="
|
|
|
|
+ entry.getValue());
|
|
|
|
c++;
|
2010-06-03 01:55:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void doRestart() {
|
|
|
|
try {
|
|
|
|
String action = "org.mozilla.gecko.restart" + getAppName();
|
2010-10-25 00:26:19 +04:00
|
|
|
Intent intent = new Intent(action);
|
|
|
|
intent.setClassName("org.mozilla." + getAppName(),
|
|
|
|
"org.mozilla." + getAppName() + ".Restarter");
|
|
|
|
addEnvToIntent(intent);
|
2010-10-27 05:57:29 +04:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
2010-10-25 00:26:19 +04:00
|
|
|
Log.i("GeckoAppJava", intent.toString());
|
2010-10-27 05:57:29 +04:00
|
|
|
startActivity(intent);
|
2010-06-03 01:55:28 +04:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.i("GeckoAppJava", e.toString());
|
|
|
|
}
|
2010-10-25 00:26:19 +04:00
|
|
|
finish();
|
2010-06-03 01:55:28 +04:00
|
|
|
}
|
2010-06-15 06:17:37 +04:00
|
|
|
|
|
|
|
public void handleNotification(String action, String alertName, String alertCookie) {
|
|
|
|
GeckoAppShell.handleNotification(action, alertName, alertCookie);
|
|
|
|
}
|
2010-09-14 05:16:24 +04:00
|
|
|
|
|
|
|
private void checkAndLaunchUpdate() {
|
|
|
|
Log.i("GeckoAppJava", "Checking for an update");
|
|
|
|
|
|
|
|
int statusCode = 8; // UNEXPECTED_ERROR
|
|
|
|
|
|
|
|
String updateDir = "/data/data/org.mozilla." + getAppName() + "/updates/0/";
|
|
|
|
File updateFile = new File(updateDir + "update.apk");
|
|
|
|
|
|
|
|
if (!updateFile.exists())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Log.i("GeckoAppJava", "Update is available!");
|
|
|
|
|
|
|
|
// Launch APK
|
2010-09-17 22:03:43 +04:00
|
|
|
File updateFileToRun = new File(updateDir + getAppName() + "-update.apk");
|
2010-09-14 05:16:24 +04:00
|
|
|
try {
|
2010-09-17 22:03:43 +04:00
|
|
|
if (updateFile.renameTo(updateFileToRun)) {
|
2010-09-14 05:16:24 +04:00
|
|
|
String amCmd = "/system/bin/am start -a android.intent.action.VIEW " +
|
|
|
|
"-n com.android.packageinstaller/.PackageInstallerActivity -d file://" +
|
|
|
|
updateFileToRun.getPath();
|
|
|
|
Log.i("GeckoAppJava", amCmd);
|
|
|
|
Runtime.getRuntime().exec(amCmd);
|
|
|
|
statusCode = 0; // OK
|
|
|
|
} else {
|
2010-09-17 22:03:43 +04:00
|
|
|
Log.i("GeckoAppJava", "Cannot rename the update file!");
|
2010-09-14 05:16:24 +04:00
|
|
|
statusCode = 7; // WRITE_ERROR
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.i("GeckoAppJava", e.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the status file
|
|
|
|
String status = statusCode == 0 ? "succeeded\n" : "failed: "+ statusCode + "\n";
|
|
|
|
|
|
|
|
File statusFile = new File(updateDir + "update.status");
|
|
|
|
OutputStream outStream;
|
|
|
|
try {
|
|
|
|
byte[] buf = status.getBytes("UTF-8");
|
|
|
|
outStream = new FileOutputStream(statusFile);
|
|
|
|
outStream.write(buf, 0, buf.length);
|
|
|
|
outStream.close();
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.i("GeckoAppJava", e.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (statusCode == 0)
|
|
|
|
System.exit(0);
|
|
|
|
}
|
2010-09-30 19:37:36 +04:00
|
|
|
|
|
|
|
static final int FILE_PICKER_REQUEST = 1;
|
|
|
|
|
|
|
|
private SynchronousQueue<String> mFilePickerResult = new SynchronousQueue();
|
2010-11-05 20:43:12 +03:00
|
|
|
public String showFilePicker(String aMimeType) {
|
2010-09-30 19:37:36 +04:00
|
|
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
2010-11-05 20:43:12 +03:00
|
|
|
intent.setType(aMimeType);
|
2010-09-30 19:37:36 +04:00
|
|
|
GeckoApp.this.
|
|
|
|
startActivityForResult(
|
|
|
|
Intent.createChooser(intent,"choose a file"),
|
|
|
|
FILE_PICKER_REQUEST);
|
|
|
|
String filePickerResult = "";
|
|
|
|
try {
|
|
|
|
filePickerResult = mFilePickerResult.take();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
Log.i("GeckoApp", "error: " + e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return filePickerResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode,
|
|
|
|
Intent data) {
|
|
|
|
String filePickerResult = "";
|
|
|
|
if (data != null && resultCode == RESULT_OK) {
|
|
|
|
try {
|
|
|
|
ContentResolver cr = getContentResolver();
|
|
|
|
Uri uri = data.getData();
|
|
|
|
String mimeType = cr.getType(uri);
|
|
|
|
String fileExt = "." +
|
|
|
|
mimeType.substring(mimeType.lastIndexOf('/') + 1);
|
|
|
|
File file =
|
|
|
|
File.createTempFile("tmp_" +
|
|
|
|
(int)Math.floor(1000 * Math.random()),
|
|
|
|
fileExt,
|
|
|
|
new File("/data/data/org.mozilla." +
|
|
|
|
getAppName()));
|
|
|
|
|
|
|
|
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) {
|
|
|
|
Log.e("GeckoApp", "error : "+ e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
mFilePickerResult.put(filePickerResult);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
Log.i("GeckoApp", "error: " + e);
|
|
|
|
}
|
|
|
|
}
|
2010-06-03 01:55:28 +04:00
|
|
|
}
|