am 32207e3c: Merge "Changes to Data Injection mode APIs" into mnc-dev

* commit '32207e3c66f9b7979a6d465b87eb531327916081':
  Changes to Data Injection mode APIs
This commit is contained in:
Aravind Akella
2015-07-02 00:36:35 +00:00
committed by Android Git Automerger
4 changed files with 45 additions and 63 deletions

View File

@@ -13421,7 +13421,6 @@ package android.hardware {
public abstract class SensorManager { public abstract class SensorManager {
method public boolean cancelTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor); method public boolean cancelTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor);
method public boolean enableDataInjectionMode(boolean);
method public boolean flush(android.hardware.SensorEventListener); method public boolean flush(android.hardware.SensorEventListener);
method public static float getAltitude(float, float); method public static float getAltitude(float, float);
method public static void getAngleChange(float[], float[], float[]); method public static void getAngleChange(float[], float[], float[]);
@@ -13434,6 +13433,7 @@ package android.hardware {
method public static void getRotationMatrixFromVector(float[], float[]); method public static void getRotationMatrixFromVector(float[], float[]);
method public java.util.List<android.hardware.Sensor> getSensorList(int); method public java.util.List<android.hardware.Sensor> getSensorList(int);
method public deprecated int getSensors(); method public deprecated int getSensors();
method public boolean initDataInjection(boolean);
method public boolean injectSensorData(android.hardware.Sensor, float[], int, long); method public boolean injectSensorData(android.hardware.Sensor, float[], int, long);
method public deprecated boolean registerListener(android.hardware.SensorListener, int); method public deprecated boolean registerListener(android.hardware.SensorListener, int);
method public deprecated boolean registerListener(android.hardware.SensorListener, int, int); method public deprecated boolean registerListener(android.hardware.SensorListener, int, int);

View File

@@ -1568,47 +1568,41 @@ public abstract class SensorManager {
/** /**
* For testing purposes only. Not for third party applications. * For testing purposes only. Not for third party applications.
* *
* Enable data injection mode in sensor service. This mode is * Initialize data injection mode and create a client for data injection. SensorService should
* expected to be used only for testing purposes. If the HAL is * already be operating in DATA_INJECTION mode for this call succeed. To set SensorService into
* set to data injection mode, it will ignore the input from * DATA_INJECTION mode "adb shell dumpsys sensorservice data_injection" needs to be called
* physical sensors and read sensor data that is injected from * through adb. Typically this is done using a host side test. This mode is expected to be used
* the test application. This mode is used for testing vendor * only for testing purposes. If the HAL is set to data injection mode, it will ignore the input
* implementations for various algorithms like Rotation Vector, * from physical sensors and read sensor data that is injected from the test application. This
* Significant Motion, Step Counter etc. * 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.
* *
* The tests which call this API need to have {@code * @param enable True to initialize a client in DATA_INJECTION mode.
* android.permission.LOCATION_HADWARE} permission which isn't * False to clean up the native resources.
* 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.
* *
* @return true if the HAL supports data injection and false * @return true if the HAL supports data injection and false
* otherwise. * otherwise.
* @hide * @hide
*/ */
@SystemApi @SystemApi
public boolean enableDataInjectionMode(boolean enable) { public boolean initDataInjection(boolean enable) {
return enableDataInjectionImpl(enable); return initDataInjectionImpl(enable);
} }
/** /**
* @hide * @hide
*/ */
protected abstract boolean enableDataInjectionImpl(boolean enable); protected abstract boolean initDataInjectionImpl(boolean enable);
/** /**
* For testing purposes only. Not for third party applications. * For testing purposes only. Not for third party applications.
* *
* This method is used to inject raw sensor data into the HAL. * This method is used to inject raw sensor data into the HAL. Call {@link
* Call enableDataInjection before this method to set the HAL in * initDataInjection(boolean)} before this method to set the HAL in data injection mode. This
* data injection mode. This method should be called only if a * method should be called only if a previous call to initDataInjection has been successful and
* previous call to enableDataInjection has been successful and * the HAL and SensorService are already opreating in data injection mode.
* 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.
* *
* @param sensor The sensor to inject. * @param sensor The sensor to inject.
* @param values Sensor values to inject. The length of this * @param values Sensor values to inject. The length of this
@@ -1650,9 +1644,6 @@ public abstract class SensorManager {
if (timestamp <= 0) { if (timestamp <= 0) {
throw new IllegalArgumentException("Negative or zero sensor timestamp"); 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); return injectSensorDataImpl(sensor, values, accuracy, timestamp);
} }

View File

@@ -43,7 +43,7 @@ public class SystemSensorManager extends SensorManager {
private static native void nativeClassInit(); private static native void nativeClassInit();
private static native long nativeCreate(String opPackageName); private static native long nativeCreate(String opPackageName);
private static native int nativeGetNextSensor(long nativeInstance, Sensor sensor, int next); 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 boolean sSensorModuleInitialized = false;
private static InjectEventQueue mInjectEventQueue = null; private static InjectEventQueue mInjectEventQueue = null;
@@ -64,7 +64,6 @@ public class SystemSensorManager extends SensorManager {
private final Looper mMainLooper; private final Looper mMainLooper;
private final int mTargetSdkLevel; private final int mTargetSdkLevel;
private final Context mContext; private final Context mContext;
private final boolean mHasDataInjectionPermissions;
private final long mNativeInstance; private final long mNativeInstance;
/** {@hide} */ /** {@hide} */
@@ -79,8 +78,6 @@ public class SystemSensorManager extends SensorManager {
sSensorModuleInitialized = true; sSensorModuleInitialized = true;
nativeClassInit(); nativeClassInit();
} }
mHasDataInjectionPermissions = context.checkSelfPermission(
Manifest.permission.LOCATION_HARDWARE) == PackageManager.PERMISSION_GRANTED;
} }
// initialize the sensor list // initialize the sensor list
@@ -230,23 +227,26 @@ public class SystemSensorManager extends SensorManager {
} }
} }
protected boolean enableDataInjectionImpl(boolean enable) { protected boolean initDataInjectionImpl(boolean enable) {
if (!mHasDataInjectionPermissions) {
throw new SecurityException("Permission denial. Calling enableDataInjection without "
+ Manifest.permission.LOCATION_HARDWARE);
}
synchronized (mLock) { synchronized (mLock) {
int ret = nativeEnableDataInjection(mNativeInstance, enable); if (enable) {
// The HAL does not support injection. Ignore. boolean isDataInjectionModeEnabled = nativeIsDataInjectionEnabled(mNativeInstance);
if (ret != 0) { // The HAL does not support injection OR SensorService hasn't been set in DI mode.
Log.e(TAG, "HAL does not support data injection"); if (!isDataInjectionModeEnabled) {
return false; Log.e(TAG, "Data Injection mode not enabled");
} return false;
mDataInjectionMode = enable; }
// If data injection is being disabled clean up the native resources. mDataInjectionMode = true;
if (!enable && mInjectEventQueue != null) { // Initialize a client for data_injection.
mInjectEventQueue.dispose(); if (mInjectEventQueue == null) {
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; return true;
} }
@@ -254,18 +254,11 @@ public class SystemSensorManager extends SensorManager {
protected boolean injectSensorDataImpl(Sensor sensor, float[] values, int accuracy, protected boolean injectSensorDataImpl(Sensor sensor, float[] values, int accuracy,
long timestamp) { long timestamp) {
if (!mHasDataInjectionPermissions) {
throw new SecurityException("Permission denial. Calling injectSensorData without "
+ Manifest.permission.LOCATION_HARDWARE);
}
synchronized (mLock) { synchronized (mLock) {
if (!mDataInjectionMode) { if (!mDataInjectionMode) {
Log.e(TAG, "Data injection mode not activated before calling injectSensorData"); Log.e(TAG, "Data injection mode not activated before calling injectSensorData");
return false; return false;
} }
if (mInjectEventQueue == null) {
mInjectEventQueue = new InjectEventQueue(mMainLooper, this);
}
int ret = mInjectEventQueue.injectSensorData(sensor.getHandle(), values, accuracy, int ret = mInjectEventQueue.injectSensorData(sensor.getHandle(), values, accuracy,
timestamp); timestamp);
// If there are any errors in data injection clean up the native resources. // If there are any errors in data injection clean up the native resources.

View File

@@ -130,7 +130,6 @@ getInternedString(JNIEnv *env, const String8* string) {
internedStrings.insert(std::make_pair(string, internedString)); internedStrings.insert(std::make_pair(string, internedString));
env->DeleteLocalRef(localString); env->DeleteLocalRef(localString);
} }
return internedString; return internedString;
} }
@@ -182,10 +181,9 @@ nativeGetNextSensor(JNIEnv *env, jclass clazz, jlong sensorManager, jobject sens
return size_t(next) < count ? next : 0; return size_t(next) < count ? next : 0;
} }
static int nativeEnableDataInjection(JNIEnv *_env, jclass _this, jlong sensorManager, static jboolean nativeIsDataInjectionEnabled(JNIEnv *_env, jclass _this, jlong sensorManager) {
jboolean enable) {
SensorManager* mgr = reinterpret_cast<SensorManager*>(sensorManager); SensorManager* mgr = reinterpret_cast<SensorManager*>(sensorManager);
return mgr->enableDataInjection(enable); return mgr->isDataInjectionEnabled();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@@ -358,9 +356,9 @@ static JNINativeMethod gSystemSensorManagerMethods[] = {
"(JLandroid/hardware/Sensor;I)I", "(JLandroid/hardware/Sensor;I)I",
(void*)nativeGetNextSensor }, (void*)nativeGetNextSensor },
{"nativeEnableDataInjection", {"nativeIsDataInjectionEnabled",
"(JZ)I", "(J)Z",
(void*)nativeEnableDataInjection }, (void*)nativeIsDataInjectionEnabled},
}; };
static JNINativeMethod gBaseEventQueueMethods[] = { static JNINativeMethod gBaseEventQueueMethods[] = {