[lib.base_shell] remove base shell lib
This library is not longer needed.
Change-Id: Ia3d52fb59b12f336fc9372d509b1b9e672249949
diff --git a/lib/base_shell/BUILD.gn b/lib/base_shell/BUILD.gn
deleted file mode 100644
index 36859b2..0000000
--- a/lib/base_shell/BUILD.gn
+++ /dev/null
@@ -1,33 +0,0 @@
-# Copyright 2018 The Fuchsia 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("//build/dart/dart_library.gni")
-
-dart_library("lib.base_shell") {
- package_name = "lib.base_shell"
- sources_required = false
-
- sources = [
- "base_model.dart",
- "netstack_model.dart",
- "user_manager.dart",
- # Including these sources triggers analysis errors.
- # "base_shell_model.dart",
- # "base_shell_widget.dart",
- ]
-
- deps = [
- "//sdk/fidl/fuchsia.modular",
- "//sdk/fidl/fuchsia.modular.auth",
- "//sdk/fidl/fuchsia.netstack",
- "//sdk/fidl/fuchsia.timezone",
- "//sdk/fidl/fuchsia.ui.input",
- "//sdk/fidl/fuchsia.ui.views",
- "//third_party/dart-pkg/git/flutter/packages/flutter",
- "//topaz/public/dart/fidl",
- "//topaz/public/dart/fuchsia_scenic_flutter",
- "//topaz/public/dart/widgets:lib.widgets",
- "//zircon/system/fidl/fuchsia-net:fuchsia-net",
- ]
-}
diff --git a/lib/base_shell/analysis_options.yaml b/lib/base_shell/analysis_options.yaml
deleted file mode 100644
index 49a21d7..0000000
--- a/lib/base_shell/analysis_options.yaml
+++ /dev/null
@@ -1,6 +0,0 @@
-# Copyright 2018 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-include: ../analysis_options.yaml
-
diff --git a/lib/base_shell/lib/base_model.dart b/lib/base_shell/lib/base_model.dart
deleted file mode 100644
index b6f2711..0000000
--- a/lib/base_shell/lib/base_model.dart
+++ /dev/null
@@ -1,372 +0,0 @@
-// Copyright 2017 The Fuchsia 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 'dart:async';
-import 'dart:developer' show Timeline;
-
-import 'package:fidl/fidl.dart';
-import 'package:fidl_fuchsia_cobalt/fidl_async.dart' as cobalt;
-import 'package:fidl_fuchsia_modular/fidl_async.dart';
-import 'package:fidl_fuchsia_modular_auth/fidl_async.dart';
-import 'package:fidl_fuchsia_netstack/fidl_async.dart';
-import 'package:fidl_fuchsia_sys/fidl_async.dart';
-import 'package:fidl_fuchsia_ui_gfx/fidl_async.dart';
-import 'package:fidl_fuchsia_ui_input/fidl_async.dart' as input;
-import 'package:fidl_fuchsia_ui_policy/fidl_async.dart';
-import 'package:fuchsia_logger/logger.dart';
-import 'package:fuchsia_services/services.dart' as app;
-import 'package:meta/meta.dart';
-import 'package:zircon/zircon.dart' show Channel;
-
-import 'base_shell_model.dart';
-import 'netstack_model.dart';
-import 'user_manager.dart';
-
-export 'package:lib.widgets/model.dart'
- show ScopedModel, ScopedModelDescendant, ModelFinder;
-
-/// Function signature for GetPresentationMode callback
-typedef GetPresentationModeCallback = void Function(PresentationMode mode);
-
-const Duration _kCobaltTimerTimeout = Duration(seconds: 20);
-const int _kSessionShellLoginTimeMetricId = 14;
-
-// This class is extends the Presentation protocol and implements and PresentationModeListener.
-// It delegates the methods to the Presentation received by the CommonBaseShellModel that owns it.
-class CommonBaseShellPresentationImpl extends Presentation
- implements PresentationModeListener {
- final CommonBaseShellModel _model;
-
- CommonBaseShellPresentationImpl(this._model);
-
- /// |Presentation|.
- @override
- // ignore: avoid_positional_boolean_parameters
- Future<void> enableClipping(bool enabled) async {
- await _model.presentation.enableClipping(enabled);
- }
-
- @override
- Future<void> useOrthographicView() async {
- await _model.presentation.useOrthographicView();
- }
-
- @override
- Future<void> usePerspectiveView() async {
- await _model.presentation.usePerspectiveView();
- }
-
- @override
- Future<void> setRendererParams(List<RendererParam> params) async {
- await _model.presentation.setRendererParams(params);
- }
-
- @override
- Future<void> setDisplayUsage(DisplayUsage usage) async {
- await _model.presentation.setDisplayUsage(usage);
- }
-
- @override
- // ignore: avoid_positional_boolean_parameters
- Future<void> setDisplayRotation(
- double displayRotationDegrees, bool animate) async {
- await _model.presentation
- .setDisplayRotation(displayRotationDegrees, animate);
- }
-
- @override
- Future<void> setDisplaySizeInMm(num widthInMm, num heightInMm) async {
- await _model.presentation.setDisplaySizeInMm(widthInMm, heightInMm);
- }
-
- @override
- Future<void> captureKeyboardEventHack(input.KeyboardEvent eventToCapture,
- InterfaceHandle<KeyboardCaptureListenerHack> listener) async {
- await _model.presentation
- .captureKeyboardEventHack(eventToCapture, listener);
- }
-
- @override
- Future<void> capturePointerEventsHack(
- InterfaceHandle<PointerCaptureListenerHack> listener) async {
- await _model.presentation.capturePointerEventsHack(listener);
- }
-
- @override
- Future<PresentationMode> getPresentationMode() async {
- return await _model.presentation.getPresentationMode();
- }
-
- @override
- Future<void> setPresentationModeListener(
- InterfaceHandle<PresentationModeListener> listener) async {
- await _model.presentation.setPresentationModeListener(listener);
- }
-
- @override
- Future<void> registerMediaButtonsListener(
- InterfaceHandle<MediaButtonsListener> listener) async {
- await _model.presentation.registerMediaButtonsListener(listener);
- }
-
- /// |PresentationModeListener|.
- @override
- Future<void> onModeChanged() async {
- PresentationMode mode = await getPresentationMode();
- log.info('Presentation mode changed to: $mode');
- switch (mode) {
- case PresentationMode.tent:
- await setDisplayRotation(180.0, true);
- break;
- case PresentationMode.tablet:
- // TODO(sanjayc): Figure out up/down orientation.
- await setDisplayRotation(90.0, true);
- break;
- case PresentationMode.laptop:
- default:
- await setDisplayRotation(0.0, true);
- break;
- }
- }
-}
-
-/// Provides common features needed by all base shells.
-///
-/// This includes user management, presentation handling,
-/// and keyboard shortcuts.
-class CommonBaseShellModel extends BaseShellModel
- implements
- ServiceProvider,
- KeyboardCaptureListenerHack,
- PointerCaptureListenerHack {
- /// Handles login, logout, and adding/removing users.
- ///
- /// Shouldn't be used before onReady.
- BaseShellUserManager _userManager;
-
- NetstackModel _netstackModel;
-
- /// Logs metrics to Cobalt. May be null, in which case no metrics are logged.
- final cobalt.Logger logger;
-
- /// A list of accounts that are already logged in on the device.
- ///
- /// Only updated after [refreshUsers] is called.
- List<Account> _accounts;
-
- final List<KeyboardCaptureListenerHackBinding> _keyBindings = [];
-
- final PresentationModeListenerBinding _presentationModeListenerBinding =
- PresentationModeListenerBinding();
- final PointerCaptureListenerHackBinding _pointerCaptureListenerBinding =
- PointerCaptureListenerHackBinding();
-
- final List<PresentationBinding> _presentationBindings =
- <PresentationBinding>[];
-
- CommonBaseShellPresentationImpl _presentationImpl;
-
- /// Has the user logged in or not yet?
- bool _loggedIn = false;
-
- /// Constructor
- CommonBaseShellModel([this.logger]) : super() {
- _presentationImpl = CommonBaseShellPresentationImpl(this);
- }
-
- List<Account> get accounts => _accounts;
-
- // |ServiceProvider|.
- @override
- Future<void> connectToService(String serviceName, Channel channel) {
- if (serviceName == 'ui.Presentation') {
- _presentationBindings.add(PresentationBinding()
- ..bind(_presentationImpl, InterfaceRequest<Presentation>(channel)));
- } else {
- log.warning(
- 'UserPickerBaseShell: received request for unknown service: $serviceName !');
- channel.close();
- }
-
- return null;
- }
-
- /// Create a new user and login with that user
- Future createAndLoginUser() async {
- try {
- final userId = await _userManager.addUser();
- await login(userId);
- } on UserLoginException catch (ex) {
- log.severe(ex);
- } finally {
- notifyListeners();
- }
- }
-
- /// Whether or not the device has an internet connection.
- ///
- /// Currently, having an IP is equivalent to having internet, although
- /// this is not completely reliable. This will be always false until
- /// onReady is called.
- bool get hasInternetConnection =>
- _netstackModel?.networkReachable?.value ?? false;
-
- Future<void> waitForInternetConnection() async {
- if (hasInternetConnection) {
- return null;
- }
-
- final completer = Completer<void>();
-
- void listener() {
- if (hasInternetConnection) {
- _netstackModel.removeListener(listener);
- completer.complete();
- }
- }
-
- _netstackModel.addListener(listener);
-
- return completer.future;
- }
-
- /// Login with given user
- Future<void> login(String accountId) async {
- if (_loggedIn) {
- log.warning(
- 'Ignoring unsupported attempt to log in while already logged in!',
- );
- return;
- }
-
- Timeline.instantSync('logging in', arguments: {'accountId': '$accountId'});
-
- if (logger != null) {
- await logger
- .startTimer(
- _kSessionShellLoginTimeMetricId,
- 0,
- '',
- 'session_shell_login_timer_id',
- DateTime.now().millisecondsSinceEpoch,
- _kCobaltTimerTimeout.inSeconds)
- .then((status) {
- if (status != cobalt.Status.ok) {
- log.warning(
- 'Failed to start timer metric '
- '$_kSessionShellLoginTimeMetricId: $status. ',
- );
- }
- });
- }
-
- _userManager.login(accountId);
- _loggedIn = true;
-
- notifyListeners();
- }
-
- /// Called when the the session shell logs out.
- @mustCallSuper
- Future<void> onLogout() async {
- _loggedIn = false;
-
- for (PresentationBinding presentationBinding in _presentationBindings) {
- presentationBinding.close();
- }
- await refreshUsers();
-
- notifyListeners();
- }
-
- /// |KeyboardCaptureListener|.
- @override
- Future<void> onEvent(input.KeyboardEvent ev) async {}
-
- /// |PointerCaptureListener|.
- @override
- Future<void> onPointerEvent(input.PointerEvent event) async {}
-
- // |BaseShellModel|.
- // TODO: revert to default state when client logs out.
- @mustCallSuper
- @override
- Future<void> onReady(
- UserProvider userProvider,
- BaseShellContext baseShellContext,
- Presentation presentation,
- ) async {
- super.onReady(userProvider, baseShellContext, presentation);
-
- final netstackProxy = NetstackProxy();
- app.StartupContext.fromStartupInfo()
- .incoming
- .connectToService(netstackProxy);
- _netstackModel = NetstackModel(netstack: netstackProxy)..start();
-
- await presentation
- .capturePointerEventsHack(_pointerCaptureListenerBinding.wrap(this));
- await presentation.setPresentationModeListener(
- _presentationModeListenerBinding.wrap(_presentationImpl));
-
- _userManager = BaseShellUserManager(userProvider);
-
- _userManager.onLogout.listen((_) async {
- if (logger != null) {
- await logger
- .endTimer(
- 'session_shell_log_out_timer_id',
- DateTime.now().millisecondsSinceEpoch,
- _kCobaltTimerTimeout.inSeconds)
- .then((status) {
- if (status != cobalt.Status.ok) {
- log.warning(
- 'Failed to end timer metric '
- 'session_shell_log_out_timer_id: $status. ',
- );
- }
- });
- }
- log.info('UserPickerBaseShell: User logged out!');
- await onLogout();
- });
-
- await refreshUsers();
- }
-
- // |BaseShellModel|
- // TODO: revert to default state when client logs out.
- @override
- void onStop() {
- for (final binding in _keyBindings) {
- binding.close();
- }
- _presentationModeListenerBinding.close();
- _netstackModel.dispose();
- super.onStop();
- }
-
- // TODO: revert to default state when client logs out.
- /// Refreshes the list of users.
- Future<void> refreshUsers() async {
- _accounts = List<Account>.from(await _userManager.getPreviousUsers());
- notifyListeners();
- }
-
- // TODO: revert to default state when client logs out.
- /// Permanently removes the user.
- Future removeUser(Account account) async {
- try {
- await _userManager.removeUser(account.id);
- } on UserLoginException catch (ex) {
- log.severe(ex);
- } finally {
- await refreshUsers();
- }
- }
-
- @override
- // TODO: implement $serviceData
- ServiceData get $serviceData => null;
-}
diff --git a/lib/base_shell/lib/base_shell_model.dart b/lib/base_shell/lib/base_shell_model.dart
deleted file mode 100644
index aaa6435..0000000
--- a/lib/base_shell/lib/base_shell_model.dart
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2017 The Fuchsia 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:fidl_fuchsia_modular/fidl_async.dart';
-import 'package:fidl_fuchsia_ui_policy/fidl_async.dart';
-import 'package:lib.widgets/model.dart';
-import 'package:meta/meta.dart';
-
-export 'package:lib.widgets/model.dart' show ScopedModel, ScopedModelDescendant;
-
-/// The [Model] that provides a [BaseShellContext] and [UserProvider].
-class BaseShellModel extends Model {
- BaseShellContext _baseShellContext;
- UserProvider _userProvider;
- Presentation _presentation;
-
- /// The [BaseShellContext] given to this app's [BaseShell].
- BaseShellContext get baseShellContext => _baseShellContext;
-
- /// The [UserProvider] given to this app's [BaseShell].
- UserProvider get userProvider => _userProvider;
-
- /// The [Presentation] given to this app's [BaseShell].
- Presentation get presentation => _presentation;
-
- /// Called when this app's [BaseShell] is given its [BaseShellContext],
- /// and [UserProvider], and (optionally) its [Presentation].
- @mustCallSuper
- void onReady(
- UserProvider userProvider,
- BaseShellContext baseShellContext,
- Presentation presentation,
- ) {
- _userProvider = userProvider;
- _baseShellContext = baseShellContext;
- _presentation = presentation;
- notifyListeners();
- }
-
- /// Called when the app's [BaseShell] stops.
- void onStop() => null;
-}
diff --git a/lib/base_shell/lib/base_shell_widget.dart b/lib/base_shell/lib/base_shell_widget.dart
deleted file mode 100644
index b6026b9..0000000
--- a/lib/base_shell/lib/base_shell_widget.dart
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright 2017 The Fuchsia 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:fidl/fidl.dart';
-import 'package:fidl_fuchsia_auth/fidl_async.dart';
-import 'package:fidl_fuchsia_modular/fidl_async.dart';
-import 'package:flutter/material.dart';
-import 'package:flutter/widgets.dart';
-import 'package:fuchsia_services/services.dart' show StartupContext;
-import 'package:lib.device.dart/device.dart';
-import 'package:lib.widgets/widgets.dart' show WindowMediaQuery;
-import 'package:meta/meta.dart';
-
-import 'base_shell_model.dart';
-
-/// A wrapper widget intended to be the root of the application that is
-/// a [BaseShell]. Its main purpose is to hold the [StartupContext] and
-/// [BaseShell] instances so they aren't garbage collected.
-/// For convenience, [advertise] does the advertising of the app as a
-/// [BaseShell] to the rest of the system via the [StartupContext].
-/// Also for convienence, the [BaseShellModel] given to this widget
-/// will be made available to [child] and [child]'s descendants.
-class BaseShellWidget<T extends BaseShellModel> extends StatelessWidget {
- /// The [StartupContext] to [advertise] its [BaseShell] services to.
- final StartupContext startupContext;
-
- /// The bindings for the [BaseShell] service implemented by [BaseShellImpl].
- final Set<BaseShellBinding> _baseShellBindingSet =
- Set<BaseShellBinding>();
-
- /// The bindings for the [Lifecycle] service implemented by [BaseShellImpl].
- final Set<LifecycleBinding> _lifecycleBindingSet =
- Set<LifecycleBinding>();
-
- /// The [BaseShell] to [advertise].
- final BaseShellImpl _baseShell;
-
- /// The rest of the application.
- final Widget child;
-
- final T _baseShellModel;
-
- /// Constructor.
- BaseShellWidget({
- @required this.startupContext,
- T baseShellModel,
- AuthenticationUiContext authenticationUiContext,
- this.child,
- }) : _baseShellModel = baseShellModel,
- _baseShell = _createBaseShell(
- baseShellModel,
- authenticationUiContext,
- );
-
- @override
- Widget build(BuildContext context) => MaterialApp(
- home: Material(
- child: Directionality(
- textDirection: TextDirection.ltr,
- child: WindowMediaQuery(
- child: _baseShellModel == null
- ? child
- : ScopedModel<T>(model: _baseShellModel, child: child),
- ),
- ),
- ),
- );
-
- /// Advertises [_baseShell] as a [BaseShell] to the rest of the system via
- /// the [StartupContext].
- void advertise() {
- startupContext.outgoing
- ..addPublicService((InterfaceRequest<BaseShell> request) {
- BaseShellBinding binding = BaseShellBinding()
- ..bind(_baseShell, request);
- _baseShellBindingSet.add(binding);
- }, BaseShell.$serviceName)
- ..addPublicService((InterfaceRequest<Lifecycle> request) {
- LifecycleBinding binding = LifecycleBinding()
- ..bind(_baseShell, request);
- _lifecycleBindingSet.add(binding);
- }, Lifecycle.$serviceName);
- }
-
- static BaseShell _createBaseShell(
- BaseShellModel baseShellModel,
- AuthenticationUiContext authenticationUiContext,
- ) {
- return BaseShellImpl(
- authenticationUiContext: authenticationUiContext,
- onReady: baseShellModel?.onReady,
- onStop: () {
- baseShellModel?.onStop?.call();
- },
- );
- }
-
- /// Cancels any authentication flow currently in progress.
- void cancelAuthenticationFlow() {
- _baseShell.closeAuthenticationUiContextBindings();
- }
-}
diff --git a/lib/base_shell/lib/netstack_model.dart b/lib/base_shell/lib/netstack_model.dart
deleted file mode 100644
index 4384fa9..0000000
--- a/lib/base_shell/lib/netstack_model.dart
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2017 The Fuchsia 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 'dart:async';
-
-import 'package:fidl_fuchsia_net/fidl_async.dart' as net;
-import 'package:fidl_fuchsia_netstack/fidl_async.dart' as ns;
-import 'package:fidl_fuchsia_hardware_ethernet/fidl_async.dart' as eth;
-import 'package:flutter/widgets.dart';
-import 'package:fuchsia_services/services.dart';
-import 'package:lib.widgets/model.dart';
-
-/// Provides netstack information.
-class NetstackModel extends Model with TickerProviderModelMixin {
- /// The netstack containing networking information for the device.
- final ns.NetstackProxy netstack;
-
- StreamSubscription<bool> _reachabilitySubscription;
- StreamSubscription<List<ns.NetInterface>> _interfaceSubscription;
- final net.ConnectivityProxy connectivity = net.ConnectivityProxy();
-
- final ValueNotifier<bool> networkReachable = ValueNotifier<bool>(false);
-
- List<ns.NetInterface> _interfaces;
-
- /// Constructor.
- NetstackModel({this.netstack}) {
- StartupContext.fromStartupInfo().incoming.connectToService(connectivity);
- networkReachable.addListener(notifyListeners);
- _reachabilitySubscription =
- connectivity.onNetworkReachable.listen((reachable) {
- networkReachable.value = reachable;
- });
- }
-
- /// The current interfaces on the device.
- List<ns.NetInterface> get interfaces => _interfaces;
-
- void interfacesChanged(List<ns.NetInterface> interfaces) {
- _interfaces = interfaces
- .where((ns.NetInterface interface) =>
- interface.features & eth.infoFeatureLoopback == 0)
- .toList();
- notifyListeners();
- }
-
- /// Starts listening for netstack interfaces.
- void start() {
- _interfaceSubscription =
- netstack.onInterfacesChanged.listen(interfacesChanged);
- }
-
- /// Stops listening for netstack interfaces.
- void stop() {
- if (_interfaceSubscription != null) {
- _interfaceSubscription.cancel();
- _interfaceSubscription = null;
- }
-
- if (_reachabilitySubscription != null) {
- _reachabilitySubscription.cancel();
- _reachabilitySubscription = null;
- }
- }
-}
diff --git a/lib/base_shell/lib/user_manager.dart b/lib/base_shell/lib/user_manager.dart
deleted file mode 100644
index e02a559..0000000
--- a/lib/base_shell/lib/user_manager.dart
+++ /dev/null
@@ -1,86 +0,0 @@
-import 'dart:async';
-
-import 'package:fidl_fuchsia_modular/fidl_async.dart';
-import 'package:fidl_fuchsia_modular_auth/fidl_async.dart';
-import 'package:fuchsia_logger/logger.dart';
-
-/// Handles adding, removing, and logging, and controlling users.
-class BaseShellUserManager {
- final UserProvider _userProvider;
-
- final StreamController<void> _userLogoutController =
- StreamController<void>.broadcast();
-
- BaseShellUserManager(this._userProvider);
-
- Stream<void> get onLogout => _userLogoutController.stream;
-
- /// Adds a new user, displaying UI as required.
- ///
- /// The UI will be displayed in the space provided to authenticationContext
- /// in the base shell widget.
- Future<String> addUser() {
- final completer = Completer<String>();
-
- _userProvider.addUser(IdentityProvider.google).then((response) {
- if (response.errorCode == null || response.errorCode == '') {
- completer.complete(response.account.id);
- } else {
- log.warning('ERROR adding user! ${response.errorCode}');
- completer
- .completeError(UserLoginException('addUser', response.errorCode));
- }
- });
-
- return completer.future;
- }
-
- /// Logs in the user given by [accountId].
- void login(String accountId) {
- final UserLoginParams params = UserLoginParams(
- accountId: accountId,
- );
-
- _userProvider.login(params);
- }
-
- Future<void> removeUser(String userId) {
- final completer = Completer<void>();
-
- _userProvider.removeUser(userId).then((errorCode) {
- if (errorCode != null && errorCode != '') {
- completer
- .completeError(UserLoginException('removing $userId', errorCode));
- }
- completer.complete();
- });
-
- return completer.future;
- }
-
- /// Gets the list of accounts already logged in.
- Future<Iterable<Account>> getPreviousUsers() {
- final completer = Completer<Iterable<Account>>();
-
- _userProvider.previousUsers().then(completer.complete);
-
- return completer.future;
- }
-
- void close() {
- _userLogoutController.close();
- }
-}
-
-/// Exception thrown when performing user management operations.
-class UserLoginException implements Exception {
- final String errorCode;
- final String operation;
-
- UserLoginException(this.operation, this.errorCode);
-
- @override
- String toString() {
- return 'Failed during $operation: $errorCode';
- }
-}
diff --git a/lib/base_shell/pubspec.yaml b/lib/base_shell/pubspec.yaml
deleted file mode 100644
index 2a2ea63..0000000
--- a/lib/base_shell/pubspec.yaml
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright 2018 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-name: base_shell
-dependencies:
- flutter:
- sdk: flutter
\ No newline at end of file