Revert "gs101: Enable SkiaVk as RenderEngine backend" am: 36c9c135fd am: cbb7eda2fb

Original change: https://googleplex-android-review.googlesource.com/c/device/google/gs101/+/24866271

Change-Id: Ia866558f36426477768058ba393ef11e91002b22
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/device.mk b/device.mk
index 6db1d36..0795d06 100644
--- a/device.mk
+++ b/device.mk
@@ -21,7 +21,8 @@
 include device/google/gs-common/soc/freq.mk
 include device/google/gs-common/modem/modem.mk
 include device/google/gs-common/aoc/aoc.mk
-include device/google/gs-common/thermal/thermal.mk
+include device/google/gs-common/thermal/dump/thermal.mk
+include device/google/gs-common/thermal/thermal_hal/device.mk
 include device/google/gs-common/pixel_metrics/pixel_metrics.mk
 include device/google/gs-common/performance/perf.mk
 include device/google/gs-common/display/dump.mk
@@ -200,6 +201,7 @@
 
 $(call soong_config_set,pixel_mali,soc,$(TARGET_BOARD_PLATFORM))
 
+include device/google/gs-common/gpu/gpu.mk
 PRODUCT_PACKAGES += \
 	libGLES_mali \
 	vulkan.mali \
@@ -846,10 +848,6 @@
 PRODUCT_PRODUCT_PROPERTIES += \
 	persist.sys.fuse.passthrough.enable=true
 
-# Use FUSE BPF
-PRODUCT_PRODUCT_PROPERTIES += \
-	ro.fuse.bpf.enabled=true
-
 # Use /product/etc/fstab.postinstall to mount system_other
 PRODUCT_PRODUCT_PROPERTIES += \
 	ro.postinstall.fstab.prefix=/product
@@ -892,10 +890,8 @@
 
 $(call inherit-product-if-exists, vendor/samsung_slsi/telephony/$(BOARD_USES_SHARED_VENDOR_TELEPHONY)/shannon-iwlan/device-vendor.mk)
 
-#RCS Test Messaging App
 PRODUCT_PACKAGES_DEBUG += \
-	preinstalled-packages-product-gs101-device-debug.xml \
-	TestRcsApp
+	preinstalled-packages-product-gs101-device-debug.xml
 
 PRODUCT_PACKAGES += ShannonRcs
 endif
@@ -969,9 +965,6 @@
 PRODUCT_COPY_FILES += \
 	device/google/gs101/radio/gnss_blanking.csv:$(TARGET_COPY_OUT_VENDOR)/etc/modem/gnss_blanking.csv
 
-# ARM NN files
-ARMNN_COMPUTE_CL_ENABLE := 1
-
 # Vibrator Diag
 PRODUCT_PACKAGES_DEBUG += \
 	diag-vibrator \
@@ -1038,7 +1031,6 @@
 	libgc2_utils
 
 # Thermal HAL
-include hardware/google/pixel/thermal/device.mk
 PRODUCT_PROPERTY_OVERRIDES += persist.vendor.enable.thermal.genl=true
 
 # EdgeTPU
diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml
index 732338c..5f8e283 100644
--- a/device_framework_matrix_product.xml
+++ b/device_framework_matrix_product.xml
@@ -42,7 +42,7 @@
     </hal>
     <hal format="aidl" optional="true">
       <name>com.google.face.debug</name>
-      <version>4</version>
+      <version>3-4</version>
         <interface>
             <name>IDebugHost</name>
             <instance>default</instance>
@@ -69,6 +69,14 @@
         </interface>
     </hal>
     <hal format="aidl" optional="true">
+        <name>com.google.edgetpu.tachyon</name>
+        <version>1</version>
+        <interface>
+            <name>IComputeService</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="aidl" optional="true">
       <name>com.google.hardware.pixel.display</name>
         <version>9</version>
         <interface>
@@ -118,7 +126,7 @@
     </hal>
     <hal format="aidl" optional="true">
         <name>vendor.google.wifi_ext</name>
