diff --git a/examples/material_gallery/android/AndroidManifest.xml b/examples/material_gallery/android/AndroidManifest.xml index 2fbd96d14ea..951c123523c 100644 --- a/examples/material_gallery/android/AndroidManifest.xml +++ b/examples/material_gallery/android/AndroidManifest.xml @@ -15,9 +15,5 @@ - diff --git a/packages/updater/.gitignore b/packages/updater/.gitignore deleted file mode 100644 index b9a62f75231..00000000000 --- a/packages/updater/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.idea -.pub/ -pubspec.lock diff --git a/packages/updater/lib/main.dart b/packages/updater/lib/main.dart deleted file mode 100644 index 4f748f6e446..00000000000 --- a/packages/updater/lib/main.dart +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2015 The Chromium 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:io'; - -import 'package:mojo/core.dart'; -import 'package:flutter/http.dart' as http; -import 'package:flutter/services.dart'; -import 'package:flx/bundle.dart'; -import 'package:sky_services/updater/update_service.mojom.dart'; -import 'package:path/path.dart' as path; -import 'package:yaml/yaml.dart' as yaml; - -import 'pipe_to_file.dart'; -import 'version.dart'; - -const String kManifestFile = 'flutter.yaml'; -const String kBundleFile = 'app.flx'; - -UpdateServiceProxy _initUpdateService() { - UpdateServiceProxy updateService = new UpdateServiceProxy.unbound(); - shell.connectToService(null, updateService); - return updateService; -} - -final UpdateServiceProxy _updateService = _initUpdateService(); - -String cachedDataDir = null; -Future getDataDir() async { - if (cachedDataDir == null) - cachedDataDir = await getAppDataDir(); - return cachedDataDir; -} - -class UpdateFailure extends Error { - UpdateFailure(this._message); - String _message; - String toString() => _message; -} - -class UpdateTask { - UpdateTask(); - - Future run() async { - try { - await _runImpl(); - } on UpdateFailure catch (e) { - print('Update failed: $e'); - } catch (e, stackTrace) { - print('Update failed: $e'); - print('Stack: $stackTrace'); - } finally { - _updateService.ptr.notifyUpdateCheckComplete(); - } - } - - Future _runImpl() async { - _dataDir = await getDataDir(); - - await _readLocalManifest(); - yaml.YamlMap remoteManifest = await _fetchManifest(); - if (!_shouldUpdate(remoteManifest)) { - print('Update skipped. No new version.'); - return; - } - await _fetchBundle(); - await _validateBundle(); - await _replaceBundle(); - print('Update success.'); - } - - Map _currentManifest; - String _dataDir; - String _tempPath; - - Future _readLocalManifest() async { - String bundlePath = path.join(_dataDir, kBundleFile); - Bundle bundle = await Bundle.readHeader(bundlePath); - _currentManifest = bundle.manifest; - } - - Future _fetchManifest() async { - String manifestUrl = _currentManifest['update-url'] + '/' + kManifestFile; - String manifestData = (await http.get(manifestUrl)).body; - return yaml.loadYaml(manifestData, sourceUrl: manifestUrl); - } - - bool _shouldUpdate(yaml.YamlMap remoteManifest) { - Version currentVersion = new Version(_currentManifest['version']); - Version remoteVersion = new Version(remoteManifest['version']); - return (currentVersion < remoteVersion); - } - - Future _fetchBundle() async { - // TODO(mpcomplete): Use the cache dir. We need an equivalent of mkstemp(). - _tempPath = path.join(_dataDir, 'tmp.skyx'); - String bundleUrl = _currentManifest['update-url'] + '/' + kBundleFile; - UrlResponse response = await fetchUrl(bundleUrl); - int result = await PipeToFile.copyToFile(response.body, _tempPath); - if (result != MojoResult.kOk) - throw new UpdateFailure('Failure fetching new package: ${response.statusLine}'); - } - - Future _validateBundle() async { - Bundle bundle = await Bundle.readHeader(_tempPath); - - if (bundle == null) - throw new UpdateFailure('Remote package not a valid FLX file.'); - if (bundle.manifest['key'] != _currentManifest['key']) - throw new UpdateFailure('Remote package key does not match.'); - if (!await bundle.verifyContent()) - throw new UpdateFailure('Invalid package signature or hash. This package has been tampered with.'); - } - - Future _replaceBundle() async { - String bundlePath = path.join(_dataDir, kBundleFile); - await new File(_tempPath).rename(bundlePath); - } -} - -void main() { - UpdateTask task = new UpdateTask(); - task.run(); -} diff --git a/packages/updater/lib/pipe_to_file.dart b/packages/updater/lib/pipe_to_file.dart deleted file mode 100644 index d11663908b5..00000000000 --- a/packages/updater/lib/pipe_to_file.dart +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2015 The Chromium 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:io'; -import 'dart:typed_data'; - -import 'package:mojo/core.dart'; - -// Helper class to drain the contents of a mojo data pipe to a file. -class PipeToFile { - MojoDataPipeConsumer _consumer; - MojoEventSubscription _events; - IOSink _outputStream; - - PipeToFile(this._consumer, String outputPath) { - _events = new MojoEventSubscription(_consumer.handle); - _outputStream = new File(outputPath).openWrite(); - } - - Future _doRead() async { - ByteData thisRead = _consumer.beginRead(); - if (thisRead == null) { - throw 'Data pipe beginRead failed: ${_consumer.status}'; - } - // TODO(mpcomplete): Should I worry about the _eventStream listen callback - // being invoked again before this completes? - await _outputStream.add(thisRead.buffer.asUint8List()); - return _consumer.endRead(thisRead.lengthInBytes); - } - - Future drain() { - Completer completer = new Completer(); - _events.subscribe((int signal) { - (() async { - if (MojoHandleSignals.isReadable(signal)) { - int result = await _doRead(); - if (result != MojoResult.kOk) { - _events.close(); - _events = null; - _outputStream.close(); - completer.complete(result); - } else { - _events.enableReadEvents(); - } - } else if (MojoHandleSignals.isPeerClosed(signal)) { - _events.close(); - _events = null; - _outputStream.close(); - completer.complete(MojoResult.kOk); - } else { - throw 'Unexpected handle event: ${MojoHandleSignals.string(signal)}'; - } - })(); - }); - return completer.future; - } - - static Future copyToFile(MojoDataPipeConsumer consumer, String outputPath) { - PipeToFile drainer = new PipeToFile(consumer, outputPath); - return drainer.drain(); - } -} diff --git a/packages/updater/lib/version.dart b/packages/updater/lib/version.dart deleted file mode 100644 index 15c1ab7d5c2..00000000000 --- a/packages/updater/lib/version.dart +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2015 The Chromium 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:math'; - -// This class represents a dot-separated version string. Used for comparing -// versions. -// Usage: assert(new Version('1.1.0') < new Version('1.2.1')); -class Version { - Version(String versionStr) : - _parts = versionStr.split('.').map((String val) => int.parse(val)).toList(); - - List _parts; - - bool operator<(Version other) => _compare(other) < 0; - bool operator==(dynamic other) => other is Version && _compare(other) == 0; - bool operator>(Version other) => _compare(other) > 0; - - int _compare(Version other) { - int length = min(_parts.length, other._parts.length); - for (int i = 0; i < length; ++i) { - if (_parts[i] < other._parts[i]) - return -1; - if (_parts[i] > other._parts[i]) - return 1; - } - return _parts.length - other._parts.length; // results in 1.0 < 1.0.0 - } - - int get hashCode => _parts.fold(373, (int acc, int part) => 37*acc + part); -} diff --git a/packages/updater/pubspec.yaml b/packages/updater/pubspec.yaml deleted file mode 100644 index 192dd01afb5..00000000000 --- a/packages/updater/pubspec.yaml +++ /dev/null @@ -1,16 +0,0 @@ -name: updater -author: Flutter Authors -description: An autoupdater for Flutter -homepage: http://flutter.io -dependencies: - path: ^1.3.0 - yaml: ^2.1.3 - - # TODO(abarth): Updater should not depend on flutter - flutter: - path: ../flutter - flx: - path: ../flx - -environment: - sdk: '>=1.12.0 <2.0.0'