ppm_popup_response_e *responses,
size_t privacies_count)
{
- if (!privacies || !responses || privacies_count < 1) {
+ if (((!privacies || !responses) && privacies_count > 0) || (privacies_count == 0 && (privacies || responses))) {
return PRIVACY_PRIVILEGE_MANAGER_ERROR_INVALID_PARAMETER;
}
return ret;
}
- askuser_popup_result* aresults = (askuser_popup_result*) calloc(1, sizeof(askuser_popup_result) * privacies_count);
- if (!aresults) {
- return PRIVACY_PRIVILEGE_MANAGER_ERROR_OUT_OF_MEMORY;
- }
+ askuser_popup_result* aresults = NULL;
+
+ if (privacies_count > 0) {
+ aresults = (askuser_popup_result*) calloc(1, sizeof(askuser_popup_result) * privacies_count);
+ if (!aresults) {
+ return PRIVACY_PRIVILEGE_MANAGER_ERROR_OUT_OF_MEMORY;
+ }
- for (size_t i = 0; i < privacies_count; ++i) {
- switch( responses[i] ) {
- case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESPONSE_ALLOW_FOREVER :
- aresults[i] = ASKUSER_POPUP_RESULT_ALLOW_FOREVER;
- break;
- case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESPONSE_DENY_FOREVER :
- aresults[i] = ASKUSER_POPUP_RESULT_DENY_FOREVER;
- break;
- case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESPONSE_DENY_ONCE :
- aresults[i] = ASKUSER_POPUP_RESULT_DENY_ONCE;
- break;
- default:
- free(aresults);
- return PRIVACY_PRIVILEGE_MANAGER_ERROR_INVALID_PARAMETER;
+ for (size_t i = 0; i < privacies_count; ++i) {
+ switch( responses[i] ) {
+ case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESPONSE_ALLOW_FOREVER :
+ aresults[i] = ASKUSER_POPUP_RESULT_ALLOW_FOREVER;
+ break;
+ case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESPONSE_DENY_FOREVER :
+ aresults[i] = ASKUSER_POPUP_RESULT_DENY_FOREVER;
+ break;
+ case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESPONSE_DENY_ONCE :
+ aresults[i] = ASKUSER_POPUP_RESULT_DENY_ONCE;
+ break;
+ default:
+ free(aresults);
+ return PRIVACY_PRIVILEGE_MANAGER_ERROR_INVALID_PARAMETER;
+ }
}
}
* @param[in] privacies The privacies array for which user response has been acquired.
* @param[in] responses The responses array for corresponding privacies.
* @param[in] privacies_count The number of elements in the privacies and results arrays.
+ * If set to 0, both privacies and responses need to be set to NULL
+ * and API will operate as if DENY_ONCE answer was passed to askuser.
*
* @return 0 on success, otherwise a negative error value
* @retval #PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE Successful
const askuser_popup_result responses[],
size_t privacies_count)
{
- if (!privacies || !responses || privacies_count < 1) {
+ if (((!privacies || !responses) && privacies_count > 0) || (privacies_count == 0 && (privacies || responses))) {
return ASKUSER_API_INVALID_PARAM;
}
* \param[in] privacies The privacies array for which user response has been acquired.
* \param[in] responses The responses array for corresponding privacies.
* \param[in] privacies_count The number of elements in the privacies and results arrays.
+ * If set to 0, both privacies and responses need to be set to NULL
+ * and API will operate as if DENY_ONCE answer was passed to askuser.
*
* \return ASKUSER_API_SUCCESS on success
* \return a negative value in case of an error (see "Status return codes")
SEP_LEN + // space
MIN_EXT_RESPONSE_POPUP_ID_LEN +
SEP_LEN + // space
- MIN_PRIVS_NUMBER_LENGTH +
- MIN_PRIVS_NUMBER * (
- SEP_LEN + // space
- MIN_PRIVILEGE_ENC_LENGTH + // assuming privacy can't be longer than privilege
- SEP_LEN + // space
- MIN_RESPONSE_STATUS_LEN) + // response
+ MIN_PRIVS_NUMBER_LENGTH + // in case vectors have lenght 0
SEP_LEN; // new line
const std::size_t MAX_EXT_RESPONSE_MESSAGE_LENGHT = MAX_COMMAND_LENGTH +
const unsigned int ASKUSER_MESSAGE_PRIVILEGES_COUNT_POS = 2;
const unsigned int ASKUSER_MESSAGE_FIRST_PRIVILEGE_POS = 3;
const unsigned int ASKUSER_MESSAGE_MIN_MSG_PARAM_COUNT = 4; //cmd, requestId, privilegeCount, privilege
-const unsigned int ASKUSER_MESSAGE_MIN_EXT_RESPONSE_MSG_PARAM_COUNT = 5; //cmd, popup_id, privacyCount, privacy, response
+const unsigned int ASKUSER_MESSAGE_MIN_EXT_RESPONSE_MSG_PARAM_COUNT = 3; //cmd, popup_id, privacyCount == 0
const unsigned int ASKUSER_MESSAGE_SEND_SYNC_MSG_RESULT_PARAM_COUNT = 2; //cmd, result
const unsigned int ASKUSER_MESSAGE_EXT_RESPONSE_POPUP_ID_POS = 1;
const unsigned int ASKUSER_MESSAGE_EXT_RESPONSE_PRIV_COUNT_POS = 2;
}
popup_id = std::stoi(message[ASKUSER_MESSAGE_EXT_RESPONSE_POPUP_ID_POS]);
privaciesCount = std::stoul(message[ASKUSER_MESSAGE_EXT_RESPONSE_PRIV_COUNT_POS]);
- if (message.size() != 2 * privaciesCount + ASKUSER_MESSAGE_MIN_EXT_RESPONSE_MSG_PARAM_COUNT - 2) {
+ if (message.size() != 2 * privaciesCount + ASKUSER_MESSAGE_MIN_EXT_RESPONSE_MSG_PARAM_COUNT) {
ALOGE("Inappropriate message size for MSGID_EXT_POPUP_RESPONSE command, size: " << message.size());
return -EINVAL;
}