Support incompatible charger state in the battery main page
https://screenshot.googleplex.com/PrSzAtMAhsyqbsR Bug: 271775549 Test: make test RunSettingsRoboTests Change-Id: I0bb912eaab9c8837eaa3a9b998b3ebb5a8e6f99f
This commit is contained in:
@@ -16,11 +16,15 @@
|
||||
|
||||
package com.android.settings.testutils;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.hardware.usb.UsbPort;
|
||||
import android.hardware.usb.UsbPortStatus;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.room.Room;
|
||||
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryInformation;
|
||||
@@ -36,6 +40,9 @@ import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.robolectric.Shadows;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BatteryTestUtils {
|
||||
|
||||
public static Intent getChargingIntent() {
|
||||
@@ -163,6 +170,7 @@ public class BatteryTestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets customized battery changed intent. */
|
||||
public static Intent getCustomBatteryIntent(int plugged, int level, int scale, int status) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(BatteryManager.EXTRA_PLUGGED, plugged);
|
||||
@@ -172,4 +180,16 @@ public class BatteryTestUtils {
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
/** Configures the incompatible charger environment. */
|
||||
public static void setupIncompatibleEvent(
|
||||
UsbPort mockUsbPort, UsbManager mockUsbManager, UsbPortStatus mockUsbPortStatus) {
|
||||
final List<UsbPort> usbPorts = new ArrayList<>();
|
||||
usbPorts.add(mockUsbPort);
|
||||
when(mockUsbManager.getPorts()).thenReturn(usbPorts);
|
||||
when(mockUsbPort.getStatus()).thenReturn(mockUsbPortStatus);
|
||||
when(mockUsbPort.supportsComplianceWarnings()).thenReturn(true);
|
||||
when(mockUsbPortStatus.isConnected()).thenReturn(true);
|
||||
when(mockUsbPortStatus.getComplianceWarnings()).thenReturn(new int[]{1});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user