Snap for 7901677 from a27af0c4b5385eefd79198701adf7be9cde6db16 to sc-platform-release

Change-Id: Ifaabb25d7066deb2bd00eb6b0e63b84300b61082
diff --git a/64bitonly/product/sdk_phone64_arm64.mk b/64bitonly/product/sdk_phone64_arm64.mk
index d665246..cd69897 100644
--- a/64bitonly/product/sdk_phone64_arm64.mk
+++ b/64bitonly/product/sdk_phone64_arm64.mk
@@ -40,6 +40,9 @@
 #
 $(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_product.mk)
 
+PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP := \
+    development/sys-img/images_arm64-v8a_source.prop_template
+
 #
 # All components inherited here go to vendor or vendor_boot image
 #
diff --git a/64bitonly/product/sdk_phone64_x86_64.mk b/64bitonly/product/sdk_phone64_x86_64.mk
index 2686954..ac55493 100644
--- a/64bitonly/product/sdk_phone64_x86_64.mk
+++ b/64bitonly/product/sdk_phone64_x86_64.mk
@@ -38,6 +38,9 @@
 #
 $(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_product.mk)
 
+PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP := \
+    development/sys-img/images_x86_64_source.prop_template
+
 #
 # All components inherited here go to vendor image
 #
diff --git a/64bitonly/product/vendor.mk b/64bitonly/product/vendor.mk
index c2c651f..dc6c3f8 100644
--- a/64bitonly/product/vendor.mk
+++ b/64bitonly/product/vendor.mk
@@ -42,6 +42,7 @@
     libcuttlefish-ril-2 \
     libgoldfish-rild \
     qemu-adb-keys \
+    qemu-device-state \
     qemu-props \
     stagefright \
     fingerprint.ranchu \
@@ -78,8 +79,7 @@
     libGLESv1_enc \
     libEGL_angle \
     libGLESv1_CM_angle \
-    libGLESv2_angle \
-    libfeature_support_angle.so
+    libGLESv2_angle
 endif
 
 PRODUCT_PACKAGES += \
@@ -263,6 +263,7 @@
 
 PRODUCT_COPY_FILES += \
     device/generic/goldfish/data/etc/dtb.img:dtb.img \
+    device/generic/goldfish/emulator-info.txt:data/misc/emulator/version.txt \
     device/generic/goldfish/data/etc/apns-conf.xml:data/misc/apns/apns-conf.xml \
     device/generic/goldfish/radio/RadioConfig/radioconfig.xml:data/misc/emulator/config/radioconfig.xml \
     device/generic/goldfish/data/etc/iccprofile_for_sim0.xml:data/misc/modem_simulator/iccprofile_for_sim0.xml \
@@ -293,7 +294,6 @@
     device/generic/goldfish/input/virtio_input_multi_touch_11.idc:$(TARGET_COPY_OUT_VENDOR)/usr/idc/virtio_input_multi_touch_11.idc \
     device/generic/goldfish/display_settings_freeform.xml:$(TARGET_COPY_OUT_VENDOR)/etc/display_settings_freeform.xml \
     device/generic/goldfish/display_settings.xml:$(TARGET_COPY_OUT_VENDOR)/etc/display_settings.xml \
-    device/generic/goldfish/device_state_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/devicestate/device_state_configuration.xml \
     device/generic/goldfish/data/etc/config.ini:config.ini \
     device/generic/goldfish/wifi/simulated_hostapd.conf:$(TARGET_COPY_OUT_VENDOR)/etc/simulated_hostapd.conf \
     device/generic/goldfish/wifi/wpa_supplicant.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wifi/wpa_supplicant.conf \
@@ -322,8 +322,8 @@
     frameworks/native/data/etc/android.hardware.vulkan.level-1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.level.xml \
     frameworks/native/data/etc/android.hardware.vulkan.compute-0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.compute.xml \
     frameworks/native/data/etc/android.hardware.vulkan.version-1_1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml \
-    frameworks/native/data/etc/android.software.vulkan.deqp.level-2020-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \
-    frameworks/native/data/etc/android.software.opengles.deqp.level-2020-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml \
+    frameworks/native/data/etc/android.software.vulkan.deqp.level-2021-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \
+    frameworks/native/data/etc/android.software.opengles.deqp.level-2021-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml \
     frameworks/native/data/etc/android.software.autofill.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.autofill.xml \
     frameworks/native/data/etc/android.software.verified_boot.xml:${TARGET_COPY_OUT_PRODUCT}/etc/permissions/android.software.verified_boot.xml \
     device/generic/goldfish/data/etc/permissions/privapp-permissions-goldfish.xml:$(TARGET_COPY_OUT_PRODUCT)/etc/permissions/privapp-permissions-goldfish.xml \