-        <version>1</version>
+        <version>2-3</version>
         <interface>
             <name>IWifiExt</name>
             <instance>default</instance>
@@ -134,6 +142,13 @@
             <instance>sced0</instance>
         </interface>
     </hal>
+    <hal format="aidl" optional="true">
+        <name>com.google.pixel.modem.logmasklibrary</name>
+        <interface>
+            <name>ILiboemserviceProxy</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
     <hal format="hidl" optional="true">
         <name>vendor.samsung_slsi.telephony.hardware.radioExternal</name>
         <version>1.1</version>
diff --git a/fingerprint/udfps_common.mk b/fingerprint/udfps_common.mk
deleted file mode 100644
index 5808856..0000000
--- a/fingerprint/udfps_common.mk
+++ /dev/null
@@ -1,35 +0,0 @@
-#
-# Copyright (C) 2020 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.
-#
-
-# Fingerprint manifest
-ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT)))
-DEVICE_MANIFEST_FILE += \
-    device/google/gs101/fingerprint/vendor.goodix.hardware.biometrics.fingerprint@2.1-service.xml
-endif
-
-# Include the Goodix AIDL HAL namespaces.
-PRODUCT_SOONG_NAMESPACES += vendor/goodix/udfps/fp_utils
-ifeq ($(GOODIX_CONFIG_BUILD_VERSION), g6_trusty)
-PRODUCT_SOONG_NAMESPACES += vendor/goodix/udfps/g6_trusty
-PRODUCT_SOONG_NAMESPACES += vendor/goodix/udfps/g6_aidl_trusty
-else ifeq ($(GOODIX_CONFIG_BUILD_VERSION), g7_trusty)
-PRODUCT_SOONG_NAMESPACES += vendor/goodix/udfps/g7_trusty
-PRODUCT_SOONG_NAMESPACES += vendor/goodix/udfps/g7_aidl_trusty
-else
-$(error Invalid udfps build version)
-endif
-
-$(call soong_config_set,fp_hal_feature,biometric_suez_support,true)
diff --git a/fingerprint/udfps_factory.mk b/fingerprint/udfps_factory.mk
deleted file mode 100644
index de831e4..0000000
--- a/fingerprint/udfps_factory.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-#
-# Copyright (C) 2020 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.
-#
-
-PRODUCT_PACKAGES += \
-    android.hardware.biometrics.fingerprint@2.1-service.goodix \
-    GF_delmar_factory \
-    udfps_test
-
-DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE += device/google/gs101/fingerprint/compatibility_matrix_factory.xml
-
-PRODUCT_PROPERTY_OVERRIDES += \
-    gf.debug.dump_data=1
diff --git a/fingerprint/udfps_shipping.mk b/fingerprint/udfps_shipping.mk
deleted file mode 100644
index c8203b1..0000000
--- a/fingerprint/udfps_shipping.mk
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# 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.
-#
-
-PRODUCT_COPY_FILES += \
-    frameworks/native/data/etc/android.hardware.fingerprint.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.fingerprint.xml
-
-PRODUCT_PACKAGES += \
-    android.hardware.biometrics.fingerprint-service.goodix
diff --git a/fingerprint/vendor.goodix.hardware.biometrics.fingerprint@2.1-service.xml b/fingerprint/vendor.goodix.hardware.biometrics.fingerprint@2.1-service.xml
deleted file mode 100644
index e42448f..0000000
--- a/fingerprint/vendor.goodix.hardware.biometrics.fingerprint@2.1-service.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<manifest version="1.0" type="device">
-  <hal format="hidl">
-    <name>vendor.goodix.hardware.biometrics.fingerprint</name>
-    <transport>hwbinder</transport>
-    <version>2.1</version>
-    <interface>
-      <name>IGoodixFingerprintDaemon</name>
-      <instance>default</instance>
-    </interface>
-  </hal>
-</manifest>
diff --git a/preinstalled-packages-product-gs101-device-debug.xml b/preinstalled-packages-product-gs101-device-debug.xml
index 64524bc..88204bc 100644
--- a/preinstalled-packages-product-gs101-device-debug.xml
+++ b/preinstalled-packages-product-gs101-device-debug.xml
@@ -22,14 +22,6 @@
         <install-in user-type="FULL" />
         <install-in user-type="PROFILE" />
         <do-not-install-in user-type="android.os.usertype.profile.CLONE" />
