Merge "Add vendor_dlkm partition (2nd attempt)" into sc-dev
diff --git a/BoardConfig-common.mk b/BoardConfig-common.mk
index 57fa101..9f2ee03 100644
--- a/BoardConfig-common.mk
+++ b/BoardConfig-common.mk
@@ -175,7 +175,8 @@
 
 BOARD_SUPER_PARTITION_SIZE := 8531214336
 BOARD_SUPER_PARTITION_GROUPS := google_dynamic_partitions
-BOARD_GOOGLE_DYNAMIC_PARTITIONS_SIZE := 8531214336
+# Set size to BOARD_SUPER_PARTITION_SIZE - overhead (4MiB) (b/182237294)
+BOARD_GOOGLE_DYNAMIC_PARTITIONS_SIZE := 8527020032
 BOARD_GOOGLE_DYNAMIC_PARTITIONS_PARTITION_LIST := \
     system \
     system_ext \
diff --git a/conf/init.gs101.rc b/conf/init.gs101.rc
index c288888..9779cb5 100644
--- a/conf/init.gs101.rc
+++ b/conf/init.gs101.rc
@@ -535,6 +535,13 @@
     chown system system /sys/devices/virtual/sec/tsp/cmd_result
     chown system system /sys/devices/virtual/sec/tsp/status
 
+# Route touch_sensitivity_mode to persist
+on property:debug.touch_sensitivity_mode=0
+    setprop persist.vendor.touch_sensitivity_mode 0
+
+on property:debug.touch_sensitivity_mode=1
+    setprop persist.vendor.touch_sensitivity_mode 1
+
 on property:init.svc.vendor.charger=running
     stop keymaster-4-0
 
diff --git a/default-permissions.xml b/default-permissions.xml
index 4524ddb..2a236fb 100644
--- a/default-permissions.xml
+++ b/default-permissions.xml
@@ -72,6 +72,16 @@
     </exception>
 
     <exception
+            package="com.verizon.mips.services">
+        <!-- Call -->
+        <permission name="android.permission.PROCESS_OUTGOING_CALLS" fixed="false"/>
+        <!-- Phone -->
+        <permission name="android.permission.READ_PHONE_STATE" fixed="false"/>
+        <!-- SMS -->
+        <permission name="android.permission.RECEIVE_SMS" fixed="false"/>
+    </exception>
+
+    <exception
         package="com.google.android.factorytest">
         <!-- Camera -->
         <permission name="android.permission.CAMERA" fixed="false"/>
diff --git a/device.mk b/device.mk
index ca5d67d..ff421da 100644
--- a/device.mk
+++ b/device.mk
@@ -461,6 +461,16 @@
 	android.hardware.drm@1.4-service.widevine \
 	liboemcrypto \
 
+ORIOLE_PRODUCT := %oriole
+RAVEN_PRODUCT := %raven
+ifneq (,$(filter $(ORIOLE_PRODUCT), $(TARGET_PRODUCT)))
+        LOCAL_TARGET_PRODUCT := oriole
+else ifneq (,$(filter $(RAVEN_PRODUCT), $(TARGET_PRODUCT)))
+        LOCAL_TARGET_PRODUCT := raven
+else
+        LOCAL_TARGET_PRODUCT := slider
+endif
+
 SOONG_CONFIG_NAMESPACES += lyric
 SOONG_CONFIG_lyric += \
 	soc \
@@ -474,10 +484,13 @@
 	soc \
 	gcam_awb \
 	ghawb_truetone \
+        target_device \
 
 SOONG_CONFIG_google3a_config_soc := gs101
 SOONG_CONFIG_google3a_config_gcam_awb := true
 SOONG_CONFIG_google3a_config_ghawb_truetone := true
+SOONG_CONFIG_google3a_config_target_device := $(LOCAL_TARGET_PRODUCT)
+
 
 SOONG_CONFIG_NAMESPACES += gch
 SOONG_CONFIG_gch += \
@@ -1062,6 +1075,10 @@
 include hardware/google/pixel/thermal/device.mk
 PRODUCT_PROPERTY_OVERRIDES += persist.vendor.enable.thermal.genl=true
 