diff --git a/camera/media_codecs_google_video_default.xml b/camera/media_codecs_google_video_default.xml
index 1a0ee97..cc5ba1f 100644
--- a/camera/media_codecs_google_video_default.xml
+++ b/camera/media_codecs_google_video_default.xml
@@ -58,8 +58,8 @@
             <Limit name="bitrate" range="1-120000000" />
             <Limit name="frame-rate" range="1-480" />
             <Limit name="performance-point-3840x2160" value="30" />
-            <Limit name="measured-frame-rate-320x240" range="1000-1500" />
-            <Limit name="measured-frame-rate-720x480" range="400-800" />
+            <Limit name="measured-frame-rate-320x240" range="257-266" />
+            <Limit name="measured-frame-rate-720x480" range="262-264" />
             <Limit name="measured-frame-rate-1280x720" range="227-251" />
             <Limit name="measured-frame-rate-1920x1080" range="235-247" />
             <Limit name="measured-frame-rate-3840x2160" range="235-247" />
@@ -122,18 +122,17 @@
             <Feature name="adaptive-playback" />
         </MediaCodec>
         <MediaCodec name="c2.goldfish.vp8.decoder" type="video/x-vnd.on2.vp8">
-            <Limit name="size" min="96x96" max="3840x2160" />
+            <Limit name="size" min="96x96" max="2560x2560" />
             <Limit name="alignment" value="2x2" />
             <Limit name="block-size" value="16x16" />
             <Limit name="blocks-per-second" min="24" max="2073600" />
             <Limit name="bitrate" range="1-120000000" />
             <Limit name="frame-rate" range="1-480" />
-            <Limit name="performance-point-3840x2160" value="30" />
+            <Limit name="performance-point-1920x1080" value="30" />
             <Limit name="measured-frame-rate-320x180" range="743-817" />
             <Limit name="measured-frame-rate-640x360" range="237-258" />
             <Limit name="measured-frame-rate-1280x720" range="60-160" />
             <Limit name="measured-frame-rate-1920x1080" range="30-160" />
-            <Limit name="measured-frame-rate-3840x2160" range="30-90" />
             <Feature name="adaptive-playback" />
         </MediaCodec>
         <MediaCodec name="c2.goldfish.vp9.decoder" type="video/x-vnd.on2.vp9">
@@ -144,10 +143,10 @@
             <Limit name="bitrate" range="1-120000000" />
             <Limit name="frame-rate" range="1-480" />
             <Limit name="performance-point-3840x2160" value="30" />
-            <Limit name="measured-frame-rate-320x180" range="237-258" />
+            <Limit name="measured-frame-rate-320x180" range="950-970" />
             <Limit name="measured-frame-rate-640x360" range="237-258" />
             <Limit name="measured-frame-rate-1280x720" range="237-258" />
-            <Limit name="measured-frame-rate-1920x1080" range="293-302" />
+            <Limit name="measured-frame-rate-1920x1080" range="100-120" />
             <Limit name="measured-frame-rate-3840x2160" range="30-90" />
             <Feature name="adaptive-playback" />
         </MediaCodec>
diff --git a/camera/media_codecs_performance_c2.xml b/camera/media_codecs_performance_c2.xml
index 7c0268e..ba46e4e 100644
--- a/camera/media_codecs_performance_c2.xml
+++ b/camera/media_codecs_performance_c2.xml
@@ -19,9 +19,10 @@
 
         <MediaCodec name="c2.android.avc.decoder" type="video/avc" update="true">
             <Limit name="measured-frame-rate-320x240" range="486-504" /> <!-- N=50 v96%=1.3 -->
-            <Limit name="measured-frame-rate-720x480" range="128-130" /> <!-- v90%=1.0 -->
-            <Limit name="measured-frame-rate-1280x720" range="48-49" /> <!-- v90%=1.0 -->
-            <Limit name="measured-frame-rate-1920x1080" range="22-22" /> <!-- v90%=1.0 -->
+            <Limit name="measured-frame-rate-640x360" range="267-275" /> <!-- v90%=1.1 -->
+            <Limit name="measured-frame-rate-720x480" range="248-248" /> <!-- v90%=1.1 -->
+            <Limit name="measured-frame-rate-1280x720" range="107-108" /> <!-- v90%=1.0 -->
+            <Limit name="measured-frame-rate-1920x1080" range="50-50" /> <!-- v90%=1.0 -->
         </MediaCodec>
         <MediaCodec name="c2.android.hevc.decoder" type="video/hevc" update="true">
             <Limit name="measured-frame-rate-352x288" range="469-485" /> <!-- v90%=1.1 -->
@@ -51,20 +52,20 @@
         </MediaCodec>
         <MediaCodec name="c2.android.h263.decoder" type="video/3gpp" update="true">
             <!-- measured 90%:1219-1704 med:1479 N=12 -->