-    </install-in-user-type>
-
-    <!-- RCS - Rich Communication Services (TestRcsApp)
-    TODO(b/259401601): Check if this should be preinstalled for SYSTEM user -->
-    <install-in-user-type package="com.google.android.sample.rcsclient">
-        <install-in user-type="SYSTEM" />
-        <install-in user-type="FULL" />
-        <install-in user-type="PROFILE" />
-        <do-not-install-in user-type="android.os.usertype.profile.CLONE" />
+        <do-not-install-in user-type="android.os.usertype.profile.PRIVATE" />
     </install-in-user-type>
 </config>
diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp
index 7a14888..c2f15c7 100644
--- a/usb/usb/Usb.cpp
+++ b/usb/usb/Usb.cpp
@@ -81,10 +81,15 @@
 constexpr char kPogoUsbActive[] = "/sys/devices/platform/google,pogo/pogo_usb_active";
 constexpr char KPogoMoveDataToUsb[] = "/sys/devices/platform/google,pogo/move_data_to_usb";
 constexpr char kPowerSupplyUsbType[] = "/sys/class/power_supply/usb/usb_type";
+constexpr char kUdcState[] = "/sys/devices/platform/11110000.usb/11110000.dwc3/udc/11110000.dwc3/state";
+// xhci-hcd-exynos and usb device numbering could vary on different platforms
+constexpr char kHostUeventRegex[] = "^(bind|unbind)@(/devices/platform/11110000\\.usb/11110000\\.dwc3/xhci-hcd-exynos\\.[0-9]\\.auto/)usb([0-9])/[0-9]-0:1\\.0";
 constexpr int kSamplingIntervalSec = 5;
 void queryVersionHelper(android::hardware::usb::Usb *usb,
                         std::vector<PortStatus> *currentPortStatus);
 
+#define USB_STATE_MAX_LEN 20
+
 ScopedAStatus Usb::enableUsbData(const string& in_portName, bool in_enable,
         int64_t in_transactionId) {
     bool result = true;
@@ -907,17 +912,113 @@
     }
 }
 
-struct data {
-    int uevent_fd;
-    ::aidl::android::hardware::usb::Usb *usb;
-};
+static void unregisterEpollEntry(Usb *usb, std::string name) {
+    std::map<std::string, struct Usb::epollEntry> *map;
+    int fd;
 
-static void uevent_event(uint32_t /*epevents*/, struct data *payload) {
+    map = &usb->mEpollEntries;
+    auto it = map->find(name);
+    if (it != map->end()) {
+        ALOGI("epoll unregister %s", name.c_str());
+        fd = it->second.payload.fd;
+        epoll_ctl(usb->mEpollFd, EPOLL_CTL_DEL, fd, NULL);
+        close(fd);
+        map->erase(it);
+    }
+}
+
+static void unregisterEpollEntries(Usb *usb) {
+    std::map<std::string, struct Usb::epollEntry> *map;
+    std::string name;
+
+    map = &usb->mEpollEntries;
+    for (auto it = map->begin(); it != map->end();) {
+        name = it->first;
+        it++;
+        unregisterEpollEntry(usb, name);
+    }
+}
+
+static int registerEpollEntry(Usb *usb, std::string name, int fd, int flags,
+                              void (*func)(uint32_t, struct Usb::payload*)) {
+    std::map<std::string, struct Usb::epollEntry> *map;
+    struct Usb::epollEntry *entry;
+    struct epoll_event ev;
+
+    map = &usb->mEpollEntries;
+    if (map->find(name) != map->end()) {
+        ALOGE("%s already registered", name.c_str());
+        unregisterEpollEntry(usb, name);
+    }
+
+    entry = &(*map)[name];
+    entry->payload.fd = fd;
+    entry->payload.name = name;
+    entry->payload.usb = usb;
+    entry->cb = std::bind(func, std::placeholders::_1, &entry->payload);
+
+    ev.events = flags;
+    ev.data.ptr = (void *)&entry->cb;
+
+    if (epoll_ctl(usb->mEpollFd, EPOLL_CTL_ADD, fd, &ev) != 0) {
+        ALOGE("epoll_ctl failed; errno=%d", errno);
+        unregisterEpollEntry(usb, name);
+        return -1;
+    }
+
+    ALOGI("epoll register %s", name.c_str());
+
+    return 0;
+}
+
+static int registerEpollEntryByFile(Usb *usb, std::string name, int flags,
+                              void (*func)(uint32_t, struct Usb::payload*)) {
+    int fd;
+
+    fd = open(name.c_str(), O_RDONLY);
+    if (fd < 0) {
+        ALOGE("Cannot open %s", name.c_str());
+        return -1;
+    }
+
+    return registerEpollEntry(usb, name, fd, flags, func);
+}
+
+static void clearUsbDeviceState(struct Usb::usbDeviceState *device) {
+    device->latestState.clear();
+    device->portResetCount = 0;
+}
+
+static void updateUsbDeviceState(struct Usb::usbDeviceState *device, char *state) {
+    ALOGI("Update USB device state: %s", state);
+
+    device->latestState = state;
+
+    if (!std::strcmp(state, "configured\n")) {
+        device->portResetCount = 0;
+    } else if (!std::strcmp(state, "default\n")) {
+        device->portResetCount++;
+    }
+}
+
+static void host_event(uint32_t /*epevents*/, struct Usb::payload *payload) {
+    int n;
+    char state[USB_STATE_MAX_LEN] = {0};
+    struct Usb::usbDeviceState *device;
+
+    lseek(payload->fd, 0, SEEK_SET);
+    n = read(payload->fd, &state, USB_STATE_MAX_LEN);
+
+    updateUsbDeviceState(&payload->usb->mHostStateMap[payload->name], state);
+}
+
+static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) {
     char msg[UEVENT_MSG_LEN + 2];
     char *cp;
     int n;
+    std::cmatch match;
 
-    n = uevent_kernel_multicast_recv(payload->uevent_fd, msg, UEVENT_MSG_LEN);
+    n = uevent_kernel_multicast_recv(payload->fd, msg, UEVENT_MSG_LEN);
     if (n <= 0)
         return;
     if (n >= UEVENT_MSG_LEN) /* overflow -- discard */
@@ -963,6 +1064,29 @@
         } else if (!strncmp(cp, kOverheatStatsDev, strlen(kOverheatStatsDev))) {
             ALOGV("Overheat Cooling device suez update");
             report_overheat_event(payload->usb);
+        } else if (std::regex_match(cp, match, std::regex(kHostUeventRegex))) {
+            /*
+             * Matched strings:
+             * 1st: entire string
+             * 2nd: uevent action, either "bind" or "unbind"
+             * 3rd: xhci device path, e.g. devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto
+             * 4th: usb device number, e.g. 1 for usb1
+             *
+             * The strings are used to composed usb device state path, e.g.
+             * /sys/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto/usb2/2-0:1.0/usb2-port1/state
+             */
+            if (match.size() == 4) {
+                std::string action = match[1].str();
+                std::string id = match[3].str();
+                std::string path = "/sys" + match[2].str() + "usb" + id + "/" +
+                                   id + "-0:1.0/usb" + id + "-port1/state";
+                if (action == "bind") {
+                    registerEpollEntryByFile(payload->usb, path, EPOLLPRI, host_event);
+                } else if (action == "unbind") {
+                    unregisterEpollEntry(payload->usb, path);
+                    clearUsbDeviceState(&payload->usb->mHostStateMap[path]);
+                }
+            }
         }
         /* advance to after the next \0 */
         while (*cp++) {
@@ -970,37 +1094,46 @@
     }
 }
 
+static void udc_event(uint32_t /*epevents*/, struct Usb::payload *payload) {
+    int n;
+    char state[USB_STATE_MAX_LEN] = {0};
+
+    lseek(payload->fd, 0, SEEK_SET);
+    n = read(payload->fd, &state, USB_STATE_MAX_LEN);
+
+    updateUsbDeviceState(&payload->usb->mDeviceState, state);
+}
+
 void *work(void *param) {
     int epoll_fd, uevent_fd;
-    struct epoll_event ev;
     int nevents = 0;
-    struct data payload;
+    Usb *usb = (Usb *)param;
 
     ALOGE("creating thread");
 
-    uevent_fd = uevent_open_socket(64 * 1024, true);
-
-    if (uevent_fd < 0) {
-        ALOGE("uevent_init: uevent_open_socket failed\n");
-        return NULL;
-    }
-
-    payload.uevent_fd = uevent_fd;
-    payload.usb = (::aidl::android::hardware::usb::Usb *)param;
-
-    fcntl(uevent_fd, F_SETFL, O_NONBLOCK);
-
-    ev.events = EPOLLIN;
-    ev.data.ptr = (void *)uevent_event;
-
     epoll_fd = epoll_create(64);
     if (epoll_fd == -1) {
         ALOGE("epoll_create failed; errno=%d", errno);
+        return NULL;
+    }
+    usb->mEpollFd = epoll_fd;
+
+    // Monitor uevent
+    uevent_fd = uevent_open_socket(64 * 1024, true);
+    if (uevent_fd < 0) {
+        ALOGE("uevent_init: uevent_open_socket failed");
+        goto error;
+    }
+    fcntl(uevent_fd, F_SETFL, O_NONBLOCK);
+
+    if (registerEpollEntry(usb, "uevent", uevent_fd, EPOLLIN, uevent_event)) {
+        ALOGE("failed to monitor uevent");
         goto error;
     }
 
-    if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, uevent_fd, &ev) == -1) {
-        ALOGE("epoll_ctl failed; errno=%d", errno);
+    // Monitor udc state
+    if (registerEpollEntryByFile(usb, kUdcState, EPOLLPRI, udc_event)) {
+        ALOGE("failed to monitor udc state");
         goto error;
     }
 
@@ -1017,14 +1150,15 @@
 
         for (int n = 0; n < nevents; ++n) {
             if (events[n].data.ptr)
-                (*(void (*)(int, struct data *payload))events[n].data.ptr)(events[n].events,
-                                                                           &payload);
+                (*(std::function<void(uint32_t)>*)events[n].data.ptr)(events[n].events);
         }
     }
 
     ALOGI("exiting worker thread");
 error:
-    close(uevent_fd);
+    unregisterEpollEntries(usb);
+
+    usb->mEpollFd = -1;
 
     if (epoll_fd >= 0)
         close(epoll_fd);
diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h
index 1a93e19..aa8a149 100644
--- a/usb/usb/Usb.h
+++ b/usb/usb/Usb.h
@@ -89,6 +89,29 @@
     float mPluggedTemperatureCelsius;
     // Usb Data status
     bool mUsbDataEnabled;
+
+    // USB device state monitoring
+    struct usbDeviceState {
+        std::string latestState;
+        int portResetCount;
+    };
+    struct usbDeviceState mDeviceState;
+    // Map host device path name to usbDeviceState
+    std::map<std::string, struct usbDeviceState> mHostStateMap;
+
+    // File monitoring through epoll
+    int mEpollFd;
+    struct payload {
+        int fd;
+        std::string name;
+        Usb *usb;
+     };
+    struct epollEntry {
+         struct payload payload;
+         std::function<void(uint32_t)> cb;
+    };
+    std::map<std::string, struct epollEntry> mEpollEntries;
+
   private:
     pthread_t mPoll;
 };