diff --git a/embedding/android/GeckoAppShell.java b/embedding/android/GeckoAppShell.java index 19204cd8fb8..5561f8f196f 100644 --- a/embedding/android/GeckoAppShell.java +++ b/embedding/android/GeckoAppShell.java @@ -679,6 +679,42 @@ public class GeckoAppShell }); } + /* + * Keep these values consistent with |SensorType| in Hal.h + */ + private static final int SENSOR_ORIENTATION = 1; + private static final int SENSOR_ACCELERATION = 2; + private static final int SENSOR_PROXIMITY = 3; + + private static Sensor gProximitySensor = null; + + public static void enableSensor(int aSensortype) { + SensorManager sm = (SensorManager) + GeckoApp.surfaceView.getContext(). + getSystemService(Context.SENSOR_SERVICE); + + switch(aSensortype) { + case SENSOR_PROXIMITY: + if(gProximitySensor == null) + gProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY); + sm.registerListener(GeckoApp.surfaceView, gProximitySensor, + SensorManager.SENSOR_DELAY_GAME); + break; + } + } + + public static void disableSensor(int aSensortype) { + SensorManager sm = (SensorManager) + GeckoApp.surfaceView.getContext(). + getSystemService(Context.SENSOR_SERVICE); + + switch(aSensortype) { + case SENSOR_PROXIMITY: + sm.unregisterListener(GeckoApp.surfaceView, gProximitySensor); + break; + } + } + public static void moveTaskToBack() { GeckoApp.mAppContext.moveTaskToBack(true); } diff --git a/widget/android/AndroidBridge.cpp b/widget/android/AndroidBridge.cpp index 64127c3d7d2..c23928bb73d 100644 --- a/widget/android/AndroidBridge.cpp +++ b/widget/android/AndroidBridge.cpp @@ -107,6 +107,12 @@ AndroidBridge::Init(JNIEnv *jEnv, jEnableDeviceMotion = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableDeviceMotion", "(Z)V"); jEnableLocation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableLocation", "(Z)V"); + jEnableSensor = + (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, + "enableSensor", "(I)V"); + jDisableSensor = + (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, + "disableSensor", "(I)V"); jReturnIMEQueryResult = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "returnIMEQueryResult", "(Ljava/lang/String;II)V"); jScheduleRestart = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "scheduleRestart", "()V"); jNotifyXreExit = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "onXreExit", "()V"); @@ -315,6 +321,20 @@ AndroidBridge::EnableLocation(bool aEnable) env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableLocation, aEnable); } +void +AndroidBridge::EnableSensor(int aSensorType) { + ALOG_BRIDGE("AndroidBridge::EnableSensor"); + mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jEnableSensor, + aSensorType); +} + +void +AndroidBridge::DisableSensor(int aSensorType) { + ALOG_BRIDGE("AndroidBridge::DisableSensor"); + mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jDisableSensor, + aSensorType); +} + void AndroidBridge::ReturnIMEQueryResult(const PRUnichar *aResult, PRUint32 aLen, int aSelStart, int aSelLen) diff --git a/widget/android/AndroidBridge.h b/widget/android/AndroidBridge.h index a236649fa00..faafc718419 100644 --- a/widget/android/AndroidBridge.h +++ b/widget/android/AndroidBridge.h @@ -162,6 +162,10 @@ public: void EnableLocation(bool aEnable); + void EnableSensor(int aSensorType); + + void DisableSensor(int aSensorType); + void ReturnIMEQueryResult(const PRUnichar *aResult, PRUint32 aLen, int aSelStart, int aSelLen); void NotifyXreExit(); @@ -419,6 +423,8 @@ protected: jmethodID jAcknowledgeEventSync; jmethodID jEnableDeviceMotion; jmethodID jEnableLocation; + jmethodID jEnableSensor; + jmethodID jDisableSensor; jmethodID jReturnIMEQueryResult; jmethodID jNotifyAppShellReady; jmethodID jNotifyXreExit;