blob: 9309ed749757a14f2bc6c3a393bb7d69ace35061 [file] [log] [blame]
Doug Zongker9270a202012-01-09 15:16:13 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Doug Zongker9270a202012-01-09 15:16:13 -080017#include <errno.h>
Dan Albert8f6eb5c2015-02-24 22:07:18 -080018#include <inttypes.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <unistd.h>
Doug Zongker9270a202012-01-09 15:16:13 -080023
Josh Gao038c4a12018-07-27 11:18:30 -070024#include <functional>
Tianjie Xu6af51a02017-04-19 14:00:52 -070025#include <string>
Tao Bao5de19e22019-01-02 09:35:59 -080026#include <string_view>
Josh Gao2aa0d3a2017-04-13 12:45:55 -070027#include <thread>
28
Doug Zongker9270a202012-01-09 15:16:13 -080029#include "adb.h"
Josh Gao038c4a12018-07-27 11:18:30 -070030#include "adb_unique_fd.h"
Dan Albert8f6eb5c2015-02-24 22:07:18 -080031#include "fdevent.h"
32#include "fuse_adb_provider.h"
Josh Gao038c4a12018-07-27 11:18:30 -070033#include "services.h"
Elliott Hughes24eb8a02016-06-15 15:12:17 -070034#include "sysdeps.h"
Doug Zongker9270a202012-01-09 15:16:13 -080035
Josh Gao038c4a12018-07-27 11:18:30 -070036static void sideload_host_service(unique_fd sfd, const std::string& args) {
katao77d61732018-09-20 20:34:05 +080037 int64_t file_size;
38 int block_size;
39 if ((sscanf(args.c_str(), "%" SCNd64 ":%d", &file_size, &block_size) != 2) || file_size <= 0 ||
40 block_size <= 0) {
41 printf("bad sideload-host arguments: %s\n", args.c_str());
42 exit(1);
43 }
Doug Zongker9270a202012-01-09 15:16:13 -080044
katao77d61732018-09-20 20:34:05 +080045 printf("sideload-host file size %" PRId64 " block size %d\n", file_size, block_size);
Doug Zongker9270a202012-01-09 15:16:13 -080046
katao77d61732018-09-20 20:34:05 +080047 int result = run_adb_fuse(sfd, file_size, block_size);
Doug Zongker9270a202012-01-09 15:16:13 -080048
katao77d61732018-09-20 20:34:05 +080049 printf("sideload_host finished\n");
50 exit(result == 0 ? 0 : 1);
Doug Zongker9270a202012-01-09 15:16:13 -080051}
52
Tao Bao5de19e22019-01-02 09:35:59 -080053unique_fd daemon_service_to_fd(std::string_view name, atransport* /* transport */) {
54 if (name.starts_with("sideload:")) {
55 // This exit status causes recovery to print a special error message saying to use a newer adb
56 // (that supports sideload-host).
Tao Bao99f0d9e2016-10-13 12:46:38 -070057 exit(3);
Tao Bao5de19e22019-01-02 09:35:59 -080058 } else if (name.starts_with("sideload-host:")) {
59 std::string arg(name.substr(strlen("sideload-host:")));
Josh Gao038c4a12018-07-27 11:18:30 -070060 return create_service_thread("sideload-host",
61 std::bind(sideload_host_service, std::placeholders::_1, arg));
Tao Bao99f0d9e2016-10-13 12:46:38 -070062 }
Josh Gao038c4a12018-07-27 11:18:30 -070063 return unique_fd{};
Doug Zongker9270a202012-01-09 15:16:13 -080064}