Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(957)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java

Issue 292693004: [DeviceLight] Browser+java part (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add android instrumentation tests for DeviceLight Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java b/content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java
index bdb7741c6f205c8412ef30415a6d27d1dfd7ade2..67b180197cdc0ad5a6ffc39397e7be61523f902f 100644
--- a/content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java
+++ b/content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java
@@ -26,12 +26,12 @@ import java.util.Set;
import java.util.concurrent.Callable;
/**
- * Android implementation of the device motion and orientation APIs.
+ * Android implementation of the device {motion|orientation|light} APIs.
*/
@JNINamespace("content")
class DeviceSensors implements SensorEventListener {
- private static final String TAG = "DeviceMotionAndOrientation";
+ private static final String TAG = "DeviceSensors";
// These fields are lazily initialized by getHandler().
private Thread mThread;
@@ -66,6 +66,7 @@ class DeviceSensors implements SensorEventListener {
*/
static final int DEVICE_ORIENTATION = 0;
static final int DEVICE_MOTION = 1;
+ static final int DEVICE_LIGHT = 2;
static final Set<Integer> DEVICE_ORIENTATION_SENSORS = CollectionUtil.newHashSet(
Sensor.TYPE_ROTATION_VECTOR);
@@ -74,9 +75,12 @@ class DeviceSensors implements SensorEventListener {
Sensor.TYPE_ACCELEROMETER,
Sensor.TYPE_LINEAR_ACCELERATION,
Sensor.TYPE_GYROSCOPE);
+ static final Set<Integer> DEVICE_LIGHT_SENSORS = CollectionUtil.newHashSet(
+ Sensor.TYPE_LIGHT);
@VisibleForTesting
final Set<Integer> mActiveSensors = new HashSet<Integer>();
+ boolean mDeviceLightIsActive = false;
boolean mDeviceMotionIsActive = false;
boolean mDeviceOrientationIsActive = false;
@@ -92,7 +96,7 @@ class DeviceSensors implements SensorEventListener {
* @param rateInMilliseconds Requested callback rate in milliseconds. The
* actual rate may be higher. Unwanted events should be ignored.
* @param eventType Type of event to listen to, can be either DEVICE_ORIENTATION or
- * DEVICE_MOTION.
+ * DEVICE_MOTION or DEVICE_LIGHT.
* @return True on success.
*/
@CalledByNative
@@ -108,6 +112,9 @@ class DeviceSensors implements SensorEventListener {
// note: device motion spec does not require all sensors to be available
success = registerSensors(DEVICE_MOTION_SENSORS, rateInMilliseconds, false);
break;
+ case DEVICE_LIGHT:
+ success = registerSensors(DEVICE_LIGHT_SENSORS, rateInMilliseconds, false);
+ break;
default:
Log.e(TAG, "Unknown event type: " + eventType);
return false;
@@ -132,7 +139,7 @@ class DeviceSensors implements SensorEventListener {
* if they are still in use by a different event type.
*
* @param eventType Type of event to listen to, can be either DEVICE_ORIENTATION or
- * DEVICE_MOTION.
+ * DEVICE_MOTION or DEVICE_LIGHT.
* We strictly guarantee that the corresponding native*() methods will not be called
* after this method returns.
*/
@@ -145,11 +152,25 @@ class DeviceSensors implements SensorEventListener {
if (mDeviceMotionIsActive) {
sensorsToRemainActive.addAll(DEVICE_MOTION_SENSORS);
}
+ if (mDeviceLightIsActive) {
+ sensorsToRemainActive.addAll(DEVICE_LIGHT_SENSORS);
+ }
break;
case DEVICE_MOTION:
if (mDeviceOrientationIsActive) {
sensorsToRemainActive.addAll(DEVICE_ORIENTATION_SENSORS);
}
+ if (mDeviceLightIsActive) {
+ sensorsToRemainActive.addAll(DEVICE_LIGHT_SENSORS);
+ }
+ break;
+ case DEVICE_LIGHT:
+ if (mDeviceMotionIsActive) {
+ sensorsToRemainActive.addAll(DEVICE_MOTION_SENSORS);
+ }
+ if (mDeviceOrientationIsActive) {
+ sensorsToRemainActive.addAll(DEVICE_ORIENTATION_SENSORS);
+ }
break;
default:
Log.e(TAG, "Unknown event type: " + eventType);
@@ -211,6 +232,10 @@ class DeviceSensors implements SensorEventListener {
}
}
break;
+ case Sensor.TYPE_LIGHT:
+ if (mDeviceLightIsActive) {
+ gotLight(values[0]);
+ }
default:
// Unexpected
return;
@@ -344,6 +369,9 @@ class DeviceSensors implements SensorEventListener {
case DEVICE_MOTION:
mDeviceMotionIsActive = value;
return;
+ case DEVICE_LIGHT:
+ mDeviceLightIsActive = value;
+ return;
}
}
@@ -425,6 +453,14 @@ class DeviceSensors implements SensorEventListener {
}
}
+ protected void gotLight(double value) {
+ synchronized (mNativePtrLock) {
+ if (mNativePtr != 0) {
+ nativeGotLight(mNativePtr, value);
+ }
+ }
+ }
+
private Handler getHandler() {
// TODO(timvolodine): Remove the mHandlerLock when sure that getHandler is not called
// from multiple threads. This will be the case when device motion and device orientation
@@ -483,6 +519,13 @@ class DeviceSensors implements SensorEventListener {
double alpha, double beta, double gamma);
/**
+ * Device Light value from Ambient Light sensors
timvolodine 2014/07/16 15:39:38 nit: add "." in the end.
riju_ 2014/07/18 15:59:18 Done.
+ */
+ private native void nativeGotLight(
+ long nativeSensorManagerAndroid,
+ double value);
+
+ /**
* Need the an interface for SensorManager for testing.
*/
interface SensorManagerProxy {

Powered by Google App Engine
This is Rietveld 408576698