usb: update incompatible charger warning reason

Report COMPLIANCE_WARNING_INPUT_POWER_LIMITED instead of
COMPLIANCE_WARNING_OTHER to flag incompatible chargers. The underlying
logic that generates the warning remains the same, what's changed is
the enum that's being used.
The purpose of the change is to have a warning type that better
represents what actually happens and free up COMPLIANCE_WARNING_OTHER
that was intended to act as a fallback reason code.
The flag enable_input_power_limited_warning controls whether to switch
to the new enum, while the flag enable_usb_data_compliance_warning
controls the new enums that are added as FlaggedApi in the framework.
Both flags need to be on to enable the change.

Bug: 308700954
Test: manual tests with local flag override
Change-Id: I6595706d1b83d533fc2d3e29086773270e045ede
This commit is contained in:
Roy Luo 2023-11-06 23:12:46 +00:00
parent 64853c99f4
commit 398ceca7a9
2 changed files with 27 additions and 4 deletions

View file

@ -46,21 +46,29 @@ cc_binary {
"android.hardware.thermal@2.0", "android.hardware.thermal@2.0",
"android.hardware.thermal-V1-ndk", "android.hardware.thermal-V1-ndk",
"android.hardware.usb.gadget@1.0", "android.hardware.usb.gadget@1.0",
"android.hardware.usb-V2-ndk", "android.hardware.usb-V3-ndk",
"android.hardware.usb.gadget-V1-ndk", "android.hardware.usb.gadget-V1-ndk",
"libcutils", "libcutils",
"android.frameworks.stats-V2-ndk", "android.frameworks.stats-V2-ndk",
"pixelatoms-cpp", "pixelatoms-cpp",
"libbinder_ndk", "libbinder_ndk",
"libprotobuf-cpp-lite", "libprotobuf-cpp-lite",
"server_configurable_flags",
], ],
static_libs: [ static_libs: [
"libpixelusb-aidl", "libpixelusb-aidl",
"libpixelstats", "libpixelstats",
"libthermalutils", "libthermalutils",
"android.hardware.usb.flags-aconfig-c-lib",
], ],
export_shared_lib_headers: [ export_shared_lib_headers: [
"android.frameworks.stats-V2-ndk", "android.frameworks.stats-V2-ndk",
"pixelatoms-cpp", "pixelatoms-cpp",
], ],
} }
cc_aconfig_library {
name: "android.hardware.usb.flags-aconfig-c-lib",
vendor: true,
aconfig_declarations: "android.hardware.usb.flags-aconfig",
}

View file

@ -42,10 +42,13 @@
#include "Usb.h" #include "Usb.h"
#include <aidl/android/frameworks/stats/IStats.h> #include <aidl/android/frameworks/stats/IStats.h>
#include <android_hardware_usb_flags.h>
#include <pixelusb/CommonUtils.h> #include <pixelusb/CommonUtils.h>
#include <pixelusb/UsbGadgetAidlCommon.h> #include <pixelusb/UsbGadgetAidlCommon.h>
#include <pixelstats/StatsHelper.h> #include <pixelstats/StatsHelper.h>
namespace usb_flags = android::hardware::usb::flags;
using aidl::android::frameworks::stats::IStats; using aidl::android::frameworks::stats::IStats;
using android::base::GetProperty; using android::base::GetProperty;
using android::base::Join; using android::base::Join;
@ -78,6 +81,7 @@ constexpr char kComplianceWarningBC12[] = "bc12";
constexpr char kComplianceWarningDebugAccessory[] = "debug-accessory"; constexpr char kComplianceWarningDebugAccessory[] = "debug-accessory";
constexpr char kComplianceWarningMissingRp[] = "missing_rp"; constexpr char kComplianceWarningMissingRp[] = "missing_rp";
constexpr char kComplianceWarningOther[] = "other"; constexpr char kComplianceWarningOther[] = "other";
constexpr char kComplianceWarningInputPowerLimited[] = "input_power_limited";
constexpr char kStatusPath[] = "-0025/contaminant_detection_status"; constexpr char kStatusPath[] = "-0025/contaminant_detection_status";
constexpr char kSinkLimitEnable[] = "-0025/usb_limit_sink_enable"; constexpr char kSinkLimitEnable[] = "-0025/usb_limit_sink_enable";
constexpr char kSourceLimitEnable[] = "-0025/usb_limit_source_enable"; constexpr char kSourceLimitEnable[] = "-0025/usb_limit_source_enable";
@ -361,9 +365,20 @@ Status queryNonCompliantChargerStatus(std::vector<PortStatus> *currentPortStatus
continue; continue;
} }
if (!strncmp(reason.c_str(), kComplianceWarningOther, if (!strncmp(reason.c_str(), kComplianceWarningOther,
strlen(kComplianceWarningOther))) { strlen(kComplianceWarningOther)) ||
(*currentPortStatus)[i].complianceWarnings.push_back(ComplianceWarning::OTHER); !strncmp(reason.c_str(), kComplianceWarningInputPowerLimited,
strlen(kComplianceWarningInputPowerLimited))) {
if (usb_flags::enable_usb_data_compliance_warning() &&
usb_flags::enable_input_power_limited_warning()) {
ALOGI("Report through INPUT_POWER_LIMITED warning");
(*currentPortStatus)[i].complianceWarnings.push_back(
ComplianceWarning::INPUT_POWER_LIMITED);
continue; continue;
} else {
(*currentPortStatus)[i].complianceWarnings.push_back(
ComplianceWarning::OTHER);
continue;
}
} }
} }
if ((*currentPortStatus)[i].complianceWarnings.size() > 0 && if ((*currentPortStatus)[i].complianceWarnings.size() > 0 &&