diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-06-29 18:43:34 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2023-06-29 18:43:34 +0000 |
commit | 4166297bf48b592612592e3c68c1dea51a4cb928 (patch) | |
tree | e90ae3851038e32d3b23d9f6bcd37c9a5ac95f71 | |
parent | 72c371cea1d97892a06619f5adf43eb39713e058 (diff) | |
parent | 958ee1c33229e60df8d08472799632e6dfbc6daf (diff) | |
download | qemu-snap-temp-L60900000961888091.tar.gz |
Merge "Merge cherrypicks of ['android-review.googlesource.com/2636811', 'android-review.googlesource.com/2636814'] into emu-32-release." into emu-32-releasesnap-temp-L87000000961890077snap-temp-L60900000961888091snap-temp-L15200000962184086
-rw-r--r-- | android/android-emu/android-emu.cmake | 1 | ||||
-rw-r--r-- | android/android-emu/android/car-physics.cpp | 37 | ||||
-rw-r--r-- | android/android-emu/android/car-physics.h | 19 | ||||
-rw-r--r-- | android/android-emu/android/emulator-window.c | 13 | ||||
-rw-r--r-- | android/android-emu/android/hw-sensors.cpp | 12 | ||||
-rw-r--r-- | android/android-emu/android/hw-sensors.h | 3 | ||||
-rw-r--r-- | android/android-emu/android/physics/PhysicalModel.cpp | 36 | ||||
-rw-r--r-- | android/android-emu/android/physics/PhysicalModel.h | 5 | ||||
-rw-r--r-- | android/android-emu/android/physics/PhysicalModel_unittest.cpp | 3 | ||||
-rw-r--r-- | android/android-emu/android/qemu-setup.cpp | 2 | ||||
-rw-r--r-- | android/android-emu/android/skin/qt/device-3d-widget.cpp | 7 | ||||
-rw-r--r-- | android/android-emu/android/skin/qt/extended-pages/virtual-sensors-page.cpp | 23 | ||||
-rw-r--r-- | android/android-grpc/emulator_controller.proto | 2 | ||||
-rw-r--r-- | android/emu/avd/src/android/avd/hardware-properties.ini | 7 | ||||
-rw-r--r-- | android/emu/protos/automation.proto | 4 |
15 files changed, 159 insertions, 15 deletions
diff --git a/android/android-emu/android-emu.cmake b/android/android-emu/android-emu.cmake index 939b1c5e98..8deeed9861 100644 --- a/android/android-emu/android-emu.cmake +++ b/android/android-emu/android-emu.cmake @@ -58,6 +58,7 @@ set(android-emu-common android/boot-properties.c android/bootconfig.cpp android/car-cluster.cpp + android/car-physics.cpp android/car.cpp android/cros.c android/emulation/AdbDebugPipe.cpp diff --git a/android/android-emu/android/car-physics.cpp b/android/android-emu/android/car-physics.cpp new file mode 100644 index 0000000000..3602011d47 --- /dev/null +++ b/android/android-emu/android/car-physics.cpp @@ -0,0 +1,37 @@ +/* Copyright (C) 2022 The Android Open Source Project +** +** This software is licensed under the terms of the GNU General Public +** License version 2, as published by the Free Software Foundation, and +** may be copied, distributed, and modified under those terms. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +*/ +#include "android/car-physics.h" + +#include "android/console.h" +#include "android/hw-sensors.h" +#include "android/physics/PhysicalModel.h" +#include "android/utils/debug.h" + +#include <stdio.h> +#include <string.h> + +// forward declaration +typedef struct SkinLayout SkinLayout; + +void android_car_physics_init() { + // Phones and cars use a different default orientation. + // See + // https://source.android.com/docs/core/interaction/sensors/sensor-types#limited_axes_imu_sensors + physicalModel_setGravity(android_physical_model_instance(), 0.f, 0.f, + -9.81f); + + // Phones are tilted by 4.75f in + // external/qemu/android/android-emu/android/emulator-window.c + // emulator_window_setup(...). Override this with zero. + android_sensors_set_coarse_orientation(ANDROID_COARSE_PORTRAIT, + 0.f /* no tilt */); +}
\ No newline at end of file diff --git a/android/android-emu/android/car-physics.h b/android/android-emu/android/car-physics.h new file mode 100644 index 0000000000..1dae7bcab2 --- /dev/null +++ b/android/android-emu/android/car-physics.h @@ -0,0 +1,19 @@ +/* Copyright (C) 2022 The Android Open Source Project +** +** This software is licensed under the terms of the GNU General Public +** License version 2, as published by the Free Software Foundation, and +** may be copied, distributed, and modified under those terms. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +*/ +#pragma once +#include "android/utils/compiler.h" + +ANDROID_BEGIN_HEADER + +extern void android_car_physics_init(); + +ANDROID_END_HEADER diff --git a/android/android-emu/android/emulator-window.c b/android/android-emu/android/emulator-window.c index f249beba88..14c4365c38 100644 --- a/android/android-emu/android/emulator-window.c +++ b/android/android-emu/android/emulator-window.c @@ -361,10 +361,15 @@ static void emulator_window_setup(EmulatorWindow* emulator) { // Set the coarse orientation of the modeled device to match the skin // layout at startup by default. const SkinLayout* layout = skin_ui_get_current_layout(emulator->ui); - // Historically, the AVD starts up with the screen mostly - // vertical, but tilted back 4.75 degrees. Retain that - // initial orientation. - emulator_window_set_device_coarse_orientation(layout->orientation, 4.75f); + + if (avdInfo_getAvdFlavor(getConsoleAgents()->settings->avdInfo()) != + AVD_ANDROID_AUTO) { + // Historically, the AVD starts up with the screen mostly + // vertical, but tilted back 4.75 degrees. Retain that + // initial orientation. + emulator_window_set_device_coarse_orientation(layout->orientation, + 4.75f); + } if (emulator->onion) { skin_ui_set_onion(emulator->ui, emulator->onion, diff --git a/android/android-emu/android/hw-sensors.cpp b/android/android-emu/android/hw-sensors.cpp index 95b51d6251..334b374f56 100644 --- a/android/android-emu/android/hw-sensors.cpp +++ b/android/android-emu/android/hw-sensors.cpp @@ -936,6 +936,10 @@ static void _hwSensors_init(HwSensors* h) { h->sensors[ANDROID_SENSOR_ACCELERATION].enabled = true; } + if (getConsoleAgents()->settings->hw()->hw_accelerometer_uncalibrated) { + h->sensors[ANDROID_SENSOR_ACCELERATION_UNCALIBRATED].enabled = true; + } + if (getConsoleAgents()->settings->hw()->hw_gyroscope) { h->sensors[ANDROID_SENSOR_GYROSCOPE].enabled = true; } @@ -1465,6 +1469,14 @@ bool android_foldable_rollable_configured() { return (getConsoleAgents()->settings->hw()->hw_sensor_roll && getConsoleAgents()->settings->hw()->hw_sensor_roll_count > 0); } +bool android_is_automotive() { + if (getConsoleAgents()->settings->android_qemu_mode()) { + AvdFlavor flavor = avdInfo_getAvdFlavor(getConsoleAgents()->settings->avdInfo()); + return flavor == AVD_ANDROID_AUTO; + } + return false; +} + bool android_hw_sensors_is_loading_snapshot() { return physicalModel_isLoadingSnapshot(android_physical_model_instance()); } diff --git a/android/android-emu/android/hw-sensors.h b/android/android-emu/android/hw-sensors.h index 31d207cea0..d99fa48143 100644 --- a/android/android-emu/android/hw-sensors.h +++ b/android/android-emu/android/hw-sensors.h @@ -123,6 +123,7 @@ typedef enum{ SENSOR_(HEART_RATE, "heart-rate", HeartRate, float, "heart-rate:%g") \ SENSOR_(RGBC_LIGHT, "rgbc-light", RgbcLight, vec4, "rgbc-light:%g:%g:%g:%g") \ SENSOR_(WRIST_TILT, "wrist-tilt", WristTilt, float, "wrist-tilt:%g") \ + SENSOR_(ACCELERATION_UNCALIBRATED,"acceleration-uncalibrated",AccelerometerUncalibrated,vec3,"acceleration-uncalibrated:%g:%g:%g") \ // clang-format on typedef enum { #define SENSOR_(x,y,z,v,w) ANDROID_SENSOR_##x, @@ -170,6 +171,7 @@ typedef enum{ PHYSICAL_PARAMETER_(HEART_RATE, "heart-rate", HeartRate, float) \ PHYSICAL_PARAMETER_(RGBC_LIGHT, "rgbc-light", RgbcLight, vec4) \ PHYSICAL_PARAMETER_(WRIST_TILT, "wrist-tilt", WristTilt, float) \ + PHYSICAL_PARAMETER_(ROTATION_UNCALIBRATED, "rotation-uncalibrated", AccelerometerUncalibrated, vec3) \ // clang-format on typedef enum { #define PHYSICAL_PARAMETER_(x,y,z,w) PHYSICAL_PARAMETER_##x, @@ -383,4 +385,5 @@ bool android_foldable_rollable_configured(); bool android_hw_sensors_is_loading_snapshot(); bool android_heart_rate_sensor_configured(); bool android_foldable_posture_name(int posture, char* name); +bool android_is_automotive(); ANDROID_END_HEADER diff --git a/android/android-emu/android/physics/PhysicalModel.cpp b/android/android-emu/android/physics/PhysicalModel.cpp index 73114fcb18..0edd521eca 100644 --- a/android/android-emu/android/physics/PhysicalModel.cpp +++ b/android/android-emu/android/physics/PhysicalModel.cpp @@ -89,6 +89,11 @@ public: void setCurrentTime(int64_t time_ns); /* + * Sets the current gravity of the PhysicalModel simulation. + */ + void setGravity(float x, float y, float z); + + /* * Replays a PhysicalModelEvent onto the current PhysicalModel state. */ void replayEvent(const pb::PhysicalModelEvent& event); @@ -526,6 +531,11 @@ void PhysicalModelImpl::setCurrentTime(int64_t time_ns) { } } +void PhysicalModelImpl::setGravity(float x, float y, float z) { + mAmbientEnvironment.setGravity(glm::vec3(x, y, z), + PHYSICAL_INTERPOLATION_STEP); +} + void PhysicalModelImpl::replayEvent(const pb::PhysicalModelEvent& event) { switch (fromProto(event.type())) { #define PHYSICAL_PARAMETER_ENUM(x) PHYSICAL_PARAMETER_##x @@ -762,6 +772,19 @@ void PhysicalModelImpl::setTargetInternalWristTilt(float value, targetStateChanged(); } +void PhysicalModelImpl::setTargetInternalAccelerometerUncalibrated(vec3, PhysicalInterpolation) { + physicalStateChanging(); + { + std::lock_guard<std::recursive_mutex> lock(mMutex); + // Not supported to set the uncalibrated accelerometer value. + } + targetStateChanged(); +} + +vec3 PhysicalModelImpl::getParameterAccelerometerUncalibrated(ParameterValueType) const { + return fromGlm(mInertialModel.getAcceleration()); +} + vec3 PhysicalModelImpl::getParameterPosition( ParameterValueType parameterValueType) const { std::lock_guard<std::recursive_mutex> lock(mMutex); @@ -928,6 +951,12 @@ vec3 PhysicalModelImpl::getPhysicalAccelerometer() const { mAmbientEnvironment.getGravity())); } +vec3 PhysicalModelImpl::getPhysicalAccelerometerUncalibrated() const { + // Same values for the calibrated and uncalibrated accelerometer + // Bias will be added to the balues on the guest side. + return getPhysicalAccelerometer(); +} + vec3 PhysicalModelImpl::getPhysicalGyroscope() const { return fromGlm(glm::conjugate(mInertialModel.getRotation()) * mInertialModel.getRotationalVelocity()); @@ -1522,6 +1551,13 @@ void physicalModel_setCurrentTime(PhysicalModel* model, int64_t time_ns) { } } +void physicalModel_setGravity(PhysicalModel* model, float x, float y, float z) { + PhysicalModelImpl* impl = PhysicalModelImpl::getImpl(model); + if (impl != nullptr) { + impl->setGravity(x, y, z); + } +} + #define SET_PHYSICAL_TARGET_FUNCTION_NAME(x) physicalModel_setTarget##x #define SET_TARGET_FUNCTION_NAME(x) setTarget##x #define PHYSICAL_PARAMETER_(x, y, z, w) \ diff --git a/android/android-emu/android/physics/PhysicalModel.h b/android/android-emu/android/physics/PhysicalModel.h index 63d9f936a1..7c126c57c6 100644 --- a/android/android-emu/android/physics/PhysicalModel.h +++ b/android/android-emu/android/physics/PhysicalModel.h @@ -70,6 +70,11 @@ void physicalModel_free(PhysicalModel* model); */ void physicalModel_setCurrentTime(PhysicalModel* model, int64_t time_ns); +/* + * Update the gravity in the model. + */ +void physicalModel_setGravity(PhysicalModel* model, float x, float y, float z); + /* Target setters for all physical parameters */ #define SET_TARGET_FUNCTION_NAME(x) physicalModel_setTarget##x #define PHYSICAL_PARAMETER_(x,y,z,w) void SET_TARGET_FUNCTION_NAME(z)(\ diff --git a/android/android-emu/android/physics/PhysicalModel_unittest.cpp b/android/android-emu/android/physics/PhysicalModel_unittest.cpp index 5bd452cf92..0b2b6532e0 100644 --- a/android/android-emu/android/physics/PhysicalModel_unittest.cpp +++ b/android/android-emu/android/physics/PhysicalModel_unittest.cpp @@ -362,6 +362,7 @@ TEST(PhysicalModel, SaveLoadStateSimple) { static constexpr vec3 kVecZero = {0.f, 0.f, 0.f}; static constexpr vec3 kAccelOverride = {1.f, 2.f, 3.f}; +static constexpr vec3 kAccelUncalibratedOverride = {1.f, 2.f, 3.f}; static constexpr vec3 kGyroOverride = {4.f, 5.f, 6.f}; static constexpr vec3 kMagnetometerOverride = {7.f, 8.f, 9.f}; static constexpr vec3 kOrientationOverride = {10.f, 11.f, 12.f}; @@ -418,6 +419,8 @@ static void applyOverrides(PhysicalModel* model) { model, kMagneticUncalibratedOverride); physicalModel_overrideGyroscopeUncalibrated(model, kGyroUncalibratedOverride); + physicalModel_overrideAccelerometerUncalibrated(model, + kAccelUncalibratedOverride); } TEST(PhysicalModel, SaveLoadOverrides) { diff --git a/android/android-emu/android/qemu-setup.cpp b/android/android-emu/android/qemu-setup.cpp index 9400231fe5..efae6554cd 100644 --- a/android/android-emu/android/qemu-setup.cpp +++ b/android/android-emu/android/qemu-setup.cpp @@ -30,6 +30,7 @@ #include "android/base/system/System.h" // for System #include "android/boot-properties.h" // for boot_pr... #include "android/car-cluster.h" // for android... +#include "android/car-physics.h" // for android... #include "android/car.h" // for android... #include "android/clipboard-pipe.h" // for android... #include "android/cmdline-option.h" // for android... @@ -506,6 +507,7 @@ bool android_emulation_setup(const AndroidConsoleAgents* agents, bool isQemu2) { if (flavor == AVD_ANDROID_AUTO) { android_car_init(); android_car_cluster_init(); + android_car_physics_init(); } } diff --git a/android/android-emu/android/skin/qt/device-3d-widget.cpp b/android/android-emu/android/skin/qt/device-3d-widget.cpp index 9f2caa3386..c4a602f159 100644 --- a/android/android-emu/android/skin/qt/device-3d-widget.cpp +++ b/android/android-emu/android/skin/qt/device-3d-widget.cpp @@ -60,7 +60,10 @@ static glm::vec3 clampPosition(glm::vec3 position) { static constexpr int kAnimationIntervalMs = 33; Device3DWidget::Device3DWidget(QWidget* parent) - : GLWidget(parent), mUseAbstractDevice(android_foldable_hinge_configured() || android_foldable_rollable_configured()) { + : GLWidget(parent), mUseAbstractDevice( + android_foldable_hinge_configured() + || android_foldable_rollable_configured() + || android_is_automotive()) { toggleAA(); setFocusPolicy(Qt::ClickFocus); @@ -249,7 +252,7 @@ bool Device3DWidget::initModel() { // Load the model and set up buffers. std::vector<float> model_vertex_data; std::vector<GLuint> indices; - QFile model_file(":/phone-model/model.obj"); + QFile model_file(":/car-model/model.obj"); if (model_file.open(QFile::ReadOnly)) { QTextStream file_stream(&model_file); if (!parseWavefrontOBJ(file_stream, model_vertex_data, indices)) { diff --git a/android/android-emu/android/skin/qt/extended-pages/virtual-sensors-page.cpp b/android/android-emu/android/skin/qt/extended-pages/virtual-sensors-page.cpp index 32ea93c794..a804e9e9fe 100644 --- a/android/android-emu/android/skin/qt/extended-pages/virtual-sensors-page.cpp +++ b/android/android-emu/android/skin/qt/extended-pages/virtual-sensors-page.cpp @@ -142,10 +142,6 @@ VirtualSensorsPage::VirtualSensorsPage(QWidget* parent) updateSensorValuesInUI(); - if (avdInfo_getAvdFlavor(getConsoleAgents()->settings->avdInfo()) == AVD_ANDROID_AUTO) { - mUi->tabWidget->removeTab(kAccelerometerTabIndex); - } - if (avdInfo_getAvdFlavor(getConsoleAgents()->settings->avdInfo()) == AVD_WEAR) { if (avdInfo_getApiLevel(getConsoleAgents()->settings->avdInfo()) < 28) { // This feature is currently only available on Wear OS API 28+ emulators. @@ -758,6 +754,7 @@ void VirtualSensorsPage::updateModelFromAccelWidget( const glm::vec3 currentPosition = getPhysicalParameterTargetVec3(PHYSICAL_PARAMETER_POSITION); + if (!vecNearEqual(position, currentPosition)) { setPhysicalParameterTarget(PHYSICAL_PARAMETER_POSITION, mode, {position.x, position.y, position.z}); @@ -765,6 +762,8 @@ void VirtualSensorsPage::updateModelFromAccelWidget( const glm::vec3 currentRotationDegrees = getPhysicalParameterTargetVec3(PHYSICAL_PARAMETER_ROTATION); + const glm::vec3 currentPositionUncalib = + getPhysicalParameterTargetVec3(PHYSICAL_PARAMETER_ROTATION_UNCALIBRATED); if (!vecNearEqual(rotationDegrees, currentRotationDegrees)) { setPhysicalParameterTarget( PHYSICAL_PARAMETER_ROTATION, mode, @@ -906,8 +905,6 @@ void VirtualSensorsPage::updateSensorValuesInUI() { if (sSensorsAgent != nullptr) { sSensorsAgent->advanceTime(); - glm::vec3 gravity_vector(0.0f, 9.81f, 0.0f); - glm::vec3 device_accelerometer; std::vector<float*> out = {&device_accelerometer.x, &device_accelerometer.y, @@ -941,9 +938,17 @@ void VirtualSensorsPage::updateSensorValuesInUI() { } if (coarse_orientation != mCoarseOrientation) { mCoarseOrientation = coarse_orientation; - // Signal to the extended-window to rotate the emulator window - // since an orientation has been detected in the sensor values. - emit(coarseOrientationChanged(mCoarseOrientation)); + // Only allow orientation changes on cars, when the orientation + // sensor was enabled in the AVD config. + if (!android_is_automotive() || + getConsoleAgents() + ->settings->hw() + ->hw_sensors_orientation) { + // Signal to the extended-window to rotate the emulator + // window since an orientation has been detected in the + // sensor values. + emit(coarseOrientationChanged(mCoarseOrientation)); + } } } diff --git a/android/android-grpc/emulator_controller.proto b/android/android-grpc/emulator_controller.proto index 3378144581..95be48915e 100644 --- a/android/android-grpc/emulator_controller.proto +++ b/android/android-grpc/emulator_controller.proto @@ -427,6 +427,8 @@ message SensorValue { RGBC_LIGHT = 15; // WIRST_TILT (16) is skipped; clients should use get/setPhysicalModel() // instead. + // Measures acceleration force and provides bias data. + ACCELERATION_UNCALIBRATED = 17; } // Type of sensor diff --git a/android/emu/avd/src/android/avd/hardware-properties.ini b/android/emu/avd/src/android/avd/hardware-properties.ini index 35611eb7fe..6aca6657b9 100644 --- a/android/emu/avd/src/android/avd/hardware-properties.ini +++ b/android/emu/avd/src/android/avd/hardware-properties.ini @@ -151,6 +151,13 @@ default = yes abstract = Accelerometer description = Whether there is an accelerometer in the device. +# Accelerometer (uncalibrated) +name = hw.accelerometer_uncalibrated +type = boolean +default = yes +abstract = AccelerometerUncalibrated +description = Whether there is an uncalibrated accelerometer in the device. + # Gyroscope (used for VR) name = hw.gyroscope type = boolean diff --git a/android/emu/protos/automation.proto b/android/emu/protos/automation.proto index d2fc2486b0..5bbdb444f0 100644 --- a/android/emu/protos/automation.proto +++ b/android/emu/protos/automation.proto @@ -30,6 +30,8 @@ message ParameterValue { } message PhysicalModelEvent { + // The following list of sensors should be kept in sync with PHYSICAL_PARAMETERS_LIST in + // hw-sensor.h enum ParameterType { POSITION = 0; ROTATION = 1; @@ -51,6 +53,7 @@ message PhysicalModelEvent { HEART_RATE = 17; RGBC_LIGHT = 18; WRIST_TILT = 19; + ROTATION_UNCALIBRATED = 20; } optional ParameterType type = 1; @@ -84,6 +87,7 @@ message SensorOverrideEvent { HEART_RATE = 14; RGBC_LIGHT = 15; WRIST_TILT = 16; + ACCELERATION_UNCALIBRATED = 17; } optional Sensor sensor = 1; |