am b0a05404: Merge change 23223 into eclair
Merge commit 'b0a054048329c31948c2f5dbcc11b6f99e454177' into eclair-plus-aosp * commit 'b0a054048329c31948c2f5dbcc11b6f99e454177': SensorService: call close_data_source when we have no more sensor clients.
This commit is contained in:
@@ -84,12 +84,16 @@ class SensorService extends ISensorService.Stub {
|
|||||||
if (hasSensor(sensor)) {
|
if (hasSensor(sensor)) {
|
||||||
removeSensor(sensor);
|
removeSensor(sensor);
|
||||||
try {
|
try {
|
||||||
deactivateIfUnused(sensor);
|
deactivateIfUnusedLocked(sensor);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.w(TAG, "RemoteException in binderDied");
|
Log.w(TAG, "RemoteException in binderDied");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mListeners.size() == 0) {
|
||||||
|
_sensors_control_wake();
|
||||||
|
_sensors_control_close();
|
||||||
|
}
|
||||||
mListeners.notify();
|
mListeners.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,9 +106,12 @@ class SensorService extends ISensorService.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Bundle getDataChannel() throws RemoteException {
|
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)
|
public boolean enableSensor(IBinder binder, String name, int sensor, int enable)
|
||||||
throws RemoteException {
|
throws RemoteException {
|
||||||
if (localLOGV) Log.d(TAG, "enableSensor " + name + "(#" + sensor + ") " + enable);
|
if (localLOGV) Log.d(TAG, "enableSensor " + name + "(#" + sensor + ") " + enable);
|
||||||
@@ -163,7 +170,7 @@ class SensorService extends ISensorService.Stub {
|
|||||||
l.addSensor(sensor, enable);
|
l.addSensor(sensor, enable);
|
||||||
} else {
|
} else {
|
||||||
l.removeSensor(sensor);
|
l.removeSensor(sensor);
|
||||||
deactivateIfUnused(sensor);
|
deactivateIfUnusedLocked(sensor);
|
||||||
if (l.mSensors == 0) {
|
if (l.mSensors == 0) {
|
||||||
mListeners.remove(l);
|
mListeners.remove(l);
|
||||||
binder.unlinkToDeath(l, 0);
|
binder.unlinkToDeath(l, 0);
|
||||||
@@ -173,12 +180,13 @@ class SensorService extends ISensorService.Stub {
|
|||||||
|
|
||||||
if (mListeners.size() == 0) {
|
if (mListeners.size() == 0) {
|
||||||
_sensors_control_wake();
|
_sensors_control_wake();
|
||||||
|
_sensors_control_close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deactivateIfUnused(int sensor) throws RemoteException {
|
private void deactivateIfUnusedLocked(int sensor) throws RemoteException {
|
||||||
int size = mListeners.size();
|
int size = mListeners.size();
|
||||||
for (int i=0 ; i<size ; i++) {
|
for (int i=0 ; i<size ; i++) {
|
||||||
if (mListeners.get(i).hasSensor(sensor))
|
if (mListeners.get(i).hasSensor(sensor))
|
||||||
@@ -187,10 +195,11 @@ class SensorService extends ISensorService.Stub {
|
|||||||
_sensors_control_activate(sensor, false);
|
_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 int _sensors_control_init();
|
||||||
private static native Bundle _sensors_control_open();
|
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 boolean _sensors_control_activate(int sensor, boolean activate);
|
||||||
private static native int _sensors_control_set_delay(int ms);
|
private static native int _sensors_control_set_delay(int ms);
|
||||||
private static native int _sensors_control_wake();
|
private static native int _sensors_control_wake();
|
||||||
|
|||||||
@@ -111,6 +111,15 @@ android_open(JNIEnv *env, jclass clazz)
|
|||||||
return bundle;
|
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
|
static jboolean
|
||||||
android_activate(JNIEnv *env, jclass clazz, jint sensor, jboolean activate)
|
android_activate(JNIEnv *env, jclass clazz, jint sensor, jboolean activate)
|
||||||
{
|
{
|
||||||
@@ -135,6 +144,7 @@ android_data_wake(JNIEnv *env, jclass clazz)
|
|||||||
static JNINativeMethod gMethods[] = {
|
static JNINativeMethod gMethods[] = {
|
||||||
{"_sensors_control_init", "()I", (void*) android_init },
|
{"_sensors_control_init", "()I", (void*) android_init },
|
||||||
{"_sensors_control_open", "()Landroid/os/Bundle;", (void*) android_open },
|
{"_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_activate", "(IZ)Z", (void*) android_activate },
|
||||||
{"_sensors_control_wake", "()I", (void*) android_data_wake },
|
{"_sensors_control_wake", "()I", (void*) android_data_wake },
|
||||||
{"_sensors_control_set_delay","(I)I", (void*) android_set_delay },
|
{"_sensors_control_set_delay","(I)I", (void*) android_set_delay },
|
||||||
|
|||||||
Reference in New Issue
Block a user