+# TPU firmware
+PRODUCT_PACKAGES += \
+	edgetpu-abrolhos.fw
+
 # TPU NN HAL
 PRODUCT_PACKAGES += \
 	android.hardware.neuralnetworks@1.3-service-darwinn
diff --git a/dumpstate/DumpstateDevice.cpp b/dumpstate/DumpstateDevice.cpp
index 7d5bce8..e83f056 100644
--- a/dumpstate/DumpstateDevice.cpp
+++ b/dumpstate/DumpstateDevice.cpp
@@ -361,6 +361,9 @@
     DumpFileToFd(fd, "RTX", "/dev/logbuffer_rtx");
 
     RunCommandToFd(fd, "gvotables", {"/vendor/bin/sh", "-c", "cat /sys/kernel/debug/gvotables/*/status"});
+    DumpFileToFd(fd, "BCL", "/sys/devices/virtual/pmic/mitigation/triggered_stats");
+    DumpFileToFd(fd, "IF PMIC", "/sys/devices/virtual/pmic/max77759-mitigation/triggered_stats");
+
 }
 
 // Dump items related to thermal
diff --git a/interfaces/boot/1.2/BootControl.cpp b/interfaces/boot/1.2/BootControl.cpp
index 8a24334..70b9594 100644
--- a/interfaces/boot/1.2/BootControl.cpp
+++ b/interfaces/boot/1.2/BootControl.cpp
@@ -25,6 +25,7 @@
 #include <libboot_control/libboot_control.h>
 #include <log/log.h>
 
+#include "DevInfo.h"
 #include "GptUtils.h"
 
 namespace android {
@@ -46,6 +47,7 @@
 
 #define BOOT_A_PATH     "/dev/block/by-name/boot_a"
 #define BOOT_B_PATH     "/dev/block/by-name/boot_b"
+#define DEVINFO_PATH    "/dev/block/by-name/devinfo"
 
 // slot flags
 #define AB_ATTR_PRIORITY_SHIFT      52
@@ -100,29 +102,76 @@
     return !!(e->attr & flag);
 }
 
-static int setSlotFlag(uint32_t slot, uint64_t flag) {
+static bool setSlotFlag(uint32_t slot, uint64_t flag) {
     std::string dev_path = getDevPath(slot);
     if (dev_path.empty()) {
         ALOGI("Could not get device path for slot %d\n", slot);
-        return -1;
+        return false;
     }
 
     GptUtils gpt(dev_path);
     if (gpt.Load()) {
         ALOGI("failed to load gpt data\n");
-        return -1;
+        return false;
     }
 
     gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a");
     if (e == nullptr) {
         ALOGI("failed to get gpt entry\n");
-        return -1;
+        return false;
     }
 
     e->attr |= flag;
     gpt.Sync();
 
-    return 0;
+    return true;
+}
+
+static bool is_devinfo_valid;
+static bool is_devinfo_initialized;
+static std::mutex devinfo_lock;
+static devinfo_t devinfo;
+
+static bool isDevInfoValid() {
+    const std::lock_guard<std::mutex> lock(devinfo_lock);
+
+    if (is_devinfo_initialized) {
+        return is_devinfo_valid;
+    }
+
+    is_devinfo_initialized = true;
+
+    android::base::unique_fd fd(open(DEVINFO_PATH, O_RDONLY));
+    android::base::ReadFully(fd, &devinfo, sizeof devinfo);
+
+    if (devinfo.magic != DEVINFO_MAGIC) {
+        return is_devinfo_valid;
+    }
+
+    uint32_t version = ((uint32_t)devinfo.ver_major << 16) | devinfo.ver_minor;
+    // only version 3.3+ supports A/B data
+    if (version >= 0x0003'0003) {
+        is_devinfo_valid = true;
+    }
+
+    return is_devinfo_valid;
+}
+
+static bool DevInfoSync() {
+    if (!isDevInfoValid()) {
+        return false;
+    }
+
+    android::base::unique_fd fd(open(DEVINFO_PATH, O_WRONLY));
+    return android::base::WriteFully(fd, &devinfo, sizeof devinfo);
+}
+
+static void DevInfoInitSlot(devinfo_ab_slot_data_t &slot_data) {
+    slot_data.retry_count = AB_ATTR_MAX_RETRY_COUNT;
+    slot_data.unbootable = 0;
+    slot_data.successful = 0;
+    slot_data.active = 1;
+    slot_data.fastboot_ok = 0;
 }
 
 }  // namespace
