void show_reboot_menu()
{
    static char* headers[] = {  "Reboot Selection Menu",
                                "",
                                NULL
    };
    for (;;)
    {
        int chosen_item = get_menu_selection(headers, REBOOT_MENU_ITEMS, 0, 0);
        switch (chosen_item)
        {
            case ITEM_REBOOT_NORMAL:
                android_reboot(ANDROID_RB_RESTART, 0, 0);
                break;
            case ITEM_REBOOT_RECOVERY:
                android_reboot(ANDROID_RB_RESTART2, 2, "recovery");
                break;
            case ITEM_REBOOT_DOWNLOAD:
                android_reboot(ANDROID_RB_RESTART2, 2, "download");
                break;
            default:
                return;
        }

    }
}
// reboot: Reboot the system. Return -1 on error, no return on success
int TWFunc::tw_reboot(RebootCommand command)
{
	// Always force a sync before we reboot
	sync();
	Update_Log_File();

	switch (command) {
		case rb_current:
		case rb_system:
			Update_Intent_File("s");
			sync();
			check_and_run_script("/sbin/rebootsystem.sh", "reboot system");
#ifdef ANDROID_RB_PROPERTY
			return property_set(ANDROID_RB_PROPERTY, "reboot,");
#elif defined(ANDROID_RB_RESTART)
			return android_reboot(ANDROID_RB_RESTART, 0, 0);
#else
			return reboot(RB_AUTOBOOT);
#endif
		case rb_recovery:
			check_and_run_script("/sbin/rebootrecovery.sh", "reboot recovery");
#ifdef ANDROID_RB_PROPERTY
			return property_set(ANDROID_RB_PROPERTY, "reboot,recovery");
#else
			return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "recovery");
#endif
		case rb_bootloader:
			check_and_run_script("/sbin/rebootbootloader.sh", "reboot bootloader");
#ifdef ANDROID_RB_PROPERTY
			return property_set(ANDROID_RB_PROPERTY, "reboot,bootloader");
#else
			return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "bootloader");
#endif
		case rb_poweroff:
			check_and_run_script("/sbin/poweroff.sh", "power off");
#ifdef ANDROID_RB_PROPERTY
			return property_set(ANDROID_RB_PROPERTY, "shutdown,");
#elif defined(ANDROID_RB_POWEROFF)
			return android_reboot(ANDROID_RB_POWEROFF, 0, 0);
#else
			return reboot(RB_POWER_OFF);
#endif
		case rb_download:
			check_and_run_script("/sbin/rebootdownload.sh", "reboot download");
#ifdef ANDROID_RB_PROPERTY
			return property_set(ANDROID_RB_PROPERTY, "reboot,download");
#else
			return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "download");
