2013-05-29 00:25:55 +00:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
2012-05-21 11:12:37 +00: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 18:28:17 +00:00
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2013-11-04 19:48:58 +00:00
|
|
|
import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
|
2014-02-05 01:58:15 +00:00
|
|
|
import org.mozilla.gecko.favicons.decoders.FaviconDecoder;
|
2011-12-20 15:28:12 +00:00
|
|
|
import org.mozilla.gecko.gfx.BitmapUtils;
|
2012-02-03 07:30:41 +00:00
|
|
|
import org.mozilla.gecko.gfx.GeckoLayerClient;
|
2011-11-18 18:28:17 +00:00
|
|
|
import org.mozilla.gecko.gfx.LayerView;
|
2013-02-08 14:13:09 +00:00
|
|
|
import org.mozilla.gecko.gfx.PanZoomController;
|
2014-01-25 05:57:13 +00:00
|
|
|
import org.mozilla.gecko.mozglue.GeckoLoader;
|
2013-11-12 18:40:59 +00:00
|
|
|
import org.mozilla.gecko.mozglue.generatorannotations.OptionalGeneratedParameter;
|
|
|
|
import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI;
|
2014-01-25 05:57:13 +00:00
|
|
|
import org.mozilla.gecko.mozglue.JNITarget;
|
2013-12-05 02:32:53 +00:00
|
|
|
import org.mozilla.gecko.mozglue.RobocopTarget;
|
2014-01-25 05:57:13 +00:00
|
|
|
import org.mozilla.gecko.prompts.PromptService;
|
2014-01-09 18:18:55 +00:00
|
|
|
import org.mozilla.gecko.util.ActivityResultHandler;
|
2012-08-03 00:13:40 +00:00
|
|
|
import org.mozilla.gecko.util.GeckoEventListener;
|
2013-04-02 14:03:39 +00:00
|
|
|
import org.mozilla.gecko.util.HardwareUtils;
|
2014-01-07 23:46:44 +00:00
|
|
|
import org.mozilla.gecko.util.ProxySelector;
|
2013-03-15 10:52:53 +00:00
|
|
|
import org.mozilla.gecko.util.ThreadUtils;
|
2014-01-25 05:57:13 +00:00
|
|
|
import org.mozilla.gecko.webapp.Allocator;
|
2014-01-09 18:18:55 +00:00
|
|
|
import org.mozilla.gecko.webapp.InstallListener;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2013-05-24 16:21:01 +00:00
|
|
|
import android.app.Activity;
|
2012-07-28 00:54:28 +00:00
|
|
|
import android.app.ActivityManager;
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.content.ActivityNotFoundException;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2014-01-09 18:18:55 +00:00
|
|
|
import android.content.IntentFilter;
|
2012-08-21 11:20:26 +00:00
|
|
|
import android.content.SharedPreferences;
|
2012-07-28 00:54:28 +00:00
|
|
|
import android.content.pm.ActivityInfo;
|
2013-05-24 16:21:01 +00:00
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
|
import android.content.pm.PackageInfo;
|
2012-07-28 00:54:28 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2013-05-24 16:21:01 +00:00
|
|
|
import android.content.pm.PackageManager.NameNotFoundException;
|
2012-07-28 00:54:28 +00:00
|
|
|
import android.content.pm.ResolveInfo;
|
2013-05-24 16:21:01 +00:00
|
|
|
import android.content.pm.ServiceInfo;
|
|
|
|
import android.content.pm.Signature;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.content.res.TypedArray;
|
|
|
|
import android.graphics.Bitmap;
|
2012-07-28 00:54:28 +00:00
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.ImageFormat;
|
|
|
|
import android.graphics.Paint;
|
2013-07-04 13:53:25 +00:00
|
|
|
import android.graphics.PixelFormat;
|
2012-07-28 00:54:28 +00:00
|
|
|
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;
|
2013-05-24 16:21:01 +00:00
|
|
|
import android.hardware.SensorEventListener;
|
2012-07-28 00:54:28 +00:00
|
|
|
import android.location.Criteria;
|
|
|
|
import android.location.Location;
|
2013-05-24 16:21:01 +00:00
|
|
|
import android.location.LocationListener;
|
2012-07-28 00:54:28 +00:00
|
|
|
import android.location.LocationManager;
|
2011-11-18 18:28:17 +00:00
|
|
|
import android.media.MediaScannerConnection;
|
|
|
|
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
import android.net.NetworkInfo;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
2014-01-09 18:18:55 +00:00
|
|
|
import android.os.Environment;
|
2013-07-09 20:25:55 +00:00
|
|
|
import android.os.Handler;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.os.Looper;
|
|
|
|
import android.os.Message;
|
|
|
|
import android.os.MessageQueue;
|
2013-01-28 18:28:18 +00:00
|
|
|
import android.os.SystemClock;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.os.Vibrator;
|
|
|
|
import android.provider.Settings;
|
2013-12-23 19:09:25 +00:00
|
|
|
import android.support.v4.util.LruCache;
|
2013-11-19 04:43:09 +00:00
|
|
|
import android.telephony.TelephonyManager;
|
2013-04-08 07:51:56 +00:00
|
|
|
import android.text.TextUtils;
|
2012-07-28 00:54:28 +00:00
|
|
|
import android.util.Base64;
|
|
|
|
import android.util.DisplayMetrics;
|
|
|
|
import android.util.Log;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.view.ContextThemeWrapper;
|
|
|
|
import android.view.HapticFeedbackConstants;
|
|
|
|
import android.view.Surface;
|
2013-05-24 16:21:01 +00:00
|
|
|
import android.view.SurfaceView;
|
2013-07-01 06:01:57 +00:00
|
|
|
import android.view.TextureView;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
import android.webkit.MimeTypeMap;
|
2013-05-24 16:21:01 +00:00
|
|
|
import android.widget.AbsoluteLayout;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.widget.Toast;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-07-28 00:53:54 +00:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.Closeable;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
2013-02-21 16:24:08 +00:00
|
|
|
import java.io.FileReader;
|
2012-07-28 00:53:54 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.io.StringWriter;
|
2014-01-09 18:18:55 +00:00
|
|
|
import java.net.MalformedURLException;
|
2013-04-08 07:51:56 +00:00
|
|
|
import java.net.Proxy;
|
|
|
|
import java.net.URI;
|
2012-07-28 00:53:54 +00:00
|
|
|
import java.net.URL;
|
|
|
|
import java.nio.ByteBuffer;
|
2013-05-24 16:21:01 +00:00
|
|
|
import java.util.ArrayList;
|
2013-03-18 13:24:53 +00:00
|
|
|
import java.util.HashMap;
|
2012-07-28 00:53:54 +00:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2013-02-08 23:30:28 +00:00
|
|
|
import java.util.Locale;
|
2013-02-21 16:24:08 +00:00
|
|
|
import java.util.Map;
|
2012-07-28 00:53:54 +00:00
|
|
|
import java.util.NoSuchElementException;
|
|
|
|
import java.util.StringTokenizer;
|
2013-02-21 16:24:08 +00:00
|
|
|
import java.util.TreeMap;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-07-18 00:54:54 +00:00
|
|
|
public class GeckoAppShell
|
|
|
|
{
|
2011-11-18 18:28:17 +00: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;
|
|
|
|
|
2012-11-01 20:11:02 +00:00
|
|
|
static private GeckoEditableListener mEditableListener = null;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2013-03-18 13:24:53 +00:00
|
|
|
static private final HashMap<String, String>
|
|
|
|
mAlertCookies = new HashMap<String, String>();
|
|
|
|
|
2013-11-28 05:17:13 +00:00
|
|
|
// See also HardwareUtils.LOW_MEMORY_THRESHOLD_MB.
|
|
|
|
static private final int HIGH_MEMORY_DEVICE_THRESHOLD_MB = 768;
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
/* 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 21:34:02 +00:00
|
|
|
static public final int WPL_STATE_IS_NETWORK = 0x00040000;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2013-11-19 04:43:09 +00:00
|
|
|
/* Keep in sync with constants found here:
|
|
|
|
http://mxr.mozilla.org/mozilla-central/source/netwerk/base/public/nsINetworkLinkService.idl
|
|
|
|
*/
|
|
|
|
static public final int LINK_TYPE_UNKNOWN = 0;
|
|
|
|
static public final int LINK_TYPE_ETHERNET = 1;
|
|
|
|
static public final int LINK_TYPE_USB = 2;
|
|
|
|
static public final int LINK_TYPE_WIFI = 3;
|
|
|
|
static public final int LINK_TYPE_WIMAX = 4;
|
|
|
|
static public final int LINK_TYPE_2G = 5;
|
|
|
|
static public final int LINK_TYPE_3G = 6;
|
|
|
|
static public final int LINK_TYPE_4G = 7;
|
|
|
|
|
2012-04-20 04:54:50 +00:00
|
|
|
public static final String SHORTCUT_TYPE_WEBAPP = "webapp";
|
|
|
|
public static final String SHORTCUT_TYPE_BOOKMARK = "bookmark";
|
|
|
|
|
2012-08-22 15:37:08 +00:00
|
|
|
static private final boolean LOGGING = false;
|
|
|
|
|
2011-12-19 20:10:35 +00:00
|
|
|
static private int sDensityDpi = 0;
|
2013-07-04 13:53:25 +00:00
|
|
|
static private int sScreenDepth = 0;
|
2013-02-04 22:53:39 +00:00
|
|
|
|
2012-08-02 22:12:35 +00:00
|
|
|
private static final EventDispatcher sEventDispatcher = new EventDispatcher();
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-10-26 22:47:35 +00:00
|
|
|
/* Default colors. */
|
|
|
|
private static final float[] DEFAULT_LAUNCHER_ICON_HSV = { 32.0f, 1.0f, 1.0f };
|
|
|
|
|
2012-02-15 18:56:00 +00: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 23:57:09 +00:00
|
|
|
/* Default value of how fast we should hint the Android sensors. */
|
|
|
|
private static int sDefaultSensorHint = 100;
|
|
|
|
|
2012-03-13 23:57:51 +00: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 16:43:45 +00:00
|
|
|
private static Sensor gLightSensor = null;
|
2012-03-13 23:57:51 +00:00
|
|
|
|
2013-05-07 22:19:58 +00:00
|
|
|
private static volatile boolean mLocationHighAccuracy;
|
2012-03-21 17:52:35 +00:00
|
|
|
|
2013-03-21 20:32:11 +00:00
|
|
|
static NotificationClient sNotificationClient;
|
2012-07-13 18:08:19 +00:00
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
/* The Android-side API: API methods that Android calls */
|
|
|
|
|
|
|
|
// Initialization methods
|
|
|
|
public static native void nativeInit();
|
|
|
|
|
|
|
|
// helper methods
|
|
|
|
// public static native void setSurfaceView(GeckoSurfaceView sv);
|
2012-02-17 14:16:14 +00:00
|
|
|
public static native void setLayerClient(GeckoLayerClient client);
|
2011-11-18 18:28:17 +00:00
|
|
|
public static native void onResume();
|
2013-06-15 21:40:27 +00:00
|
|
|
public static void callObserver(String observerKey, String topic, String data) {
|
|
|
|
sendEventToGecko(GeckoEvent.createCallObserverEvent(observerKey, topic, data));
|
|
|
|
}
|
2013-06-19 17:55:35 +00:00
|
|
|
public static void removeObserver(String observerKey) {
|
|
|
|
sendEventToGecko(GeckoEvent.createRemoveObserverEvent(observerKey));
|
|
|
|
}
|
2012-06-01 00:07:07 +00:00
|
|
|
public static native Message getNextMessageFromQueue(MessageQueue queue);
|
2012-07-20 19:20:51 +00:00
|
|
|
public static native void onSurfaceTextureFrameAvailable(Object surfaceTexture, int id);
|
2013-11-27 11:52:05 +00:00
|
|
|
public static native void dispatchMemoryPressure();
|
2012-01-23 20:03:25 +00:00
|
|
|
|
2012-03-07 19:19:05 +00:00
|
|
|
public static void registerGlobalExceptionHandler() {
|
|
|
|
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-03-07 19:19:05 +00:00
|
|
|
public void uncaughtException(Thread thread, Throwable e) {
|
2014-01-18 05:32:24 +00:00
|
|
|
handleUncaughtException(thread, e);
|
2012-03-07 19:19:05 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getStackTraceString(Throwable e) {
|
2012-01-23 20:03:25 +00:00
|
|
|
StringWriter sw = new StringWriter();
|
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
|
e.printStackTrace(pw);
|
|
|
|
pw.flush();
|
2012-03-07 19:19:05 +00:00
|
|
|
return sw.toString();
|
2012-01-23 20:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static native void reportJavaCrash(String stackTrace);
|
|
|
|
|
2012-01-06 00:14:23 +00:00
|
|
|
public static void notifyUriVisited(String uri) {
|
2012-02-09 07:18:27 +00:00
|
|
|
sendEventToGecko(GeckoEvent.createVisitedEvent(uri));
|
2012-01-06 00:14:23 +00:00
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2013-05-10 01:48:00 +00:00
|
|
|
public static native void processNextNativeEvent(boolean mayWait);
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
public static native void notifyBatteryChange(double aLevel, boolean aCharging, double aRemainingTime);
|
|
|
|
|
2012-02-04 02:35:58 +00:00
|
|
|
public static native void scheduleComposite();
|
2013-01-10 17:32:43 +00:00
|
|
|
|
2013-02-08 21:42:13 +00:00
|
|
|
// Resuming the compositor is a synchronous request, so be
|
2013-01-10 17:32:43 +00:00
|
|
|
// careful of possible deadlock. Resuming the compositor will also cause
|
|
|
|
// a composition, so there is no need to schedule a composition after
|
|
|
|
// resuming.
|
2012-04-20 15:46:30 +00:00
|
|
|
public static native void scheduleResumeComposition(int width, int height);
|
2013-01-10 17:32:43 +00:00
|
|
|
|
2012-10-25 16:23:47 +00:00
|
|
|
public static native float computeRenderIntegrity();
|
2011-11-24 13:10:20 +00:00
|
|
|
|
2012-04-27 20:04:47 +00:00
|
|
|
public static native SurfaceBits getSurfaceBits(Surface surface);
|
|
|
|
|
2012-05-30 16:10:49 +00:00
|
|
|
public static native void onFullScreenPluginHidden(View view);
|
|
|
|
|
2013-11-04 19:48:58 +00:00
|
|
|
public static class CreateShortcutFaviconLoadedListener implements OnFaviconLoadedListener {
|
|
|
|
private final String title;
|
|
|
|
private final String url;
|
|
|
|
|
|
|
|
public CreateShortcutFaviconLoadedListener(final String url, final String title) {
|
|
|
|
this.url = url;
|
|
|
|
this.title = title;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFaviconLoaded(String pageUrl, String faviconURL, Bitmap favicon) {
|
|
|
|
GeckoAppShell.createShortcut(title, url, url, favicon, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-24 20:12:25 +00:00
|
|
|
private static final class GeckoMediaScannerClient implements MediaScannerConnectionClient {
|
|
|
|
private final String mFile;
|
|
|
|
private final String mMimeType;
|
|
|
|
private MediaScannerConnection mScanner;
|
|
|
|
|
|
|
|
public static void startScan(Context context, String file, String mimeType) {
|
|
|
|
new GeckoMediaScannerClient(context, file, mimeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
private GeckoMediaScannerClient(Context context, String file, String mimeType) {
|
|
|
|
mFile = file;
|
|
|
|
mMimeType = mimeType;
|
|
|
|
mScanner = new MediaScannerConnection(context, this);
|
|
|
|
mScanner.connect();
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-11-18 18:28:17 +00:00
|
|
|
public void onMediaScannerConnected() {
|
|
|
|
mScanner.scanFile(mFile, mMimeType);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-11-18 18:28:17 +00:00
|
|
|
public void onScanCompleted(String path, Uri uri) {
|
|
|
|
if(path.equals(mFile)) {
|
|
|
|
mScanner.disconnect();
|
|
|
|
mScanner = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-24 16:21:01 +00:00
|
|
|
private static LayerView sLayerView;
|
|
|
|
|
|
|
|
public static void setLayerView(LayerView lv) {
|
|
|
|
sLayerView = lv;
|
|
|
|
}
|
|
|
|
|
2013-12-06 19:43:12 +00:00
|
|
|
@RobocopTarget
|
2013-05-24 16:21:01 +00:00
|
|
|
public static LayerView getLayerView() {
|
|
|
|
return sLayerView;
|
|
|
|
}
|
|
|
|
|
2012-10-29 23:34:29 +00:00
|
|
|
public static void runGecko(String apkPath, String args, String url, String type) {
|
2013-07-09 20:25:55 +00:00
|
|
|
// Preparation for pumpMessageLoop()
|
|
|
|
MessageQueue.IdleHandler idleHandler = new MessageQueue.IdleHandler() {
|
|
|
|
@Override public boolean queueIdle() {
|
2013-07-26 19:02:00 +00:00
|
|
|
final Handler geckoHandler = ThreadUtils.sGeckoHandler;
|
2013-07-09 20:25:55 +00:00
|
|
|
Message idleMsg = Message.obtain(geckoHandler);
|
|
|
|
// Use |Message.obj == GeckoHandler| to identify our "queue is empty" message
|
|
|
|
idleMsg.obj = geckoHandler;
|
|
|
|
geckoHandler.sendMessageAtFrontOfQueue(idleMsg);
|
|
|
|
// Keep this IdleHandler
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Looper.myQueue().addIdleHandler(idleHandler);
|
2012-06-18 17:03:03 +00:00
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
// run gecko -- it will spawn its own thread
|
|
|
|
GeckoAppShell.nativeInit();
|
|
|
|
|
2013-05-24 16:21:01 +00:00
|
|
|
if (sLayerView != null)
|
|
|
|
GeckoAppShell.setLayerClient(sLayerView.getLayerClient());
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
// First argument is the .apk path
|
|
|
|
String combinedArgs = apkPath + " -greomni " + apkPath;
|
|
|
|
if (args != null)
|
|
|
|
combinedArgs += " " + args;
|
|
|
|
if (url != null)
|
2012-04-14 02:45:25 +00:00
|
|
|
combinedArgs += " -url " + url;
|
|
|
|
if (type != null)
|
|
|
|
combinedArgs += " " + type;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2013-05-24 16:21:01 +00:00
|
|
|
DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
|
2012-01-20 14:36:08 +00:00
|
|
|
combinedArgs += " -width " + metrics.widthPixels + " -height " + metrics.heightPixels;
|
|
|
|
|
2013-05-24 16:21:01 +00:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-12-12 08:27:34 +00:00
|
|
|
public void run() {
|
|
|
|
geckoLoaded();
|
|
|
|
}
|
|
|
|
});
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
// and go
|
2014-01-09 18:18:55 +00:00
|
|
|
Log.d(LOGTAG, "GeckoLoader.nativeRun " + combinedArgs);
|
2013-02-07 14:37:06 +00:00
|
|
|
GeckoLoader.nativeRun(combinedArgs);
|
2013-07-09 20:25:55 +00:00
|
|
|
|
|
|
|
// Remove pumpMessageLoop() idle handler
|
|
|
|
Looper.myQueue().removeIdleHandler(idleHandler);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Called on the UI thread after Gecko loads.
|
|
|
|
private static void geckoLoaded() {
|
2012-11-01 20:11:02 +00:00
|
|
|
GeckoEditable editable = new GeckoEditable();
|
|
|
|
// install the gecko => editable listener
|
|
|
|
mEditableListener = editable;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
2011-11-24 07:04:26 +00:00
|
|
|
|
2012-01-31 00:53:14 +00:00
|
|
|
static void sendPendingEventsToGecko() {
|
2011-11-18 18:28:17 +00:00
|
|
|
try {
|
|
|
|
while (!gPendingEvents.isEmpty()) {
|
|
|
|
GeckoEvent e = gPendingEvents.removeFirst();
|
|
|
|
notifyGeckoOfEvent(e);
|
|
|
|
}
|
|
|
|
} catch (NoSuchElementException e) {}
|
|
|
|
}
|
|
|
|
|
2013-12-06 19:43:11 +00:00
|
|
|
@RobocopTarget
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void sendEventToGecko(GeckoEvent e) {
|
2013-01-23 14:38:57 +00:00
|
|
|
if (GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) {
|
2011-11-18 18:28:17 +00:00
|
|
|
notifyGeckoOfEvent(e);
|
|
|
|
} else {
|
|
|
|
gPendingEvents.addLast(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
*/
|
2014-01-18 05:32:24 +00:00
|
|
|
|
2014-01-29 00:32:28 +00:00
|
|
|
@WrapElementForJNI(allowMultithread = true, generateStatic = true, noThrow = true)
|
2014-01-18 05:32:24 +00:00
|
|
|
public static void handleUncaughtException(Thread thread, Throwable e) {
|
|
|
|
if (thread == null) {
|
|
|
|
thread = Thread.currentThread();
|
|
|
|
}
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Log.e(LOGTAG, ">>> REPORTING UNCAUGHT EXCEPTION FROM THREAD "
|
|
|
|
+ thread.getId() + " (\"" + thread.getName() + "\")", e);
|
|
|
|
|
|
|
|
Thread mainThread = ThreadUtils.getUiThread();
|
|
|
|
if (mainThread != null && thread != mainThread) {
|
|
|
|
Log.e(LOGTAG, "Main thread stack:");
|
|
|
|
for (StackTraceElement ste : mainThread.getStackTrace()) {
|
|
|
|
Log.e(LOGTAG, ste.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e instanceof OutOfMemoryError) {
|
|
|
|
SharedPreferences prefs = getSharedPreferences();
|
|
|
|
SharedPreferences.Editor editor = prefs.edit();
|
|
|
|
editor.putBoolean(GeckoApp.PREFS_OOM_EXCEPTION, true);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
reportJavaCrash(getStackTraceString(e));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(generateStatic = true)
|
2013-03-19 20:54:49 +00:00
|
|
|
public static void notifyIME(int type) {
|
2012-11-01 20:11:02 +00:00
|
|
|
if (mEditableListener != null) {
|
2013-03-19 20:54:49 +00:00
|
|
|
mEditableListener.notifyIME(type);
|
2012-11-01 20:11:02 +00:00
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(generateStatic = true)
|
2013-03-19 20:54:48 +00:00
|
|
|
public static void notifyIMEContext(int state, String typeHint,
|
|
|
|
String modeHint, String actionHint) {
|
2012-11-01 20:11:02 +00:00
|
|
|
if (mEditableListener != null) {
|
2013-03-19 20:54:48 +00:00
|
|
|
mEditableListener.notifyIMEContext(state, typeHint,
|
2012-11-01 20:11:02 +00:00
|
|
|
modeHint, actionHint);
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(generateStatic = true)
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void notifyIMEChange(String text, int start, int end, int newEnd) {
|
2012-11-01 20:11:02 +00:00
|
|
|
if (newEnd < 0) { // Selection change
|
|
|
|
mEditableListener.onSelectionChange(start, end);
|
|
|
|
} else { // Text change
|
|
|
|
mEditableListener.onTextChange(text, start, end, newEnd);
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-03-10 22:43:30 +00:00
|
|
|
private static final Object sEventAckLock = new Object();
|
|
|
|
private static boolean sWaitingForEventAck;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
// Block the current thread until the Gecko event loop is caught up
|
2013-03-10 22:43:30 +00:00
|
|
|
public static void sendEventToGeckoSync(GeckoEvent e) {
|
|
|
|
e.setAckNeeded(true);
|
|
|
|
|
2013-01-28 18:28:18 +00:00
|
|
|
long time = SystemClock.uptimeMillis();
|
2013-03-15 10:52:53 +00:00
|
|
|
boolean isUiThread = ThreadUtils.isOnUiThread();
|
2013-01-28 18:28:18 +00:00
|
|
|
|
2013-03-10 22:43:30 +00:00
|
|
|
synchronized (sEventAckLock) {
|
|
|
|
if (sWaitingForEventAck) {
|
2013-02-01 16:45:16 +00:00
|
|
|
// should never happen since we always leave it as false when we exit this function.
|
|
|
|
Log.e(LOGTAG, "geckoEventSync() may have been called twice concurrently!", new Exception());
|
|
|
|
// fall through for graceful handling
|
|
|
|
}
|
2013-01-28 18:28:18 +00:00
|
|
|
|
2013-03-10 22:43:30 +00:00
|
|
|
sendEventToGecko(e);
|
|
|
|
sWaitingForEventAck = true;
|
2013-02-01 16:45:16 +00:00
|
|
|
while (true) {
|
|
|
|
try {
|
2013-06-26 14:59:37 +00:00
|
|
|
sEventAckLock.wait(1000);
|
2013-02-01 16:45:16 +00:00
|
|
|
} catch (InterruptedException ie) {
|
|
|
|
}
|
2013-03-10 22:43:30 +00:00
|
|
|
if (!sWaitingForEventAck) {
|
2013-02-01 16:45:16 +00:00
|
|
|
// response received
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
long waited = SystemClock.uptimeMillis() - time;
|
|
|
|
Log.d(LOGTAG, "Gecko event sync taking too long: " + waited + "ms");
|
|
|
|
}
|
2013-01-28 18:28:18 +00:00
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Signal the Java thread that it's time to wake up
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2013-03-10 22:43:30 +00:00
|
|
|
public static void acknowledgeEvent() {
|
|
|
|
synchronized (sEventAckLock) {
|
|
|
|
sWaitingForEventAck = false;
|
|
|
|
sEventAckLock.notifyAll();
|
2013-02-01 16:45:16 +00:00
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 22:19:58 +00:00
|
|
|
private static float getLocationAccuracy(Location location) {
|
|
|
|
float radius = location.getAccuracy();
|
|
|
|
return (location.hasAccuracy() && radius > 0) ? radius : 1001;
|
|
|
|
}
|
|
|
|
|
2013-05-17 16:21:04 +00:00
|
|
|
private static Location getLastKnownLocation(LocationManager lm) {
|
2013-05-07 22:19:58 +00:00
|
|
|
Location lastKnownLocation = null;
|
|
|
|
List<String> providers = lm.getAllProviders();
|
|
|
|
|
|
|
|
for (String provider : providers) {
|
|
|
|
Location location = lm.getLastKnownLocation(provider);
|
|
|
|
if (location == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastKnownLocation == null) {
|
|
|
|
lastKnownLocation = location;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-08 22:21:57 +00:00
|
|
|
long timeDiff = location.getTime() - lastKnownLocation.getTime();
|
2013-05-07 22:19:58 +00:00
|
|
|
if (timeDiff > 0 ||
|
|
|
|
(timeDiff == 0 &&
|
|
|
|
getLocationAccuracy(location) < getLocationAccuracy(lastKnownLocation))) {
|
|
|
|
lastKnownLocation = location;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lastKnownLocation;
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void enableLocation(final boolean enable) {
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-11-18 18:28:17 +00:00
|
|
|
public void run() {
|
2013-05-24 16:21:01 +00:00
|
|
|
LocationManager lm = getLocationManager(getContext());
|
2013-05-17 16:21:04 +00:00
|
|
|
if (lm == null) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
if (enable) {
|
2013-05-17 16:21:04 +00:00
|
|
|
Location lastKnownLocation = getLastKnownLocation(lm);
|
2013-05-07 22:19:58 +00:00
|
|
|
if (lastKnownLocation != null) {
|
2013-05-24 16:21:01 +00:00
|
|
|
getGeckoInterface().getLocationListener().onLocationChanged(lastKnownLocation);
|
2013-05-07 22:19:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-14 00:01:58 +00:00
|
|
|
Criteria criteria = new Criteria();
|
2012-03-21 17:52:35 +00: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-14 00:01:58 +00:00
|
|
|
String provider = lm.getBestProvider(criteria, true);
|
2011-11-18 18:28:17 +00:00
|
|
|
if (provider == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Looper l = Looper.getMainLooper();
|
2013-05-24 16:21:01 +00:00
|
|
|
lm.requestLocationUpdates(provider, 100, (float).5, getGeckoInterface().getLocationListener(), l);
|
2011-11-18 18:28:17 +00:00
|
|
|
} else {
|
2013-05-24 16:21:01 +00:00
|
|
|
lm.removeUpdates(getGeckoInterface().getLocationListener());
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-05-17 16:21:04 +00:00
|
|
|
private static LocationManager getLocationManager(Context context) {
|
|
|
|
try {
|
|
|
|
return (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
|
|
|
} catch (NoSuchFieldError e) {
|
|
|
|
// Some Tegras throw exceptions about missing the CONTROL_LOCATION_UPDATES permission,
|
|
|
|
// which allows enabling/disabling location update notifications from the cell radio.
|
|
|
|
// CONTROL_LOCATION_UPDATES is not for use by normal applications, but we might be
|
|
|
|
// hitting this problem if the Tegras are confused about missing cell radios.
|
|
|
|
Log.e(LOGTAG, "LOCATION_SERVICE not found?!", e);
|
|
|
|
return null;
|
|
|
|
}
|
2013-05-07 22:19:58 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-03-21 17:52:35 +00:00
|
|
|
public static void enableLocationHighAccuracy(final boolean enable) {
|
|
|
|
mLocationHighAccuracy = enable;
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-02-05 19:54:25 +00:00
|
|
|
public static void enableSensor(int aSensortype) {
|
2013-05-24 16:21:01 +00:00
|
|
|
GeckoInterface gi = getGeckoInterface();
|
|
|
|
if (gi == null)
|
|
|
|
return;
|
2012-02-05 19:54:25 +00:00
|
|
|
SensorManager sm = (SensorManager)
|
2013-05-24 16:21:01 +00:00
|
|
|
getContext().getSystemService(Context.SENSOR_SERVICE);
|
2012-02-05 19:54:25 +00:00
|
|
|
|
|
|
|
switch(aSensortype) {
|
2012-03-13 23:57:51 +00:00
|
|
|
case GeckoHalDefines.SENSOR_ORIENTATION:
|
|
|
|
if(gOrientationSensor == null)
|
|
|
|
gOrientationSensor = sm.getDefaultSensor(Sensor.TYPE_ORIENTATION);
|
2013-05-24 16:21:01 +00:00
|
|
|
if (gOrientationSensor != null)
|
|
|
|
sm.registerListener(gi.getSensorEventListener(), gOrientationSensor, sDefaultSensorHint);
|
2012-03-13 23:57:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoHalDefines.SENSOR_ACCELERATION:
|
|
|
|
if(gAccelerometerSensor == null)
|
|
|
|
gAccelerometerSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
|
|
|
if (gAccelerometerSensor != null)
|
2013-05-24 16:21:01 +00:00
|
|
|
sm.registerListener(gi.getSensorEventListener(), gAccelerometerSensor, sDefaultSensorHint);
|
2012-03-13 23:57:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoHalDefines.SENSOR_PROXIMITY:
|
2013-05-24 16:21:01 +00:00
|
|
|
if(gProximitySensor == null )
|
2012-02-05 19:54:25 +00:00
|
|
|
gProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
2012-03-13 23:57:51 +00:00
|
|
|
if (gProximitySensor != null)
|
2013-05-24 16:21:01 +00:00
|
|
|
sm.registerListener(gi.getSensorEventListener(), gProximitySensor, SensorManager.SENSOR_DELAY_NORMAL);
|
2012-03-13 23:57:51 +00:00
|
|
|
break;
|
|
|
|
|
2012-05-02 16:43:45 +00:00
|
|
|
case GeckoHalDefines.SENSOR_LIGHT:
|
|
|
|
if(gLightSensor == null)
|
|
|
|
gLightSensor = sm.getDefaultSensor(Sensor.TYPE_LIGHT);
|
|
|
|
if (gLightSensor != null)
|
2013-05-24 16:21:01 +00:00
|
|
|
sm.registerListener(gi.getSensorEventListener(), gLightSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
2012-05-02 16:43:45 +00:00
|
|
|
break;
|
|
|
|
|
2012-03-13 23:57:51 +00:00
|
|
|
case GeckoHalDefines.SENSOR_LINEAR_ACCELERATION:
|
|
|
|
if(gLinearAccelerometerSensor == null)
|
2012-03-21 06:36:17 +00:00
|
|
|
gLinearAccelerometerSensor = sm.getDefaultSensor(10 /* API Level 9 - TYPE_LINEAR_ACCELERATION */);
|
2012-03-13 23:57:51 +00:00
|
|
|
if (gLinearAccelerometerSensor != null)
|
2013-05-24 16:21:01 +00:00
|
|
|
sm.registerListener(gi.getSensorEventListener(), gLinearAccelerometerSensor, sDefaultSensorHint);
|
2012-03-13 23:57:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoHalDefines.SENSOR_GYROSCOPE:
|
|
|
|
if(gGyroscopeSensor == null)
|
|
|
|
gGyroscopeSensor = sm.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
|
|
|
|
if (gGyroscopeSensor != null)
|
2013-05-24 16:21:01 +00:00
|
|
|
sm.registerListener(gi.getSensorEventListener(), gGyroscopeSensor, sDefaultSensorHint);
|
2012-02-05 19:54:25 +00:00
|
|
|
break;
|
2012-03-21 06:36:17 +00:00
|
|
|
default:
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.w(LOGTAG, "Error! Can't enable unknown SENSOR type " + aSensortype);
|
2012-02-05 19:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-02-05 19:54:25 +00:00
|
|
|
public static void disableSensor(int aSensortype) {
|
2013-05-24 16:21:01 +00:00
|
|
|
GeckoInterface gi = getGeckoInterface();
|
|
|
|
if (gi == null)
|
|
|
|
return;
|
|
|
|
|
2012-02-05 19:54:25 +00:00
|
|
|
SensorManager sm = (SensorManager)
|
2013-05-24 16:21:01 +00:00
|
|
|
getContext().getSystemService(Context.SENSOR_SERVICE);
|
2012-02-05 19:54:25 +00:00
|
|
|
|
2012-03-13 23:57:51 +00:00
|
|
|
switch (aSensortype) {
|
|
|
|
case GeckoHalDefines.SENSOR_ORIENTATION:
|
|
|
|
if (gOrientationSensor != null)
|
2013-05-24 16:21:01 +00:00
|
|
|
sm.unregisterListener(gi.getSensorEventListener(), gOrientationSensor);
|
2012-03-13 23:57:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoHalDefines.SENSOR_ACCELERATION:
|
|
|
|
if (gAccelerometerSensor != null)
|
2013-05-24 16:21:01 +00:00
|
|
|
sm.unregisterListener(gi.getSensorEventListener(), gAccelerometerSensor);
|
2012-03-13 23:57:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoHalDefines.SENSOR_PROXIMITY:
|
|
|
|
if (gProximitySensor != null)
|
2013-05-24 16:21:01 +00:00
|
|
|
sm.unregisterListener(gi.getSensorEventListener(), gProximitySensor);
|
2012-03-13 23:57:51 +00:00
|
|
|
break;
|
|
|
|
|
2012-05-02 16:43:45 +00:00
|
|
|
case GeckoHalDefines.SENSOR_LIGHT:
|
|
|
|
if (gLightSensor != null)
|
2013-05-24 16:21:01 +00:00
|
|
|
sm.unregisterListener(gi.getSensorEventListener(), gLightSensor);
|
2012-05-02 16:43:45 +00:00
|
|
|
break;
|
|
|
|
|
2012-03-13 23:57:51 +00:00
|
|
|
case GeckoHalDefines.SENSOR_LINEAR_ACCELERATION:
|
|
|
|
if (gLinearAccelerometerSensor != null)
|
2013-05-24 16:21:01 +00:00
|
|
|
sm.unregisterListener(gi.getSensorEventListener(), gLinearAccelerometerSensor);
|
2012-03-13 23:57:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoHalDefines.SENSOR_GYROSCOPE:
|
|
|
|
if (gGyroscopeSensor != null)
|
2013-05-24 16:21:01 +00:00
|
|
|
sm.unregisterListener(gi.getSensorEventListener(), gGyroscopeSensor);
|
2012-02-05 19:54:25 +00:00
|
|
|
break;
|
2012-03-21 06:36:17 +00:00
|
|
|
default:
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.w(LOGTAG, "Error! Can't disable unknown SENSOR type " + aSensortype);
|
2012-02-05 19:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void moveTaskToBack() {
|
2013-05-24 16:21:01 +00:00
|
|
|
if (getGeckoInterface() != null)
|
|
|
|
getGeckoInterface().getActivity().moveTaskToBack(true);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void returnIMEQueryResult(String result, int selectionStart, int selectionLength) {
|
2012-03-23 21:00:19 +00: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 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "NotifyXreExit")
|
2012-07-18 05:39:46 +00:00
|
|
|
static void onXreExit() {
|
2013-01-23 14:38:57 +00:00
|
|
|
// The launch state can only be Launched or GeckoRunning at this point
|
|
|
|
GeckoThread.setLaunchState(GeckoThread.LaunchState.GeckoExiting);
|
2013-05-24 16:21:01 +00:00
|
|
|
if (getGeckoInterface() != null) {
|
|
|
|
if (gRestartScheduled) {
|
|
|
|
getGeckoInterface().doRestart();
|
|
|
|
} else {
|
|
|
|
getGeckoInterface().getActivity().finish();
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.d(LOGTAG, "Killing via System.exit()");
|
2011-11-18 18:28:17 +00:00
|
|
|
System.exit(0);
|
|
|
|
}
|
2012-06-18 17:03:03 +00:00
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-07-18 05:39:46 +00:00
|
|
|
static void scheduleRestart() {
|
2011-11-18 18:28:17 +00:00
|
|
|
gRestartScheduled = true;
|
|
|
|
}
|
|
|
|
|
2014-02-12 07:41:05 +00:00
|
|
|
public static Intent getWebappIntent(String aURI, String aOrigin, String aTitle, Bitmap aIcon) {
|
2014-01-09 18:18:55 +00:00
|
|
|
Intent intent;
|
2012-06-18 17:03:03 +00:00
|
|
|
|
2014-01-09 18:18:55 +00:00
|
|
|
if (AppConstants.MOZ_ANDROID_SYNTHAPKS) {
|
2014-01-25 05:57:13 +00:00
|
|
|
Allocator slots = Allocator.getInstance(getContext());
|
2014-01-09 18:18:55 +00:00
|
|
|
int index = slots.getIndexForOrigin(aOrigin);
|
2012-06-18 17:03:03 +00:00
|
|
|
|
2014-01-09 18:18:55 +00:00
|
|
|
if (index == -1) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
String packageName = slots.getAppForIndex(index);
|
|
|
|
intent = getContext().getPackageManager().getLaunchIntentForPackage(packageName);
|
|
|
|
if (aURI != null) {
|
|
|
|
intent.setData(Uri.parse(aURI));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int index;
|
|
|
|
if (aIcon != null && !TextUtils.isEmpty(aTitle))
|
2014-02-12 07:41:05 +00:00
|
|
|
index = WebappAllocator.getInstance(getContext()).findAndAllocateIndex(aOrigin, aTitle, aIcon);
|
2014-01-09 18:18:55 +00:00
|
|
|
else
|
2014-02-12 07:41:05 +00:00
|
|
|
index = WebappAllocator.getInstance(getContext()).getIndexForApp(aOrigin);
|
2014-01-09 18:18:55 +00:00
|
|
|
|
|
|
|
if (index == -1)
|
|
|
|
return null;
|
|
|
|
|
2014-02-12 07:41:05 +00:00
|
|
|
intent = getWebappIntent(index, aURI);
|
2014-01-09 18:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return intent;
|
2012-08-22 15:37:14 +00:00
|
|
|
}
|
|
|
|
|
2014-02-12 07:41:05 +00:00
|
|
|
// The old implementation of getWebappIntent. Not used by MOZ_ANDROID_SYNTHAPKS.
|
|
|
|
public static Intent getWebappIntent(int aIndex, String aURI) {
|
2012-06-18 17:03:03 +00:00
|
|
|
Intent intent = new Intent();
|
2012-08-22 15:37:14 +00:00
|
|
|
intent.setAction(GeckoApp.ACTION_WEBAPP_PREFIX + aIndex);
|
2012-06-18 17:03:03 +00:00
|
|
|
intent.setData(Uri.parse(aURI));
|
2013-04-10 00:10:47 +00:00
|
|
|
intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME,
|
2013-04-17 23:24:02 +00:00
|
|
|
AppConstants.ANDROID_PACKAGE_NAME + ".WebApps$WebApp" + aIndex);
|
2012-06-18 17:03:03 +00:00
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
// "Installs" an application by creating a shortcut
|
2012-06-18 17:03:03 +00:00
|
|
|
// This is the entry point from AndroidBridge.h
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-07-18 05:39:46 +00:00
|
|
|
static void createShortcut(String aTitle, String aURI, String aIconData, String aType) {
|
2012-06-18 17:03:03 +00:00
|
|
|
if ("webapp".equals(aType)) {
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.w(LOGTAG, "createShortcut with no unique URI should not be used for aType = webapp!");
|
2012-06-18 17:03:03 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 18:32:05 +00:00
|
|
|
createShortcut(aTitle, aURI, aURI, aIconData, aType);
|
2012-06-18 17:03:03 +00:00
|
|
|
}
|
|
|
|
|
2014-02-05 01:58:15 +00:00
|
|
|
// For non-webapps.
|
2013-05-31 21:36:39 +00:00
|
|
|
public static void createShortcut(String aTitle, String aURI, Bitmap aBitmap, String aType) {
|
2012-06-18 17:03:03 +00:00
|
|
|
createShortcut(aTitle, aURI, aURI, aBitmap, aType);
|
|
|
|
}
|
|
|
|
|
2014-02-05 01:58:15 +00:00
|
|
|
// Internal, for webapps.
|
|
|
|
static void createShortcut(final String aTitle, final String aURI, final String aUniqueURI, final String aIconData, final String aType) {
|
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
// TODO: use the cache. Bug 961600.
|
|
|
|
Bitmap icon = FaviconDecoder.getMostSuitableBitmapFromDataURI(aIconData, getPreferredIconSize());
|
|
|
|
GeckoAppShell.doCreateShortcut(aTitle, aURI, aURI, icon, aType);
|
|
|
|
}
|
|
|
|
});
|
2011-12-20 15:28:12 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 17:03:03 +00:00
|
|
|
public static void createShortcut(final String aTitle, final String aURI, final String aUniqueURI,
|
2014-02-05 01:58:15 +00:00
|
|
|
final Bitmap aIcon, final String aType) {
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-12-20 15:28:12 +00:00
|
|
|
public void run() {
|
2014-02-05 01:58:15 +00:00
|
|
|
GeckoAppShell.doCreateShortcut(aTitle, aURI, aUniqueURI, aIcon, aType);
|
2011-12-20 15:28:12 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-02-05 01:58:15 +00:00
|
|
|
/**
|
|
|
|
* Call this method only on the background thread.
|
|
|
|
*/
|
|
|
|
private static void doCreateShortcut(final String aTitle, final String aURI, final String aUniqueURI,
|
|
|
|
final Bitmap aIcon, final String aType) {
|
|
|
|
// The intent to be launched by the shortcut.
|
|
|
|
Intent shortcutIntent;
|
|
|
|
if (aType.equalsIgnoreCase(SHORTCUT_TYPE_WEBAPP)) {
|
2014-02-12 07:41:05 +00:00
|
|
|
shortcutIntent = getWebappIntent(aURI, aUniqueURI, aTitle, aIcon);
|
2014-02-05 01:58:15 +00:00
|
|
|
} else {
|
|
|
|
shortcutIntent = new Intent();
|
|
|
|
shortcutIntent.setAction(GeckoApp.ACTION_BOOKMARK);
|
|
|
|
shortcutIntent.setData(Uri.parse(aURI));
|
|
|
|
shortcutIntent.setClassName(AppConstants.ANDROID_PACKAGE_NAME,
|
|
|
|
AppConstants.BROWSER_INTENT_CLASS);
|
|
|
|
}
|
|
|
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
|
|
|
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, getLauncherIcon(aIcon, aType));
|
|
|
|
|
|
|
|
if (aTitle != null) {
|
|
|
|
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, aTitle);
|
|
|
|
} else {
|
|
|
|
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not allow duplicate items.
|
|
|
|
intent.putExtra("duplicate", false);
|
|
|
|
|
|
|
|
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
|
|
|
getContext().sendBroadcast(intent);
|
|
|
|
}
|
|
|
|
|
2012-06-06 20:52:14 +00:00
|
|
|
public static void removeShortcut(final String aTitle, final String aURI, final String aType) {
|
2012-06-18 17:03:03 +00:00
|
|
|
removeShortcut(aTitle, aURI, null, aType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void removeShortcut(final String aTitle, final String aURI, final String aUniqueURI, final String aType) {
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-06-06 20:52:14 +00:00
|
|
|
public void run() {
|
|
|
|
// the intent to be launched by the shortcut
|
2012-06-18 17:03:03 +00:00
|
|
|
Intent shortcutIntent;
|
2012-06-06 20:52:14 +00:00
|
|
|
if (aType.equalsIgnoreCase(SHORTCUT_TYPE_WEBAPP)) {
|
2014-02-12 07:41:05 +00:00
|
|
|
shortcutIntent = getWebappIntent(aURI, aUniqueURI, "", null);
|
2012-06-18 17:03:03 +00:00
|
|
|
if (shortcutIntent == null)
|
|
|
|
return;
|
2012-06-06 20:52:14 +00:00
|
|
|
} else {
|
2012-06-18 17:03:03 +00:00
|
|
|
shortcutIntent = new Intent();
|
2012-06-06 20:52:14 +00:00
|
|
|
shortcutIntent.setAction(GeckoApp.ACTION_BOOKMARK);
|
2013-04-10 00:10:47 +00:00
|
|
|
shortcutIntent.setClassName(AppConstants.ANDROID_PACKAGE_NAME,
|
|
|
|
AppConstants.BROWSER_INTENT_CLASS);
|
2012-06-18 17:03:03 +00:00
|
|
|
shortcutIntent.setData(Uri.parse(aURI));
|
2012-06-06 20:52:14 +00: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");
|
2013-05-24 16:21:01 +00:00
|
|
|
getContext().sendBroadcast(intent);
|
2012-06-06 20:52:14 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-11-21 22:44:00 +00:00
|
|
|
@JNITarget
|
2012-09-12 18:32:05 +00:00
|
|
|
static public int getPreferredIconSize() {
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
2013-05-24 16:21:01 +00:00
|
|
|
ActivityManager am = (ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE);
|
2012-09-12 18:32:05 +00:00
|
|
|
return am.getLauncherLargeIconSize();
|
|
|
|
} else {
|
|
|
|
switch (getDpi()) {
|
|
|
|
case DisplayMetrics.DENSITY_MEDIUM:
|
|
|
|
return 48;
|
|
|
|
case DisplayMetrics.DENSITY_XHIGH:
|
|
|
|
return 96;
|
|
|
|
case DisplayMetrics.DENSITY_HIGH:
|
|
|
|
default:
|
|
|
|
return 72;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-20 04:54:50 +00:00
|
|
|
static private Bitmap getLauncherIcon(Bitmap aSource, String aType) {
|
2011-12-20 15:28:12 +00:00
|
|
|
final int kOffset = 6;
|
|
|
|
final int kRadius = 5;
|
2012-09-12 18:32:05 +00:00
|
|
|
int size = getPreferredIconSize();
|
2012-10-26 22:47:35 +00:00
|
|
|
int insetSize = aSource != null ? size * 2 / 3 : size;
|
2011-12-20 15:28:12 +00:00
|
|
|
|
2012-09-12 18:32:05 +00:00
|
|
|
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
2011-12-20 15:28:12 +00:00
|
|
|
Canvas canvas = new Canvas(bitmap);
|
|
|
|
|
2012-04-20 04:54:50 +00:00
|
|
|
|
2011-12-20 15:28:12 +00:00
|
|
|
// draw a base color
|
|
|
|
Paint paint = new Paint();
|
|
|
|
if (aSource == null) {
|
2012-10-26 22:47:35 +00:00
|
|
|
// If we aren't drawing a favicon, just use an orange color.
|
|
|
|
paint.setColor(Color.HSVToColor(DEFAULT_LAUNCHER_ICON_HSV));
|
2012-09-12 18:32:05 +00:00
|
|
|
canvas.drawRoundRect(new RectF(kOffset, kOffset, size - kOffset, size - kOffset), kRadius, kRadius, paint);
|
2013-07-02 17:00:10 +00:00
|
|
|
} else if (aType.equalsIgnoreCase(SHORTCUT_TYPE_WEBAPP) || aSource.getWidth() >= insetSize || aSource.getHeight() >= insetSize) {
|
|
|
|
// otherwise, if this is a webapp or if the icons is lare enough, just draw it
|
|
|
|
Rect iconBounds = new Rect(0, 0, size, size);
|
|
|
|
canvas.drawBitmap(aSource, null, iconBounds, null);
|
|
|
|
return bitmap;
|
2011-12-20 15:28:12 +00:00
|
|
|
} else {
|
2012-09-12 18:32:05 +00:00
|
|
|
// otherwise use the dominant color from the icon + a layer of transparent white to lighten it somewhat
|
2011-12-20 15:28:12 +00:00
|
|
|
int color = BitmapUtils.getDominantColor(aSource);
|
|
|
|
paint.setColor(color);
|
2012-09-12 18:32:05 +00:00
|
|
|
canvas.drawRoundRect(new RectF(kOffset, kOffset, size - kOffset, size - kOffset), kRadius, kRadius, paint);
|
2011-12-20 15:28:12 +00:00
|
|
|
paint.setColor(Color.argb(100, 255, 255, 255));
|
2012-09-12 18:32:05 +00:00
|
|
|
canvas.drawRoundRect(new RectF(kOffset, kOffset, size - kOffset, size - kOffset), kRadius, kRadius, paint);
|
2011-12-20 15:28:12 +00:00
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2011-12-20 15:28:12 +00:00
|
|
|
// draw the overlay
|
2013-05-24 16:21:01 +00:00
|
|
|
Bitmap overlay = BitmapUtils.decodeResource(getContext(), R.drawable.home_bg);
|
2012-09-12 18:32:05 +00:00
|
|
|
canvas.drawBitmap(overlay, null, new Rect(0, 0, size, size), null);
|
2011-12-20 15:28:12 +00:00
|
|
|
|
2012-09-12 18:32:05 +00:00
|
|
|
// draw the favicon
|
2011-12-20 15:28:12 +00:00
|
|
|
if (aSource == null)
|
2013-05-24 16:21:01 +00:00
|
|
|
aSource = BitmapUtils.decodeResource(getContext(), R.drawable.home_star);
|
2011-12-20 15:28:12 +00:00
|
|
|
|
2012-09-12 18:32:05 +00:00
|
|
|
// by default, we scale the icon to this size
|
2012-10-26 22:47:35 +00:00
|
|
|
int sWidth = insetSize / 2;
|
2012-09-12 18:32:05 +00:00
|
|
|
int sHeight = sWidth;
|
|
|
|
|
2012-10-26 22:47:35 +00:00
|
|
|
int halfSize = size / 2;
|
2012-09-12 18:32:05 +00:00
|
|
|
canvas.drawBitmap(aSource,
|
|
|
|
null,
|
|
|
|
new Rect(halfSize - sWidth,
|
|
|
|
halfSize - sHeight,
|
|
|
|
halfSize + sWidth,
|
|
|
|
halfSize + sHeight),
|
|
|
|
null);
|
|
|
|
|
2011-12-20 15:28:12 +00:00
|
|
|
return bitmap;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetHandlersForMimeTypeWrapper")
|
2012-07-18 05:39:46 +00:00
|
|
|
static String[] getHandlersForMimeType(String aMimeType, String aAction) {
|
2011-11-18 18:28:17 +00:00
|
|
|
Intent intent = getIntentForActionString(aAction);
|
|
|
|
if (aMimeType != null && aMimeType.length() > 0)
|
|
|
|
intent.setType(aMimeType);
|
|
|
|
return getHandlersForIntent(intent);
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetHandlersForURLWrapper")
|
2012-07-18 05:39:46 +00:00
|
|
|
static String[] getHandlersForURL(String aURL, String aAction) {
|
2011-11-18 18:28:17 +00: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();
|
2013-04-25 20:31:50 +00:00
|
|
|
|
2013-05-24 16:21:01 +00:00
|
|
|
Intent intent = getOpenURIIntent(getContext(), uri.toString(), "",
|
2013-04-25 20:31:50 +00:00
|
|
|
TextUtils.isEmpty(aAction) ? Intent.ACTION_VIEW : aAction, "");
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
return getHandlersForIntent(intent);
|
|
|
|
}
|
|
|
|
|
2013-05-06 23:26:13 +00:00
|
|
|
static boolean hasHandlersForIntent(Intent intent) {
|
2013-05-24 16:21:01 +00:00
|
|
|
PackageManager pm = getContext().getPackageManager();
|
2013-05-06 23:26:13 +00:00
|
|
|
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
|
|
|
|
return !list.isEmpty();
|
|
|
|
}
|
|
|
|
|
2012-07-18 05:39:46 +00:00
|
|
|
static String[] getHandlersForIntent(Intent intent) {
|
2013-05-24 16:21:01 +00:00
|
|
|
PackageManager pm = getContext().getPackageManager();
|
2011-11-18 18:28:17 +00:00
|
|
|
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-18 05:39:46 +00:00
|
|
|
static Intent getIntentForActionString(String aAction) {
|
2011-11-18 18:28:17 +00:00
|
|
|
// Default to the view action if no other action as been specified.
|
2013-05-06 23:26:13 +00:00
|
|
|
if (TextUtils.isEmpty(aAction)) {
|
2011-11-18 18:28:17 +00:00
|
|
|
return new Intent(Intent.ACTION_VIEW);
|
2013-05-06 23:26:13 +00:00
|
|
|
}
|
|
|
|
return new Intent(aAction);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetExtensionFromMimeTypeWrapper")
|
2012-07-18 05:39:46 +00:00
|
|
|
static String getExtensionFromMimeType(String aMimeType) {
|
2011-11-18 18:28:17 +00:00
|
|
|
return MimeTypeMap.getSingleton().getExtensionFromMimeType(aMimeType);
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetMimeTypeFromExtensionsWrapper")
|
2012-07-18 05:39:46 +00:00
|
|
|
static String getMimeTypeFromExtensions(String aFileExt) {
|
2012-10-02 18:00:19 +00:00
|
|
|
StringTokenizer st = new StringTokenizer(aFileExt, ".,; ");
|
2011-11-18 18:28:17 +00:00
|
|
|
String type = null;
|
|
|
|
String subType = null;
|
|
|
|
while (st.hasMoreElements()) {
|
|
|
|
String ext = st.nextToken();
|
2013-09-11 17:21:57 +00:00
|
|
|
String mt = getMimeTypeFromExtension(ext);
|
2011-11-18 18:28:17 +00:00
|
|
|
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 21:25:15 +00: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 21:36:48 +00:00
|
|
|
|
|
|
|
if (dir == null) {
|
|
|
|
showImageShareFailureToast();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-10 21:25:15 +00: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 21:36:48 +00:00
|
|
|
showImageShareFailureToast();
|
2012-07-10 21:25:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
safeStreamClose(os);
|
|
|
|
}
|
2013-05-24 16:21:01 +00:00
|
|
|
getContext().startActivity(Intent.createChooser(intent,
|
|
|
|
getContext().getResources().getString(R.string.share_title)));
|
2012-07-10 21:25:15 +00:00
|
|
|
}
|
|
|
|
|
2012-07-19 21:36:48 +00:00
|
|
|
// Don't fail silently, tell the user that we weren't able to share the image
|
|
|
|
private static final void showImageShareFailureToast() {
|
2013-05-24 16:21:01 +00:00
|
|
|
Toast toast = Toast.makeText(getContext(),
|
|
|
|
getContext().getResources().getString(R.string.share_image_failed),
|
2012-07-19 21:36:48 +00:00
|
|
|
Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
|
2012-12-13 18:06:05 +00:00
|
|
|
static boolean isUriSafeForScheme(Uri aUri) {
|
|
|
|
// Bug 794034 - We don't want to pass MWI or USSD codes to the
|
|
|
|
// dialer, and ensure the Uri class doesn't parse a URI
|
|
|
|
// containing a fragment ('#')
|
|
|
|
final String scheme = aUri.getScheme();
|
|
|
|
if ("tel".equals(scheme) || "sms".equals(scheme)) {
|
|
|
|
final String number = aUri.getSchemeSpecificPart();
|
|
|
|
if (number.contains("#") || number.contains("*") || aUri.getFragment() != null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-05 20:55:26 +00:00
|
|
|
/**
|
|
|
|
* Given the inputs to <code>getOpenURIIntent</code>, plus an optional
|
|
|
|
* package name and class name, create and fire an intent to open the
|
|
|
|
* provided URI.
|
|
|
|
*
|
|
|
|
* @param targetURI the string spec of the URI to open.
|
|
|
|
* @param mimeType an optional MIME type string.
|
|
|
|
* @param action an Android action specifier, such as
|
|
|
|
* <code>Intent.ACTION_SEND</code>.
|
|
|
|
* @param title the title to use in <code>ACTION_SEND</code> intents.
|
|
|
|
* @return true if the activity started successfully; false otherwise.
|
|
|
|
*/
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2013-05-31 21:36:39 +00:00
|
|
|
public static boolean openUriExternal(String targetURI,
|
|
|
|
String mimeType,
|
2013-09-09 12:57:36 +00:00
|
|
|
@OptionalGeneratedParameter String packageName,
|
|
|
|
@OptionalGeneratedParameter String className,
|
|
|
|
@OptionalGeneratedParameter String action,
|
|
|
|
@OptionalGeneratedParameter String title) {
|
2013-05-24 16:21:01 +00:00
|
|
|
final Context context = getContext();
|
2013-02-05 20:55:26 +00:00
|
|
|
final Intent intent = getOpenURIIntent(context, targetURI,
|
|
|
|
mimeType, action, title);
|
|
|
|
|
|
|
|
if (intent == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (packageName.length() > 0 && className.length() > 0) {
|
|
|
|
intent.setClassName(packageName, className);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
try {
|
2013-02-05 20:55:26 +00:00
|
|
|
context.startActivity(intent);
|
2011-11-18 18:28:17 +00:00
|
|
|
return true;
|
2013-02-05 20:55:26 +00:00
|
|
|
} catch (ActivityNotFoundException e) {
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 23:30:28 +00:00
|
|
|
/**
|
|
|
|
* Return a <code>Uri</code> instance which is equivalent to <code>u</code>,
|
|
|
|
* but with a guaranteed-lowercase scheme as if the API level 16 method
|
|
|
|
* <code>u.normalizeScheme</code> had been called.
|
|
|
|
*
|
|
|
|
* @param u the <code>Uri</code> to normalize.
|
|
|
|
* @return a <code>Uri</code>, which might be <code>u</code>.
|
|
|
|
*/
|
|
|
|
static Uri normalizeUriScheme(final Uri u) {
|
|
|
|
final String scheme = u.getScheme();
|
|
|
|
final String lower = scheme.toLowerCase(Locale.US);
|
|
|
|
if (lower.equals(scheme)) {
|
|
|
|
return u;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, return a new URI with a normalized scheme.
|
|
|
|
return u.buildUpon().scheme(lower).build();
|
|
|
|
}
|
|
|
|
|
2013-05-15 17:55:06 +00:00
|
|
|
/**
|
|
|
|
* Given a URI, a MIME type, and a title,
|
|
|
|
* produce a share intent which can be used to query all activities
|
|
|
|
* than can open the specified URI.
|
|
|
|
*
|
|
|
|
* @param context a <code>Context</code> instance.
|
|
|
|
* @param targetURI the string spec of the URI to open.
|
|
|
|
* @param mimeType an optional MIME type string.
|
|
|
|
* @param title the title to use in <code>ACTION_SEND</code> intents.
|
|
|
|
* @return an <code>Intent</code>, or <code>null</code> if none could be
|
|
|
|
* produced.
|
|
|
|
*/
|
|
|
|
static Intent getShareIntent(final Context context,
|
|
|
|
final String targetURI,
|
|
|
|
final String mimeType,
|
|
|
|
final String title) {
|
|
|
|
Intent shareIntent = getIntentForActionString(Intent.ACTION_SEND);
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_TEXT, targetURI);
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);
|
|
|
|
|
|
|
|
// Note that EXTRA_TITLE is intended to be used for share dialog
|
|
|
|
// titles. Common usage (e.g., Pocket) suggests that it's sometimes
|
|
|
|
// interpreted as an alternate to EXTRA_SUBJECT, so we include it.
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_TITLE, title);
|
|
|
|
|
|
|
|
if (mimeType != null && mimeType.length() > 0) {
|
|
|
|
shareIntent.setType(mimeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
return shareIntent;
|
|
|
|
}
|
|
|
|
|
2013-02-05 20:55:26 +00:00
|
|
|
/**
|
|
|
|
* Given a URI, a MIME type, an Android intent "action", and a title,
|
|
|
|
* produce an intent which can be used to start an activity to open
|
|
|
|
* the specified URI.
|
|
|
|
*
|
|
|
|
* @param context a <code>Context</code> instance.
|
|
|
|
* @param targetURI the string spec of the URI to open.
|
|
|
|
* @param mimeType an optional MIME type string.
|
|
|
|
* @param action an Android action specifier, such as
|
|
|
|
* <code>Intent.ACTION_SEND</code>.
|
|
|
|
* @param title the title to use in <code>ACTION_SEND</code> intents.
|
|
|
|
* @return an <code>Intent</code>, or <code>null</code> if none could be
|
|
|
|
* produced.
|
|
|
|
*/
|
|
|
|
static Intent getOpenURIIntent(final Context context,
|
|
|
|
final String targetURI,
|
|
|
|
final String mimeType,
|
|
|
|
final String action,
|
|
|
|
final String title) {
|
|
|
|
|
|
|
|
if (action.equalsIgnoreCase(Intent.ACTION_SEND)) {
|
2013-05-15 17:55:06 +00:00
|
|
|
Intent shareIntent = getShareIntent(context, targetURI, mimeType, title);
|
2013-02-05 20:55:26 +00:00
|
|
|
return Intent.createChooser(shareIntent,
|
|
|
|
context.getResources().getString(R.string.share_title));
|
|
|
|
}
|
|
|
|
|
2013-11-05 00:29:07 +00:00
|
|
|
final Uri uri = normalizeUriScheme(targetURI.indexOf(':') >= 0 ? Uri.parse(targetURI) : new Uri.Builder().scheme(targetURI).build());
|
2013-02-05 20:55:26 +00:00
|
|
|
if (mimeType.length() > 0) {
|
|
|
|
Intent intent = getIntentForActionString(action);
|
2013-02-08 23:30:28 +00:00
|
|
|
intent.setDataAndType(uri, mimeType);
|
2013-02-05 20:55:26 +00:00
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isUriSafeForScheme(uri)) {
|
|
|
|
return null;
|
|
|
|
}
|
2013-02-08 23:30:28 +00:00
|
|
|
|
2013-02-05 20:55:26 +00:00
|
|
|
final String scheme = uri.getScheme();
|
2013-03-07 14:44:22 +00:00
|
|
|
|
|
|
|
final Intent intent;
|
2013-05-06 23:26:13 +00:00
|
|
|
|
|
|
|
// Compute our most likely intent, then check to see if there are any
|
|
|
|
// custom handlers that would apply.
|
|
|
|
// Start with the original URI. If we end up modifying it, we'll
|
|
|
|
// overwrite it.
|
|
|
|
final Intent likelyIntent = getIntentForActionString(action);
|
|
|
|
likelyIntent.setData(uri);
|
|
|
|
|
|
|
|
if ("vnd.youtube".equals(scheme) && !hasHandlersForIntent(likelyIntent)) {
|
|
|
|
// Special-case YouTube to use our own player if no system handler
|
|
|
|
// exists.
|
2013-03-07 14:44:22 +00:00
|
|
|
intent = new Intent(VideoPlayer.VIDEO_ACTION);
|
2013-04-10 00:10:47 +00:00
|
|
|
intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME,
|
2013-03-07 14:44:22 +00:00
|
|
|
"org.mozilla.gecko.VideoPlayer");
|
2013-05-06 23:26:13 +00:00
|
|
|
intent.setData(uri);
|
2013-03-07 14:44:22 +00:00
|
|
|
} else {
|
2013-05-06 23:26:13 +00:00
|
|
|
intent = likelyIntent;
|
2013-03-07 14:44:22 +00:00
|
|
|
}
|
2013-02-05 20:55:26 +00:00
|
|
|
|
2013-05-06 23:26:13 +00:00
|
|
|
// Have a special handling for SMS, as the message body
|
2013-02-05 20:55:26 +00:00
|
|
|
// is not extracted from the URI automatically.
|
|
|
|
if (!"sms".equals(scheme)) {
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
|
|
|
final String query = uri.getEncodedQuery();
|
|
|
|
if (TextUtils.isEmpty(query)) {
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
|
|
|
final String[] fields = query.split("&");
|
|
|
|
boolean foundBody = false;
|
|
|
|
String resultQuery = "";
|
|
|
|
for (String field : fields) {
|
|
|
|
if (foundBody || !field.startsWith("body=")) {
|
|
|
|
resultQuery = resultQuery.concat(resultQuery.length() > 0 ? "&" + field : field);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Found the first body param. Put it into the intent.
|
|
|
|
final String body = Uri.decode(field.substring(5));
|
|
|
|
intent.putExtra("sms_body", body);
|
|
|
|
foundBody = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundBody) {
|
|
|
|
// No need to rewrite the URI, then.
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Form a new URI without the body field in the query part, and
|
|
|
|
// push that into the new Intent.
|
|
|
|
final String newQuery = resultQuery.length() > 0 ? "?" + resultQuery : "";
|
2013-02-08 23:30:28 +00:00
|
|
|
final Uri pruned = uri.buildUpon().encodedQuery(newQuery).build();
|
|
|
|
intent.setData(pruned);
|
2013-02-05 20:55:26 +00:00
|
|
|
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
2013-03-21 20:32:11 +00:00
|
|
|
public static void setNotificationClient(NotificationClient client) {
|
2013-03-11 18:59:23 +00:00
|
|
|
if (sNotificationClient == null) {
|
|
|
|
sNotificationClient = client;
|
|
|
|
} else {
|
2013-03-21 20:32:11 +00:00
|
|
|
Log.d(LOGTAG, "Notification client already set");
|
2013-03-11 18:59:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "ShowAlertNotificationWrapper")
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void showAlertNotification(String aImageUrl, String aAlertTitle, String aAlertText,
|
|
|
|
String aAlertCookie, String aAlertName) {
|
|
|
|
// The intent to launch when the user clicks the expanded notification
|
2013-05-24 16:21:01 +00:00
|
|
|
String app = getContext().getClass().getName();
|
2013-03-19 21:09:44 +00:00
|
|
|
Intent notificationIntent = new Intent(GeckoApp.ACTION_ALERT_CALLBACK);
|
2013-04-10 00:10:47 +00:00
|
|
|
notificationIntent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, app);
|
2013-03-19 21:09:44 +00:00
|
|
|
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2013-03-11 18:59:23 +00:00
|
|
|
int notificationID = aAlertName.hashCode();
|
|
|
|
|
2012-08-22 15:37:08 +00:00
|
|
|
// Put the strings into the intent as an URI "alert:?name=<alertName>&app=<appName>&cookie=<cookie>"
|
|
|
|
Uri.Builder b = new Uri.Builder();
|
2013-03-11 18:59:23 +00:00
|
|
|
Uri dataUri = b.scheme("alert").path(Integer.toString(notificationID))
|
|
|
|
.appendQueryParameter("name", aAlertName)
|
|
|
|
.appendQueryParameter("cookie", aAlertCookie)
|
|
|
|
.build();
|
2011-11-18 18:28:17 +00:00
|
|
|
notificationIntent.setData(dataUri);
|
2013-03-19 21:09:44 +00:00
|
|
|
PendingIntent contentIntent = PendingIntent.getActivity(
|
2013-05-24 16:21:01 +00:00
|
|
|
getContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2013-03-18 13:24:53 +00:00
|
|
|
mAlertCookies.put(aAlertName, aAlertCookie);
|
|
|
|
callObserver(aAlertName, "alertshow", aAlertCookie);
|
|
|
|
|
2013-03-19 21:09:44 +00:00
|
|
|
sNotificationClient.add(notificationID, aImageUrl, aAlertTitle, aAlertText, contentIntent);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void alertsProgressListener_OnProgress(String aAlertName, long aProgress, long aProgressMax, String aAlertText) {
|
2013-03-11 18:59:23 +00:00
|
|
|
int notificationID = aAlertName.hashCode();
|
|
|
|
sNotificationClient.update(notificationID, aProgress, aProgressMax, aAlertText);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2013-03-18 13:24:53 +00:00
|
|
|
public static void closeNotification(String aAlertName) {
|
|
|
|
String alertCookie = mAlertCookies.get(aAlertName);
|
|
|
|
if (alertCookie != null) {
|
|
|
|
callObserver(aAlertName, "alertfinished", alertCookie);
|
|
|
|
mAlertCookies.remove(aAlertName);
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
removeObserver(aAlertName);
|
|
|
|
|
|
|
|
int notificationID = aAlertName.hashCode();
|
2013-03-18 13:24:53 +00:00
|
|
|
sNotificationClient.remove(notificationID);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void handleNotification(String aAction, String aAlertName, String aAlertCookie) {
|
|
|
|
int notificationID = aAlertName.hashCode();
|
|
|
|
|
2012-08-22 15:37:08 +00:00
|
|
|
if (GeckoApp.ACTION_ALERT_CALLBACK.equals(aAction)) {
|
2011-11-18 18:28:17 +00:00
|
|
|
callObserver(aAlertName, "alertclickcallback", aAlertCookie);
|
|
|
|
|
2013-07-18 23:35:34 +00:00
|
|
|
if (sNotificationClient.isOngoing(notificationID)) {
|
2013-03-11 18:59:23 +00:00
|
|
|
// When clicked, keep the notification if it displays progress
|
2011-11-18 18:28:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-03-18 13:24:53 +00:00
|
|
|
closeNotification(aAlertName);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetDpiWrapper")
|
2011-11-18 18:28:17 +00:00
|
|
|
public static int getDpi() {
|
2011-12-19 20:10:35 +00:00
|
|
|
if (sDensityDpi == 0) {
|
2013-05-24 16:21:01 +00:00
|
|
|
sDensityDpi = getContext().getResources().getDisplayMetrics().densityDpi;
|
2011-12-19 20:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sDensityDpi;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2013-09-18 00:45:03 +00:00
|
|
|
public static float getDensity() {
|
|
|
|
return getContext().getResources().getDisplayMetrics().density;
|
|
|
|
}
|
|
|
|
|
2013-07-02 13:44:44 +00:00
|
|
|
private static boolean isHighMemoryDevice() {
|
2013-11-28 05:17:13 +00:00
|
|
|
return HardwareUtils.getMemSize() > HIGH_MEMORY_DEVICE_THRESHOLD_MB;
|
2013-07-02 13:44:44 +00:00
|
|
|
}
|
|
|
|
|
2013-07-04 13:53:25 +00:00
|
|
|
/**
|
|
|
|
* Returns the colour depth of the default screen. This will either be
|
|
|
|
* 24 or 16.
|
|
|
|
*/
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetScreenDepthWrapper")
|
2013-07-04 13:53:27 +00:00
|
|
|
public static synchronized int getScreenDepth() {
|
2013-07-02 13:44:44 +00:00
|
|
|
if (sScreenDepth == 0) {
|
|
|
|
sScreenDepth = 16;
|
2013-07-18 19:09:01 +00:00
|
|
|
PixelFormat info = new PixelFormat();
|
|
|
|
PixelFormat.getPixelFormatInfo(getGeckoInterface().getActivity().getWindowManager().getDefaultDisplay().getPixelFormat(), info);
|
|
|
|
if (info.bitsPerPixel >= 24 && isHighMemoryDevice()) {
|
|
|
|
sScreenDepth = 24;
|
2013-07-04 13:53:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sScreenDepth;
|
|
|
|
}
|
|
|
|
|
2013-07-04 13:53:27 +00:00
|
|
|
public static synchronized void setScreenDepthOverride(int aScreenDepth) {
|
|
|
|
if (sScreenDepth != 0) {
|
|
|
|
Log.e(LOGTAG, "Tried to override screen depth after it's already been set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sScreenDepth = aScreenDepth;
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void setFullScreen(boolean fullscreen) {
|
2013-05-24 16:21:01 +00:00
|
|
|
if (getGeckoInterface() != null)
|
|
|
|
getGeckoInterface().setFullScreen(fullscreen);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void performHapticFeedback(boolean aIsLongPress) {
|
2012-02-15 18:56:00 +00: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) {
|
2013-05-24 16:21:01 +00:00
|
|
|
LayerView layerView = getLayerView();
|
2012-02-15 18:56:00 +00:00
|
|
|
layerView.performHapticFeedback(aIsLongPress ?
|
|
|
|
HapticFeedbackConstants.LONG_PRESS :
|
|
|
|
HapticFeedbackConstants.VIRTUAL_KEY);
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static Vibrator vibrator() {
|
2013-05-24 16:21:01 +00:00
|
|
|
LayerView layerView = getLayerView();
|
2011-11-18 18:28:17 +00:00
|
|
|
return (Vibrator) layerView.getContext().getSystemService(Context.VIBRATOR_SERVICE);
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "Vibrate1")
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void vibrate(long milliseconds) {
|
2012-02-15 18:56:00 +00:00
|
|
|
sVibrationEndTime = System.nanoTime() + milliseconds * 1000000;
|
|
|
|
sVibrationMaybePlaying = true;
|
2011-11-18 18:28:17 +00:00
|
|
|
vibrator().vibrate(milliseconds);
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "VibrateA")
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void vibrate(long[] pattern, int repeat) {
|
2012-02-15 18:56:00 +00: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 18:28:17 +00:00
|
|
|
vibrator().vibrate(pattern, repeat);
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void cancelVibrate() {
|
2012-02-15 18:56:00 +00:00
|
|
|
sVibrationMaybePlaying = false;
|
|
|
|
sVibrationEndTime = 0;
|
2011-11-18 18:28:17 +00:00
|
|
|
vibrator().cancel();
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void showInputMethodPicker() {
|
|
|
|
InputMethodManager imm = (InputMethodManager)
|
2013-05-24 16:21:01 +00:00
|
|
|
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
2011-11-18 18:28:17 +00:00
|
|
|
imm.showInputMethodPicker();
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void setKeepScreenOn(final boolean on) {
|
2013-05-24 16:21:01 +00:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-11-18 18:28:17 +00:00
|
|
|
public void run() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-04-07 07:09:26 +00:00
|
|
|
public static void notifyDefaultPrevented(final boolean defaultPrevented) {
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-01-25 00:31:33 +00:00
|
|
|
public void run() {
|
2013-05-24 16:21:01 +00:00
|
|
|
LayerView view = getLayerView();
|
2013-02-08 14:13:09 +00:00
|
|
|
PanZoomController controller = (view == null ? null : view.getPanZoomController());
|
|
|
|
if (controller != null) {
|
|
|
|
controller.notifyDefaultActionPrevented(defaultPrevented);
|
2012-08-28 00:34:58 +00:00
|
|
|
}
|
2012-01-25 00:31:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static boolean isNetworkLinkUp() {
|
|
|
|
ConnectivityManager cm = (ConnectivityManager)
|
2013-05-24 16:21:01 +00:00
|
|
|
getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
2013-11-27 23:37:44 +00:00
|
|
|
try {
|
|
|
|
NetworkInfo info = cm.getActiveNetworkInfo();
|
|
|
|
if (info == null || !info.isConnected())
|
|
|
|
return false;
|
|
|
|
} catch (SecurityException se) {
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
2013-11-27 23:37:44 +00:00
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static boolean isNetworkLinkKnown() {
|
|
|
|
ConnectivityManager cm = (ConnectivityManager)
|
2013-05-24 16:21:01 +00:00
|
|
|
getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
2013-11-27 23:37:44 +00:00
|
|
|
try {
|
|
|
|
if (cm.getActiveNetworkInfo() == null)
|
|
|
|
return false;
|
|
|
|
} catch (SecurityException se) {
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
2013-11-27 23:37:44 +00:00
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2013-11-19 04:43:09 +00:00
|
|
|
public static int networkLinkType() {
|
|
|
|
ConnectivityManager cm = (ConnectivityManager)
|
|
|
|
getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
NetworkInfo info = cm.getActiveNetworkInfo();
|
|
|
|
if (info == null) {
|
|
|
|
return LINK_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (info.getType()) {
|
|
|
|
case ConnectivityManager.TYPE_ETHERNET:
|
|
|
|
return LINK_TYPE_ETHERNET;
|
|
|
|
case ConnectivityManager.TYPE_WIFI:
|
|
|
|
return LINK_TYPE_WIFI;
|
|
|
|
case ConnectivityManager.TYPE_WIMAX:
|
|
|
|
return LINK_TYPE_WIMAX;
|
|
|
|
case ConnectivityManager.TYPE_MOBILE:
|
|
|
|
break; // We will handle sub-types after the switch.
|
|
|
|
default:
|
|
|
|
Log.w(LOGTAG, "Ignoring the current network type.");
|
|
|
|
return LINK_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
TelephonyManager tm = (TelephonyManager)
|
|
|
|
getContext().getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
if (tm == null) {
|
|
|
|
Log.e(LOGTAG, "Telephony service does not exist");
|
|
|
|
return LINK_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (tm.getNetworkType()) {
|
|
|
|
case TelephonyManager.NETWORK_TYPE_IDEN:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_CDMA:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_GPRS:
|
|
|
|
return LINK_TYPE_2G;
|
|
|
|
case TelephonyManager.NETWORK_TYPE_1xRTT:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_EDGE:
|
|
|
|
return LINK_TYPE_2G; // 2.5G
|
|
|
|
case TelephonyManager.NETWORK_TYPE_UMTS:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_EVDO_0:
|
|
|
|
return LINK_TYPE_3G;
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSPA:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSDPA:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSUPA:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_EVDO_A:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_EVDO_B:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_EHRPD:
|
|
|
|
return LINK_TYPE_3G; // 3.5G
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSPAP:
|
|
|
|
return LINK_TYPE_3G; // 3.75G
|
|
|
|
case TelephonyManager.NETWORK_TYPE_LTE:
|
|
|
|
return LINK_TYPE_4G; // 3.9G
|
|
|
|
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
|
|
|
|
default:
|
|
|
|
Log.w(LOGTAG, "Connected to an unknown mobile network!");
|
|
|
|
return LINK_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetSystemColoursWrapper")
|
2011-11-18 18:28:17 +00: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 =
|
2013-05-24 16:21:01 +00:00
|
|
|
new ContextThemeWrapper(getContext(), android.R.style.TextAppearance);
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void killAnyZombies() {
|
|
|
|
GeckoProcessesVisitor visitor = new GeckoProcessesVisitor() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-11-18 18:28:17 +00:00
|
|
|
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;
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-11-18 18:28:17 +00:00
|
|
|
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-31 00:53:14 +00:00
|
|
|
interface GeckoProcessesVisitor{
|
2011-11-18 18:28:17 +00:00
|
|
|
boolean callback(int pid);
|
|
|
|
}
|
|
|
|
|
2012-07-15 07:07:58 +00:00
|
|
|
private static void EnumerateGeckoProcesses(GeckoProcessesVisitor visiter) {
|
2013-02-24 23:19:10 +00:00
|
|
|
int pidColumn = -1;
|
|
|
|
int userColumn = -1;
|
2012-07-18 05:39:46 +00:00
|
|
|
|
2011-11-18 18:28:17 +00: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
|
2013-02-24 23:19:10 +00:00
|
|
|
StringTokenizer st = new StringTokenizer(headerOutput);
|
|
|
|
|
|
|
|
int tokenSoFar = 0;
|
|
|
|
while (st.hasMoreTokens()) {
|
|
|
|
String next = st.nextToken();
|
|
|
|
if (next.equalsIgnoreCase("PID"))
|
|
|
|
pidColumn = tokenSoFar;
|
|
|
|
else if (next.equalsIgnoreCase("USER"))
|
|
|
|
userColumn = tokenSoFar;
|
|
|
|
tokenSoFar++;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// alright, the rest are process entries.
|
|
|
|
String psOutput = null;
|
|
|
|
while ((psOutput = in.readLine()) != null) {
|
|
|
|
String[] split = psOutput.split("\\s+");
|
2013-02-24 23:19:10 +00:00
|
|
|
if (split.length <= pidColumn || split.length <= userColumn)
|
2011-11-18 18:28:17 +00:00
|
|
|
continue;
|
2013-02-24 23:19:10 +00:00
|
|
|
int uid = android.os.Process.getUidForName(split[userColumn]);
|
2011-11-18 18:28:17 +00:00
|
|
|
if (uid == android.os.Process.myUid() &&
|
|
|
|
!split[split.length - 1].equalsIgnoreCase("ps")) {
|
2013-02-24 23:19:10 +00:00
|
|
|
int pid = Integer.parseInt(split[pidColumn]);
|
2011-11-18 18:28:17 +00:00
|
|
|
boolean keepGoing = visiter.callback(pid);
|
|
|
|
if (keepGoing == false)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
in.close();
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.w(LOGTAG, "Failed to enumerate Gecko processes.", e);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void waitForAnotherGeckoProc(){
|
|
|
|
int countdown = 40;
|
|
|
|
while (!checkForGeckoProcs() && --countdown > 0) {
|
|
|
|
try {
|
2012-01-24 17:16:48 +00:00
|
|
|
Thread.sleep(100);
|
2011-11-18 18:28:17 +00:00
|
|
|
} catch (InterruptedException ie) {}
|
|
|
|
}
|
|
|
|
}
|
2013-02-21 16:24:08 +00:00
|
|
|
public static String getAppNameByPID(int pid) {
|
|
|
|
BufferedReader cmdlineReader = null;
|
|
|
|
String path = "/proc/" + pid + "/cmdline";
|
|
|
|
try {
|
|
|
|
File cmdlineFile = new File(path);
|
|
|
|
if (!cmdlineFile.exists())
|
|
|
|
return "";
|
|
|
|
cmdlineReader = new BufferedReader(new FileReader(cmdlineFile));
|
|
|
|
return cmdlineReader.readLine().trim();
|
|
|
|
} catch (Exception ex) {
|
|
|
|
return "";
|
|
|
|
} finally {
|
|
|
|
if (null != cmdlineReader) {
|
|
|
|
try {
|
|
|
|
cmdlineReader.close();
|
|
|
|
} catch (Exception e) {}
|
2013-02-21 13:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void listOfOpenFiles() {
|
|
|
|
int pidColumn = -1;
|
|
|
|
int nameColumn = -1;
|
|
|
|
|
|
|
|
try {
|
2013-05-24 16:21:01 +00:00
|
|
|
String filter = GeckoProfile.get(getContext()).getDir().toString();
|
2013-02-21 16:24:08 +00:00
|
|
|
Log.i(LOGTAG, "[OPENFILE] Filter: " + filter);
|
|
|
|
|
2013-02-21 13:52:37 +00:00
|
|
|
// run lsof and parse its output
|
|
|
|
java.lang.Process lsof = Runtime.getRuntime().exec("lsof");
|
|
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(lsof.getInputStream()), 2048);
|
|
|
|
|
|
|
|
String headerOutput = in.readLine();
|
|
|
|
StringTokenizer st = new StringTokenizer(headerOutput);
|
|
|
|
int token = 0;
|
|
|
|
while (st.hasMoreTokens()) {
|
|
|
|
String next = st.nextToken();
|
|
|
|
if (next.equalsIgnoreCase("PID"))
|
|
|
|
pidColumn = token;
|
|
|
|
else if (next.equalsIgnoreCase("NAME"))
|
|
|
|
nameColumn = token;
|
|
|
|
token++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// alright, the rest are open file entries.
|
2013-02-21 16:24:08 +00:00
|
|
|
Map<Integer, String> pidNameMap = new TreeMap<Integer, String>();
|
2013-02-21 13:52:37 +00:00
|
|
|
String output = null;
|
|
|
|
while ((output = in.readLine()) != null) {
|
|
|
|
String[] split = output.split("\\s+");
|
|
|
|
if (split.length <= pidColumn || split.length <= nameColumn)
|
|
|
|
continue;
|
2013-02-21 16:24:08 +00:00
|
|
|
Integer pid = new Integer(split[pidColumn]);
|
|
|
|
String name = pidNameMap.get(pid);
|
|
|
|
if (name == null) {
|
|
|
|
name = getAppNameByPID(pid.intValue());
|
|
|
|
pidNameMap.put(pid, name);
|
|
|
|
}
|
|
|
|
String file = split[nameColumn];
|
|
|
|
if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(file) && file.startsWith(filter))
|
|
|
|
Log.i(LOGTAG, "[OPENFILE] " + name + "(" + split[pidColumn] + ") : " + file);
|
2013-02-21 13:52:37 +00:00
|
|
|
}
|
|
|
|
in.close();
|
|
|
|
} catch (Exception e) { }
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void scanMedia(String aFile, String aMimeType) {
|
2013-09-11 17:21:57 +00:00
|
|
|
// If the platform didn't give us a mimetype, try to guess one from the filename
|
|
|
|
if (TextUtils.isEmpty(aMimeType)) {
|
|
|
|
int extPosition = aFile.lastIndexOf(".");
|
|
|
|
if (extPosition > 0 && extPosition < aFile.length() - 1) {
|
|
|
|
aMimeType = getMimeTypeFromExtension(aFile.substring(extPosition+1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-24 16:21:01 +00:00
|
|
|
Context context = getContext();
|
2013-01-24 20:12:25 +00:00
|
|
|
GeckoMediaScannerClient.startScan(context, aFile, aMimeType);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetIconForExtensionWrapper")
|
2011-11-18 18:28:17 +00:00
|
|
|
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);
|
|
|
|
|
2013-05-24 16:21:01 +00:00
|
|
|
PackageManager pm = getContext().getPackageManager();
|
2011-11-18 18:28:17 +00:00
|
|
|
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) {
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.w(LOGTAG, "getIconForExtension failed.", e);
|
2011-11-18 18:28:17 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-11 17:21:57 +00:00
|
|
|
private static String getMimeTypeFromExtension(String ext) {
|
|
|
|
final MimeTypeMap mtm = MimeTypeMap.getSingleton();
|
|
|
|
return mtm.getMimeTypeFromExtension(ext);
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
private static Drawable getDrawableForExtension(PackageManager pm, String aExt) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
2013-09-11 17:21:57 +00:00
|
|
|
final String mimeType = getMimeTypeFromExtension(aExt);
|
2011-11-18 18:28:17 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static boolean getShowPasswordSetting() {
|
|
|
|
try {
|
|
|
|
int showPassword =
|
2013-05-24 16:21:01 +00:00
|
|
|
Settings.System.getInt(getContext().getContentResolver(),
|
2011-11-18 18:28:17 +00:00
|
|
|
Settings.System.TEXT_SHOW_PASSWORD, 1);
|
|
|
|
return (showPassword > 0);
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "AddPluginViewWrapper")
|
2011-12-18 05:34:03 +00:00
|
|
|
public static void addPluginView(View view,
|
2013-08-13 15:49:21 +00:00
|
|
|
float x, float y,
|
|
|
|
float w, float h,
|
2012-10-26 22:47:35 +00:00
|
|
|
boolean isFullScreen) {
|
2013-05-24 16:21:01 +00:00
|
|
|
if (getGeckoInterface() != null)
|
2013-08-13 15:49:21 +00:00
|
|
|
getGeckoInterface().addPluginView(view, new RectF(x, y, x + w, y + h), isFullScreen);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-05-30 16:10:49 +00:00
|
|
|
public static void removePluginView(View view, boolean isFullScreen) {
|
2013-05-24 16:21:01 +00:00
|
|
|
if (getGeckoInterface() != null)
|
|
|
|
getGeckoInterface().removePluginView(view, isFullScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A plugin that wish to be loaded in the WebView must provide this permission
|
|
|
|
* in their AndroidManifest.xml.
|
|
|
|
*/
|
|
|
|
public static final String PLUGIN_ACTION = "android.webkit.PLUGIN";
|
|
|
|
public static final String PLUGIN_PERMISSION = "android.webkit.permission.PLUGIN";
|
|
|
|
|
|
|
|
private static final String PLUGIN_SYSTEM_LIB = "/system/lib/plugins/";
|
|
|
|
|
|
|
|
private static final String PLUGIN_TYPE = "type";
|
|
|
|
private static final String TYPE_NATIVE = "native";
|
|
|
|
static public ArrayList<PackageInfo> mPackageInfoCache = new ArrayList<PackageInfo>();
|
|
|
|
|
|
|
|
// Returns null if plugins are blocked on the device.
|
|
|
|
static String[] getPluginDirectories() {
|
|
|
|
|
|
|
|
// An awful hack to detect Tegra devices. Easiest way to do it without spinning up a EGL context.
|
2014-01-24 14:50:47 +00:00
|
|
|
boolean isTegra = (new File("/system/lib/hw/gralloc.tegra.so")).exists() ||
|
|
|
|
(new File("/system/lib/hw/gralloc.tegra3.so")).exists();
|
2013-05-24 16:21:01 +00:00
|
|
|
if (isTegra) {
|
|
|
|
// disable Flash on Tegra ICS with CM9 and other custom firmware (bug 736421)
|
|
|
|
File vfile = new File("/proc/version");
|
|
|
|
FileReader vreader = null;
|
|
|
|
try {
|
|
|
|
if (vfile.canRead()) {
|
|
|
|
vreader = new FileReader(vfile);
|
|
|
|
String version = new BufferedReader(vreader).readLine();
|
|
|
|
if (version.indexOf("CM9") != -1 ||
|
|
|
|
version.indexOf("cyanogen") != -1 ||
|
|
|
|
version.indexOf("Nova") != -1)
|
|
|
|
{
|
|
|
|
Log.w(LOGTAG, "Blocking plugins because of Tegra 2 + unofficial ICS bug (bug 736421)");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException ex) {
|
|
|
|
// nothing
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
if (vreader != null) {
|
|
|
|
vreader.close();
|
|
|
|
}
|
|
|
|
} catch (IOException ex) {
|
|
|
|
// nothing
|
|
|
|
}
|
|
|
|
}
|
2014-01-24 14:50:47 +00:00
|
|
|
|
|
|
|
// disable on KitKat (bug 957694)
|
|
|
|
if (Build.VERSION.SDK_INT >= 19) {
|
|
|
|
Log.w(LOGTAG, "Blocking plugins because of Tegra (bug 957694)");
|
|
|
|
return null;
|
|
|
|
}
|
2013-05-24 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ArrayList<String> directories = new ArrayList<String>();
|
|
|
|
PackageManager pm = getContext().getPackageManager();
|
|
|
|
List<ResolveInfo> plugins = pm.queryIntentServices(new Intent(PLUGIN_ACTION),
|
|
|
|
PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);
|
|
|
|
|
|
|
|
synchronized(mPackageInfoCache) {
|
|
|
|
|
|
|
|
// clear the list of existing packageInfo objects
|
|
|
|
mPackageInfoCache.clear();
|
|
|
|
|
|
|
|
|
|
|
|
for (ResolveInfo info : plugins) {
|
|
|
|
|
|
|
|
// retrieve the plugin's service information
|
|
|
|
ServiceInfo serviceInfo = info.serviceInfo;
|
|
|
|
if (serviceInfo == null) {
|
|
|
|
Log.w(LOGTAG, "Ignoring bad plugin.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Blacklist HTC's flash lite.
|
|
|
|
// See bug #704516 - We're not quite sure what Flash Lite does,
|
|
|
|
// but loading it causes Flash to give errors and fail to draw.
|
|
|
|
if (serviceInfo.packageName.equals("com.htc.flashliteplugin")) {
|
|
|
|
Log.w(LOGTAG, "Skipping HTC's flash lite plugin");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Retrieve information from the plugin's manifest.
|
|
|
|
PackageInfo pkgInfo;
|
|
|
|
try {
|
|
|
|
pkgInfo = pm.getPackageInfo(serviceInfo.packageName,
|
|
|
|
PackageManager.GET_PERMISSIONS
|
|
|
|
| PackageManager.GET_SIGNATURES);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.w(LOGTAG, "Can't find plugin: " + serviceInfo.packageName);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pkgInfo == null) {
|
|
|
|
Log.w(LOGTAG, "Not loading plugin: " + serviceInfo.packageName + ". Could not load package information.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* find the location of the plugin's shared library. The default
|
|
|
|
* is to assume the app is either a user installed app or an
|
|
|
|
* updated system app. In both of these cases the library is
|
|
|
|
* stored in the app's data directory.
|
|
|
|
*/
|
|
|
|
String directory = pkgInfo.applicationInfo.dataDir + "/lib";
|
|
|
|
final int appFlags = pkgInfo.applicationInfo.flags;
|
|
|
|
final int updatedSystemFlags = ApplicationInfo.FLAG_SYSTEM |
|
|
|
|
ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
|
|
|
|
|
|
|
|
// preloaded system app with no user updates
|
|
|
|
if ((appFlags & updatedSystemFlags) == ApplicationInfo.FLAG_SYSTEM) {
|
|
|
|
directory = PLUGIN_SYSTEM_LIB + pkgInfo.packageName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the plugin has the required permissions
|
|
|
|
String permissions[] = pkgInfo.requestedPermissions;
|
|
|
|
if (permissions == null) {
|
|
|
|
Log.w(LOGTAG, "Not loading plugin: " + serviceInfo.packageName + ". Does not have required permission.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
boolean permissionOk = false;
|
|
|
|
for (String permit : permissions) {
|
|
|
|
if (PLUGIN_PERMISSION.equals(permit)) {
|
|
|
|
permissionOk = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!permissionOk) {
|
|
|
|
Log.w(LOGTAG, "Not loading plugin: " + serviceInfo.packageName + ". Does not have required permission (2).");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check to ensure the plugin is properly signed
|
|
|
|
Signature signatures[] = pkgInfo.signatures;
|
|
|
|
if (signatures == null) {
|
|
|
|
Log.w(LOGTAG, "Not loading plugin: " + serviceInfo.packageName + ". Not signed.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine the type of plugin from the manifest
|
|
|
|
if (serviceInfo.metaData == null) {
|
|
|
|
Log.e(LOGTAG, "The plugin '" + serviceInfo.name + "' has no defined type.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
String pluginType = serviceInfo.metaData.getString(PLUGIN_TYPE);
|
|
|
|
if (!TYPE_NATIVE.equals(pluginType)) {
|
|
|
|
Log.e(LOGTAG, "Unrecognized plugin type: " + pluginType);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Class<?> cls = getPluginClass(serviceInfo.packageName, serviceInfo.name);
|
|
|
|
|
|
|
|
//TODO implement any requirements of the plugin class here!
|
|
|
|
boolean classFound = true;
|
|
|
|
|
|
|
|
if (!classFound) {
|
|
|
|
Log.e(LOGTAG, "The plugin's class' " + serviceInfo.name + "' does not extend the appropriate class.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (NameNotFoundException e) {
|
|
|
|
Log.e(LOGTAG, "Can't find plugin: " + serviceInfo.packageName);
|
|
|
|
continue;
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
Log.e(LOGTAG, "Can't find plugin's class: " + serviceInfo.name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if all checks have passed then make the plugin available
|
|
|
|
mPackageInfoCache.add(pkgInfo);
|
|
|
|
directories.add(directory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return directories.toArray(new String[directories.size()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static String getPluginPackage(String pluginLib) {
|
|
|
|
|
|
|
|
if (pluginLib == null || pluginLib.length() == 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
synchronized(mPackageInfoCache) {
|
|
|
|
for (PackageInfo pkgInfo : mPackageInfoCache) {
|
|
|
|
if (pluginLib.contains(pkgInfo.packageName)) {
|
|
|
|
return pkgInfo.packageName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Class<?> getPluginClass(String packageName, String className)
|
|
|
|
throws NameNotFoundException, ClassNotFoundException {
|
|
|
|
Context pluginContext = getContext().createPackageContext(packageName,
|
|
|
|
Context.CONTEXT_INCLUDE_CODE |
|
|
|
|
Context.CONTEXT_IGNORE_SECURITY);
|
|
|
|
ClassLoader pluginCL = pluginContext.getClassLoader();
|
|
|
|
return pluginCL.loadClass(className);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-12-11 21:53:06 +00:00
|
|
|
@WrapElementForJNI(allowMultithread = true)
|
2011-11-18 18:28:17 +00:00
|
|
|
public static Class<?> loadPluginClass(String className, String libName) {
|
2013-05-24 16:21:01 +00:00
|
|
|
if (getGeckoInterface() == null)
|
|
|
|
return null;
|
2011-11-18 18:28:17 +00:00
|
|
|
try {
|
2013-05-24 16:21:01 +00:00
|
|
|
final String packageName = getPluginPackage(libName);
|
2012-10-26 22:47:35 +00:00
|
|
|
final int contextFlags = Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY;
|
2013-05-24 16:21:01 +00:00
|
|
|
final Context pluginContext = getContext().createPackageContext(packageName, contextFlags);
|
2012-10-26 22:47:35 +00:00
|
|
|
return pluginContext.getClassLoader().loadClass(className);
|
2011-11-18 18:28:17 +00:00
|
|
|
} catch (java.lang.ClassNotFoundException cnfe) {
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.w(LOGTAG, "Couldn't find plugin class " + className, cnfe);
|
|
|
|
return null;
|
2011-11-18 18:28:17 +00:00
|
|
|
} catch (android.content.pm.PackageManager.NameNotFoundException nnfe) {
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.w(LOGTAG, "Couldn't find package.", nnfe);
|
|
|
|
return null;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-24 16:21:01 +00:00
|
|
|
private static ContextGetter sContextGetter;
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(allowMultithread = true)
|
2013-02-09 21:38:08 +00:00
|
|
|
public static Context getContext() {
|
2013-05-24 16:21:01 +00:00
|
|
|
return sContextGetter.getContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setContextGetter(ContextGetter cg) {
|
|
|
|
sContextGetter = cg;
|
|
|
|
}
|
|
|
|
|
2013-12-03 23:05:43 +00:00
|
|
|
public static SharedPreferences getSharedPreferences() {
|
|
|
|
if (sContextGetter == null) {
|
|
|
|
throw new IllegalStateException("No ContextGetter; cannot fetch prefs.");
|
|
|
|
}
|
|
|
|
return sContextGetter.getSharedPreferences();
|
|
|
|
}
|
|
|
|
|
2013-06-05 06:26:11 +00:00
|
|
|
public interface AppStateListener {
|
|
|
|
public void onPause();
|
|
|
|
public void onResume();
|
2013-07-11 15:17:37 +00:00
|
|
|
public void onOrientationChanged();
|
2013-06-05 06:26:11 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 16:21:01 +00:00
|
|
|
public interface GeckoInterface {
|
|
|
|
public GeckoProfile getProfile();
|
|
|
|
public PromptService getPromptService();
|
|
|
|
public Activity getActivity();
|
|
|
|
public String getDefaultUAString();
|
|
|
|
public LocationListener getLocationListener();
|
|
|
|
public SensorEventListener getSensorEventListener();
|
|
|
|
public void doRestart();
|
|
|
|
public void setFullScreen(boolean fullscreen);
|
2013-08-13 15:49:21 +00:00
|
|
|
public void addPluginView(View view, final RectF rect, final boolean isFullScreen);
|
2013-05-24 16:21:01 +00:00
|
|
|
public void removePluginView(final View view, final boolean isFullScreen);
|
|
|
|
public void enableCameraView();
|
|
|
|
public void disableCameraView();
|
2013-06-05 06:26:11 +00:00
|
|
|
public void addAppStateListener(AppStateListener listener);
|
|
|
|
public void removeAppStateListener(AppStateListener listener);
|
2013-07-01 06:01:57 +00:00
|
|
|
public View getCameraView();
|
2013-05-24 16:21:01 +00:00
|
|
|
public void notifyWakeLockChanged(String topic, String state);
|
|
|
|
public FormAssistPopup getFormAssistPopup();
|
|
|
|
public boolean areTabsShown();
|
|
|
|
public AbsoluteLayout getPluginContainer();
|
|
|
|
public void notifyCheckUpdateResult(String result);
|
|
|
|
public boolean hasTabsSideBar();
|
|
|
|
public void invalidateOptionsMenu();
|
|
|
|
};
|
|
|
|
|
|
|
|
private static GeckoInterface sGeckoInterface;
|
|
|
|
|
|
|
|
public static GeckoInterface getGeckoInterface() {
|
|
|
|
return sGeckoInterface;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setGeckoInterface(GeckoInterface aGeckoInterface) {
|
|
|
|
sGeckoInterface = aGeckoInterface;
|
2013-02-09 21:38:08 +00:00
|
|
|
}
|
|
|
|
|
2012-07-18 05:39:46 +00:00
|
|
|
public static android.hardware.Camera sCamera = null;
|
2012-09-21 00:44:24 +00:00
|
|
|
|
2012-07-18 05:39:46 +00:00
|
|
|
static native void cameraCallbackBridge(byte[] data);
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-07-18 05:39:46 +00:00
|
|
|
static int kPreferedFps = 25;
|
|
|
|
static byte[] sCameraBuffer = null;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2013-09-09 12:57:36 +00:00
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "InitCameraWrapper")
|
2012-07-18 05:39:46 +00:00
|
|
|
static int[] initCamera(String aContentType, int aCamera, int aWidth, int aHeight) {
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2012-10-26 22:47:35 +00:00
|
|
|
@Override
|
2011-11-18 18:28:17 +00:00
|
|
|
public void run() {
|
|
|
|
try {
|
2013-05-24 16:21:01 +00:00
|
|
|
if (getGeckoInterface() != null)
|
|
|
|
getGeckoInterface().enableCameraView();
|
2011-11-18 18:28:17 +00:00
|
|
|
} 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 {
|
2013-07-01 06:01:57 +00:00
|
|
|
if (getGeckoInterface() != null) {
|
|
|
|
View cameraView = getGeckoInterface().getCameraView();
|
|
|
|
if (cameraView instanceof SurfaceView) {
|
|
|
|
sCamera.setPreviewDisplay(((SurfaceView)cameraView).getHolder());
|
|
|
|
} else if (cameraView instanceof TextureView) {
|
|
|
|
sCamera.setPreviewTexture(((TextureView)cameraView).getSurfaceTexture());
|
|
|
|
}
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
} catch(IOException e) {
|
2013-07-01 06:01:57 +00:00
|
|
|
Log.w(LOGTAG, "Error setPreviewXXX:", e);
|
2011-11-18 18:28:17 +00:00
|
|
|
} catch(RuntimeException e) {
|
2013-07-01 06:01:57 +00:00
|
|
|
Log.w(LOGTAG, "Error setPreviewXXX:", e);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sCamera.setParameters(params);
|
|
|
|
sCameraBuffer = new byte[(bufferSize * 12) / 8];
|
|
|
|
sCamera.addCallbackBuffer(sCameraBuffer);
|
|
|
|
sCamera.setPreviewCallbackWithBuffer(new android.hardware.Camera.PreviewCallback() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-11-18 18:28:17 +00:00
|
|
|
public void onPreviewFrame(byte[] data, android.hardware.Camera camera) {
|
|
|
|
cameraCallbackBridge(data);
|
|
|
|
if (sCamera != null)
|
|
|
|
sCamera.addCallbackBuffer(sCameraBuffer);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
sCamera.startPreview();
|
|
|
|
params = sCamera.getParameters();
|
|
|
|
result[0] = 1;
|
|
|
|
result[1] = params.getPreviewSize().width;
|
|
|
|
result[2] = params.getPreviewSize().height;
|
|
|
|
result[3] = params.getPreviewFrameRate();
|
|
|
|
} catch(RuntimeException e) {
|
2012-10-26 22:47:35 +00:00
|
|
|
Log.w(LOGTAG, "initCamera RuntimeException.", e);
|
2011-11-18 18:28:17 +00:00
|
|
|
result[0] = result[1] = result[2] = result[3] = 0;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-07-18 05:39:46 +00:00
|
|
|
static synchronized void closeCamera() {
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2012-10-26 22:47:35 +00:00
|
|
|
@Override
|
2011-11-18 18:28:17 +00:00
|
|
|
public void run() {
|
|
|
|
try {
|
2013-05-24 16:21:01 +00:00
|
|
|
if (getGeckoInterface() != null)
|
|
|
|
getGeckoInterface().disableCameraView();
|
2011-11-18 18:28:17 +00:00
|
|
|
} catch (Exception e) {}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (sCamera != null) {
|
|
|
|
sCamera.stopPreview();
|
|
|
|
sCamera.release();
|
|
|
|
sCamera = null;
|
|
|
|
sCameraBuffer = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-17 15:30:34 +00: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.
|
|
|
|
*/
|
2013-12-06 19:43:11 +00:00
|
|
|
@RobocopTarget
|
2012-08-03 01:38:45 +00:00
|
|
|
public static void registerEventListener(String event, GeckoEventListener listener) {
|
2012-08-02 22:12:35 +00:00
|
|
|
sEventDispatcher.registerEventListener(event, listener);
|
|
|
|
}
|
|
|
|
|
2013-08-20 00:22:47 +00:00
|
|
|
public static EventDispatcher getEventDispatcher() {
|
2012-08-02 22:12:35 +00:00
|
|
|
return sEventDispatcher;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 15:30:34 +00: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.
|
|
|
|
*/
|
2013-12-06 19:43:12 +00:00
|
|
|
@RobocopTarget
|
2012-08-03 01:38:45 +00:00
|
|
|
public static void unregisterEventListener(String event, GeckoEventListener listener) {
|
2012-08-02 22:12:35 +00:00
|
|
|
sEventDispatcher.unregisterEventListener(event, listener);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2011-11-20 23:00:46 +00:00
|
|
|
/*
|
|
|
|
* Battery API related methods.
|
|
|
|
*/
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void enableBatteryNotifications() {
|
|
|
|
GeckoBatteryManager.enableNotifications();
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "HandleGeckoMessageWrapper")
|
2014-02-11 17:16:00 +00:00
|
|
|
public static void handleGeckoMessage(String message) {
|
|
|
|
sEventDispatcher.dispatchEvent(message);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2011-11-18 18:28:17 +00:00
|
|
|
public static void disableBatteryNotifications() {
|
|
|
|
GeckoBatteryManager.disableNotifications();
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetCurrentBatteryInformationWrapper")
|
2011-11-18 18:28:17 +00:00
|
|
|
public static double[] getCurrentBatteryInformation() {
|
|
|
|
return GeckoBatteryManager.getCurrentInformation();
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "CheckURIVisited")
|
2013-09-09 12:57:36 +00:00
|
|
|
static void checkUriVisited(String uri) {
|
2011-11-18 18:28:17 +00:00
|
|
|
GlobalHistory.getInstance().checkUriVisited(uri);
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "MarkURIVisited")
|
2013-09-09 12:57:36 +00:00
|
|
|
static void markUriVisited(final String uri) {
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-11-18 18:28:17 +00:00
|
|
|
public void run() {
|
|
|
|
GlobalHistory.getInstance().add(uri);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "SetURITitle")
|
2013-09-09 12:57:36 +00:00
|
|
|
static void setUriTitle(final String uri, final String title) {
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2013-02-18 17:27:30 +00:00
|
|
|
public void run() {
|
|
|
|
GlobalHistory.getInstance().update(uri, title);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-07-18 05:39:46 +00:00
|
|
|
static void hideProgressDialog() {
|
2011-11-18 18:28:17 +00:00
|
|
|
// unused stub
|
|
|
|
}
|
|
|
|
|
2011-11-20 23:00:46 +00:00
|
|
|
/*
|
|
|
|
* WebSMS related methods.
|
|
|
|
*/
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "SendMessageWrapper")
|
2012-11-06 21:32:07 +00:00
|
|
|
public static void sendMessage(String aNumber, String aMessage, int aRequestId) {
|
2012-01-17 18:38:04 +00:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
SmsManager.getInstance().send(aNumber, aMessage, aRequestId);
|
2012-01-17 18:52:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetMessageWrapper")
|
2012-11-06 21:32:07 +00:00
|
|
|
public static void getMessage(int aMessageId, int aRequestId) {
|
2012-01-17 18:38:04 +00:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
SmsManager.getInstance().getMessage(aMessageId, aRequestId);
|
2012-01-17 18:52:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "DeleteMessageWrapper")
|
2012-11-06 21:32:07 +00:00
|
|
|
public static void deleteMessage(int aMessageId, int aRequestId) {
|
2012-01-17 18:38:04 +00:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
SmsManager.getInstance().deleteMessage(aMessageId, aRequestId);
|
2012-01-17 18:52:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "CreateMessageListWrapper")
|
2012-11-06 21:32:07 +00:00
|
|
|
public static void createMessageList(long aStartDate, long aEndDate, String[] aNumbers, int aNumbersCount, int aDeliveryState, boolean aReverse, int aRequestId) {
|
2012-01-17 18:38:04 +00:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
SmsManager.getInstance().createMessageList(aStartDate, aEndDate, aNumbers, aNumbersCount, aDeliveryState, aReverse, aRequestId);
|
2012-01-17 18:52:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetNextMessageInListWrapper")
|
2012-11-06 21:32:07 +00:00
|
|
|
public static void getNextMessageInList(int aListId, int aRequestId) {
|
2012-01-17 18:38:04 +00:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
SmsManager.getInstance().getNextMessageInList(aListId, aRequestId);
|
2012-01-17 18:52:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-01-17 18:52:17 +00:00
|
|
|
public static void clearMessageList(int aListId) {
|
2012-01-17 18:38:04 +00:00
|
|
|
if (SmsManager.getInstance() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmsManager.getInstance().clearMessageList(aListId);
|
2011-11-20 23:00:46 +00:00
|
|
|
}
|
2011-11-30 04:58:39 +00:00
|
|
|
|
2013-04-02 14:03:39 +00:00
|
|
|
/* Called by JNI from AndroidBridge, and by reflection from tests/BaseTest.java.in */
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2013-12-05 02:32:53 +00:00
|
|
|
@RobocopTarget
|
2011-12-14 21:53:38 +00:00
|
|
|
public static boolean isTablet() {
|
2013-04-02 14:03:39 +00:00
|
|
|
return HardwareUtils.isTablet();
|
2013-02-22 07:22:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-04 03:59:27 +00:00
|
|
|
public static void viewSizeChanged() {
|
2013-05-24 16:21:01 +00:00
|
|
|
LayerView v = getLayerView();
|
2012-11-01 20:11:02 +00:00
|
|
|
if (v != null && v.isIMEEnabled()) {
|
|
|
|
sendEventToGecko(GeckoEvent.createBroadcastEvent(
|
|
|
|
"ScrollTo:FocusedInput", ""));
|
2011-12-04 03:59:27 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-16 13:44:07 +00:00
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetCurrentNetworkInformationWrapper")
|
2012-01-16 13:44:07 +00:00
|
|
|
public static double[] getCurrentNetworkInformation() {
|
2012-01-16 17:17:34 +00:00
|
|
|
return GeckoNetworkManager.getInstance().getCurrentInformation();
|
2012-01-16 13:44:07 +00:00
|
|
|
}
|
2012-01-16 14:01:07 +00:00
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-01-16 14:01:07 +00:00
|
|
|
public static void enableNetworkNotifications() {
|
|
|
|
GeckoNetworkManager.getInstance().enableNotifications();
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-01-16 14:01:07 +00:00
|
|
|
public static void disableNetworkNotifications() {
|
|
|
|
GeckoNetworkManager.getInstance().disableNotifications();
|
|
|
|
}
|
2012-02-01 19:37:03 +00:00
|
|
|
|
2012-02-07 20:32:56 +00: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 19:37:03 +00: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 20:32:56 +00:00
|
|
|
private static final byte[] map1_urlsafe;
|
2012-02-01 19:37:03 +00: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 20:32:56 +00:00
|
|
|
map1[i++] = '+'; map1[i++] = '/';
|
|
|
|
map1_urlsafe = map1.clone();
|
|
|
|
map1_urlsafe[62] = '-'; map1_urlsafe[63] = '_';
|
2012-02-01 19:37:03 +00: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 20:32:56 +00:00
|
|
|
map2['-'] = (byte)62; map2['_'] = (byte)63;
|
2012-02-01 19:37:03 +00: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 20:32:56 +00:00
|
|
|
public static byte[] encodeBase64(byte[] in, int flags) {
|
2012-02-01 19:37:03 +00:00
|
|
|
if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.FROYO)
|
2012-02-07 20:32:56 +00:00
|
|
|
return Base64.encode(in, flags | Base64.NO_WRAP);
|
2012-02-01 19:37:03 +00: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 20:32:56 +00:00
|
|
|
byte[] toMap = ((flags & BASE64_URL_SAFE) == 0 ? map1 : map1_urlsafe);
|
2012-02-01 19:37:03 +00: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 20:32:56 +00: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 19:37:03 +00: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 20:32:56 +00:00
|
|
|
public static byte[] decodeBase64(byte[] in, int flags) {
|
2012-02-01 19:37:03 +00:00
|
|
|
if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.FROYO)
|
2012-02-07 20:32:56 +00:00
|
|
|
return Base64.decode(in, flags);
|
2012-02-01 19:37:03 +00: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 20:32:56 +00:00
|
|
|
public static byte[] decodeBase64(String s, int flags) {
|
|
|
|
return decodeBase64(s.getBytes(), flags);
|
2012-02-01 19:37:03 +00:00
|
|
|
}
|
2012-03-20 13:09:45 +00:00
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetScreenOrientationWrapper")
|
2012-03-20 13:09:45 +00:00
|
|
|
public static short getScreenOrientation() {
|
|
|
|
return GeckoScreenOrientationListener.getInstance().getScreenOrientation();
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-03-20 13:09:45 +00:00
|
|
|
public static void enableScreenOrientationNotifications() {
|
|
|
|
GeckoScreenOrientationListener.getInstance().enableNotifications();
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-03-20 13:09:45 +00:00
|
|
|
public static void disableScreenOrientationNotifications() {
|
|
|
|
GeckoScreenOrientationListener.getInstance().disableNotifications();
|
|
|
|
}
|
2012-03-30 06:31:12 +00:00
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-03-30 06:31:12 +00:00
|
|
|
public static void lockScreenOrientation(int aOrientation) {
|
|
|
|
GeckoScreenOrientationListener.getInstance().lockScreenOrientation(aOrientation);
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-03-30 06:31:12 +00:00
|
|
|
public static void unlockScreenOrientation() {
|
|
|
|
GeckoScreenOrientationListener.getInstance().unlockScreenOrientation();
|
|
|
|
}
|
2012-04-05 05:50:06 +00:00
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-06-05 05:14:12 +00:00
|
|
|
public static boolean pumpMessageLoop() {
|
2013-07-26 19:02:00 +00:00
|
|
|
Handler geckoHandler = ThreadUtils.sGeckoHandler;
|
|
|
|
Message msg = getNextMessageFromQueue(ThreadUtils.sGeckoQueue);
|
|
|
|
|
2012-06-01 00:07:07 +00:00
|
|
|
if (msg == null)
|
2012-06-05 05:14:12 +00:00
|
|
|
return false;
|
2013-07-26 19:02:00 +00:00
|
|
|
if (msg.obj == geckoHandler && msg.getTarget() == geckoHandler) {
|
2013-07-09 20:25:55 +00:00
|
|
|
// Our "queue is empty" message; see runGecko()
|
|
|
|
msg.recycle();
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-05 05:14:12 +00:00
|
|
|
if (msg.getTarget() == null)
|
2012-06-01 00:07:07 +00:00
|
|
|
Looper.myLooper().quit();
|
|
|
|
else
|
|
|
|
msg.getTarget().dispatchMessage(msg);
|
|
|
|
msg.recycle();
|
2012-06-05 05:14:12 +00:00
|
|
|
return true;
|
2012-05-03 14:53:31 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-06-14 16:08:51 +00:00
|
|
|
public static void notifyWakeLockChanged(String topic, String state) {
|
2013-05-24 16:21:01 +00:00
|
|
|
if (getGeckoInterface() != null)
|
|
|
|
getGeckoInterface().notifyWakeLockChanged(topic, state);
|
2012-06-14 16:08:51 +00:00
|
|
|
}
|
2012-07-05 14:12:10 +00:00
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-07-20 19:20:51 +00:00
|
|
|
public static void registerSurfaceTextureFrameListener(Object surfaceTexture, final int id) {
|
|
|
|
((SurfaceTexture)surfaceTexture).setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-07-20 19:20:51 +00:00
|
|
|
public void onFrameAvailable(SurfaceTexture surfaceTexture) {
|
|
|
|
GeckoAppShell.onSurfaceTextureFrameAvailable(surfaceTexture, id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(allowMultithread = true)
|
2012-07-20 19:20:51 +00:00
|
|
|
public static void unregisterSurfaceTextureFrameListener(Object surfaceTexture) {
|
|
|
|
((SurfaceTexture)surfaceTexture).setOnFrameAvailableListener(null);
|
|
|
|
}
|
2012-08-31 13:31:29 +00:00
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI
|
2012-10-05 19:35:26 +00:00
|
|
|
public static boolean unlockProfile() {
|
|
|
|
// Try to kill any zombie Fennec's that might be running
|
|
|
|
GeckoAppShell.killAnyZombies();
|
|
|
|
|
|
|
|
// Then force unlock this profile
|
2013-05-24 16:21:01 +00:00
|
|
|
if (getGeckoInterface() != null) {
|
|
|
|
GeckoProfile profile = getGeckoInterface().getProfile();
|
|
|
|
File lock = profile.getFile(".parentlock");
|
|
|
|
return lock.exists() && lock.delete();
|
|
|
|
}
|
|
|
|
return false;
|
2012-10-05 19:35:26 +00:00
|
|
|
}
|
2012-11-13 19:25:18 +00:00
|
|
|
|
2013-11-12 18:40:59 +00:00
|
|
|
@WrapElementForJNI(stubName = "GetProxyForURIWrapper")
|
2012-11-13 19:25:18 +00:00
|
|
|
public static String getProxyForURI(String spec, String scheme, String host, int port) {
|
2014-01-07 23:46:44 +00:00
|
|
|
final ProxySelector ps = new ProxySelector();
|
2013-12-23 19:09:25 +00:00
|
|
|
|
2014-01-07 23:46:44 +00:00
|
|
|
Proxy proxy = ps.select(scheme, host);
|
2013-12-23 19:09:25 +00:00
|
|
|
if (Proxy.NO_PROXY.equals(proxy)) {
|
|
|
|
return "DIRECT";
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (proxy.type()) {
|
|
|
|
case HTTP:
|
|
|
|
return "PROXY " + proxy.address().toString();
|
|
|
|
case SOCKS:
|
|
|
|
return "SOCKS " + proxy.address().toString();
|
|
|
|
}
|
|
|
|
|
2012-11-13 19:25:18 +00:00
|
|
|
return "DIRECT";
|
|
|
|
}
|
2014-01-09 18:18:55 +00:00
|
|
|
|
2012-07-18 05:39:46 +00:00
|
|
|
}
|