• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import '../base/process.dart';
6
7import 'fuchsia_device.dart';
8import 'fuchsia_pm.dart';
9
10// usage: amber_ctl <command> [opts]
11// Commands
12//     get_up        - get an update for a package
13//       Options
14//         -n:      name of the package
15//         -v:      version of the package to retrieve, if none is supplied any
16//                  package instance could match
17//         -m:      merkle root of the package to retrieve, if none is supplied
18//                  any package instance could match
19//
20//     get_blob      - get the specified content blob
21//         -i: content ID of the blob
22//
23//     add_src       - add a source to the list we can use
24//         -n: name of the update source (optional, with URL)
25//         -f: file path or url to a source config file
26//         -h: SHA256 hash of source config file (optional, with URL)
27//         -x: do not disable other active sources (if the provided source is
28//             enabled)
29//
30//     add_repo_cfg  - add a repository config to the set of known repositories,
31//                     using a source config
32//         -n: name of the update source (optional, with URL)
33//         -f: file path or url to a source config file
34//         -h: SHA256 hash of source config file (optional, with URL)
35//
36//     rm_src        - remove a source, if it exists
37//         -n: name of the update source
38//
39//     list_srcs     - list the set of sources we can use
40//
41//     enable_src
42//         -n: name of the update source
43//         -x: do not disable other active sources
44//
45//     disable_src
46//         -n: name of the update source
47//
48//     system_update - check for, download, and apply any available system
49//                     update
50//
51//     gc - trigger a garbage collection
52//
53//     print_state - print go routine state of amber process
54
55/// Simple wrapper for interacting with the 'amber_ctl' tool running on the
56/// Fuchsia device.
57class FuchsiaAmberCtl {
58  /// Teaches the amber instance running on [device] about the Fuchsia package
59  /// server accessible via [configUrl].
60  Future<bool> addSrc(FuchsiaDevice device, FuchsiaPackageServer server) async {
61    final String configUrl = '${server.url}/config.json';
62    final RunResult result =
63        await device.shell('amber_ctl add_src -x -f $configUrl');
64    return result.exitCode == 0;
65  }
66
67  /// Instructs the amber instance running on [device] to forget about the
68  /// Fuchsia package server that it was accessing via [serverUrl].
69  Future<bool> rmSrc(FuchsiaDevice device, FuchsiaPackageServer server) async {
70    final RunResult result =
71        await device.shell('amber_ctl rm_src -n ${server.url}');
72    return result.exitCode == 0;
73  }
74
75  /// Instructs the amber instance running on [device] to prefetch the package
76  /// [packageName].
77  Future<bool> getUp(FuchsiaDevice device, String packageName) async {
78    final RunResult result =
79        await device.shell('amber_ctl get_up -n $packageName');
80    return result.exitCode == 0;
81  }
82
83  /// Converts the amber source config created when [server] was set up to a
84  /// pkg_resolver repo config, and teaches the pkg_resolver instance running
85  /// on [device] about the [FuchsiaPackageServer].
86  Future<bool> addRepoCfg(FuchsiaDevice device, FuchsiaPackageServer server) async {
87    final String configUrl = '${server.url}/config.json';
88    final RunResult result =
89        await device.shell('amber_ctl add_repo_cfg -n ${server.name} -f $configUrl');
90    return result.exitCode == 0;
91  }
92
93  /// Instructs the pkg_resolver instance running on [device] to prefetch the
94  /// package [packageName].
95  Future<bool> pkgCtlResolve(FuchsiaDevice device, FuchsiaPackageServer server,
96                             String packageName) async {
97    final String packageUrl = 'fuchsia-pkg://${server.name}/$packageName';
98    final RunResult result = await device.shell('pkgctl resolve $packageUrl');
99    return result.exitCode == 0;
100  }
101
102  /// Instructs the pkg_resolver instance running on [device] to forget about
103  /// the Fuchsia package server that it was accessing via [serverUrl].
104  Future<bool> pkgCtlRepoRemove(FuchsiaDevice device, FuchsiaPackageServer server) async {
105    final String repoUrl = 'fuchsia-pkg://${server.name}';
106    final RunResult result = await device.shell('pkgctl repo remove --repo-url $repoUrl');
107    return result.exitCode == 0;
108  }
109}
110