From bd6ccb606a11dacf7c72970a9d623e6b89668d70 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 29 Apr 2020 16:31:42 -0700 Subject: [PATCH] [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. --- .../lib/src/android/android_device.dart | 3 +++ .../android/android_device_stop_test.dart | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 packages/flutter_tools/test/general.shard/android/android_device_stop_test.dart diff --git a/packages/flutter_tools/lib/src/android/android_device.dart b/packages/flutter_tools/lib/src/android/android_device.dart index 0a3b9e680a..46b52c1014 100644 --- a/packages/flutter_tools/lib/src/android/android_device.dart +++ b/packages/flutter_tools/lib/src/android/android_device.dart @@ -647,6 +647,9 @@ class AndroidDevice extends Device { @override Future stopApp(AndroidApk app) { + if (app == null) { + return Future.value(false); + } final List command = adbCommandForDevice(['shell', 'am', 'force-stop', app.id]); return processUtils.stream(command).then( (int exitCode) => exitCode == 0 || allowHeapCorruptionOnWindows(exitCode)); diff --git a/packages/flutter_tools/test/general.shard/android/android_device_stop_test.dart b/packages/flutter_tools/test/general.shard/android/android_device_stop_test.dart new file mode 100644 index 0000000000..c7fc8db9b1 --- /dev/null +++ b/packages/flutter_tools/test/general.shard/android/android_device_stop_test.dart @@ -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); + }); +}