Merge tag 'android-13.0.0_r52' into int/13/fp3

Android 13.0.0 Release 52 (TQ3A.230605.012)

* tag 'android-13.0.0_r52': (80 commits)
  Camera: Fix VTS failure for depth only camera
  Camera: VTS: Wait for release fence before consuming buffers
  VTS add length is not zero check for executeSetClientTarget
  [DO NOT MERGE] Add group 'uhid' to sensors multi-HAL.
  Fix crash issue on test case RadioHidlTest_v1_5#startNetworkScan.
  Throw away initial measurements before interval tests
  Used LTE bands for network scan
  Sensor:Add sensor type HINGE_ANGLE to function assertTypeMatchStringType
  Fix for VTS test CleanupConnectionsOnInitialize
  identity: VTS: allow for multiple interpretations of AuthKey validity.
  Add ATSC support in the vts
  Add REQUEST_NOT_SUPPORTED and INVALID_ARGUMENTS to be allowed.
  Fix google vts dead lock
  identity: VTS: allow for multiple interpretations of AuthKey validity.
  Fix epoll leaks: clean up file descriptor and epoll instance properly
  Patch for VTS
  VtsHalMediaOmx: fix OmxCodecAllowedTest to match requirement
  audio: Remove InputStreamTest#getCapturePosition test
  Camera VTS: Override RotateAndCrop metadata
  VHAL for PERF_VEHICLE_SPEED_DISPLAY.
  ...

Change-Id: If9501924af1d9924f6a8d4f2aa1b714b0a6bc04b
diff --git a/biometrics/fingerprint/2.1/default/BiometricsFingerprint.cpp b/biometrics/fingerprint/2.1/default/BiometricsFingerprint.cpp
index f687959..d12dce8 100644
--- a/biometrics/fingerprint/2.1/default/BiometricsFingerprint.cpp
+++ b/biometrics/fingerprint/2.1/default/BiometricsFingerprint.cpp
@@ -257,6 +257,53 @@
     return fp_device;
 }
 
+namespace {
+
+struct notified_fingerprint {
+    notified_fingerprint()
+        : devId{ 0 }
+        , msg{ nullptr }
+        , fp{}
+    {
+    }
+    uint64_t devId;
+    const fingerprint_msg_t *msg;
+    fingerprint_enumerated_t fp;
+};
+
+// Helper for fixing up same fingerprint enumerated twice
+//
+// The FP3 fingerprint device implementation and enumerates the last fingerprint
+// in the list twice. The Android framework does not expect this, considers it
+// as "unknown" for second enumeration and discards it.
+//
+// Discard duplicated messages. To be on the safe side, compare all information
+// (and data pointers) we have.
+bool is_same_fingerprint_as_last_enumerate(
+    const uint64_t devId,
+    const fingerprint_msg_t *msg,
+    const fingerprint_enumerated_t fp)
+{
+    static notified_fingerprint last_fingerprint{};
+
+    const bool is_same =
+        devId == last_fingerprint.devId
+        && msg == last_fingerprint.msg
+        && fp.finger.gid == last_fingerprint.fp.finger.gid
+        && fp.finger.fid == last_fingerprint.fp.finger.fid
+        && fp.remaining_templates == last_fingerprint.fp.remaining_templates;
+
+    last_fingerprint.devId = devId;
+    last_fingerprint.msg = msg;
+    last_fingerprint.fp.finger.gid = fp.finger.gid;
+    last_fingerprint.fp.finger.fid = fp.finger.fid;
+    last_fingerprint.fp.remaining_templates = fp.remaining_templates;
+
+    return is_same;
+}
+
+}
+
 void BiometricsFingerprint::notify(const fingerprint_msg_t *msg) {
     BiometricsFingerprint* thisPtr = static_cast<BiometricsFingerprint*>(
             BiometricsFingerprint::getInstance());
@@ -340,6 +387,10 @@
                 msg->data.enumerated.finger.fid,
                 msg->data.enumerated.finger.gid,
                 msg->data.enumerated.remaining_templates);
