Unverified Commit e8bc5c5a authored by keyonghan's avatar keyonghan Committed by GitHub

Support Samsung phone when getting device `wakefulness` status (#98146)

parent e907b03c
......@@ -505,7 +505,10 @@ class AndroidDevice extends Device {
/// See: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/PowerManagerInternal.java
Future<String> _getWakefulness() async {
final String powerInfo = await shellEval('dumpsys', <String>['power']);
final String wakefulness = grep('mWakefulness=', from: powerInfo).single.split('=')[1].trim();
// A motoG4 phone returns `mWakefulness=Awake`.
// A Samsung phone returns `getWakefullnessLocked()=Awake`.
final RegExp wakefulnessRegexp = RegExp(r'.*(mWakefulness=|getWakefulnessLocked\(\)=).*');
final String wakefulness = grep(wakefulnessRegexp, from: powerInfo).single.split('=')[1].trim();
return wakefulness;
}
......
......@@ -40,6 +40,12 @@ void main() {
expect(await device.isAsleep(), isFalse);
});
test('reads Awake - samsung devices', () async {
FakeDevice.pretendAwakeSamsung();
expect(await device.isAwake(), isTrue);
expect(await device.isAsleep(), isFalse);
});
test('reads Asleep', () async {
FakeDevice.pretendAsleep();
expect(await device.isAwake(), isFalse);
......@@ -190,6 +196,12 @@ class FakeDevice extends AndroidDevice {
''';
}
static void pretendAwakeSamsung() {
output = '''
getWakefulnessLocked()=Awake
''';
}
static void pretendAsleep() {
output = '''
mWakefulness=Asleep
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment