Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 32e9163b authored by Elliott Hughes's avatar Elliott Hughes
Browse files

resolved conflicts for merge of b471f524 to lmp-mr1-dev-plus-aosp

Change-Id: I6efd0d4a0ece0b065d02796916355ad5ae8b4eea
parents b1d67c1d cbdf4a95
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ LOCAL_SRC_FILES := \
	jdwp_service.c \
	framebuffer_service.c \
	remount_service.c \
	disable_verity_service.c \
	set_verity_enable_state_service.c \
	usb_linux_client.c

LOCAL_CFLAGS := \
+3 −1
Original line number Diff line number Diff line
@@ -328,8 +328,10 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri

#if !ADB_HOST
void framebuffer_service(int fd, void *cookie);
// Allow enable-verity to write to system and vendor block devices
int make_system_and_vendor_block_devices_writable();
void remount_service(int fd, void *cookie);
void disable_verity_service(int fd, void* cookie);
void set_verity_enabled_state_service(int fd, void* cookie);
#endif

/* packet allocator */
+99 −127
Original line number Diff line number Diff line
@@ -190,6 +190,8 @@ void help()
        "\n"
        "  adb restore <file>           - restore device contents from the <file> backup archive\n"
        "\n"
        "  adb disable-verity           - disable dm-verity checking on USERDEBUG builds\n"
        "  adb enable-verity            - re-enable dm-verity checking on USERDEBUG builds\n"
        "  adb keygen <file>            - generate adb public/private key. The private key is stored in <file>,\n"
        "                                 and the public key is stored in <file>.pub. Any existing files\n"
        "                                 are overwritten.\n"
@@ -1264,13 +1266,44 @@ int adb_commandline(int argc, char **argv)
        return r;
    }

