mirror of
https://github.com/flutter/flutter
synced 2024-08-27 20:10:11 +00:00
Enable Windows platform_channel test (#106973)
This commit is contained in:
parent
5ca39a2054
commit
f3717d70d7
1
.ci.yaml
1
.ci.yaml
|
@ -3994,7 +3994,6 @@ targets:
|
|||
["devicelab", "hostonly"]
|
||||
task_name: platform_channel_sample_test_windows
|
||||
scheduler: luci
|
||||
bringup: true
|
||||
|
||||
- name: Windows plugin_dependencies_test
|
||||
recipe: devicelab/devicelab_drone
|
||||
|
|
|
@ -28,9 +28,13 @@ class _PlatformChannelState extends State<PlatformChannel> {
|
|||
try {
|
||||
final int? result = await methodChannel.invokeMethod('getBatteryLevel');
|
||||
batteryLevel = 'Battery level: $result%.';
|
||||
} on PlatformException {
|
||||
} on PlatformException catch (e) {
|
||||
if (e.code == 'NO_BATTERY') {
|
||||
batteryLevel = 'No battery.';
|
||||
} else {
|
||||
batteryLevel = 'Failed to get battery level.';
|
||||
}
|
||||
}
|
||||
setState(() {
|
||||
_batteryLevel = batteryLevel;
|
||||
});
|
||||
|
|
|
@ -31,7 +31,11 @@ void main() {
|
|||
batteryLevel = await driver.getText(batteryLevelLabel);
|
||||
}
|
||||
|
||||
expect(batteryLevel.contains('%'), isTrue);
|
||||
// Allow either a battery percentage or "No battery" since it will vary
|
||||
// by device; either indicates that a known response came from the host
|
||||
// implementation.
|
||||
expect(batteryLevel.contains('%') || batteryLevel.contains('No battery'),
|
||||
isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -16,10 +16,17 @@
|
|||
|
||||
#include "flutter/generated_plugin_registrant.h"
|
||||
|
||||
static constexpr int kBatteryError = -1;
|
||||
static constexpr int kNoBattery = -2;
|
||||
|
||||
static int GetBatteryLevel() {
|
||||
SYSTEM_POWER_STATUS status;
|
||||
if (GetSystemPowerStatus(&status) == 0 || status.BatteryLifePercent == 255) {
|
||||
return -1;
|
||||
if (GetSystemPowerStatus(&status) == 0) {
|
||||
return kBatteryError;
|
||||
} else if (status.BatteryFlag == 128) {
|
||||
return kNoBattery;
|
||||
} else if (status.BatteryLifePercent == 255) {
|
||||
return kBatteryError;
|
||||
}
|
||||
return status.BatteryLifePercent;
|
||||
}
|
||||
|
@ -59,10 +66,12 @@ bool FlutterWindow::OnCreate() {
|
|||
if (call.method_name() == "getBatteryLevel") {
|
||||
int battery_level = GetBatteryLevel();
|
||||
|
||||
if (battery_level != -1) {
|
||||
result->Success(battery_level);
|
||||
} else {
|
||||
if (battery_level == kBatteryError) {
|
||||
result->Error("UNAVAILABLE", "Battery level not available.");
|
||||
} else if (battery_level == kNoBattery) {
|
||||
result->Error("NO_BATTERY", "Device does not have a battery.");
|
||||
} else {
|
||||
result->Success(battery_level);
|
||||
}
|
||||
} else {
|
||||
result->NotImplemented();
|
||||
|
|
Loading…
Reference in a new issue