Beispiel #1
0
void AppRequests::didFetchAppRequests(const Vector<screw::facebook::GraphRequest *> &requests) {
    for (GraphRequest *request : requests) {
        string dataStr = request->getDataString();
        Value &v = request->getValue();
        FB_LOG_INFO("AppRequests::didFetchAppRequests - data str = %s", dataStr.c_str());
        if (dataStr.length()) {
            ValueMap m;
            if (JsonUtils::parse(dataStr, m)) {
                if (m.find(AppRequestsDataTypeKey) == m.end()) {
                    FB_LOG("AppRequests::didFetchAppRequests - request data with no type (be aware) %s", v.getDescription().c_str());
                }
                ValueSetter::set(v, "data", Value(m));
                FB_LOG("AppRequests::didFetchAppRequests - parsed data = %s", Value(m).getDescription().c_str());
            } else {
                FB_LOG("AppRequests::didFetchAppRequests - non JSON request data (cleared) %s", v.getDescription().c_str());
                ValueSetter::clear(v, "data");
            }
        }
        _data->set(AppRequestsRequestsKey + "/" + request->getId(), v);
        
        //Delete request
        Request::requestForDelete(request->getId(), nullptr)->execute();
    }
    
    if (requests.size()) {
        _data->save();
    }
}
Beispiel #2
0
void Session::updateState(Session::State state, const list<string> &permissions, SessionError *error) {
	CCASSERT(VALIDATE_STATE(state), "Invalid state");
    FB_LOG("Session::updateState - state = %s", __stateString[state]);
    FB_LOG("Session::updateState - permissions = (%s)", utils::StringUtils::join(permissions, ",").c_str());

	_state = state;
	_permissions = permissions;
	if (_callback)
		_callback(this, error);
}
Beispiel #3
0
void Session::init(State state, const string &appId, list<string> permissions) {
	CCASSERT(!_initialized, "Must be initialized only once");
	CCASSERT(appId != "", "Application ID must not be empty");
    FB_LOG("Session::init - state = %s, appid = %s", __stateString[state], appId.c_str());
    FB_LOG("Session::init - permissions = [%s]", utils::StringUtils::join(permissions, ",").c_str());

	_initialized = true;
	_state = state;
	_appId = appId;
	_permissions = permissions;
}
//private static native void nativeCompleteAppRequest(long requestCode, int error, String errorMessage, String jsonResponse);
JNIEXPORT void JNICALL Java_com_screw_facebook_WebDialog_nativeCompleteAppRequest(JNIEnv *env, jclass jclass, jlong jrequestCode,
													jint jerror, jstring jerrorMessage, jstring jjson) {

	FB_LOG("Dialog_nativeCompleteAppRequest - request code = %ld, error = %d", (long)jrequestCode, jerror);
	FB_LOG_INFO("Dialog_nativeCompleteAppRequest - json response = %s", jni::Helper::jString2String(env, jjson).c_str());
	string errorMessage = jni::Helper::jString2String(env, jerrorMessage);
	string json = jni::Helper::jString2String(env, jjson);
	jni::WebDialogAndroid::onDialogComplete((long)jrequestCode, (int)jerror, errorMessage, json);
}
Beispiel #5
0
void WebDialog::show() {
    FB_LOG("Dialog::show - showing %ld dialog(s)", _dialogs.size());
    CCASSERT(!_dialogs.contains(this), "Bitch ! - try to show a dialog twice ?? ");
    _dialogs.pushBack(this);
    WebDialogCallback callback = this->getCallback();
    this->setCallback([=](int error, ValueMap &values){
        if (callback) {
            callback(error, values);
        }
        _dialogs.eraseObject(this);
    });
    _impl->show(this);
}
Beispiel #6
0
void AppRequests::fetchAppRequests(const ApprequestsRequestCallback &callback) {
    Request *request = Request::requestForAppRequests([=](int error, const Vector<GraphRequest *> &requests){
        FB_LOG("AppRequests::fetchAppRequests - callback error = %d", error);
        if (error == 0) {
            this->didFetchAppRequests(requests);
        }
        if (callback) {
            callback(error, requests);
        }
        //Fire notification
        Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(FacebookRequestsDidFetchNotification);
    });
    
    request->execute();
}
Beispiel #7
0
void DialogAndroid::present(ShareDialogParams *params, const DialogCallback &callback) {
	FB_LOG("DialogAndroid::show - showing dialog #%ld...", _requestCode + 1);
	_requestCode++;
	if (callback) {
		_callbacks[_requestCode] = callback;
	}
	JNIEnv *env = JniHelper::getEnv();
	jobject jparams = Helper::valueMap2jBundle(env, params->getValue().asValueMap());
	env->CallStaticVoidMethod(Helper::jDialogClassID, Helper::jDialogPresentShareDialogMethodID,
			(jlong)_requestCode,
			jparams
		);

	env->DeleteLocalRef(jparams);
}
Beispiel #8
0
/*
 * Func: fb_send
 * Desc: Send message from output buffer after attaching the prefix. It also
 * resets the output buffer.
 *
 * This function expects that the output buffer has first 4 bytes unused so that
 * it can prepend the message type (INFO, DATA, FAIL, OKAY). Also, the output
 * buffer is expected to be in the following state:
 * head = 0, tail = pointing to end of data
 * Thus, length = tail - head (So, length = PREFIX_LEN + output str len).
 *
 * On return, buffer state is: head = 0, tail = PREFIX_LEN.
 */