@@ -152,8 +201,17 @@
         _hidl_cb({true, ""});
         return Void();
     }
-    int ret = setSlotFlag(getCurrentSlot(), AB_ATTR_SUCCESSFUL);
-    ret ? _hidl_cb({false, "Failed to set successful flag"}) : _hidl_cb({true, ""});
+
+    bool ret;
+    if (isDevInfoValid()) {
+        auto const slot = getCurrentSlot();
+        devinfo.ab_data.slots[slot].successful = 1;
+        ret = DevInfoSync();
+    } else {
+        ret = setSlotFlag(getCurrentSlot(), AB_ATTR_SUCCESSFUL);
+    }
+
+    !ret ? _hidl_cb({false, "Failed to set successful flag"}) : _hidl_cb({true, ""});
     return Void();
 }
 
@@ -163,27 +221,45 @@
         return Void();
     }
 
-    std::string dev_path = getDevPath(slot);
-    if (dev_path.empty()) {
-        _hidl_cb({false, "Could not get device path for slot"});
-        return Void();
-    }
+    if (isDevInfoValid()) {
+        auto &active_slot_data = devinfo.ab_data.slots[slot];
+        auto &inactive_slot_data = devinfo.ab_data.slots[!slot];
 
-    GptUtils gpt(dev_path);
-    if (gpt.Load()) {
-        _hidl_cb({false, "failed to load gpt data"});
-        return Void();
-    }
+        inactive_slot_data.active = 0;
+        DevInfoInitSlot(active_slot_data);
 
-    gpt_entry *active_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_a" : "boot_b");
-    gpt_entry *inactive_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_b" : "boot_a");
-    if (active_entry == nullptr || inactive_entry == nullptr) {
-        _hidl_cb({false, "failed to get entries for boot partitions"});
-        return Void();
-    }
+        if (!DevInfoSync()) {
+            _hidl_cb({false, "Could not update DevInfo data"});
+            return Void();
+        }
+    } else {
+        std::string dev_path = getDevPath(slot);
+        if (dev_path.empty()) {
+            _hidl_cb({false, "Could not get device path for slot"});
+            return Void();
+        }
 
-    ALOGV("slot active attributes %lx\n", active_entry->attr);
-    ALOGV("slot inactive attributes %lx\n", inactive_entry->attr);
+        GptUtils gpt(dev_path);
+        if (gpt.Load()) {
+            _hidl_cb({false, "failed to load gpt data"});
+            return Void();
+        }
+
+        gpt_entry *active_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_a" : "boot_b");
+        gpt_entry *inactive_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_b" : "boot_a");
+        if (active_entry == nullptr || inactive_entry == nullptr) {
+            _hidl_cb({false, "failed to get entries for boot partitions"});
+            return Void();
+        }
+
+        ALOGV("slot active attributes %lx\n", active_entry->attr);
+        ALOGV("slot inactive attributes %lx\n", inactive_entry->attr);
+
+        // update attributes for active and inactive
+        inactive_entry->attr &= ~AB_ATTR_ACTIVE;
+        active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) |
+                             (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT);
+    }
 
     char boot_dev[PROPERTY_VALUE_MAX];
     property_get("ro.boot.bootdevice", boot_dev, "");
@@ -207,11 +283,6 @@
         }
     }
 
-    // update attributes for active and inactive
-    inactive_entry->attr &= ~AB_ATTR_ACTIVE;
-    active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) |
-                         (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT);
-
     //
     // bBootLunEn
     // 0x1  => Boot LU A = enabled, Boot LU B = disable
@@ -234,20 +305,29 @@
         return Void();
     }
 
