| Index: device/sensors/android/java/src/org/chromium/device/sensors/SensorImpl.java
|
| diff --git a/device/sensors/android/java/src/org/chromium/device/sensors/SensorImpl.java b/device/sensors/android/java/src/org/chromium/device/sensors/SensorImpl.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d328360f2fb39d96337e7bfd09f5ecfa593f8fd4
|
| --- /dev/null
|
| +++ b/device/sensors/android/java/src/org/chromium/device/sensors/SensorImpl.java
|
| @@ -0,0 +1,76 @@
|
| +// 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 org.chromium.mojo.system.MojoException;
|
| +import org.chromium.mojom.device.sensors.Sensor;
|
| +import org.chromium.mojom.device.sensors.SensorClient;
|
| +import org.chromium.mojom.device.sensors.SensorConfiguration;
|
| +
|
| +/**
|
| + * Implementation of Sensor mojo interface
|
| + * device/sensors/sensor.mojom
|
| + */
|
| +public class SensorImpl implements Sensor, SensorProxy {
|
| + private final SensorBase mSensor;
|
| + private final SensorConfigurations mConfigurations = new SensorConfigurations();
|
| + private SensorClient mClient;
|
| +
|
| + public SensorImpl(SensorBase sensor) {
|
| + mSensor = sensor;
|
| + }
|
| +
|
| + @Override
|
| + public void setClient(SensorClient client) {
|
| + mClient = client;
|
| + mSensor.addSensorProxy(this);
|
| + }
|
| +
|
| + @Override
|
| + public void start(SensorConfiguration configuration, StartResponse response) {
|
| + mConfigurations.add(configuration);
|
| + boolean startedListening = mSensor.startListening(this);
|
| + if (!startedListening) mConfigurations.remove(configuration);
|
| + response.call(startedListening);
|
| + }
|
| +
|
| + @Override
|
| + public void stop(SensorConfiguration configuration, StopResponse response) {
|
| + mConfigurations.remove(configuration);
|
| + if (mConfigurations.isEmpty()) {
|
| + response.call(mSensor.stopListening(this));
|
| + } else {
|
| + response.call(mSensor.configuratoinUpdated());
|
| + }
|
| + }
|
| +
|
| + @Override
|
| + public void close() {
|
| + mConfigurations.clear();
|
| + mSensor.stopListening(this);
|
| + mSensor.removeSensorProxy(this);
|
| + }
|
| +
|
| + @Override
|
| + public void onConnectionError(MojoException e) {
|
| + close();
|
| + }
|
| +
|
| + @Override
|
| + public SensorConfiguration getCurrentConfiguration() {
|
| + if (!mConfigurations.isEmpty()) return mConfigurations.get(0);
|
| + return null;
|
| + }
|
| +
|
| + @Override
|
| + public void reportError() {
|
| + if (mClient != null) mClient.onSensorError();
|
| + }
|
| +
|
| + @Override
|
| + public void reportSensorReadingChaned() {
|
| + if (mClient != null) mClient.onSensorReadingChanged();
|
| + }
|
| +}
|
|
|