Merge TQ2A.230405.003

Bug: 271343657
Merged-In: I46ec45354ae72a6a758aba2c2a31af92f1da4038
Change-Id: I2222e003c0ffe38ca39f9ff9d779644f09389d2f
diff --git a/BoardConfig-common.mk b/BoardConfig-common.mk
index 0538b86..fa3d102 100644
--- a/BoardConfig-common.mk
+++ b/BoardConfig-common.mk
@@ -341,9 +341,6 @@
 BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE := 0x04000000
 BOARD_DTBOIMG_PARTITION_SIZE := 0x01000000
 
-# System As Root
-BOARD_BUILD_SYSTEM_ROOT_IMAGE := false
-
 # Vendor ramdisk image for kernel development
 BOARD_BUILD_VENDOR_RAMDISK_IMAGE := true
 
diff --git a/conf/init.gs101.rc b/conf/init.gs101.rc
index 267a181..e3697fc 100644
--- a/conf/init.gs101.rc
+++ b/conf/init.gs101.rc
@@ -281,6 +281,12 @@
     # Adaptive charge
     chown system system /sys/class/power_supply/battery/charge_deadline
 
+    # Charging policy
+    chown system system /sys/class/power_supply/battery/charging_policy
+
+    # BatteryHealthData
+    chown system system /sys/class/power_supply/battery/first_usage_date
+
     # Battery Defender
     chown system system /sys/devices/platform/google,battery/power_supply/battery/bd_trickle_cnt
     chown system system /sys/devices/platform/google,battery/power_supply/battery/bd_trickle_dry_run
@@ -871,7 +877,8 @@
 service storageproxyd /vendor/bin/storageproxyd -d /dev/trusty-ipc-dev0 \
         -r /dev/sg1 -p /data/vendor/ss -t ufs
     class early_hal
-    user root
+    user system
+    group system
 
 # Write build info to kdebuginfo
 on property:ro.build.fingerprint=*
diff --git a/confirmationui/confirmationui.mk b/confirmationui/confirmationui.mk
index 85f77c9..8607ce4 100644
--- a/confirmationui/confirmationui.mk
+++ b/confirmationui/confirmationui.mk
@@ -1,6 +1,6 @@
 # Trusty ConfirmationUI HAL
 PRODUCT_PACKAGES += \
-	android.hardware.confirmationui@1.0-service.trusty.vendor
+	android.hardware.confirmationui-service.trusty.vendor
 
 # Trusty Secure DPU Daemon
 PRODUCT_PACKAGES += \
diff --git a/device.mk b/device.mk
index f93a450..016e5f9 100644
--- a/device.mk
+++ b/device.mk
@@ -568,10 +568,8 @@
         ConnectivityOverlay
 
 PRODUCT_PACKAGES_DEBUG += \
-	sg_write_buffer \
 	f2fs_io \
 	check_f2fs \
-	f2fsstat \
 	f2fs.fibmap \
 	dump.f2fs
 
@@ -646,6 +644,7 @@
 	debug.hwc.winupdate=1
 
 # hw composer HAL
+$(call soong_config_set,google_displaycolor,displaycolor_platform,gs101)
 PRODUCT_PACKAGES += \
 	libdisplaycolor \
 	hwcomposer.$(TARGET_BOARD_PLATFORM)