#endif
		default:
			return -1;
	}
	return -1;
}
//INTENT_REBOOT, reboot, 0, NULL | reboot, 1, "recovery" | bootloader |
static intentResult * intent_reboot(int argc, char *argv[])
{
    return_intent_result_if_fail(argc == 1);
    finish_recovery(NULL);
    if(strstr(argv[0], "reboot") != NULL)
        android_reboot(ANDROID_RB_RESTART, 0, 0);
    else if(strstr(argv[0], "poweroff") != NULL)
        android_reboot(ANDROID_RB_POWEROFF, 0, 0);
    else android_reboot(ANDROID_RB_RESTART2, 0, argv[0]);
    return miuiIntent_result_set(0, NULL);
}
static void android_os_Power_reboot(JNIEnv *env, jobject clazz, jstring reason)
{
    if (reason == NULL) {
        android_reboot(ANDROID_RB_RESTART, 0, 0);
    } else {
        const char *chars = env->GetStringUTFChars(reason, NULL);
        android_reboot(ANDROID_RB_RESTART2, 0, (char *) chars);
        env->ReleaseStringUTFChars(reason, chars);  // In case it fails.
    }
    jniThrowIOException(env, errno);
}
Exemple #5
0
static void do_reboot(int exit)
{
    sync();
    umount(REALDATA);

    if(exit & EXIT_REBOOT_RECOVERY)         android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
    else if(exit & EXIT_REBOOT_BOOTLOADER)  android_reboot(ANDROID_RB_RESTART2, 0, "bootloader");
    else if(exit & EXIT_SHUTDOWN)           android_reboot(ANDROID_RB_POWEROFF, 0, 0);
    else                                    android_reboot(ANDROID_RB_RESTART, 0, 0);

    while(1);
}
Exemple #6
0
void reboot_service(int fd, void *arg)
{
    char buf[100];
    int pid, ret;

    sync();

    /* Attempt to unmount the SD card first.
     * No need to bother checking for errors.
     */
    pid = fork();
    if (pid == 0) {
        /* ask vdc to unmount it */
        execl("/system/bin/vdc", "/system/bin/vdc", "volume", "unmount",
                getenv("EXTERNAL_STORAGE"), "force", NULL);
    } else if (pid > 0) {
        /* wait until vdc succeeds or fails */
        waitpid(pid, &ret, 0);
    }

    ret = android_reboot(ANDROID_RB_RESTART2, 0, (char *) arg);
    if (ret < 0) {
        snprintf(buf, sizeof(buf), "reboot failed: %s\n", strerror(errno));
        writex(fd, buf, strlen(buf));
    }
    free(arg);
    adb_close(fd);
}
Exemple #7
0
// call a clean reboot
void reboot_main_system(int cmd, int flags, char *arg) {
    write_recovery_version();
    verify_root_and_recovery();
    finish_recovery(NULL); // sync() in here
    vold_unmount_all();
    android_reboot(cmd, flags, arg);
}
int do_powerctl(int nargs, char **args)
{
    char *command;
    int len = 0;
    int cmd = 0;
    char *reboot_target;

    command = args[1];

    if (strncmp(command, "shutdown", 8) == 0) {
        cmd = ANDROID_RB_POWEROFF;
        len = 8;
    } else if (strncmp(command, "reboot", 6) == 0) {
        cmd = ANDROID_RB_RESTART2;
        len = 6;
    } else {
        ERROR("powerctl: unrecognized command '%s'\n", command);
        return -EINVAL;
    }

    if (command[len] == ',') {
        reboot_target = &command[len + 1];
    } else if (command[len] == '\0') {
        reboot_target = "";
    } else {
        ERROR("powerctl: unrecognized reboot target '%s'\n", &command[len]);
        return -EINVAL;
    }

    return android_reboot(cmd, 0, reboot_target);
}
Exemple #9
0
static int phone_shutdown(void)
{
    int fd;
    int ret = -1;
    int time_consume = 0;;
    time_t start_time,end_time;

    start_time = time(NULL);
    ret = mkdir("/cache/recovery/",S_IRWXU | S_IRWXG | S_IRWXO);
    if (-1 == ret && (errno != EEXIST)) {
        LOGE("mkdir /cache/recovery/ failed.");
    }

    fd=open("/cache/recovery/command",O_WRONLY|O_CREAT,0777);
    if (fd >= 0) {
        write(fd,"--wipe_data\n--locale=zh_CN", strlen("--wipe_data\n--locale=zh_CN") + 1);
        write(fd, "--reason=wipe_data_via_recovery\n", strlen("--reason=wipe_data_via_recovery\n") + 1);
        sync();
        close(fd);
    } else {
        LOGE("open /cache/recovery/command failed");
        return -1;
    }

    end_time = time(NULL);
    time_consume = end_time -start_time;
    LOGD("mmitest select menu = <%s> consume time = %d",MENU_FACTORY_RESET,time_consume);
    usleep(200*1000);
    android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
    return 0;
}
Exemple #10
0
static int phone_reboot(void)
{
    LOGD("==== phone_reboot enter ====\n");
    sync();
    android_reboot(ANDROID_RB_RESTART2, 0, "normal");
    return 0;
}
// call a clean reboot
void reboot_main_system(int cmd, int flags, char *arg) {
    verify_settings_file();
    write_recovery_version();

    verify_root_and_recovery();

    finish_recovery(NULL); // sync() in here
    vold_unmount_all();

    char buffer[80];
    if ((unsigned)cmd == ANDROID_RB_POWEROFF) {
        strcpy(buffer, "shutdown,");
    } else {
        strcpy(buffer, "reboot,");
    }
    if (arg != NULL) {
        strncat(buffer, arg, sizeof(buffer));
    }
    property_set(ANDROID_RB_PROPERTY, buffer);
    sleep(5);

    // Attempt to reboot using older methods in case the recovery
    // that we are updating does not support init property reboot
    // android_reboot() is defined in libcutils/android_reboot.c
    LOGI("trying legacy android_reboot() command\n");
    android_reboot(cmd, flags, arg);
}
void show_power_options_menu() {
	static char* headers[] = { "Power Options",
                                "",
                                NULL
    };

	#define POWER_OPTIONS_ITEM_REBOOT	0
	#define POWER_OPTIONS_ITEM_POWEROFF	1

	static char* list[3];
	list[0] = "Reboot Recovery";
	list[1] = "Power Off";
	list[2] = NULL;
	for (;;) {
		int chosen_item = get_menu_selection(headers, list, 0, 0);
		switch (chosen_item) {
			case GO_BACK:
				return;
			case POWER_OPTIONS_ITEM_REBOOT:
				android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
				break;
			case POWER_OPTIONS_ITEM_POWEROFF:
				pass_shutdown_cmd();
				break;
		}
	}
}
// Process a key-up or -down event.  A key is "registered" when it is
// pressed and then released, with no other keypresses or releases in
// between.  Registered keys are passed to CheckKey() to see if it
// should trigger a visibility toggle, an immediate reboot, or be
// queued to be processed next time the foreground thread wants a key
// (eg, for the menu).
//
// We also keep track of which keys are currently down so that
// CheckKey can call IsKeyPressed to see what other keys are held when
// a key is registered.
//
// updown == 1 for key down events; 0 for key up events
void RecoveryUI::process_key(int key_code, int updown) {
    bool register_key = false;
    bool long_press = false;
    bool reboot_enabled;

    pthread_mutex_lock(&key_queue_mutex);
    key_pressed[key_code] = updown;
    if (updown) {
        ++key_down_count;
        key_last_down = key_code;
        key_long_press = false;
        pthread_t th;
        key_timer_t* info = new key_timer_t;
        info->ui = this;
        info->key_code = key_code;
        info->count = key_down_count;
        pthread_create(&th, NULL, &RecoveryUI::time_key_helper, info);
        pthread_detach(th);
    } else {
        if (key_last_down == key_code) {
            long_press = key_long_press;
            register_key = true;
        }
        key_last_down = -1;
    }
    reboot_enabled = enable_reboot;
    pthread_mutex_unlock(&key_queue_mutex);

    if (register_key) {
        NextCheckKeyIsLong(long_press);
        switch (CheckKey(key_code)) {
        case RecoveryUI::IGNORE:
            break;

        case RecoveryUI::TOGGLE:
            ShowText(!IsTextVisible());
            break;

        case RecoveryUI::REBOOT:
#ifdef ANDROID_RB_RESTART
            if (reboot_enabled) {
                android_reboot(ANDROID_RB_RESTART, 0, 0);
            }
#endif
            break;

        case RecoveryUI::ENQUEUE:
            EnqueueKey(key_code);
            break;

        case RecoveryUI::MOUNT_SYSTEM:
#ifndef NO_RECOVERY_MOUNT
            ensure_path_mounted("/system");
            Print("Mounted /system.");
#endif
            break;
        }
    }
}
Exemple #14
0
void reboot(const char* destination) {
    android_reboot(ANDROID_RB_RESTART2, 0, destination);
    // We're init, so android_reboot will actually have been a syscall so there's nothing
    // to wait for. If android_reboot returns, just abort so that the kernel will reboot
    // itself when init dies.
    PLOG(FATAL) << "reboot failed";
    abort();
}
Exemple #15
0
int eng_linuxcmd_rpoweron(char *req, char *rsp)
{
    sprintf(rsp, "%s%s", SPRDENG_OK, ENG_STREND);
    sync();
    android_reboot(ANDROID_RB_RESTART2, 0, "fastsleep");

    return 0;
}
void show_power_menu()
{

    static char* headers[] = {  "Reboot or Shutdown",
                                "",
                                NULL
    };

    static char* list[] = { "Reboot System",
                            "Reboot to Recovery",
                            "Reboot to Fastboot",
			    "Shutdown",
                            NULL
    };

    for (;;)
    {
        int chosen_item = get_filtered_menu_selection(headers, list, 0, 0, sizeof(list) / sizeof(char*));
        if (chosen_item == GO_BACK)
            break;
        switch (chosen_item)
        {
            case 0:
                ui_print("Rebooting System...\n");
		android_reboot(ANDROID_RB_RESTART, 0, 0);
                break;

            case 1:
                ui_print("Rebooting Into Recovery...\n");
		android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
                break;

	    case 2:
		ui_print("Rebooting Into Fastboot Mode...\n");
        	android_reboot(ANDROID_RB_RESTART2, 0, "bootloader");
        	break;

	    case 3:
		ui_print("Shutting down...\n");
        	android_reboot(ANDROID_RB_POWEROFF, 0, 0);
		break;
	}
    }	
}
/**
 * Decrypt Android user data.
 *
 * @param user Android user id
 * @param password Android user passwd
 *
 * @return 0 on success, negative value on error
 */
