blob: 388d414347c1768d478e6f04976268a925b17742 [file] [log] [blame]
Dan Albert9a894b72015-02-18 18:36:08 -08001/*
2 * Copyright (C) 2015 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
17#include <errno.h>
xunchang95d67322019-04-05 16:16:07 -070018#include <fcntl.h>
Dan Albert9a894b72015-02-18 18:36:08 -080019#include <signal.h>
20#include <stdio.h>
21#include <stdlib.h>
xunchang95d67322019-04-05 16:16:07 -070022#include <strings.h>
23
24#include <android-base/logging.h>
25#include <android-base/parseint.h>
Dan Albert9a894b72015-02-18 18:36:08 -080026
Dan Albert8f6eb5c2015-02-24 22:07:18 -080027#include "adb.h"
Elliott Hughes9813f5b2015-06-23 11:12:58 -070028#include "adb_auth.h"
Dan Albert8f6eb5c2015-02-24 22:07:18 -080029#include "transport.h"
30
xunchang95d67322019-04-05 16:16:07 -070031#include "minadbd_services.h"
32#include "minadbd_types.h"
Dan Albertf3a57262015-02-19 13:21:14 -080033
Tao Bao378bfbf2019-04-16 14:22:25 -070034using namespace std::string_literals;
35
xunchang95d67322019-04-05 16:16:07 -070036int main(int argc, char** argv) {
37 android::base::InitLogging(argv, &android::base::StderrLogger);
38 // TODO(xunchang) implement a command parser
Tao Bao378bfbf2019-04-16 14:22:25 -070039 if ((argc != 3 && argc != 4) || argv[1] != "--socket_fd"s ||
40 (argc == 4 && argv[3] != "--rescue"s)) {
xunchang95d67322019-04-05 16:16:07 -070041 LOG(ERROR) << "minadbd has invalid arguments, argc: " << argc;
42 exit(kMinadbdArgumentsParsingError);
43 }
Dan Albert9a894b72015-02-18 18:36:08 -080044
xunchang95d67322019-04-05 16:16:07 -070045 int socket_fd;
46 if (!android::base::ParseInt(argv[2], &socket_fd)) {
47 LOG(ERROR) << "Failed to parse int in " << argv[2];
48 exit(kMinadbdArgumentsParsingError);
49 }
50 if (fcntl(socket_fd, F_GETFD, 0) == -1) {
51 PLOG(ERROR) << "Failed to get minadbd socket";
52 exit(kMinadbdSocketIOError);
53 }
54 SetMinadbdSocketFd(socket_fd);
Elliott Hughes9813f5b2015-06-23 11:12:58 -070055
Tao Bao378bfbf2019-04-16 14:22:25 -070056 if (argc == 4) {
57 SetMinadbdRescueMode(true);
58 adb_device_banner = "rescue";
59 } else {
Dan Albert9a894b72015-02-18 18:36:08 -080060 adb_device_banner = "sideload";
Tao Bao378bfbf2019-04-16 14:22:25 -070061 }
Dan Albert9a894b72015-02-18 18:36:08 -080062
xunchang95d67322019-04-05 16:16:07 -070063 signal(SIGPIPE, SIG_IGN);
Dan Albert9a894b72015-02-18 18:36:08 -080064
xunchang95d67322019-04-05 16:16:07 -070065 // We can't require authentication for sideloading. http://b/22025550.
66 auth_required = false;
Dan Albert9a894b72015-02-18 18:36:08 -080067
xunchang95d67322019-04-05 16:16:07 -070068 init_transport_registration();
69 usb_init();
Dan Albert9a894b72015-02-18 18:36:08 -080070
bigbiff26d5d5f2020-03-23 09:56:16 -040071<<<<<<< HEAD
Ethan Yonker534d4e02016-08-26 10:05:03 -050072 //VLOG(ADB) << "Event loop starting";
Dan Albert9a894b72015-02-18 18:36:08 -080073 fdevent_loop();
bigbiff26d5d5f2020-03-23 09:56:16 -040074=======
xunchang95d67322019-04-05 16:16:07 -070075 VLOG(ADB) << "Event loop starting";
76 fdevent_loop();
bigbiff26d5d5f2020-03-23 09:56:16 -040077>>>>>>> android-10.0.0_r25
Dan Albert9a894b72015-02-18 18:36:08 -080078
xunchang95d67322019-04-05 16:16:07 -070079 return 0;
Dan Albert9a894b72015-02-18 18:36:08 -080080}