Merge "Clean up get sensorList." into mnc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c5889757cb
@@ -42,7 +42,8 @@ import java.util.List;
|
||||
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 boolean nativeGetSensorAtIndex(long nativeInstance,
|
||||
Sensor sensor, int index);
|
||||
private static native boolean nativeIsDataInjectionEnabled(long nativeInstance);
|
||||
|
||||
private static boolean sSensorModuleInitialized = false;
|
||||
@@ -80,15 +81,12 @@ public class SystemSensorManager extends SensorManager {
|
||||
}
|
||||
|
||||
// initialize the sensor list
|
||||
int i = 0;
|
||||
do {
|
||||
for (int index = 0;;++index) {
|
||||
Sensor sensor = new Sensor();
|
||||
i = nativeGetNextSensor(mNativeInstance, sensor, i);
|
||||
if (i >= 0) {
|
||||
mFullSensorsList.add(sensor);
|
||||
mHandleToSensor.append(sensor.getHandle(), sensor);
|
||||
}
|
||||
} while (i > 0);
|
||||
if (!nativeGetSensorAtIndex(mNativeInstance, sensor, index)) break;
|
||||
mFullSensorsList.add(sensor);
|
||||
mHandleToSensor.append(sensor.getHandle(), sensor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -141,18 +141,18 @@ nativeCreate
|
||||
return (jlong) new SensorManager(String16(opPackageNameUtf.c_str()));
|
||||
}
|
||||
|
||||
static jint
|
||||
nativeGetNextSensor(JNIEnv *env, jclass clazz, jlong sensorManager, jobject sensor, jint next)
|
||||
static jboolean
|
||||
nativeGetSensorAtIndex(JNIEnv *env, jclass clazz, jlong sensorManager, jobject sensor, jint index)
|
||||
{
|
||||
SensorManager* mgr = reinterpret_cast<SensorManager*>(sensorManager);
|
||||
|
||||
Sensor const* const* sensorList;
|
||||
size_t count = mgr->getSensorList(&sensorList);
|
||||
if (size_t(next) >= count) {
|
||||
return -1;
|
||||
if (size_t(index) >= count) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Sensor const* const list = sensorList[next];
|
||||
Sensor const* const list = sensorList[index];
|
||||
const SensorOffsets& sensorOffsets(gSensorOffsets);
|
||||
jstring name = getInternedString(env, &list->getName());
|
||||
jstring vendor = getInternedString(env, &list->getVendor());
|
||||
@@ -177,8 +177,7 @@ nativeGetNextSensor(JNIEnv *env, jclass clazz, jlong sensorManager, jobject sens
|
||||
jstring stringType = getInternedString(env, &list->getStringType());
|
||||
env->SetObjectField(sensor, sensorOffsets.stringType, stringType);
|
||||
}
|
||||
next++;
|
||||
return size_t(next) < count ? next : 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static jboolean nativeIsDataInjectionEnabled(JNIEnv *_env, jclass _this, jlong sensorManager) {
|
||||
@@ -352,9 +351,9 @@ static JNINativeMethod gSystemSensorManagerMethods[] = {
|
||||
"(Ljava/lang/String;)J",
|
||||
(void*)nativeCreate },
|
||||
|
||||
{"nativeGetNextSensor",
|
||||
"(JLandroid/hardware/Sensor;I)I",
|
||||
(void*)nativeGetNextSensor },
|
||||
{"nativeGetSensorAtIndex",
|
||||
"(JLandroid/hardware/Sensor;I)Z",
|
||||
(void*)nativeGetSensorAtIndex },
|
||||
|
||||
{"nativeIsDataInjectionEnabled",
|
||||
"(J)Z",
|
||||
|
||||
Reference in New Issue
Block a user