2011-11-18 10:28:17 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2011-12-20 07:28:12 -08:00
|
|
|
import org.mozilla.gecko.gfx.BitmapUtils;
|
2012-02-02 23:30:41 -08:00
|
|
|
import org.mozilla.gecko.gfx.GeckoLayerClient;
|
2012-07-11 11:13:49 -07:00
|
|
|
import org.mozilla.gecko.gfx.GfxInfoThread;
|
2012-04-24 12:13:36 -07:00
|
|
|
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
|
2012-07-27 17:53:54 -07:00
|
|
|
import org.mozilla.gecko.gfx.IntSize;
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
import org.mozilla.gecko.gfx.LayerController;
|
2011-11-18 10:28:17 -08:00
|
|
|
import org.mozilla.gecko.gfx.LayerView;
|
2012-06-14 09:08:51 -07:00
|
|
|
import org.mozilla.gecko.gfx.RectUtils;
|
2012-07-27 17:53:54 -07:00
|
|
|
import org.mozilla.gecko.gfx.ScreenshotLayer;
|
2012-07-31 15:54:29 -07:00
|
|
|
import org.mozilla.gecko.mozglue.DirectBufferAllocator;
|
2012-07-27 21:57:47 -07:00
|
|
|
import org.mozilla.gecko.util.FloatUtils;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-27 17:53:54 -07:00
|
|
|
import org.json.JSONObject;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.ActivityManager;
|
|
|
|
import android.app.NotificationManager;
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.content.ActivityNotFoundException;
|
|
|
|
import android.content.ClipData;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.ActivityInfo;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.ResolveInfo;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.content.res.TypedArray;
|
|
|
|
import android.graphics.Bitmap;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.ImageFormat;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.graphics.Rect;
|
|
|
|
import android.graphics.RectF;
|
|
|
|
import android.graphics.SurfaceTexture;
|
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.hardware.Sensor;
|
|
|
|
import android.hardware.SensorManager;
|
|
|
|
import android.location.Criteria;
|
|
|
|
import android.location.Location;
|
|
|
|
import android.location.LocationManager;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.media.MediaScannerConnection;
|
|
|
|
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
import android.net.NetworkInfo;
|
|
|
|
import android.net.Uri;
|
2012-04-24 18:39:10 -07:00
|
|
|
import android.opengl.GLES20;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Environment;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
|
|
|
import android.os.Message;
|
|
|
|
import android.os.MessageQueue;
|
|
|
|
import android.os.StatFs;
|
|
|
|
import android.os.Vibrator;
|
|
|
|
import android.provider.Settings;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.util.Base64;
|
|
|
|
import android.util.DisplayMetrics;
|
|
|
|
import android.util.FloatMath;
|
|
|
|
import android.util.Log;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.view.ContextThemeWrapper;
|
|
|
|
import android.view.HapticFeedbackConstants;
|
|
|
|
import android.view.Surface;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
import android.webkit.MimeTypeMap;
|
|
|
|
import android.widget.Toast;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-27 17:53:54 -07:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.Closeable;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.io.StringWriter;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
import java.text.DecimalFormatSymbols;
|
|
|
|
import java.text.NumberFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.NoSuchElementException;
|
|
|
|
import java.util.Queue;
|
|
|
|
import java.util.StringTokenizer;
|
|
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
|
import java.util.concurrent.SynchronousQueue;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
public class GeckoAppShell
|
|
|
|
{
|
2011-11-18 10:28:17 -08:00
|
|
|
private static final String LOGTAG = "GeckoAppShell";
|
|
|
|
|
|
|
|
// static members only
|
|
|
|
private GeckoAppShell() { }
|
|
|
|
|
|
|
|
static private LinkedList<GeckoEvent> gPendingEvents =
|
|
|
|
new LinkedList<GeckoEvent>();
|
|
|
|
|
|
|
|
static private boolean gRestartScheduled = false;
|
|
|
|
|
|
|
|
static private GeckoInputConnection mInputConnection = null;
|
|
|
|
|
|
|
|
static private final HashMap<Integer, AlertNotification>
|
|
|
|
mAlertNotifications = new HashMap<Integer, AlertNotification>();
|
|
|
|
|
|
|
|
/* Keep in sync with constants found here:
|
|
|
|
http://mxr.mozilla.org/mozilla-central/source/uriloader/base/nsIWebProgressListener.idl
|
|
|
|
*/
|
|
|
|
static public final int WPL_STATE_START = 0x00000001;
|
|
|
|
static public final int WPL_STATE_STOP = 0x00000010;
|
|
|
|
static public final int WPL_STATE_IS_DOCUMENT = 0x00020000;
|
2011-12-21 13:34:02 -08:00
|
|
|
static public final int WPL_STATE_IS_NETWORK = 0x00040000;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-04-19 21:54:50 -07:00
|
|
|
public static final String SHORTCUT_TYPE_WEBAPP = "webapp";
|
|
|
|
public static final String SHORTCUT_TYPE_BOOKMARK = "bookmark";
|
|
|
|
|
2012-05-14 14:48:04 -07:00
|
|
|
static public final int RESTORE_NONE = 0;
|
|
|
|
static public final int RESTORE_OOM = 1;
|
|
|
|
static public final int RESTORE_CRASH = 2;
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
static private File sCacheFile = null;
|
|
|
|
static private int sFreeSpace = -1;
|
2012-07-17 22:39:46 -07:00
|
|
|
static File sHomeDir = null;
|
2011-12-19 12:10:35 -08:00
|
|
|
static private int sDensityDpi = 0;
|
2012-01-19 12:19:56 -08:00
|
|
|
private static Boolean sSQLiteLibsLoaded = false;
|
2012-03-08 10:25:44 -08:00
|
|
|
private static Boolean sNSSLibsLoaded = false;
|
2012-03-08 10:25:44 -08:00
|
|
|
private static Boolean sLibsSetup = false;
|
|
|
|
private static File sGREDir = null;
|
2012-04-17 08:30:34 -07:00
|
|
|
private static Map<String, CopyOnWriteArrayList<GeckoEventListener>> mEventListeners
|
|
|
|
= new HashMap<String, CopyOnWriteArrayList<GeckoEventListener>>();
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-02-15 10:56:00 -08:00
|
|
|
/* Is the value in sVibrationEndTime valid? */
|
|
|
|
private static boolean sVibrationMaybePlaying = false;
|
|
|
|
|
|
|
|
/* Time (in System.nanoTime() units) when the currently-playing vibration
|
|
|
|
* is scheduled to end. This value is valid only when
|
|
|
|
* sVibrationMaybePlaying is true. */
|
|
|
|
private static long sVibrationEndTime = 0;
|
|
|
|
|
2012-03-13 16:57:09 -07:00
|
|
|
/* Default value of how fast we should hint the Android sensors. */
|
|
|
|
private static int sDefaultSensorHint = 100;
|
|
|
|
|
2012-03-13 16:57:51 -07:00
|
|
|
private static Sensor gAccelerometerSensor = null;
|
|
|
|
private static Sensor gLinearAccelerometerSensor = null;
|
|
|
|
private static Sensor gGyroscopeSensor = null;
|
|
|
|
private static Sensor gOrientationSensor = null;
|
|
|
|
private static Sensor gProximitySensor = null;
|
2012-05-02 09:43:45 -07:00
|
|
|
private static Sensor gLightSensor = null;
|
2012-03-13 16:57:51 -07:00
|
|
|
|
2012-03-21 10:52:35 -07:00
|
|
|
private static boolean mLocationHighAccuracy = false;
|
|
|
|
|
2012-05-03 07:53:31 -07:00
|
|
|
private static Handler sGeckoHandler;
|
|
|
|
|
2012-07-05 07:12:10 -07:00
|
|
|
public static GfxInfoThread sGfxInfoThread = null;
|
|
|
|
|
2012-07-13 11:08:19 -07:00
|
|
|
static ActivityHandlerHelper sActivityHelper = new ActivityHandlerHelper();
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
/* The Android-side API: API methods that Android calls */
|
|
|
|
|
|
|
|
// Initialization methods
|
|
|
|
public static native void nativeInit();
|
|
|
|
public static native void nativeRun(String args);
|
|
|
|
|
|
|
|
// helper methods
|
|
|
|
// public static native void setSurfaceView(GeckoSurfaceView sv);
|
2012-02-17 06:16:14 -08:00
|
|
|
public static native void setLayerClient(GeckoLayerClient client);
|
2011-11-18 10:28:17 -08:00
|
|
|
public static native void putenv(String map);
|
|
|
|
public static native void onResume();
|
|
|
|
public static native void onLowMemory();
|
|
|
|
public static native void callObserver(String observerKey, String topic, String data);
|
|
|
|
public static native void removeObserver(String observerKey);
|
2012-01-19 12:19:56 -08:00
|
|
|
public static native void loadGeckoLibsNative(String apkName);
|
2012-03-17 12:32:44 -07:00
|
|
|
public static native void loadSQLiteLibsNative(String apkName, boolean shouldExtract);
|
|
|
|
public static native void loadNSSLibsNative(String apkName, boolean shouldExtract);
|
2011-11-18 10:28:17 -08:00
|
|
|
public static native void onChangeNetworkLinkStatus(String status);
|
2012-05-31 17:07:07 -07:00
|
|
|
public static native Message getNextMessageFromQueue(MessageQueue queue);
|
2012-07-20 12:20:51 -07:00
|
|
|
public static native void onSurfaceTextureFrameAvailable(Object surfaceTexture, int id);
|
2012-01-23 12:03:25 -08:00
|
|
|
|
2012-03-07 11:19:05 -08:00
|
|
|
public static void registerGlobalExceptionHandler() {
|
|
|
|
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
|
|
|
public void uncaughtException(Thread thread, Throwable e) {
|
|
|
|
Log.e(LOGTAG, ">>> REPORTING UNCAUGHT EXCEPTION FROM THREAD "
|
|
|
|
+ thread.getId() + " (\"" + thread.getName() + "\")", e);
|
2012-03-28 17:51:02 -07:00
|
|
|
|
|
|
|
// If the uncaught exception was rethrown, walk the exception `cause` chain to find
|
|
|
|
// the original exception so Socorro can correctly collate related crash reports.
|
|
|
|
Throwable cause;
|
|
|
|
while ((cause = e.getCause()) != null) {
|
|
|
|
e = cause;
|
|
|
|
}
|
|
|
|
|
2012-03-07 11:19:05 -08:00
|
|
|
reportJavaCrash(getStackTraceString(e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getStackTraceString(Throwable e) {
|
2012-01-23 12:03:25 -08:00
|
|
|
StringWriter sw = new StringWriter();
|
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
|
e.printStackTrace(pw);
|
|
|
|
pw.flush();
|
2012-03-07 11:19:05 -08:00
|
|
|
return sw.toString();
|
2012-01-23 12:03:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private static native void reportJavaCrash(String stackTrace);
|
|
|
|
|
2012-01-05 16:14:23 -08:00
|
|
|
public static void notifyUriVisited(String uri) {
|
2012-02-08 23:18:27 -08:00
|
|
|
sendEventToGecko(GeckoEvent.createVisitedEvent(uri));
|
2012-01-05 16:14:23 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
public static native void processNextNativeEvent();
|
|
|
|
|
|
|
|
public static native void notifyBatteryChange(double aLevel, boolean aCharging, double aRemainingTime);
|
|
|
|
|
2011-11-24 05:10:20 -08:00
|
|
|
public static native void notifySmsReceived(String aSender, String aBody, long aTimestamp);
|
2012-01-17 10:52:17 -08:00
|
|
|
public static native int saveMessageInSentbox(String aReceiver, String aBody, long aTimestamp);
|
|
|
|
public static native void notifySmsSent(int aId, String aReceiver, String aBody, long aTimestamp, int aRequestId, long aProcessId);
|
|
|
|
public static native void notifySmsDelivered(int aId, String aReceiver, String aBody, long aTimestamp);
|
|
|
|
public static native void notifySmsSendFailed(int aError, int aRequestId, long aProcessId);
|
|
|
|
public static native void notifyGetSms(int aId, String aReceiver, String aSender, String aBody, long aTimestamp, int aRequestId, long aProcessId);
|
|
|
|
public static native void notifyGetSmsFailed(int aError, int aRequestId, long aProcessId);
|
|
|
|
public static native void notifySmsDeleted(boolean aDeleted, int aRequestId, long aProcessId);
|
|
|
|
public static native void notifySmsDeleteFailed(int aError, int aRequestId, long aProcessId);
|
|
|
|
public static native void notifyNoMessageInList(int aRequestId, long aProcessId);
|
|
|
|
public static native void notifyListCreated(int aListId, int aMessageId, String aReceiver, String aSender, String aBody, long aTimestamp, int aRequestId, long aProcessId);
|
|
|
|
public static native void notifyGotNextMessage(int aMessageId, String aReceiver, String aSender, String aBody, long aTimestamp, int aRequestId, long aProcessId);
|
|
|
|
public static native void notifyReadingMessageListFailed(int aError, int aRequestId, long aProcessId);
|
|
|
|
|
2012-02-03 18:35:58 -08:00
|
|
|
public static native void scheduleComposite();
|
2012-02-05 10:33:38 -08:00
|
|
|
public static native void schedulePauseComposition();
|
2012-04-20 08:46:30 -07:00
|
|
|
public static native void scheduleResumeComposition(int width, int height);
|
2011-11-24 05:10:20 -08:00
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
public static native SurfaceBits getSurfaceBits(Surface surface);
|
|
|
|
|
2012-05-30 09:10:49 -07:00
|
|
|
public static native void onFullScreenPluginHidden(View view);
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
private static class GeckoMediaScannerClient implements MediaScannerConnectionClient {
|
2011-11-18 10:28:17 -08:00
|
|
|
private String mFile = "";
|
|
|
|
private String mMimeType = "";
|
|
|
|
private MediaScannerConnection mScanner = null;
|
|
|
|
|
|
|
|
public GeckoMediaScannerClient(Context aContext, String aFile, String aMimeType) {
|
|
|
|
mFile = aFile;
|
|
|
|
mMimeType = aMimeType;
|
|
|
|
mScanner = new MediaScannerConnection(aContext, this);
|
|
|
|
if (mScanner != null)
|
|
|
|
mScanner.connect();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onMediaScannerConnected() {
|
|
|
|
mScanner.scanFile(mFile, mMimeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onScanCompleted(String path, Uri uri) {
|
|
|
|
if(path.equals(mFile)) {
|
|
|
|
mScanner.disconnect();
|
|
|
|
mScanner = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a Handler for the main java thread
|
|
|
|
public static Handler getMainHandler() {
|
|
|
|
return GeckoApp.mAppContext.mMainHandler;
|
|
|
|
}
|
|
|
|
|
2012-05-03 07:53:31 -07:00
|
|
|
public static Handler getGeckoHandler() {
|
|
|
|
return sGeckoHandler;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public static Handler getHandler() {
|
2012-02-26 22:34:23 -08:00
|
|
|
return GeckoBackgroundThread.getHandler();
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
public static File getCacheDir(Context context) {
|
2011-11-18 10:28:17 -08:00
|
|
|
if (sCacheFile == null)
|
2012-03-08 10:25:44 -08:00
|
|
|
sCacheFile = context.getCacheDir();
|
2011-11-18 10:28:17 -08:00
|
|
|
return sCacheFile;
|
|
|
|
}
|
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
public static long getFreeSpace(Context context) {
|
2011-11-18 10:28:17 -08:00
|
|
|
try {
|
|
|
|
if (sFreeSpace == -1) {
|
2012-03-08 10:25:44 -08:00
|
|
|
File cacheDir = getCacheDir(context);
|
2011-11-18 10:28:17 -08:00
|
|
|
if (cacheDir != null) {
|
|
|
|
StatFs cacheStats = new StatFs(cacheDir.getPath());
|
|
|
|
sFreeSpace = cacheStats.getFreeBlocks() *
|
|
|
|
cacheStats.getBlockSize();
|
|
|
|
} else {
|
|
|
|
Log.i(LOGTAG, "Unable to get cache dir");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "exception while stating cache dir: ", e);
|
|
|
|
}
|
|
|
|
return sFreeSpace;
|
|
|
|
}
|
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
public static File getGREDir(Context context) {
|
|
|
|
if (sGREDir == null)
|
|
|
|
sGREDir = new File(context.getApplicationInfo().dataDir);
|
|
|
|
return sGREDir;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
// java-side stuff
|
2012-03-08 10:25:44 -08:00
|
|
|
public static void loadLibsSetup(Context context) {
|
|
|
|
if (sLibsSetup)
|
|
|
|
return;
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
// 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.
|
2012-03-08 10:25:44 -08:00
|
|
|
GeckoProfile profile = GeckoProfile.get(context);
|
|
|
|
|
|
|
|
File cacheFile = getCacheDir(context);
|
|
|
|
putenv("GRE_HOME=" + getGREDir(context).getPath());
|
2012-02-25 20:22:40 -08:00
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
// setup the libs cache
|
|
|
|
String linkerCache = System.getenv("MOZ_LINKER_CACHE");
|
2012-05-02 04:15:07 -07:00
|
|
|
if (linkerCache == null) {
|
|
|
|
linkerCache = cacheFile.getPath();
|
|
|
|
GeckoAppShell.putenv("MOZ_LINKER_CACHE=" + linkerCache);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GeckoApp.mAppContext != null &&
|
|
|
|
GeckoApp.mAppContext.linkerExtract()) {
|
|
|
|
GeckoAppShell.putenv("MOZ_LINKER_EXTRACT=1");
|
|
|
|
// Ensure that the cache dir is world-writable
|
|
|
|
File cacheDir = new File(linkerCache);
|
|
|
|
if (cacheDir.isDirectory()) {
|
|
|
|
cacheDir.setWritable(true, false);
|
|
|
|
cacheDir.setExecutable(true, false);
|
|
|
|
cacheDir.setReadable(true, false);
|
|
|
|
}
|
2012-03-08 10:25:44 -08:00
|
|
|
}
|
2012-05-02 04:15:07 -07:00
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
sLibsSetup = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void setupPluginEnvironment(GeckoApp context) {
|
|
|
|
// setup plugin path directories
|
2011-11-18 10:28:17 -08:00
|
|
|
try {
|
2012-03-08 10:25:44 -08:00
|
|
|
String[] dirs = context.getPluginDirectories();
|
2012-07-25 21:44:11 -07:00
|
|
|
// Check to see if plugins were blocked.
|
|
|
|
if (dirs == null) {
|
|
|
|
GeckoAppShell.putenv("MOZ_PLUGINS_BLOCKED=1");
|
|
|
|
GeckoAppShell.putenv("MOZ_PLUGIN_PATH=");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
StringBuffer pluginSearchPath = new StringBuffer();
|
|
|
|
for (int i = 0; i < dirs.length; i++) {
|
|
|
|
Log.i(LOGTAG, "dir: " + dirs[i]);
|
|
|
|
pluginSearchPath.append(dirs[i]);
|
|
|
|
pluginSearchPath.append(":");
|
|
|
|
}
|
|
|
|
GeckoAppShell.putenv("MOZ_PLUGIN_PATH="+pluginSearchPath);
|
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
File pluginDataDir = context.getDir("plugins", 0);
|
|
|
|
GeckoAppShell.putenv("ANDROID_PLUGIN_DATADIR=" + pluginDataDir.getPath());
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
} catch (Exception ex) {
|
|
|
|
Log.i(LOGTAG, "exception getting plugin dirs", ex);
|
2012-02-23 01:57:56 -08:00
|
|
|
}
|
2012-03-08 10:25:44 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
private static void setupDownloadEnvironment(GeckoApp context) {
|
2011-11-18 10:28:17 -08:00
|
|
|
try {
|
|
|
|
File downloadDir = null;
|
|
|
|
File updatesDir = null;
|
|
|
|
if (Build.VERSION.SDK_INT >= 8) {
|
|
|
|
downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
2012-03-08 10:25:44 -08:00
|
|
|
updatesDir = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
|
2012-07-19 11:26:59 -07:00
|
|
|
}
|
|
|
|
if (downloadDir == null) {
|
|
|
|
downloadDir = new File(Environment.getExternalStorageDirectory().getPath(), "download");
|
|
|
|
}
|
|
|
|
if (updatesDir == null) {
|
|
|
|
updatesDir = downloadDir;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
GeckoAppShell.putenv("DOWNLOADS_DIRECTORY=" + downloadDir.getPath());
|
|
|
|
GeckoAppShell.putenv("UPDATES_DIRECTORY=" + updatesDir.getPath());
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2012-07-23 12:04:28 -07:00
|
|
|
Log.i(LOGTAG, "No download directory has been found: ", e);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-03-08 10:25:44 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
public static void setupGeckoEnvironment(Context context) {
|
|
|
|
GeckoProfile profile = GeckoProfile.get(context);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
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);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-03-08 10:25:44 -08:00
|
|
|
// 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());
|
|
|
|
|
2012-05-23 01:36:39 -07:00
|
|
|
// Enable fixed position layers
|
|
|
|
GeckoAppShell.putenv("MOZ_ENABLE_FIXED_POSITION_LAYERS=1");
|
|
|
|
|
2012-06-11 13:06:07 -07:00
|
|
|
// setup the app-specific cache path
|
|
|
|
f = context.getCacheDir();
|
|
|
|
GeckoAppShell.putenv("CACHE_DIRECTORY=" + f.getPath());
|
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
putLocaleEnv();
|
2012-01-19 12:19:56 -08:00
|
|
|
}
|
|
|
|
|
2012-03-22 10:35:19 -07:00
|
|
|
/* This method is referenced by Robocop via reflection. */
|
2012-03-08 10:25:44 -08:00
|
|
|
public static void loadSQLiteLibs(Context context, String apkName) {
|
2012-01-19 12:19:56 -08:00
|
|
|
if (sSQLiteLibsLoaded)
|
|
|
|
return;
|
|
|
|
synchronized(sSQLiteLibsLoaded) {
|
|
|
|
if (sSQLiteLibsLoaded)
|
|
|
|
return;
|
2012-03-08 10:25:44 -08:00
|
|
|
loadMozGlue();
|
|
|
|
// the extract libs parameter is being removed in bug 732069
|
2012-03-09 10:23:00 -08:00
|
|
|
loadLibsSetup(context);
|
2012-03-17 12:32:44 -07:00
|
|
|
loadSQLiteLibsNative(apkName, false);
|
2012-01-19 12:19:56 -08:00
|
|
|
sSQLiteLibsLoaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
public static void loadNSSLibs(Context context, String apkName) {
|
|
|
|
if (sNSSLibsLoaded)
|
|
|
|
return;
|
|
|
|
synchronized(sNSSLibsLoaded) {
|
|
|
|
if (sNSSLibsLoaded)
|
|
|
|
return;
|
|
|
|
loadMozGlue();
|
|
|
|
loadLibsSetup(context);
|
2012-03-17 12:32:44 -07:00
|
|
|
loadNSSLibsNative(apkName, false);
|
2012-03-08 10:25:44 -08:00
|
|
|
sNSSLibsLoaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
public static void loadMozGlue() {
|
|
|
|
System.loadLibrary("mozglue");
|
|
|
|
}
|
|
|
|
|
2012-01-19 12:19:56 -08:00
|
|
|
public static void loadGeckoLibs(String apkName) {
|
2012-03-08 10:25:44 -08:00
|
|
|
loadLibsSetup(GeckoApp.mAppContext);
|
2012-01-19 12:19:56 -08:00
|
|
|
loadGeckoLibsNative(apkName);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void putLocaleEnv() {
|
|
|
|
GeckoAppShell.putenv("LANG=" + Locale.getDefault().toString());
|
|
|
|
NumberFormat nf = NumberFormat.getInstance();
|
|
|
|
if (nf instanceof DecimalFormat) {
|
|
|
|
DecimalFormat df = (DecimalFormat)nf;
|
|
|
|
DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
|
|
|
|
|
|
|
|
GeckoAppShell.putenv("LOCALE_DECIMAL_POINT=" + dfs.getDecimalSeparator());
|
|
|
|
GeckoAppShell.putenv("LOCALE_THOUSANDS_SEP=" + dfs.getGroupingSeparator());
|
|
|
|
GeckoAppShell.putenv("LOCALE_GROUPING=" + (char)df.getGroupingSize());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-14 14:48:04 -07:00
|
|
|
public static void runGecko(String apkPath, String args, String url, String type, int restoreMode) {
|
2012-06-18 10:03:03 -07:00
|
|
|
WebAppAllocator.getInstance();
|
|
|
|
|
2012-05-03 07:53:31 -07:00
|
|
|
Looper.prepare();
|
|
|
|
sGeckoHandler = new Handler();
|
2012-06-18 10:03:03 -07:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
// run gecko -- it will spawn its own thread
|
|
|
|
GeckoAppShell.nativeInit();
|
|
|
|
|
|
|
|
Log.i(LOGTAG, "post native init");
|
|
|
|
|
|
|
|
// Tell Gecko where the target byte buffer is for rendering
|
2012-02-17 06:16:14 -08:00
|
|
|
GeckoAppShell.setLayerClient(GeckoApp.mAppContext.getLayerClient());
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-02-02 23:30:41 -08:00
|
|
|
Log.i(LOGTAG, "setLayerClient called");
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
// First argument is the .apk path
|
|
|
|
String combinedArgs = apkPath + " -greomni " + apkPath;
|
|
|
|
if (args != null)
|
|
|
|
combinedArgs += " " + args;
|
|
|
|
if (url != null)
|
2012-04-13 19:45:25 -07:00
|
|
|
combinedArgs += " -url " + url;
|
|
|
|
if (type != null)
|
|
|
|
combinedArgs += " " + type;
|
2012-05-14 14:48:04 -07:00
|
|
|
if (restoreMode != RESTORE_NONE)
|
|
|
|
combinedArgs += " -restoremode " + restoreMode;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-08-01 14:56:26 -07:00
|
|
|
DisplayMetrics metrics = GeckoApp.mAppContext.getResources().getDisplayMetrics();
|
2012-01-20 06:36:08 -08:00
|
|
|
combinedArgs += " -width " + metrics.widthPixels + " -height " + metrics.heightPixels;
|
|
|
|
|
2011-12-12 00:27:34 -08:00
|
|
|
GeckoApp.mAppContext.runOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
geckoLoaded();
|
|
|
|
}
|
|
|
|
});
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
// and go
|
|
|
|
GeckoAppShell.nativeRun(combinedArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called on the UI thread after Gecko loads.
|
|
|
|
private static void geckoLoaded() {
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
final LayerController layerController = GeckoApp.mAppContext.getLayerController();
|
|
|
|
LayerView v = layerController.getView();
|
2012-01-26 11:23:13 -08:00
|
|
|
mInputConnection = v.setInputConnectionHandler();
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
layerController.notifyLayerClientOfGeometryChange();
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2011-11-23 23:04:26 -08:00
|
|
|
|
2012-01-30 16:53:14 -08:00
|
|
|
static void sendPendingEventsToGecko() {
|
2011-11-18 10:28:17 -08:00
|
|
|
try {
|
|
|
|
while (!gPendingEvents.isEmpty()) {
|
|
|
|
GeckoEvent e = gPendingEvents.removeFirst();
|
|
|
|
notifyGeckoOfEvent(e);
|
|
|
|
}
|
|
|
|
} catch (NoSuchElementException e) {}
|
|
|
|
}
|
|
|
|
|
2012-03-22 10:35:19 -07:00
|
|
|
/* This method is referenced by Robocop via reflection. */
|
2011-11-18 10:28:17 -08:00
|
|
|
public static void sendEventToGecko(GeckoEvent e) {
|
2012-01-24 09:16:48 -08:00
|
|
|
if (GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning)) {
|
2011-11-18 10:28:17 -08:00
|
|
|
notifyGeckoOfEvent(e);
|
|
|
|
} else {
|
|
|
|
gPendingEvents.addLast(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void sendEventToGeckoSync(GeckoEvent e) {
|
|
|
|
sendEventToGecko(e);
|
|
|
|
geckoEventSync();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell the Gecko event loop that an event is available.
|
|
|
|
public static native void notifyGeckoOfEvent(GeckoEvent event);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The Gecko-side API: API methods that Gecko calls
|
|
|
|
*/
|
|
|
|
public static void notifyIME(int type, int state) {
|
2011-12-21 15:14:46 -08:00
|
|
|
if (mInputConnection != null)
|
|
|
|
mInputConnection.notifyIME(type, state);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void notifyIMEEnabled(int state, String typeHint,
|
|
|
|
String actionHint, boolean landscapeFS) {
|
2012-03-13 14:22:54 -07:00
|
|
|
// notifyIMEEnabled() still needs the landscapeFS parameter because it is called from JNI
|
|
|
|
// code that assumes it has the same signature as XUL Fennec's (which does use landscapeFS).
|
2011-12-21 15:14:46 -08:00
|
|
|
if (mInputConnection != null)
|
2012-03-13 14:22:54 -07:00
|
|
|
mInputConnection.notifyIMEEnabled(state, typeHint, actionHint);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void notifyIMEChange(String text, int start, int end, int newEnd) {
|
2011-12-21 15:14:46 -08:00
|
|
|
if (mInputConnection != null)
|
|
|
|
mInputConnection.notifyIMEChange(text, start, end, newEnd);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-04-24 12:13:36 -07:00
|
|
|
// Called by AndroidBridge using JNI
|
2012-06-14 09:08:51 -07:00
|
|
|
public static void notifyScreenShot(final ByteBuffer data, final int tabId,
|
|
|
|
final int left, final int top,
|
|
|
|
final int right, final int bottom,
|
|
|
|
final int bufferWidth, final int bufferHeight, final int token) {
|
|
|
|
ScreenshotHandler.notifyScreenShot(data, tabId, left, top, right, bottom, bufferWidth, bufferHeight, token);
|
2012-02-03 22:48:26 -08:00
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
private static CountDownLatch sGeckoPendingAcks = null;
|
|
|
|
|
|
|
|
// Block the current thread until the Gecko event loop is caught up
|
|
|
|
synchronized public static void geckoEventSync() {
|
|
|
|
sGeckoPendingAcks = new CountDownLatch(1);
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createSyncEvent());
|
2011-11-18 10:28:17 -08:00
|
|
|
while (sGeckoPendingAcks.getCount() != 0) {
|
|
|
|
try {
|
|
|
|
sGeckoPendingAcks.await();
|
2012-01-31 06:40:58 -08:00
|
|
|
} catch(InterruptedException e) {}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
sGeckoPendingAcks = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Signal the Java thread that it's time to wake up
|
|
|
|
public static void acknowledgeEventSync() {
|
|
|
|
CountDownLatch tmp = sGeckoPendingAcks;
|
|
|
|
if (tmp != null)
|
|
|
|
tmp.countDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void enableLocation(final boolean enable) {
|
|
|
|
getMainHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
LocationManager lm = (LocationManager)
|
|
|
|
GeckoApp.mAppContext.getSystemService(Context.LOCATION_SERVICE);
|
|
|
|
|
|
|
|
if (enable) {
|
2012-01-13 16:01:58 -08:00
|
|
|
Criteria criteria = new Criteria();
|
2012-03-21 10:52:35 -07:00
|
|
|
criteria.setSpeedRequired(false);
|
|
|
|
criteria.setBearingRequired(false);
|
|
|
|
criteria.setAltitudeRequired(false);
|
|
|
|
if (mLocationHighAccuracy) {
|
|
|
|
criteria.setAccuracy(Criteria.ACCURACY_FINE);
|
|
|
|
criteria.setCostAllowed(true);
|
|
|
|
criteria.setPowerRequirement(Criteria.POWER_HIGH);
|
|
|
|
} else {
|
|
|
|
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
|
|
|
|
criteria.setCostAllowed(false);
|
|
|
|
criteria.setPowerRequirement(Criteria.POWER_LOW);
|
|
|
|
}
|
|
|
|
|
2012-01-13 16:01:58 -08:00
|
|
|
String provider = lm.getBestProvider(criteria, true);
|
2011-11-18 10:28:17 -08:00
|
|
|
if (provider == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Looper l = Looper.getMainLooper();
|
|
|
|
Location loc = lm.getLastKnownLocation(provider);
|
|
|
|
if (loc != null) {
|
|
|
|
GeckoApp.mAppContext.onLocationChanged(loc);
|
|
|
|
}
|
|
|
|
lm.requestLocationUpdates(provider, 100, (float).5, GeckoApp.mAppContext, l);
|
|
|
|
} else {
|
|
|
|
lm.removeUpdates(GeckoApp.mAppContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-03-21 10:52:35 -07:00
|
|
|
public static void enableLocationHighAccuracy(final boolean enable) {
|
|
|
|
Log.i(LOGTAG, "Location provider - high accuracy: " + enable);
|
|
|
|
mLocationHighAccuracy = enable;
|
|
|
|
}
|
|
|
|
|
2012-02-05 11:54:25 -08:00
|
|
|
public static void enableSensor(int aSensortype) {
|
|
|
|
SensorManager sm = (SensorManager)
|
|
|
|
GeckoApp.mAppContext.getSystemService(Context.SENSOR_SERVICE);
|
|
|
|
|
|
|
|
switch(aSensortype) {
|
2012-03-13 16:57:51 -07:00
|
|
|
case GeckoHalDefines.SENSOR_ORIENTATION:
|
2012-03-20 23:36:17 -07:00
|
|
|
Log.i(LOGTAG, "Enabling SENSOR_ORIENTATION");
|
2012-03-13 16:57:51 -07:00
|
|
|
if(gOrientationSensor == null)
|
|
|
|
gOrientationSensor = sm.getDefaultSensor(Sensor.TYPE_ORIENTATION);
|
|
|
|
if (gOrientationSensor != null)
|
|
|
|
sm.registerListener(GeckoApp.mAppContext, gOrientationSensor, sDefaultSensorHint);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoHalDefines.SENSOR_ACCELERATION:
|
2012-03-20 23:36:17 -07:00
|
|
|
Log.i(LOGTAG, "Enabling SENSOR_ACCELERATION");
|
2012-03-13 16:57:51 -07:00
|
|
|
if(gAccelerometerSensor == null)
|
|
|
|
gAccelerometerSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
|
|
|
if (gAccelerometerSensor != null)
|
|
|
|
sm.registerListener(GeckoApp.mAppContext, gAccelerometerSensor, sDefaultSensorHint);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoHalDefines.SENSOR_PROXIMITY:
|
2012-03-20 23:36:17 -07:00
|
|
|
Log.i(LOGTAG, "Enabling SENSOR_PROXIMITY");
|
2012-02-05 11:54:25 -08:00
|
|
|
if(gProximitySensor == null)
|
|
|
|
gProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
2012-03-13 16:57:51 -07:00
|
|
|
if (gProximitySensor != null)
|
2012-05-02 09:43:45 -07:00
|
|
|
sm.registerListener(GeckoApp.mAppContext, gProximitySensor, SensorManager.SENSOR_DELAY_NORMAL);
|
2012-03-13 16:57:51 -07:00
|
|
|
break;
|
|
|
|
|
2012-05-02 09:43:45 -07:00
|
|
|
case GeckoHalDefines.SENSOR_LIGHT:
|
|
|
|
Log.i(LOGTAG, "Enabling SENSOR_LIGHT");
|
|
|
|
if(gLightSensor == null)
|
|
|
|
gLightSensor = sm.getDefaultSensor(Sensor.TYPE_LIGHT);
|
|
|
|
if (gLightSensor != null)
|
|
|
|
sm.registerListener(GeckoApp.mAppContext, gLightSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
|
|
|
break;
|
|
|
|
|
2012-03-13 16:57:51 -07:00
|
|
|
case GeckoHalDefines.SENSOR_LINEAR_ACCELERATION:
|
2012-03-20 23:36:17 -07:00
|
|
|
Log.i(LOGTAG, "Enabling SENSOR_LINEAR_ACCELERATION");
|
2012-03-13 16:57:51 -07:00
|
|
|
if(gLinearAccelerometerSensor == null)
|
2012-03-20 23:36:17 -07:00
|
|
|
gLinearAccelerometerSensor = sm.getDefaultSensor(10 /* API Level 9 - TYPE_LINEAR_ACCELERATION */);
|
2012-03-13 16:57:51 -07:00
|
|
|
if (gLinearAccelerometerSensor != null)
|
|
|
|
sm.registerListener(GeckoApp.mAppContext, gLinearAccelerometerSensor, sDefaultSensorHint);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoHalDefines.SENSOR_GYROSCOPE:
|
2012-03-20 23:36:17 -07:00
|
|
|
Log.i(LOGTAG, "Enabling SENSOR_GYROSCOPE");
|
2012-03-13 16:57:51 -07:00
|
|
|
if(gGyroscopeSensor == null)
|
|
|
|
gGyroscopeSensor = sm.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
|
|
|
|
if (gGyroscopeSensor != null)
|
|
|
|
sm.registerListener(GeckoApp.mAppContext, gGyroscopeSensor, sDefaultSensorHint);
|
2012-02-05 11:54:25 -08:00
|
|
|
break;
|
2012-03-20 23:36:17 -07:00
|
|
|
default:
|
|
|
|
Log.e(LOGTAG, "Error! SENSOR type used " + aSensortype);
|
2012-02-05 11:54:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void disableSensor(int aSensortype) {
|
|
|
|
SensorManager sm = (SensorManager)
|
|
|
|
GeckoApp.mAppContext.getSystemService(Context.SENSOR_SERVICE);
|
|
|
|
|
2012-03-13 16:57:51 -07:00
|
|
|
switch (aSensortype) {
|
|
|
|
case GeckoHalDefines.SENSOR_ORIENTATION:
|
2012-03-20 23:36:17 -07:00
|
|
|
Log.i(LOGTAG, "Disabling SENSOR_ORIENTATION");
|
2012-03-13 16:57:51 -07:00
|
|
|
if (gOrientationSensor != null)
|
|
|
|
sm.unregisterListener(GeckoApp.mAppContext, gOrientationSensor);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoHalDefines.SENSOR_ACCELERATION:
|
2012-03-20 23:36:17 -07:00
|
|
|
Log.i(LOGTAG, "Disabling SENSOR_ACCELERATION");
|
2012-03-13 16:57:51 -07:00
|
|
|
if (gAccelerometerSensor != null)
|
|
|
|
sm.unregisterListener(GeckoApp.mAppContext, gAccelerometerSensor);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoHalDefines.SENSOR_PROXIMITY:
|
2012-03-20 23:36:17 -07:00
|
|
|
Log.i(LOGTAG, "Disabling SENSOR_PROXIMITY");
|
2012-03-13 16:57:51 -07:00
|
|
|
if (gProximitySensor != null)
|
|
|
|
sm.unregisterListener(GeckoApp.mAppContext, gProximitySensor);
|
|
|
|
break;
|
|
|
|
|
2012-05-02 09:43:45 -07:00
|
|
|
case GeckoHalDefines.SENSOR_LIGHT:
|
|
|
|
Log.i(LOGTAG, "Disabling SENSOR_LIGHT");
|
|
|
|
if (gLightSensor != null)
|
|
|
|
sm.unregisterListener(GeckoApp.mAppContext, gLightSensor);
|
|
|
|
break;
|
|
|
|
|
2012-03-13 16:57:51 -07:00
|
|
|
case GeckoHalDefines.SENSOR_LINEAR_ACCELERATION:
|
2012-03-20 23:36:17 -07:00
|
|
|
Log.i(LOGTAG, "Disabling SENSOR_LINEAR_ACCELERATION");
|
2012-03-13 16:57:51 -07:00
|
|
|
if (gLinearAccelerometerSensor != null)
|
|
|
|
sm.unregisterListener(GeckoApp.mAppContext, gLinearAccelerometerSensor);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoHalDefines.SENSOR_GYROSCOPE:
|
2012-03-20 23:36:17 -07:00
|
|
|
Log.i(LOGTAG, "Disabling SENSOR_GYROSCOPE");
|
2012-03-13 16:57:51 -07:00
|
|
|
if (gGyroscopeSensor != null)
|
|
|
|
sm.unregisterListener(GeckoApp.mAppContext, gGyroscopeSensor);
|
2012-02-05 11:54:25 -08:00
|
|
|
break;
|
2012-03-20 23:36:17 -07:00
|
|
|
default:
|
|
|
|
Log.e(LOGTAG, "Error! SENSOR type used " + aSensortype);
|
2012-02-05 11:54:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public static void moveTaskToBack() {
|
|
|
|
GeckoApp.mAppContext.moveTaskToBack(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void returnIMEQueryResult(String result, int selectionStart, int selectionLength) {
|
2012-03-23 14:00:19 -07:00
|
|
|
// This method may be called from JNI to report Gecko's current selection indexes, but
|
|
|
|
// Native Fennec doesn't care because the Java code already knows the selection indexes.
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static void onXreExit() {
|
2011-11-18 10:28:17 -08:00
|
|
|
// mLaunchState can only be Launched or GeckoRunning at this point
|
2012-01-24 09:16:48 -08:00
|
|
|
GeckoApp.setLaunchState(GeckoApp.LaunchState.GeckoExiting);
|
2011-11-18 10:28:17 -08:00
|
|
|
Log.i(LOGTAG, "XRE exited");
|
|
|
|
if (gRestartScheduled) {
|
|
|
|
GeckoApp.mAppContext.doRestart();
|
|
|
|
} else {
|
|
|
|
Log.i(LOGTAG, "we're done, good bye");
|
|
|
|
GeckoApp.mAppContext.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.w(LOGTAG, "Killing via System.exit()");
|
|
|
|
System.exit(0);
|
|
|
|
}
|
2012-06-18 10:03:03 -07:00
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static void scheduleRestart() {
|
2011-11-18 10:28:17 -08:00
|
|
|
Log.i(LOGTAG, "scheduling restart");
|
|
|
|
gRestartScheduled = true;
|
|
|
|
}
|
|
|
|
|
2012-08-06 09:30:12 -07:00
|
|
|
public static File installWebApp(String aTitle, String aURI, String aUniqueURI, String aIconURL) {
|
|
|
|
int index = WebAppAllocator.getInstance(GeckoApp.mAppContext).findAndAllocateIndex(aUniqueURI);
|
|
|
|
GeckoProfile profile = GeckoProfile.get(GeckoApp.mAppContext, "webapp" + index);
|
|
|
|
createShortcut(aTitle, aURI, aUniqueURI, aIconURL, "webapp");
|
|
|
|
return profile.getDir();
|
|
|
|
}
|
|
|
|
|
2012-06-18 10:03:03 -07:00
|
|
|
public static Intent getWebAppIntent(String aURI, String aUniqueURI, boolean forInstall) {
|
|
|
|
int index;
|
|
|
|
|
|
|
|
if (forInstall)
|
|
|
|
index = WebAppAllocator.getInstance(GeckoApp.mAppContext).findAndAllocateIndex(aUniqueURI);
|
|
|
|
else
|
|
|
|
index = WebAppAllocator.getInstance(GeckoApp.mAppContext).getIndexForApp(aUniqueURI);
|
|
|
|
|
|
|
|
if (index == -1)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setAction(GeckoApp.ACTION_WEBAPP_PREFIX + index);
|
|
|
|
intent.setData(Uri.parse(aURI));
|
|
|
|
intent.setClassName(GeckoApp.mAppContext, GeckoApp.mAppContext.getPackageName() + ".WebApps$WebApp" + index);
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
// "Installs" an application by creating a shortcut
|
2012-06-18 10:03:03 -07:00
|
|
|
// This is the entry point from AndroidBridge.h
|
2012-07-17 22:39:46 -07:00
|
|
|
static void createShortcut(String aTitle, String aURI, String aIconData, String aType) {
|
2012-06-18 10:03:03 -07:00
|
|
|
if ("webapp".equals(aType)) {
|
|
|
|
Log.e(LOGTAG, "createShortcut with no unique URI should not be used for aType = webapp!");
|
|
|
|
}
|
|
|
|
|
|
|
|
byte[] raw = Base64.decode(aIconData.substring(22), Base64.DEFAULT);
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeByteArray(raw, 0, raw.length);
|
|
|
|
createShortcut(aTitle, aURI, aURI, bitmap, aType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// internal, for non-webapps
|
|
|
|
static void createShortcut(String aTitle, String aURI, Bitmap aBitmap, String aType) {
|
|
|
|
createShortcut(aTitle, aURI, aURI, aBitmap, aType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// internal, for webapps
|
2012-07-17 22:39:46 -07:00
|
|
|
static void createShortcut(String aTitle, String aURI, String aUniqueURI, String aIconData, String aType) {
|
2011-12-20 07:28:12 -08:00
|
|
|
byte[] raw = Base64.decode(aIconData.substring(22), Base64.DEFAULT);
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeByteArray(raw, 0, raw.length);
|
2012-06-18 10:03:03 -07:00
|
|
|
createShortcut(aTitle, aURI, aUniqueURI, bitmap, aType);
|
2011-12-20 07:28:12 -08:00
|
|
|
}
|
|
|
|
|
2012-06-18 10:03:03 -07:00
|
|
|
public static void createShortcut(final String aTitle, final String aURI, final String aUniqueURI,
|
|
|
|
final Bitmap aIcon, final String aType)
|
|
|
|
{
|
2011-12-20 07:28:12 -08:00
|
|
|
getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
// the intent to be launched by the shortcut
|
2012-06-18 10:03:03 -07:00
|
|
|
Intent shortcutIntent;
|
2012-04-19 21:54:50 -07:00
|
|
|
if (aType.equalsIgnoreCase(SHORTCUT_TYPE_WEBAPP)) {
|
2012-06-18 10:03:03 -07:00
|
|
|
shortcutIntent = getWebAppIntent(aURI, aUniqueURI, true);
|
2011-12-20 07:28:12 -08:00
|
|
|
} else {
|
2012-06-18 10:03:03 -07:00
|
|
|
shortcutIntent = new Intent();
|
2012-01-28 09:24:51 -08:00
|
|
|
shortcutIntent.setAction(GeckoApp.ACTION_BOOKMARK);
|
|
|
|
shortcutIntent.setData(Uri.parse(aURI));
|
2012-06-18 10:03:03 -07:00
|
|
|
shortcutIntent.setClassName(GeckoApp.mAppContext,
|
|
|
|
GeckoApp.mAppContext.getPackageName() + ".App");
|
2011-12-20 07:28:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
|
|
|
if (aTitle != null)
|
|
|
|
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, aTitle);
|
|
|
|
else
|
|
|
|
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, aURI);
|
2012-04-19 21:54:50 -07:00
|
|
|
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, getLauncherIcon(aIcon, aType));
|
2012-04-19 21:54:48 -07:00
|
|
|
|
|
|
|
// Do not allow duplicate items
|
|
|
|
intent.putExtra("duplicate", false);
|
|
|
|
|
2011-12-20 07:28:12 -08:00
|
|
|
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
|
|
|
GeckoApp.mAppContext.sendBroadcast(intent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-06-06 13:52:14 -07:00
|
|
|
public static void removeShortcut(final String aTitle, final String aURI, final String aType) {
|
2012-06-18 10:03:03 -07:00
|
|
|
removeShortcut(aTitle, aURI, null, aType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void removeShortcut(final String aTitle, final String aURI, final String aUniqueURI, final String aType) {
|
2012-06-06 13:52:14 -07:00
|
|
|
getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
// the intent to be launched by the shortcut
|
2012-06-18 10:03:03 -07:00
|
|
|
Intent shortcutIntent;
|
2012-06-06 13:52:14 -07:00
|
|
|
if (aType.equalsIgnoreCase(SHORTCUT_TYPE_WEBAPP)) {
|
2012-06-18 10:03:03 -07:00
|
|
|
int index = WebAppAllocator.getInstance(GeckoApp.mAppContext).findAndAllocateIndex(aUniqueURI);
|
|
|
|
shortcutIntent = getWebAppIntent(aURI, aUniqueURI, false);
|
|
|
|
if (shortcutIntent == null)
|
|
|
|
return;
|
2012-06-06 13:52:14 -07:00
|
|
|
} else {
|
2012-06-18 10:03:03 -07:00
|
|
|
shortcutIntent = new Intent();
|
2012-06-06 13:52:14 -07:00
|
|
|
shortcutIntent.setAction(GeckoApp.ACTION_BOOKMARK);
|
2012-06-18 10:03:03 -07:00
|
|
|
shortcutIntent.setClassName(GeckoApp.mAppContext,
|
|
|
|
GeckoApp.mAppContext.getPackageName() + ".App");
|
|
|
|
shortcutIntent.setData(Uri.parse(aURI));
|
2012-06-06 13:52:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
|
|
|
if (aTitle != null)
|
|
|
|
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, aTitle);
|
|
|
|
else
|
|
|
|
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, aURI);
|
|
|
|
|
|
|
|
intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
|
|
|
|
GeckoApp.mAppContext.sendBroadcast(intent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-06-18 10:03:03 -07:00
|
|
|
public static void uninstallWebApp(final String uniqueURI) {
|
|
|
|
// On uninstall, we need to do a couple of things:
|
|
|
|
// 1. nuke the running app process.
|
|
|
|
// 2. nuke the profile that was assigned to that webapp
|
|
|
|
getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
int index = WebAppAllocator.getInstance(GeckoApp.mAppContext).releaseIndexForApp(uniqueURI);
|
|
|
|
|
|
|
|
// if -1, nothing to do; we didn't think it was installed anyway
|
|
|
|
if (index == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// kill the app if it's running
|
|
|
|
String targetProcessName = GeckoApp.mAppContext.getPackageName();
|
|
|
|
targetProcessName = targetProcessName + ":" + targetProcessName + ".WebApp" + index;
|
|
|
|
|
|
|
|
ActivityManager am = (ActivityManager) GeckoApp.mAppContext.getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
|
List<ActivityManager.RunningAppProcessInfo> procs = am.getRunningAppProcesses();
|
|
|
|
if (procs != null) {
|
|
|
|
for (ActivityManager.RunningAppProcessInfo proc : procs) {
|
|
|
|
if (proc.processName.equals(targetProcessName)) {
|
|
|
|
android.os.Process.killProcess(proc.pid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// then nuke the profile
|
|
|
|
GeckoProfile.removeProfile(GeckoApp.mAppContext, "webapp" + index);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:54:50 -07:00
|
|
|
static private Bitmap getLauncherIcon(Bitmap aSource, String aType) {
|
2011-12-20 07:28:12 -08:00
|
|
|
final int kOffset = 6;
|
|
|
|
final int kRadius = 5;
|
2012-01-04 12:52:22 -08:00
|
|
|
int kIconSize;
|
|
|
|
int kOverlaySize;
|
|
|
|
switch (getDpi()) {
|
|
|
|
case DisplayMetrics.DENSITY_MEDIUM:
|
|
|
|
kIconSize = 48;
|
|
|
|
kOverlaySize = 32;
|
|
|
|
break;
|
|
|
|
case DisplayMetrics.DENSITY_XHIGH:
|
|
|
|
kIconSize = 96;
|
|
|
|
kOverlaySize = 48;
|
|
|
|
break;
|
|
|
|
case DisplayMetrics.DENSITY_HIGH:
|
|
|
|
default:
|
|
|
|
kIconSize = 72;
|
|
|
|
kOverlaySize = 32;
|
|
|
|
}
|
2011-12-20 07:28:12 -08:00
|
|
|
|
|
|
|
Bitmap bitmap = Bitmap.createBitmap(kIconSize, kIconSize, Bitmap.Config.ARGB_8888);
|
|
|
|
Canvas canvas = new Canvas(bitmap);
|
|
|
|
|
2012-04-19 21:54:50 -07:00
|
|
|
if (aType.equalsIgnoreCase(SHORTCUT_TYPE_WEBAPP)) {
|
|
|
|
Rect iconBounds = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
|
|
|
|
canvas.drawBitmap(aSource, null, iconBounds, null);
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
2011-12-20 07:28:12 -08:00
|
|
|
// draw a base color
|
|
|
|
Paint paint = new Paint();
|
|
|
|
if (aSource == null) {
|
|
|
|
float[] hsv = new float[3];
|
|
|
|
hsv[0] = 32.0f;
|
|
|
|
hsv[1] = 1.0f;
|
|
|
|
hsv[2] = 1.0f;
|
|
|
|
paint.setColor(Color.HSVToColor(hsv));
|
|
|
|
canvas.drawRoundRect(new RectF(kOffset, kOffset, kIconSize - kOffset, kIconSize - kOffset), kRadius, kRadius, paint);
|
|
|
|
} else {
|
|
|
|
int color = BitmapUtils.getDominantColor(aSource);
|
|
|
|
paint.setColor(color);
|
|
|
|
canvas.drawRoundRect(new RectF(kOffset, kOffset, kIconSize - kOffset, kIconSize - kOffset), kRadius, kRadius, paint);
|
|
|
|
paint.setColor(Color.argb(100, 255, 255, 255));
|
|
|
|
canvas.drawRoundRect(new RectF(kOffset, kOffset, kIconSize - kOffset, kIconSize - kOffset), kRadius, kRadius, paint);
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-12-20 07:28:12 -08:00
|
|
|
// draw the overlay
|
|
|
|
Bitmap overlay = BitmapFactory.decodeResource(GeckoApp.mAppContext.getResources(), R.drawable.home_bg);
|
2012-01-04 12:52:22 -08:00
|
|
|
canvas.drawBitmap(overlay, null, new Rect(0, 0, kIconSize, kIconSize), null);
|
2011-12-20 07:28:12 -08:00
|
|
|
|
|
|
|
// draw the bitmap
|
|
|
|
if (aSource == null)
|
|
|
|
aSource = BitmapFactory.decodeResource(GeckoApp.mAppContext.getResources(), R.drawable.home_star);
|
|
|
|
|
|
|
|
if (aSource.getWidth() < kOverlaySize || aSource.getHeight() < kOverlaySize) {
|
|
|
|
canvas.drawBitmap(aSource,
|
|
|
|
null,
|
|
|
|
new Rect(kIconSize/2 - kOverlaySize/2,
|
|
|
|
kIconSize/2 - kOverlaySize/2,
|
|
|
|
kIconSize/2 + kOverlaySize/2,
|
|
|
|
kIconSize/2 + kOverlaySize/2),
|
|
|
|
null);
|
2011-11-18 10:28:17 -08:00
|
|
|
} else {
|
2011-12-20 07:28:12 -08:00
|
|
|
canvas.drawBitmap(aSource,
|
|
|
|
null,
|
|
|
|
new Rect(kIconSize/2 - aSource.getWidth()/2,
|
|
|
|
kIconSize/2 - aSource.getHeight()/2,
|
|
|
|
kIconSize/2 + aSource.getWidth()/2,
|
|
|
|
kIconSize/2 + aSource.getHeight()/2),
|
|
|
|
null);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-12-20 07:28:12 -08:00
|
|
|
return bitmap;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static String[] getHandlersForMimeType(String aMimeType, String aAction) {
|
2011-11-18 10:28:17 -08:00
|
|
|
Intent intent = getIntentForActionString(aAction);
|
|
|
|
if (aMimeType != null && aMimeType.length() > 0)
|
|
|
|
intent.setType(aMimeType);
|
|
|
|
return getHandlersForIntent(intent);
|
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static String[] getHandlersForURL(String aURL, String aAction) {
|
2011-11-18 10:28:17 -08:00
|
|
|
// aURL may contain the whole URL or just the protocol
|
|
|
|
Uri uri = aURL.indexOf(':') >= 0 ? Uri.parse(aURL) : new Uri.Builder().scheme(aURL).build();
|
|
|
|
Intent intent = getIntentForActionString(aAction);
|
|
|
|
intent.setData(uri);
|
|
|
|
return getHandlersForIntent(intent);
|
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static String[] getHandlersForIntent(Intent intent) {
|
2011-11-18 10:28:17 -08:00
|
|
|
PackageManager pm = GeckoApp.mAppContext.getPackageManager();
|
|
|
|
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
|
|
|
|
int numAttr = 4;
|
|
|
|
String[] ret = new String[list.size() * numAttr];
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
ResolveInfo resolveInfo = list.get(i);
|
|
|
|
ret[i * numAttr] = resolveInfo.loadLabel(pm).toString();
|
|
|
|
if (resolveInfo.isDefault)
|
|
|
|
ret[i * numAttr + 1] = "default";
|
|
|
|
else
|
|
|
|
ret[i * numAttr + 1] = "";
|
|
|
|
ret[i * numAttr + 2] = resolveInfo.activityInfo.applicationInfo.packageName;
|
|
|
|
ret[i * numAttr + 3] = resolveInfo.activityInfo.name;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static Intent getIntentForActionString(String aAction) {
|
2011-11-18 10:28:17 -08:00
|
|
|
// Default to the view action if no other action as been specified.
|
|
|
|
if (aAction != null && aAction.length() > 0)
|
|
|
|
return new Intent(aAction);
|
|
|
|
else
|
|
|
|
return new Intent(Intent.ACTION_VIEW);
|
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static String getExtensionFromMimeType(String aMimeType) {
|
2011-11-18 10:28:17 -08:00
|
|
|
return MimeTypeMap.getSingleton().getExtensionFromMimeType(aMimeType);
|
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static String getMimeTypeFromExtensions(String aFileExt) {
|
2011-11-18 10:28:17 -08:00
|
|
|
MimeTypeMap mtm = MimeTypeMap.getSingleton();
|
|
|
|
StringTokenizer st = new StringTokenizer(aFileExt, "., ");
|
|
|
|
String type = null;
|
|
|
|
String subType = null;
|
|
|
|
while (st.hasMoreElements()) {
|
|
|
|
String ext = st.nextToken();
|
|
|
|
String mt = mtm.getMimeTypeFromExtension(ext);
|
|
|
|
if (mt == null)
|
|
|
|
continue;
|
|
|
|
int slash = mt.indexOf('/');
|
|
|
|
String tmpType = mt.substring(0, slash);
|
|
|
|
if (!tmpType.equalsIgnoreCase(type))
|
|
|
|
type = type == null ? tmpType : "*";
|
|
|
|
String tmpSubType = mt.substring(slash + 1);
|
|
|
|
if (!tmpSubType.equalsIgnoreCase(subType))
|
|
|
|
subType = subType == null ? tmpSubType : "*";
|
|
|
|
}
|
|
|
|
if (type == null)
|
|
|
|
type = "*";
|
|
|
|
if (subType == null)
|
|
|
|
subType = "*";
|
|
|
|
return type + "/" + subType;
|
|
|
|
}
|
|
|
|
|
2012-07-10 14:25:15 -07:00
|
|
|
static void safeStreamClose(Closeable stream) {
|
|
|
|
try {
|
|
|
|
if (stream != null)
|
|
|
|
stream.close();
|
|
|
|
} catch (IOException e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shareImage(String aSrc, String aType) {
|
|
|
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
boolean isDataURI = aSrc.startsWith("data:");
|
|
|
|
OutputStream os = null;
|
|
|
|
File dir = GeckoApp.getTempDirectory();
|
2012-07-19 14:36:48 -07:00
|
|
|
|
|
|
|
if (dir == null) {
|
|
|
|
showImageShareFailureToast();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-10 14:25:15 -07:00
|
|
|
GeckoApp.deleteTempFiles();
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Create a temporary file for the image
|
|
|
|
File imageFile = File.createTempFile("image",
|
|
|
|
"." + aType.replace("image/",""),
|
|
|
|
dir);
|
|
|
|
os = new FileOutputStream(imageFile);
|
|
|
|
|
|
|
|
if (isDataURI) {
|
|
|
|
// We are dealing with a Data URI
|
|
|
|
int dataStart = aSrc.indexOf(',');
|
|
|
|
byte[] buf = Base64.decode(aSrc.substring(dataStart+1), Base64.DEFAULT);
|
|
|
|
os.write(buf);
|
|
|
|
} else {
|
|
|
|
// We are dealing with a URL
|
|
|
|
InputStream is = null;
|
|
|
|
try {
|
|
|
|
URL url = new URL(aSrc);
|
|
|
|
is = url.openStream();
|
|
|
|
byte[] buf = new byte[2048];
|
|
|
|
int length;
|
|
|
|
|
|
|
|
while ((length = is.read(buf)) != -1) {
|
|
|
|
os.write(buf, 0, length);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
safeStreamClose(is);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile));
|
|
|
|
|
|
|
|
// If we were able to determine the image type, send that in the intent. Otherwise,
|
|
|
|
// use a generic type.
|
|
|
|
if (aType.startsWith("image/")) {
|
|
|
|
intent.setType(aType);
|
|
|
|
} else {
|
|
|
|
intent.setType("image/*");
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
if (!isDataURI) {
|
|
|
|
// If we failed, at least send through the URL link
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, aSrc);
|
|
|
|
intent.setType("text/plain");
|
|
|
|
} else {
|
2012-07-19 14:36:48 -07:00
|
|
|
showImageShareFailureToast();
|
2012-07-10 14:25:15 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
safeStreamClose(os);
|
|
|
|
}
|
|
|
|
GeckoApp.mAppContext.startActivity(Intent.createChooser(intent,
|
|
|
|
GeckoApp.mAppContext.getResources().getString(R.string.share_title)));
|
|
|
|
}
|
|
|
|
|
2012-07-19 14:36:48 -07:00
|
|
|
// Don't fail silently, tell the user that we weren't able to share the image
|
|
|
|
private static final void showImageShareFailureToast() {
|
|
|
|
Toast toast = Toast.makeText(GeckoApp.mAppContext,
|
|
|
|
GeckoApp.mAppContext.getResources().getString(R.string.share_image_failed),
|
|
|
|
Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static boolean openUriExternal(String aUriSpec, String aMimeType, String aPackageName,
|
|
|
|
String aClassName, String aAction, String aTitle) {
|
2011-11-18 10:28:17 -08:00
|
|
|
Intent intent = getIntentForActionString(aAction);
|
|
|
|
if (aAction.equalsIgnoreCase(Intent.ACTION_SEND)) {
|
2012-02-24 16:21:42 -08:00
|
|
|
Intent shareIntent = getIntentForActionString(aAction);
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_TEXT, aUriSpec);
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_SUBJECT, aTitle);
|
2011-11-18 10:28:17 -08:00
|
|
|
if (aMimeType != null && aMimeType.length() > 0)
|
2012-02-24 16:21:42 -08:00
|
|
|
shareIntent.setType(aMimeType);
|
|
|
|
intent = Intent.createChooser(shareIntent, GeckoApp.mAppContext.getResources().getString(R.string.share_title));
|
2011-11-18 10:28:17 -08:00
|
|
|
} else if (aMimeType.length() > 0) {
|
|
|
|
intent.setDataAndType(Uri.parse(aUriSpec), aMimeType);
|
|
|
|
} else {
|
|
|
|
Uri uri = Uri.parse(aUriSpec);
|
|
|
|
if ("sms".equals(uri.getScheme())) {
|
|
|
|
// Have a apecial handling for the SMS, as the message body
|
|
|
|
// is not extracted from the URI automatically
|
|
|
|
final String query = uri.getEncodedQuery();
|
|
|
|
if (query != null && query.length() > 0) {
|
|
|
|
final String[] fields = query.split("&");
|
|
|
|
boolean foundBody = false;
|
|
|
|
String resultQuery = "";
|
|
|
|
for (int i = 0; i < fields.length; i++) {
|
|
|
|
final String field = fields[i];
|
|
|
|
if (field.length() > 5 && "body=".equals(field.substring(0, 5))) {
|
|
|
|
final String body = Uri.decode(field.substring(5));
|
|
|
|
intent.putExtra("sms_body", body);
|
|
|
|
foundBody = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
resultQuery = resultQuery.concat(resultQuery.length() > 0 ? "&" + field : field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (foundBody) {
|
|
|
|
// Put the query without the body field back into the URI
|
|
|
|
final String prefix = aUriSpec.substring(0, aUriSpec.indexOf('?'));
|
|
|
|
uri = Uri.parse(resultQuery.length() > 0 ? prefix + "?" + resultQuery : prefix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
intent.setData(uri);
|
|
|
|
}
|
|
|
|
if (aPackageName.length() > 0 && aClassName.length() > 0)
|
|
|
|
intent.setClassName(aPackageName, aClassName);
|
|
|
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
try {
|
|
|
|
GeckoApp.mAppContext.startActivity(intent);
|
|
|
|
return true;
|
|
|
|
} catch(ActivityNotFoundException e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static SynchronousQueue<String> sClipboardQueue =
|
|
|
|
new SynchronousQueue<String>();
|
|
|
|
private static String EMPTY_STRING = new String();
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
// On some devices, access to the clipboard service needs to happen
|
|
|
|
// on a thread with a looper, so dispatch this to our looper thread
|
|
|
|
// Note: the main looper won't work because it may be blocked on the
|
|
|
|
// gecko thread, which is most likely this thread
|
2012-01-30 16:53:14 -08:00
|
|
|
static String getClipboardText() {
|
|
|
|
getHandler().post(new Runnable() {
|
2012-07-17 22:39:46 -07:00
|
|
|
@SuppressWarnings("deprecation")
|
2011-11-18 10:28:17 -08:00
|
|
|
public void run() {
|
|
|
|
Context context = GeckoApp.mAppContext;
|
|
|
|
String text = null;
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
|
|
|
android.content.ClipboardManager cm = (android.content.ClipboardManager)
|
|
|
|
context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
if (cm.hasPrimaryClip()) {
|
|
|
|
ClipData clip = cm.getPrimaryClip();
|
|
|
|
if (clip != null) {
|
|
|
|
ClipData.Item item = clip.getItemAt(0);
|
|
|
|
text = item.coerceToText(context).toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
android.text.ClipboardManager cm = (android.text.ClipboardManager)
|
|
|
|
context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
if (cm.hasText())
|
|
|
|
text = cm.getText().toString();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
sClipboardQueue.put(text != null ? text : EMPTY_STRING);
|
|
|
|
} catch (InterruptedException ie) {}
|
|
|
|
}});
|
|
|
|
try {
|
|
|
|
String ret = sClipboardQueue.take();
|
2012-01-03 09:19:44 -08:00
|
|
|
return (EMPTY_STRING.equals(ret) ? null : ret);
|
2011-11-18 10:28:17 -08:00
|
|
|
} catch (InterruptedException ie) {}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-01-30 16:53:14 -08:00
|
|
|
static void setClipboardText(final String text) {
|
|
|
|
getHandler().post(new Runnable() {
|
2012-07-17 22:39:46 -07:00
|
|
|
@SuppressWarnings("deprecation")
|
2011-11-18 10:28:17 -08:00
|
|
|
public void run() {
|
|
|
|
Context context = GeckoApp.mAppContext;
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
|
|
|
android.content.ClipboardManager cm = (android.content.ClipboardManager)
|
|
|
|
context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
cm.setPrimaryClip(ClipData.newPlainText("Text", text));
|
|
|
|
} else {
|
|
|
|
android.text.ClipboardManager cm = (android.text.ClipboardManager)
|
|
|
|
context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
cm.setText(text);
|
|
|
|
}
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void showAlertNotification(String aImageUrl, String aAlertTitle, String aAlertText,
|
|
|
|
String aAlertCookie, String aAlertName) {
|
|
|
|
Log.i(LOGTAG, "GeckoAppShell.showAlertNotification\n" +
|
|
|
|
"- image = '" + aImageUrl + "'\n" +
|
|
|
|
"- title = '" + aAlertTitle + "'\n" +
|
|
|
|
"- text = '" + aAlertText +"'\n" +
|
|
|
|
"- cookie = '" + aAlertCookie +"'\n" +
|
|
|
|
"- name = '" + aAlertName + "'");
|
|
|
|
|
|
|
|
int icon = R.drawable.icon; // Just use the app icon by default
|
|
|
|
|
|
|
|
Uri imageUri = Uri.parse(aImageUrl);
|
|
|
|
String scheme = imageUri.getScheme();
|
|
|
|
if ("drawable".equals(scheme)) {
|
|
|
|
String resource = imageUri.getSchemeSpecificPart();
|
|
|
|
resource = resource.substring(resource.lastIndexOf('/') + 1);
|
|
|
|
try {
|
2012-02-14 12:28:27 -08:00
|
|
|
Class<R.drawable> drawableClass = R.drawable.class;
|
2011-11-18 10:28:17 -08:00
|
|
|
Field f = drawableClass.getField(resource);
|
|
|
|
icon = f.getInt(null);
|
|
|
|
} catch (Exception e) {} // just means the resource doesn't exist
|
|
|
|
imageUri = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
int notificationID = aAlertName.hashCode();
|
|
|
|
|
|
|
|
// Remove the old notification with the same ID, if any
|
|
|
|
removeNotification(notificationID);
|
|
|
|
|
|
|
|
AlertNotification notification =
|
|
|
|
new AlertNotification(GeckoApp.mAppContext,notificationID, icon,
|
|
|
|
aAlertTitle, aAlertText,
|
|
|
|
System.currentTimeMillis());
|
|
|
|
|
|
|
|
// The intent to launch when the user clicks the expanded notification
|
|
|
|
Intent notificationIntent = new Intent(GeckoApp.ACTION_ALERT_CLICK);
|
|
|
|
notificationIntent.setClassName(GeckoApp.mAppContext,
|
|
|
|
GeckoApp.mAppContext.getPackageName() + ".NotificationHandler");
|
|
|
|
|
|
|
|
// Put the strings into the intent as an URI "alert:<name>#<cookie>"
|
|
|
|
Uri dataUri = Uri.fromParts("alert", aAlertName, aAlertCookie);
|
|
|
|
notificationIntent.setData(dataUri);
|
|
|
|
|
|
|
|
PendingIntent contentIntent = PendingIntent.getBroadcast(GeckoApp.mAppContext, 0, notificationIntent, 0);
|
|
|
|
notification.setLatestEventInfo(GeckoApp.mAppContext, aAlertTitle, aAlertText, contentIntent);
|
|
|
|
notification.setCustomIcon(imageUri);
|
|
|
|
// The intent to execute when the status entry is deleted by the user with the "Clear All Notifications" button
|
|
|
|
Intent clearNotificationIntent = new Intent(GeckoApp.ACTION_ALERT_CLEAR);
|
|
|
|
clearNotificationIntent.setClassName(GeckoApp.mAppContext,
|
|
|
|
GeckoApp.mAppContext.getPackageName() + ".NotificationHandler");
|
|
|
|
clearNotificationIntent.setData(dataUri);
|
|
|
|
notification.deleteIntent = PendingIntent.getBroadcast(GeckoApp.mAppContext, 0, clearNotificationIntent, 0);
|
|
|
|
|
|
|
|
mAlertNotifications.put(notificationID, notification);
|
|
|
|
|
|
|
|
notification.show();
|
|
|
|
|
|
|
|
Log.i(LOGTAG, "Created notification ID " + notificationID);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void alertsProgressListener_OnProgress(String aAlertName, long aProgress, long aProgressMax, String aAlertText) {
|
|
|
|
Log.i(LOGTAG, "GeckoAppShell.alertsProgressListener_OnProgress\n" +
|
|
|
|
"- name = '" + aAlertName +"', " +
|
|
|
|
"progress = " + aProgress +" / " + aProgressMax + ", text = '" + aAlertText + "'");
|
|
|
|
|
|
|
|
int notificationID = aAlertName.hashCode();
|
|
|
|
AlertNotification notification = mAlertNotifications.get(notificationID);
|
|
|
|
if (notification != null)
|
|
|
|
notification.updateProgress(aAlertText, aProgress, aProgressMax);
|
|
|
|
|
|
|
|
if (aProgress == aProgressMax) {
|
|
|
|
// Hide the notification at 100%
|
|
|
|
removeObserver(aAlertName);
|
|
|
|
removeNotification(notificationID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void alertsProgressListener_OnCancel(String aAlertName) {
|
|
|
|
Log.i(LOGTAG, "GeckoAppShell.alertsProgressListener_OnCancel('" + aAlertName + "')");
|
|
|
|
|
|
|
|
removeObserver(aAlertName);
|
|
|
|
|
|
|
|
int notificationID = aAlertName.hashCode();
|
|
|
|
removeNotification(notificationID);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void handleNotification(String aAction, String aAlertName, String aAlertCookie) {
|
|
|
|
int notificationID = aAlertName.hashCode();
|
|
|
|
|
|
|
|
if (GeckoApp.ACTION_ALERT_CLICK.equals(aAction)) {
|
|
|
|
Log.i(LOGTAG, "GeckoAppShell.handleNotification: callObserver(alertclickcallback)");
|
|
|
|
callObserver(aAlertName, "alertclickcallback", aAlertCookie);
|
|
|
|
|
|
|
|
AlertNotification notification = mAlertNotifications.get(notificationID);
|
|
|
|
if (notification != null && notification.isProgressStyle()) {
|
|
|
|
// When clicked, keep the notification, if it displays a progress
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callObserver(aAlertName, "alertfinished", aAlertCookie);
|
|
|
|
|
|
|
|
removeObserver(aAlertName);
|
|
|
|
|
|
|
|
removeNotification(notificationID);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void removeNotification(int notificationID) {
|
|
|
|
mAlertNotifications.remove(notificationID);
|
|
|
|
|
|
|
|
NotificationManager notificationManager = (NotificationManager)
|
|
|
|
GeckoApp.mAppContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
notificationManager.cancel(notificationID);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getDpi() {
|
2011-12-19 12:10:35 -08:00
|
|
|
if (sDensityDpi == 0) {
|
2012-08-01 14:56:26 -07:00
|
|
|
sDensityDpi = GeckoApp.mAppContext.getResources().getDisplayMetrics().densityDpi;
|
2011-12-19 12:10:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return sDensityDpi;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void setFullScreen(boolean fullscreen) {
|
|
|
|
GeckoApp.mAppContext.setFullScreen(fullscreen);
|
|
|
|
}
|
|
|
|
|
2012-03-18 09:15:56 -07:00
|
|
|
public static String showFilePickerForExtensions(String aExtensions) {
|
2012-07-13 11:08:19 -07:00
|
|
|
return sActivityHelper.showFilePicker(GeckoApp.mAppContext, getMimeTypeFromExtensions(aExtensions));
|
2012-03-18 09:15:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String showFilePickerForMimeType(String aMimeType) {
|
2012-07-13 11:08:19 -07:00
|
|
|
return sActivityHelper.showFilePicker(GeckoApp.mAppContext, aMimeType);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void performHapticFeedback(boolean aIsLongPress) {
|
2012-02-15 10:56:00 -08:00
|
|
|
// Don't perform haptic feedback if a vibration is currently playing,
|
|
|
|
// because the haptic feedback will nuke the vibration.
|
|
|
|
if (!sVibrationMaybePlaying || System.nanoTime() >= sVibrationEndTime) {
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
LayerController layerController = GeckoApp.mAppContext.getLayerController();
|
|
|
|
LayerView layerView = layerController.getView();
|
2012-02-15 10:56:00 -08:00
|
|
|
layerView.performHapticFeedback(aIsLongPress ?
|
|
|
|
HapticFeedbackConstants.LONG_PRESS :
|
|
|
|
HapticFeedbackConstants.VIRTUAL_KEY);
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private static Vibrator vibrator() {
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
LayerController layerController = GeckoApp.mAppContext.getLayerController();
|
|
|
|
LayerView layerView = layerController.getView();
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
return (Vibrator) layerView.getContext().getSystemService(Context.VIBRATOR_SERVICE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void vibrate(long milliseconds) {
|
2012-02-15 10:56:00 -08:00
|
|
|
sVibrationEndTime = System.nanoTime() + milliseconds * 1000000;
|
|
|
|
sVibrationMaybePlaying = true;
|
2011-11-18 10:28:17 -08:00
|
|
|
vibrator().vibrate(milliseconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void vibrate(long[] pattern, int repeat) {
|
2012-02-15 10:56:00 -08:00
|
|
|
// If pattern.length is even, the last element in the pattern is a
|
|
|
|
// meaningless delay, so don't include it in vibrationDuration.
|
|
|
|
long vibrationDuration = 0;
|
|
|
|
int iterLen = pattern.length - (pattern.length % 2 == 0 ? 1 : 0);
|
|
|
|
for (int i = 0; i < iterLen; i++) {
|
|
|
|
vibrationDuration += pattern[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
sVibrationEndTime = System.nanoTime() + vibrationDuration * 1000000;
|
|
|
|
sVibrationMaybePlaying = true;
|
2011-11-18 10:28:17 -08:00
|
|
|
vibrator().vibrate(pattern, repeat);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void cancelVibrate() {
|
2012-02-15 10:56:00 -08:00
|
|
|
sVibrationMaybePlaying = false;
|
|
|
|
sVibrationEndTime = 0;
|
2011-11-18 10:28:17 -08:00
|
|
|
vibrator().cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void showInputMethodPicker() {
|
|
|
|
InputMethodManager imm = (InputMethodManager)
|
|
|
|
GeckoApp.mAppContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
imm.showInputMethodPicker();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setKeepScreenOn(final boolean on) {
|
|
|
|
GeckoApp.mAppContext.runOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-04-07 00:09:26 -07:00
|
|
|
public static void notifyDefaultPrevented(final boolean defaultPrevented) {
|
2012-01-24 16:31:33 -08:00
|
|
|
getMainHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
LayerView view = GeckoApp.mAppContext.getLayerController().getView();
|
2012-04-07 00:09:26 -07:00
|
|
|
view.getTouchEventHandler().handleEventListenerAction(!defaultPrevented);
|
2012-01-24 16:31:33 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public static boolean isNetworkLinkUp() {
|
|
|
|
ConnectivityManager cm = (ConnectivityManager)
|
|
|
|
GeckoApp.mAppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
NetworkInfo info = cm.getActiveNetworkInfo();
|
|
|
|
if (info == null || !info.isConnected())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isNetworkLinkKnown() {
|
|
|
|
ConnectivityManager cm = (ConnectivityManager)
|
|
|
|
GeckoApp.mAppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
if (cm.getActiveNetworkInfo() == null)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setSelectedLocale(String localeCode) {
|
2012-01-30 19:59:47 -08:00
|
|
|
/* Bug 713464: This method is still called from Gecko side.
|
|
|
|
Earlier we had an option to run Firefox in a language other than system's language.
|
|
|
|
However, this is not supported as of now.
|
|
|
|
Gecko resets the locale to en-US by calling this function with an empty string.
|
|
|
|
This affects GeckoPreferences activity in multi-locale builds.
|
|
|
|
|
|
|
|
//We're not using this, not need to save it (see bug 635342)
|
|
|
|
SharedPreferences settings =
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoApp.mAppContext.getPreferences(Activity.MODE_PRIVATE);
|
|
|
|
settings.edit().putString(GeckoApp.mAppContext.getPackageName() + ".locale",
|
|
|
|
localeCode).commit();
|
|
|
|
Locale locale;
|
|
|
|
int index;
|
|
|
|
if ((index = localeCode.indexOf('-')) != -1 ||
|
|
|
|
(index = localeCode.indexOf('_')) != -1) {
|
|
|
|
String langCode = localeCode.substring(0, index);
|
|
|
|
String countryCode = localeCode.substring(index + 1);
|
|
|
|
locale = new Locale(langCode, countryCode);
|
|
|
|
} else {
|
|
|
|
locale = new Locale(localeCode);
|
|
|
|
}
|
|
|
|
Locale.setDefault(locale);
|
|
|
|
|
|
|
|
Resources res = GeckoApp.mAppContext.getBaseContext().getResources();
|
|
|
|
Configuration config = res.getConfiguration();
|
|
|
|
config.locale = locale;
|
|
|
|
res.updateConfiguration(config, res.getDisplayMetrics());
|
2012-01-30 19:59:47 -08:00
|
|
|
*/
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int[] getSystemColors() {
|
|
|
|
// attrsAppearance[] must correspond to AndroidSystemColors structure in android/AndroidBridge.h
|
|
|
|
final int[] attrsAppearance = {
|
|
|
|
android.R.attr.textColor,
|
|
|
|
android.R.attr.textColorPrimary,
|
|
|
|
android.R.attr.textColorPrimaryInverse,
|
|
|
|
android.R.attr.textColorSecondary,
|
|
|
|
android.R.attr.textColorSecondaryInverse,
|
|
|
|
android.R.attr.textColorTertiary,
|
|
|
|
android.R.attr.textColorTertiaryInverse,
|
|
|
|
android.R.attr.textColorHighlight,
|
|
|
|
android.R.attr.colorForeground,
|
|
|
|
android.R.attr.colorBackground,
|
|
|
|
android.R.attr.panelColorForeground,
|
|
|
|
android.R.attr.panelColorBackground
|
|
|
|
};
|
|
|
|
|
|
|
|
int[] result = new int[attrsAppearance.length];
|
|
|
|
|
|
|
|
final ContextThemeWrapper contextThemeWrapper =
|
|
|
|
new ContextThemeWrapper(GeckoApp.mAppContext, android.R.style.TextAppearance);
|
|
|
|
|
|
|
|
final TypedArray appearance = contextThemeWrapper.getTheme().obtainStyledAttributes(attrsAppearance);
|
|
|
|
|
|
|
|
if (appearance != null) {
|
|
|
|
for (int i = 0; i < appearance.getIndexCount(); i++) {
|
|
|
|
int idx = appearance.getIndex(i);
|
|
|
|
int color = appearance.getColor(idx, 0);
|
|
|
|
result[idx] = color;
|
|
|
|
}
|
|
|
|
appearance.recycle();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void killAnyZombies() {
|
|
|
|
GeckoProcessesVisitor visitor = new GeckoProcessesVisitor() {
|
|
|
|
public boolean callback(int pid) {
|
|
|
|
if (pid != android.os.Process.myPid())
|
|
|
|
android.os.Process.killProcess(pid);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
EnumerateGeckoProcesses(visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean checkForGeckoProcs() {
|
|
|
|
|
|
|
|
class GeckoPidCallback implements GeckoProcessesVisitor {
|
|
|
|
public boolean otherPidExist = false;
|
|
|
|
public boolean callback(int pid) {
|
|
|
|
if (pid != android.os.Process.myPid()) {
|
|
|
|
otherPidExist = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GeckoPidCallback visitor = new GeckoPidCallback();
|
|
|
|
EnumerateGeckoProcesses(visitor);
|
|
|
|
return visitor.otherPidExist;
|
|
|
|
}
|
|
|
|
|
2012-01-30 16:53:14 -08:00
|
|
|
interface GeckoProcessesVisitor{
|
2011-11-18 10:28:17 -08:00
|
|
|
boolean callback(int pid);
|
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static int sPidColumn = -1;
|
|
|
|
static int sUserColumn = -1;
|
2012-07-15 00:07:58 -07:00
|
|
|
private static void EnumerateGeckoProcesses(GeckoProcessesVisitor visiter) {
|
2012-07-17 22:39:46 -07:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
try {
|
|
|
|
|
|
|
|
// run ps and parse its output
|
|
|
|
java.lang.Process ps = Runtime.getRuntime().exec("ps");
|
|
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(ps.getInputStream()),
|
|
|
|
2048);
|
|
|
|
|
|
|
|
String headerOutput = in.readLine();
|
|
|
|
|
|
|
|
// figure out the column offsets. We only care about the pid and user fields
|
|
|
|
if (sPidColumn == -1 || sUserColumn == -1) {
|
|
|
|
StringTokenizer st = new StringTokenizer(headerOutput);
|
|
|
|
|
|
|
|
int tokenSoFar = 0;
|
|
|
|
while(st.hasMoreTokens()) {
|
|
|
|
String next = st.nextToken();
|
|
|
|
if (next.equalsIgnoreCase("PID"))
|
|
|
|
sPidColumn = tokenSoFar;
|
|
|
|
else if (next.equalsIgnoreCase("USER"))
|
|
|
|
sUserColumn = tokenSoFar;
|
|
|
|
tokenSoFar++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// alright, the rest are process entries.
|
|
|
|
String psOutput = null;
|
|
|
|
while ((psOutput = in.readLine()) != null) {
|
|
|
|
String[] split = psOutput.split("\\s+");
|
|
|
|
if (split.length <= sPidColumn || split.length <= sUserColumn)
|
|
|
|
continue;
|
|
|
|
int uid = android.os.Process.getUidForName(split[sUserColumn]);
|
|
|
|
if (uid == android.os.Process.myUid() &&
|
|
|
|
!split[split.length - 1].equalsIgnoreCase("ps")) {
|
|
|
|
int pid = Integer.parseInt(split[sPidColumn]);
|
|
|
|
boolean keepGoing = visiter.callback(pid);
|
|
|
|
if (keepGoing == false)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
in.close();
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
Log.i(LOGTAG, "finding procs throws ", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void waitForAnotherGeckoProc(){
|
|
|
|
int countdown = 40;
|
|
|
|
while (!checkForGeckoProcs() && --countdown > 0) {
|
|
|
|
try {
|
2012-01-24 09:16:48 -08:00
|
|
|
Thread.sleep(100);
|
2011-11-18 10:28:17 -08:00
|
|
|
} catch (InterruptedException ie) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void scanMedia(String aFile, String aMimeType) {
|
|
|
|
Context context = GeckoApp.mAppContext;
|
|
|
|
GeckoMediaScannerClient client = new GeckoMediaScannerClient(context, aFile, aMimeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static byte[] getIconForExtension(String aExt, int iconSize) {
|
|
|
|
try {
|
|
|
|
if (iconSize <= 0)
|
|
|
|
iconSize = 16;
|
|
|
|
|
|
|
|
if (aExt != null && aExt.length() > 1 && aExt.charAt(0) == '.')
|
|
|
|
aExt = aExt.substring(1);
|
|
|
|
|
|
|
|
PackageManager pm = GeckoApp.mAppContext.getPackageManager();
|
|
|
|
Drawable icon = getDrawableForExtension(pm, aExt);
|
|
|
|
if (icon == null) {
|
|
|
|
// Use a generic icon
|
|
|
|
icon = pm.getDefaultActivityIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
Bitmap bitmap = ((BitmapDrawable)icon).getBitmap();
|
|
|
|
if (bitmap.getWidth() != iconSize || bitmap.getHeight() != iconSize)
|
|
|
|
bitmap = Bitmap.createScaledBitmap(bitmap, iconSize, iconSize, true);
|
|
|
|
|
|
|
|
ByteBuffer buf = ByteBuffer.allocate(iconSize * iconSize * 4);
|
|
|
|
bitmap.copyPixelsToBuffer(buf);
|
|
|
|
|
|
|
|
return buf.array();
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
Log.i(LOGTAG, "getIconForExtension error: ", e);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Drawable getDrawableForExtension(PackageManager pm, String aExt) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
MimeTypeMap mtm = MimeTypeMap.getSingleton();
|
|
|
|
String mimeType = mtm.getMimeTypeFromExtension(aExt);
|
|
|
|
if (mimeType != null && mimeType.length() > 0)
|
|
|
|
intent.setType(mimeType);
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
|
|
|
|
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
|
|
|
|
if (list.size() == 0)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
ResolveInfo resolveInfo = list.get(0);
|
|
|
|
|
|
|
|
if (resolveInfo == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
ActivityInfo activityInfo = resolveInfo.activityInfo;
|
|
|
|
|
|
|
|
return activityInfo.loadIcon(pm);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean getShowPasswordSetting() {
|
|
|
|
try {
|
|
|
|
int showPassword =
|
|
|
|
Settings.System.getInt(GeckoApp.mAppContext.getContentResolver(),
|
|
|
|
Settings.System.TEXT_SHOW_PASSWORD, 1);
|
|
|
|
return (showPassword > 0);
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-17 21:34:03 -08:00
|
|
|
public static void addPluginView(View view,
|
2012-01-18 07:41:35 -08:00
|
|
|
int x, int y,
|
2012-05-30 09:10:49 -07:00
|
|
|
int w, int h,
|
2012-06-06 19:39:36 -07:00
|
|
|
boolean isFullScreen)
|
2012-06-19 13:37:57 -07:00
|
|
|
{
|
2012-04-27 13:04:47 -07:00
|
|
|
ImmutableViewportMetrics pluginViewport;
|
|
|
|
|
2012-06-06 19:39:36 -07:00
|
|
|
Log.i(LOGTAG, "addPluginView:" + view + " @ x:" + x + " y:" + y + " w:" + w + " h:" + h + " fullscreen: " + isFullScreen);
|
2012-04-27 13:04:47 -07:00
|
|
|
|
2012-06-06 19:39:36 -07:00
|
|
|
GeckoApp.mAppContext.addPluginView(view, new Rect(x, y, x + w, y + h), isFullScreen);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-05-30 09:10:49 -07:00
|
|
|
public static void removePluginView(View view, boolean isFullScreen) {
|
|
|
|
Log.i(LOGTAG, "removePluginView:" + view + " fullscreen: " + isFullScreen);
|
|
|
|
GeckoApp.mAppContext.removePluginView(view, isFullScreen);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Class<?> loadPluginClass(String className, String libName) {
|
|
|
|
Log.i(LOGTAG, "in loadPluginClass... attempting to access className, then libName.....");
|
|
|
|
Log.i(LOGTAG, "className: " + className);
|
|
|
|
Log.i(LOGTAG, "libName: " + libName);
|
|
|
|
|
|
|
|
try {
|
|
|
|
String packageName = GeckoApp.mAppContext.getPluginPackage(libName);
|
|
|
|
Log.i(LOGTAG, "load \"" + className + "\" from \"" + packageName +
|
|
|
|
"\" for \"" + libName + "\"");
|
|
|
|
Context pluginContext =
|
|
|
|
GeckoApp.mAppContext.createPackageContext(packageName,
|
|
|
|
Context.CONTEXT_INCLUDE_CODE |
|
|
|
|
Context.CONTEXT_IGNORE_SECURITY);
|
|
|
|
ClassLoader pluginCL = pluginContext.getClassLoader();
|
|
|
|
return pluginCL.loadClass(className);
|
|
|
|
} catch (java.lang.ClassNotFoundException cnfe) {
|
|
|
|
Log.i(LOGTAG, "class not found", cnfe);
|
|
|
|
} catch (android.content.pm.PackageManager.NameNotFoundException nnfe) {
|
|
|
|
Log.i(LOGTAG, "package not found", nnfe);
|
|
|
|
}
|
|
|
|
Log.e(LOGTAG, "couldn't find class");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static native void executeNextRunnable();
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static class GeckoRunnableCallback implements Runnable {
|
2011-11-18 10:28:17 -08:00
|
|
|
public void run() {
|
|
|
|
Log.i(LOGTAG, "run GeckoRunnableCallback");
|
|
|
|
GeckoAppShell.executeNextRunnable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void postToJavaThread(boolean mainThread) {
|
|
|
|
Log.i(LOGTAG, "post to " + (mainThread ? "main " : "") + "java thread");
|
|
|
|
getMainHandler().post(new GeckoRunnableCallback());
|
|
|
|
}
|
2012-07-17 22:39:46 -07:00
|
|
|
|
|
|
|
public static android.hardware.Camera sCamera = null;
|
|
|
|
|
|
|
|
static native void cameraCallbackBridge(byte[] data);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static int kPreferedFps = 25;
|
|
|
|
static byte[] sCameraBuffer = null;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static int[] initCamera(String aContentType, int aCamera, int aWidth, int aHeight) {
|
2011-11-18 10:28:17 -08:00
|
|
|
Log.i(LOGTAG, "initCamera(" + aContentType + ", " + aWidth + "x" + aHeight + ") on thread " + Thread.currentThread().getId());
|
|
|
|
|
|
|
|
getMainHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
GeckoApp.mAppContext.enableCameraView();
|
|
|
|
} catch (Exception e) {}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// [0] = 0|1 (failure/success)
|
|
|
|
// [1] = width
|
|
|
|
// [2] = height
|
|
|
|
// [3] = fps
|
|
|
|
int[] result = new int[4];
|
|
|
|
result[0] = 0;
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 9) {
|
|
|
|
if (android.hardware.Camera.getNumberOfCameras() == 0)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// no front/back camera before API level 9
|
|
|
|
if (Build.VERSION.SDK_INT >= 9)
|
|
|
|
sCamera = android.hardware.Camera.open(aCamera);
|
|
|
|
else
|
|
|
|
sCamera = android.hardware.Camera.open();
|
|
|
|
|
|
|
|
android.hardware.Camera.Parameters params = sCamera.getParameters();
|
|
|
|
params.setPreviewFormat(ImageFormat.NV21);
|
|
|
|
|
|
|
|
// use the preview fps closest to 25 fps.
|
|
|
|
int fpsDelta = 1000;
|
|
|
|
try {
|
|
|
|
Iterator<Integer> it = params.getSupportedPreviewFrameRates().iterator();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
int nFps = it.next();
|
|
|
|
if (Math.abs(nFps - kPreferedFps) < fpsDelta) {
|
|
|
|
fpsDelta = Math.abs(nFps - kPreferedFps);
|
|
|
|
params.setPreviewFrameRate(nFps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(Exception e) {
|
|
|
|
params.setPreviewFrameRate(kPreferedFps);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up the closest preview size available
|
|
|
|
Iterator<android.hardware.Camera.Size> sit = params.getSupportedPreviewSizes().iterator();
|
|
|
|
int sizeDelta = 10000000;
|
|
|
|
int bufferSize = 0;
|
|
|
|
while (sit.hasNext()) {
|
|
|
|
android.hardware.Camera.Size size = sit.next();
|
|
|
|
if (Math.abs(size.width * size.height - aWidth * aHeight) < sizeDelta) {
|
|
|
|
sizeDelta = Math.abs(size.width * size.height - aWidth * aHeight);
|
|
|
|
params.setPreviewSize(size.width, size.height);
|
|
|
|
bufferSize = size.width * size.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2012-07-13 07:17:03 -07:00
|
|
|
sCamera.setPreviewDisplay(GeckoApp.mAppContext.cameraView.getHolder());
|
2011-11-18 10:28:17 -08:00
|
|
|
} catch(IOException e) {
|
|
|
|
Log.e(LOGTAG, "Error setPreviewDisplay:", e);
|
|
|
|
} catch(RuntimeException e) {
|
|
|
|
Log.e(LOGTAG, "Error setPreviewDisplay:", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
sCamera.setParameters(params);
|
|
|
|
sCameraBuffer = new byte[(bufferSize * 12) / 8];
|
|
|
|
sCamera.addCallbackBuffer(sCameraBuffer);
|
|
|
|
sCamera.setPreviewCallbackWithBuffer(new android.hardware.Camera.PreviewCallback() {
|
|
|
|
public void onPreviewFrame(byte[] data, android.hardware.Camera camera) {
|
|
|
|
cameraCallbackBridge(data);
|
|
|
|
if (sCamera != null)
|
|
|
|
sCamera.addCallbackBuffer(sCameraBuffer);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
sCamera.startPreview();
|
|
|
|
params = sCamera.getParameters();
|
|
|
|
Log.i(LOGTAG, "Camera: " + params.getPreviewSize().width + "x" + params.getPreviewSize().height +
|
|
|
|
" @ " + params.getPreviewFrameRate() + "fps. format is " + params.getPreviewFormat());
|
|
|
|
result[0] = 1;
|
|
|
|
result[1] = params.getPreviewSize().width;
|
|
|
|
result[2] = params.getPreviewSize().height;
|
|
|
|
result[3] = params.getPreviewFrameRate();
|
|
|
|
|
|
|
|
Log.i(LOGTAG, "Camera preview started");
|
|
|
|
} catch(RuntimeException e) {
|
|
|
|
Log.e(LOGTAG, "initCamera RuntimeException : ", e);
|
|
|
|
result[0] = result[1] = result[2] = result[3] = 0;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static synchronized void closeCamera() {
|
2011-11-18 10:28:17 -08:00
|
|
|
Log.i(LOGTAG, "closeCamera() on thread " + Thread.currentThread().getId());
|
|
|
|
getMainHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
GeckoApp.mAppContext.disableCameraView();
|
|
|
|
} catch (Exception e) {}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (sCamera != null) {
|
|
|
|
sCamera.stopPreview();
|
|
|
|
sCamera.release();
|
|
|
|
sCamera = null;
|
|
|
|
sCameraBuffer = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-17 08:30:34 -07:00
|
|
|
/**
|
|
|
|
* Adds a listener for a gecko event.
|
|
|
|
* This method is thread-safe and may be called at any time. In particular, calling it
|
|
|
|
* with an event that is currently being processed has the properly-defined behaviour that
|
|
|
|
* any added listeners will not be invoked on the event currently being processed, but
|
|
|
|
* will be invoked on future events of that type.
|
|
|
|
*
|
|
|
|
* This method is referenced by Robocop via reflection.
|
|
|
|
*/
|
2011-11-18 10:28:17 -08:00
|
|
|
public static void registerGeckoEventListener(String event, GeckoEventListener listener) {
|
2012-04-17 08:30:34 -07:00
|
|
|
synchronized (mEventListeners) {
|
|
|
|
CopyOnWriteArrayList<GeckoEventListener> listeners = mEventListeners.get(event);
|
|
|
|
if (listeners == null) {
|
|
|
|
// create a CopyOnWriteArrayList so that we can modify it
|
|
|
|
// concurrently with iterating through it in handleGeckoMessage.
|
|
|
|
// Otherwise we could end up throwing a ConcurrentModificationException.
|
|
|
|
listeners = new CopyOnWriteArrayList<GeckoEventListener>();
|
|
|
|
}
|
|
|
|
listeners.add(listener);
|
|
|
|
mEventListeners.put(event, listeners);
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static SynchronousQueue<Date> sTracerQueue = new SynchronousQueue<Date>();
|
2011-11-18 10:28:17 -08:00
|
|
|
public static void fireAndWaitForTracerEvent() {
|
|
|
|
getMainHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
sTracerQueue.put(new Date());
|
|
|
|
} catch(InterruptedException ie) {
|
|
|
|
Log.w(LOGTAG, "exception firing tracer", ie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
sTracerQueue.take();
|
|
|
|
} catch(InterruptedException ie) {
|
|
|
|
Log.w(LOGTAG, "exception firing tracer", ie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-17 08:30:34 -07:00
|
|
|
/**
|
|
|
|
* Remove a previously-registered listener for a gecko event.
|
|
|
|
* This method is thread-safe and may be called at any time. In particular, calling it
|
|
|
|
* with an event that is currently being processed has the properly-defined behaviour that
|
|
|
|
* any removed listeners will still be invoked on the event currently being processed, but
|
|
|
|
* will not be invoked on future events of that type.
|
|
|
|
*
|
|
|
|
* This method is referenced by Robocop via reflection.
|
|
|
|
*/
|
2011-11-18 10:28:17 -08:00
|
|
|
public static void unregisterGeckoEventListener(String event, GeckoEventListener listener) {
|
2012-04-17 08:30:34 -07:00
|
|
|
synchronized (mEventListeners) {
|
|
|
|
CopyOnWriteArrayList<GeckoEventListener> listeners = mEventListeners.get(event);
|
|
|
|
if (listeners == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
listeners.remove(listener);
|
|
|
|
if (listeners.size() == 0) {
|
|
|
|
mEventListeners.remove(event);
|
|
|
|
}
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-11-20 15:00:46 -08:00
|
|
|
/*
|
|
|
|
* Battery API related methods.
|
|
|
|
*/
|
2011-11-18 10:28:17 -08:00
|
|
|
public static void enableBatteryNotifications() {
|
|
|
|
GeckoBatteryManager.enableNotifications();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String handleGeckoMessage(String message) {
|
|
|
|
//
|
|
|
|
// {"gecko": {
|
|
|
|
// "type": "value",
|
|
|
|
// "event_specific": "value",
|
|
|
|
// ....
|
|
|
|
try {
|
|
|
|
JSONObject json = new JSONObject(message);
|
|
|
|
final JSONObject geckoObject = json.getJSONObject("gecko");
|
|
|
|
String type = geckoObject.getString("type");
|
|
|
|
|
2012-04-17 08:30:34 -07:00
|
|
|
CopyOnWriteArrayList<GeckoEventListener> listeners;
|
|
|
|
synchronized (mEventListeners) {
|
|
|
|
listeners = mEventListeners.get(type);
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-02-27 07:13:36 -08:00
|
|
|
if (listeners == null)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
String response = null;
|
|
|
|
|
|
|
|
for (GeckoEventListener listener : listeners) {
|
|
|
|
listener.handleMessage(type, geckoObject);
|
|
|
|
if (listener instanceof GeckoEventResponder) {
|
|
|
|
String newResponse = ((GeckoEventResponder)listener).getResponse();
|
|
|
|
if (response != null && newResponse != null) {
|
|
|
|
Log.e(LOGTAG, "Received two responses for message of type " + type);
|
|
|
|
}
|
|
|
|
response = newResponse;
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-02-27 07:13:36 -08:00
|
|
|
if (response != null)
|
|
|
|
return response;
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
} catch (Exception e) {
|
2012-03-30 06:46:27 -07:00
|
|
|
Log.e(LOGTAG, "handleGeckoMessage throws " + e, e);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void disableBatteryNotifications() {
|
|
|
|
GeckoBatteryManager.disableNotifications();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static double[] getCurrentBatteryInformation() {
|
|
|
|
return GeckoBatteryManager.getCurrentInformation();
|
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static void checkUriVisited(String uri) { // invoked from native JNI code
|
2011-11-18 10:28:17 -08:00
|
|
|
GlobalHistory.getInstance().checkUriVisited(uri);
|
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static void markUriVisited(final String uri) { // invoked from native JNI code
|
2011-11-18 10:28:17 -08:00
|
|
|
getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
GlobalHistory.getInstance().add(uri);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static void hideProgressDialog() {
|
2011-11-18 10:28:17 -08:00
|
|
|
// unused stub
|
|
|
|
}
|
|
|
|
|
2011-11-20 15:00:46 -08:00
|
|
|
/*
|
|
|
|
* WebSMS related methods.
|
|
|
|
*/
|
2011-11-25 01:48:51 -08:00
|
|
|
public static int getNumberOfMessagesForText(String aText) {
|
2012-01-17 10:38:04 -08:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SmsManager.getInstance().getNumberOfMessagesForText(aText);
|
2011-11-25 01:48:51 -08:00
|
|
|
}
|
2011-11-20 15:00:46 -08:00
|
|
|
|
2012-01-17 10:52:17 -08:00
|
|
|
public static void sendMessage(String aNumber, String aMessage, int aRequestId, long aProcessId) {
|
2012-01-17 10:38:04 -08:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmsManager.getInstance().send(aNumber, aMessage, aRequestId, aProcessId);
|
2012-01-17 10:52:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int saveSentMessage(String aRecipient, String aBody, long aDate) {
|
2012-01-17 10:38:04 -08:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SmsManager.getInstance().saveSentMessage(aRecipient, aBody, aDate);
|
2012-01-17 10:52:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void getMessage(int aMessageId, int aRequestId, long aProcessId) {
|
2012-01-17 10:38:04 -08:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmsManager.getInstance().getMessage(aMessageId, aRequestId, aProcessId);
|
2012-01-17 10:52:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void deleteMessage(int aMessageId, int aRequestId, long aProcessId) {
|
2012-01-17 10:38:04 -08:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmsManager.getInstance().deleteMessage(aMessageId, aRequestId, aProcessId);
|
2012-01-17 10:52:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void createMessageList(long aStartDate, long aEndDate, String[] aNumbers, int aNumbersCount, int aDeliveryState, boolean aReverse, int aRequestId, long aProcessId) {
|
2012-01-17 10:38:04 -08:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmsManager.getInstance().createMessageList(aStartDate, aEndDate, aNumbers, aNumbersCount, aDeliveryState, aReverse, aRequestId, aProcessId);
|
2012-01-17 10:52:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void getNextMessageInList(int aListId, int aRequestId, long aProcessId) {
|
2012-01-17 10:38:04 -08:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmsManager.getInstance().getNextMessageInList(aListId, aRequestId, aProcessId);
|
2012-01-17 10:52:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void clearMessageList(int aListId) {
|
2012-01-17 10:38:04 -08:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmsManager.getInstance().clearMessageList(aListId);
|
2011-11-20 15:00:46 -08:00
|
|
|
}
|
2011-11-29 20:58:39 -08:00
|
|
|
|
2011-12-14 13:53:38 -08:00
|
|
|
public static boolean isTablet() {
|
2012-07-13 13:47:41 -07:00
|
|
|
return GeckoApp.mAppContext.isTablet();
|
2011-12-14 13:53:38 -08:00
|
|
|
}
|
|
|
|
|
2011-12-03 19:59:27 -08:00
|
|
|
public static void viewSizeChanged() {
|
|
|
|
if (mInputConnection != null && mInputConnection.isIMEEnabled()) {
|
2012-02-08 23:18:27 -08:00
|
|
|
sendEventToGecko(GeckoEvent.createBroadcastEvent("ScrollTo:FocusedInput", ""));
|
2011-12-03 19:59:27 -08:00
|
|
|
}
|
|
|
|
}
|
2012-01-16 05:44:07 -08:00
|
|
|
|
|
|
|
public static double[] getCurrentNetworkInformation() {
|
2012-01-16 09:17:34 -08:00
|
|
|
return GeckoNetworkManager.getInstance().getCurrentInformation();
|
2012-01-16 05:44:07 -08:00
|
|
|
}
|
2012-01-16 06:01:07 -08:00
|
|
|
|
|
|
|
public static void enableNetworkNotifications() {
|
|
|
|
GeckoNetworkManager.getInstance().enableNotifications();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void disableNetworkNotifications() {
|
|
|
|
GeckoNetworkManager.getInstance().disableNotifications();
|
|
|
|
}
|
2012-02-01 11:37:03 -08:00
|
|
|
|
2012-02-07 12:32:56 -08:00
|
|
|
// values taken from android's Base64
|
|
|
|
public static final int BASE64_DEFAULT = 0;
|
|
|
|
public static final int BASE64_URL_SAFE = 8;
|
2012-02-01 11:37:03 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* taken from http://www.source-code.biz/base64coder/java/Base64Coder.java.txt and modified (MIT License)
|
|
|
|
*/
|
|
|
|
// Mapping table from 6-bit nibbles to Base64 characters.
|
|
|
|
private static final byte[] map1 = new byte[64];
|
2012-02-07 12:32:56 -08:00
|
|
|
private static final byte[] map1_urlsafe;
|
2012-02-01 11:37:03 -08:00
|
|
|
static {
|
|
|
|
int i=0;
|
|
|
|
for (byte c='A'; c<='Z'; c++) map1[i++] = c;
|
|
|
|
for (byte c='a'; c<='z'; c++) map1[i++] = c;
|
|
|
|
for (byte c='0'; c<='9'; c++) map1[i++] = c;
|
2012-02-07 12:32:56 -08:00
|
|
|
map1[i++] = '+'; map1[i++] = '/';
|
|
|
|
map1_urlsafe = map1.clone();
|
|
|
|
map1_urlsafe[62] = '-'; map1_urlsafe[63] = '_';
|
2012-02-01 11:37:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mapping table from Base64 characters to 6-bit nibbles.
|
|
|
|
private static final byte[] map2 = new byte[128];
|
|
|
|
static {
|
|
|
|
for (int i=0; i<map2.length; i++) map2[i] = -1;
|
|
|
|
for (int i=0; i<64; i++) map2[map1[i]] = (byte)i;
|
2012-02-07 12:32:56 -08:00
|
|
|
map2['-'] = (byte)62; map2['_'] = (byte)63;
|
2012-02-01 11:37:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
final static byte EQUALS_ASCII = (byte) '=';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encodes a byte array into Base64 format.
|
|
|
|
* No blanks or line breaks are inserted in the output.
|
|
|
|
* @param in An array containing the data bytes to be encoded.
|
|
|
|
* @return A character array containing the Base64 encoded data.
|
|
|
|
*/
|
2012-02-07 12:32:56 -08:00
|
|
|
public static byte[] encodeBase64(byte[] in, int flags) {
|
2012-02-01 11:37:03 -08:00
|
|
|
if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.FROYO)
|
2012-02-07 12:32:56 -08:00
|
|
|
return Base64.encode(in, flags | Base64.NO_WRAP);
|
2012-02-01 11:37:03 -08:00
|
|
|
int oDataLen = (in.length*4+2)/3; // output length without padding
|
|
|
|
int oLen = ((in.length+2)/3)*4; // output length including padding
|
|
|
|
byte[] out = new byte[oLen];
|
|
|
|
int ip = 0;
|
|
|
|
int iEnd = in.length;
|
|
|
|
int op = 0;
|
2012-02-07 12:32:56 -08:00
|
|
|
byte[] toMap = ((flags & BASE64_URL_SAFE) == 0 ? map1 : map1_urlsafe);
|
2012-02-01 11:37:03 -08:00
|
|
|
while (ip < iEnd) {
|
|
|
|
int i0 = in[ip++] & 0xff;
|
|
|
|
int i1 = ip < iEnd ? in[ip++] & 0xff : 0;
|
|
|
|
int i2 = ip < iEnd ? in[ip++] & 0xff : 0;
|
|
|
|
int o0 = i0 >>> 2;
|
|
|
|
int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
|
|
|
|
int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
|
|
|
|
int o3 = i2 & 0x3F;
|
2012-02-07 12:32:56 -08:00
|
|
|
out[op++] = toMap[o0];
|
|
|
|
out[op++] = toMap[o1];
|
|
|
|
out[op] = op < oDataLen ? toMap[o2] : EQUALS_ASCII; op++;
|
|
|
|
out[op] = op < oDataLen ? toMap[o3] : EQUALS_ASCII; op++;
|
2012-02-01 11:37:03 -08:00
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decodes a byte array from Base64 format.
|
|
|
|
* No blanks or line breaks are allowed within the Base64 encoded input data.
|
|
|
|
* @param in A character array containing the Base64 encoded data.
|
|
|
|
* @param iOff Offset of the first character in <code>in</code> to be processed.
|
|
|
|
* @param iLen Number of characters to process in <code>in</code>, starting at <code>iOff</code>.
|
|
|
|
* @return An array containing the decoded data bytes.
|
|
|
|
* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
|
|
|
|
*/
|
2012-02-07 12:32:56 -08:00
|
|
|
public static byte[] decodeBase64(byte[] in, int flags) {
|
2012-02-01 11:37:03 -08:00
|
|
|
if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.FROYO)
|
2012-02-07 12:32:56 -08:00
|
|
|
return Base64.decode(in, flags);
|
2012-02-01 11:37:03 -08:00
|
|
|
int iOff = 0;
|
|
|
|
int iLen = in.length;
|
|
|
|
if (iLen%4 != 0) throw new IllegalArgumentException ("Length of Base64 encoded input string is not a multiple of 4.");
|
|
|
|
while (iLen > 0 && in[iOff+iLen-1] == '=') iLen--;
|
|
|
|
int oLen = (iLen*3) / 4;
|
|
|
|
byte[] out = new byte[oLen];
|
|
|
|
int ip = iOff;
|
|
|
|
int iEnd = iOff + iLen;
|
|
|
|
int op = 0;
|
|
|
|
while (ip < iEnd) {
|
|
|
|
int i0 = in[ip++];
|
|
|
|
int i1 = in[ip++];
|
|
|
|
int i2 = ip < iEnd ? in[ip++] : 'A';
|
|
|
|
int i3 = ip < iEnd ? in[ip++] : 'A';
|
|
|
|
if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127)
|
|
|
|
throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
|
|
|
|
int b0 = map2[i0];
|
|
|
|
int b1 = map2[i1];
|
|
|
|
int b2 = map2[i2];
|
|
|
|
int b3 = map2[i3];
|
|
|
|
if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0)
|
|
|
|
throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
|
|
|
|
int o0 = ( b0 <<2) | (b1>>>4);
|
|
|
|
int o1 = ((b1 & 0xf)<<4) | (b2>>>2);
|
|
|
|
int o2 = ((b2 & 3)<<6) | b3;
|
|
|
|
out[op++] = (byte)o0;
|
|
|
|
if (op<oLen) out[op++] = (byte)o1;
|
|
|
|
if (op<oLen) out[op++] = (byte)o2; }
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2012-02-07 12:32:56 -08:00
|
|
|
public static byte[] decodeBase64(String s, int flags) {
|
|
|
|
return decodeBase64(s.getBytes(), flags);
|
2012-02-01 11:37:03 -08:00
|
|
|
}
|
2012-03-20 06:09:45 -07:00
|
|
|
|
|
|
|
public static short getScreenOrientation() {
|
|
|
|
return GeckoScreenOrientationListener.getInstance().getScreenOrientation();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void enableScreenOrientationNotifications() {
|
|
|
|
GeckoScreenOrientationListener.getInstance().enableNotifications();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void disableScreenOrientationNotifications() {
|
|
|
|
GeckoScreenOrientationListener.getInstance().disableNotifications();
|
|
|
|
}
|
2012-03-29 23:31:12 -07:00
|
|
|
|
|
|
|
public static void lockScreenOrientation(int aOrientation) {
|
|
|
|
GeckoScreenOrientationListener.getInstance().lockScreenOrientation(aOrientation);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void unlockScreenOrientation() {
|
|
|
|
GeckoScreenOrientationListener.getInstance().unlockScreenOrientation();
|
|
|
|
}
|
2012-04-04 22:50:06 -07:00
|
|
|
|
2012-06-05 08:28:37 -07:00
|
|
|
public static void pumpMessageLoop() {
|
2012-05-31 17:07:07 -07:00
|
|
|
MessageQueue mq = Looper.myQueue();
|
|
|
|
Message msg = getNextMessageFromQueue(mq);
|
|
|
|
if (msg == null)
|
2012-06-05 08:28:37 -07:00
|
|
|
return;
|
|
|
|
if (msg.getTarget() == null)
|
2012-05-31 17:07:07 -07:00
|
|
|
Looper.myLooper().quit();
|
|
|
|
else
|
|
|
|
msg.getTarget().dispatchMessage(msg);
|
|
|
|
msg.recycle();
|
2012-05-03 07:53:31 -07:00
|
|
|
}
|
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
static class AsyncResultHandler extends FilePickerResultHandler {
|
2012-04-04 22:50:06 -07:00
|
|
|
private long mId;
|
|
|
|
AsyncResultHandler(long id) {
|
2012-07-13 11:06:24 -07:00
|
|
|
super(null);
|
2012-04-04 22:50:06 -07:00
|
|
|
mId = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onActivityResult(int resultCode, Intent data) {
|
|
|
|
GeckoAppShell.notifyFilePickerResult(handleActivityResult(resultCode, data), mId);
|
|
|
|
}
|
2012-07-17 22:39:46 -07:00
|
|
|
|
2012-04-04 22:50:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static native void notifyFilePickerResult(String filePath, long id);
|
|
|
|
|
|
|
|
/* Called by JNI from AndroidBridge */
|
|
|
|
public static void showFilePickerAsync(String aMimeType, long id) {
|
2012-07-13 11:08:19 -07:00
|
|
|
if (!sActivityHelper.showFilePicker(GeckoApp.mAppContext, aMimeType, new AsyncResultHandler(id))) {
|
2012-04-04 22:50:06 -07:00
|
|
|
GeckoAppShell.notifyFilePickerResult("", id);
|
2012-07-13 11:07:43 -07:00
|
|
|
}
|
2012-04-04 22:50:06 -07:00
|
|
|
}
|
2012-07-13 11:07:43 -07:00
|
|
|
|
2012-06-14 09:08:51 -07:00
|
|
|
public static void screenshotWholePage(Tab tab) {
|
|
|
|
ScreenshotHandler.screenshotWholePage(tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called by AndroidBridge using JNI
|
|
|
|
public static void notifyPaintedRect(float top, float left, float bottom, float right) {
|
|
|
|
ScreenshotHandler.notifyPaintedRect(top, left, bottom, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void notifyWakeLockChanged(String topic, String state) {
|
|
|
|
GeckoApp.mAppContext.notifyWakeLockChanged(topic, state);
|
|
|
|
}
|
2012-07-05 07:12:10 -07:00
|
|
|
|
|
|
|
public static String getGfxInfoData() {
|
|
|
|
String data = sGfxInfoThread.getData();
|
|
|
|
sGfxInfoThread = null;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2012-07-20 12:20:51 -07:00
|
|
|
public static void registerSurfaceTextureFrameListener(Object surfaceTexture, final int id) {
|
|
|
|
((SurfaceTexture)surfaceTexture).setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
|
|
|
|
public void onFrameAvailable(SurfaceTexture surfaceTexture) {
|
|
|
|
GeckoAppShell.onSurfaceTextureFrameAvailable(surfaceTexture, id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void unregisterSurfaceTextureFrameListener(Object surfaceTexture) {
|
|
|
|
((SurfaceTexture)surfaceTexture).setOnFrameAvailableListener(null);
|
|
|
|
}
|
2012-07-17 22:39:46 -07:00
|
|
|
}
|
2012-06-14 09:08:51 -07:00
|
|
|
|
2012-07-18 08:23:16 -07:00
|
|
|
class ScreenshotHandler implements Runnable {
|
|
|
|
public static final int SCREENSHOT_THUMBNAIL = 0;
|
|
|
|
public static final int SCREENSHOT_CHECKERBOARD = 1;
|
2012-04-24 12:13:36 -07:00
|
|
|
|
2012-07-18 08:23:16 -07:00
|
|
|
private static final String LOGTAG = "GeckoScreenshotHandler";
|
|
|
|
private static final int BYTES_FOR_16BPP = 2;
|
|
|
|
private static final int MAX_PIXELS_PER_SLICE = 100000;
|
2012-04-24 12:13:36 -07:00
|
|
|
|
2012-07-18 08:23:16 -07:00
|
|
|
private static boolean sDisableScreenshot;
|
|
|
|
private static ScreenshotHandler sInstance;
|
2012-06-14 09:08:51 -07:00
|
|
|
|
2012-07-18 08:23:16 -07:00
|
|
|
private final int mMaxTextureSize;
|
|
|
|
private final int mMinTextureSize;
|
|
|
|
private final int mMaxPixels;
|
2012-04-24 12:13:36 -07:00
|
|
|
|
2012-07-18 08:23:16 -07:00
|
|
|
private final Queue<PendingScreenshot> mPendingScreenshots;
|
|
|
|
private final ByteBuffer mBuffer;
|
|
|
|
private int mBufferWidth;
|
|
|
|
private int mBufferHeight;
|
|
|
|
private RectF mPageRect;
|
|
|
|
private float mWidthRatio;
|
|
|
|
private float mHeightRatio;
|
|
|
|
|
|
|
|
private int mTabId;
|
|
|
|
private RectF mDirtyRect;
|
|
|
|
private boolean mIsRepaintRunnablePosted;
|
|
|
|
|
|
|
|
private static synchronized ScreenshotHandler getInstance() {
|
|
|
|
if (sInstance == null) {
|
|
|
|
try {
|
|
|
|
sInstance = new ScreenshotHandler();
|
|
|
|
} catch (UnsupportedOperationException e) {
|
|
|
|
// initialization failed, fall through and return null
|
2012-04-24 12:13:36 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-18 08:23:16 -07:00
|
|
|
return sInstance;
|
2012-07-17 22:39:46 -07:00
|
|
|
}
|
2012-04-24 12:13:36 -07:00
|
|
|
|
2012-07-18 08:23:16 -07:00
|
|
|
private ScreenshotHandler() {
|
|
|
|
int[] maxTextureSize = new int[1];
|
|
|
|
GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
|
|
|
|
mMaxTextureSize = maxTextureSize[0];
|
|
|
|
if (mMaxTextureSize == 0) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
mMaxPixels = Math.min(ScreenshotLayer.getMaxNumPixels(), mMaxTextureSize * mMaxTextureSize);
|
|
|
|
mMinTextureSize = (int)Math.ceil(mMaxPixels / mMaxTextureSize);
|
|
|
|
mPendingScreenshots = new LinkedList<PendingScreenshot>();
|
2012-07-31 15:54:29 -07:00
|
|
|
mBuffer = DirectBufferAllocator.allocate(mMaxPixels * BYTES_FOR_16BPP);
|
2012-07-18 08:23:16 -07:00
|
|
|
mDirtyRect = new RectF();
|
|
|
|
clearDirtyRect();
|
2012-07-17 22:39:46 -07:00
|
|
|
}
|
2012-05-04 06:19:01 -07:00
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
// Invoked via reflection from robocop test
|
|
|
|
public static void disableScreenshot() {
|
|
|
|
sDisableScreenshot = true;
|
|
|
|
}
|
2012-06-14 09:08:51 -07:00
|
|
|
|
2012-07-17 22:39:46 -07:00
|
|
|
public static void screenshotWholePage(Tab tab) {
|
2012-07-18 08:23:16 -07:00
|
|
|
if (sDisableScreenshot || GeckoApp.mAppContext.isApplicationInBackground()) {
|
2012-07-17 22:39:46 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-07-18 08:23:16 -07:00
|
|
|
ScreenshotHandler handler = getInstance();
|
|
|
|
if (handler == null) {
|
2012-07-17 22:39:46 -07:00
|
|
|
return;
|
2012-06-14 09:08:51 -07:00
|
|
|
}
|
|
|
|
|
2012-07-18 08:23:16 -07:00
|
|
|
handler.screenshotWholePage(tab.getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void screenshotWholePage(int tabId) {
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
LayerController layerController = GeckoApp.mAppContext.getLayerController();
|
|
|
|
if (layerController == null) {
|
2012-07-17 22:39:46 -07:00
|
|
|
return;
|
2012-07-18 08:23:16 -07:00
|
|
|
}
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
ImmutableViewportMetrics viewport = layerController.getViewportMetrics();
|
2012-07-18 08:23:16 -07:00
|
|
|
RectF pageRect = viewport.getCssPageRect();
|
|
|
|
|
|
|
|
if (FloatUtils.fuzzyEquals(pageRect.width(), 0) || FloatUtils.fuzzyEquals(pageRect.height(), 0)) {
|
2012-07-17 22:39:46 -07:00
|
|
|
return;
|
2012-07-18 08:23:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
synchronized (this) {
|
|
|
|
// if we're doing a full-page screenshot, toss any
|
|
|
|
// dirty rects we have saved up and reset the tab id.
|
|
|
|
mTabId = tabId;
|
|
|
|
clearDirtyRect();
|
|
|
|
}
|
|
|
|
synchronized (mPendingScreenshots) {
|
|
|
|
for (Iterator<PendingScreenshot> i = mPendingScreenshots.iterator(); i.hasNext(); ) {
|
|
|
|
i.next().discard();
|
2012-07-15 00:07:58 -07:00
|
|
|
}
|
2012-06-14 09:08:51 -07:00
|
|
|
}
|
2012-07-18 08:23:16 -07:00
|
|
|
|
|
|
|
int dstx = 0;
|
|
|
|
int dsty = 0;
|
|
|
|
float bestZoomFactor = (float)Math.sqrt(pageRect.width() * pageRect.height() / mMaxPixels);
|
|
|
|
int dstw = IntSize.largestPowerOfTwoLessThan(pageRect.width() / bestZoomFactor);
|
|
|
|
// clamp with min texture size so that the height doesn't exceed the sMaxTextureSize
|
|
|
|
dstw = clamp(mMinTextureSize, dstw, mMaxTextureSize);
|
|
|
|
int dsth = mMaxPixels / dstw;
|
|
|
|
|
|
|
|
mPageRect = pageRect;
|
|
|
|
mBufferWidth = dstw;
|
|
|
|
mBufferHeight = dsth;
|
|
|
|
mWidthRatio = dstw / pageRect.width();
|
|
|
|
mHeightRatio = dsth / pageRect.height();
|
|
|
|
|
|
|
|
scheduleCheckerboardScreenshotEvent(pageRect, dstx, dsty, dstw, dsth);
|
2012-07-17 22:39:46 -07:00
|
|
|
}
|
2012-06-14 09:08:51 -07:00
|
|
|
|
2012-07-18 08:23:16 -07:00
|
|
|
private static int clamp(int min, int val, int max) {
|
|
|
|
return Math.max(Math.min(max, val), min);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void notifyPaintedRect(float top, float left, float bottom, float right) {
|
|
|
|
if (sDisableScreenshot) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ScreenshotHandler handler = getInstance();
|
|
|
|
if (handler == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
handler.notifyPageUpdated(top, left, bottom, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void notifyPageUpdated(float top, float left, float bottom, float right) {
|
|
|
|
synchronized (this) {
|
|
|
|
if (mPageRect == null || Tabs.getInstance().getSelectedTab().getId() != mTabId) {
|
|
|
|
// if mPageRect is null, we haven't done a full-page
|
|
|
|
// screenshot yet (or screenshotWholePage failed for some reason),
|
|
|
|
// so ignore partial updates. also if the tab changed, ignore
|
|
|
|
// partial updates until we do the next whole-page screenshot.
|
2012-07-17 22:39:46 -07:00
|
|
|
return;
|
2012-07-18 08:23:16 -07:00
|
|
|
}
|
|
|
|
mDirtyRect.top = Math.max(mPageRect.top, Math.min(top, mDirtyRect.top));
|
|
|
|
mDirtyRect.left = Math.max(mPageRect.left, Math.min(left, mDirtyRect.left));
|
|
|
|
mDirtyRect.bottom = Math.min(mPageRect.bottom, Math.max(bottom, mDirtyRect.bottom));
|
|
|
|
mDirtyRect.right = Math.min(mPageRect.right, Math.max(right, mDirtyRect.right));
|
|
|
|
if (!mIsRepaintRunnablePosted) {
|
|
|
|
GeckoAppShell.getHandler().postDelayed(this, 5000);
|
|
|
|
mIsRepaintRunnablePosted = true;
|
|
|
|
}
|
2012-07-17 22:39:46 -07:00
|
|
|
}
|
|
|
|
}
|
2012-06-14 09:08:51 -07:00
|
|
|
|
2012-07-18 08:23:16 -07:00
|
|
|
private void clearDirtyRect() {
|
|
|
|
mDirtyRect.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
|
|
|
|
Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
// make a copy of the dirty rect to work with so we can keep
|
|
|
|
// accumulating new dirty rects.
|
|
|
|
RectF dirtyRect = new RectF();
|
|
|
|
synchronized (this) {
|
|
|
|
dirtyRect.set(mDirtyRect);
|
|
|
|
clearDirtyRect();
|
|
|
|
mIsRepaintRunnablePosted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dirtyRect.width() <= 0 || dirtyRect.height() <= 0) {
|
|
|
|
// we have nothing in the dirty rect, so nothing to do
|
|
|
|
return;
|
2012-07-17 22:39:46 -07:00
|
|
|
}
|
2012-06-14 09:08:51 -07:00
|
|
|
|
2012-07-18 08:23:16 -07:00
|
|
|
Tab selectedTab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (selectedTab == null || selectedTab.getId() != mTabId) {
|
|
|
|
// tab changed, so bail out before we start screenshotting
|
|
|
|
// the wrong tab. note we must do this *after* resetting
|
|
|
|
// mIsRepaintRunnablePosted above.
|
|
|
|
return;
|
2012-07-15 00:07:58 -07:00
|
|
|
}
|
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
LayerController layerController = GeckoApp.mAppContext.getLayerController();
|
|
|
|
if (layerController == null) {
|
2012-07-18 08:23:16 -07:00
|
|
|
// we could be in the midst of an activity tear-down and re-start, so guard
|
|
|
|
// against a null layer controller.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
ImmutableViewportMetrics viewport = layerController.getViewportMetrics();
|
2012-07-18 08:23:16 -07:00
|
|
|
if (RectUtils.fuzzyEquals(mPageRect, viewport.getCssPageRect())) {
|
|
|
|
// the page size hasn't changed, so our dirty rect is still valid and we can just
|
|
|
|
// repaint that area
|
|
|
|
int dstx = (int)(mWidthRatio * (dirtyRect.left - viewport.cssPageRectLeft));
|
|
|
|
int dsty = (int)(mHeightRatio * (dirtyRect.top - viewport.cssPageRectTop));
|
|
|
|
int dstw = (int)(mWidthRatio * dirtyRect.width());
|
|
|
|
int dsth = (int)(mHeightRatio * dirtyRect.height());
|
|
|
|
scheduleCheckerboardScreenshotEvent(dirtyRect, dstx, dsty, dstw, dsth);
|
|
|
|
} else {
|
|
|
|
// the page size changed, so we need to re-screenshot the whole page
|
|
|
|
screenshotWholePage(mTabId);
|
|
|
|
}
|
2012-07-17 22:39:46 -07:00
|
|
|
}
|
2012-07-15 00:07:58 -07:00
|
|
|
|
2012-07-18 08:23:16 -07:00
|
|
|
private void scheduleCheckerboardScreenshotEvent(RectF srcRect, int dstx, int dsty, int dstw, int dsth) {
|
|
|
|
int numSlices = (int)FloatMath.ceil(srcRect.width() * srcRect.height() / MAX_PIXELS_PER_SLICE);
|
|
|
|
if (numSlices == 0 || dstw == 0 || dsth == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PendingScreenshot pending = new PendingScreenshot(mTabId);
|
|
|
|
int sliceDstH = Math.max(1, dsth / numSlices);
|
|
|
|
float sliceSrcH = sliceDstH * srcRect.height() / dsth;
|
|
|
|
float srcY = srcRect.top;
|
|
|
|
for (int i = 0; i < dsth; i += sliceDstH) {
|
|
|
|
if (i + sliceDstH > dsth) {
|
|
|
|
// the last slice may be smaller to account for rounding error.
|
|
|
|
sliceDstH = dsth - i;
|
|
|
|
sliceSrcH = sliceDstH * srcRect.height() / dsth;
|
|
|
|
}
|
|
|
|
GeckoEvent event = GeckoEvent.createScreenshotEvent(mTabId,
|
|
|
|
(int)srcRect.left, (int)srcY, (int)srcRect.width(), (int)sliceSrcH,
|
|
|
|
dstx, dsty + i, dstw, sliceDstH,
|
|
|
|
mBufferWidth, mBufferHeight, SCREENSHOT_CHECKERBOARD, mBuffer);
|
|
|
|
srcY += sliceSrcH;
|
|
|
|
pending.addEvent(event);
|
|
|
|
}
|
|
|
|
synchronized (mPendingScreenshots) {
|
|
|
|
mPendingScreenshots.add(pending);
|
|
|
|
if (mPendingScreenshots.size() == 1) {
|
|
|
|
sendNextEventToGecko();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendNextEventToGecko() {
|
|
|
|
synchronized (mPendingScreenshots) {
|
|
|
|
while (!mPendingScreenshots.isEmpty()) {
|
|
|
|
// some of the pending screenshots may have been discard()ed
|
|
|
|
// so keep looping until we find a real one
|
|
|
|
if (mPendingScreenshots.element().sendNextEventToGecko()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mPendingScreenshots.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void notifyScreenShot(final ByteBuffer data, final int tabId,
|
2012-07-17 22:39:46 -07:00
|
|
|
final int left, final int top,
|
2012-07-18 08:23:16 -07:00
|
|
|
final int right, final int bottom,
|
2012-07-17 22:39:46 -07:00
|
|
|
final int bufferWidth, final int bufferHeight, final int token) {
|
|
|
|
GeckoAppShell.getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
switch (token) {
|
2012-07-18 08:23:16 -07:00
|
|
|
case SCREENSHOT_CHECKERBOARD:
|
2012-07-17 22:39:46 -07:00
|
|
|
{
|
2012-07-18 08:23:16 -07:00
|
|
|
ScreenshotHandler handler = getInstance();
|
|
|
|
if (Tabs.getInstance().getSelectedTab().getId() == tabId) {
|
|
|
|
PendingScreenshot current;
|
|
|
|
synchronized (handler.mPendingScreenshots) {
|
|
|
|
current = handler.mPendingScreenshots.element();
|
|
|
|
current.slicePainted(left, top, right, bottom);
|
|
|
|
if (current.sendNextEventToGecko()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// this screenshot has all its slices done, so push it out
|
|
|
|
// to the layer renderer and remove it from the list
|
|
|
|
}
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
LayerController layerController = GeckoApp.mAppContext.getLayerController();
|
|
|
|
if (layerController != null) {
|
|
|
|
layerController.getView().getRenderer().setCheckerboardBitmap(
|
2012-07-18 08:23:16 -07:00
|
|
|
data, bufferWidth, bufferHeight, handler.mPageRect,
|
|
|
|
current.getPaintedRegion());
|
|
|
|
}
|
2012-06-14 09:08:51 -07:00
|
|
|
}
|
2012-07-18 08:23:16 -07:00
|
|
|
synchronized (handler.mPendingScreenshots) {
|
|
|
|
handler.mPendingScreenshots.remove();
|
|
|
|
handler.sendNextEventToGecko();
|
2012-06-14 09:08:51 -07:00
|
|
|
}
|
2012-07-17 22:39:46 -07:00
|
|
|
break;
|
|
|
|
}
|
2012-07-18 08:23:16 -07:00
|
|
|
case SCREENSHOT_THUMBNAIL:
|
2012-07-17 22:39:46 -07:00
|
|
|
{
|
2012-07-18 08:23:16 -07:00
|
|
|
Tab tab = Tabs.getInstance().getTab(tabId);
|
2012-07-20 09:38:02 -07:00
|
|
|
if (tab != null) {
|
|
|
|
GeckoApp.mAppContext.handleThumbnailData(tab, data);
|
|
|
|
}
|
2012-07-17 22:39:46 -07:00
|
|
|
break;
|
2012-06-14 09:08:51 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-17 22:39:46 -07:00
|
|
|
}
|
|
|
|
});
|
2012-06-06 19:39:01 -07:00
|
|
|
}
|
2012-07-18 08:23:16 -07:00
|
|
|
|
|
|
|
static class PendingScreenshot {
|
|
|
|
private final int mTabId;
|
|
|
|
private final LinkedList<GeckoEvent> mEvents;
|
|
|
|
private final Rect mPainted;
|
|
|
|
|
|
|
|
PendingScreenshot(int tabId) {
|
|
|
|
mTabId = tabId;
|
|
|
|
mEvents = new LinkedList<GeckoEvent>();
|
|
|
|
mPainted = new Rect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void addEvent(GeckoEvent event) {
|
|
|
|
mEvents.add(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean sendNextEventToGecko() {
|
|
|
|
if (!mEvents.isEmpty()) {
|
|
|
|
GeckoAppShell.sendEventToGecko(mEvents.remove());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void slicePainted(int left, int top, int right, int bottom) {
|
|
|
|
mPainted.union(left, top, right, bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect getPaintedRegion() {
|
|
|
|
return mPainted;
|
|
|
|
}
|
|
|
|
|
|
|
|
void discard() {
|
|
|
|
mEvents.clear();
|
|
|
|
}
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|