top:
    if (argc == 0) {
        return usage();
    }

    /* adb_connect() commands */
    /* handle wait-for-* prefix */
    if (!strncmp(argv[0], "wait-for-", strlen("wait-for-"))) {
        char* service = argv[0];
        if (!strncmp(service, "wait-for-device", strlen("wait-for-device"))) {
            if (ttype == kTransportUsb) {
                service = "wait-for-usb";
            } else if (ttype == kTransportLocal) {
                service = "wait-for-local";
            } else {
                service = "wait-for-any";
            }
        }

        format_host_command(buf, sizeof buf, service, ttype, serial);

        if (adb_command(buf)) {
            D("failure: %s *\n",adb_error());
            fprintf(stderr,"error: %s\n", adb_error());
            return 1;
        }

        /* Allow a command to be run after wait-for-device,
            * e.g. 'adb wait-for-device shell'.
            */
        if (argc == 1) {
            return 0;
        }

        /* Fall through */
        argc--;
        argv++;
    }

    /* adb_connect() commands */
    if (!strcmp(argv[0], "devices")) {
        char *tmp;
        char *listopt;
@@ -1292,8 +1325,7 @@ top:
            return 1;
        }
    }

    if(!strcmp(argv[0], "connect")) {
    else if (!strcmp(argv[0], "connect")) {
        char *tmp;
        if (argc != 2) {
            fprintf(stderr, "Usage: adb connect <host>[:<port>]\n");
@@ -1308,8 +1340,7 @@ top:
            return 1;
        }
    }

    if(!strcmp(argv[0], "disconnect")) {
    else if (!strcmp(argv[0], "disconnect")) {
        char *tmp;
        if (argc > 2) {
            fprintf(stderr, "Usage: adb disconnect [<host>[:<port>]]\n");
@@ -1328,12 +1359,10 @@ top:
            return 1;
        }
    }

    if (!strcmp(argv[0], "emu")) {
    else if (!strcmp(argv[0], "emu")) {
        return adb_send_emulator_command(argc, argv);
    }

    if(!strcmp(argv[0], "shell") || !strcmp(argv[0], "hell")) {
    else if (!strcmp(argv[0], "shell") || !strcmp(argv[0], "hell")) {
        int r;
        int fd;

@@ -1392,8 +1421,7 @@ top:
            }
        }
    }

    if (!strcmp(argv[0], "exec-in") || !strcmp(argv[0], "exec-out")) {
    else if (!strcmp(argv[0], "exec-in") || !strcmp(argv[0], "exec-out")) {
        int exec_in = !strcmp(argv[0], "exec-in");
        int fd;

@@ -1422,8 +1450,7 @@ top:
        adb_close(fd);
        return 0;
    }

    if(!strcmp(argv[0], "kill-server")) {
    else if (!strcmp(argv[0], "kill-server")) {
        int fd;
        fd = _adb_connect("host:kill");
        if (fd == -1) {
@@ -1432,8 +1459,7 @@ top:
        }
        return 0;
    }

    if(!strcmp(argv[0], "sideload")) {
    else if (!strcmp(argv[0], "sideload")) {
        if (argc != 2) return usage();
        if (adb_sideload_host(argv[1])) {
            return 1;
@@ -1441,11 +1467,14 @@ top:
            return 0;
        }
    }

    if(!strcmp(argv[0], "remount") || !strcmp(argv[0], "reboot")
            || !strcmp(argv[0], "reboot-bootloader")
            || !strcmp(argv[0], "tcpip") || !strcmp(argv[0], "usb")
            || !strcmp(argv[0], "root") || !strcmp(argv[0], "disable-verity")) {
    else if (!strcmp(argv[0], "remount") ||
             !strcmp(argv[0], "reboot") ||
             !strcmp(argv[0], "reboot-bootloader") ||
             !strcmp(argv[0], "tcpip") ||
             !strcmp(argv[0], "usb") ||
             !strcmp(argv[0], "root") ||
             !strcmp(argv[0], "disable-verity") ||
             !strcmp(argv[0], "enable-verity")) {
        char command[100];
        if (!strcmp(argv[0], "reboot-bootloader"))
            snprintf(command, sizeof(command), "reboot:bootloader");
@@ -1462,49 +1491,13 @@ top:
        fprintf(stderr,"error: %s\n", adb_error());
        return 1;
    }

    if(!strcmp(argv[0], "bugreport")) {
    else if (!strcmp(argv[0], "bugreport")) {
        if (argc != 1) return usage();
        do_cmd(ttype, serial, "shell", "bugreport", 0);
        return 0;
    }

    /* adb_command() wrapper commands */

    if(!strncmp(argv[0], "wait-for-", strlen("wait-for-"))) {
        char* service = argv[0];
        if (!strncmp(service, "wait-for-device", strlen("wait-for-device"))) {
            if (ttype == kTransportUsb) {
                service = "wait-for-usb";
            } else if (ttype == kTransportLocal) {
                service = "wait-for-local";
            } else {
                service = "wait-for-any";
            }
        }

        format_host_command(buf, sizeof buf, service, ttype, serial);

        if (adb_command(buf)) {
            D("failure: %s *\n",adb_error());
            fprintf(stderr,"error: %s\n", adb_error());
            return 1;
        }

        /* Allow a command to be run after wait-for-device,
            * e.g. 'adb wait-for-device shell'.
            */
        if(argc > 1) {
            argc--;
            argv++;
            goto top;
        }
        return 0;
    }

    if(!strcmp(argv[0], "forward") ||
       !strcmp(argv[0], "reverse"))
    {
    else if (!strcmp(argv[0], "forward") || !strcmp(argv[0], "reverse")) {
        char host_prefix[64];
        char reverse = (char) !strcmp(argv[0], "reverse");
        char remove = 0;
@@ -1595,15 +1588,12 @@ top:
        }
        return 0;
    }

    /* do_sync_*() commands */

    if(!strcmp(argv[0], "ls")) {
    else if (!strcmp(argv[0], "ls")) {
        if (argc != 2) return usage();
        return do_sync_ls(argv[1]);
    }

    if(!strcmp(argv[0], "push")) {
    else if (!strcmp(argv[0], "push")) {
        int show_progress = 0;
        int copy_attrs = 0; // unused
        const char* lpath = NULL, *rpath = NULL;
@@ -1616,8 +1606,7 @@ top:

        return usage();
    }

    if(!strcmp(argv[0], "pull")) {
    else if (!strcmp(argv[0], "pull")) {
        int show_progress = 0;
        int copy_attrs = 0;
        const char* rpath = NULL, *lpath = ".";
@@ -1630,23 +1619,19 @@ top:

        return usage();
    }

    if (!strcmp(argv[0], "install")) {
    else if (!strcmp(argv[0], "install")) {
        if (argc < 2) return usage();
        return install_app(ttype, serial, argc, argv);
    }

    if (!strcmp(argv[0], "install-multiple")) {
    else if (!strcmp(argv[0], "install-multiple")) {
        if (argc < 2) return usage();
        return install_multiple_app(ttype, serial, argc, argv);
    }

    if (!strcmp(argv[0], "uninstall")) {
    else if (!strcmp(argv[0], "uninstall")) {
        if (argc < 2) return usage();
        return uninstall_app(ttype, serial, argc, argv);
    }

    if(!strcmp(argv[0], "sync")) {
    else if (!strcmp(argv[0], "sync")) {
        char *srcarg, *android_srcpath, *data_srcpath, *vendor_srcpath;
        int listonly = 0;

@@ -1682,10 +1667,8 @@ top:
        free(data_srcpath);
        return ret;
    }

    /* passthrough commands */

    if(!strcmp(argv[0],"get-state") ||
    else if (!strcmp(argv[0],"get-state") ||
        !strcmp(argv[0],"get-serialno") ||
        !strcmp(argv[0],"get-devpath"))
    {
@@ -1700,40 +1683,31 @@ top:
            return 1;
        }
    }

    /* other commands */

    if(!strcmp(argv[0],"status-window")) {
    else if (!strcmp(argv[0],"status-window")) {
        status_window(ttype, serial);
        return 0;
    }

    if(!strcmp(argv[0],"logcat") || !strcmp(argv[0],"lolcat") || !strcmp(argv[0],"longcat")) {
    else if (!strcmp(argv[0],"logcat") || !strcmp(argv[0],"lolcat") || !strcmp(argv[0],"longcat")) {
        return logcat(ttype, serial, argc, argv);
    }

    if(!strcmp(argv[0],"ppp")) {
    else if (!strcmp(argv[0],"ppp")) {
        return ppp(argc, argv);
    }

    if (!strcmp(argv[0], "start-server")) {
    else if (!strcmp(argv[0], "start-server")) {
        return adb_connect("host:start-server");
    }

    if (!strcmp(argv[0], "backup")) {
    else if (!strcmp(argv[0], "backup")) {
        return backup(argc, argv);
    }

    if (!strcmp(argv[0], "restore")) {
    else if (!strcmp(argv[0], "restore")) {
        return restore(argc, argv);
    }

    if (!strcmp(argv[0], "keygen")) {
    else if (!strcmp(argv[0], "keygen")) {
        if (argc < 2) return usage();
        return adb_auth_keygen(argv[1]);
    }

    if (!strcmp(argv[0], "jdwp")) {
    else if (!strcmp(argv[0], "jdwp")) {
        int  fd = adb_connect("jdwp");
        if (fd >= 0) {
            read_and_dump(fd);
@@ -1744,14 +1718,12 @@ top:
            return -1;
        }
    }

    /* "adb /?" is a common idiom under Windows */
    if(!strcmp(argv[0], "help") || !strcmp(argv[0], "/?")) {
    else if (!strcmp(argv[0], "help") || !strcmp(argv[0], "/?")) {
        help();
        return 0;
    }

    if(!strcmp(argv[0], "version")) {
    else if (!strcmp(argv[0], "version")) {
        version(stdout);
        return 0;
    }
+58 −9
Original line number Diff line number Diff line
@@ -79,29 +79,57 @@ static int hasVendorPartition()
    return false;
}

static int make_block_device_writable(const char* dir)
{
    char *dev = 0;
    int fd = -1;
    int OFF = 0;
    int rc = -1;

    dev = find_mount(dir);
    if (!dev)
        goto errout;

    fd = unix_open(dev, O_RDONLY | O_CLOEXEC);
    if (fd < 0)
        goto errout;

    if (ioctl(fd, BLKROSET, &OFF)) {
        goto errout;
    }

    rc = 0;

errout:
    if (fd >= 0) {
        adb_close(fd);
    }

    if (dev) {
        free(dev);
    }
    return rc;
}

/* Init mounts /system as read only, remount to enable writes. */
static int remount(const char* dir, int* dir_ro)
{
    char *dev;
    int fd;
    int OFF = 0;

    if (dir_ro == 0) {
        return 0;
    }

    if (make_block_device_writable(dir)) {
        return -1;
    }

    dev = find_mount(dir);

    if (!dev)
        return -1;

    fd = unix_open(dev, O_RDONLY | O_CLOEXEC);
    if (fd < 0)
        return -1;

    ioctl(fd, BLKROSET, &OFF);
    adb_close(fd);

    *dir_ro = mount(dev, dir, "none", MS_REMOUNT, NULL);

    free(dev);
@@ -114,6 +142,28 @@ static void write_string(int fd, const char* str)
    writex(fd, str, strlen(str));
}

int make_system_and_vendor_block_devices_writable(int fd)
{
    char buffer[200];
    if (make_block_device_writable("/system")) {
        snprintf(buffer, sizeof(buffer),
                 "Failed to make system block device writable %s\n",
                 strerror(errno));
        write_string(fd, buffer);
        return -1;
    }

    if (hasVendorPartition() && make_block_device_writable("/vendor")) {
        snprintf(buffer, sizeof(buffer),
                 "Failed to make vendor block device writable: %s\n",
                 strerror(errno));
        write_string(fd, buffer);
        return -1;
    }

    return 0;
}

void remount_service(int fd, void *cookie)
{
    char buffer[200];
@@ -167,4 +217,3 @@ void remount_service(int fd, void *cookie)

    adb_close(fd);
}
+3 −1
Original line number Diff line number Diff line
@@ -472,7 +472,9 @@ int service_to_fd(const char *name)
            }
        }
    } else if(!strncmp(name, "disable-verity:", 15)) {
        ret = create_service_thread(disable_verity_service, NULL);
        ret = create_service_thread(set_verity_enabled_state_service, (void*)0);
    } else if(!strncmp(name, "enable-verity:", 15)) {
        ret = create_service_thread(set_verity_enabled_state_service, (void*)1);
#endif
    }
    if (ret >= 0) {
Loading