-            <Limit name="measured-frame-rate-176x144" range="1441-1441" /> <!-- v90%=1.2 -->
+            <Limit name="measured-frame-rate-176x144" range="470-520" /> <!-- v90%=1.2 -->
             <!-- measured 96%:889-1227 med:922 SLOW -->
-            <Limit name="measured-frame-rate-352x288" range="921-1045" /> <!-- N=50 v96%=1.2 -->
+            <Limit name="measured-frame-rate-352x288" range="470-520" /> <!-- N=50 v96%=1.2 -->
         </MediaCodec>
         <MediaCodec name="c2.android.mpeg4.decoder" type="video/mp4v-es" update="true">
             <!-- measured 90%:1298-1653 med:1316 SLOW N=12 -->
-            <Limit name="measured-frame-rate-176x144" range="1315-1465" /> <!-- v90%=1.1 -->
+            <Limit name="measured-frame-rate-176x144" range="540-590" /> <!-- v90%=1.1 -->
         </MediaCodec>
     </Decoders>
 
     <Encoders>
 
         <MediaCodec name="c2.android.h263.encoder" type="video/3gpp" update="true">
-            <Limit name="measured-frame-rate-176x144" range="287-459" /> <!-- TWEAKED N=224 -->
+            <Limit name="measured-frame-rate-176x144" range="1400-1560" /> <!-- SHOULDN'T HAVE TWEAKED N=220 v90%=4.0 -->
         </MediaCodec>
         <MediaCodec name="c2.android.avc.encoder" type="video/avc" update="true">
             <Limit name="measured-frame-rate-320x240" range="287-326" /> <!-- Manual N=20 -->
@@ -76,7 +77,7 @@
             <Limit name="measured-frame-rate-320x240" range="47-60" /> <!-- Manual N=20 -->
         </MediaCodec>
         <MediaCodec name="c2.android.mpeg4.encoder" type="video/mp4v-es" update="true">
-            <Limit name="measured-frame-rate-176x144" range="203-445" /> <!-- SHOULDN'T HAVE TWEAKED N=220 v90%=4.0 -->
+            <Limit name="measured-frame-rate-176x144" range="1400-1560" /> <!-- SHOULDN'T HAVE TWEAKED N=220 v90%=4.0 -->
         </MediaCodec>
         <MediaCodec name="c2.android.vp8.encoder" type="video/x-vnd.on2.vp8" update="true">
             <Limit name="measured-frame-rate-320x180" range="178-245" /> <!-- Manual N=20 -->
diff --git a/data/etc/advancedFeatures.ini b/data/etc/advancedFeatures.ini
index 211c31c..d6cb066 100644
--- a/data/etc/advancedFeatures.ini
+++ b/data/etc/advancedFeatures.ini
@@ -26,3 +26,4 @@
 DeviceSkinOverlay = on
 VulkanQueueSubmitWithCommands = on
 VulkanBatchedDescriptorSetUpdate = on
+DeviceStateOnBoot = on
diff --git a/data/etc/advancedFeatures.ini.arm b/data/etc/advancedFeatures.ini.arm
index 2d8d006..a7bc7f9 100644
--- a/data/etc/advancedFeatures.ini.arm
+++ b/data/etc/advancedFeatures.ini.arm
@@ -25,3 +25,4 @@
 DeviceSkinOverlay = on
 VulkanQueueSubmitWithCommands = on
 VulkanBatchedDescriptorSetUpdate = on
+DeviceStateOnBoot = on
diff --git a/data/etc/google/64bit/user/advancedFeatures.ini b/data/etc/google/64bit/user/advancedFeatures.ini
index 8e362e1..91f7635 100644
--- a/data/etc/google/64bit/user/advancedFeatures.ini
+++ b/data/etc/google/64bit/user/advancedFeatures.ini
@@ -27,3 +27,4 @@
 DeviceSkinOverlay = on
 VulkanQueueSubmitWithCommands = on
 VulkanBatchedDescriptorSetUpdate = on
+DeviceStateOnBoot = on
diff --git a/data/etc/google/64bit/user/arm64/advancedFeatures.ini b/data/etc/google/64bit/user/arm64/advancedFeatures.ini
index f4bea5e..dbfb12c 100644
--- a/data/etc/google/64bit/user/arm64/advancedFeatures.ini
+++ b/data/etc/google/64bit/user/arm64/advancedFeatures.ini
@@ -26,3 +26,4 @@
 DeviceSkinOverlay = on
 VulkanQueueSubmitWithCommands = on
 VulkanBatchedDescriptorSetUpdate = on
+DeviceStateOnBoot = on
diff --git a/data/etc/google/64bit/userdebug/advancedFeatures.ini b/data/etc/google/64bit/userdebug/advancedFeatures.ini
index 8e362e1..91f7635 100644
--- a/data/etc/google/64bit/userdebug/advancedFeatures.ini
+++ b/data/etc/google/64bit/userdebug/advancedFeatures.ini
@@ -27,3 +27,4 @@
 DeviceSkinOverlay = on
 VulkanQueueSubmitWithCommands = on
 VulkanBatchedDescriptorSetUpdate = on
