Unverified Commit f09eb8af authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate first_run and bot_detector to null safety (#80096)

parent ff970cb1
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
...@@ -15,9 +13,9 @@ import 'platform.dart'; ...@@ -15,9 +13,9 @@ import 'platform.dart';
class BotDetector { class BotDetector {
BotDetector({ BotDetector({
@required HttpClientFactory httpClientFactory, required HttpClientFactory httpClientFactory,
@required Platform platform, required Platform platform,
@required PersistentToolState persistentToolState, required PersistentToolState persistentToolState,
}) : }) :
_platform = platform, _platform = platform,
_azureDetector = AzureDetector( _azureDetector = AzureDetector(
...@@ -31,7 +29,7 @@ class BotDetector { ...@@ -31,7 +29,7 @@ class BotDetector {
Future<bool> get isRunningOnBot async { Future<bool> get isRunningOnBot async {
if (_persistentToolState.isRunningOnBot != null) { if (_persistentToolState.isRunningOnBot != null) {
return _persistentToolState.isRunningOnBot; return _persistentToolState.isRunningOnBot!;
} }
if ( if (
// Explicitly stated to not be a bot. // Explicitly stated to not be a bot.
...@@ -86,18 +84,18 @@ class BotDetector { ...@@ -86,18 +84,18 @@ class BotDetector {
@visibleForTesting @visibleForTesting
class AzureDetector { class AzureDetector {
AzureDetector({ AzureDetector({
@required HttpClientFactory httpClientFactory, required HttpClientFactory httpClientFactory,
}) : _httpClientFactory = httpClientFactory; }) : _httpClientFactory = httpClientFactory;
static const String _serviceUrl = 'http://169.254.169.254/metadata/instance'; static const String _serviceUrl = 'http://169.254.169.254/metadata/instance';
final HttpClientFactory _httpClientFactory; final HttpClientFactory _httpClientFactory;
bool _isRunningOnAzure; bool? _isRunningOnAzure;
Future<bool> get isRunningOnAzure async { Future<bool> get isRunningOnAzure async {
if (_isRunningOnAzure != null) { if (_isRunningOnAzure != null) {
return _isRunningOnAzure; return _isRunningOnAzure!;
} }
const Duration connectionTimeout = Duration(milliseconds: 250); const Duration connectionTimeout = Duration(milliseconds: 250);
const Duration requestTimeout = Duration(seconds: 1); const Duration requestTimeout = Duration(seconds: 1);
......
...@@ -13,7 +13,7 @@ import '../base/logger.dart'; ...@@ -13,7 +13,7 @@ import '../base/logger.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../base/terminal.dart'; import '../base/terminal.dart';
import '../cache.dart'; import '../cache.dart';
import '../globals.dart' as globals; import '../globals_null_migrated.dart' as globals;
import '../persistent_tool_state.dart'; import '../persistent_tool_state.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import '../version.dart'; import '../version.dart';
......
...@@ -13,7 +13,7 @@ import '../base/process.dart'; ...@@ -13,7 +13,7 @@ import '../base/process.dart';
import '../base/time.dart'; import '../base/time.dart';
import '../cache.dart'; import '../cache.dart';
import '../dart/pub.dart'; import '../dart/pub.dart';
import '../globals.dart' as globals; import '../globals_null_migrated.dart' as globals;
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import '../version.dart'; import '../version.dart';
......
...@@ -6,10 +6,7 @@ ...@@ -6,10 +6,7 @@
import 'android/gradle_utils.dart'; import 'android/gradle_utils.dart';
import 'artifacts.dart'; import 'artifacts.dart';
import 'base/bot_detector.dart';
import 'base/context.dart'; import 'base/context.dart';
import 'base/io.dart';
import 'base/net.dart';
import 'build_system/build_system.dart'; import 'build_system/build_system.dart';
import 'device.dart'; import 'device.dart';
import 'doctor.dart'; import 'doctor.dart';
...@@ -21,7 +18,6 @@ import 'ios/xcodeproj.dart'; ...@@ -21,7 +18,6 @@ import 'ios/xcodeproj.dart';
import 'macos/cocoapods.dart'; import 'macos/cocoapods.dart';
import 'macos/cocoapods_validator.dart'; import 'macos/cocoapods_validator.dart';
import 'macos/xcode.dart'; import 'macos/xcode.dart';
import 'persistent_tool_state.dart';
import 'project.dart'; import 'project.dart';
import 'reporting/reporting.dart'; import 'reporting/reporting.dart';
import 'runner/local_engine.dart'; import 'runner/local_engine.dart';
...@@ -32,7 +28,6 @@ Artifacts get artifacts => context.get<Artifacts>(); ...@@ -32,7 +28,6 @@ Artifacts get artifacts => context.get<Artifacts>();
BuildSystem get buildSystem => context.get<BuildSystem>(); BuildSystem get buildSystem => context.get<BuildSystem>();
CrashReporter get crashReporter => context.get<CrashReporter>(); CrashReporter get crashReporter => context.get<CrashReporter>();
Doctor get doctor => context.get<Doctor>(); Doctor get doctor => context.get<Doctor>();
PersistentToolState get persistentToolState => PersistentToolState.instance;
Usage get flutterUsage => context.get<Usage>(); Usage get flutterUsage => context.get<Usage>();
DeviceManager get deviceManager => context.get<DeviceManager>(); DeviceManager get deviceManager => context.get<DeviceManager>();
...@@ -56,15 +51,5 @@ XcodeProjectInterpreter get xcodeProjectInterpreter => context.get<XcodeProjectI ...@@ -56,15 +51,5 @@ XcodeProjectInterpreter get xcodeProjectInterpreter => context.get<XcodeProjectI
XCDevice get xcdevice => context.get<XCDevice>(); XCDevice get xcdevice => context.get<XCDevice>();
final BotDetector _defaultBotDetector = BotDetector(
httpClientFactory: context.get<HttpClientFactory>() ?? () => HttpClient(),
platform: globals.platform,
persistentToolState: persistentToolState,
);
BotDetector get botDetector => context.get<BotDetector>() ?? _defaultBotDetector;
Future<bool> get isRunningOnBot => botDetector.isRunningOnBot;
/// Gradle utils in the current [AppContext]. /// Gradle utils in the current [AppContext].
GradleUtils get gradleUtils => context.get<GradleUtils>(); GradleUtils get gradleUtils => context.get<GradleUtils>();
...@@ -6,6 +6,7 @@ import 'package:process/process.dart'; ...@@ -6,6 +6,7 @@ import 'package:process/process.dart';
import 'android/android_sdk.dart'; import 'android/android_sdk.dart';
import 'android/android_studio.dart'; import 'android/android_studio.dart';
import 'base/bot_detector.dart';
import 'base/config.dart'; import 'base/config.dart';
import 'base/context.dart'; import 'base/context.dart';
import 'base/error_handling_io.dart'; import 'base/error_handling_io.dart';
...@@ -23,6 +24,7 @@ import 'base/time.dart'; ...@@ -23,6 +24,7 @@ import 'base/time.dart';
import 'base/user_messages.dart'; import 'base/user_messages.dart';
import 'cache.dart'; import 'cache.dart';
import 'ios/plist_parser.dart'; import 'ios/plist_parser.dart';
import 'persistent_tool_state.dart';
import 'version.dart'; import 'version.dart';
Cache get cache => context.get<Cache>()!; Cache get cache => context.get<Cache>()!;
...@@ -35,6 +37,20 @@ AndroidStudio? get androidStudio => context.get<AndroidStudio>(); ...@@ -35,6 +37,20 @@ AndroidStudio? get androidStudio => context.get<AndroidStudio>();
AndroidSdk? get androidSdk => context.get<AndroidSdk>(); AndroidSdk? get androidSdk => context.get<AndroidSdk>();
FlutterVersion get flutterVersion => context.get<FlutterVersion>()!; FlutterVersion get flutterVersion => context.get<FlutterVersion>()!;
PersistentToolState? get persistentToolState => PersistentToolState.instance;
BotDetector get botDetector => context.get<BotDetector>() ?? _defaultBotDetector;
final BotDetector _defaultBotDetector = BotDetector(
httpClientFactory: context.get<HttpClientFactory>() ?? () => HttpClient(),
platform: platform,
persistentToolState: persistentToolState ?? PersistentToolState(
fileSystem: fs,
logger: logger,
platform: platform,
),
);
Future<bool> get isRunningOnBot => botDetector.isRunningOnBot;
/// Currently active implementation of the file system. /// Currently active implementation of the file system.
/// ///
/// By default it uses local disk-based implementation. Override this in tests /// By default it uses local disk-based implementation. Override this in tests
......
...@@ -2,11 +2,8 @@ ...@@ -2,11 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:convert/convert.dart'; import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart'; import 'package:crypto/crypto.dart';
import 'package:meta/meta.dart';
import '../convert.dart'; import '../convert.dart';
import '../persistent_tool_state.dart'; import '../persistent_tool_state.dart';
...@@ -46,7 +43,7 @@ const String _kFlutterFirstRunMessage = ''' ...@@ -46,7 +43,7 @@ const String _kFlutterFirstRunMessage = '''
/// need to be displayed. /// need to be displayed.
class FirstRunMessenger { class FirstRunMessenger {
FirstRunMessenger({ FirstRunMessenger({
@required PersistentToolState persistentToolState required PersistentToolState persistentToolState
}) : _persistentToolState = persistentToolState; }) : _persistentToolState = persistentToolState;
final PersistentToolState _persistentToolState; final PersistentToolState _persistentToolState;
...@@ -64,7 +61,7 @@ class FirstRunMessenger { ...@@ -64,7 +61,7 @@ class FirstRunMessenger {
if (_persistentToolState.shouldRedisplayWelcomeMessage == false) { if (_persistentToolState.shouldRedisplayWelcomeMessage == false) {
return false; return false;
} }
final String oldHash = _persistentToolState.lastActiveLicenseTermsHash; final String? oldHash = _persistentToolState.lastActiveLicenseTermsHash;
return oldHash != _currentHash; return oldHash != _currentHash;
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/persistent_tool_state.dart'; import 'package:flutter_tools/src/persistent_tool_state.dart';
...@@ -48,7 +46,7 @@ void main() { ...@@ -48,7 +46,7 @@ void main() {
}); });
} }
FirstRunMessenger setUpFirstRunMessenger({bool redisplayWelcomeMessage, bool test = false }) { FirstRunMessenger setUpFirstRunMessenger({bool? redisplayWelcomeMessage, bool test = false }) {
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final PersistentToolState state = PersistentToolState.test(directory: fileSystem.currentDirectory, logger: BufferLogger.test()); final PersistentToolState state = PersistentToolState.test(directory: fileSystem.currentDirectory, logger: BufferLogger.test());
if (redisplayWelcomeMessage != null) { if (redisplayWelcomeMessage != null) {
...@@ -63,7 +61,7 @@ FirstRunMessenger setUpFirstRunMessenger({bool redisplayWelcomeMessage, bool tes ...@@ -63,7 +61,7 @@ FirstRunMessenger setUpFirstRunMessenger({bool redisplayWelcomeMessage, bool tes
class TestFirstRunMessenger extends FirstRunMessenger { class TestFirstRunMessenger extends FirstRunMessenger {
TestFirstRunMessenger(PersistentToolState persistentToolState) : super(persistentToolState: persistentToolState); TestFirstRunMessenger(PersistentToolState persistentToolState) : super(persistentToolState: persistentToolState);
String overrideLicenseTerms; String? overrideLicenseTerms;
@override @override
String get licenseTerms => overrideLicenseTerms ?? super.licenseTerms; String get licenseTerms => overrideLicenseTerms ?? super.licenseTerms;
......
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