Loading core/java/android/hardware/Sensor.java +22 −12 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ import android.compat.annotation.UnsupportedAppUsage; import android.hardware.input.InputSensorInfo; import android.os.Build; import java.util.UUID; /** * Class representing a sensor. Use {@link SensorManager#getSensorList} to get * the list of available sensors. For more information about Android sensors, Loading Loading @@ -925,6 +927,7 @@ public final class Sensor { @UnsupportedAppUsage private int mFlags; private int mId; private UUID mUuid; Sensor() { } Loading @@ -951,6 +954,8 @@ public final class Sensor { this.mMaxDelay = sensorInfo.getMaxDelay(); this.mFlags = sensorInfo.getFlags(); this.mId = sensorInfo.getId(); // The UUID is never specified when creating a sensor from Input manager this.mUuid = new UUID((long) this.mId, 0); } /** Loading Loading @@ -1040,11 +1045,9 @@ public final class Sensor { } /** * Do not use. * * This method throws an UnsupportedOperationException. * * Use getId() if you want a unique ID. * Reserved for system and audio servers. * When called from an unauthorized context, the UUID will contain the * sensor ID in the MSB and 0 in the LSB. * * @see getId * Loading @@ -1052,7 +1055,7 @@ public final class Sensor { */ @SystemApi public java.util.UUID getUuid() { throw new UnsupportedOperationException(); return mUuid; } /** Loading Loading @@ -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, * we do not pass in the actual UUID. * NOTE: to be used only by native bindings in SensorManager. * * @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. * * @see #getId */ private void setUuid(long msb, long lsb) { // TODO(b/29547335): Rename this method to setId. mId = (int) msb; private void setId(int id) { mId = id; } } core/jni/android_hardware_SensorManager.cpp +6 −3 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ struct SensorOffsets jfieldID flags; //methods jmethodID setType; jmethodID setId; jmethodID setUuid; jmethodID init; } gSensorOffsets; Loading Loading @@ -112,6 +113,7 @@ nativeClassInit (JNIEnv *_env, jclass _this) sensorOffsets.flags = GetFieldIDOrDie(_env,sensorClass, "mFlags", "I"); 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.init = GetMethodIDOrDie(_env,sensorClass, "<init>", "()V"); Loading Loading @@ -188,9 +190,10 @@ translateNativeSensorToJavaSensor(JNIEnv *env, jobject sensor, const Sensor& nat env->SetObjectField(sensor, sensorOffsets.stringType, stringType); } // TODO(b/29547335): Rename "setUuid" method to "setId". int64_t id = nativeSensor.getId(); env->CallVoidMethod(sensor, sensorOffsets.setUuid, id, 0); int32_t id = nativeSensor.getId(); env->CallVoidMethod(sensor, sensorOffsets.setId, id); Sensor::uuid_t uuid = nativeSensor.getUuid(); env->CallVoidMethod(sensor, sensorOffsets.setUuid, id, uuid.i64[0], uuid.i64[1]); } return sensor; } Loading Loading
core/java/android/hardware/Sensor.java +22 −12 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ import android.compat.annotation.UnsupportedAppUsage; import android.hardware.input.InputSensorInfo; import android.os.Build; import java.util.UUID; /** * Class representing a sensor. Use {@link SensorManager#getSensorList} to get * the list of available sensors. For more information about Android sensors, Loading Loading @@ -925,6 +927,7 @@ public final class Sensor { @UnsupportedAppUsage private int mFlags; private int mId; private UUID mUuid; Sensor() { } Loading @@ -951,6 +954,8 @@ public final class Sensor { this.mMaxDelay = sensorInfo.getMaxDelay(); this.mFlags = sensorInfo.getFlags(); this.mId = sensorInfo.getId(); // The UUID is never specified when creating a sensor from Input manager this.mUuid = new UUID((long) this.mId, 0); } /** Loading Loading @@ -1040,11 +1045,9 @@ public final class Sensor { } /** * Do not use. * * This method throws an UnsupportedOperationException. * * Use getId() if you want a unique ID. * Reserved for system and audio servers. * When called from an unauthorized context, the UUID will contain the * sensor ID in the MSB and 0 in the LSB. * * @see getId * Loading @@ -1052,7 +1055,7 @@ public final class Sensor { */ @SystemApi public java.util.UUID getUuid() { throw new UnsupportedOperationException(); return mUuid; } /** Loading Loading @@ -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, * we do not pass in the actual UUID. * NOTE: to be used only by native bindings in SensorManager. * * @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. * * @see #getId */ private void setUuid(long msb, long lsb) { // TODO(b/29547335): Rename this method to setId. mId = (int) msb; private void setId(int id) { mId = id; } }
core/jni/android_hardware_SensorManager.cpp +6 −3 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ struct SensorOffsets jfieldID flags; //methods jmethodID setType; jmethodID setId; jmethodID setUuid; jmethodID init; } gSensorOffsets; Loading Loading @@ -112,6 +113,7 @@ nativeClassInit (JNIEnv *_env, jclass _this) sensorOffsets.flags = GetFieldIDOrDie(_env,sensorClass, "mFlags", "I"); 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.init = GetMethodIDOrDie(_env,sensorClass, "<init>", "()V"); Loading Loading @@ -188,9 +190,10 @@ translateNativeSensorToJavaSensor(JNIEnv *env, jobject sensor, const Sensor& nat env->SetObjectField(sensor, sensorOffsets.stringType, stringType); } // TODO(b/29547335): Rename "setUuid" method to "setId". int64_t id = nativeSensor.getId(); env->CallVoidMethod(sensor, sensorOffsets.setUuid, id, 0); int32_t id = nativeSensor.getId(); env->CallVoidMethod(sensor, sensorOffsets.setId, id); Sensor::uuid_t uuid = nativeSensor.getUuid(); env->CallVoidMethod(sensor, sensorOffsets.setUuid, id, uuid.i64[0], uuid.i64[1]); } return sensor; } Loading