+            if (is_same_fingerprint_as_last_enumerate(devId, msg, msg->data.enumerated)) {
+                ALOGW("Fingerprint device enumerated same fingerprint again. Dropping event.");
+                break;
+            }
             if (!thisPtr->mClientCallback->onEnumerate(devId,
                     msg->data.enumerated.finger.fid,
                     msg->data.enumerated.finger.gid,
diff --git a/graphics/composer/2.1/default/android.hardware.graphics.composer@2.1-service.rc b/graphics/composer/2.1/default/android.hardware.graphics.composer@2.1-service.rc
index c8fccdc..bed81d6 100644
--- a/graphics/composer/2.1/default/android.hardware.graphics.composer@2.1-service.rc
+++ b/graphics/composer/2.1/default/android.hardware.graphics.composer@2.1-service.rc
@@ -1,5 +1,6 @@
 service vendor.hwcomposer-2-1 /vendor/bin/hw/android.hardware.graphics.composer@2.1-service
     interface android.hardware.graphics.composer@2.1::IComposer default
+    interface vendor.display.config@2.0::IDisplayConfig default
     class hal animation
     user system
     group graphics drmrpc
diff --git a/graphics/mapper/2.0/utils/passthrough/include/mapper-passthrough/2.0/Gralloc1Hal.h b/graphics/mapper/2.0/utils/passthrough/include/mapper-passthrough/2.0/Gralloc1Hal.h
index db7e67d..5f0a176 100644
--- a/graphics/mapper/2.0/utils/passthrough/include/mapper-passthrough/2.0/Gralloc1Hal.h
+++ b/graphics/mapper/2.0/utils/passthrough/include/mapper-passthrough/2.0/Gralloc1Hal.h
@@ -259,19 +259,22 @@
 
         for (int i = 0; i < 3; i++) {
             const auto& plane = flex.planes[i];
-            // must have 8-bit depth
-            if (plane.bits_per_component != 8 || plane.bits_used != 8) {
+            // Must be a positive multiple of 8.
+            if (plane.bits_per_component <= 0 || (plane.bits_per_component % 8) != 0) {
                 return false;
             }
-
+            // Must be between 1 and bits_per_component, inclusive.
+            if (plane.bits_used < 1 || plane.bits_used > plane.bits_per_component) {
+                return false;
+            }
             if (plane.component == FLEX_COMPONENT_Y) {
                 // Y must not be interleaved
-                if (plane.h_increment != 1) {
+                if (plane.h_increment != 1 && plane.h_increment != 2) {
                     return false;
                 }
             } else {
                 // Cb and Cr can be interleaved
-                if (plane.h_increment != 1 && plane.h_increment != 2) {
+                if (plane.h_increment != 1 && plane.h_increment != 2 && plane.h_increment != 4) {
                     return false;
                 }
             }
diff --git a/wifi/1.6/default/hidl_struct_util.cpp b/wifi/1.6/default/hidl_struct_util.cpp
index 2112b26..96d920a 100644
--- a/wifi/1.6/default/hidl_struct_util.cpp
+++ b/wifi/1.6/default/hidl_struct_util.cpp
@@ -156,10 +156,8 @@
         }
     }
 
-    // There are no flags for these 3 in the legacy feature set. Adding them to
+    // There are no flags for these in the legacy feature set. Adding this to
     // the set because all the current devices support it.
-    *hidl_caps |= HidlChipCaps::DEBUG_RING_BUFFER_VENDOR_DATA;
-    *hidl_caps |= HidlChipCaps::DEBUG_HOST_WAKE_REASON_STATS;
     *hidl_caps |= HidlChipCaps::DEBUG_ERROR_ALERTS;
     return true;
 }
diff --git a/wifi/1.6/default/wifi_chip.cpp b/wifi/1.6/default/wifi_chip.cpp
index c7c00b1..6789d6d 100644
--- a/wifi/1.6/default/wifi_chip.cpp
+++ b/wifi/1.6/default/wifi_chip.cpp
@@ -22,6 +22,7 @@
 #include <net/if.h>
 #include <sys/stat.h>
 #include <sys/sysmacros.h>
+#include <net/if.h>
 
 #include "hidl_return_util.h"
 #include "hidl_struct_util.h"
@@ -735,7 +736,36 @@
                            &WifiChip::getAvailableModesInternal_1_6, hidl_status_cb);
 }
 
+void WifiChip::QcRemoveAndClearDynamicIfaces() {
+    for (const auto& iface : created_ap_ifaces_) {
+        std::string ifname = iface->getName();
+        legacy_hal::wifi_error legacy_status =
+            legacy_hal_.lock()->deleteVirtualInterface(ifname);
+        if (legacy_status != legacy_hal::WIFI_SUCCESS) {
+            LOG(ERROR) << "Failed to remove interface: " << ifname << " "
+                       << legacyErrorToString(legacy_status);
+        }
+    }
+
+    for (const auto& iface : created_sta_ifaces_) {
+        std::string ifname = iface->getName();
+        legacy_hal::wifi_error legacy_status =
+            legacy_hal_.lock()->deleteVirtualInterface(ifname);
+        if (legacy_status != legacy_hal::WIFI_SUCCESS) {
+            LOG(ERROR) << "Failed to remove interface: " << ifname << " "
+                       << legacyErrorToString(legacy_status);
+        }
+    }
+
+    // created_ap/sta_ifaces are also part of sta/ap_ifaces.
+    // Do no invalidate here.
+
+    created_ap_ifaces_.clear();
+    created_sta_ifaces_.clear();
+}
+
 void WifiChip::invalidateAndRemoveAllIfaces() {
+    QcRemoveAndClearDynamicIfaces();
     invalidateAndClearBridgedApAll();
     invalidateAndClearAll(ap_ifaces_);
     invalidateAndClearAll(nan_ifaces_);
@@ -970,12 +1000,17 @@
     if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::AP)) {
         return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
     }
+    bool iface_created = false;
     std::string ifname = allocateApIfaceName();
