2 * Copyright (C) 2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
20 #include "anbox/cmds/wait_ready.h"
21 #include "anbox/dbus/stub/application_manager.h"
24 constexpr const unsigned int max_wait_attempts{30};
27 anbox::cmds::WaitReady::WaitReady()
28 : CommandWithFlagsAndAction{
29 cli::Name{"wait-ready"}, cli::Usage{"wait-ready"},
30 cli::Description{"Wait until the Android system has successfully booted"}} {
32 flag(cli::make_flag(cli::Name{"use-system-dbus"},
33 cli::Description{"Use system instead of session DBus"},
36 action([this](const cli::Command::Context&) {
37 auto bus_type = anbox::dbus::Bus::Type::Session;
39 bus_type = anbox::dbus::Bus::Type::System;
40 auto bus = std::make_shared<anbox::dbus::Bus>(bus_type);
42 auto stub = dbus::stub::ApplicationManager::create_for_bus(bus);
45 while (n < max_wait_attempts) {
46 stub->update_properties();
47 if (stub->ready().get())
50 std::this_thread::sleep_for(std::chrono::seconds{1});