+DeviceStateOnBoot = on
diff --git a/data/etc/google/64bit/userdebug/arm64/advancedFeatures.ini b/data/etc/google/64bit/userdebug/arm64/advancedFeatures.ini
index 70bd240..372836d 100644
--- a/data/etc/google/64bit/userdebug/arm64/advancedFeatures.ini
+++ b/data/etc/google/64bit/userdebug/arm64/advancedFeatures.ini
@@ -25,3 +25,4 @@
 DeviceSkinOverlay = on
 VulkanQueueSubmitWithCommands = on
 VulkanBatchedDescriptorSetUpdate = on
+DeviceStateOnBoot = on
diff --git a/data/etc/google/user/advancedFeatures.ini b/data/etc/google/user/advancedFeatures.ini
index 96b75e3..1e9327b 100644
--- a/data/etc/google/user/advancedFeatures.ini
+++ b/data/etc/google/user/advancedFeatures.ini
@@ -27,3 +27,4 @@
 DeviceSkinOverlay = on
 VulkanQueueSubmitWithCommands = on
 VulkanBatchedDescriptorSetUpdate = on
+DeviceStateOnBoot = on
diff --git a/data/etc/google/user/arm64/advancedFeatures.ini b/data/etc/google/user/arm64/advancedFeatures.ini
index 784af9b..64ede30 100644
--- a/data/etc/google/user/arm64/advancedFeatures.ini
+++ b/data/etc/google/user/arm64/advancedFeatures.ini
@@ -26,3 +26,4 @@
 DeviceSkinOverlay = on
 VulkanQueueSubmitWithCommands = on
 VulkanBatchedDescriptorSetUpdate = on
+DeviceStateOnBoot = on
diff --git a/data/etc/google/userdebug/advancedFeatures.ini b/data/etc/google/userdebug/advancedFeatures.ini
index d70f9f2..ceef674 100644
--- a/data/etc/google/userdebug/advancedFeatures.ini
+++ b/data/etc/google/userdebug/advancedFeatures.ini
@@ -28,3 +28,4 @@
 DeviceSkinOverlay = on
 VulkanQueueSubmitWithCommands = on
 VulkanBatchedDescriptorSetUpdate = on
+DeviceStateOnBoot = on
diff --git a/data/etc/google/userdebug/arm64/advancedFeatures.ini b/data/etc/google/userdebug/arm64/advancedFeatures.ini
index 2d8d006..a7bc7f9 100644
--- a/data/etc/google/userdebug/arm64/advancedFeatures.ini
+++ b/data/etc/google/userdebug/arm64/advancedFeatures.ini
@@ -25,3 +25,4 @@
 DeviceSkinOverlay = on
 VulkanQueueSubmitWithCommands = on
 VulkanBatchedDescriptorSetUpdate = on
+DeviceStateOnBoot = on
diff --git a/device_state_configuration.xml b/device_state_configuration.xml
deleted file mode 100644
index 17a09c4..0000000
--- a/device_state_configuration.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<device-state-config>
-  <device-state>
-    <identifier>0</identifier>
-    <conditions>
-      <lid-switch>
-        <open>false</open>
-      </lid-switch>
-    </conditions>
-  </device-state>
-  <device-state>
-    <identifier>1</identifier>
-    <conditions>
-      <lid-switch>
-        <open>true</open>
-      </lid-switch>
-    </conditions>
-  </device-state>
-</device-state-config>
diff --git a/emulator-info.txt b/emulator-info.txt
index 532435c..d115120 100644
--- a/emulator-info.txt
+++ b/emulator-info.txt
@@ -1,2 +1,2 @@
 # Emulator (stable) version
-require version-emulator=7479360
+require version-emulator=7637665
diff --git a/emulator64_x86_64_arm64/BoardConfig.mk b/emulator64_x86_64_arm64/BoardConfig.mk
index ce88f07..09c8047 100755
--- a/emulator64_x86_64_arm64/BoardConfig.mk
+++ b/emulator64_x86_64_arm64/BoardConfig.mk
@@ -28,7 +28,7 @@
 
 TARGET_PRELINK_MODULE := false
 
-include build/make/target/board/BoardConfigMainlineCommon.mk
+include build/make/target/board/BoardConfigGsiCommon.mk
 include build/make/target/board/BoardConfigEmuCommon.mk
 
 # the settings differ from BoardConfigMainlineCommon.mk
diff --git a/fingerprint/fingerprint.c b/fingerprint/fingerprint.c
index d89145c..dff5d98 100644
--- a/fingerprint/fingerprint.c
+++ b/fingerprint/fingerprint.c
@@ -267,13 +267,6 @@
     uint64_t authenticator_id = 0;
     loadFingerprints(&qdev->listener);
     loadAuthenticatorId(qdev->listener.authid_filename, &authenticator_id);