diff --git a/dumpstate/OWNERS b/dumpstate/OWNERS
new file mode 100644
index 0000000..c6adf31
--- /dev/null
+++ b/dumpstate/OWNERS
@@ -0,0 +1,10 @@
+aaronding@google.com
+rurumihong@google.com
+adamshih@google.com
+wilsonsung@google.com
+lucaswei@google.com
+cyanhsieh@google.com
+rogerliao@google.com
+cyuanjen@google.com
+robinpeng@google.com
+
diff --git a/dumpstate/README.txt b/dumpstate/README.txt
new file mode 100644
index 0000000..b279bda
--- /dev/null
+++ b/dumpstate/README.txt
@@ -0,0 +1 @@
+Please refer to go/pixel-recycle to modularize your code in this space.
diff --git a/fingerprint/extension/Android.bp b/fingerprint/extension/Android.bp
index fa2f13e..f36f3d5 100644
--- a/fingerprint/extension/Android.bp
+++ b/fingerprint/extension/Android.bp
@@ -8,7 +8,7 @@
 }
 
 sh_binary {
-    name: "fingerprint.extension.sh",
+    name: "fingerprint.extension",
     init_rc: ["init.fingerprint.extension.rc"],
     src: "fingerprint.extension.sh",
     system_ext_specific: true,
diff --git a/fingerprint/extension/fingerprint.extension.mk b/fingerprint/extension/fingerprint.extension.mk
index 1ef2374..1b8270a 100644
--- a/fingerprint/extension/fingerprint.extension.mk
+++ b/fingerprint/extension/fingerprint.extension.mk
@@ -1,11 +1,10 @@
 # Fingerprint extension feature
 ifneq (,$(filter userdebug, $(TARGET_BUILD_VARIANT)))
-SOONG_CONFIG_fp_hal_feature += report_bug_support
-SOONG_CONFIG_fp_hal_feature_report_bug_support := true
+$(call soong_config_set,fp_hal_feature,report_bug_support,true)
 BOARD_SEPOLICY_DIRS += hardware/google/pixel-sepolicy/fingerprint-extension/vendor/
 SYSTEM_EXT_PUBLIC_SEPOLICY_DIRS += hardware/google/pixel-sepolicy/fingerprint-extension/system_ext/public/
 SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS += hardware/google/pixel-sepolicy/fingerprint-extension/system_ext/private/
 PRODUCT_PACKAGES += \
     fps_ext_bug_lib \
-    fingerprint.extension.sh
+    fingerprint.extension
 endif
diff --git a/fingerprint/extension/init.fingerprint.extension.rc b/fingerprint/extension/init.fingerprint.extension.rc
index 9277ce0..70bcfd2 100644
--- a/fingerprint/extension/init.fingerprint.extension.rc
+++ b/fingerprint/extension/init.fingerprint.extension.rc
@@ -1,18 +1,18 @@
 # init-fingerprint-extension-sh is to send intent command to app
 # for tracking fingerprint issue.
-service fingerprint-extension-bug-latency /system_ext/bin/fingerprint.extension.sh latency
+service fingerprint-extension-bug-latency /system_ext/bin/fingerprint.extension latency
     group shell
     user shell
     disabled
     oneshot
 
-service fingerprint-extension-bug-lockout /system_ext/bin/fingerprint.extension.sh lockout
+service fingerprint-extension-bug-lockout /system_ext/bin/fingerprint.extension lockout
     group shell
     user shell
     disabled
     oneshot
 
-service fingerprint-extension-bug-auth /system_ext/bin/fingerprint.extension.sh auth
+service fingerprint-extension-bug-auth /system_ext/bin/fingerprint.extension auth
     group shell
     user shell
     disabled
diff --git a/health/android.hardware.health-service.gs101.xml b/health/android.hardware.health-service.gs101.xml
index 98026cb..1fe9b8d 100644
--- a/health/android.hardware.health-service.gs101.xml
+++ b/health/android.hardware.health-service.gs101.xml
@@ -1,7 +1,7 @@
 <manifest version="1.0" type="device">
     <hal format="aidl">
         <name>android.hardware.health</name>
-        <version>1</version>
+        <version>2</version>
         <fqname>IHealth/default</fqname>
     </hal>
 </manifest>
diff --git a/manifest.xml b/manifest.xml
index 51f3345..09fbd8a 100644
--- a/manifest.xml
+++ b/manifest.xml
@@ -133,14 +133,6 @@
             <instance>default</instance>
         </interface>
     </hal>
-    <hal format="aidl">
-        <name>vendor.google.google_battery</name>
-        <version>1</version>
-        <interface>
-            <name>IGoogleBattery</name>
-            <instance>default</instance>
-        </interface>
-    </hal>
     <hal format="hidl">
        <name>vendor.google.whitechapel.audio.audioext</name>
        <transport>hwbinder</transport>
diff --git a/manifest_64.xml b/manifest_64.xml
index 5d33f74..4edb2e9 100644
--- a/manifest_64.xml
+++ b/manifest_64.xml
@@ -116,14 +116,6 @@
             <instance>default</instance>
         </interface>
     </hal>
-    <hal format="aidl">
-        <name>vendor.google.google_battery</name>
-        <version>1</version>
-        <interface>
-            <name>IGoogleBattery</name>
-            <instance>default</instance>
-        </interface>
-    </hal>
     <hal format="hidl">
        <name>vendor.google.whitechapel.audio.audioext</name>
        <transport>hwbinder</transport>
diff --git a/usb/gadget/Android.bp b/usb/gadget/Android.bp
index ab7ac32..d9e4647 100644
--- a/usb/gadget/Android.bp
+++ b/usb/gadget/Android.bp
@@ -27,26 +27,27 @@
 cc_binary {
     name: "android.hardware.usb.gadget-service.gs101",
     relative_install_path: "hw",
-    init_rc: ["android.hardware.usb.gadget-service.gs101.rc"],
+    init_rc: ["android.hardware.usb.gadget-service.rc"],
     vintf_fragments: [
-        "android.hardware.usb.gadget@1.2-service.gs101.xml",
+        "android.hardware.usb.gadget-service.xml",
     ],
+    vendor: true,
     srcs: ["service_gadget.cpp", "UsbGadget.cpp"],
     cflags: ["-Wall", "-Werror"],
     shared_libs: [
         "libbase",
-        "libbinder",
-        "libhidlbase",
         "liblog",
         "libutils",
-        "libhardware",
-        "android.hardware.usb.gadget@1.0",
-        "android.hardware.usb.gadget@1.1",
-        "android.hardware.usb.gadget@1.2",
+        "android.frameworks.stats-V1-ndk",
+        "android.hardware.usb.gadget-V1-ndk",
         "libcutils",
+        "libbinder_ndk",
     ],
     static_libs: [
         "libpixelusb",
     ],
     proprietary: true,
+    export_shared_lib_headers: [
+        "android.frameworks.stats-V1-ndk",
+    ],
 }
diff --git a/usb/gadget/UsbGadget.cpp b/usb/gadget/UsbGadget.cpp
index b6d1dd3..9313863 100644
--- a/usb/gadget/UsbGadget.cpp
+++ b/usb/gadget/UsbGadget.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#define LOG_TAG "android.hardware.usb.gadget@1.2-service.gs101"
+#define LOG_TAG "android.hardware.usb.gadget.aidl-service"
 
 #include "UsbGadget.h"
 #include <dirent.h>
@@ -26,12 +26,13 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <aidl/android/frameworks/stats/IStats.h>
+
+namespace aidl {
 namespace android {
 namespace hardware {
 namespace usb {
 namespace gadget {
-namespace V1_2 {
-namespace implementation {
 
 string enabledPath;
 constexpr char kHsi2cPath[] = "/sys/devices/platform/10d50000.hsi2c";
@@ -46,7 +47,7 @@
     }
 }
 
-V1_0::Status UsbGadget::getUsbGadgetIrqPath() {
+Status UsbGadget::getUsbGadgetIrqPath() {
     std::string irqs;
     size_t read_pos = 0;
     size_t found_pos = 0;
@@ -93,17 +94,20 @@
     gadget->mCurrentUsbFunctionsApplied = functionsApplied;
 }
 
-Return<void> UsbGadget::getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback> &callback) {
-    Return<void> ret = callback->getCurrentUsbFunctionsCb(
+ScopedAStatus UsbGadget::getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback> &callback,
+        int64_t in_transactionId) {
+    ScopedAStatus ret = callback->getCurrentUsbFunctionsCb(
         mCurrentUsbFunctions,
-        mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED : Status::FUNCTIONS_NOT_APPLIED);
+        mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED : Status::FUNCTIONS_NOT_APPLIED,
+        in_transactionId);
     if (!ret.isOk())
-        ALOGE("Call to getCurrentUsbFunctionsCb failed %s", ret.description().c_str());
+        ALOGE("Call to getCurrentUsbFunctionsCb failed %s", ret.getDescription().c_str());
 
-    return Void();
+    return ScopedAStatus::ok();
 }
 
-Return<void> UsbGadget::getUsbSpeed(const sp<V1_2::IUsbGadgetCallback> &callback) {
+ScopedAStatus UsbGadget::getUsbSpeed(const shared_ptr<IUsbGadgetCallback> &callback,
+        int64_t in_transactionId) {
     std::string current_speed;
     if (ReadFileToString(SPEED_PATH, &current_speed)) {
         current_speed = Trim(current_speed);
@@ -121,25 +125,26 @@
         else if (current_speed == "UNKNOWN")
             mUsbSpeed = UsbSpeed::UNKNOWN;
         else
-            mUsbSpeed = UsbSpeed::RESERVED_SPEED;
+            mUsbSpeed = UsbSpeed::UNKNOWN;
     } else {
         ALOGE("Fail to read current speed");
         mUsbSpeed = UsbSpeed::UNKNOWN;
     }
 
     if (callback) {
-        Return<void> ret = callback->getUsbSpeedCb(mUsbSpeed);
+        ScopedAStatus ret = callback->getUsbSpeedCb(mUsbSpeed, in_transactionId);
 
         if (!ret.isOk())
-            ALOGE("Call to getUsbSpeedCb failed %s", ret.description().c_str());
+            ALOGE("Call to getUsbSpeedCb failed %s", ret.getDescription().c_str());
     }
 
-    return Void();
+    return ScopedAStatus::ok();
 }
 
-V1_0::Status UsbGadget::tearDownGadget() {
-    if (resetGadget() != Status::SUCCESS)
+Status UsbGadget::tearDownGadget() {
+    if (Status(resetGadget()) != Status::SUCCESS){
         return Status::ERROR;
+    }
 
     if (monitorFfs.isMonitorRunning()) {
         monitorFfs.reset();
@@ -149,139 +154,152 @@
     return Status::SUCCESS;
 }
 
-static V1_0::Status validateAndSetVidPid(uint64_t functions) {
-    V1_0::Status ret = Status::SUCCESS;
+static Status validateAndSetVidPid(uint64_t functions) {
+    Status ret = Status::SUCCESS;
     std::string vendorFunctions = getVendorFunctions();
 
     switch (functions) {
-        case static_cast<uint64_t>(GadgetFunction::MTP):
+        case GadgetFunction::MTP:
             if (!(vendorFunctions == "user" || vendorFunctions == "")) {
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
                 ret = Status::CONFIGURATION_NOT_SUPPORTED;
             } else {
-                ret = setVidPid("0x18d1", "0x4ee1");
+                ret = Status(setVidPid("0x18d1", "0x4ee1"));
             }
             break;
-        case GadgetFunction::ADB | GadgetFunction::MTP:
+        case GadgetFunction::ADB |
+                GadgetFunction::MTP:
             if (!(vendorFunctions == "user" || vendorFunctions == "")) {
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
                 ret = Status::CONFIGURATION_NOT_SUPPORTED;
             } else {
-                ret = setVidPid("0x18d1", "0x4ee2");
+                ret = Status(setVidPid("0x18d1", "0x4ee2"));
             }
             break;
-        case static_cast<uint64_t>(GadgetFunction::RNDIS):
-        case GadgetFunction::RNDIS | GadgetFunction::NCM:
+        case GadgetFunction::RNDIS:
+        case GadgetFunction::RNDIS |
+                GadgetFunction::NCM:
             if (!(vendorFunctions == "user" || vendorFunctions == "")) {
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
                 ret = Status::CONFIGURATION_NOT_SUPPORTED;
             } else {
-                ret = setVidPid("0x18d1", "0x4ee3");
+                ret = Status(setVidPid("0x18d1", "0x4ee3"));
             }
             break;
-        case GadgetFunction::ADB | GadgetFunction::RNDIS:
-        case GadgetFunction::ADB | GadgetFunction::RNDIS | GadgetFunction::NCM:
+        case GadgetFunction::ADB |
+                GadgetFunction::RNDIS:
+        case GadgetFunction::ADB |
+                GadgetFunction::RNDIS |
+                GadgetFunction::NCM:
             if (vendorFunctions == "dm") {
-                ret = setVidPid("0x04e8", "0x6862");
+                ret = Status(setVidPid("0x04e8", "0x6862"));
             } else {
                 if (!(vendorFunctions == "user" || vendorFunctions == "")) {
                     ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
                     ret = Status::CONFIGURATION_NOT_SUPPORTED;
                 } else {
-                    ret = setVidPid("0x18d1", "0x4ee4");
+                    ret = Status(setVidPid("0x18d1", "0x4ee4"));
                 }
             }
             break;
-        case static_cast<uint64_t>(GadgetFunction::PTP):
+        case GadgetFunction::PTP:
             if (!(vendorFunctions == "user" || vendorFunctions == "")) {
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
                 ret = Status::CONFIGURATION_NOT_SUPPORTED;
             } else {
-                ret = setVidPid("0x18d1", "0x4ee5");
+                ret = Status(setVidPid("0x18d1", "0x4ee5"));
             }
             break;
-        case GadgetFunction::ADB | GadgetFunction::PTP:
+        case GadgetFunction::ADB |
+                GadgetFunction::PTP:
             if (!(vendorFunctions == "user" || vendorFunctions == "")) {
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
                 ret = Status::CONFIGURATION_NOT_SUPPORTED;
             } else {
-                ret = setVidPid("0x18d1", "0x4ee6");
+                ret = Status(setVidPid("0x18d1", "0x4ee6"));
             }
             break;
-        case static_cast<uint64_t>(GadgetFunction::ADB):
+        case GadgetFunction::ADB:
             if (vendorFunctions == "dm") {
-                ret = setVidPid("0x04e8", "0x6862");
+                ret = Status(setVidPid("0x04e8", "0x6862"));
             } else if (vendorFunctions == "etr_miu") {
-                ret = setVidPid("0x18d1", "0x4ee2");
+                ret = Status(setVidPid("0x18d1", "0x4ee2"));
             } else if (vendorFunctions == "uwb_acm"){
-                ret = setVidPid("0x18d1", "0x4ee2");
+                ret = Status(setVidPid("0x18d1", "0x4ee2"));
             } else {
                 if (!(vendorFunctions == "user" || vendorFunctions == "")) {
                     ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
                     ret = Status::CONFIGURATION_NOT_SUPPORTED;
                 } else {
-                    ret = setVidPid("0x18d1", "0x4ee7");
+                    ret = Status(setVidPid("0x18d1", "0x4ee7"));
                 }
             }
             break;
-        case static_cast<uint64_t>(GadgetFunction::MIDI):
+        case GadgetFunction::MIDI:
             if (!(vendorFunctions == "user" || vendorFunctions == "")) {
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
                 ret = Status::CONFIGURATION_NOT_SUPPORTED;
             } else {
-                ret = setVidPid("0x18d1", "0x4ee8");
+                ret = Status(setVidPid("0x18d1", "0x4ee8"));
             }
             break;
-        case GadgetFunction::ADB | GadgetFunction::MIDI:
+        case GadgetFunction::ADB |
+                GadgetFunction::MIDI:
             if (!(vendorFunctions == "user" || vendorFunctions == "")) {
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
                 ret = Status::CONFIGURATION_NOT_SUPPORTED;
             } else {
-                ret = setVidPid("0x18d1", "0x4ee9");
+                ret = Status(setVidPid("0x18d1", "0x4ee9"));
             }
             break;
-        case static_cast<uint64_t>(GadgetFunction::ACCESSORY):
+        case GadgetFunction::ACCESSORY:
             if (!(vendorFunctions == "user" || vendorFunctions == ""))
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
-            ret = setVidPid("0x18d1", "0x2d00");
+            ret = Status(setVidPid("0x18d1", "0x2d00"));
             break;
-        case GadgetFunction::ADB | GadgetFunction::ACCESSORY:
+        case GadgetFunction::ADB |
+                 GadgetFunction::ACCESSORY:
             if (!(vendorFunctions == "user" || vendorFunctions == ""))
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
-            ret = setVidPid("0x18d1", "0x2d01");
+            ret = Status(setVidPid("0x18d1", "0x2d01"));
             break;
-        case static_cast<uint64_t>(GadgetFunction::AUDIO_SOURCE):
+        case GadgetFunction::AUDIO_SOURCE:
             if (!(vendorFunctions == "user" || vendorFunctions == ""))
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
-            ret = setVidPid("0x18d1", "0x2d02");
+            ret = Status(setVidPid("0x18d1", "0x2d02"));
             break;
-        case GadgetFunction::ADB | GadgetFunction::AUDIO_SOURCE:
+        case GadgetFunction::ADB |
+                GadgetFunction::AUDIO_SOURCE:
             if (!(vendorFunctions == "user" || vendorFunctions == ""))
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
-            ret = setVidPid("0x18d1", "0x2d03");
+            ret = Status(setVidPid("0x18d1", "0x2d03"));
             break;
-        case GadgetFunction::ACCESSORY | GadgetFunction::AUDIO_SOURCE:
+        case GadgetFunction::ACCESSORY |
+                GadgetFunction::AUDIO_SOURCE:
             if (!(vendorFunctions == "user" || vendorFunctions == ""))
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
-            ret = setVidPid("0x18d1", "0x2d04");
+            ret = Status(setVidPid("0x18d1", "0x2d04"));
             break;
-        case GadgetFunction::ADB | GadgetFunction::ACCESSORY | GadgetFunction::AUDIO_SOURCE:
+        case GadgetFunction::ADB |
+                GadgetFunction::ACCESSORY |
+                GadgetFunction::AUDIO_SOURCE:
             if (!(vendorFunctions == "user" || vendorFunctions == ""))
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
-            ret = setVidPid("0x18d1", "0x2d05");
+            ret = Status(setVidPid("0x18d1", "0x2d05"));
             break;
-        case static_cast<uint64_t>(GadgetFunction::NCM):
+        case GadgetFunction::NCM:
             if (!(vendorFunctions == "user" || vendorFunctions == ""))
                 ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
-            ret = setVidPid("0x18d1", "0x4eeb");
+            ret = Status(setVidPid("0x18d1", "0x4eeb"));
             break;
-        case GadgetFunction::ADB | GadgetFunction::NCM:
+        case GadgetFunction::ADB |
+                GadgetFunction::NCM:
             if (vendorFunctions == "dm") {
-                ret = setVidPid("0x04e8", "0x6862");
+                ret = Status(setVidPid("0x04e8", "0x6862"));
             } else {
                 if (!(vendorFunctions == "user" || vendorFunctions == ""))
                     ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str());
-                ret = setVidPid("0x18d1", "0x4eec");
+                ret = Status(setVidPid("0x18d1", "0x4eec"));
             }
             break;
         default:
@@ -291,31 +309,33 @@
     return ret;
 }
 
-Return<Status> UsbGadget::reset() {
+ScopedAStatus UsbGadget::reset() {
     ALOGI("USB Gadget reset");
 
     if (!WriteStringToFile("none", PULLUP_PATH)) {
         ALOGI("Gadget cannot be pulled down");
-        return Status::ERROR;
+        return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+                -1, "Gadget cannot be pulled down");
     }
 
     usleep(kDisconnectWaitUs);
 
     if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) {
         ALOGI("Gadget cannot be pulled up");
-        return Status::ERROR;
+        return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+                -1, "Gadget cannot be pulled up");
     }
 
-    return Status::SUCCESS;
+    return ScopedAStatus::ok();
 }
 
-V1_0::Status UsbGadget::setupFunctions(uint64_t functions,
-                                       const sp<V1_0::IUsbGadgetCallback> &callback,
-                                       uint64_t timeout) {
+Status UsbGadget::setupFunctions(long functions,
+        const shared_ptr<IUsbGadgetCallback> &callback, uint64_t timeout,
+        int64_t in_transactionId) {
     bool ffsEnabled = false;
     int i = 0;
 
-    if (addGenericAndroidFunctions(&monitorFfs, functions, &ffsEnabled, &i) !=
+    if (Status(addGenericAndroidFunctions(&monitorFfs, functions, &ffsEnabled, &i)) !=
         Status::SUCCESS)
         return Status::ERROR;
 
@@ -325,7 +345,7 @@
         ALOGI("enable usbradio debug functions");
         if ((functions & GadgetFunction::RNDIS) != 0) {
             if (linkFunction("acm.gs6", i++))
-	        return Status::ERROR;
+                return Status::ERROR;
             if (linkFunction("dm.gs7", i++))
                 return Status::ERROR;
         } else {
@@ -333,7 +353,7 @@
                 return Status::ERROR;
             if (linkFunction("acm.gs6", i++))
                 return Status::ERROR;
-	}
+        }
     } else if (vendorFunctions == "etr_miu") {
         ALOGI("enable etr_miu functions");
         if (linkFunction("etr_miu.gs11", i++))
@@ -346,7 +366,7 @@
 
     if ((functions & GadgetFunction::ADB) != 0) {
         ffsEnabled = true;
-        if (addAdb(&monitorFfs, &i) != Status::SUCCESS)
+        if (Status(addAdb(&monitorFfs, &i)) != Status::SUCCESS)
             return Status::ERROR;
     }
 
@@ -362,7 +382,7 @@
             return Status::ERROR;
         mCurrentUsbFunctionsApplied = true;
         if (callback)
-            callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS);
+            callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId);
         return Status::SUCCESS;
     }
 
@@ -377,12 +397,13 @@
 
     if (callback) {
         bool pullup = monitorFfs.waitForPullUp(timeout);
-        Return<void> ret = callback->setCurrentUsbFunctionsCb(
-            functions, pullup ? Status::SUCCESS : Status::ERROR);
-        if (!ret.isOk())
-            ALOGE("setCurrentUsbFunctionsCb error %s", ret.description().c_str());
+        ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(
+            functions, pullup ? Status::SUCCESS : Status::ERROR, in_transactionId);
+        if (!ret.isOk()) {
+            ALOGE("setCurrentUsbFunctionsCb error %s", ret.getDescription().c_str());
+            return Status::ERROR;
+        }
     }
-
     return Status::SUCCESS;
 }
 
@@ -409,9 +430,10 @@
     return Status::ERROR;
 }
 
-Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
-                                               const sp<V1_0::IUsbGadgetCallback> &callback,
-                                               uint64_t timeout) {
+ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions,
+                                               const shared_ptr<IUsbGadgetCallback> &callback,
+                                               int64_t timeout,
+                                               int64_t in_transactionId) {
     std::unique_lock<std::mutex> lk(mLockSetCurrentFunction);
     std::string current_usb_power_operation_mode, current_usb_type;
     std::string usb_limit_sink_enable;
@@ -430,7 +452,7 @@
         getUsbGadgetIrqPath();
 
     // Unlink the gadget and stop the monitor if running.
-    V1_0::Status status = tearDownGadget();
+    Status status = tearDownGadget();
     if (status != Status::SUCCESS) {
         goto error;
     }
@@ -440,13 +462,15 @@
     // Leave the gadget pulled down to give time for the host to sense disconnect.
     usleep(kDisconnectWaitUs);
 
-    if (functions == static_cast<uint64_t>(GadgetFunction::NONE)) {
+    if (functions == GadgetFunction::NONE) {
         if (callback == NULL)
-            return Void();
-        Return<void> ret = callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS);
+            return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+                -1, "callback == NULL");
+        ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId);
         if (!ret.isOk())
-            ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str());
-        return Void();
+            ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str());
+        return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+                -1, "Error while calling setCurrentUsbFunctionsCb");
     }
 
     status = validateAndSetVidPid(functions);
