TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / cmds / install.cpp
1 /*
2  * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3, as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranties of
10  * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11  * PURPOSE.  See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17
18 #include "anbox/cmds/install.h"
19 #include "anbox/dbus/stub/application_manager.h"
20
21 #include <core/dbus/asio/executor.h>
22
23 #include <boost/filesystem.hpp>
24
25 namespace fs = boost::filesystem;
26
27 anbox::cmds::Install::Install()
28     : CommandWithFlagsAndAction{
29           cli::Name{"install"}, cli::Usage{"install"},
30           cli::Description{
31               "Install specified application in the Android container"}} {
32   flag(cli::make_flag(cli::Name{"apk"},
33                       cli::Description{"Path to APK to install"}, apk_));
34   action([this](const cli::Command::Context&) {
35     if (apk_.length() == 0)
36       BOOST_THROW_EXCEPTION(std::runtime_error("No APK to install specified"));
37
38     if (!fs::is_regular_file(apk_))
39       BOOST_THROW_EXCEPTION(
40           std::runtime_error("Specified APK file does not exist"));
41
42     auto bus =
43         std::make_shared<core::dbus::Bus>(core::dbus::WellKnownBus::session);
44     bus->install_executor(core::dbus::asio::make_executor(bus));
45     auto stub = dbus::stub::ApplicationManager::create_for_bus(bus);
46
47     stub->install(apk_);
48
49     return EXIT_SUCCESS;
50   });
51 }