diff options
author | Aravind Akella <aakella@google.com> | 2015-06-29 12:35:51 -0700 |
---|---|---|
committer | Aravind Akella <aakella@google.com> | 2015-06-29 13:04:09 -0700 |
commit | d123b51f8b14047804612cb1b15288cca81ed4f9 (patch) | |
tree | c0c1a2b22d5821ef3f040c221724d69f64db01d3 /core/java | |
parent | a1b647c8833cf85e304e3c201e7d0477b9838502 (diff) | |
download | frameworks_base-d123b51f8b14047804612cb1b15288cca81ed4f9.zip frameworks_base-d123b51f8b14047804612cb1b15288cca81ed4f9.tar.gz frameworks_base-d123b51f8b14047804612cb1b15288cca81ed4f9.tar.bz2 |
Changes to Data Injection mode APIs
Change-Id: Id55eaf03656d2d55df7f38d4cac643d97354fe9b
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/hardware/SensorManager.java | 49 | ||||
-rw-r--r-- | core/java/android/hardware/SystemSensorManager.java | 47 |
2 files changed, 40 insertions, 56 deletions
diff --git a/core/java/android/hardware/SensorManager.java b/core/java/android/hardware/SensorManager.java index d6b1142..d456b5e 100644 --- a/core/java/android/hardware/SensorManager.java +++ b/core/java/android/hardware/SensorManager.java @@ -1568,47 +1568,41 @@ public abstract class SensorManager { /** * For testing purposes only. Not for third party applications. * - * Enable data injection mode in sensor service. This mode is - * expected to be used only for testing purposes. If the HAL is - * set to data injection mode, it will ignore the input from - * physical sensors and read sensor data that is injected from - * the test application. This mode is used for testing vendor - * implementations for various algorithms like Rotation Vector, - * Significant Motion, Step Counter etc. - * - * The tests which call this API need to have {@code - * android.permission.LOCATION_HADWARE} permission which isn't - * available for third party applications. - * - * @param enable True to set the HAL in DATA_INJECTION mode. - * False to reset the HAL back to NORMAL mode. + * Initialize data injection mode and create a client for data injection. SensorService should + * already be operating in DATA_INJECTION mode for this call succeed. To set SensorService into + * DATA_INJECTION mode "adb shell dumpsys sensorservice data_injection" needs to be called + * through adb. Typically this is done using a host side test. This mode is expected to be used + * only for testing purposes. If the HAL is set to data injection mode, it will ignore the input + * from physical sensors and read sensor data that is injected from the test application. This + * mode is used for testing vendor implementations for various algorithms like Rotation Vector, + * Significant Motion, Step Counter etc. Not all HALs support DATA_INJECTION. This method will + * fail in those cases. Once this method succeeds, the test can call + * {@link injectSensorData(Sensor, float[], int, long)} to inject sensor data into the HAL. + * + * @param enable True to initialize a client in DATA_INJECTION mode. + * False to clean up the native resources. * * @return true if the HAL supports data injection and false * otherwise. * @hide */ @SystemApi - public boolean enableDataInjectionMode(boolean enable) { - return enableDataInjectionImpl(enable); + public boolean initDataInjection(boolean enable) { + return initDataInjectionImpl(enable); } /** * @hide */ - protected abstract boolean enableDataInjectionImpl(boolean enable); + protected abstract boolean initDataInjectionImpl(boolean enable); /** * For testing purposes only. Not for third party applications. * - * This method is used to inject raw sensor data into the HAL. - * Call enableDataInjection before this method to set the HAL in - * data injection mode. This method should be called only if a - * previous call to enableDataInjection has been successful and - * the HAL is already in data injection mode. - * - * The tests which call this API need to have {@code - * android.permission.LOCATION_HARDWARE} permission which isn't - * available for third party applications. + * This method is used to inject raw sensor data into the HAL. Call {@link + * initDataInjection(boolean)} before this method to set the HAL in data injection mode. This + * method should be called only if a previous call to initDataInjection has been successful and + * the HAL and SensorService are already opreating in data injection mode. * * @param sensor The sensor to inject. * @param values Sensor values to inject. The length of this @@ -1650,9 +1644,6 @@ public abstract class SensorManager { if (timestamp <= 0) { throw new IllegalArgumentException("Negative or zero sensor timestamp"); } - if (timestamp > SystemClock.elapsedRealtimeNanos()) { - throw new IllegalArgumentException("Sensor timestamp into the future"); - } return injectSensorDataImpl(sensor, values, accuracy, timestamp); } diff --git a/core/java/android/hardware/SystemSensorManager.java b/core/java/android/hardware/SystemSensorManager.java index d7960af..52e2565 100644 --- a/core/java/android/hardware/SystemSensorManager.java +++ b/core/java/android/hardware/SystemSensorManager.java @@ -43,7 +43,7 @@ public class SystemSensorManager extends SensorManager { private static native void nativeClassInit(); private static native long nativeCreate(String opPackageName); private static native int nativeGetNextSensor(long nativeInstance, Sensor sensor, int next); - private static native int nativeEnableDataInjection(long nativeInstance, boolean enable); + private static native boolean nativeIsDataInjectionEnabled(long nativeInstance); private static boolean sSensorModuleInitialized = false; private static InjectEventQueue mInjectEventQueue = null; @@ -64,7 +64,6 @@ public class SystemSensorManager extends SensorManager { private final Looper mMainLooper; private final int mTargetSdkLevel; private final Context mContext; - private final boolean mHasDataInjectionPermissions; private final long mNativeInstance; /** {@hide} */ @@ -79,8 +78,6 @@ public class SystemSensorManager extends SensorManager { sSensorModuleInitialized = true; nativeClassInit(); } - mHasDataInjectionPermissions = context.checkSelfPermission( - Manifest.permission.LOCATION_HARDWARE) == PackageManager.PERMISSION_GRANTED; } // initialize the sensor list @@ -230,23 +227,26 @@ public class SystemSensorManager extends SensorManager { } } - protected boolean enableDataInjectionImpl(boolean enable) { - if (!mHasDataInjectionPermissions) { - throw new SecurityException("Permission denial. Calling enableDataInjection without " - + Manifest.permission.LOCATION_HARDWARE); - } + protected boolean initDataInjectionImpl(boolean enable) { synchronized (mLock) { - int ret = nativeEnableDataInjection(mNativeInstance, enable); - // The HAL does not support injection. Ignore. - if (ret != 0) { - Log.e(TAG, "HAL does not support data injection"); - return false; - } - mDataInjectionMode = enable; - // If data injection is being disabled clean up the native resources. - if (!enable && mInjectEventQueue != null) { - mInjectEventQueue.dispose(); - mInjectEventQueue = null; + if (enable) { + boolean isDataInjectionModeEnabled = nativeIsDataInjectionEnabled(mNativeInstance); + // The HAL does not support injection OR SensorService hasn't been set in DI mode. + if (!isDataInjectionModeEnabled) { + Log.e(TAG, "Data Injection mode not enabled"); + return false; + } + mDataInjectionMode = true; + // Initialize a client for data_injection. + if (mInjectEventQueue == null) { + mInjectEventQueue = new InjectEventQueue(mMainLooper, this); + } + } else { + // If data injection is being disabled clean up the native resources. + if (mInjectEventQueue != null) { + mInjectEventQueue.dispose(); + mInjectEventQueue = null; + } } return true; } @@ -254,18 +254,11 @@ public class SystemSensorManager extends SensorManager { protected boolean injectSensorDataImpl(Sensor sensor, float[] values, int accuracy, long timestamp) { - if (!mHasDataInjectionPermissions) { - throw new SecurityException("Permission denial. Calling injectSensorData without " - + Manifest.permission.LOCATION_HARDWARE); - } synchronized (mLock) { if (!mDataInjectionMode) { Log.e(TAG, "Data injection mode not activated before calling injectSensorData"); return false; } - if (mInjectEventQueue == null) { - mInjectEventQueue = new InjectEventQueue(mMainLooper, this); - } int ret = mInjectEventQueue.injectSensorData(sensor.getHandle(), values, accuracy, timestamp); // If there are any errors in data injection clean up the native resources. |