[flutter_tools] android device stopApp handles null apk (#55990)

The resident runner does not check if the ApplicationPackage is null when trying to stop the app. Update AndroidDevice.stopApp to handle this case by returning false.

The package will be null when flutter attach is used.
This commit is contained in:
Jonah Williams 2020-04-29 16:31:42 -07:00 committed by GitHub
parent fdc6f38a44
commit bd6ccb606a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -647,6 +647,9 @@ class AndroidDevice extends Device {
@override
Future<bool> stopApp(AndroidApk app) {
if (app == null) {
return Future<bool>.value(false);
}
final List<String> command = adbCommandForDevice(<String>['shell', 'am', 'force-stop', app.id]);
return processUtils.stream(command).then<bool>(
(int exitCode) => exitCode == 0 || allowHeapCorruptionOnWindows(exitCode));

View File

@ -0,0 +1,15 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/android/android_device.dart';
import '../../src/common.dart';
void main() {
testWithoutContext('AndroidDevice.stopApp handles a null ApplicationPackage', () async {
final AndroidDevice androidDevice = AndroidDevice('2');
expect(await androidDevice.stopApp(null), false);
});
}