-    std::string dev_path = getDevPath(slot);
-    if (dev_path.empty()) {
-        _hidl_cb({false, "Could not get device path for slot"});
-        return Void();
+    if (isDevInfoValid()) {
+        auto &slot_data = devinfo.ab_data.slots[slot];
+        slot_data.unbootable = 1;
+        if (!DevInfoSync()) {
+            _hidl_cb({false, "Could not update DevInfo data"});
+            return Void();
+        }
+    } else {
+        std::string dev_path = getDevPath(slot);
+        if (dev_path.empty()) {
+            _hidl_cb({false, "Could not get device path for slot"});
+            return Void();
+        }
+
+        GptUtils gpt(dev_path);
+        gpt.Load();
+
+        gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a");
+        e->attr |= AB_ATTR_UNBOOTABLE;
+
+        gpt.Sync();
     }
 
-    GptUtils gpt(dev_path);
-    gpt.Load();
-
-    gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a");
-    e->attr |= AB_ATTR_UNBOOTABLE;
-
-    gpt.Sync();
-
     _hidl_cb({true, ""});
     return Void();
 }
@@ -257,7 +337,16 @@
         return BoolResult::FALSE;
     if (slot >= getNumberSlots())
         return BoolResult::INVALID_SLOT;
-    return isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE) ? BoolResult::FALSE : BoolResult::TRUE;
+
+    bool unbootable;
+    if (isDevInfoValid()) {
+        auto &slot_data = devinfo.ab_data.slots[slot];
+        unbootable = !!slot_data.unbootable;
+    } else {
+        unbootable = isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE);
+    }
+
+    return unbootable ? BoolResult::FALSE : BoolResult::TRUE;
 }
 
 Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful(
@@ -269,7 +358,16 @@
     }
     if (slot >= getNumberSlots())
         return BoolResult::INVALID_SLOT;
-    return isSlotFlagSet(slot, AB_ATTR_SUCCESSFUL) ? BoolResult::TRUE : BoolResult::FALSE;
+
+    bool successful;
+    if (isDevInfoValid()) {
+        auto &slot_data = devinfo.ab_data.slots[slot];
+        successful = !!slot_data.successful;
+    } else {
+        successful = isSlotFlagSet(slot, AB_ATTR_SUCCESSFUL);
+    }
+
+    return successful ? BoolResult::TRUE : BoolResult::FALSE;
 }
 
 Return<void> BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) {
@@ -300,6 +398,8 @@
     if (getNumberSlots() == 0)
         return 0;
 
+    if (isDevInfoValid())
+        return devinfo.ab_data.slots[1].active ? 1 : 0;
     return isSlotFlagSet(1, AB_ATTR_ACTIVE) ? 1 : 0;
 }
 
diff --git a/interfaces/boot/1.2/DevInfo.h b/interfaces/boot/1.2/DevInfo.h
new file mode 100644
index 0000000..a09a83a
--- /dev/null
+++ b/interfaces/boot/1.2/DevInfo.h
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+namespace android {
+namespace hardware {
+namespace boot {
+namespace V1_2 {
+namespace implementation {
+
+//
+// definitions taken from ABL code
+//
+
+constexpr uint32_t DEVINFO_MAGIC = 0x49564544;
+constexpr size_t DEVINFO_AB_SLOT_COUNT = 2;
+
+struct devinfo_ab_slot_data_t {
+    uint8_t retry_count;
+    uint8_t unbootable : 1;
+    uint8_t successful : 1;
+    uint8_t active : 1;
+    uint8_t fastboot_ok : 1;
+    uint8_t : 4;
+    uint8_t unused[2];
+} __attribute__((packed));
+
+typedef struct {
+    devinfo_ab_slot_data_t slots[DEVINFO_AB_SLOT_COUNT];
+} __attribute__((packed)) devinfo_ab_data_t;
+
+struct devinfo_t {
+    uint32_t magic;
+    uint16_t ver_major;
+    uint16_t ver_minor;
+    uint8_t unused[40];
+    devinfo_ab_data_t ab_data;
+    uint8_t unused1[72];  // use remaining up to complete 128 bytes
+} __attribute__((packed));
+
+static_assert(sizeof(devinfo_t) == 128, "invalid devinfo struct size");
+
+}  // namespace implementation
+}  // namespace V1_2
+}  // namespace boot
+}  // namespace hardware
+}  // namespace android
diff --git a/pixelstats/service.cpp b/pixelstats/service.cpp
index 4df1d84..33d885f 100644
--- a/pixelstats/service.cpp
+++ b/pixelstats/service.cpp
@@ -31,6 +31,7 @@
     .UFSLifetimeA = UFSHC_PATH(health_descriptor/life_time_estimation_a),
     .UFSLifetimeB = UFSHC_PATH(health_descriptor/life_time_estimation_b),
     .UFSLifetimeC = UFSHC_PATH(health_descriptor/life_time_estimation_c),