-    WifiStatus status = createVirtualApInterface(ifname);
-    if (status.code != WifiStatusCode::SUCCESS) {
-        return {status, {}};
+    if (!if_nametoindex(ifname.c_str())) {
+        WifiStatus status = createVirtualApInterface(ifname);
+        if (status.code != WifiStatusCode::SUCCESS) {
+            return {status, {}};
+        }
+        iface_created = true;
     }
     sp<WifiApIface> iface = newWifiApIface(ifname);
+    if (iface_created) created_ap_ifaces_.push_back(iface);
     return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
 }
 
@@ -1044,7 +1079,9 @@
     // nan/rtt objects over AP iface. But, there is no harm to do it
     // here and not make that assumption all over the place.
     invalidateAndRemoveDependencies(ifname);
-    deleteApIface(ifname);
+    if (findUsingName(created_ap_ifaces_, ifname) != nullptr) {
+        invalidateAndClear(created_ap_ifaces_, iface);
+    }
     invalidateAndClear(ap_ifaces_, iface);
     for (const auto& callback : event_cb_handler_.getCallbacks()) {
         if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) {
@@ -1195,16 +1232,23 @@
     if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::STA)) {
         return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
     }
+    bool iface_created = false;
     std::string ifname = allocateStaIfaceName();
-    legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->createVirtualInterface(
-            ifname, hidl_struct_util::convertHidlIfaceTypeToLegacy(IfaceType::STA));
-    if (legacy_status != legacy_hal::WIFI_SUCCESS) {
-        LOG(ERROR) << "Failed to add interface: " << ifname << " "
-                   << legacyErrorToString(legacy_status);
-        return {createWifiStatusFromLegacyError(legacy_status), {}};
+    if (!if_nametoindex(ifname.c_str())) {
+        legacy_hal::wifi_error legacy_status =
+            legacy_hal_.lock()->createVirtualInterface(
+                ifname,
+                hidl_struct_util::convertHidlIfaceTypeToLegacy(IfaceType::STA));
+        if (legacy_status != legacy_hal::WIFI_SUCCESS) {
+            LOG(ERROR) << "Failed to add interface: " << ifname << " "
+                       << legacyErrorToString(legacy_status);
+            return {createWifiStatusFromLegacyError(legacy_status), {}};
+        }
+        iface_created = true;
     }
     sp<WifiStaIface> iface = new WifiStaIface(ifname, legacy_hal_, iface_util_);
     sta_ifaces_.push_back(iface);
+    if (iface_created) created_sta_ifaces_.push_back(iface);
     for (const auto& callback : event_cb_handler_.getCallbacks()) {
         if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) {
             LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
@@ -1237,10 +1281,14 @@
     }
     // Invalidate & remove any dependent objects first.
     invalidateAndRemoveDependencies(ifname);
-    legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->deleteVirtualInterface(ifname);
-    if (legacy_status != legacy_hal::WIFI_SUCCESS) {
-        LOG(ERROR) << "Failed to remove interface: " << ifname << " "
-                   << legacyErrorToString(legacy_status);
+    if (findUsingName(created_sta_ifaces_, ifname) != nullptr) {
+        legacy_hal::wifi_error legacy_status =
+            legacy_hal_.lock()->deleteVirtualInterface(ifname);
+        if (legacy_status != legacy_hal::WIFI_SUCCESS) {
+            LOG(ERROR) << "Failed to remove interface: " << ifname << " "
+                       << legacyErrorToString(legacy_status);
+        }
+        invalidateAndClear(created_sta_ifaces_, iface);
     }
     invalidateAndClear(sta_ifaces_, iface);
     for (const auto& callback : event_cb_handler_.getCallbacks()) {
@@ -1923,7 +1971,7 @@
 }
 
 // AP iface names start with idx 1 for modes supporting
-// concurrent STA and not dual AP, else start with idx 0.
+// concurrent STA, else start with idx 0.
 std::string WifiChip::allocateApIfaceName() {
     // Check if we have a dedicated iface for AP.
     std::vector<std::string> ifnames = getPredefinedApIfaceNames(false);
diff --git a/wifi/1.6/default/wifi_chip.h b/wifi/1.6/default/wifi_chip.h
index e8ddaa6..27baf3d 100644
--- a/wifi/1.6/default/wifi_chip.h
+++ b/wifi/1.6/default/wifi_chip.h
@@ -275,6 +275,7 @@
     void deleteApIface(const std::string& if_name);
     bool findUsingNameFromBridgedApInstances(const std::string& name);
     WifiStatus triggerSubsystemRestartInternal();
+    void QcRemoveAndClearDynamicIfaces();
     std::pair<WifiStatus, sp<V1_6::IWifiRttController>> createRttControllerInternal_1_6(
             const sp<IWifiIface>& bound_iface);
     std::pair<WifiStatus, std::vector<V1_6::WifiUsableChannel>> getUsableChannelsInternal_1_6(
@@ -305,6 +306,10 @@
 
     const std::function<void(const std::string&)> subsystemCallbackHandler_;
     std::map<std::string, std::vector<std::string>> br_ifaces_ap_instances_;
+
+    std::vector<sp<WifiApIface>> created_ap_ifaces_;
+    std::vector<sp<WifiStaIface>> created_sta_ifaces_;
+
     DISALLOW_COPY_AND_ASSIGN(WifiChip);
 };