OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.device.sensors; |
| 6 |
| 7 import org.chromium.mojo.system.MojoException; |
| 8 import org.chromium.mojom.device.sensors.Sensor; |
| 9 import org.chromium.mojom.device.sensors.SensorClient; |
| 10 import org.chromium.mojom.device.sensors.SensorConfiguration; |
| 11 |
| 12 /** |
| 13 * Implementation of Sensor mojo interface |
| 14 * device/sensors/sensor.mojom |
| 15 */ |
| 16 public class SensorImpl implements Sensor, SensorProxy { |
| 17 private final SensorBase mSensor; |
| 18 private final SensorConfigurations mConfigurations = new SensorConfiguration
s(); |
| 19 private SensorClient mClient; |
| 20 |
| 21 public SensorImpl(SensorBase sensor) { |
| 22 mSensor = sensor; |
| 23 } |
| 24 |
| 25 @Override |
| 26 public void setClient(SensorClient client) { |
| 27 mClient = client; |
| 28 mSensor.addSensorProxy(this); |
| 29 } |
| 30 |
| 31 @Override |
| 32 public void start(SensorConfiguration configuration, StartResponse response)
{ |
| 33 mConfigurations.add(configuration); |
| 34 boolean startedListening = mSensor.startListening(this); |
| 35 if (!startedListening) mConfigurations.remove(configuration); |
| 36 response.call(startedListening); |
| 37 } |
| 38 |
| 39 @Override |
| 40 public void stop(SensorConfiguration configuration, StopResponse response) { |
| 41 mConfigurations.remove(configuration); |
| 42 if (mConfigurations.isEmpty()) { |
| 43 response.call(mSensor.stopListening(this)); |
| 44 } else { |
| 45 response.call(mSensor.configuratoinUpdated()); |
| 46 } |
| 47 } |
| 48 |
| 49 @Override |
| 50 public void close() { |
| 51 mConfigurations.clear(); |
| 52 mSensor.stopListening(this); |
| 53 mSensor.removeSensorProxy(this); |
| 54 } |
| 55 |
| 56 @Override |
| 57 public void onConnectionError(MojoException e) { |
| 58 close(); |
| 59 } |
| 60 |
| 61 @Override |
| 62 public SensorConfiguration getCurrentConfiguration() { |
| 63 if (!mConfigurations.isEmpty()) return mConfigurations.get(0); |
| 64 return null; |
| 65 } |
| 66 |
| 67 @Override |
| 68 public void reportError() { |
| 69 if (mClient != null) mClient.onSensorError(); |
| 70 } |
| 71 |
| 72 @Override |
| 73 public void reportSensorReadingChaned() { |
| 74 if (mClient != null) mClient.onSensorReadingChanged(); |
| 75 } |
| 76 } |
OLD | NEW |