Dan Albert | 9a894b7 | 2015-02-18 18:36:08 -0800 | [diff] [blame] | 1 | /* |
| 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> |
xunchang | 95d6732 | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 18 | #include <fcntl.h> |
Dan Albert | 9a894b7 | 2015-02-18 18:36:08 -0800 | [diff] [blame] | 19 | #include <signal.h> |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
xunchang | 95d6732 | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 22 | #include <strings.h> |
| 23 | |
| 24 | #include <android-base/logging.h> |
| 25 | #include <android-base/parseint.h> |
Dan Albert | 9a894b7 | 2015-02-18 18:36:08 -0800 | [diff] [blame] | 26 | |
Dan Albert | 8f6eb5c | 2015-02-24 22:07:18 -0800 | [diff] [blame] | 27 | #include "adb.h" |
Elliott Hughes | 9813f5b | 2015-06-23 11:12:58 -0700 | [diff] [blame] | 28 | #include "adb_auth.h" |
Dan Albert | 8f6eb5c | 2015-02-24 22:07:18 -0800 | [diff] [blame] | 29 | #include "transport.h" |
| 30 | |
xunchang | 95d6732 | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 31 | #include "minadbd_services.h" |
| 32 | #include "minadbd_types.h" |
Dan Albert | f3a5726 | 2015-02-19 13:21:14 -0800 | [diff] [blame] | 33 | |
Tao Bao | 378bfbf | 2019-04-16 14:22:25 -0700 | [diff] [blame] | 34 | using namespace std::string_literals; |
| 35 | |
xunchang | 95d6732 | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 36 | int main(int argc, char** argv) { |
| 37 | android::base::InitLogging(argv, &android::base::StderrLogger); |
| 38 | // TODO(xunchang) implement a command parser |
Tao Bao | 378bfbf | 2019-04-16 14:22:25 -0700 | [diff] [blame] | 39 | if ((argc != 3 && argc != 4) || argv[1] != "--socket_fd"s || |
| 40 | (argc == 4 && argv[3] != "--rescue"s)) { |
xunchang | 95d6732 | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 41 | LOG(ERROR) << "minadbd has invalid arguments, argc: " << argc; |
| 42 | exit(kMinadbdArgumentsParsingError); |
| 43 | } |
Dan Albert | 9a894b7 | 2015-02-18 18:36:08 -0800 | [diff] [blame] | 44 | |
xunchang | 95d6732 | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 45 | 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 Hughes | 9813f5b | 2015-06-23 11:12:58 -0700 | [diff] [blame] | 55 | |
Tao Bao | 378bfbf | 2019-04-16 14:22:25 -0700 | [diff] [blame] | 56 | if (argc == 4) { |
| 57 | SetMinadbdRescueMode(true); |
| 58 | adb_device_banner = "rescue"; |
| 59 | } else { |
Dan Albert | 9a894b7 | 2015-02-18 18:36:08 -0800 | [diff] [blame] | 60 | adb_device_banner = "sideload"; |
Tao Bao | 378bfbf | 2019-04-16 14:22:25 -0700 | [diff] [blame] | 61 | } |
Dan Albert | 9a894b7 | 2015-02-18 18:36:08 -0800 | [diff] [blame] | 62 | |
xunchang | 95d6732 | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 63 | signal(SIGPIPE, SIG_IGN); |
Dan Albert | 9a894b7 | 2015-02-18 18:36:08 -0800 | [diff] [blame] | 64 | |
xunchang | 95d6732 | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 65 | // We can't require authentication for sideloading. http://b/22025550. |
| 66 | auth_required = false; |
Dan Albert | 9a894b7 | 2015-02-18 18:36:08 -0800 | [diff] [blame] | 67 | |
xunchang | 95d6732 | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 68 | init_transport_registration(); |
| 69 | usb_init(); |
Dan Albert | 9a894b7 | 2015-02-18 18:36:08 -0800 | [diff] [blame] | 70 | |
Ethan Yonker | 534d4e0 | 2016-08-26 10:05:03 -0500 | [diff] [blame] | 71 | //VLOG(ADB) << "Event loop starting"; |
Dan Albert | 9a894b7 | 2015-02-18 18:36:08 -0800 | [diff] [blame] | 72 | fdevent_loop(); |
| 73 | |
xunchang | 95d6732 | 2019-04-05 16:16:07 -0700 | [diff] [blame] | 74 | return 0; |
Dan Albert | 9a894b7 | 2015-02-18 18:36:08 -0800 | [diff] [blame] | 75 | } |