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

Unified Diff: device/generic_sensor/android/java/src/org/chromium/device/sensors/PlatformSensorProvider.java

Issue 2284613002: [sensors] Android platform adaptation for Generic Sensor API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 4 years, 4 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: device/generic_sensor/android/java/src/org/chromium/device/sensors/PlatformSensorProvider.java
diff --git a/device/generic_sensor/android/java/src/org/chromium/device/sensors/PlatformSensorProvider.java b/device/generic_sensor/android/java/src/org/chromium/device/sensors/PlatformSensorProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..ec63f88d277a90b693ebc03711a309908fbd3b56
--- /dev/null
+++ b/device/generic_sensor/android/java/src/org/chromium/device/sensors/PlatformSensorProvider.java
@@ -0,0 +1,73 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.device.sensors;
+
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+import android.os.Handler;
+import android.os.HandlerThread;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+
+import org.chromium.mojom.device.mojom.SensorType;
+
+/**
+ * Lifetime is controlled by device::PlatformSensorProviderAndroid.
+ */
+@JNINamespace("device")
+final class PlatformSensorProvider {
+ private final SensorManager mSensorManager;
+ private final HandlerThread mSensorsThread;
+ private final Handler mHandler;
+
+ private PlatformSensorProvider(Context context) {
+ mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
+
+ if (mSensorManager != null) {
+ mSensorsThread = new HandlerThread("SensorsHandlerThread");
Ted C 2016/09/01 00:12:36 what thread are sensors handled on for other platf
shalamov 2016/09/06 12:36:43 Added code that starts / stops thread when there a
+ mSensorsThread.start();
+ mHandler = new Handler(mSensorsThread.getLooper());
+ } else {
+ mSensorsThread = null;
+ mHandler = null;
+ }
+ }
+
+ @CalledByNative
+ private static PlatformSensorProvider create(Context context) {
+ return new PlatformSensorProvider(context);
+ }
+
+ @CalledByNative
+ private PlatformSensor createSensor(int type) {
+ if (mSensorManager == null || mHandler == null) return null;
+
+ try {
+ switch (type) {
+ case SensorType.AMBIENT_LIGHT:
+ return new GenericPlatformSensor(
+ Sensor.TYPE_LIGHT, 1, mSensorManager, mHandler);
+ case SensorType.ACCELEROMETER:
+ return new GenericPlatformSensor(
+ Sensor.TYPE_ACCELEROMETER, 3, mSensorManager, mHandler);
+ case SensorType.LINEAR_ACCELERATION:
+ return new GenericPlatformSensor(
+ Sensor.TYPE_LINEAR_ACCELERATION, 3, mSensorManager, mHandler);
+ case SensorType.GYROSCOPE:
+ return new GenericPlatformSensor(
+ Sensor.TYPE_GYROSCOPE, 3, mSensorManager, mHandler);
+ case SensorType.MAGNETOMETER:
+ return new GenericPlatformSensor(
+ Sensor.TYPE_MAGNETIC_FIELD, 3, mSensorManager, mHandler);
+ }
+ } catch (PlatformSensorException e) {
+ return null;
+ }
+
+ return null;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698