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

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: rebase Created 6 years, 3 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 ade4dfb098f5f0ac06af46a67a78f8aae5ca734b..376b954213bc7b6760c2cbbfdeb3d4abb9ceb945 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
@@ -25,12 +25,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;
@@ -65,6 +65,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);
@@ -73,9 +74,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;
@@ -91,7 +95,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
@@ -107,6 +111,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, true);
+ break;
default:
Log.e(TAG, "Unknown event type: " + eventType);
return false;
@@ -131,7 +138,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.
*/
@@ -144,11 +151,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);
@@ -210,6 +231,11 @@ class DeviceSensors implements SensorEventListener {
}
}
break;
+ case Sensor.TYPE_LIGHT:
+ if (mDeviceLightIsActive) {
+ gotLight(values[0]);
+ }
+ break;
default:
// Unexpected
return;
@@ -343,6 +369,9 @@ class DeviceSensors implements SensorEventListener {
case DEVICE_MOTION:
mDeviceMotionIsActive = value;
return;
+ case DEVICE_LIGHT:
+ mDeviceLightIsActive = value;
+ return;
}
}
@@ -424,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
@@ -482,6 +519,13 @@ class DeviceSensors 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 {
« no previous file with comments | « content/content_browser.gypi ('k') | content/public/android/javatests/src/org/chromium/content/browser/DeviceSensorsTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698