Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5889757 authored by Aravind Akella's avatar Aravind Akella Committed by Android (Google) Code Review
Browse files

Merge "Clean up get sensorList." into mnc-dev

parents 588932a5 516e40ea
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -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) {
            if (!nativeGetSensorAtIndex(mNativeInstance, sensor, index)) break;
            mFullSensorsList.add(sensor);
            mHandleToSensor.append(sensor.getHandle(), sensor);
        }
        } while (i > 0);
    }


+9 −10
Original line number Diff line number Diff line
@@ -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",