int android_decrypt_user_data(int user, char *password)
{
    char storage_path[MAX_PATH_LENGTH];
    int ret;

    LOGI("Decrypt user %d data", user);

    android_stop_services();

    memset(storage_path, 0, sizeof(storage_path));
    sprintf(storage_path, "%s%d/", ANDROID_USER_DATA_PATH, user);
    if (user == PRIMARY_USER) {
        ret = umount_ecryptfs(ANDROID_PRIMARY_USER_DATA_PATH);
        if (ret < 0) {
            LOGE("Error unmounting %s",
                 ANDROID_PRIMARY_USER_DATA_PATH);
            return ret;
        }
    } else {
        ret = EFS_lock(storage_path);
        if (ret < 0) {
            LOGE("Can't unlock efs storage");
            return ret;
        }
    }

    ret = EFS_recover_data_and_remove(storage_path, password);
    if (ret < 0) {
        LOGE("Error decrypting efs storage");
        return ret;
    }

    memset(storage_path, 0, sizeof(storage_path));
    sprintf(storage_path, "%s%d/", ANDROID_VIRTUAL_SDCARD_PATH, user);

    ret = EFS_lock(storage_path);
    if (ret < 0) {
        LOGE("Can't unlock efs storage");
        return ret;
    }

    ret = EFS_recover_data_and_remove(storage_path, password);
    if (ret < 0) {
        LOGE("Error decrypting efs storage");
        return ret;
    }

    if (user == PRIMARY_USER) {
        android_reboot(ANDROID_RB_RESTART, 0, 0);
    }

    android_start_services();
    return 0;
}
// Advanced boot menu(boot, recovery boot, boot-loader) return 1 if chosen 'boot'
void show_advanced_boot_menu()
{
    static char* headers[] = {  "高级电源菜单",
                                "",
                                NULL
    };

    static char* list[] = { "重启系统",
                            "关闭系统",
                            "重启至Recovery",
                            "重启至Fastboot",
                            NULL
    };

    for (;;)
    {
        int chosen_item = get_filtered_menu_selection(headers, list, 0, 0, sizeof(list) / sizeof(char*));
        if (chosen_item == GO_BACK)
            break;
        switch (chosen_item)
        {
        		case 0:
                                ui_print("正在重启...\n");
                                android_reboot(ANDROID_RB_RESTART, 0, 0);
				break;
			case 1:
                                ui_print("正在关机...\n");
                                android_reboot(ANDROID_RB_POWEROFF, 0, 0);
                                break;
			case 2:
				ui_print("正在重启...\n");
				android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
				break;
			case 3:
				ui_print("正在重启...\n");
				android_reboot(ANDROID_RB_RESTART2, 0, "bootloader");
				break;

        }
    }
}
Exemple #19
0
static void wipe_userdata()
{
    mkdir("/cache/recovery", 0700);
    int fd = open("/cache/recovery/command", O_RDWR|O_CREAT|O_TRUNC|O_NOFOLLOW, 0600);
    if (fd >= 0) {
        write(fd, "--wipe_data", strlen("--wipe_data") + 1);
        close(fd);
    } else {
        SLOGE("could not open /cache/recovery/command\n");
    }
    android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
}
// =================================================================
// 2. Reboot to the Brillo system
// =================================================================
static void *thread_reboot(void *arg) {
    int *fastbootd_reboot = (int *)arg;

    usleep(8 * 1000 * 1000);

    if (*fastbootd_reboot) {
        ALOGI("fastbootd: rebooting ...");
        android::base::WriteStringToFile("5", "/sys/module/bcm2709/parameters/reboot_part");
        android_reboot(ANDROID_RB_RESTART, 0, NULL);
    }

    return NULL;
}
// call a clean reboot
void reboot_main_system(int cmd, int flags, char *arg) {
    write_recovery_version();

#ifdef BOARD_NATIVE_DUALBOOT
    device_verify_root_and_recovery();
#else
    verify_root_and_recovery();
#endif

    finish_recovery(NULL); // sync() in here
    vold_unmount_all();
    android_reboot(cmd, flags, arg);
}
static int wipe_data_via_recovery() {
    mkdir("/cache/recovery", 0700);
    int fd = open("/cache/recovery/command", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0600);
    if (fd >= 0) {
        write(fd, "--wipe_data\n", strlen("--wipe_data\n") + 1);
        write(fd, "--reason=wipe_data_via_recovery\n", strlen("--reason=wipe_data_via_recovery\n") + 1);
        close(fd);
    } else {
        ERROR("could not open /cache/recovery/command\n");
        return -1;
    }
    android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
    while (1) { pause(); }  // never reached
}
Exemple #23
0
static int run_core(void)
{
    int res = -1;
    struct fstab *fstab = NULL;

    if(wait_for_file("/dev/graphics/fb0", 5) < 0)
    {
        ERROR("Waiting too long for fb0");
        goto exit;
    }

#ifdef MR_POPULATE_BY_NAME_PATH
    Populate_ByName_using_emmc();
#endif

    fstab = fstab_auto_load();
    if(!fstab)
        goto exit;

#if 0
    fstab_dump(fstab); //debug
#endif

    // mount and run multirom from sdcard
    res = mount_and_run(fstab);
    if(res < 0 && mrom_is_second_boot())
    {
        ERROR("This is second boot and we couldn't mount /data, reboot!\n");
        sync();
        //android_reboot(ANDROID_RB_RESTART, 0, 0);
        android_reboot(ANDROID_RB_RESTART2, 0, "recovery"); // favour reboot to recovery, to avoid possible bootlooping
        while(1)
            sleep(1);
    }

    if(access(KEEP_REALDATA, F_OK) < 0) {
        umount(REALDATA);
        rmdir(REALDATA);
        encryption_destroy();
    }

    encryption_cleanup();

exit:
    if(fstab)
        fstab_destroy(fstab);

    return res;
}
int do_powerctl(int nargs, char **args)
{
    char command[PROP_VALUE_MAX];
    int res;
    int len = 0;
    int cmd = 0;
    const char *reboot_target;
    void (*callback_on_ro_remount)(const struct mntent*) = NULL;

    res = expand_props(command, args[1], sizeof(command));
    if (res) {
        ERROR("powerctl: cannot expand '%s'\n", args[1]);
        return -EINVAL;
    }

    if (strncmp(command, "shutdown", 8) == 0) {
        if (property_get_bool("init.shutdown_to_charging", false)) {
            return android_reboot(ANDROID_RB_RESTART2, 0, "charging");
        }
        cmd = ANDROID_RB_POWEROFF;
        len = 8;
        callback_on_ro_remount = unmount_and_fsck;
    } else if (strncmp(command, "reboot", 6) == 0) {
        cmd = ANDROID_RB_RESTART2;
        len = 6;
    } else {
        ERROR("powerctl: unrecognized command '%s'\n", command);
        return -EINVAL;
    }

    if (command[len] == ',') {
        char prop_value[PROP_VALUE_MAX] = {0};
        reboot_target = &command[len + 1];

        if ((property_get("init.svc.recovery", prop_value) == 0) &&
            (strncmp(reboot_target, "keys", 4) == 0)) {
            ERROR("powerctl: permission denied\n");
            return -EINVAL;
        }
    } else if (command[len] == '\0') {
        reboot_target = "";
    } else {
        ERROR("powerctl: unrecognized reboot target '%s'\n", &command[len]);
        return -EINVAL;
    }

    return android_reboot_with_callback(cmd, 0, reboot_target,
                                        callback_on_ro_remount);
}
Exemple #25
0
void do_reboot(int type)
{
    sync();
    emergency_remount_ro();

    switch(type)
    {
        default:
        case REBOOT_SYSTEM:
            android_reboot(ANDROID_RB_RESTART, 0, 0);
            break;
        case REBOOT_RECOVERY:
            android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
            break;
        case REBOOT_BOOTLOADER:
            android_reboot(ANDROID_RB_RESTART2, 0, "bootloader");
            break;
        case REBOOT_SHUTDOWN:
            android_reboot(ANDROID_RB_POWEROFF, 0, 0);
            break;
    }

    while(1);
}
static void temperature_check()
{
    int zone_temp, i;

    for (i = 0; i < sizeof(thermal_zones)/sizeof(struct thermal_zone); i++) {
        if (thermal_zones[i].index == -1) continue;
        zone_temp = get_zone_temp(thermal_zones[i].index);
        if (zone_temp >= thermal_zones[i].critical_temp) {
            LOGI("Temperature(%d) of %s skin is higher than threshold(%d)",
                zone_temp, thermal_zones[i].name, thermal_zones[i].critical_temp);
            system("echo 1 > /sys/module/intel_mid_osip/parameters/force_shutdown_occured");
            LOGW("Powering off the platform by Thermal daemon due to critical temperature");
            android_reboot(ANDROID_RB_POWEROFF, 0, NULL);
        }
    }
}
Exemple #27
0
static void
try_autodeploy(const char *path) {
    int status = INSTALL_SUCCESS;

    ensure_path_mounted(path);
    if(access(path, F_OK) != -1) {
        status = install_package(path);
        if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n");
        if (unlink(path) && errno != ENOENT) {
                LOGW("Can't unlink %s\n", path);
        }
        finish_recovery(NULL);
        sync();
        android_reboot(ANDROID_RB_RESTART, 0, 0);
    }
}
Exemple #28
0
// Process a key-up or -down event.  A key is "registered" when it is
// pressed and then released, with no other keypresses or releases in
// between.  Registered keys are passed to CheckKey() to see if it
// should trigger a visibility toggle, an immediate reboot, or be
// queued to be processed next time the foreground thread wants a key
// (eg, for the menu).
//
// We also keep track of which keys are currently down so that
// CheckKey can call IsKeyPressed to see what other keys are held when
// a key is registered.
//
// updown == 1 for key down events; 0 for key up events
void RecoveryUI::process_key(int key_code, int updown) {
    bool register_key = false;
    bool long_press = false;

    pthread_mutex_lock(&key_queue_mutex);
    key_pressed[key_code] = updown;
    if (updown) {
        ++key_down_count;
        key_last_down = key_code;
        key_long_press = false;
        pthread_t th;
        key_timer_t* info = new key_timer_t;
        info->ui = this;
        info->key_code = key_code;
        info->count = key_down_count;
        pthread_create(&th, NULL, &RecoveryUI::time_key_helper, info);
        pthread_detach(th);
    } else {
        if (key_last_down == key_code) {
            long_press = key_long_press;
            register_key = true;
        }
        key_last_down = -1;
    }
    pthread_mutex_unlock(&key_queue_mutex);

    if (register_key) {
        NextCheckKeyIsLong(long_press);
        switch (CheckKey(key_code)) {
          case RecoveryUI::IGNORE:
            break;

          case RecoveryUI::TOGGLE:
            ShowText(!IsTextVisible());
            break;

          case RecoveryUI::REBOOT:
            android_reboot(ANDROID_RB_RESTART, 0, 0);
            break;

          case RecoveryUI::ENQUEUE:
            EnqueueKey(key_code);
            break;
        }
    }
}
Exemple #29
0
static void selinux_initialize(void)
{
    if (selinux_is_disabled()) {
        return;
    }

    INFO("loading selinux policy\n");
    if (selinux_android_load_policy() < 0) {
        ERROR("SELinux: Failed to load policy; rebooting into recovery mode\n");
        android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
        while (1) { pause(); }  // never reached
    }

    selinux_init_all_handles();
    bool is_enforcing = selinux_is_enforcing();
    INFO("SELinux: security_setenforce(%d)\n", is_enforcing);
    security_setenforce(is_enforcing);
}
int do_powerctl(int nargs, char **args)
{
    char command[PROP_VALUE_MAX];
    int res;
    int len = 0;
    int cmd = 0;
    const char *reboot_target;

    res = expand_props(command, args[1], sizeof(command));
    if (res) {
        ERROR("powerctl: cannot expand '%s'\n", args[1]);
        return -EINVAL;
    }

    if (strncmp(command, "shutdown", 8) == 0) {
        cmd = ANDROID_RB_POWEROFF;
        len = 8;
    } else if (strncmp(command, "reboot", 6) == 0) {
        cmd = ANDROID_RB_RESTART2;
        len = 6;
    } else {
        ERROR("powerctl: unrecognized command '%s'\n", command);
        return -EINVAL;
    }

    if (command[len] == ',') {
        char prop_value[PROP_VALUE_MAX] = {0};
        reboot_target = &command[len + 1];

        if ((property_get("init.svc.recovery", prop_value) == 0) &&
            (strncmp(reboot_target, "keys", 4) == 0)) {
            ERROR("powerctl: permission denied\n");
            return -EINVAL;
        }
    } else if (command[len] == '\0') {
        reboot_target = "";
    } else {
        ERROR("powerctl: unrecognized reboot target '%s'\n", &command[len]);
        return -EINVAL;
    }

    return android_reboot(cmd, 0, reboot_target);
}