-    if (authenticator_id == 0) {
-        // firs time, create an authenticator id
-        authenticator_id = get_64bit_rand();
-        // save it to disk
-        saveAuthenticatorId(qdev->listener.authid_filename, authenticator_id);
-    }
-
     qdev->authenticator_id = authenticator_id;
     pthread_mutex_unlock(&qdev->lock);
 
@@ -538,6 +531,22 @@
         device->notify(&msg);
     }
 
+    // where there are no enrollment, reset authenticator id to 0
+    bool has_fingerprints = false;
+    for (idx = 0; idx < MAX_NUM_FINGERS; idx++) {
+        uint32_t theFid = qdev->listener.fingerid[idx];
+        if (theFid != 0) {
+            has_fingerprints = true;
+            break;
+        }
+    }
+
+    if (!has_fingerprints) {
+        qdev->authenticator_id = 0;
+        saveAuthenticatorId(qdev->listener.authid_filename, qdev->authenticator_id);
+    }
+
+
     return 0;
 }
 
@@ -637,6 +646,10 @@
         qdev->listener.secureid[idx] = qdev->secure_user_id;
         qdev->listener.fingerid[idx] = fid;
         saveFingerprint(&qdev->listener, idx);
+        uint64_t authenticator_id = get_64bit_rand();
+        // save it to disk
+        saveAuthenticatorId(qdev->listener.authid_filename, authenticator_id);
+        qdev->authenticator_id = authenticator_id;
         qdev->listener.state = STATE_IDLE;
     }
     pthread_mutex_unlock(&qdev->lock);
diff --git a/init.ranchu.rc b/init.ranchu.rc
index d4cef38..d62215d 100644
--- a/init.ranchu.rc
+++ b/init.ranchu.rc
@@ -25,6 +25,8 @@
     # GTS tests are migrated to ro.boot.qemu.
     setprop ro.kernel.qemu 1
 
+    verity_update_state
+
 on init
     # set RLIMIT_MEMLOCK to 8MB for BPF network statistics
     setrlimit memlock 8388608 8388608
@@ -63,11 +65,13 @@
 on post-fs-data
     setprop vold.post_fs_data_done 1
     mkdir /data/vendor/adb 0755 root root
+    mkdir /data/vendor/devicestate 0755 root root
     mkdir /data/vendor/var 0755 root root
     mkdir /data/vendor/var/run 0755 root root
     mkdir /data/vendor/var/run/netns 0755 root root
 
     start qemu-adb-keys
+    start qemu-device-state
 
 on zygote-start
     # Create the directories used by the Wireless subsystem
@@ -198,6 +202,12 @@
     group root
     oneshot
 
+service qemu-device-state /vendor/bin/qemu-device-state
+    class core
+    user root
+    group root
+    oneshot
+
 service goldfish-logcat /system/bin/logcat -f /dev/hvc1 ${ro.boot.logcat}
     class main
     user logd
diff --git a/init.system_ext.rc b/init.system_ext.rc
index 5f8cb4e..5c2db83 100644
--- a/init.system_ext.rc
+++ b/init.system_ext.rc
@@ -5,3 +5,9 @@
     copy /data/vendor/adb/adb_keys /data/misc/adb/adb_keys
     chown system shell /data/misc/adb/adb_keys
     chmod 0640 /data/misc/adb/adb_keys
+
+on property:init.svc.qemu-device-state=stopped && property:ro.boot.qemu.device_state=*
+    mkdir /data/system/devicestate/ 0755 system system
+    copy /data/vendor/devicestate/device_state_configuration.xml /data/system/devicestate/device_state_configuration.xml
+    rm /data/vendor/devicestate/device_state_configuration.xml
+    chown system system /data/system/devicestate/device_state_configuration.xml
diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml
index 119ac53..b7e54f5 100644
--- a/overlay/frameworks/base/core/res/res/values/config.xml
+++ b/overlay/frameworks/base/core/res/res/values/config.xml
@@ -57,10 +57,14 @@
     <!-- The device states (supplied by DeviceStateManager) that should be treated as folded by the
          display fold controller. -->
     <integer-array name="config_foldedDeviceStates" translatable="false">
-      <item>0</item> <!-- CLOSED -->
+      <item>1</item> <!-- CLOSED -->
     </integer-array>
 
     <!-- This device is able to support the microphone and camera global toggles. -->
     <bool name="config_supportsMicToggle">true</bool>
     <bool name="config_supportsCamToggle">true</bool>
+    <!-- Restricting eth0 -->
+    <string-array translatable="false" name="config_ethernet_interfaces">
+        <item>eth0;11,12,14;;</item>
+    </string-array>
 </resources>
