static int switch_to_legacy_properties()
{
	if (!legacy_props_env_initd) {
		if (legacy_properties_init() != 0)
			return -1;

		char tmp[32];
		int propfd, propsz;
		legacy_get_property_workspace(&propfd, &propsz);
		sprintf(tmp, "%d,%d", dup(propfd), propsz);
		setenv("ANDROID_PROPERTY_WORKSPACE", tmp, 1);
		legacy_props_env_initd = true;
	}

	if (TWFunc::Path_Exists(properties_path)) {
		// hide real properties so that the updater uses the envvar to find the legacy format properties
		if (rename(properties_path, properties_path_renamed) != 0) {
			LOGERR("Renaming %s failed: %s\n", properties_path, strerror(errno));
			return -1;
		} else {
			legacy_props_path_modified = true;
		}
	}

	return 0;
}
Example #2
0
static int set_legacy_props() {
    if (!legacy_props_env_initd) {
        if (legacy_properties_init() != 0)
            return -1;

        char tmp[32];
        int propfd, propsz;
        legacy_get_property_workspace(&propfd, &propsz);
        sprintf(tmp, "%d,%d", dup(propfd), propsz);
        setenv("ANDROID_PROPERTY_WORKSPACE", tmp, 1);
        legacy_props_env_initd = true;
    }

    if (rename(DEV_PROP_PATH, DEV_PROP_BACKUP_PATH) != 0) {
        LOGE("Could not rename properties path: %s\n", DEV_PROP_PATH);
        return -1;
    } else {
        legacy_props_path_modified = true;
    }

    return 0;
}
Example #3
0
static bool initialize_adb()
{
    bool ret = true;

    const char *version = get_mbtool_version();
    ret = write_file("/sys/class/android_usb/android0/enable", "0", 1) && ret;
    ret = write_file("/sys/class/android_usb/android0/idVendor", "18D1", 4) && ret;
    ret = write_file("/sys/class/android_usb/android0/idProduct", "4EE7", 4) && ret;
    ret = write_file("/sys/class/android_usb/android0/f_ffs/aliases", "adb", 3) && ret;
    ret = write_file("/sys/class/android_usb/android0/functions", "adb", 3) && ret;
    ret = write_file("/sys/class/android_usb/android0/iManufacturer", "mbtool", 6) && ret;
    ret = write_file("/sys/class/android_usb/android0/iProduct", "miniadbd", 8) && ret;
    ret = write_file("/sys/class/android_usb/android0/iSerial", version, strlen(version)) && ret;
    ret = write_file("/sys/class/android_usb/android0/enable", "1", 1) && ret;

    // Create functionfs paths
    if (!util::mkdir_recursive(USB_FFS_ADB_PATH, 0770)) {
        LOGW("%s: Failed to create directory: %s",
             USB_FFS_ADB_PATH, strerror(errno));
        ret = false;
    }
    if (!util::mount("adb", USB_FFS_ADB_PATH, "functionfs", 0, "")) {
        LOGW("%s: Failed to mount functionfs: %s",
             USB_FFS_ADB_PATH, strerror(errno));
        ret = false;
    }

    // Set environment variables
    ret = setenv("PATH", "/system/bin", 1) == 0 && ret;
    ret = setenv("LD_LIBRARY_PATH", "/system/lib", 1) == 0 && ret;
    ret = setenv("ANDROID_DATA", "/data", 1) == 0 && ret;
    ret = setenv("ANDROID_ROOT", "/system", 1) == 0 && ret;

    // Use TWRP's legacy property workspace hack. TouchWiz's sh binary segfaults
    // if there's no property service (i.e. no /dev/__properties__ and no valid
    // ANDROID_PROPERTY_WORKSPACE environment variable). This doesn't actually
    // start a "real" properties service (getprop and setprop will never work),
    // but it's enough to prevent the segfaults.
    char tmp[32];
    int propfd, propsz;
    legacy_properties_init();

    // Load /default.prop
    std::unordered_map<std::string, std::string> props;
    util::file_get_all_properties("/default.prop", &props);
    for (auto const &pair : props) {
        legacy_property_set(pair.first.c_str(), pair.second.c_str());
    }
    // Load /system/build.prop
    props.clear();
    util::file_get_all_properties("/system/build.prop", &props);
    for (auto const &pair : props) {
        legacy_property_set(pair.first.c_str(), pair.second.c_str());
    }

    legacy_get_property_workspace(&propfd, &propsz);
    snprintf(tmp, sizeof(tmp), "%d,%d", dup(propfd), propsz);

    char *orig_prop_env = getenv("ANDROID_PROPERTY_WORKSPACE");
    LOGD("Original properties environment: %s",
         orig_prop_env ? orig_prop_env : "null");

    setenv("ANDROID_PROPERTY_WORKSPACE", tmp, 1);

    LOGD("Switched to legacy properties environment: %s", tmp);

    return ret;
}