+    .UFSHostResetPath = UFSHC_PATH(err_stats/dev_reset_count),
     .F2fsStatsPath = "/sys/fs/f2fs/",
 };
 
diff --git a/powerhint.json b/powerhint.json
index 336b395..2133b8b 100644
--- a/powerhint.json
+++ b/powerhint.json
@@ -5,6 +5,7 @@
       "Path": "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq",
       "Values": [
         "9999999",
+        "1401000",
         "1197000"
       ],
       "DefaultIndex": 0,
@@ -45,7 +46,7 @@
       "Path": "/sys/devices/system/cpu/cpu6/cpufreq/scaling_max_freq",
       "Values": [
         "9999999",
-        "1999000"
+        "1826000"
       ],
       "DefaultIndex": 0,
       "ResetOnInit": true
@@ -64,10 +65,11 @@
       "Name": "GPUMinFreq",
       "Path": "/sys/devices/platform/1c500000.mali/scaling_min_freq",
       "Values": [
-        "151000",
-        "762000"
+        "762000",
+        "471000",
+        "302000",
+        "151000"
       ],
-      "DefaultIndex": 0,
       "ResetOnInit": true
     },
     {
@@ -200,22 +202,34 @@
       "Value": "9999999"
     },
     {
-      "PowerHint": "CAMERA_STREAMING_STANDARD",
+      "PowerHint": "CAMERA_STREAMING_HIGH",
       "Node": "CPUBigClusterMaxFreq",
       "Duration": 0,
-      "Value": "1999000"
+      "Value": "1826000"
+    },
+    {
+      "PowerHint": "CAMERA_STREAMING_HIGH",
+      "Node": "CPULittleClusterMaxFreq",
+      "Duration": 0,
+      "Value": "1401000"
+    },
+    {
+      "PowerHint": "CAMERA_STREAMING_HIGH",
+      "Node": "GPUMinFreq",
+      "Duration": 0,
+      "Value": "302000"
     },
     {
       "PowerHint": "CAMERA_STREAMING_STANDARD",
-      "Node": "PreferHighCapEnable",
+      "Node": "CPUBigClusterMaxFreq",
       "Duration": 0,
-      "Value": "1"
+      "Value": "1826000"
     },
     {
       "PowerHint": "CAMERA_STREAMING_STANDARD",
       "Node": "GPUMinFreq",
       "Duration": 0,
-      "Value": "762000"
+      "Value": "471000"
     },
     {
       "PowerHint": "THERMAL_FLASH_LED_REDUCE_CRITICAL",
diff --git a/rro_overlays/WifiOverlay/res/values/config.xml b/rro_overlays/WifiOverlay/res/values/config.xml
index de8766d..3002216 100644
--- a/rro_overlays/WifiOverlay/res/values/config.xml
+++ b/rro_overlays/WifiOverlay/res/values/config.xml
@@ -106,6 +106,9 @@
     <!-- Override channel utilization estimation with fixed value, disabled in brcm-based pixels -->
     <bool translatable="false" name="config_wifiChannelUtilizationOverrideEnabled">false</bool>
 
+    <!-- Enable adding minimum confirmation duration when sending network score to connectivity service. -->
+    <bool translatable="false" name="config_wifiMinConfirmationDurationSendNetworkScoreEnabled">true</bool>
+
     <!-- Enable concurrent STA + STA peer to peer + internet connectivity -->
     <bool translatable="false" name="config_wifiMultiStaLocalOnlyConcurrencyEnabled">true</bool>