@@ -455,7 +479,7 @@
         goto error;
     }
 
-    status = setupFunctions(functions, callback, timeout);
+    status = setupFunctions(functions, callback, timeout, in_transactionId);
     if (status != Status::SUCCESS) {
         goto error;
     }
@@ -495,20 +519,23 @@
     }
 
     ALOGI("Usb Gadget setcurrent functions called successfully");
-    return Void();
+    return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+                -1, "Usb Gadget setcurrent functions called successfully");
+
 
 error:
     ALOGI("Usb Gadget setcurrent functions failed");
     if (callback == NULL)
-        return Void();
-    Return<void> ret = callback->setCurrentUsbFunctionsCb(functions, status);
+        return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+                -1, "Usb Gadget setcurrent functions failed");
+    ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, status, in_transactionId);
     if (!ret.isOk())
-        ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str());
-    return Void();
+        ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str());
+    return ScopedAStatus::fromServiceSpecificErrorWithMessage(
+                -1, "Error while calling setCurrentUsbFunctionsCb");
 }
-}  // namespace implementation
-}  // namespace V1_2
 }  // namespace gadget
 }  // namespace usb
 }  // namespace hardware
 }  // namespace android
+}  // aidl
diff --git a/usb/gadget/UsbGadget.h b/usb/gadget/UsbGadget.h
index 96a356d..45e1b25 100644
--- a/usb/gadget/UsbGadget.h
+++ b/usb/gadget/UsbGadget.h
@@ -21,11 +21,13 @@
 #include <android-base/unique_fd.h>
 #include <android-base/parseint.h>
 #include <android-base/strings.h>
