diff options
author | Mike Lockwood <lockwood@android.com> | 2009-08-28 18:08:27 -0700 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2009-08-30 14:25:56 -0400 |
commit | 2d6b67d37f3164e53b311650aab94faabf46ef67 (patch) | |
tree | 0e0f301a837c0eb6b870b80860b6a4ba7c63a629 /services | |
parent | 56f67d21459ad3f136c73c8932904d4a495989c0 (diff) | |
download | frameworks_base-2d6b67d37f3164e53b311650aab94faabf46ef67.zip frameworks_base-2d6b67d37f3164e53b311650aab94faabf46ef67.tar.gz frameworks_base-2d6b67d37f3164e53b311650aab94faabf46ef67.tar.bz2 |
SensorService: call close_data_source when we have no more sensor clients.
Change-Id: I94accda4571c3f2cf6f8a5b6801e37c30c027fe1
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'services')
-rw-r--r-- | services/java/com/android/server/SensorService.java | 21 | ||||
-rw-r--r-- | services/jni/com_android_server_SensorService.cpp | 10 |
2 files changed, 25 insertions, 6 deletions
diff --git a/services/java/com/android/server/SensorService.java b/services/java/com/android/server/SensorService.java index ceef39f..4dfeb9d 100644 --- a/services/java/com/android/server/SensorService.java +++ b/services/java/com/android/server/SensorService.java @@ -84,12 +84,16 @@ class SensorService extends ISensorService.Stub { if (hasSensor(sensor)) { removeSensor(sensor); try { - deactivateIfUnused(sensor); + deactivateIfUnusedLocked(sensor); } catch (RemoteException e) { Log.w(TAG, "RemoteException in binderDied"); } } } + if (mListeners.size() == 0) { + _sensors_control_wake(); + _sensors_control_close(); + } mListeners.notify(); } } @@ -102,9 +106,12 @@ class SensorService extends ISensorService.Stub { } public Bundle getDataChannel() throws RemoteException { - return _sensors_control_open(); + // synchronize so we do not require sensor HAL to be thread-safe. + synchronized(mListeners) { + return _sensors_control_open(); + } } - + public boolean enableSensor(IBinder binder, String name, int sensor, int enable) throws RemoteException { if (localLOGV) Log.d(TAG, "enableSensor " + name + "(#" + sensor + ") " + enable); @@ -163,7 +170,7 @@ class SensorService extends ISensorService.Stub { l.addSensor(sensor, enable); } else { l.removeSensor(sensor); - deactivateIfUnused(sensor); + deactivateIfUnusedLocked(sensor); if (l.mSensors == 0) { mListeners.remove(l); binder.unlinkToDeath(l, 0); @@ -173,12 +180,13 @@ class SensorService extends ISensorService.Stub { if (mListeners.size() == 0) { _sensors_control_wake(); + _sensors_control_close(); } } return true; } - void deactivateIfUnused(int sensor) throws RemoteException { + private void deactivateIfUnusedLocked(int sensor) throws RemoteException { int size = mListeners.size(); for (int i=0 ; i<size ; i++) { if (mListeners.get(i).hasSensor(sensor)) @@ -187,10 +195,11 @@ class SensorService extends ISensorService.Stub { _sensors_control_activate(sensor, false); } - ArrayList<Listener> mListeners = new ArrayList<Listener>(); + private ArrayList<Listener> mListeners = new ArrayList<Listener>(); private static native int _sensors_control_init(); private static native Bundle _sensors_control_open(); + private static native int _sensors_control_close(); private static native boolean _sensors_control_activate(int sensor, boolean activate); private static native int _sensors_control_set_delay(int ms); private static native int _sensors_control_wake(); diff --git a/services/jni/com_android_server_SensorService.cpp b/services/jni/com_android_server_SensorService.cpp index 7390786..3911d1f 100644 --- a/services/jni/com_android_server_SensorService.cpp +++ b/services/jni/com_android_server_SensorService.cpp @@ -111,6 +111,15 @@ android_open(JNIEnv *env, jclass clazz) return bundle; } +static jint +android_close(JNIEnv *env, jclass clazz) +{ + if (sSensorDevice->close_data_source) + return sSensorDevice->close_data_source(sSensorDevice); + else + return 0; +} + static jboolean android_activate(JNIEnv *env, jclass clazz, jint sensor, jboolean activate) { @@ -135,6 +144,7 @@ android_data_wake(JNIEnv *env, jclass clazz) static JNINativeMethod gMethods[] = { {"_sensors_control_init", "()I", (void*) android_init }, {"_sensors_control_open", "()Landroid/os/Bundle;", (void*) android_open }, + {"_sensors_control_close", "()I", (void*) android_close }, {"_sensors_control_activate", "(IZ)Z", (void*) android_activate }, {"_sensors_control_wake", "()I", (void*) android_data_wake }, {"_sensors_control_set_delay","(I)I", (void*) android_set_delay }, |