static void fb_send(struct fb_buffer *output, const char *prefix)
{
	const size_t prefix_size = PREFIX_LEN;
	size_t response_length = fb_buffer_length(output);

	fb_buffer_rewind(output);

	char *resp = fb_buffer_tail(output);
	memcpy(resp, prefix, prefix_size);

	FB_LOG("Response: %.*s\n", (int)response_length, resp);

	usb_gadget_send(resp, response_length);

	fb_buffer_push(output, PREFIX_LEN);
}
void WebDialogAndroid::show(WebDialog *dialog) {
	FB_LOG("WebDialogAndroid::show - showing dialog #%ld...", _requestCode + 1);
	_requestCode++;
	if (dialog->getCallback()) {
		_callbacks[_requestCode] = dialog->getCallback();
	}
	JNIEnv *env = JniHelper::getEnv();
	jstring jdialog = env->NewStringUTF(dialog->getDialog().c_str());
	jobject jparams = Helper::valueMap2jBundle(env, dialog->getParams());
	env->CallStaticVoidMethod(Helper::jWebDialogClassID, Helper::jWebDialogShowMethodID,
			(jlong)_requestCode,
			jdialog,
			jparams
		);

	env->DeleteLocalRef(jdialog);
	env->DeleteLocalRef(jparams);
}
Beispiel #10
0
void DialogAndroid::present(OpenGraphActionShareDialogParams *params, const DialogCallback &callback) {
	FB_LOG("DialogAndroid::show - showing dialog #%ld...", _requestCode + 1);
	_requestCode++;
	if (callback) {
		_callbacks[_requestCode] = callback;
	}
	JNIEnv *env = JniHelper::getEnv();
	/* Flatten action to avoid missing data (and bug) when convert to Bundle */
	OpenGraphAction *action = params->getAction();
	if (action) {
		params->set("action", screw::utils::JsonUtils::toJsonString(action->getValue().asValueMap()));
	}
	jobject jparams = Helper::valueMap2jBundle(env, params->getValue().asValueMap());
	env->CallStaticVoidMethod(Helper::jDialogClassID, Helper::jDialogPresentShareActionDialogMethodID,
			(jlong)_requestCode,
			jparams
		);

	env->DeleteLocalRef(jparams);
}
Beispiel #11
0
static int battery_soc_check(void)
{
	/*
	 * If board does not define this function, then by default it is
	 * assumed that there are no restrictions on flash/erase
	 * operation w.r.t. battery state-of-charge.
	 */
	if (fb_board_handler.battery_soc_ok == NULL) {
		FB_LOG("No handler defined for battery_soc_ok\n");
		return 1;
	}

	/*
	 * No check for battery state-of-charge is performed if GBB override is
	 * set.
	 */
	if (fb_check_gbb_override())
		return 1;

	return fb_board_handler.battery_soc_ok();
}
Beispiel #12
0
static int fb_read_var(struct fb_cmd *cmd, fb_getvar_t var)
{
	size_t input_len = fb_buffer_length(&cmd->input);

	struct fb_buffer *output = &cmd->output;

	switch (var) {
	case FB_VERSION:
		fb_add_string(output, FB_VERSION_STRING, NULL);
		break;

	case FB_DWNLD_SIZE:
		fb_add_number(output, "0x%llx", fb_get_max_download_size());
		break;

	case FB_PART_SIZE: {
		if (input_len == 0) {
			fb_add_string(output, "invalid partition", NULL);
			return -1;
		}

		char *data = fb_buffer_pull(&cmd->input, input_len);
		char *part_name = fb_get_string(data, input_len);
		uint64_t part_size;

		part_size = backend_get_part_size_bytes(part_name);
		fb_free_string(part_name);

		if (part_size == 0) {
			fb_add_string(output, "invalid partition", NULL);
			return -1;
		}

		fb_add_number(output, "0x%llx", part_size);
		break;
	}
	case FB_PART_TYPE: {
		if (input_len == 0) {
			fb_add_string(output, "invalid partition", NULL);
			return -1;
		}

		char *data = fb_buffer_pull(&cmd->input, input_len);

		char *part_name = fb_get_string(data, input_len);
		const char *str = backend_get_part_fs_type(part_name);
		fb_free_string(part_name);

		if (str == NULL) {
			fb_add_string(output, "invalid partition", NULL);
			return -1;
		}

		fb_add_string(output, str, NULL);
		break;
	}
	case FB_BDEV_SIZE: {
		if (input_len == 0) {
			fb_add_string(output, "invalid bdev", NULL);
			return -1;
		}

		char *data = fb_buffer_pull(&cmd->input, input_len);
		char *bdev_name = fb_get_string(data, input_len);
		uint64_t bdev_size;

		bdev_size = backend_get_bdev_size_bytes(bdev_name);
		fb_free_string(bdev_name);

		if (bdev_size == 0) {
			fb_add_string(output, "invalid bdev", NULL);
			return -1;
		}

		fb_add_number(output, "%llu", bdev_size);
		break;
	}
	case FB_SECURE: {
		if (fb_cap_func_allowed(FB_ID_FLASH) == FB_CAP_FUNC_NOT_ALLOWED)
			fb_add_string(output, "yes", NULL);
		else
			fb_add_string(output, "no", NULL);
		break;
	}
	case FB_UNLOCKED: {
		if (fb_device_unlocked())
			fb_add_string(output, "yes", NULL);
		else
			fb_add_string(output, "no", NULL);
		break;
	}
	case  FB_OFF_MODE_CHARGE: {
		fb_add_number(output, "%lld",
			      !vbnv_read(VBNV_BOOT_ON_AC_DETECT));
		break;
	}
	case FB_BATT_VOLTAGE: {
		uint32_t val_mv;
		if ((fb_board_handler.read_batt_volt == NULL) ||
		    (fb_board_handler.read_batt_volt(&val_mv) != 0))
			fb_add_string(output, "Unknown", NULL);
		else
			fb_add_number(output, "%lld mV", val_mv);
		break;
	}
	case FB_BATT_SOC_OK: {
		/*
		 * This variable is supposed to return yes if device battery
		 * state-of-charge is acceptable for flashing.
		 */
		if (battery_soc_check())
			fb_add_string(output, "yes", NULL);
		else
			fb_add_string(output, "no", NULL);
		break;
	}
	case FB_GBB_FLAGS: {
		GoogleBinaryBlockHeader *gbb = cparams.gbb_data;
		fb_add_number(output, "0x%llx", gbb->flags);
		break;
	}
	case FB_OEM_VERSION: {
		if (input_len == 0) {
			fb_add_string(output, "invalid arg", NULL);
			return -1;
		}

		char *data = fb_buffer_pull(&cmd->input, input_len);
		char *fw_type = fb_get_string(data, input_len);
		int i;

		for (i = 0; i < ARRAY_SIZE(fb_fw_type_to_index); i++) {
			if (strcmp(fb_fw_type_to_index[i].name, fw_type) == 0)
				break;
		}

		if (i == ARRAY_SIZE(fb_fw_type_to_index)) {
			fb_add_string(output, "invalid arg", NULL);
			return -1;
		}

		const char *version = get_fw_id(fb_fw_type_to_index[i].index);
		if (version == NULL)
			fb_add_string(output, "unknown", NULL);
		else
			fb_add_string(output, "%s", version);

		break;
	}
#if CONFIG_FASTBOOT_SLOTS
	case FB_HAS_SLOT: {
		if (input_len == 0) {
			fb_add_string(output, "invalid arg", NULL);
			return -1;
		}

		char *base = fb_buffer_pull(&cmd->input, input_len);
		int i;

		for (i = 0; i < fb_base_count; i++) {
			if (input_len != strlen(fb_base_list[i].base_name))
				continue;

			if (strncmp(base, fb_base_list[i].base_name,
				    input_len) == 0)
				break;
		}

		if (i == fb_base_count) {
			fb_add_string(output, "invalid arg", NULL);
			return -1;
		}

		if (fb_base_list[i].is_slotted == 1)
			fb_add_string(output, "yes", NULL);
		else
			fb_add_string(output, "no", NULL);

		break;
	}
	case FB_CURR_SLOT: {
		int slot = backend_get_curr_slot();

		if (slot < 0) {
			fb_add_string(output, "no valid curr slot", NULL);
			return -1;
		}

		assert(slot < CONFIG_FASTBOOT_SLOTS_COUNT);
		fb_add_string(output, slot_get_suffix(slot), NULL);
		break;
	}
	case FB_SLOT_SUFFIXES: {
		int i;

		fb_add_string(output, CONFIG_FASTBOOT_SLOTS_STARTING_SUFFIX,
			      NULL);

		for (i = 1; i < CONFIG_FASTBOOT_SLOTS_COUNT; i++)
			fb_add_string(output, ",%s", slot_get_suffix(i));
		break;
	}
	case FB_SLOT_SUCCESSFUL:
	case FB_SLOT_UNBOOTABLE:
	case FB_SLOT_RETRY_COUNT: {
		if (input_len != 2) {
			fb_add_string(output, "invalid arg", NULL);
			return -1;
		}

		char *data = fb_buffer_pull(&cmd->input, input_len);
		int index = slot_get_index(data, input_len);
		int ret = backend_get_slot_flags(var, index);

		if (ret < 0) {
			fb_add_string(output, "failed to get flags", NULL);
			return -1;
		}

		fb_add_number(output, "%lld", ret);
		break;
	}
#endif
	default:
		goto board_read;
	}

	return 0;

board_read:
	if (fb_board_handler.get_var)
		return fb_board_handler.get_var(cmd, var);
	else {
		FB_LOG("ERROR: get_var is not defined by board\n");
		return -1;
	}
}