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

Commit 29ad6b39 authored by Alexey Polyudov's avatar Alexey Polyudov Committed by Peng Xu
Browse files

sensors: pass sensor handle along with injected event

Change-Id: I5e8eacfa940c082a14a9876f455c55b84b975086
Merged-In: I5e8eacfa940c082a14a9876f455c55b84b975086
parent 8078996f
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -189,6 +189,16 @@ public class SensorAdditionalInfo {
     */
    public static final int TYPE_MAGNETIC_FIELD_CALIBRATION = 0x30004;

    /**
     * Custom sensor info: array of float values interpreted by sensor based on the type
     * Any type between TYPE_CUSTOM_INFO <= info_type < TYPE_DEBUG_INFO may be
     * used to send custom sensor info.
     * @hide
     */
    public static final int TYPE_CUSTOM_INFO = 0x10000000;
    /** @hide */
    public static final int TYPE_DEBUG_INFO  = 0x40000000;

    SensorAdditionalInfo(
            Sensor aSensor, int aType, int aSerial, int [] aIntValues, float [] aFloatValues) {
        sensor = aSensor;
@@ -211,4 +221,13 @@ public class SensorAdditionalInfo {
                null, TYPE_LOCAL_GEOMAGNETIC_FIELD, 0,
                null, new float[] { strength, declination, inclination});
    }
    /** @hide */
    public static SensorAdditionalInfo createCustomInfo(Sensor aSensor, int type, float [] data) {
        if (type < TYPE_CUSTOM_INFO || type >= TYPE_DEBUG_INFO || aSensor == null) {
            throw new IllegalArgumentException("invalid parameter(s): type: " + type +
                    "; sensor: " + aSensor);
        }

        return new SensorAdditionalInfo(aSensor, type, 0, null, data);
    }
}
+4 −2
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public class SystemSensorManager extends SensorManager {
            long nativeInstance, int channelHandle, int sensorHandle, int rate);

    private static native int nativeSetOperationParameter(
            long nativeInstance, int type, float[] floatValues, int[] intValues);
            long nativeInstance, int handle, int type, float[] floatValues, int[] intValues);

    private static final Object sLock = new Object();
    @GuardedBy("sLock")
@@ -956,7 +956,9 @@ public class SystemSensorManager extends SensorManager {
    }

    protected boolean setOperationParameterImpl(SensorAdditionalInfo parameter) {
        int handle = -1;
        if (parameter.sensor != null) handle = parameter.sensor.getHandle();
        return nativeSetOperationParameter(
                mNativeInstance, parameter.type, parameter.floatValues, parameter.intValues) == 0;
                mNativeInstance, handle, parameter.type, parameter.floatValues, parameter.intValues) == 0;
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -270,7 +270,7 @@ static jint nativeConfigDirectChannel(JNIEnv *_env, jclass _this, jlong sensorMa
}

static jint nativeSetOperationParameter(JNIEnv *_env, jclass _this, jlong sensorManager,
        jint type, jfloatArray floats, jintArray ints) {
        jint handle, jint type, jfloatArray floats, jintArray ints) {
    SensorManager* mgr = reinterpret_cast<SensorManager*>(sensorManager);
    Vector<float> floatVector;
    Vector<int32_t> int32Vector;
@@ -285,7 +285,7 @@ static jint nativeSetOperationParameter(JNIEnv *_env, jclass _this, jlong sensor
        _env->GetIntArrayRegion(ints, 0, _env->GetArrayLength(ints), int32Vector.editArray());
    }

    return mgr->setOperationParameter(type, floatVector, int32Vector);
    return mgr->setOperationParameter(handle, type, floatVector, int32Vector);
}

//----------------------------------------------------------------------------
@@ -512,7 +512,7 @@ static const JNINativeMethod gSystemSensorManagerMethods[] = {
            (void*)nativeConfigDirectChannel },

    {"nativeSetOperationParameter",
            "(JI[F[I)I",
            "(JII[F[I)I",
            (void*)nativeSetOperationParameter },
};