-#include <android/hardware/usb/gadget/1.2/IUsbGadget.h>
-#include <android/hardware/usb/gadget/1.2/types.h>
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-#include <pixelusb/UsbGadgetCommon.h>
+#include <aidl/android/hardware/usb/gadget/BnUsbGadget.h>
+#include <aidl/android/hardware/usb/gadget/BnUsbGadgetCallback.h>
+#include <aidl/android/hardware/usb/gadget/GadgetFunction.h>
+#include <aidl/android/hardware/usb/gadget/IUsbGadget.h>
+#include <aidl/android/hardware/usb/gadget/IUsbGadgetCallback.h>
+#include <pixelusb/UsbGadgetAidlCommon.h>
+#include <sched.h>
 #include <sys/epoll.h>
 #include <sys/eventfd.h>
 #include <utils/Log.h>
@@ -35,14 +37,17 @@
 #include <string>
 #include <thread>
 
+namespace aidl {
 namespace android {
 namespace hardware {
 namespace usb {
 namespace gadget {
-namespace V1_2 {
-namespace implementation {
 
-using ::android::sp;
+using ::aidl::android::hardware::usb::gadget::GadgetFunction;
+using ::aidl::android::hardware::usb::gadget::IUsbGadgetCallback;
+using ::aidl::android::hardware::usb::gadget::IUsbGadget;
+using ::aidl::android::hardware::usb::gadget::Status;
+using ::aidl::android::hardware::usb::gadget::UsbSpeed;
 using ::android::base::GetProperty;
 using ::android::base::SetProperty;
 using ::android::base::ParseUint;
@@ -50,12 +55,6 @@
 using ::android::base::ReadFileToString;
 using ::android::base::Trim;
 using ::android::base::WriteStringToFile;
-using ::android::hardware::hidl_array;
-using ::android::hardware::hidl_memory;
-using ::android::hardware::hidl_string;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::Return;
-using ::android::hardware::Void;
 using ::android::hardware::google::pixel::usb::addAdb;
 using ::android::hardware::google::pixel::usb::addEpollFd;
 using ::android::hardware::google::pixel::usb::getVendorFunctions;
@@ -66,10 +65,8 @@
 using ::android::hardware::google::pixel::usb::resetGadget;
 using ::android::hardware::google::pixel::usb::setVidPid;
 using ::android::hardware::google::pixel::usb::unlinkFunctions;
-using ::android::hardware::usb::gadget::V1_0::Status;
-using ::android::hardware::usb::gadget::V1_0::IUsbGadgetCallback;
-using ::android::hardware::usb::gadget::V1_2::IUsbGadget;
-using ::android::hardware::usb::gadget::V1_2::GadgetFunction;
+using ::ndk::ScopedAStatus;
+using ::std::shared_ptr;
 using ::std::string;
 
 constexpr char kGadgetName[] = "11110000.dwc3";
@@ -95,36 +92,39 @@
 #define CURRENT_USB_TYPE_PATH			POWER_SUPPLY_PATH	"usb_type"
 #define CURRENT_USB_POWER_OPERATION_MODE_PATH	USB_PORT0_PATH		"power_operation_mode"
 
-struct UsbGadget : public IUsbGadget {
+struct UsbGadget : public BnUsbGadget {
     UsbGadget();
 
     // Makes sure that only one request is processed at a time.
     std::mutex mLockSetCurrentFunction;
     std::string mGadgetIrqPath;
-    uint64_t mCurrentUsbFunctions;
+    long mCurrentUsbFunctions;
     bool mCurrentUsbFunctionsApplied;
     UsbSpeed mUsbSpeed;
 
-    Return<void> setCurrentUsbFunctions(uint64_t functions,
-                                        const sp<V1_0::IUsbGadgetCallback> &callback,
-                                        uint64_t timeout) override;
+    ScopedAStatus setCurrentUsbFunctions(long functions,
+            const shared_ptr<IUsbGadgetCallback> &callback,
+            int64_t timeout, int64_t in_transactionId) override;
 
-    Return<void> getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback> &callback) override;
+    ScopedAStatus getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback> &callback,
+	    int64_t in_transactionId) override;
 
-    Return<Status> reset() override;
+    ScopedAStatus reset() override;
 
-    Return<void> getUsbSpeed(const sp<V1_2::IUsbGadgetCallback> &callback) override;
+    ScopedAStatus getUsbSpeed(const shared_ptr<IUsbGadgetCallback> &callback,
+	    int64_t in_transactionId) override;
+
+    ScopedAStatus setVidPid(const char *vid,const char *pid);
 
   private:
     Status tearDownGadget();
     Status getUsbGadgetIrqPath();
-    Status setupFunctions(uint64_t functions, const sp<V1_0::IUsbGadgetCallback> &callback,
-                          uint64_t timeout);
+    Status setupFunctions(long functions, const shared_ptr<IUsbGadgetCallback> &callback,
+            uint64_t timeout, int64_t in_transactionId);
 };
 
-}  // namespace implementation
-}  // namespace V1_2
 }  // namespace gadget
 }  // namespace usb
 }  // namespace hardware
 }  // namespace android
