diff --git a/api/current.txt b/api/current.txt
index 36dbc40f93aa9..94e07fc684ab9 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -13503,6 +13503,7 @@ package android.hardware {
public final class Sensor {
method public int getFifoMaxEventCount();
method public int getFifoReservedEventCount();
+ method public int getId();
method public int getMaxDelay();
method public float getMaximumRange();
method public int getMinDelay();
@@ -13512,9 +13513,10 @@ package android.hardware {
method public float getResolution();
method public java.lang.String getStringType();
method public int getType();
- method public java.util.UUID getUuid();
method public java.lang.String getVendor();
method public int getVersion();
+ method public boolean isAdditionalInfoSupported();
+ method public boolean isDynamicSensor();
method public boolean isWakeUpSensor();
field public static final int REPORTING_MODE_CONTINUOUS = 0; // 0x0
field public static final int REPORTING_MODE_ONE_SHOT = 2; // 0x2
@@ -13633,8 +13635,9 @@ package android.hardware {
method public static void getRotationMatrixFromVector(float[], float[]);
method public java.util.List getSensorList(int);
method public deprecated int getSensors();
- method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback);
- method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback, android.os.Handler);
+ method public boolean isDynamicSensorDiscoverySupported();
+ method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback);
+ method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback, android.os.Handler);
method public deprecated boolean registerListener(android.hardware.SensorListener, int);
method public deprecated boolean registerListener(android.hardware.SensorListener, int, int);
method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int);
@@ -13643,7 +13646,7 @@ package android.hardware {
method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int, int, android.os.Handler);
method public static boolean remapCoordinateSystem(float[], int, int, float[]);
method public boolean requestTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor);
- method public void unregisterDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback);
+ method public void unregisterDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback);
method public deprecated void unregisterListener(android.hardware.SensorListener);
method public deprecated void unregisterListener(android.hardware.SensorListener, int);
method public void unregisterListener(android.hardware.SensorEventListener, android.hardware.Sensor);
@@ -13708,8 +13711,8 @@ package android.hardware {
field public static final float STANDARD_GRAVITY = 9.80665f;
}
- public static abstract class SensorManager.DynamicSensorConnectionCallback {
- ctor public SensorManager.DynamicSensorConnectionCallback();
+ public static abstract class SensorManager.DynamicSensorCallback {
+ ctor public SensorManager.DynamicSensorCallback();
method public void onDynamicSensorConnected(android.hardware.Sensor);
method public void onDynamicSensorDisconnected(android.hardware.Sensor);
}
diff --git a/api/system-current.txt b/api/system-current.txt
index 96f2b06a07915..69a49d15144bd 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -13902,6 +13902,7 @@ package android.hardware {
public final class Sensor {
method public int getFifoMaxEventCount();
method public int getFifoReservedEventCount();
+ method public int getId();
method public int getMaxDelay();
method public float getMaximumRange();
method public int getMinDelay();
@@ -13914,7 +13915,9 @@ package android.hardware {
method public java.util.UUID getUuid();
method public java.lang.String getVendor();
method public int getVersion();
+ method public boolean isAdditionalInfoSupported();
method public boolean isDataInjectionSupported();
+ method public boolean isDynamicSensor();
method public boolean isWakeUpSensor();
field public static final int REPORTING_MODE_CONTINUOUS = 0; // 0x0
field public static final int REPORTING_MODE_ONE_SHOT = 2; // 0x2
@@ -14039,8 +14042,9 @@ package android.hardware {
method public deprecated int getSensors();
method public boolean initDataInjection(boolean);
method public boolean injectSensorData(android.hardware.Sensor, float[], int, long);
- method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback);
- method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback, android.os.Handler);
+ method public boolean isDynamicSensorDiscoverySupported();
+ method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback);
+ method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback, android.os.Handler);
method public deprecated boolean registerListener(android.hardware.SensorListener, int);
method public deprecated boolean registerListener(android.hardware.SensorListener, int, int);
method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int);
@@ -14049,7 +14053,7 @@ package android.hardware {
method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int, int, android.os.Handler);
method public static boolean remapCoordinateSystem(float[], int, int, float[]);
method public boolean requestTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor);
- method public void unregisterDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback);
+ method public void unregisterDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback);
method public deprecated void unregisterListener(android.hardware.SensorListener);
method public deprecated void unregisterListener(android.hardware.SensorListener, int);
method public void unregisterListener(android.hardware.SensorEventListener, android.hardware.Sensor);
@@ -14114,8 +14118,8 @@ package android.hardware {
field public static final float STANDARD_GRAVITY = 9.80665f;
}
- public static abstract class SensorManager.DynamicSensorConnectionCallback {
- ctor public SensorManager.DynamicSensorConnectionCallback();
+ public static abstract class SensorManager.DynamicSensorCallback {
+ ctor public SensorManager.DynamicSensorCallback();
method public void onDynamicSensorConnected(android.hardware.Sensor);
method public void onDynamicSensorDisconnected(android.hardware.Sensor);
}
diff --git a/api/test-current.txt b/api/test-current.txt
index 92a466c796866..53da4598c02bb 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -13513,6 +13513,7 @@ package android.hardware {
public final class Sensor {
method public int getFifoMaxEventCount();
method public int getFifoReservedEventCount();
+ method public int getId();
method public int getMaxDelay();
method public float getMaximumRange();
method public int getMinDelay();
@@ -13522,9 +13523,10 @@ package android.hardware {
method public float getResolution();
method public java.lang.String getStringType();
method public int getType();
- method public java.util.UUID getUuid();
method public java.lang.String getVendor();
method public int getVersion();
+ method public boolean isAdditionalInfoSupported();
+ method public boolean isDynamicSensor();
method public boolean isWakeUpSensor();
field public static final int REPORTING_MODE_CONTINUOUS = 0; // 0x0
field public static final int REPORTING_MODE_ONE_SHOT = 2; // 0x2
@@ -13643,8 +13645,9 @@ package android.hardware {
method public static void getRotationMatrixFromVector(float[], float[]);
method public java.util.List getSensorList(int);
method public deprecated int getSensors();
- method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback);
- method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback, android.os.Handler);
+ method public boolean isDynamicSensorDiscoverySupported();
+ method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback);
+ method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback, android.os.Handler);
method public deprecated boolean registerListener(android.hardware.SensorListener, int);
method public deprecated boolean registerListener(android.hardware.SensorListener, int, int);
method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int);
@@ -13653,7 +13656,7 @@ package android.hardware {
method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int, int, android.os.Handler);
method public static boolean remapCoordinateSystem(float[], int, int, float[]);
method public boolean requestTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor);
- method public void unregisterDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback);
+ method public void unregisterDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback);
method public deprecated void unregisterListener(android.hardware.SensorListener);
method public deprecated void unregisterListener(android.hardware.SensorListener, int);
method public void unregisterListener(android.hardware.SensorEventListener, android.hardware.Sensor);
@@ -13718,8 +13721,8 @@ package android.hardware {
field public static final float STANDARD_GRAVITY = 9.80665f;
}
- public static abstract class SensorManager.DynamicSensorConnectionCallback {
- ctor public SensorManager.DynamicSensorConnectionCallback();
+ public static abstract class SensorManager.DynamicSensorCallback {
+ ctor public SensorManager.DynamicSensorCallback();
method public void onDynamicSensorConnected(android.hardware.Sensor);
method public void onDynamicSensorDisconnected(android.hardware.Sensor);
}
diff --git a/core/java/android/hardware/Sensor.java b/core/java/android/hardware/Sensor.java
index 63ee8d2e75d3b..cc82eb67c275c 100644
--- a/core/java/android/hardware/Sensor.java
+++ b/core/java/android/hardware/Sensor.java
@@ -186,7 +186,7 @@ public final class Sensor {
* @see #TYPE_LINEAR_ACCELERATION
*/
public static final String STRING_TYPE_LINEAR_ACCELERATION =
- "android.sensor.linear_acceleration";
+ "android.sensor.linear_acceleration";
/**
* A constant describing a rotation vector sensor type.
@@ -229,7 +229,7 @@ public final class Sensor {
* @see #TYPE_AMBIENT_TEMPERATURE
*/
public static final String STRING_TYPE_AMBIENT_TEMPERATURE =
- "android.sensor.ambient_temperature";
+ "android.sensor.ambient_temperature";
/**
* A constant describing an uncalibrated magnetic field sensor type.
@@ -254,7 +254,7 @@ public final class Sensor {
* @see #TYPE_MAGNETIC_FIELD_UNCALIBRATED
*/
public static final String STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED =
- "android.sensor.magnetic_field_uncalibrated";
+ "android.sensor.magnetic_field_uncalibrated";
/**
* A constant describing an uncalibrated rotation vector sensor type.
@@ -280,7 +280,7 @@ public final class Sensor {
* @see #TYPE_GAME_ROTATION_VECTOR
*/
public static final String STRING_TYPE_GAME_ROTATION_VECTOR =
- "android.sensor.game_rotation_vector";
+ "android.sensor.game_rotation_vector";
/**
* A constant describing an uncalibrated gyroscope sensor type.
@@ -302,7 +302,7 @@ public final class Sensor {
* @see #TYPE_GYROSCOPE_UNCALIBRATED
*/
public static final String STRING_TYPE_GYROSCOPE_UNCALIBRATED =
- "android.sensor.gyroscope_uncalibrated";
+ "android.sensor.gyroscope_uncalibrated";
/**
* A constant describing a significant motion trigger sensor.
@@ -324,7 +324,7 @@ public final class Sensor {
* @see #TYPE_SIGNIFICANT_MOTION
*/
public static final String STRING_TYPE_SIGNIFICANT_MOTION =
- "android.sensor.significant_motion";
+ "android.sensor.significant_motion";
/**
* A constant describing a step detector sensor.
@@ -391,7 +391,7 @@ public final class Sensor {
* @see #TYPE_GEOMAGNETIC_ROTATION_VECTOR
*/
public static final String STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR =
- "android.sensor.geomagnetic_rotation_vector";
+ "android.sensor.geomagnetic_rotation_vector";
/**
* A constant describing a heart rate monitor.
@@ -431,7 +431,7 @@ public final class Sensor {
* A constant string describing a wake up tilt detector sensor type.
*
* @hide
- * @see #TYPE_WAKE_UP_TILT_DETECTOR
+ * @see #TYPE_TILT_DETECTOR
*/
public static final String SENSOR_STRING_TYPE_TILT_DETECTOR =
"android.sensor.tilt_detector";
@@ -495,7 +495,7 @@ public final class Sensor {
*/
public static final String STRING_TYPE_GLANCE_GESTURE = "android.sensor.glance_gesture";
- /**
+ /**
* A constant describing a pick up sensor.
*
* A sensor of this type triggers when the device is picked up regardless of wherever it was
@@ -514,7 +514,7 @@ public final class Sensor {
*/
public static final String STRING_TYPE_PICK_UP_GESTURE = "android.sensor.pick_up_gesture";
- /**
+ /**
* A constant describing a wrist tilt gesture sensor.
*
* A sensor of this type triggers when the device face is tilted towards the user.
@@ -553,7 +553,7 @@ public final class Sensor {
*/
public static final String STRING_TYPE_DEVICE_ORIENTATION = "android.sensor.device_orientation";
- /**
+ /**
* A constant describing a pose sensor with 6 degrees of freedom.
*
* Similar to {@link #TYPE_ROTATION_VECTOR}, with additional delta
@@ -578,7 +578,7 @@ public final class Sensor {
*/
public static final String STRING_TYPE_POSE_6DOF = "android.sensor.pose_6dof";
- /**
+ /**
* A constant describing a stationary detect sensor.
*
* See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
@@ -593,7 +593,7 @@ public final class Sensor {
*/
public static final String STRING_TYPE_STATIONARY_DETECT = "android.sensor.stationary_detect";
- /**
+ /**
* A constant describing a motion detect sensor.
*
* See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
@@ -608,7 +608,7 @@ public final class Sensor {
*/
public static final String STRING_TYPE_MOTION_DETECT = "android.sensor.motion_detect";
- /**
+ /**
* A constant describing a motion detect sensor.
*
* See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
@@ -706,6 +706,14 @@ public final class Sensor {
private static final int DATA_INJECTION_MASK = 0x10;
private static final int DATA_INJECTION_SHIFT = 4;
+ // MASK for dynamic sensor (sensor that added during runtime), bit 6.
+ private static final int DYNAMIC_SENSOR_MASK = 0x20;
+ private static final int DYNAMIC_SENSOR_SHIFT = 5;
+
+ // MASK for indication bit of sensor additional information support (bit 7).
+ private static final int ADDITIONAL_INFO_MASK = 0x40;
+ private static final int ADDITIONAL_INFO_SHIFT = 6;
+
// TODO(): The following arrays are fragile and error-prone. This needs to be refactored.
// Note: This needs to be updated, whenever a new sensor is added.
@@ -887,12 +895,36 @@ public final class Sensor {
}
/**
- * @return The type of this sensor as a string.
+ * @return The UUID of the sensor. If the sensor does not support UUID, the returned value will
+ * be an all zero UUID; if the sensor's combination of type and name is guaranteed to be unique
+ * in system, the return value will be an all "F" UUID.
+ *
+ * @hide
*/
+ @SystemApi
public UUID getUuid() {
return mUuid;
}
+ /**
+ * @return The unique id of sensor. Return value of 0 means this sensor does not support UUID;
+ * return value of -1 means this sensor can be uniquely identified in system by combination of
+ * its type and name.
+ */
+ public int getId() {
+ if (mUuid == ALL_0_UUID) {
+ return 0;
+ } else if (mUuid == ALL_F_UUID) {
+ return -1;
+ } else {
+ int id = Math.abs(mUuid.hashCode()) + 1;
+ if (id <= 0) { // catch corner case when hash is Integer.MIN_VALUE and Integer.MAX_VALUE
+ id = 1;
+ }
+ return id;
+ }
+ }
+
/**
* @hide
* @return The permission required to access this sensor. If empty, no permission is required.
@@ -960,6 +992,26 @@ public final class Sensor {
return (mFlags & SENSOR_FLAG_WAKE_UP_SENSOR) != 0;
}
+ /**
+ * Returns true if the sensor is a dynamic sensor.
+ *
+ * @return true if the sensor is a dynamic sensor (sensor added at runtime).
+ * @see SensorManager.DynamicSensorCallback
+ */
+ public boolean isDynamicSensor() {
+ return (mFlags & DYNAMIC_SENSOR_MASK) != 0;
+ }
+
+ /**
+ * Returns true if the sensor supports sensor additional information API
+ *
+ * @return true if the sensor supports sensor additional information API
+ * @see SensorAdditionalInfo
+ */
+ public boolean isAdditionalInfoSupported() {
+ return (mFlags & ADDITIONAL_INFO_MASK) != 0;
+ }
+
/**
* Returns true if the sensor supports data injection when the
* HAL is set to data injection mode.
@@ -986,6 +1038,10 @@ public final class Sensor {
+ ", power=" + mPower + ", minDelay=" + mMinDelay + "}";
}
+ //special UUID hash constant
+ private final static UUID ALL_0_UUID = new UUID(0,0);
+ private final static UUID ALL_F_UUID = new UUID(~0L, ~0L);
+
/**
* Sets the Type associated with the sensor.
* NOTE: to be used only by native bindings in SensorManager.
diff --git a/core/java/android/hardware/SensorAdditionalInfo.java b/core/java/android/hardware/SensorAdditionalInfo.java
index 8e5b8a3c1a6cd..572a287f53d81 100644
--- a/core/java/android/hardware/SensorAdditionalInfo.java
+++ b/core/java/android/hardware/SensorAdditionalInfo.java
@@ -27,7 +27,7 @@ import java.lang.annotation.RetentionPolicy;
* android.hardware.SensorEventCallback#onSensorAdditionalInfo onSensorAdditionalInfo}.
*
* @see SensorManager
- * @see SensorEventListener3
+ * @see SensorEventCallback
* @see Sensor
*
*/
@@ -106,7 +106,7 @@ public class SensorAdditionalInfo {
* such as accelerometer, gyro, etc.
*
* Payload:
- * floatValues[0..11]: First 3 rows of a homogenous matrix in row major order that captures
+ * floatValues[0..11]: First 3 rows of a homogeneous matrix in row major order that captures
* any linear transformation, including rotation, scaling, shear, shift.
*/
public static final int TYPE_VEC3_CALIBRATION = 0x10002;
diff --git a/core/java/android/hardware/SensorEvent.java b/core/java/android/hardware/SensorEvent.java
index 35c96f724017b..0d96b8e82a5d9 100644
--- a/core/java/android/hardware/SensorEvent.java
+++ b/core/java/android/hardware/SensorEvent.java
@@ -18,7 +18,7 @@ package android.hardware;
/**
* This class represents a {@link android.hardware.Sensor Sensor} event and
- * holds informations such as the sensor's type, the time-stamp, accuracy and of
+ * holds information such as the sensor's type, the time-stamp, accuracy and of
* course the sensor's {@link SensorEvent#values data}.
*
*
@@ -163,7 +163,7 @@ public class SensorEvent {
*
*
* Typically the output of the gyroscope is integrated over time to
- * calculate a rotation describing the change of angles over the timestep,
+ * calculate a rotation describing the change of angles over the time step,
* for example:
*
*
@@ -173,7 +173,7 @@ public class SensorEvent {
* private float timestamp;
*
* public void onSensorChanged(SensorEvent event) {
- * // This timestep's delta rotation to be multiplied by the current rotation
+ * // This time step's delta rotation to be multiplied by the current rotation
* // after computing it from the gyro sample data.
* if (timestamp != 0) {
* final float dT = (event.timestamp - timestamp) * NS2S;
@@ -192,8 +192,8 @@ public class SensorEvent {
* axisZ /= omegaMagnitude;
* }
*
- * // Integrate around this axis with the angular speed by the timestep
- * // in order to get a delta rotation from this sample over the timestep
+ * // Integrate around this axis with the angular speed by the time step
+ * // in order to get a delta rotation from this sample over the time step
* // We will convert this axis-angle representation of the delta rotation
* // into a quaternion before turning it into the rotation matrix.
* float thetaOverTwo = omegaMagnitude * dT / 2.0f;
@@ -433,9 +433,9 @@ public class SensorEvent {
* Each field is a component of the estimated hard iron calibration.
* The values are in micro-Tesla (uT).
*
- * Hard iron - These distortions arise due to the magnetized iron, steel or permanenet
+ *
Hard iron - These distortions arise due to the magnetized iron, steel or permanent
* magnets on the device.
- * Soft iron - These distortions arise due to the interaction with the earth's magentic
+ * Soft iron - These distortions arise due to the interaction with the earth's magnetic
* field.
*
* {@link android.hardware.Sensor#TYPE_GAME_ROTATION_VECTOR}:
@@ -508,14 +508,14 @@ public class SensorEvent {
*
*
*
- * - values[0]: x*sin(θ/2)
- * - values[1]: y*sin(θ/2)
- * - values[2]: z*sin(θ/2)
- * - values[3]: cos(θ/2)
+ * - values[0]: x*sin(θ/2)
+ * - values[1]: y*sin(θ/2)
+ * - values[2]: z*sin(θ/2)
+ * - values[3]: cos(θ/2)
*
*
* - values[4]: Translation along x axis from an arbitrary origin.
- * li> values[5]: Translation along y axis from an arbitrary origin.
+ * - values[5]: Translation along y axis from an arbitrary origin.
* - values[6]: Translation along z axis from an arbitrary origin.
*
* - values[7]: Delta quaternion rotation x*sin(θ/2)
diff --git a/core/java/android/hardware/SensorManager.java b/core/java/android/hardware/SensorManager.java
index 5684aa5cb6fcf..a20307a868c7f 100644
--- a/core/java/android/hardware/SensorManager.java
+++ b/core/java/android/hardware/SensorManager.java
@@ -884,7 +884,7 @@ public abstract class SensorManager {
* Used for receiving notifications from the SensorManager when dynamic sensors are connected or
* disconnected.
*/
- public static abstract class DynamicSensorConnectionCallback {
+ public static abstract class DynamicSensorCallback {
/**
* Called when there is a dynamic sensor being connected to the system.
*
@@ -902,62 +902,73 @@ public abstract class SensorManager {
/**
- * Add a {@link android.hardware.SensorManager.DynamicSensorConnectionCallback
- * DynamicSensorConnectionCallback} to receive dynamic sensor connection callbacks. Repeat
+ * Add a {@link android.hardware.SensorManager.DynamicSensorCallback
+ * DynamicSensorCallback} to receive dynamic sensor connection callbacks. Repeat
* registration with the already registered callback object will have no additional effect.
*
* @param callback An object that implements the
- * {@link android.hardware.SensorManager.DynamicSensorConnectionCallback
- * DynamicSensorConnectionCallback}
+ * {@link android.hardware.SensorManager.DynamicSensorCallback
+ * DynamicSensorCallback}
* interface for receiving callbacks.
- * @see #addDynamicSensorCallback(DynamicSensorConnectionCallback, Handler)
+ * @see #addDynamicSensorCallback(DynamicSensorCallback, Handler)
*
* @throws IllegalArgumentException when callback is null.
*/
- public void registerDynamicSensorCallback(DynamicSensorConnectionCallback callback) {
+ public void registerDynamicSensorCallback(DynamicSensorCallback callback) {
registerDynamicSensorCallback(callback, null);
}
/**
- * Add a {@link android.hardware.SensorManager.DynamicSensorConnectionCallback
- * DynamicSensorConnectionCallback} to receive dynamic sensor connection callbacks. Repeat
+ * Add a {@link android.hardware.SensorManager.DynamicSensorCallback
+ * DynamicSensorCallback} to receive dynamic sensor connection callbacks. Repeat
* registration with the already registered callback object will have no additional effect.
*
* @param callback An object that implements the
- * {@link android.hardware.SensorManager.DynamicSensorConnectionCallback
- * DynamicSensorConnectionCallback} interface for receiving callbacks.
+ * {@link android.hardware.SensorManager.DynamicSensorCallback
+ * DynamicSensorCallback} interface for receiving callbacks.
* @param handler The {@link android.os.Handler Handler} the {@link
- * android.hardware.SensorManager.DynamicSensorConnectionCallback
+ * android.hardware.SensorManager.DynamicSensorCallback
* sensor connection events} will be delivered to.
*
* @throws IllegalArgumentException when callback is null.
*/
public void registerDynamicSensorCallback(
- DynamicSensorConnectionCallback callback, Handler handler) {
+ DynamicSensorCallback callback, Handler handler) {
registerDynamicSensorCallbackImpl(callback, handler);
}
/**
- * Remove a {@link android.hardware.SensorManager.DynamicSensorConnectionCallback
- * DynamicSensorConnectionCallback} to stop sending dynamic sensor connection events to that
+ * Remove a {@link android.hardware.SensorManager.DynamicSensorCallback
+ * DynamicSensorCallback} to stop sending dynamic sensor connection events to that
* callback.
*
* @param callback An object that implements the
- * {@link android.hardware.SensorManager.DynamicSensorConnectionCallback
- * DynamicSensorConnectionCallback}
+ * {@link android.hardware.SensorManager.DynamicSensorCallback
+ * DynamicSensorCallback}
* interface for receiving callbacks.
*/
- public void unregisterDynamicSensorCallback(DynamicSensorConnectionCallback callback) {
+ public void unregisterDynamicSensorCallback(DynamicSensorCallback callback) {
unregisterDynamicSensorCallbackImpl(callback);
}
+ /**
+ * Tell if dynamic sensor discovery feature is supported by system.
+ *
+ * @return true if dynamic sensor discovery is supported, false
+ * otherwise.
+ */
+ public boolean isDynamicSensorDiscoverySupported() {
+ List sensors = getSensorList(Sensor.TYPE_DYNAMIC_SENSOR_META);
+ return sensors.size() > 0;
+ }
+
/** @hide */
protected abstract void registerDynamicSensorCallbackImpl(
- DynamicSensorConnectionCallback callback, Handler handler);
+ DynamicSensorCallback callback, Handler handler);
/** @hide */
protected abstract void unregisterDynamicSensorCallbackImpl(
- DynamicSensorConnectionCallback callback);
+ DynamicSensorCallback callback);
/**
*
diff --git a/core/java/android/hardware/SystemSensorManager.java b/core/java/android/hardware/SystemSensorManager.java
index 7d903bd89fe41..259ca032918b7 100644
--- a/core/java/android/hardware/SystemSensorManager.java
+++ b/core/java/android/hardware/SystemSensorManager.java
@@ -1,4 +1,4 @@
- /*
+/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -76,7 +76,7 @@ public class SystemSensorManager extends SensorManager {
new HashMap();
// Dynamic Sensor callbacks
- private HashMap
+ private HashMap
mDynamicSensorCallbacks = new HashMap<>();
private BroadcastReceiver mDynamicSensorBroadcastReceiver;
@@ -120,7 +120,7 @@ public class SystemSensorManager extends SensorManager {
@Override
protected List getFullDynamicSensorList() {
// only set up broadcast receiver if the application tries to find dynamic sensors or
- // explicitly register a DynamicSensorConnectionCallback
+ // explicitly register a DynamicSensorCallback
setupDynamicSensorBroadcastReceiver();
updateDynamicSensorList();
return mFullDynamicSensorsList;
@@ -354,9 +354,9 @@ public class SystemSensorManager extends SensorManager {
Handler mainHandler = new Handler(mContext.getMainLooper());
- for (Map.Entry entry :
+ for (Map.Entry entry :
mDynamicSensorCallbacks.entrySet()) {
- final DynamicSensorConnectionCallback callback = entry.getKey();
+ final DynamicSensorCallback callback = entry.getKey();
Handler handler =
entry.getValue() == null ? mainHandler : entry.getValue();
@@ -413,7 +413,7 @@ public class SystemSensorManager extends SensorManager {
/** @hide */
protected void registerDynamicSensorCallbackImpl(
- DynamicSensorConnectionCallback callback, Handler handler) {
+ DynamicSensorCallback callback, Handler handler) {
if (DEBUG_DYNAMIC_SENSOR) {
Log.i(TAG, "DYNS Register dynamic sensor callback");
}
@@ -432,7 +432,7 @@ public class SystemSensorManager extends SensorManager {
/** @hide */
protected void unregisterDynamicSensorCallbackImpl(
- DynamicSensorConnectionCallback callback) {
+ DynamicSensorCallback callback) {
if (DEBUG_DYNAMIC_SENSOR) {
Log.i(TAG, "Removing dynamic sensor listerner");
}