summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/api/system-current.txt10
-rw-r--r--core/java/android/companion/virtual/sensor/VirtualSensorConfig.java120
-rw-r--r--services/companion/java/com/android/server/companion/virtual/SensorController.java5
-rw-r--r--services/core/java/com/android/server/sensors/SensorManagerInternal.java3
-rw-r--r--services/core/java/com/android/server/sensors/SensorService.java10
-rw-r--r--services/core/jni/com_android_server_sensor_SensorService.cpp22
-rw-r--r--services/tests/servicestests/src/com/android/server/companion/virtual/SensorControllerTest.java7
-rw-r--r--services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java3
8 files changed, 163 insertions, 17 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 4ed7b5c61321..b4760074d676 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -3333,7 +3333,12 @@ package android.companion.virtual.sensor {
method public int describeContents();
method public int getDirectChannelTypesSupported();
method public int getHighestDirectReportRateLevel();
+ method public int getMaxDelay();
+ method public float getMaximumRange();
+ method public int getMinDelay();
method @NonNull public String getName();
+ method public float getPower();
+ method public float getResolution();
method public int getType();
method @Nullable public String getVendor();
method public void writeToParcel(@NonNull android.os.Parcel, int);
@@ -3345,6 +3350,11 @@ package android.companion.virtual.sensor {
method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig build();
method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setDirectChannelTypesSupported(int);
method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setHighestDirectReportRateLevel(int);
+ method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setMaxDelay(int);
+ method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setMaximumRange(float);
+ method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setMinDelay(int);
+ method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setPower(float);
+ method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setResolution(float);
method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setVendor(@Nullable String);
}
diff --git a/core/java/android/companion/virtual/sensor/VirtualSensorConfig.java b/core/java/android/companion/virtual/sensor/VirtualSensorConfig.java
index 401e754abca6..ef55ca97585d 100644
--- a/core/java/android/companion/virtual/sensor/VirtualSensorConfig.java
+++ b/core/java/android/companion/virtual/sensor/VirtualSensorConfig.java
@@ -50,14 +50,25 @@ public final class VirtualSensorConfig implements Parcelable {
private final String mName;
@Nullable
private final String mVendor;
+ private final float mMaximumRange;
+ private final float mResolution;
+ private final float mPower;
+ private final int mMinDelay;
+ private final int mMaxDelay;
private final int mFlags;
private VirtualSensorConfig(int type, @NonNull String name, @Nullable String vendor,
+ float maximumRange, float resolution, float power, int minDelay, int maxDelay,
int flags) {
mType = type;
mName = name;
mVendor = vendor;
+ mMaximumRange = maximumRange;
+ mResolution = resolution;
+ mPower = power;
+ mMinDelay = minDelay;
+ mMaxDelay = maxDelay;
mFlags = flags;
}
@@ -65,6 +76,11 @@ public final class VirtualSensorConfig implements Parcelable {
mType = parcel.readInt();
mName = parcel.readString8();
mVendor = parcel.readString8();
+ mMaximumRange = parcel.readFloat();
+ mResolution = parcel.readFloat();
+ mPower = parcel.readFloat();
+ mMinDelay = parcel.readInt();
+ mMaxDelay = parcel.readInt();
mFlags = parcel.readInt();
}
@@ -78,6 +94,11 @@ public final class VirtualSensorConfig implements Parcelable {
parcel.writeInt(mType);
parcel.writeString8(mName);
parcel.writeString8(mVendor);
+ parcel.writeFloat(mMaximumRange);
+ parcel.writeFloat(mResolution);
+ parcel.writeFloat(mPower);
+ parcel.writeInt(mMinDelay);
+ parcel.writeInt(mMaxDelay);
parcel.writeInt(mFlags);
}
@@ -109,6 +130,47 @@ public final class VirtualSensorConfig implements Parcelable {
}
/**
+ * Returns maximum range of the sensor in the sensor's unit.
+ * @see Sensor#getMaximumRange
+ */
+ public float getMaximumRange() {
+ return mMaximumRange;
+ }
+
+ /**
+ * Returns The resolution of the sensor in the sensor's unit.
+ * @see Sensor#getResolution
+ */
+ public float getResolution() {
+ return mResolution;
+ }
+
+ /**
+ * Returns The power in mA used by this sensor while in use.
+ * @see Sensor#getPower
+ */
+ public float getPower() {
+ return mPower;
+ }
+
+ /**
+ * Returns The minimum delay allowed between two events in microseconds, or zero depending on
+ * the sensor type.
+ * @see Sensor#getMinDelay
+ */
+ public int getMinDelay() {
+ return mMinDelay;
+ }
+
+ /**
+ * Returns The maximum delay between two sensor events in microseconds.
+ * @see Sensor#getMaxDelay
+ */
+ public int getMaxDelay() {
+ return mMaxDelay;
+ }
+
+ /**
* Returns the highest supported direct report mode rate level of the sensor.
*
* @see Sensor#getHighestDirectReportRateLevel()
@@ -157,6 +219,11 @@ public final class VirtualSensorConfig implements Parcelable {
private final String mName;
@Nullable
private String mVendor;
+ private float mMaximumRange;
+ private float mResolution;
+ private float mPower;
+ private int mMinDelay;
+ private int mMaxDelay;
private int mFlags;
@SensorDirectChannel.RateLevel
int mHighestDirectReportRateLevel;
@@ -193,7 +260,8 @@ public final class VirtualSensorConfig implements Parcelable {
throw new IllegalArgumentException("Highest direct report rate level is "
+ "required for sensors with direct channel support.");
}
- return new VirtualSensorConfig(mType, mName, mVendor, mFlags);
+ return new VirtualSensorConfig(mType, mName, mVendor, mMaximumRange, mResolution,
+ mPower, mMinDelay, mMaxDelay, mFlags);
}
/**
@@ -206,6 +274,56 @@ public final class VirtualSensorConfig implements Parcelable {
}
/**
+ * Sets the maximum range of the sensor in the sensor's unit.
+ * @see Sensor#getMaximumRange
+ */
+ @NonNull
+ public VirtualSensorConfig.Builder setMaximumRange(float maximumRange) {
+ mMaximumRange = maximumRange;
+ return this;
+ }
+
+ /**
+ * Sets the resolution of the sensor in the sensor's unit.
+ * @see Sensor#getResolution
+ */
+ @NonNull
+ public VirtualSensorConfig.Builder setResolution(float resolution) {
+ mResolution = resolution;
+ return this;
+ }
+
+ /**
+ * Sets the power in mA used by this sensor while in use.
+ * @see Sensor#getPower
+ */
+ @NonNull
+ public VirtualSensorConfig.Builder setPower(float power) {
+ mPower = power;
+ return this;
+ }
+
+ /**
+ * Sets the minimum delay allowed between two events in microseconds.
+ * @see Sensor#getMinDelay
+ */
+ @NonNull
+ public VirtualSensorConfig.Builder setMinDelay(int minDelay) {
+ mMinDelay = minDelay;
+ return this;
+ }
+
+ /**
+ * Sets the maximum delay between two sensor events in microseconds.
+ * @see Sensor#getMaxDelay
+ */
+ @NonNull
+ public VirtualSensorConfig.Builder setMaxDelay(int maxDelay) {
+ mMaxDelay = maxDelay;
+ return this;
+ }
+
+ /**
* Sets the highest supported rate level for direct sensor report.
*
* @see VirtualSensorConfig#getHighestDirectReportRateLevel()
diff --git a/services/companion/java/com/android/server/companion/virtual/SensorController.java b/services/companion/java/com/android/server/companion/virtual/SensorController.java
index 7df0d861dc22..6d198de98490 100644
--- a/services/companion/java/com/android/server/companion/virtual/SensorController.java
+++ b/services/companion/java/com/android/server/companion/virtual/SensorController.java
@@ -104,8 +104,9 @@ public class SensorController {
}
final int handle = mSensorManagerInternal.createRuntimeSensor(mVirtualDeviceId,
config.getType(), config.getName(),
- config.getVendor() == null ? "" : config.getVendor(), config.getFlags(),
- mRuntimeSensorCallback);
+ config.getVendor() == null ? "" : config.getVendor(), config.getMaximumRange(),
+ config.getResolution(), config.getPower(), config.getMinDelay(),
+ config.getMaxDelay(), config.getFlags(), mRuntimeSensorCallback);
if (handle <= 0) {
throw new SensorCreationException("Received an invalid virtual sensor handle.");
}
diff --git a/services/core/java/com/android/server/sensors/SensorManagerInternal.java b/services/core/java/com/android/server/sensors/SensorManagerInternal.java
index 6c32ec2e8df8..7ff4ade1101c 100644
--- a/services/core/java/com/android/server/sensors/SensorManagerInternal.java
+++ b/services/core/java/com/android/server/sensors/SensorManagerInternal.java
@@ -60,7 +60,8 @@ public abstract class SensorManagerInternal {
* @return The sensor handle.
*/
public abstract int createRuntimeSensor(int deviceId, int type, @NonNull String name,
- @NonNull String vendor, int flags, @NonNull RuntimeSensorCallback callback);
+ @NonNull String vendor, float maximumRange, float resolution, float power,
+ int minDelay, int maxDelay, int flags, @NonNull RuntimeSensorCallback callback);
/**
* Unregisters the sensor with the given handle from the framework.
diff --git a/services/core/java/com/android/server/sensors/SensorService.java b/services/core/java/com/android/server/sensors/SensorService.java
index 1baa0a6d79a1..3de191030d71 100644
--- a/services/core/java/com/android/server/sensors/SensorService.java
+++ b/services/core/java/com/android/server/sensors/SensorService.java
@@ -56,7 +56,8 @@ public class SensorService extends SystemService {
private static native void unregisterProximityActiveListenerNative(long ptr);
private static native int registerRuntimeSensorNative(long ptr, int deviceId, int type,
- String name, String vendor, int flags,
+ String name, String vendor, float maximumRange, float resolution, float power,
+ int minDelay, int maxDelay, int flags,
SensorManagerInternal.RuntimeSensorCallback callback);
private static native void unregisterRuntimeSensorNative(long ptr, int handle);
private static native boolean sendRuntimeSensorEventNative(long ptr, int handle, int type,
@@ -96,10 +97,11 @@ public class SensorService extends SystemService {
class LocalService extends SensorManagerInternal {
@Override
public int createRuntimeSensor(int deviceId, int type, @NonNull String name,
- @NonNull String vendor, int flags, @NonNull RuntimeSensorCallback callback) {
+ @NonNull String vendor, float maximumRange, float resolution, float power,
+ int minDelay, int maxDelay, int flags, @NonNull RuntimeSensorCallback callback) {
synchronized (mLock) {
- int handle = registerRuntimeSensorNative(mPtr, deviceId, type, name, vendor, flags,
- callback);
+ int handle = registerRuntimeSensorNative(mPtr, deviceId, type, name, vendor,
+ maximumRange, resolution, power, minDelay, maxDelay, flags, callback);
mRuntimeSensorHandles.add(handle);
return handle;
}
diff --git a/services/core/jni/com_android_server_sensor_SensorService.cpp b/services/core/jni/com_android_server_sensor_SensorService.cpp
index a916b64fc0bd..eb729de6afd4 100644
--- a/services/core/jni/com_android_server_sensor_SensorService.cpp
+++ b/services/core/jni/com_android_server_sensor_SensorService.cpp
@@ -55,7 +55,8 @@ public:
void registerProximityActiveListener();
void unregisterProximityActiveListener();
jint registerRuntimeSensor(JNIEnv* env, jint deviceId, jint type, jstring name, jstring vendor,
- jint flags, jobject callback);
+ jfloat maximumRange, jfloat resolution, jfloat power, jint minDelay,
+ jint maxDelay, jint flags, jobject callback);
void unregisterRuntimeSensor(jint handle);
jboolean sendRuntimeSensorEvent(JNIEnv* env, jint handle, jint type, jlong timestamp,
jfloatArray values);
@@ -119,7 +120,9 @@ void NativeSensorService::unregisterProximityActiveListener() {
}
jint NativeSensorService::registerRuntimeSensor(JNIEnv* env, jint deviceId, jint type, jstring name,
- jstring vendor, jint flags, jobject callback) {
+ jstring vendor, jfloat maximumRange,
+ jfloat resolution, jfloat power, jint minDelay,
+ jint maxDelay, jint flags, jobject callback) {
if (mService == nullptr) {
ALOGD("Dropping registerRuntimeSensor, sensor service not available.");
return -1;
@@ -130,6 +133,11 @@ jint NativeSensorService::registerRuntimeSensor(JNIEnv* env, jint deviceId, jint
.vendor = env->GetStringUTFChars(vendor, 0),
.version = sizeof(sensor_t),
.type = type,
+ .maxRange = maximumRange,
+ .resolution = resolution,
+ .power = power,
+ .minDelay = minDelay,
+ .maxDelay = maxDelay,
#ifdef __LP64__
.flags = static_cast<uint64_t>(flags),
#else
@@ -299,10 +307,12 @@ static void unregisterProximityActiveListenerNative(JNIEnv* env, jclass, jlong p
}
static jint registerRuntimeSensorNative(JNIEnv* env, jclass, jlong ptr, jint deviceId, jint type,
- jstring name, jstring vendor, jint flags,
- jobject callback) {
+ jstring name, jstring vendor, jfloat maximumRange,
+ jfloat resolution, jfloat power, jint minDelay,
+ jint maxDelay, jint flags, jobject callback) {
auto* service = reinterpret_cast<NativeSensorService*>(ptr);
- return service->registerRuntimeSensor(env, deviceId, type, name, vendor, flags, callback);
+ return service->registerRuntimeSensor(env, deviceId, type, name, vendor, maximumRange,
+ resolution, power, minDelay, maxDelay, flags, callback);
}
static void unregisterRuntimeSensorNative(JNIEnv* env, jclass, jlong ptr, jint handle) {
@@ -324,7 +334,7 @@ static const JNINativeMethod methods[] = {
{"unregisterProximityActiveListenerNative", "(J)V",
reinterpret_cast<void*>(unregisterProximityActiveListenerNative)},
{"registerRuntimeSensorNative",
- "(JIILjava/lang/String;Ljava/lang/String;IL" RUNTIME_SENSOR_CALLBACK_CLASS ";)I",
+ "(JIILjava/lang/String;Ljava/lang/String;FFFIIIL" RUNTIME_SENSOR_CALLBACK_CLASS ";)I",
reinterpret_cast<void*>(registerRuntimeSensorNative)},
{"unregisterRuntimeSensorNative", "(JI)V",
reinterpret_cast<void*>(unregisterRuntimeSensorNative)},
diff --git a/services/tests/servicestests/src/com/android/server/companion/virtual/SensorControllerTest.java b/services/tests/servicestests/src/com/android/server/companion/virtual/SensorControllerTest.java
index 1259d7189a6d..aea8b8658984 100644
--- a/services/tests/servicestests/src/com/android/server/companion/virtual/SensorControllerTest.java
+++ b/services/tests/servicestests/src/com/android/server/companion/virtual/SensorControllerTest.java
@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
@@ -81,7 +82,8 @@ public class SensorControllerTest {
@Test
public void createSensor_invalidHandle_throwsException() {
doReturn(/* handle= */0).when(mSensorManagerInternalMock).createRuntimeSensor(
- anyInt(), anyInt(), anyString(), anyString(), anyInt(), any());
+ anyInt(), anyInt(), anyString(), anyString(), anyFloat(), anyFloat(), anyFloat(),
+ anyInt(), anyInt(), anyInt(), any());
Throwable thrown = assertThrows(
RuntimeException.class,
@@ -138,7 +140,8 @@ public class SensorControllerTest {
private void doCreateSensorSuccessfully() {
doReturn(SENSOR_HANDLE).when(mSensorManagerInternalMock).createRuntimeSensor(
- anyInt(), anyInt(), anyString(), anyString(), anyInt(), any());
+ anyInt(), anyInt(), anyString(), anyString(), anyFloat(), anyFloat(), anyFloat(),
+ anyInt(), anyInt(), anyInt(), any());
assertThat(mSensorController.createSensor(mSensorToken, mVirtualSensorConfig))
.isEqualTo(SENSOR_HANDLE);
}
diff --git a/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java
index 339ccd80c351..a4a3e363ab4d 100644
--- a/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java
@@ -536,7 +536,8 @@ public class VirtualDeviceManagerServiceTest {
.build();
doReturn(SENSOR_HANDLE).when(mSensorManagerInternalMock).createRuntimeSensor(
- anyInt(), anyInt(), anyString(), anyString(), anyInt(), any());
+ anyInt(), anyInt(), anyString(), anyString(), anyFloat(), anyFloat(), anyFloat(),
+ anyInt(), anyInt(), anyInt(), any());
mDeviceImpl.close();
mDeviceImpl = createVirtualDevice(VIRTUAL_DEVICE_ID_1, DEVICE_OWNER_UID_1, params);