+}  // aidl
diff --git a/usb/gadget/android.hardware.usb.gadget-service.gs101.rc b/usb/gadget/android.hardware.usb.gadget-service.rc
similarity index 93%
rename from usb/gadget/android.hardware.usb.gadget-service.gs101.rc
rename to usb/gadget/android.hardware.usb.gadget-service.rc
index da1a3b4..71772e8 100644
--- a/usb/gadget/android.hardware.usb.gadget-service.gs101.rc
+++ b/usb/gadget/android.hardware.usb.gadget-service.rc
@@ -1,4 +1,4 @@
-service vendor.usb-gadget-hal-1-2 /vendor/bin/hw/android.hardware.usb.gadget-service.gs101
+service vendor.usb-gadget-hal /vendor/bin/hw/android.hardware.usb.gadget-service.gs101
     class hal
     user system
     group system shell mtp wakelock
diff --git a/usb/gadget/android.hardware.usb.gadget@1.2-service.gs101.xml b/usb/gadget/android.hardware.usb.gadget-service.xml
similarity index 70%
rename from usb/gadget/android.hardware.usb.gadget@1.2-service.gs101.xml
rename to usb/gadget/android.hardware.usb.gadget-service.xml
index 8557f6f..e7eebc3 100644
--- a/usb/gadget/android.hardware.usb.gadget@1.2-service.gs101.xml
+++ b/usb/gadget/android.hardware.usb.gadget-service.xml
@@ -1,8 +1,7 @@
 <manifest version="1.0" type="device">
