summaryrefslogtreecommitdiffstats
path: root/core/java/android/hardware/SystemSensorManager.java
diff options
context:
space:
mode:
authorAravind Akella <aakella@google.com>2015-06-29 12:35:51 -0700
committerAravind Akella <aakella@google.com>2015-06-29 13:04:09 -0700
commitd123b51f8b14047804612cb1b15288cca81ed4f9 (patch)
treec0c1a2b22d5821ef3f040c221724d69f64db01d3 /core/java/android/hardware/SystemSensorManager.java
parenta1b647c8833cf85e304e3c201e7d0477b9838502 (diff)
downloadframeworks_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/android/hardware/SystemSensorManager.java')
-rw-r--r--core/java/android/hardware/SystemSensorManager.java47
1 files changed, 20 insertions, 27 deletions
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.