diff --git a/qemu-device-state/Android.bp b/qemu-device-state/Android.bp
new file mode 100644
index 0000000..ca186e0
--- /dev/null
+++ b/qemu-device-state/Android.bp
@@ -0,0 +1,44 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// this file is used to build emulator-specific program tools
+// that should only run in the emulator.
+//
+
+package {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "device_generic_goldfish_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["device_generic_goldfish_license"],
+}
+
+cc_binary {
+    name: "qemu-device-state",
+    vendor: true,
+    srcs: [
+        "qemu-device-state.cpp",
+    ],
+    shared_libs: [
+        "libbase",
+        "liblog",
+    ],
+    static_libs: [
+        "libfstab",
+    ],
+    cflags: [
+        "-DLOG_TAG=\"qemu-device-state\"",
+    ],
+}
diff --git a/qemu-device-state/qemu-device-state.cpp b/qemu-device-state/qemu-device-state.cpp
new file mode 100644
index 0000000..f85f54f
--- /dev/null
+++ b/qemu-device-state/qemu-device-state.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* this program is used to read a set of system properties and their values
+ * from the emulator program and set them in the currently-running emulated
+ * system. It does so by connecting to the 'boot-properties' qemud service.
+ *
+ * This program should be run as root and called from
+ * /system/etc/init.ranchu.rc exclusively.
+ */
+
+#define LOG_TAG  "qemu-device-state"
+
+#define DEBUG  0
+//#define LOG_NDEBUG 0
+
+#include <fstream>
+#include <iostream>
+#include <string.h>
+
+#include <log/log.h>
+
+#if DEBUG
+#  define  DD(...)    ALOGD(__VA_ARGS__)
+#else
+#  define  DD(...)    ((void)0)
+#endif
+
+#define DEVIE_STATE_PROP "qemu.device_state"
+// init will copy over this file to
+// /data/system/devicestate/device_state_configuration.xml
+#define DEVICE_STATE_FILE "/data/vendor/devicestate/device_state_configuration.xml"
+
+extern bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val);
+
+int main(void) {
+    std::string deviceState;
+    if (!fs_mgr_get_boot_config(DEVIE_STATE_PROP, &deviceState)) {
+        ALOGV("%s bootconfig prop not set", DEVIE_STATE_PROP);
+        return 0;
+    }
+
+    std::ofstream f;
+    f.open(DEVICE_STATE_FILE);
+    if (!f.is_open()) {
+        ALOGE("Failed to open %s\n", DEVICE_STATE_FILE);
+        exit(1);
+    }
+
+    ALOGI("write to %s", DEVICE_STATE_FILE);
+    f << deviceState;
+    f.close();
+    return 0;
+}
diff --git a/sensors/multihal_sensors_qemu.cpp b/sensors/multihal_sensors_qemu.cpp
index 10bd162..f261810 100644
--- a/sensors/multihal_sensors_qemu.cpp
+++ b/sensors/multihal_sensors_qemu.cpp
@@ -222,7 +222,10 @@
     } else if (const char* values = testPrefix(buf, end, "hinge-angle0", ':')) {
         if (sscanf(values, "%f", &payload->scalar) == 1) {
             if (!approximatelyEqual(state->lastHingeAngle0Value,
-                                    payload->scalar, 0.001)) {
+                                    payload->scalar, 0.001) &&
+                // b/197586273, ignore the state tracking if system sensor
+                // service has not enabled hinge sensor
+                isSensorActive(kSensorHandleHingeAngle0)) {
                 event.timestamp = nowNs + state->timeBiasNs;
                 event.sensorHandle = kSensorHandleHingeAngle0;
                 event.sensorType = SensorType::HINGE_ANGLE;
@@ -234,7 +237,8 @@
     } else if (const char* values = testPrefix(buf, end, "hinge-angle1", ':')) {
         if (sscanf(values, "%f", &payload->scalar) == 1) {
             if (!approximatelyEqual(state->lastHingeAngle1Value,
-                                    payload->scalar, 0.001)) {
+                                    payload->scalar, 0.001) &&
+                isSensorActive(kSensorHandleHingeAngle1)) {
                 event.timestamp = nowNs + state->timeBiasNs;
                 event.sensorHandle = kSensorHandleHingeAngle1;
                 event.sensorType = SensorType::HINGE_ANGLE;
@@ -246,7 +250,8 @@
     } else if (const char* values = testPrefix(buf, end, "hinge-angle2", ':')) {
         if (sscanf(values, "%f", &payload->scalar) == 1) {
             if (!approximatelyEqual(state->lastHingeAngle2Value,
-                                    payload->scalar, 0.001)) {
+                                    payload->scalar, 0.001) &&
+                isSensorActive(kSensorHandleHingeAngle2)) {
                 event.timestamp = nowNs + state->timeBiasNs;
                 event.sensorHandle = kSensorHandleHingeAngle2;
                 event.sensorType = SensorType::HINGE_ANGLE;
diff --git a/sepolicy/common/file_contexts b/sepolicy/common/file_contexts
index aeeecbb..e259c3b 100644
--- a/sepolicy/common/file_contexts
+++ b/sepolicy/common/file_contexts
@@ -31,6 +31,7 @@
 /vendor/bin/init\.ranchu-net\.sh u:object_r:goldfish_setup_exec:s0
 /vendor/bin/init\.wifi\.sh   u:object_r:goldfish_setup_exec:s0
 /vendor/bin/qemu-adb-keys    u:object_r:qemu_adb_keys_exec:s0
+/vendor/bin/qemu-device-state u:object_r:qemu_device_state_exec:s0
 /vendor/bin/qemu-props       u:object_r:qemu_props_exec:s0
 /vendor/bin/mac80211_create_radios u:object_r:mac80211_create_radios_exec:s0
 /vendor/bin/createns         u:object_r:createns_exec:s0
diff --git a/sepolicy/common/genfs_contexts b/sepolicy/common/genfs_contexts
index 3484eae..bf5fe76 100644
--- a/sepolicy/common/genfs_contexts
+++ b/sepolicy/common/genfs_contexts
@@ -30,6 +30,13 @@
 genfscon sysfs /devices/pci0000:00/0000:00:07.0/virtio4/block/vde u:object_r:sysfs_virtio_block:s0
 genfscon sysfs /devices/pci0000:00/0000:00:08.0/virtio5/block/vdf u:object_r:sysfs_virtio_block:s0
 
+# for arm64 virtio block devices
+genfscon sysfs /devices/platform/a003600.virtio_mmio/virtio2/block/vda/stat u:object_r:sysfs_virtio_block:s0
+genfscon sysfs /devices/platform/a003800.virtio_mmio/virtio3/block/vdb/stat u:object_r:sysfs_virtio_block:s0
+genfscon sysfs /devices/platform/a003a00.virtio_mmio/virtio4/block/vdc/stat u:object_r:sysfs_virtio_block:s0
+genfscon sysfs /devices/platform/a003c00.virtio_mmio/virtio5/block/vdd/stat u:object_r:sysfs_virtio_block:s0
+genfscon sysfs /devices/platform/a003e00.virtio_mmio/virtio6/block/vde/stat u:object_r:sysfs_virtio_block:s0
+
 # /sys/class/power_supply
 genfscon sysfs /devices/platform/9020000.goldfish_battery/power_supply u:object_r:sysfs_batteryinfo:s0
 
@@ -86,6 +93,8 @@
 genfscon sysfs /devices/pnp0/00:00/rtc/rtc0/alarmtimer.0.auto/wakeup/wakeup31/event_count u:object_r:sysfs_wakeup:s0
 genfscon sysfs /devices/pnp0/00:00/rtc/rtc0/alarmtimer.0.auto/wakeup/wakeup32      u:object_r:sysfs_wakeup:s0
 genfscon sysfs /devices/pnp0/00:00/rtc/rtc0/alarmtimer.0.auto/wakeup/wakeup32/event_count u:object_r:sysfs_wakeup:s0
+genfscon sysfs /devices/pnp0/00:00/rtc/rtc0/alarmtimer.0.auto/wakeup/wakeup33      u:object_r:sysfs_wakeup:s0
+genfscon sysfs /devices/pnp0/00:00/rtc/rtc0/alarmtimer.0.auto/wakeup/wakeup33/event_count u:object_r:sysfs_wakeup:s0
 genfscon sysfs /devices/pnp0/00:00/rtc/rtc0/wakeup                                 u:object_r:sysfs_wakeup:s0
 genfscon sysfs /devices/pnp0/00:00/wakeup/wakeup                                   u:object_r:sysfs_wakeup:s0
 genfscon sysfs /devices/virtual/wakeup/wakeup                                      u:object_r:sysfs_wakeup:s0
diff --git a/sepolicy/common/property_contexts b/sepolicy/common/property_contexts
index 70d8c5c..a776b0d 100644
--- a/sepolicy/common/property_contexts
+++ b/sepolicy/common/property_contexts
@@ -3,6 +3,7 @@
 vendor.qemu.networknamespace   u:object_r:vendor_qemu_prop:s0 exact string
 vendor.qemu.logcat_filter u:object_r:vendor_qemu_prop:s0 exact string
 vendor.qemu.sf.fake_camera     u:object_r:vendor_qemu_prop:s0 exact string
+vendor.qemu.vport.bluetooth u:object_r:vendor_qemu_prop:s0 exact string
 vendor.qemu.vport.modem u:object_r:vendor_qemu_prop:s0 exact string
 vendor.qemu.vport.gnss  u:object_r:vendor_qemu_prop:s0 exact string
 vendor.qemu.timezone    u:object_r:vendor_qemu_prop:s0 exact string
diff --git a/sepolicy/common/qemu_device_state.te b/sepolicy/common/qemu_device_state.te
new file mode 100644
index 0000000..2295236
--- /dev/null
+++ b/sepolicy/common/qemu_device_state.te
@@ -0,0 +1,13 @@
+# qemu-device-state service:  Writes host adb key for adbd on boot.
+type qemu_device_state, domain;
+type qemu_device_state_exec, vendor_file_type, exec_type, file_type;
+
+init_daemon_domain(qemu_device_state)
+
+# Allow qemu_device_state to read /proc/bootconfig
+allow qemu_device_state proc_cmdline:file r_file_perms;
+allow qemu_device_state proc_bootconfig:file r_file_perms;
+
+# Permission to write to /data/vendor/system/devicestate.
+allow qemu_device_state vendor_data_file:dir create_dir_perms;
+allow qemu_device_state vendor_data_file:file create_file_perms;
diff --git a/sepolicy/common/shell.te b/sepolicy/common/shell.te
index 9eba714..e3ac86c 100644
--- a/sepolicy/common/shell.te
+++ b/sepolicy/common/shell.te
@@ -2,3 +2,6 @@
 allow shell aac_drc_prop:file { getattr map open };
 allow shell device_config_runtime_native_boot_prop:file { getattr map open read };
 allow shell adbd:{ socket vsock_socket } rw_socket_perms_no_ioctl;
+
+# Allow shell to read qemu.sf.lcd_density for CTS.
+get_prop(shell, qemu_sf_lcd_density_prop)
diff --git a/vendor.mk b/vendor.mk
index fa4a3e0..fe00dfc 100644
--- a/vendor.mk
+++ b/vendor.mk
@@ -42,6 +42,7 @@
     libcuttlefish-ril-2 \
     libgoldfish-rild \
     qemu-adb-keys \
+    qemu-device-state \
     qemu-props \
     stagefright \
     fingerprint.ranchu \
@@ -81,8 +82,7 @@
     libGLESv1_enc \
     libEGL_angle \
     libGLESv1_CM_angle \
-    libGLESv2_angle \
-    libfeature_support_angle.so
+    libGLESv2_angle
 endif
 
 PRODUCT_PACKAGES += \
@@ -267,6 +267,7 @@
 
 PRODUCT_COPY_FILES += \
     device/generic/goldfish/data/etc/dtb.img:dtb.img \
+    device/generic/goldfish/emulator-info.txt:data/misc/emulator/version.txt \
     device/generic/goldfish/data/etc/apns-conf.xml:data/misc/apns/apns-conf.xml \
     device/generic/goldfish/radio/RadioConfig/radioconfig.xml:data/misc/emulator/config/radioconfig.xml \
     device/generic/goldfish/data/etc/iccprofile_for_sim0.xml:data/misc/modem_simulator/iccprofile_for_sim0.xml \
@@ -297,7 +298,6 @@
     device/generic/goldfish/input/virtio_input_multi_touch_11.idc:$(TARGET_COPY_OUT_VENDOR)/usr/idc/virtio_input_multi_touch_11.idc \
     device/generic/goldfish/display_settings_freeform.xml:$(TARGET_COPY_OUT_VENDOR)/etc/display_settings_freeform.xml \
     device/generic/goldfish/display_settings.xml:$(TARGET_COPY_OUT_VENDOR)/etc/display_settings.xml \
-    device/generic/goldfish/device_state_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/devicestate/device_state_configuration.xml \
     device/generic/goldfish/data/etc/config.ini:config.ini \
     device/generic/goldfish/wifi/simulated_hostapd.conf:$(TARGET_COPY_OUT_VENDOR)/etc/simulated_hostapd.conf \
     device/generic/goldfish/wifi/wpa_supplicant.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wifi/wpa_supplicant.conf \
@@ -325,8 +325,8 @@
     frameworks/native/data/etc/android.hardware.vulkan.level-1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.level.xml \
     frameworks/native/data/etc/android.hardware.vulkan.compute-0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.compute.xml \
     frameworks/native/data/etc/android.hardware.vulkan.version-1_1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml \
-    frameworks/native/data/etc/android.software.vulkan.deqp.level-2020-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \
-    frameworks/native/data/etc/android.software.opengles.deqp.level-2020-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml \
+    frameworks/native/data/etc/android.software.vulkan.deqp.level-2021-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \
+    frameworks/native/data/etc/android.software.opengles.deqp.level-2021-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml \
     frameworks/native/data/etc/android.software.autofill.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.autofill.xml \
     frameworks/native/data/etc/android.software.verified_boot.xml:${TARGET_COPY_OUT_PRODUCT}/etc/permissions/android.software.verified_boot.xml \
     device/generic/goldfish/data/etc/permissions/privapp-permissions-goldfish.xml:$(TARGET_COPY_OUT_PRODUCT)/etc/permissions/privapp-permissions-goldfish.xml \