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

Commit d7ca9150 authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "Sensor: expose sensor UUID to sytem and audio users"

parents ecc388fa c4399988
Loading
Loading
Loading
Loading
+22 −12
Original line number Original line Diff line number Diff line
@@ -22,6 +22,8 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.hardware.input.InputSensorInfo;
import android.hardware.input.InputSensorInfo;
import android.os.Build;
import android.os.Build;


import java.util.UUID;

/**
/**
 * Class representing a sensor. Use {@link SensorManager#getSensorList} to get
 * Class representing a sensor. Use {@link SensorManager#getSensorList} to get
 * the list of available sensors. For more information about Android sensors,
 * the list of available sensors. For more information about Android sensors,
@@ -925,6 +927,7 @@ public final class Sensor {
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    private int     mFlags;
    private int     mFlags;
    private int     mId;
    private int     mId;
    private UUID    mUuid;


    Sensor() {
    Sensor() {
    }
    }
@@ -951,6 +954,8 @@ public final class Sensor {
        this.mMaxDelay = sensorInfo.getMaxDelay();
        this.mMaxDelay = sensorInfo.getMaxDelay();
        this.mFlags = sensorInfo.getFlags();
        this.mFlags = sensorInfo.getFlags();
        this.mId = sensorInfo.getId();
        this.mId = sensorInfo.getId();
        // The UUID is never specified when creating a sensor from Input manager
        this.mUuid = new UUID((long) this.mId, 0);
    }
    }


    /**
    /**
@@ -1040,11 +1045,9 @@ public final class Sensor {
    }
    }


    /**
    /**
     * Do not use.
     * Reserved for system and audio servers.
     *
     * When called from an unauthorized context, the UUID will contain the
     * This method throws an UnsupportedOperationException.
     * sensor ID in the MSB and 0 in the LSB.
     *
     * Use getId() if you want a unique ID.
     *
     *
     * @see getId
     * @see getId
     *
     *
@@ -1052,7 +1055,7 @@ public final class Sensor {
     */
     */
    @SystemApi
    @SystemApi
    public java.util.UUID getUuid() {
    public java.util.UUID getUuid() {
        throw new UnsupportedOperationException();
        return mUuid;
    }
    }


    /**
    /**
@@ -1286,17 +1289,24 @@ public final class Sensor {
    }
    }


    /**
    /**
     * Sets the ID associated with the sensor.
     * Sets the UUID associated with the sensor.
     *
     *
     * The method name is misleading; while this ID is based on the UUID,
     * NOTE: to be used only by native bindings in SensorManager.
     * we do not pass in the actual UUID.
     *
     * @see #getUuid
     */
    private void setUuid(long msb, long lsb) {
        mUuid = new UUID(msb, lsb);
    }

    /**
     * Sets the ID associated with the sensor.
     *
     *
     * NOTE: to be used only by native bindings in SensorManager.
     * NOTE: to be used only by native bindings in SensorManager.
     *
     *
     * @see #getId
     * @see #getId
     */
     */
    private void setUuid(long msb, long lsb) {
    private void setId(int id) {
        // TODO(b/29547335): Rename this method to setId.
        mId = id;
        mId = (int) msb;
    }
    }
}
}
+6 −3
Original line number Original line Diff line number Diff line
@@ -66,6 +66,7 @@ struct SensorOffsets
    jfieldID    flags;
    jfieldID    flags;
    //methods
    //methods
    jmethodID   setType;
    jmethodID   setType;
    jmethodID   setId;
    jmethodID   setUuid;
    jmethodID   setUuid;
    jmethodID   init;
    jmethodID   init;
} gSensorOffsets;
} gSensorOffsets;
@@ -112,6 +113,7 @@ nativeClassInit (JNIEnv *_env, jclass _this)
    sensorOffsets.flags = GetFieldIDOrDie(_env,sensorClass, "mFlags", "I");
    sensorOffsets.flags = GetFieldIDOrDie(_env,sensorClass, "mFlags", "I");


    sensorOffsets.setType = GetMethodIDOrDie(_env,sensorClass, "setType", "(I)Z");
    sensorOffsets.setType = GetMethodIDOrDie(_env,sensorClass, "setType", "(I)Z");
    sensorOffsets.setId = GetMethodIDOrDie(_env,sensorClass, "setId", "(I)V");
    sensorOffsets.setUuid = GetMethodIDOrDie(_env,sensorClass, "setUuid", "(JJ)V");
    sensorOffsets.setUuid = GetMethodIDOrDie(_env,sensorClass, "setUuid", "(JJ)V");
    sensorOffsets.init = GetMethodIDOrDie(_env,sensorClass, "<init>", "()V");
    sensorOffsets.init = GetMethodIDOrDie(_env,sensorClass, "<init>", "()V");


@@ -188,9 +190,10 @@ translateNativeSensorToJavaSensor(JNIEnv *env, jobject sensor, const Sensor& nat
            env->SetObjectField(sensor, sensorOffsets.stringType, stringType);
            env->SetObjectField(sensor, sensorOffsets.stringType, stringType);
        }
        }


        // TODO(b/29547335): Rename "setUuid" method to "setId".
        int32_t id = nativeSensor.getId();
        int64_t id = nativeSensor.getId();
        env->CallVoidMethod(sensor, sensorOffsets.setId, id);
        env->CallVoidMethod(sensor, sensorOffsets.setUuid, id, 0);
        Sensor::uuid_t uuid = nativeSensor.getUuid();
        env->CallVoidMethod(sensor, sensorOffsets.setUuid, id, uuid.i64[0], uuid.i64[1]);
    }
    }
    return sensor;
    return sensor;
}
}