| Index: content/public/android/java/src/org/chromium/content/browser/DeviceMotionAndOrientation.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/DeviceMotionAndOrientation.java b/content/public/android/java/src/org/chromium/content/browser/DeviceMotionAndOrientation.java
|
| index be73f8c0ab6d84da452435d12b8b6b51e9f68e32..fb866e78c4128e38232cbbfc839d224bd87bc942 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/DeviceMotionAndOrientation.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/DeviceMotionAndOrientation.java
|
| @@ -66,6 +66,7 @@ class DeviceMotionAndOrientation 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);
|
| @@ -75,8 +76,13 @@ class DeviceMotionAndOrientation implements SensorEventListener {
|
| 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;
|
|
|
| @@ -84,6 +90,8 @@ class DeviceMotionAndOrientation implements SensorEventListener {
|
| mAppContext = context.getApplicationContext();
|
| }
|
|
|
| + // TODO(riju) : Use the Device Motion/ Orientation infrastructure as of now.
|
| + // rename accordignly later.
|
| /**
|
| * Start listening for sensor events. If this object is already listening
|
| * for events, the old callback is unregistered first.
|
| @@ -108,6 +116,9 @@ class DeviceMotionAndOrientation 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;
|
| @@ -145,11 +156,25 @@ class DeviceMotionAndOrientation 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 +236,11 @@ class DeviceMotionAndOrientation implements SensorEventListener {
|
| }
|
| }
|
| break;
|
| + case Sensor.TYPE_LIGHT:
|
| + if (mDeviceLightIsActive) {
|
| + gotLight(values[0]);
|
| + }
|
| + break;
|
| default:
|
| // Unexpected
|
| return;
|
| @@ -344,6 +374,9 @@ class DeviceMotionAndOrientation implements SensorEventListener {
|
| case DEVICE_MOTION:
|
| mDeviceMotionIsActive = value;
|
| return;
|
| + case DEVICE_LIGHT:
|
| + mDeviceLightIsActive = value;
|
| + return;
|
| }
|
| }
|
|
|
| @@ -425,6 +458,14 @@ class DeviceMotionAndOrientation 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 +524,13 @@ class DeviceMotionAndOrientation implements SensorEventListener {
|
| double alpha, double beta, double gamma);
|
|
|
| /**
|
| + * Device Light value from Ambient Light Sensors
|
| + */
|
| + private native void nativeGotLight(
|
| + long nativeSensorManagerAndroid,
|
| + double value);
|
| +
|
| + /**
|
| * Need the an interface for SensorManager for testing.
|
| */
|
| interface SensorManagerProxy {
|
|
|