Merge "Changes to Data Injection mode APIs" into mnc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
32207e3c66
@@ -13421,7 +13421,6 @@ package android.hardware {
|
||||
|
||||
public abstract class SensorManager {
|
||||
method public boolean cancelTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor);
|
||||
method public boolean enableDataInjectionMode(boolean);
|
||||
method public boolean flush(android.hardware.SensorEventListener);
|
||||
method public static float getAltitude(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 java.util.List<android.hardware.Sensor> getSensorList(int);
|
||||
method public deprecated int getSensors();
|
||||
method public boolean initDataInjection(boolean);
|
||||
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, int);
|
||||
|
||||
@@ -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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -130,7 +130,6 @@ getInternedString(JNIEnv *env, const String8* string) {
|
||||
internedStrings.insert(std::make_pair(string, internedString));
|
||||
env->DeleteLocalRef(localString);
|
||||
}
|
||||
|
||||
return internedString;
|
||||
}
|
||||
|
||||
@@ -182,10 +181,9 @@ nativeGetNextSensor(JNIEnv *env, jclass clazz, jlong sensorManager, jobject sens
|
||||
return size_t(next) < count ? next : 0;
|
||||
}
|
||||
|
||||
static int nativeEnableDataInjection(JNIEnv *_env, jclass _this, jlong sensorManager,
|
||||
jboolean enable) {
|
||||
static jboolean nativeIsDataInjectionEnabled(JNIEnv *_env, jclass _this, jlong 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",
|
||||
(void*)nativeGetNextSensor },
|
||||
|
||||
{"nativeEnableDataInjection",
|
||||
"(JZ)I",
|
||||
(void*)nativeEnableDataInjection },
|
||||
{"nativeIsDataInjectionEnabled",
|
||||
"(J)Z",
|
||||
(void*)nativeIsDataInjectionEnabled},
|
||||
};
|
||||
|
||||
static JNINativeMethod gBaseEventQueueMethods[] = {
|
||||
|
||||
Reference in New Issue
Block a user