-    <hal format="hidl">
+    <hal format="aidl">
         <name>android.hardware.usb.gadget</name>
-        <transport>hwbinder</transport>
-        <version>1.2</version>
+        <version>1</version>
         <interface>
             <name>IUsbGadget</name>
             <instance>default</instance>
diff --git a/usb/gadget/service_gadget.cpp b/usb/gadget/service_gadget.cpp
index d0908ee..e40f689 100644
--- a/usb/gadget/service_gadget.cpp
+++ b/usb/gadget/service_gadget.cpp
@@ -16,35 +16,27 @@
 
 #define LOG_TAG "android.hardware.usb.gadget-service.gs101"
 
-#include <hidl/HidlTransportSupport.h>
+#include <android-base/logging.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+#include <utils/Log.h>
 #include "UsbGadget.h"
 
-using android::sp;
-
-// libhwbinder:
-using android::hardware::configureRpcThreadpool;
-using android::hardware::joinRpcThreadpool;
-
-// Generated HIDL files
-using android::hardware::usb::gadget::V1_2::IUsbGadget;
-using android::hardware::usb::gadget::V1_2::implementation::UsbGadget;
-
 using android::OK;
+using android::sp;
 using android::status_t;
 
+using aidl::android::hardware::usb::gadget::UsbGadget;
+
 int main() {
-    android::sp<IUsbGadget> service = new UsbGadget();
-    configureRpcThreadpool(2, true /*callerWillJoin*/);
-    status_t status = service->registerAsService();
+    ABinderProcess_setThreadPoolMaxThreadCount(0);
+    std::shared_ptr<UsbGadget> usbgadget = ndk::SharedRefBase::make<UsbGadget>();
 
-    if (status != OK) {
-        ALOGE("Cannot register USB Gadget HAL service");
-        return 1;
-    }
+    const std::string instance = std::string() + UsbGadget::descriptor + "/default";
+    binder_status_t status = AServiceManager_addService(usbgadget->asBinder().get(), instance.c_str());
+    CHECK(status == STATUS_OK);
 
-    ALOGI("USB gadget HAL Ready.");
-    joinRpcThreadpool();
-    // Under noraml cases, execution will not reach this line.
-    ALOGI("USB gadget HAL failed to join thread pool.");
-    return 1;
+    ALOGV("AIDL USB Gadget HAL about to start");
+    ABinderProcess_joinThreadPool();
+    return -1; // Should never be reached
 }