Merge "Update incompatible charger checking rule" into main
diff --git a/core/java/android/hardware/usb/flags/system_sw_usb_flags.aconfig b/core/java/android/hardware/usb/flags/system_sw_usb_flags.aconfig
index 6b78d05..5c5083a 100644
--- a/core/java/android/hardware/usb/flags/system_sw_usb_flags.aconfig
+++ b/core/java/android/hardware/usb/flags/system_sw_usb_flags.aconfig
@@ -6,3 +6,10 @@
     description: "Enable USB data compliance warnings when set"
     bug: "296119135"
 }
+
+flag {
+    name: "enable_input_power_limited_warning"
+    namespace: "system_sw_usb"
+    description: "Flag incompatible charging on COMPLIANCE_WARNING_INPUT_POWER_LIMITED instead of COMPLIANCE_WARNING_OTHER when enabled"
+    bug: "308700954"
+}
diff --git a/packages/SettingsLib/src/com/android/settingslib/Utils.java b/packages/SettingsLib/src/com/android/settingslib/Utils.java
index f074106..f03263b 100644
--- a/packages/SettingsLib/src/com/android/settingslib/Utils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/Utils.java
@@ -23,6 +23,7 @@
 import android.graphics.ColorMatrix;
 import android.graphics.ColorMatrixColorFilter;
 import android.graphics.drawable.Drawable;
+import android.hardware.usb.flags.Flags;
 import android.hardware.usb.UsbManager;
 import android.hardware.usb.UsbPort;
 import android.hardware.usb.UsbPortStatus;
@@ -704,12 +705,23 @@
                 continue;
             }
             for (int complianceWarningType : complianceWarnings) {
-                switch (complianceWarningType) {
-                    case UsbPortStatus.COMPLIANCE_WARNING_OTHER:
-                    case UsbPortStatus.COMPLIANCE_WARNING_DEBUG_ACCESSORY:
-                        return true;
-                    default:
-                        break;
+                if (Flags.enableUsbDataComplianceWarning()
+                        && Flags.enableInputPowerLimitedWarning()) {
+                    switch (complianceWarningType) {
+                        case UsbPortStatus.COMPLIANCE_WARNING_INPUT_POWER_LIMITED:
+                        case UsbPortStatus.COMPLIANCE_WARNING_DEBUG_ACCESSORY:
+                            return true;
+                        default:
+                            break;
+                    }
+                } else {
+                    switch (complianceWarningType) {
+                        case UsbPortStatus.COMPLIANCE_WARNING_OTHER:
+                        case UsbPortStatus.COMPLIANCE_WARNING_DEBUG_ACCESSORY:
+                            return true;
+                        default:
+                            break;
+                    }
                 }
             }
         }
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java
index 29846ac..a88a9c7 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java
@@ -28,6 +28,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.res.Resources;
+import android.hardware.usb.flags.Flags;
 import android.hardware.usb.UsbManager;
 import android.hardware.usb.UsbPort;
 import android.hardware.usb.UsbPortStatus;
@@ -36,6 +37,7 @@
 import android.os.BatteryManager;
 import android.os.SystemProperties;
 import android.os.UserHandle;
+import android.platform.test.flag.junit.SetFlagsRule;
 import android.provider.Settings;
 import android.telephony.AccessNetworkConstants;
 import android.telephony.NetworkRegistrationInfo;
@@ -44,6 +46,7 @@
 
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.ArgumentMatcher;
@@ -85,6 +88,8 @@
     @Mock
     private UsbPortStatus mUsbPortStatus;
 
+    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
@@ -425,8 +430,38 @@
     }
 
     @Test
-    public void containsIncompatibleChargers_complianeWarningOther_returnTrue() {
+    public void containsIncompatibleChargers_complianeWarningOther_returnTrue_flagDisabled() {
+        mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_USB_DATA_COMPLIANCE_WARNING);
+        mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_INPUT_POWER_LIMITED_WARNING);
         setupIncompatibleCharging(UsbPortStatus.COMPLIANCE_WARNING_OTHER);
+
+        assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isTrue();
+    }
+
+    @Test
+    public void containsIncompatibleChargers_complianeWarningPower_returnFalse_flagDisabled() {
+        mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_USB_DATA_COMPLIANCE_WARNING);
+        mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_INPUT_POWER_LIMITED_WARNING);
+        setupIncompatibleCharging(UsbPortStatus.COMPLIANCE_WARNING_INPUT_POWER_LIMITED);
+
+        assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isFalse();
+    }
+
+    @Test
+    public void containsIncompatibleChargers_complianeWarningOther_returnFalse_flagEnabled() {
+        mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_USB_DATA_COMPLIANCE_WARNING);
+        mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_INPUT_POWER_LIMITED_WARNING);
+        setupIncompatibleCharging(UsbPortStatus.COMPLIANCE_WARNING_OTHER);
+
+        assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isFalse();
+    }
+
+    @Test
+    public void containsIncompatibleChargers_complianeWarningPower_returnTrue_flagEnabled() {
+        mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_USB_DATA_COMPLIANCE_WARNING);
+        mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_INPUT_POWER_LIMITED_WARNING);
+        setupIncompatibleCharging(UsbPortStatus.COMPLIANCE_WARNING_INPUT_POWER_LIMITED);
+
         assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isTrue();
     }
 
@@ -446,7 +481,6 @@
     public void containsIncompatibleChargers_emptyComplianceWarnings_returnFalse() {
         setupIncompatibleCharging();
         when(mUsbPortStatus.getComplianceWarnings()).thenReturn(new int[1]);
-
         assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isFalse();
     }
 
@@ -476,7 +510,7 @@
     }
 
     private void setupIncompatibleCharging() {
-        setupIncompatibleCharging(UsbPortStatus.COMPLIANCE_WARNING_OTHER);
+        setupIncompatibleCharging(UsbPortStatus.COMPLIANCE_WARNING_DEBUG_ACCESSORY);
     }
 
     private void setupIncompatibleCharging(int complianceWarningType) {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BatteryControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BatteryControllerTest.java
index 58d93c9..2f79955 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BatteryControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BatteryControllerTest.java
@@ -294,6 +294,6 @@
         when(mUsbPort.supportsComplianceWarnings()).thenReturn(true);
         when(mUsbPortStatus.isConnected()).thenReturn(true);
         when(mUsbPortStatus.getComplianceWarnings())
-                .thenReturn(new int[]{UsbPortStatus.COMPLIANCE_WARNING_OTHER});
+                .thenReturn(new int[]{UsbPortStatus.COMPLIANCE_WARNING_DEBUG_ACCESSORY});
     }
 }