Unverified Commit 0c9a4205 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate android_device to null safety (#92128)

parent 53e04de6
......@@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import 'package:process/process.dart';
import '../base/common.dart';
......@@ -29,13 +26,13 @@ import 'android_workflow.dart';
/// * [AndroidDevice], the type of discovered device.
class AndroidDevices extends PollingDeviceDiscovery {
AndroidDevices({
@required AndroidWorkflow androidWorkflow,
@required ProcessManager processManager,
@required Logger logger,
@required AndroidSdk androidSdk,
@required FileSystem fileSystem,
@required Platform platform,
@required UserMessages userMessages,
required AndroidWorkflow androidWorkflow,
required ProcessManager processManager,
required Logger logger,
AndroidSdk? androidSdk,
required FileSystem fileSystem,
required Platform platform,
required UserMessages userMessages,
}) : _androidWorkflow = androidWorkflow,
_androidSdk = androidSdk,
_processUtils = ProcessUtils(
......@@ -51,7 +48,7 @@ class AndroidDevices extends PollingDeviceDiscovery {
final AndroidWorkflow _androidWorkflow;
final ProcessUtils _processUtils;
final AndroidSdk _androidSdk;
final AndroidSdk? _androidSdk;
final ProcessManager _processManager;
final Logger _logger;
final FileSystem _fileSystem;
......@@ -65,13 +62,13 @@ class AndroidDevices extends PollingDeviceDiscovery {
bool get canListAnything => _androidWorkflow.canListDevices;
@override
Future<List<Device>> pollingGetDevices({ Duration timeout }) async {
Future<List<Device>> pollingGetDevices({ Duration? timeout }) async {
if (_doesNotHaveAdb()) {
return <AndroidDevice>[];
}
String text;
try {
text = (await _processUtils.run(<String>[_androidSdk.adbPath, 'devices', '-l'],
text = (await _processUtils.run(<String>[_androidSdk!.adbPath!, 'devices', '-l'],
throwOnError: true,
)).stdout.trim();
} on ProcessException catch (exception) {
......@@ -94,7 +91,7 @@ class AndroidDevices extends PollingDeviceDiscovery {
return <String>[];
}
final RunResult result = await _processUtils.run(<String>[_androidSdk.adbPath, 'devices', '-l']);
final RunResult result = await _processUtils.run(<String>[_androidSdk!.adbPath!, 'devices', '-l']);
if (result.exitCode != 0) {
return <String>[];
}
......@@ -108,8 +105,8 @@ class AndroidDevices extends PollingDeviceDiscovery {
bool _doesNotHaveAdb() {
return _androidSdk == null ||
_androidSdk.adbPath == null ||
!_processManager.canRun(_androidSdk.adbPath);
_androidSdk?.adbPath == null ||
!_processManager.canRun(_androidSdk!.adbPath);
}
// 015d172c98400a03 device usb:340787200X product:nakasi model:Nexus_7 device:grouper
......@@ -120,8 +117,8 @@ class AndroidDevices extends PollingDeviceDiscovery {
/// in which case information for that parameter won't be populated.
void _parseADBDeviceOutput(
String text, {
List<AndroidDevice> devices,
List<String> diagnostics,
List<AndroidDevice>? devices,
List<String>? diagnostics,
}) {
// Check for error messages from adb
if (!text.contains('List of devices')) {
......@@ -146,11 +143,11 @@ class AndroidDevices extends PollingDeviceDiscovery {
}
if (_kDeviceRegex.hasMatch(line)) {
final Match match = _kDeviceRegex.firstMatch(line);
final Match match = _kDeviceRegex.firstMatch(line)!;
final String deviceID = match[1];
final String deviceState = match[2];
String rest = match[3];
final String deviceID = match[1]!;
final String deviceState = match[2]!;
String rest = match[3]!;
final Map<String, String> info = <String, String>{};
if (rest != null && rest.isNotEmpty) {
......@@ -163,8 +160,9 @@ class AndroidDevices extends PollingDeviceDiscovery {
}
}
if (info['model'] != null) {
info['model'] = cleanAdbDeviceName(info['model']);
final String? model = info['model'];
if (model != null) {
info['model'] = cleanAdbDeviceName(model);
}
if (deviceState == 'unauthorized') {
......@@ -180,7 +178,7 @@ class AndroidDevices extends PollingDeviceDiscovery {
productID: info['product'],
modelID: info['model'] ?? deviceID,
deviceCodeName: info['device'],
androidSdk: _androidSdk,
androidSdk: _androidSdk!,
fileSystem: _fileSystem,
logger: _logger,
platform: _platform,
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'package:flutter_tools/src/android/android_device.dart';
......@@ -183,7 +181,7 @@ void main() {
});
}
AndroidDevice createFakeDevice(int sdkLevel) {
AndroidDevice createFakeDevice(int? sdkLevel) {
return FakeAndroidDevice(
sdkLevel.toString(),
kLastLogcatTimestamp,
......
......@@ -72,7 +72,6 @@ void main() {
testWithoutContext('AndroidDevices returns empty device list and diagnostics on null Android SDK', () async {
final AndroidDevices androidDevices = AndroidDevices(
androidSdk: null,
logger: BufferLogger.test(),
androidWorkflow: AndroidWorkflow(
androidSdk: FakeAndroidSdk(null),
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_tools/src/android/android_device.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/device_port_forwarder.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:file/memory.dart';
import 'package:flutter_tools/src/android/android_device.dart';
import 'package:flutter_tools/src/android/android_sdk.dart';
......@@ -42,9 +40,9 @@ const FakeCommand kShaCommand = FakeCommand(
);
void main() {
FileSystem fileSystem;
FakeProcessManager processManager;
AndroidSdk androidSdk;
late FileSystem fileSystem;
late FakeProcessManager processManager;
late AndroidSdk androidSdk;
setUp(() {
processManager = FakeProcessManager.empty();
......
// 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.
// @dart = 2.8
import 'package:file/memory.dart';
import 'package:flutter_tools/src/android/android_device.dart';
import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/fake_process_manager.dart';
void main() {
testWithoutContext('AndroidDevice.stopApp handles a null ApplicationPackage', () async {
final AndroidDevice androidDevice = AndroidDevice('1234',
androidSdk: FakeAndroidSdk(),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
platform: FakePlatform(),
processManager: FakeProcessManager.any(),
);
expect(await androidDevice.stopApp(null), false);
});
}
class FakeAndroidSdk extends Fake implements AndroidSdk { }
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
......@@ -459,15 +457,16 @@ Uptime: 441088659 Realtime: 521464097
}
AndroidDevice setUpAndroidDevice({
String id,
AndroidSdk androidSdk,
FileSystem fileSystem,
ProcessManager processManager,
Platform platform,
String? id,
AndroidSdk? androidSdk,
FileSystem? fileSystem,
ProcessManager? processManager,
Platform? platform,
AndroidConsoleSocketFactory androidConsoleSocketFactory = kAndroidConsoleSocketFactory,
}) {
androidSdk ??= FakeAndroidSdk();
return AndroidDevice(id ?? '1234',
modelID: 'TestModel',
logger: BufferLogger.test(),
platform: platform ?? FakePlatform(),
androidSdk: androidSdk,
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:file/memory.dart';
import 'package:flutter_tools/src/android/android_device.dart';
import 'package:flutter_tools/src/android/android_sdk.dart';
......@@ -41,8 +39,8 @@ const FakeCommand kStoreShaCommand = FakeCommand(
);
void main() {
FileSystem fileSystem;
BufferLogger logger;
late FileSystem fileSystem;
late BufferLogger logger;
setUp(() {
fileSystem = MemoryFileSystem.test();
......@@ -50,15 +48,16 @@ void main() {
});
AndroidDevice setUpAndroidDevice({
AndroidSdk androidSdk,
ProcessManager processManager,
AndroidSdk? androidSdk,
ProcessManager? processManager,
}) {
androidSdk ??= FakeAndroidSdk();
return AndroidDevice('1234',
modelID: 'TestModel',
logger: logger,
platform: FakePlatform(),
androidSdk: androidSdk,
fileSystem: fileSystem ?? MemoryFileSystem.test(),
fileSystem: fileSystem,
processManager: processManager ?? FakeProcessManager.any(),
);
}
......
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