mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-27 09:21:28 +00:00
commit
704d810fc5
@ -127,7 +127,7 @@ featureAbility.startAbility(
|
||||
authReadUriPermission: true,
|
||||
// indicates the grant to perform write operations on the URI
|
||||
authWriteUriPermission: true,
|
||||
// support forward intent result to origin ability
|
||||
// support forward want result to origin ability
|
||||
abilityForwardResult: true,
|
||||
// used for marking the ability start-up is triggered by continuation
|
||||
abilityContinuation: true,
|
||||
@ -208,7 +208,7 @@ featureAbility.startAbility(
|
||||
authReadUriPermission: true,
|
||||
// indicates the grant to perform write operations on the URI
|
||||
authWriteUriPermission: true,
|
||||
// support forward intent result to origin ability
|
||||
// support forward want result to origin ability
|
||||
abilityForwardResult: true,
|
||||
// used for marking the ability start-up is triggered by continuation
|
||||
abilityContinuation: true,
|
||||
|
11
bundle.json
11
bundle.json
@ -88,17 +88,6 @@
|
||||
},
|
||||
"name": "//foundation/aafwk/standard/frameworks/kits/wantagent:wantagent_innerkits"
|
||||
},
|
||||
{
|
||||
"header": {
|
||||
"header_base": "//foundation/aafwk/standard/interfaces/innerkits/intent/include/",
|
||||
"header_files": [
|
||||
"ohos/aafwk/content/intent.h",
|
||||
"ohos/aafwk/content/intent_filter.h",
|
||||
"ohos/aafwk/content/intent_params.h"
|
||||
]
|
||||
},
|
||||
"name": "//foundation/aafwk/standard/interfaces/innerkits/intent:intent"
|
||||
},
|
||||
{
|
||||
"header": {
|
||||
"header_base": "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include",
|
||||
|
@ -17,8 +17,6 @@ import("//foundation/aafwk/standard/feature.gni")
|
||||
module_output_path = "ability_runtime/ability_call_test"
|
||||
|
||||
###############################################################################
|
||||
#1. intent(c++) get/set test without transport
|
||||
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
cflags = []
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
|
||||
/**
|
||||
* @brief This method is called back to receive the connection result after an ability calls the
|
||||
* Ability#connectAbility(Intent, IAbilityConnection) method to connect it to a Service ability.
|
||||
* Ability#connectAbility(Want, IAbilityConnection) method to connect it to a Service ability.
|
||||
*
|
||||
* @param element: Indicates information about the connected Service ability.
|
||||
* @param remote: Indicates the remote proxy object of the Service ability.
|
||||
|
@ -708,8 +708,8 @@ ErrCode Ability::StartAbilityForResult(const Want &want, int requestCode, Abilit
|
||||
* Starts a new ability with specific start settings.
|
||||
* A Page or Service ability uses this method to start a specific ability.
|
||||
* The system locates the target ability from installed abilities based on
|
||||
* the value of the intent parameter and then starts it. You can specify the
|
||||
* ability to start using the intent parameter.
|
||||
* the value of the want parameter and then starts it. You can specify the
|
||||
* ability to start using the want parameter.
|
||||
*
|
||||
* @param want Indicates the ability to start.
|
||||
* @param abilityStartSetting Indicates the setting ability used to start.
|
||||
@ -1633,10 +1633,10 @@ AbilityLifecycleExecutor::LifecycleState Ability::GetState()
|
||||
|
||||
/**
|
||||
* @brief A Page or Service ability uses this method to start a specific ability. The system locates the target
|
||||
* ability from installed abilities based on the value of the intent parameter and then starts it. You can specify
|
||||
* the ability to start using the intent parameter.
|
||||
* ability from installed abilities based on the value of the want parameter and then starts it. You can specify
|
||||
* the ability to start using the want parameter.
|
||||
*
|
||||
* @param intent Indicates the ability to start.
|
||||
* @param want Indicates the ability to start.
|
||||
*
|
||||
* @return errCode ERR_OK on success, others on failure.
|
||||
*/
|
||||
@ -1686,7 +1686,7 @@ void Ability::SetMainRoute(const std::string &entry)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief By binding an action, you can set different action parameters in Intent to present different initial
|
||||
* @brief By binding an action, you can set different action parameters in Want to present different initial
|
||||
* pages. You must register actions in the profile file.
|
||||
*
|
||||
* @param action Indicates the action to bind.
|
||||
|
@ -52,7 +52,7 @@ sptr<ContinuationConnector> ContinuationConnector::GetInstance(const std::weak_p
|
||||
|
||||
/**
|
||||
* @brief This method is called back to receive the connection result after an ability calls the
|
||||
* Ability#connectAbility(Intent, IAbilityConnection) method to connect it to a Service ability.
|
||||
* Ability#connectAbility(Want, IAbilityConnection) method to connect it to a Service ability.
|
||||
*
|
||||
* @param element: Indicates information about the connected Service ability.
|
||||
* @param remote: Indicates the remote proxy object of the Service ability.
|
||||
|
@ -1,904 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ohos/aafwk/content/intent.h"
|
||||
#include "ohos/aafwk/base/array_wrapper.h"
|
||||
#include "ohos/aafwk/base/base_object.h"
|
||||
#include "ohos/aafwk/base/bool_wrapper.h"
|
||||
#include "ohos/aafwk/base/zchar_wrapper.h"
|
||||
#include "ohos/aafwk/base/byte_wrapper.h"
|
||||
#include "ohos/aafwk/base/short_wrapper.h"
|
||||
#include "ohos/aafwk/base/int_wrapper.h"
|
||||
#include "ohos/aafwk/base/long_wrapper.h"
|
||||
#include "ohos/aafwk/base/float_wrapper.h"
|
||||
#include "ohos/aafwk/base/double_wrapper.h"
|
||||
#include "ohos/aafwk/base/string_wrapper.h"
|
||||
#include "ohos/aafwk/base/zchar_wrapper.h"
|
||||
#include "string_ex.h"
|
||||
|
||||
#include <climits>
|
||||
#include <securec.h>
|
||||
|
||||
#include "parcel.h"
|
||||
|
||||
using OHOS::AppExecFwk::ElementName;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
|
||||
const std::string Intent::ACTION_PLAY("action.system.play");
|
||||
|
||||
const std::string Intent::ENTITY_HOME("entity.system.home");
|
||||
const std::string Intent::ENTITY_VIDEO("entity.system.video");
|
||||
|
||||
const std::string Intent::OCT_EQUALSTO("075"); // '='
|
||||
const std::string Intent::OCT_SEMICOLON("073"); // ';'
|
||||
|
||||
static constexpr int HEX_STRING_BUF_LEN = 12;
|
||||
static constexpr int HEX_STRING_LEN = 10; // "0xffffffff"
|
||||
|
||||
Intent::Intent() : flags_(0)
|
||||
{}
|
||||
|
||||
std::string Intent::GetAction() const
|
||||
{
|
||||
return action_;
|
||||
}
|
||||
|
||||
Intent &Intent::SetAction(const std::string &action)
|
||||
{
|
||||
action_ = action;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string Intent::GetEntity() const
|
||||
{
|
||||
return entity_;
|
||||
}
|
||||
|
||||
Intent &Intent::SetEntity(const std::string &entity)
|
||||
{
|
||||
entity_ = entity;
|
||||
return *this;
|
||||
}
|
||||
|
||||
unsigned int Intent::GetFlags() const
|
||||
{
|
||||
return flags_;
|
||||
}
|
||||
|
||||
Intent &Intent::SetFlag(const unsigned int flag)
|
||||
{
|
||||
flags_ = flag;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Intent &Intent::AddFlag(const unsigned int flag)
|
||||
{
|
||||
flags_ |= flag;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Intent::RemoveFlags(const unsigned int flag)
|
||||
{
|
||||
flags_ &= ~flag;
|
||||
}
|
||||
|
||||
ElementName Intent::GetElement() const
|
||||
{
|
||||
return element_;
|
||||
}
|
||||
|
||||
Intent &Intent::SetElement(const ElementName &element)
|
||||
{
|
||||
element_ = element;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Intent::ParseFlag(const std::string &content, Intent &intent)
|
||||
{
|
||||
std::string contentLower = LowerStr(content);
|
||||
std::string prefix = "0x";
|
||||
if (!contentLower.empty()) {
|
||||
if (contentLower.find(prefix) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (std::size_t i = prefix.length(); i < contentLower.length(); i++) {
|
||||
if (!isxdigit(contentLower[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
int base = 16; // hex string
|
||||
unsigned int flag = (unsigned int)std::stoi(contentLower, nullptr, base);
|
||||
intent.SetFlag(flag);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Intent::Decode(const std::string &str)
|
||||
{
|
||||
std::string decode;
|
||||
|
||||
for (std::size_t i = 0; i < str.length();) {
|
||||
if (str[i] == '\\') {
|
||||
if (++i >= str.length()) {
|
||||
decode += "\\";
|
||||
break;
|
||||
}
|
||||
if (str[i] == '\\') {
|
||||
decode += "\\";
|
||||
i++;
|
||||
} else if (str[i] == '0') {
|
||||
if (str.compare(i, OCT_EQUALSTO.length(), OCT_EQUALSTO) == 0) {
|
||||
decode += "=";
|
||||
i += OCT_EQUALSTO.length();
|
||||
} else if (str.compare(i, OCT_SEMICOLON.length(), OCT_SEMICOLON) == 0) {
|
||||
decode += ";";
|
||||
i += OCT_SEMICOLON.length();
|
||||
} else {
|
||||
decode += "\\" + str.substr(i, 1);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
decode += "\\" + str.substr(i, 1);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
decode += str[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return decode;
|
||||
}
|
||||
|
||||
std::string Intent::Encode(const std::string &str)
|
||||
{
|
||||
std::string encode;
|
||||
|
||||
for (std::size_t i = 0; i < str.length(); i++) {
|
||||
if (str[i] == '\\') {
|
||||
encode += "\\\\";
|
||||
} else if (str[i] == '=') {
|
||||
encode += "\\" + OCT_EQUALSTO;
|
||||
} else if (str[i] == ';') {
|
||||
encode += "\\" + OCT_SEMICOLON;
|
||||
} else {
|
||||
encode += str[i];
|
||||
}
|
||||
}
|
||||
|
||||
return encode;
|
||||
}
|
||||
|
||||
bool Intent::ParseContent(const std::string &content, std::string &prop, std::string &value)
|
||||
{
|
||||
std::string subString;
|
||||
std::size_t pos = content.find("=");
|
||||
if (pos != std::string::npos) {
|
||||
subString = content.substr(0, pos);
|
||||
prop = Decode(subString);
|
||||
subString = content.substr(pos + 1, content.length() - pos - 1);
|
||||
value = Decode(subString);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Intent::ParseUriInternal(const std::string &content, ElementName &element, Intent &intent)
|
||||
{
|
||||
static constexpr int TYPE_TAG_SIZE = 2;
|
||||
|
||||
std::string prop;
|
||||
std::string value;
|
||||
|
||||
if (content.empty() || content[0] == '=') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ParseContent(content, prop, value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (prop == "action") {
|
||||
intent.SetAction(value);
|
||||
} else if (prop == "entity") {
|
||||
intent.SetEntity(value);
|
||||
} else if (prop == "flag") {
|
||||
if (!ParseFlag(value, intent)) {
|
||||
return false;
|
||||
}
|
||||
} else if (prop == "device") {
|
||||
element.SetDeviceID(value);
|
||||
} else if (prop == "bundle") {
|
||||
element.SetBundleName(value);
|
||||
} else if (prop == "ability") {
|
||||
element.SetAbilityName(value);
|
||||
} else if (prop.length() > TYPE_TAG_SIZE) {
|
||||
std::string key = prop.substr(TYPE_TAG_SIZE);
|
||||
if (prop[0] == String::SIGNATURE && prop[1] == '.') {
|
||||
sptr<IString> valueObj = String::Parse(value);
|
||||
if (valueObj == nullptr) {
|
||||
return false;
|
||||
}
|
||||
intent.parameters_.SetParam(key, valueObj);
|
||||
} else if (prop[0] == Boolean::SIGNATURE && prop[1] == '.') {
|
||||
sptr<IBoolean> valueObj = Boolean::Parse(value);
|
||||
if (valueObj == nullptr) {
|
||||
return false;
|
||||
}
|
||||
intent.parameters_.SetParam(key, valueObj);
|
||||
} else if (prop[0] == Char::SIGNATURE && prop[1] == '.') {
|
||||
sptr<IChar> valueObj = Char::Parse(value);
|
||||
if (valueObj == nullptr) {
|
||||
return false;
|
||||
}
|
||||
intent.parameters_.SetParam(key, valueObj);
|
||||
} else if (prop[0] == Byte::SIGNATURE && prop[1] == '.') {
|
||||
sptr<IByte> valueObj = Byte::Parse(value);
|
||||
if (valueObj == nullptr) {
|
||||
return false;
|
||||
}
|
||||
intent.parameters_.SetParam(key, valueObj);
|
||||
} else if (prop[0] == Short::SIGNATURE && prop[1] == '.') {
|
||||
sptr<IShort> valueObj = Short::Parse(value);
|
||||
if (valueObj == nullptr) {
|
||||
return false;
|
||||
}
|
||||
intent.parameters_.SetParam(key, valueObj);
|
||||
} else if (prop[0] == Integer::SIGNATURE && prop[1] == '.') {
|
||||
sptr<IInteger> valueObj = Integer::Parse(value);
|
||||
if (valueObj == nullptr) {
|
||||
return false;
|
||||
}
|
||||
intent.parameters_.SetParam(key, valueObj);
|
||||
} else if (prop[0] == Long::SIGNATURE && prop[1] == '.') {
|
||||
sptr<ILong> valueObj = Long::Parse(value);
|
||||
if (valueObj == nullptr) {
|
||||
return false;
|
||||
}
|
||||
intent.parameters_.SetParam(key, valueObj);
|
||||
} else if (prop[0] == Float::SIGNATURE && prop[1] == '.') {
|
||||
sptr<IFloat> valueObj = Float::Parse(value);
|
||||
if (valueObj == nullptr) {
|
||||
return false;
|
||||
}
|
||||
intent.parameters_.SetParam(key, valueObj);
|
||||
} else if (prop[0] == Double::SIGNATURE && prop[1] == '.') {
|
||||
sptr<IDouble> valueObj = Double::Parse(value);
|
||||
if (valueObj == nullptr) {
|
||||
return false;
|
||||
}
|
||||
intent.parameters_.SetParam(key, valueObj);
|
||||
} else if (prop[0] == Array::SIGNATURE && prop[1] == '.') {
|
||||
sptr<IArray> valueObj = Array::Parse(value);
|
||||
if (valueObj == nullptr) {
|
||||
return false;
|
||||
}
|
||||
intent.parameters_.SetParam(key, valueObj);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Intent *Intent::ParseUri(const std::string &uri)
|
||||
{
|
||||
if (uri.length() <= 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string head = "#Intent;";
|
||||
std::string end = ";end";
|
||||
|
||||
if (uri.find(head) != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (uri.rfind(end) != (uri.length() - end.length())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ret = true;
|
||||
std::string content;
|
||||
std::size_t pos;
|
||||
std::size_t begin = head.length();
|
||||
ElementName element;
|
||||
Intent *intent = new Intent();
|
||||
|
||||
pos = uri.find_first_of(";", begin);
|
||||
do {
|
||||
if (pos != std::string::npos) {
|
||||
content = uri.substr(begin, pos - begin);
|
||||
ret = ParseUriInternal(content, element, *intent);
|
||||
if (!ret) {
|
||||
break;
|
||||
}
|
||||
begin = pos + 1;
|
||||
pos = uri.find(";", begin);
|
||||
if (pos == std::string::npos) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
if (ret) {
|
||||
intent->SetElement(element);
|
||||
} else {
|
||||
delete intent;
|
||||
intent = nullptr;
|
||||
}
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
std::string Intent::ToUri()
|
||||
{
|
||||
std::string uriString = "#Intent;";
|
||||
|
||||
if (action_.length() > 0) {
|
||||
uriString += "action=" + Encode(action_) + ";";
|
||||
}
|
||||
|
||||
if (entity_.length() > 0) {
|
||||
uriString += "entity=" + Encode(entity_) + ";";
|
||||
}
|
||||
|
||||
if (flags_ != 0) {
|
||||
uriString += "flag=";
|
||||
char buf[HEX_STRING_BUF_LEN];
|
||||
int len = snprintf_s(buf, sizeof(buf), HEX_STRING_LEN, "0x%08x", flags_);
|
||||
if (len == HEX_STRING_LEN) {
|
||||
std::string flag = buf;
|
||||
uriString += Encode(flag);
|
||||
uriString += ";";
|
||||
}
|
||||
}
|
||||
|
||||
std::string device = element_.GetDeviceID();
|
||||
if (device.length() > 0) {
|
||||
uriString += "device=" + Encode(device) + ";";
|
||||
}
|
||||
|
||||
std::string bundle = element_.GetBundleName();
|
||||
if (bundle.length() > 0) {
|
||||
uriString += "bundle=" + Encode(bundle) + ";";
|
||||
}
|
||||
|
||||
std::string ability = element_.GetAbilityName();
|
||||
if (ability.length() > 0) {
|
||||
uriString += "ability=" + Encode(ability) + ";";
|
||||
}
|
||||
|
||||
auto params = parameters_.GetParams();
|
||||
auto iter = params.cbegin();
|
||||
while (iter != params.cend()) {
|
||||
sptr<IInterface> o = iter->second;
|
||||
if (IString::Query(o) != nullptr) {
|
||||
uriString += String::SIGNATURE;
|
||||
} else if (IBoolean::Query(o) != nullptr) {
|
||||
uriString += Boolean::SIGNATURE;
|
||||
} else if (IChar::Query(o) != nullptr) {
|
||||
uriString += Char::SIGNATURE;
|
||||
} else if (IByte::Query(o) != nullptr) {
|
||||
uriString += Byte::SIGNATURE;
|
||||
} else if (IShort::Query(o) != nullptr) {
|
||||
uriString += Short::SIGNATURE;
|
||||
} else if (IInteger::Query(o) != nullptr) {
|
||||
uriString += Integer::SIGNATURE;
|
||||
} else if (ILong::Query(o) != nullptr) {
|
||||
uriString += Long::SIGNATURE;
|
||||
} else if (IFloat::Query(o) != nullptr) {
|
||||
uriString += Float::SIGNATURE;
|
||||
} else if (IDouble::Query(o) != nullptr) {
|
||||
uriString += Double::SIGNATURE;
|
||||
} else if (IArray::Query(o) != nullptr) {
|
||||
uriString += Array::SIGNATURE;
|
||||
}
|
||||
uriString += "." + Encode(iter->first) + "=" + Encode(Object::ToString(*(o.GetRefPtr()))) + ";";
|
||||
iter++;
|
||||
}
|
||||
|
||||
uriString += "end";
|
||||
|
||||
return uriString;
|
||||
}
|
||||
|
||||
/*
|
||||
* Intent format in Parcel. Java side should keep consistent.
|
||||
* +----------+----+-----+------+-------+----+-----------+----
|
||||
* | Action | E1 | Uri | Type | Flags | E2 | Category1 | ...
|
||||
* +----------+----+-----+------+-------+----+-----------+----
|
||||
* ----+-----------+---------+----+---------+----+------------+
|
||||
* ... | CategoryN | Package | E3 | Element | E4 | Parameters |
|
||||
* ----+-----------+---------+----+---------+----+------------+
|
||||
* E1: If -1, no Uri after it.
|
||||
* E2: Category count. If -1, no Category after it.
|
||||
* E3: if -1, no element after it.
|
||||
* E4: if -1, no parameters after it.
|
||||
*/
|
||||
bool Intent::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
// write action
|
||||
if (!parcel.WriteString16(Str8ToStr16(action_))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// write entity
|
||||
if (!parcel.WriteString16(Str8ToStr16(entity_))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// write flags
|
||||
if (!parcel.WriteUint32(flags_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// write element
|
||||
ElementName emptyElement;
|
||||
if (element_ == emptyElement) {
|
||||
if (!parcel.WriteInt32(VALUE_NULL)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!parcel.WriteInt32(VALUE_OBJECT)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteParcelable(&element_)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// write parameters
|
||||
if (parameters_.GetParams().size() == 0) {
|
||||
if (!parcel.WriteInt32(VALUE_NULL)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!parcel.WriteInt32(VALUE_OBJECT)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteParcelable(¶meters_)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Intent::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
// read action
|
||||
action_ = Str16ToStr8(parcel.ReadString16());
|
||||
|
||||
// read entity
|
||||
entity_ = Str16ToStr8(parcel.ReadString16());
|
||||
|
||||
// read flags
|
||||
if (!parcel.ReadUint32(flags_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int empty;
|
||||
// read element
|
||||
empty = VALUE_NULL;
|
||||
if (!parcel.ReadInt32(empty)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty == VALUE_OBJECT) {
|
||||
auto element = parcel.ReadParcelable<ElementName>();
|
||||
if (element != nullptr) {
|
||||
element_ = *element;
|
||||
delete element;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// read parameters
|
||||
empty = VALUE_NULL;
|
||||
if (!parcel.ReadInt32(empty)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty == VALUE_OBJECT) {
|
||||
auto params = parcel.ReadParcelable<IntentParams>();
|
||||
if (params != nullptr) {
|
||||
parameters_ = *params;
|
||||
delete params;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Intent *Intent::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
Intent *intent = new Intent();
|
||||
if (intent && !intent->ReadFromParcel(parcel)) {
|
||||
delete intent;
|
||||
intent = nullptr;
|
||||
}
|
||||
return intent;
|
||||
}
|
||||
|
||||
bool Intent::HasParameter(const std::string &key) const
|
||||
{
|
||||
return parameters_.HasParam(key);
|
||||
}
|
||||
|
||||
bool Intent::GetBoolParam(const std::string &key, const bool defaultValue)
|
||||
{
|
||||
auto value = parameters_.GetParam(key);
|
||||
IBoolean *bo = IBoolean::Query(value);
|
||||
if (bo != nullptr) {
|
||||
return Boolean::Unbox(bo);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
Intent &Intent::SetBoolParam(const std::string &key, const bool value)
|
||||
{
|
||||
parameters_.SetParam(key, Boolean::Box(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::vector<bool> Intent::GetBoolArrayParam(const std::string &key)
|
||||
{
|
||||
std::vector<bool> array;
|
||||
auto value = parameters_.GetParam(key);
|
||||
IArray *ao = IArray::Query(value);
|
||||
if (ao != nullptr && Array::IsBooleanArray(ao)) {
|
||||
auto func = [&](IInterface *object) { array.push_back(Boolean::Unbox(IBoolean::Query(object))); };
|
||||
Array::ForEach(ao, func);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
Intent &Intent::SetBoolArrayParam(const std::string &key, const std::vector<bool> &value)
|
||||
{
|
||||
size_t size = value.size();
|
||||
sptr<IArray> ao = new Array(size, g_IID_IBoolean);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
ao->Set(i, Boolean::Box(value[i]));
|
||||
}
|
||||
parameters_.SetParam(key, ao);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Intent &Intent::SetCharParam(const std::string &key, const zchar value)
|
||||
{
|
||||
parameters_.SetParam(key, Char::Box(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Intent &Intent::SetCharArrayParam(const std::string &key, const std::vector<zchar> &value)
|
||||
{
|
||||
size_t size = value.size();
|
||||
sptr<IArray> ao = new Array(size, g_IID_IChar);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
ao->Set(i, Char::Box(value[i]));
|
||||
}
|
||||
parameters_.SetParam(key, ao);
|
||||
return *this;
|
||||
}
|
||||
|
||||
zchar Intent::GetCharParam(const std::string &key, const zchar defaultValue)
|
||||
{
|
||||
auto value = parameters_.GetParam(key);
|
||||
IChar *co = IChar::Query(value);
|
||||
if (co != nullptr) {
|
||||
return Char::Unbox(co);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
std::vector<zchar> Intent::GetCharArrayParam(const std::string &key)
|
||||
{
|
||||
std::vector<zchar> array;
|
||||
auto value = parameters_.GetParam(key);
|
||||
IArray *ao = IArray::Query(value);
|
||||
if (ao != nullptr && Array::IsCharArray(ao)) {
|
||||
auto func = [&](IInterface *object) { array.push_back(Char::Unbox(IChar::Query(object))); };
|
||||
Array::ForEach(ao, func);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
Intent &Intent::SetByteParam(const std::string &key, const byte value)
|
||||
{
|
||||
parameters_.SetParam(key, Byte::Box(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Intent &Intent::SetByteArrayParam(const std::string &key, const std::vector<byte> &value)
|
||||
{
|
||||
size_t size = value.size();
|
||||
sptr<IArray> ao = new Array(size, g_IID_IByte);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
ao->Set(i, Byte::Box(value[i]));
|
||||
}
|
||||
parameters_.SetParam(key, ao);
|
||||
return *this;
|
||||
}
|
||||
|
||||
byte Intent::GetByteParam(const std::string &key, const byte defaultValue)
|
||||
{
|
||||
auto value = parameters_.GetParam(key);
|
||||
IByte *bo = IByte::Query(value);
|
||||
if (bo != nullptr) {
|
||||
return Byte::Unbox(bo);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
std::vector<byte> Intent::GetByteArrayParam(const std::string &key)
|
||||
{
|
||||
std::vector<byte> array;
|
||||
auto value = parameters_.GetParam(key);
|
||||
IArray *ao = IArray::Query(value);
|
||||
if (ao != nullptr && Array::IsByteArray(ao)) {
|
||||
auto func = [&](IInterface *object) { array.push_back(Byte::Unbox(IByte::Query(object))); };
|
||||
Array::ForEach(ao, func);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
Intent &Intent::SetShortParam(const std::string &key, const short value)
|
||||
{
|
||||
parameters_.SetParam(key, Short::Box(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Intent &Intent::SetShortArrayParam(const std::string &key, const std::vector<short> &value)
|
||||
{
|
||||
size_t size = value.size();
|
||||
sptr<IArray> ao = new Array(size, g_IID_IShort);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
ao->Set(i, Short::Box(value[i]));
|
||||
}
|
||||
parameters_.SetParam(key, ao);
|
||||
return *this;
|
||||
}
|
||||
|
||||
short Intent::GetShortParam(const std::string &key, const short defaultValue)
|
||||
{
|
||||
auto value = parameters_.GetParam(key);
|
||||
IShort *so = IShort::Query(value);
|
||||
if (so != nullptr) {
|
||||
return Short::Unbox(so);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
std::vector<short> Intent::GetShortArrayParam(const std::string &key)
|
||||
{
|
||||
std::vector<short> array;
|
||||
auto value = parameters_.GetParam(key);
|
||||
IArray *ao = IArray::Query(value);
|
||||
if (ao != nullptr && Array::IsShortArray(ao)) {
|
||||
auto func = [&](IInterface *object) { array.push_back(Short::Unbox(IShort::Query(object))); };
|
||||
Array::ForEach(ao, func);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
Intent &Intent::SetIntParam(const std::string &key, const int value)
|
||||
{
|
||||
parameters_.SetParam(key, Integer::Box(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Intent &Intent::SetIntArrayParam(const std::string &key, const std::vector<int> &value)
|
||||
{
|
||||
size_t size = value.size();
|
||||
sptr<IArray> ao = new Array(size, g_IID_IInteger);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
ao->Set(i, Integer::Box(value[i]));
|
||||
}
|
||||
parameters_.SetParam(key, ao);
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Intent::GetIntParam(const std::string &key, const int defaultValue)
|
||||
{
|
||||
auto value = parameters_.GetParam(key);
|
||||
IInteger *io = IInteger::Query(value);
|
||||
if (io != nullptr) {
|
||||
return Integer::Unbox(io);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
std::vector<int> Intent::GetIntArrayParam(const std::string &key)
|
||||
{
|
||||
std::vector<int> array;
|
||||
auto value = parameters_.GetParam(key);
|
||||
IArray *ao = IArray::Query(value);
|
||||
if (ao != nullptr && Array::IsIntegerArray(ao)) {
|
||||
auto func = [&](IInterface *object) { array.push_back(Integer::Unbox(IInteger::Query(object))); };
|
||||
Array::ForEach(ao, func);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
long Intent::GetLongParam(const std::string &key, const long defaultValue)
|
||||
{
|
||||
auto value = parameters_.GetParam(key);
|
||||
ILong *lo = ILong::Query(value);
|
||||
if (lo != nullptr) {
|
||||
return Long::Unbox(lo);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
Intent &Intent::SetLongParam(const std::string &key, const long value)
|
||||
{
|
||||
parameters_.SetParam(key, Long::Box(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::vector<long> Intent::GetLongArrayParam(const std::string &key)
|
||||
{
|
||||
std::vector<long> array;
|
||||
auto value = parameters_.GetParam(key);
|
||||
IArray *ao = IArray::Query(value);
|
||||
if (ao != nullptr && Array::IsLongArray(ao)) {
|
||||
auto func = [&](IInterface *object) { array.push_back(Long::Unbox(ILong::Query(object))); };
|
||||
Array::ForEach(ao, func);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
Intent &Intent::SetLongArrayParam(const std::string &key, const std::vector<long> &value)
|
||||
{
|
||||
size_t size = value.size();
|
||||
sptr<IArray> ao = new Array(size, g_IID_ILong);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
ao->Set(i, Long::Box(value[i]));
|
||||
}
|
||||
parameters_.SetParam(key, ao);
|
||||
return *this;
|
||||
}
|
||||
|
||||
float Intent::GetFloatParam(const std::string &key, const float defaultValue)
|
||||
{
|
||||
auto value = parameters_.GetParam(key);
|
||||
IFloat *of = IFloat::Query(value);
|
||||
if (of != nullptr) {
|
||||
return Float::Unbox(of);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
Intent &Intent::SetFloatParam(const std::string &key, const float value)
|
||||
{
|
||||
parameters_.SetParam(key, Float::Box(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::vector<float> Intent::GetFloatArrayParam(const std::string &key)
|
||||
{
|
||||
std::vector<float> array;
|
||||
auto value = parameters_.GetParam(key);
|
||||
IArray *ao = IArray::Query(value);
|
||||
if (ao != nullptr && Array::IsFloatArray(ao)) {
|
||||
auto func = [&](IInterface *object) { array.push_back(Float::Unbox(IFloat::Query(object))); };
|
||||
Array::ForEach(ao, func);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
Intent &Intent::SetFloatArrayParam(const std::string &key, const std::vector<float> &value)
|
||||
{
|
||||
size_t size = value.size();
|
||||
sptr<IArray> ao = new Array(size, g_IID_IFloat);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
ao->Set(i, Float::Box(value[i]));
|
||||
}
|
||||
parameters_.SetParam(key, ao);
|
||||
return *this;
|
||||
}
|
||||
|
||||
double Intent::GetDoubleParam(const std::string &key, const double defaultValue)
|
||||
{
|
||||
auto value = parameters_.GetParam(key);
|
||||
IDouble *dbo = IDouble::Query(value);
|
||||
if (dbo != nullptr) {
|
||||
return Double::Unbox(dbo);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
Intent &Intent::SetDoubleParam(const std::string &key, const double value)
|
||||
{
|
||||
parameters_.SetParam(key, Double::Box(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::vector<double> Intent::GetDoubleArrayParam(const std::string &key)
|
||||
{
|
||||
std::vector<double> array;
|
||||
auto value = parameters_.GetParam(key);
|
||||
IArray *ao = IArray::Query(value);
|
||||
if (ao != nullptr && Array::IsDoubleArray(ao)) {
|
||||
auto func = [&](IInterface *object) { array.push_back(Double::Unbox(IDouble::Query(object))); };
|
||||
Array::ForEach(ao, func);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
Intent &Intent::SetDoubleArrayParam(const std::string &key, const std::vector<double> &value)
|
||||
{
|
||||
size_t size = value.size();
|
||||
sptr<IArray> ao = new Array(size, g_IID_IDouble);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
ao->Set(i, Double::Box(value[i]));
|
||||
}
|
||||
parameters_.SetParam(key, ao);
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string Intent::GetStringParam(const std::string &key)
|
||||
{
|
||||
auto value = parameters_.GetParam(key);
|
||||
IString *so = IString::Query(value);
|
||||
if (so != nullptr) {
|
||||
return String::Unbox(so);
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
Intent &Intent::SetStringParam(const std::string &key, const std::string &value)
|
||||
{
|
||||
parameters_.SetParam(key, String::Box(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::vector<std::string> Intent::GetStringArrayParam(const std::string &key)
|
||||
{
|
||||
std::vector<std::string> array;
|
||||
auto value = parameters_.GetParam(key);
|
||||
IArray *ao = IArray::Query(value);
|
||||
if (ao != nullptr && Array::IsStringArray(ao)) {
|
||||
auto func = [&](IInterface *object) { array.push_back(String::Unbox(IString::Query(object))); };
|
||||
Array::ForEach(ao, func);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
Intent &Intent::SetStringArrayParam(const std::string &key, const std::vector<std::string> &value)
|
||||
{
|
||||
size_t size = value.size();
|
||||
sptr<IArray> ao = new Array(size, g_IID_IString);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
ao->Set(i, String::Box(value[i]));
|
||||
}
|
||||
parameters_.SetParam(key, ao);
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ohos/aafwk/content/intent_filter.h"
|
||||
|
||||
#include "string_ex.h"
|
||||
#include "ohos/aafwk/content/intent.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
|
||||
IntentFilter::IntentFilter()
|
||||
{}
|
||||
|
||||
std::string IntentFilter::GetEntity() const
|
||||
{
|
||||
return entity_;
|
||||
}
|
||||
|
||||
void IntentFilter::SetEntity(const std::string &entity)
|
||||
{
|
||||
entity_ = entity;
|
||||
}
|
||||
|
||||
void IntentFilter::AddAction(const std::string &action)
|
||||
{
|
||||
auto it = std::find(actions_.cbegin(), actions_.cend(), action);
|
||||
if (it == actions_.cend()) {
|
||||
actions_.push_back(action);
|
||||
}
|
||||
}
|
||||
|
||||
int IntentFilter::CountAction() const
|
||||
{
|
||||
return actions_.size();
|
||||
}
|
||||
|
||||
std::string IntentFilter::GetAction(int index) const
|
||||
{
|
||||
std::string action;
|
||||
if (index < static_cast<int>(actions_.size())) {
|
||||
action = actions_[index];
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
void IntentFilter::RemoveAction(const std::string &action)
|
||||
{
|
||||
auto it = std::find(actions_.cbegin(), actions_.cend(), action);
|
||||
if (it != actions_.cend()) {
|
||||
actions_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
bool IntentFilter::HasAction(const std::string &action) const
|
||||
{
|
||||
return std::find(actions_.cbegin(), actions_.cend(), action) != actions_.cend();
|
||||
}
|
||||
|
||||
bool IntentFilter::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
// write entity
|
||||
if (!parcel.WriteString16(Str8ToStr16(entity_))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// write actions
|
||||
std::vector<std::u16string> actionU16;
|
||||
for (std::vector<std::string>::size_type i = 0; i < actions_.size(); i++) {
|
||||
actionU16.push_back(Str8ToStr16(actions_[i]));
|
||||
}
|
||||
|
||||
return parcel.WriteString16Vector(actionU16);
|
||||
}
|
||||
|
||||
bool IntentFilter::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
// read entity
|
||||
entity_ = Str16ToStr8(parcel.ReadString16());
|
||||
|
||||
// read actions
|
||||
std::vector<std::u16string> actionU16;
|
||||
if (!parcel.ReadString16Vector(&actionU16)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
actions_.clear();
|
||||
for (std::vector<std::u16string>::size_type i = 0; i < actionU16.size(); i++) {
|
||||
actions_.push_back(Str16ToStr8(actionU16[i]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IntentFilter *IntentFilter::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
IntentFilter *filter = new (std::nothrow) IntentFilter();
|
||||
if (filter && !filter->ReadFromParcel(parcel)) {
|
||||
delete filter;
|
||||
filter = nullptr;
|
||||
}
|
||||
return filter;
|
||||
}
|
||||
|
||||
bool IntentFilter::MatchAction(const std::string &action) const
|
||||
{
|
||||
return HasAction(action);
|
||||
}
|
||||
|
||||
bool IntentFilter::MatchEntity(const std::string &entity) const
|
||||
{
|
||||
return entity_ == entity;
|
||||
}
|
||||
|
||||
bool IntentFilter::Match(const Intent &intent) const
|
||||
{
|
||||
return MatchAction(intent.GetAction()) && MatchEntity(intent.GetEntity());
|
||||
}
|
||||
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
@ -1,481 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ohos/aafwk/content/intent_params.h"
|
||||
|
||||
#include "ohos/aafwk/base/array_wrapper.h"
|
||||
#include "ohos/aafwk/base/base_object.h"
|
||||
#include "ohos/aafwk/base/bool_wrapper.h"
|
||||
#include "ohos/aafwk/base/byte_wrapper.h"
|
||||
#include "ohos/aafwk/base/short_wrapper.h"
|
||||
#include "ohos/aafwk/base/int_wrapper.h"
|
||||
#include "ohos/aafwk/base/long_wrapper.h"
|
||||
#include "ohos/aafwk/base/float_wrapper.h"
|
||||
#include "ohos/aafwk/base/double_wrapper.h"
|
||||
#include "ohos/aafwk/base/string_wrapper.h"
|
||||
#include "ohos/aafwk/base/zchar_wrapper.h"
|
||||
|
||||
#include "parcel.h"
|
||||
#include "string_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
|
||||
void IntentParams::SetParam(const std::string &key, IInterface *value)
|
||||
{
|
||||
params_[key] = value;
|
||||
}
|
||||
|
||||
sptr<IInterface> IntentParams::GetParam(const std::string &key) const
|
||||
{
|
||||
auto it = params_.find(key);
|
||||
if (it == params_.cend()) {
|
||||
return nullptr;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
const std::map<std::string, sptr<IInterface>> &IntentParams::GetParams() const
|
||||
{
|
||||
return params_;
|
||||
}
|
||||
|
||||
bool IntentParams::HasParam(const std::string &key) const
|
||||
{
|
||||
return params_.count(key) > 0;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3>
|
||||
static void FillArray(IArray *ao, std::vector<T1> &array)
|
||||
{
|
||||
auto func = [&](IInterface *object) { array.push_back(T2::Unbox(T3::Query(object))); };
|
||||
Array::ForEach(ao, func);
|
||||
}
|
||||
|
||||
bool IntentParams::WriteArrayToParcel(Parcel &parcel, IArray *ao) const
|
||||
{
|
||||
if (Array::IsStringArray(ao)) {
|
||||
std::vector<std::u16string> array;
|
||||
auto func = [&](IInterface *object) {
|
||||
std::string s = String::Unbox(IString::Query(object));
|
||||
array.push_back(Str8ToStr16(s));
|
||||
};
|
||||
Array::ForEach(ao, func);
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_STRINGARRAY)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteString16Vector(array)) {
|
||||
return false;
|
||||
}
|
||||
} else if (Array::IsBooleanArray(ao)) {
|
||||
std::vector<int8_t> array;
|
||||
FillArray<int8_t, Boolean, IBoolean>(ao, array);
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_BOOLEANARRAY)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt8Vector(array)) {
|
||||
return false;
|
||||
}
|
||||
} else if (Array::IsByteArray(ao)) {
|
||||
std::vector<int8_t> array;
|
||||
FillArray<int8_t, Byte, IByte>(ao, array);
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_BYTEARRAY)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt8Vector(array)) {
|
||||
return false;
|
||||
}
|
||||
} else if (Array::IsCharArray(ao)) {
|
||||
std::vector<int32_t> array;
|
||||
FillArray<int32_t, Char, IChar>(ao, array);
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_CHARARRAY)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt32Vector(array)) {
|
||||
return false;
|
||||
}
|
||||
} else if (Array::IsShortArray(ao)) {
|
||||
std::vector<short> array;
|
||||
FillArray<short, Short, IShort>(ao, array);
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_SHORTARRAY)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt16Vector(array)) {
|
||||
return false;
|
||||
}
|
||||
} else if (Array::IsIntegerArray(ao)) {
|
||||
std::vector<int> array;
|
||||
FillArray<int, Integer, IInteger>(ao, array);
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_INTARRAY)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt32Vector(array)) {
|
||||
return false;
|
||||
}
|
||||
} else if (Array::IsLongArray(ao)) {
|
||||
std::vector<int64_t> array;
|
||||
FillArray<int64_t, Long, ILong>(ao, array);
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_LONGARRAY)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt64Vector(array)) {
|
||||
return false;
|
||||
}
|
||||
} else if (Array::IsFloatArray(ao)) {
|
||||
std::vector<float> array;
|
||||
FillArray<float, Float, IFloat>(ao, array);
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_FLOATARRAY)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteFloatVector(array)) {
|
||||
return false;
|
||||
}
|
||||
} else if (Array::IsDoubleArray(ao)) {
|
||||
std::vector<double> array;
|
||||
FillArray<double, Double, IDouble>(ao, array);
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_DOUBLEARRAY)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteDoubleVector(array)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IntentParams::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
size_t size = params_.size();
|
||||
|
||||
if (!parcel.WriteInt32(size)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto iter = params_.cbegin();
|
||||
while (iter != params_.cend()) {
|
||||
std::string key = iter->first;
|
||||
sptr<IInterface> o = iter->second;
|
||||
if (!parcel.WriteString16(Str8ToStr16(key))) {
|
||||
return false;
|
||||
}
|
||||
if (IString::Query(o) != nullptr) {
|
||||
std::string value = String::Unbox(IString::Query(o));
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_STRING)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteString16(Str8ToStr16(value))) {
|
||||
return false;
|
||||
}
|
||||
} else if (IBoolean::Query(o) != nullptr) {
|
||||
bool value = Boolean::Unbox(IBoolean::Query(o));
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_BOOLEAN)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt8(value)) {
|
||||
return false;
|
||||
}
|
||||
} else if (IByte::Query(o) != nullptr) {
|
||||
byte value = Byte::Unbox(IByte::Query(o));
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_BYTE)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt8(value)) {
|
||||
return false;
|
||||
}
|
||||
} else if (IChar::Query(o) != nullptr) {
|
||||
zchar value = Char::Unbox(IChar::Query(o));
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_CHAR)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt32(value)) {
|
||||
return false;
|
||||
}
|
||||
} else if (IShort::Query(o) != nullptr) {
|
||||
short value = Short::Unbox(IShort::Query(o));
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_SHORT)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt16(value)) {
|
||||
return false;
|
||||
}
|
||||
} else if (IInteger::Query(o) != nullptr) {
|
||||
int value = Integer::Unbox(IInteger::Query(o));
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_INT)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt32(value)) {
|
||||
return false;
|
||||
}
|
||||
} else if (ILong::Query(o) != nullptr) {
|
||||
long value = Long::Unbox(ILong::Query(o));
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_LONG)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt64(value)) {
|
||||
return false;
|
||||
}
|
||||
} else if (IFloat::Query(o) != nullptr) {
|
||||
float value = Float::Unbox(IFloat::Query(o));
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_FLOAT)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteFloat(value)) {
|
||||
return false;
|
||||
}
|
||||
} else if (IDouble::Query(o) != nullptr) {
|
||||
double value = Double::Unbox(IDouble::Query(o));
|
||||
if (!parcel.WriteInt32(VALUE_TYPE_DOUBLE)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteDouble(value)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
IArray *ao = IArray::Query(o);
|
||||
if (ao != nullptr && !WriteArrayToParcel(parcel, ao)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
static void SetArray(const InterfaceID &id, const std::vector<T1> &value, sptr<IArray> &ao)
|
||||
{
|
||||
typename std::vector<T1>::size_type size = value.size();
|
||||
ao = new (std::nothrow) Array(size, id);
|
||||
if (ao == nullptr) {
|
||||
return;
|
||||
}
|
||||
for (typename std::vector<T1>::size_type i = 0; i < size; i++) {
|
||||
ao->Set(i, T2::Box(value[i]));
|
||||
}
|
||||
}
|
||||
|
||||
bool IntentParams::ReadArrayToParcel(Parcel &parcel, int type, sptr<IArray> &ao)
|
||||
{
|
||||
switch (type) {
|
||||
case VALUE_TYPE_STRINGARRAY: {
|
||||
std::vector<std::u16string> value;
|
||||
if (!parcel.ReadString16Vector(&value)) {
|
||||
return false;
|
||||
}
|
||||
std::vector<std::u16string>::size_type size = value.size();
|
||||
ao = new (std::nothrow) Array(size, g_IID_IString);
|
||||
if (ao == nullptr) {
|
||||
return false;
|
||||
}
|
||||
for (std::vector<std::u16string>::size_type i = 0; i < size; i++) {
|
||||
ao->Set(i, String::Box(Str16ToStr8(value[i])));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_BOOLEANARRAY: {
|
||||
std::vector<int8_t> value;
|
||||
if (!parcel.ReadInt8Vector(&value)) {
|
||||
return false;
|
||||
}
|
||||
SetArray<int8_t, Boolean>(g_IID_IBoolean, value, ao);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_BYTEARRAY: {
|
||||
std::vector<int8_t> value;
|
||||
if (!parcel.ReadInt8Vector(&value)) {
|
||||
return false;
|
||||
}
|
||||
SetArray<int8_t, Byte>(g_IID_IByte, value, ao);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_CHARARRAY: {
|
||||
std::vector<int32_t> value;
|
||||
if (!parcel.ReadInt32Vector(&value)) {
|
||||
return false;
|
||||
}
|
||||
SetArray<int32_t, Char>(g_IID_IChar, value, ao);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_SHORTARRAY: {
|
||||
std::vector<short> value;
|
||||
if (!parcel.ReadInt16Vector(&value)) {
|
||||
return false;
|
||||
}
|
||||
SetArray<short, Short>(g_IID_IShort, value, ao);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_INTARRAY: {
|
||||
std::vector<int> value;
|
||||
if (!parcel.ReadInt32Vector(&value)) {
|
||||
return false;
|
||||
}
|
||||
SetArray<int, Integer>(g_IID_IInteger, value, ao);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_LONGARRAY: {
|
||||
std::vector<int64_t> value;
|
||||
if (!parcel.ReadInt64Vector(&value)) {
|
||||
return false;
|
||||
}
|
||||
SetArray<int64_t, Long>(g_IID_ILong, value, ao);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_FLOATARRAY: {
|
||||
std::vector<float> value;
|
||||
if (!parcel.ReadFloatVector(&value)) {
|
||||
return false;
|
||||
}
|
||||
SetArray<float, Float>(g_IID_IFloat, value, ao);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_DOUBLEARRAY: {
|
||||
std::vector<double> value;
|
||||
if (!parcel.ReadDoubleVector(&value)) {
|
||||
return false;
|
||||
}
|
||||
SetArray<double, Double>(g_IID_IDouble, value, ao);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// ignore
|
||||
;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IntentParams::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
int32_t size;
|
||||
|
||||
if (!parcel.ReadInt32(size)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
std::u16string key;
|
||||
key = parcel.ReadString16();
|
||||
|
||||
sptr<IInterface> intf = nullptr;
|
||||
int type;
|
||||
if (!parcel.ReadInt32(type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case VALUE_TYPE_STRING: {
|
||||
std::u16string value = parcel.ReadString16();
|
||||
intf = String::Box(Str16ToStr8(value));
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_BOOLEAN: {
|
||||
int8_t value;
|
||||
if (!parcel.ReadInt8(value)) {
|
||||
return false;
|
||||
}
|
||||
intf = Boolean::Box(value);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_BYTE: {
|
||||
int8_t value;
|
||||
if (!parcel.ReadInt8(value)) {
|
||||
return false;
|
||||
}
|
||||
intf = Byte::Box(value);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_CHAR: {
|
||||
int32_t value;
|
||||
if (!parcel.ReadInt32(value)) {
|
||||
return false;
|
||||
}
|
||||
intf = Char::Box(value);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_SHORT: {
|
||||
short value;
|
||||
if (!parcel.ReadInt16(value)) {
|
||||
return false;
|
||||
}
|
||||
intf = Short::Box(value);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_INT: {
|
||||
int value;
|
||||
if (!parcel.ReadInt32(value)) {
|
||||
return false;
|
||||
}
|
||||
intf = Integer::Box(value);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_LONG: {
|
||||
int64_t value;
|
||||
if (!parcel.ReadInt64(value)) {
|
||||
return false;
|
||||
}
|
||||
intf = Long::Box(value);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_FLOAT: {
|
||||
float value;
|
||||
if (!parcel.ReadFloat(value)) {
|
||||
return false;
|
||||
}
|
||||
intf = Float::Box(value);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_DOUBLE: {
|
||||
double value;
|
||||
if (!parcel.ReadDouble(value)) {
|
||||
return false;
|
||||
}
|
||||
intf = Double::Box(value);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_NULL:
|
||||
break;
|
||||
default: {
|
||||
// handle array
|
||||
sptr<IArray> ao = nullptr;
|
||||
if (!ReadArrayToParcel(parcel, type, ao)) {
|
||||
return false;
|
||||
}
|
||||
intf = ao;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (intf) {
|
||||
SetParam(Str16ToStr8(key), intf);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IntentParams *IntentParams::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
IntentParams *intentParams = new (std::nothrow) IntentParams();
|
||||
if (intentParams && !intentParams->ReadFromParcel(parcel)) {
|
||||
delete intentParams;
|
||||
intentParams = nullptr;
|
||||
}
|
||||
return intentParams;
|
||||
}
|
||||
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
@ -455,7 +455,7 @@ Want &Want::SetParams(const WantParams &wantParams)
|
||||
|
||||
/**
|
||||
* @description: Obtains a bool-type value matching the given key.
|
||||
* @param key Indicates the key of IntentParams.
|
||||
* @param key Indicates the key of WantParams.
|
||||
* @param defaultValue Indicates the default bool-type value.
|
||||
* @return Returns the bool-type value of the parameter matching the given key;
|
||||
* returns the default value if the key does not exist.
|
||||
@ -472,7 +472,7 @@ bool Want::GetBoolParam(const std::string &key, bool defaultValue) const
|
||||
|
||||
/**
|
||||
* @description:Obtains a bool-type array matching the given key.
|
||||
* @param key Indicates the key of IntentParams.
|
||||
* @param key Indicates the key of WantParams.
|
||||
* @return Returns the bool-type array of the parameter matching the given key;
|
||||
* returns null if the key does not exist.
|
||||
*/
|
||||
@ -530,7 +530,7 @@ Want &Want::SetParam(const std::string &key, const std::vector<bool> &value)
|
||||
|
||||
/**
|
||||
* @description: Obtains a byte-type value matching the given key.
|
||||
* @param key Indicates the key of IntentParams.
|
||||
* @param key Indicates the key of WantParams.
|
||||
* @param defaultValue Indicates the default byte-type value.
|
||||
* @return Returns the byte-type value of the parameter matching the given key;
|
||||
* returns the default value if the key does not exist.
|
||||
@ -547,7 +547,7 @@ byte Want::GetByteParam(const std::string &key, const byte defaultValue) const
|
||||
|
||||
/**
|
||||
* @description: Obtains a byte-type array matching the given key.
|
||||
* @param key Indicates the key of IntentParams.
|
||||
* @param key Indicates the key of WantParams.
|
||||
* @return Returns the byte-type array of the parameter matching the given key;
|
||||
* returns null if the key does not exist.
|
||||
*/
|
||||
@ -574,7 +574,7 @@ std::vector<byte> Want::GetByteArrayParam(const std::string &key) const
|
||||
* @description: Sets a parameter value of the byte type.
|
||||
* @param key Indicates the key matching the parameter.
|
||||
* @param value Indicates the byte-type value of the parameter.
|
||||
* @return Returns this Intent object containing the parameter value.
|
||||
* @return Returns this Want object containing the parameter value.
|
||||
*/
|
||||
Want &Want::SetParam(const std::string &key, byte value)
|
||||
{
|
||||
@ -586,7 +586,7 @@ Want &Want::SetParam(const std::string &key, byte value)
|
||||
* @description: Sets a parameter value of the byte array type.
|
||||
* @param key Indicates the key matching the parameter.
|
||||
* @param value Indicates the byte array of the parameter.
|
||||
* @return Returns this Intent object containing the parameter value.
|
||||
* @return Returns this Want object containing the parameter value.
|
||||
*/
|
||||
Want &Want::SetParam(const std::string &key, const std::vector<byte> &value)
|
||||
{
|
||||
@ -722,7 +722,7 @@ std::vector<int> Want::GetIntArrayParam(const std::string &key) const
|
||||
* @description: Sets a parameter value of the int type.
|
||||
* @param key Indicates the key matching the parameter.
|
||||
* @param value Indicates the int value of the parameter.
|
||||
* @return Returns this Intent object containing the parameter value.
|
||||
* @return Returns this Want object containing the parameter value.
|
||||
*/
|
||||
Want &Want::SetParam(const std::string &key, int value)
|
||||
{
|
||||
@ -734,7 +734,7 @@ Want &Want::SetParam(const std::string &key, int value)
|
||||
* @description: Sets a parameter value of the int array type.
|
||||
* @param key Indicates the key matching the parameter.
|
||||
* @param value Indicates the int array of the parameter.
|
||||
* @return Returns this Intent object containing the parameter value.
|
||||
* @return Returns this Want object containing the parameter value.
|
||||
*/
|
||||
Want &Want::SetParam(const std::string &key, const std::vector<int> &value)
|
||||
{
|
||||
@ -769,7 +769,7 @@ double Want::GetDoubleParam(const std::string &key, double defaultValue) const
|
||||
|
||||
/**
|
||||
* @description: Obtains a double array matching the given key.
|
||||
* @param key Indicates the key of IntentParams.
|
||||
* @param key Indicates the key of WantParams.
|
||||
* @return Returns the double array of the parameter matching the given key;
|
||||
* returns null if the key does not exist.
|
||||
*/
|
||||
@ -796,7 +796,7 @@ std::vector<double> Want::GetDoubleArrayParam(const std::string &key) const
|
||||
* @description: Sets a parameter value of the double type.
|
||||
* @param key Indicates the key matching the parameter.
|
||||
* @param value Indicates the int value of the parameter.
|
||||
* @return Returns this Intent object containing the parameter value.
|
||||
* @return Returns this Want object containing the parameter value.
|
||||
*/
|
||||
Want &Want::SetParam(const std::string &key, double value)
|
||||
{
|
||||
@ -843,7 +843,7 @@ float Want::GetFloatParam(const std::string &key, float defaultValue) const
|
||||
|
||||
/**
|
||||
* @description: Obtains a float array matching the given key.
|
||||
* @param key Indicates the key of IntentParams.
|
||||
* @param key Indicates the key of WantParams.
|
||||
* @return Obtains a float array matching the given key.
|
||||
*/
|
||||
std::vector<float> Want::GetFloatArrayParam(const std::string &key) const
|
||||
|
@ -136,9 +136,9 @@ std::string WantParams::GetStringByType(const sptr<IInterface> iIt, int typeId)
|
||||
template<typename T1, typename T2, typename T3>
|
||||
static void SetNewArray(const AAFwk::InterfaceID &id, AAFwk::IArray *orgIArray, sptr<AAFwk::IArray> &ao);
|
||||
/**
|
||||
* @description: A constructor used to create an IntentParams instance by using the parameters of an existing
|
||||
* IntentParams object.
|
||||
* @param intentParams Indicates the existing IntentParams object.
|
||||
* @description: A constructor used to create an WantParams instance by using the parameters of an existing
|
||||
* WantParams object.
|
||||
* @param wantParams Indicates the existing WantParams object.
|
||||
*/
|
||||
WantParams::WantParams(const WantParams &wantParams)
|
||||
{
|
||||
@ -216,7 +216,7 @@ bool WantParams::NewArrayData(IArray *source, sptr<IArray> &dest)
|
||||
/**
|
||||
* @description: A WantParams used to
|
||||
*
|
||||
* @param intentParams Indicates the existing IntentParams object.
|
||||
* @param other Indicates the existing WantParams object.
|
||||
*/
|
||||
WantParams &WantParams::operator=(const WantParams &other)
|
||||
{
|
||||
@ -406,9 +406,9 @@ void WantParams::Remove(const std::string &key)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Checks whether the Intent contains the given key.
|
||||
* @description: Checks whether the Want contains the given key.
|
||||
* @param key Indicates the key to check.
|
||||
* @return Returns true if the Intent contains the key; returns false otherwise.
|
||||
* @return Returns true if the Want contains the key; returns false otherwise.
|
||||
*/
|
||||
bool WantParams::HasParam(const std::string &key) const
|
||||
{
|
||||
@ -416,7 +416,7 @@ bool WantParams::HasParam(const std::string &key) const
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Obtains the number of parameters contained in this IntentParams object.
|
||||
* @description: Obtains the number of parameters contained in this WantParams object.
|
||||
* @return Returns the number of parameters.
|
||||
*/
|
||||
int WantParams::Size() const
|
||||
@ -425,7 +425,7 @@ int WantParams::Size() const
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Checks whether this IntentParams object contains no parameters.
|
||||
* @description: Checks whether this WantParams object contains no parameters.
|
||||
* @return Returns true if this object does not contain any parameters; returns false otherwise.
|
||||
*/
|
||||
bool WantParams::IsEmpty() const
|
||||
@ -603,8 +603,8 @@ bool WantParams::DoMarshalling(Parcel &parcel) const
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Marshals an IntentParams object into a Parcel.
|
||||
* @param Key-value pairs in the IntentParams are marshalled separately.
|
||||
* @description: Marshals an WantParams object into a Parcel.
|
||||
* @param Key-value pairs in the WantParams are marshalled separately.
|
||||
* @return If any key-value pair fails to be marshalled, false is returned.
|
||||
*/
|
||||
bool WantParams::Marshalling(Parcel &parcel) const
|
||||
@ -1273,8 +1273,8 @@ bool WantParams::ReadFromParcel(Parcel &parcel)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Unmarshals an IntentParams object from a Parcel.
|
||||
* @param Key-value pairs in the IntentParams are unmarshalled separately.
|
||||
* @description: Unmarshals an WantParams object from a Parcel.
|
||||
* @param Key-value pairs in the WantParams are unmarshalled separately.
|
||||
* @return If any key-value pair fails to be unmarshalled, false is returned.
|
||||
*/
|
||||
WantParams *WantParams::Unmarshalling(Parcel &parcel)
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "ability_runtime/intent_test"
|
||||
module_output_path = "ability_runtime/want_test"
|
||||
|
||||
###############################################################################
|
||||
config("module_private_config") {
|
||||
@ -23,7 +23,6 @@ config("module_private_config") {
|
||||
"//sdk/appexecfwk/appexecfwk_base/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/uri/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/intent/include",
|
||||
"//foundation/appexecfwk/standard/common/log/include",
|
||||
]
|
||||
|
||||
@ -48,138 +47,6 @@ config("module_private_want_param_wrapper_config") {
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("intent_parcelable_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = []
|
||||
|
||||
configs = [
|
||||
":module_private_config",
|
||||
#"//foundation/aafwk/standard/interfaces/innerkits/intent:intent_public_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("intent_base_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = []
|
||||
|
||||
configs = [
|
||||
":module_private_config",
|
||||
#"//foundation/aafwk/standard/interfaces/innerkits/intent:intent_public_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("intent_parse_to_uri_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = []
|
||||
|
||||
configs = [
|
||||
":module_private_config",
|
||||
#"//foundation/aafwk/standard/interfaces/innerkits/intent:intent_public_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("intent_parameters_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = [
|
||||
"../src/ohos/aafwk/content/intent.cpp",
|
||||
"../src/ohos/aafwk/content/intent_params.cpp",
|
||||
"unittest/common/intent_parameters_test.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
":module_private_config",
|
||||
#"//foundation/aafwk/standard/interfaces/innerkits/intent:intent_public_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("intent_params_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = []
|
||||
|
||||
configs = [
|
||||
":module_private_config",
|
||||
#"//foundation/aafwk/standard/interfaces/innerkits/intent:intent_public_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("intent_filter_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = [
|
||||
"../src/ohos/aafwk/content/intent.cpp",
|
||||
"../src/ohos/aafwk/content/intent_filter.cpp",
|
||||
"../src/ohos/aafwk/content/intent_params.cpp",
|
||||
"unittest/common/intent_filter_test.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
":module_private_config",
|
||||
#"//foundation/aafwk/standard/interfaces/innerkits/intent:intent_public_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [ "ability_base:want" ]
|
||||
}
|
||||
|
||||
ohos_unittest("operation_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = [
|
||||
@ -337,11 +204,6 @@ group("unittest") {
|
||||
deps = []
|
||||
|
||||
deps += [
|
||||
":intent_base_test",
|
||||
":intent_filter_test",
|
||||
":intent_parameters_test",
|
||||
":intent_params_test",
|
||||
":intent_parse_to_uri_test",
|
||||
":operation_test",
|
||||
":patterns_matcher_test",
|
||||
":skills_test",
|
||||
|
@ -1,462 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "ohos/aafwk/content/intent.h"
|
||||
#include "ohos/aafwk/content/intent_filter.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::AAFwk;
|
||||
using OHOS::Parcel;
|
||||
|
||||
static const int LARGE_STR_LEN = 65534;
|
||||
static const int SET_COUNT = 20;
|
||||
static const int LOOP_TEST = 1000;
|
||||
|
||||
class IntentFilterBaseTest : public testing::Test {
|
||||
public:
|
||||
IntentFilterBaseTest() : filter_(nullptr)
|
||||
{}
|
||||
~IntentFilterBaseTest()
|
||||
{
|
||||
filter_ = nullptr;
|
||||
}
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
|
||||
IntentFilter *filter_;
|
||||
void CompareFilter(IntentFilter &filter1, IntentFilter &filter2);
|
||||
void SendParcelTest(IntentFilter &filter);
|
||||
};
|
||||
|
||||
void IntentFilterBaseTest::SetUpTestCase(void)
|
||||
{}
|
||||
|
||||
void IntentFilterBaseTest::TearDownTestCase(void)
|
||||
{}
|
||||
|
||||
void IntentFilterBaseTest::SetUp(void)
|
||||
{
|
||||
filter_ = new (std::nothrow) IntentFilter();
|
||||
}
|
||||
|
||||
void IntentFilterBaseTest::TearDown(void)
|
||||
{
|
||||
delete filter_;
|
||||
filter_ = nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: SetEntity/GetEntity
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: SetEntity/GetEntity
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify the function when the input string is empty
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_001, TestSize.Level1)
|
||||
{
|
||||
std::string setValue;
|
||||
filter_->SetEntity(setValue);
|
||||
EXPECT_EQ(setValue, filter_->GetEntity());
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: SetEntity/GetEntity
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: SetEntity/GetEntity
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify the function when the input string contains special characters
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_002, TestSize.Level1)
|
||||
{
|
||||
std::string setValue("@#¥#3243adsafdf_中文");
|
||||
filter_->SetEntity(setValue);
|
||||
EXPECT_EQ(setValue, filter_->GetEntity());
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: SetEntity/GetEntity
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: SetEntity/GetEntity
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify the function when the input string has a long size
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_003, TestSize.Level1)
|
||||
{
|
||||
std::string setValue(LARGE_STR_LEN, 's');
|
||||
filter_->SetEntity(setValue);
|
||||
EXPECT_EQ(setValue, filter_->GetEntity());
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: SetEntity/GetEntity
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: SetEntity/GetEntity
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify the function when the input string is overrode
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_004, TestSize.Level1)
|
||||
{
|
||||
std::string setValue1("1234");
|
||||
filter_->SetEntity(setValue1);
|
||||
|
||||
std::string setValue2("abcd");
|
||||
filter_->SetEntity(setValue2);
|
||||
|
||||
EXPECT_EQ(setValue2, filter_->GetEntity());
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: SetEntity/GetEntity
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: SetEntity/GetEntity
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify the function when the input string is set 20 times
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_005, TestSize.Level1)
|
||||
{
|
||||
std::string setValue("1234");
|
||||
for (int i = 0; i < SET_COUNT; i++) {
|
||||
filter_->SetEntity(setValue);
|
||||
}
|
||||
EXPECT_EQ(setValue, filter_->GetEntity());
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: SetEntity/GetEntity
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: SetEntity/GetEntity
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify the function when the input string is default
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_006, TestSize.Level1)
|
||||
{
|
||||
std::string setValue;
|
||||
EXPECT_EQ(setValue, filter_->GetEntity());
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: SetEntity/GetEntity
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: SetEntity/GetEntity
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify the function when the input string contains special characters
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_007, TestSize.Level1)
|
||||
{
|
||||
std::string setValue("@#¥#3243adsafdf_中文");
|
||||
for (int i = 0; i < LOOP_TEST; i++) {
|
||||
filter_->SetEntity(setValue);
|
||||
EXPECT_EQ(setValue, filter_->GetEntity());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: action
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: action
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify the function when action is not exist
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Action_001, TestSize.Level1)
|
||||
{
|
||||
std::string empty;
|
||||
std::string action = "action.system.test";
|
||||
EXPECT_EQ(0, filter_->CountAction());
|
||||
EXPECT_EQ(false, filter_->HasAction(action));
|
||||
EXPECT_EQ(empty, filter_->GetAction(0));
|
||||
|
||||
filter_->RemoveAction(action);
|
||||
EXPECT_EQ(0, filter_->CountAction());
|
||||
EXPECT_EQ(false, filter_->HasAction(action));
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: action
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: action
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify the function when actions are same
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Action_002, TestSize.Level1)
|
||||
{
|
||||
std::string action = "action.system.test";
|
||||
int actionCount = 1;
|
||||
|
||||
for (int i = 0; i < SET_COUNT; i++) {
|
||||
filter_->AddAction(action);
|
||||
}
|
||||
|
||||
EXPECT_EQ(actionCount, filter_->CountAction());
|
||||
EXPECT_EQ(true, filter_->HasAction(action));
|
||||
EXPECT_EQ(action, filter_->GetAction(0));
|
||||
|
||||
filter_->RemoveAction(action);
|
||||
EXPECT_EQ(0, filter_->CountAction());
|
||||
EXPECT_EQ(false, filter_->HasAction(action));
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: action
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: action
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify the function when actions are different
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Action_003, TestSize.Level1)
|
||||
{
|
||||
std::string actionPrefix = "action.system.test";
|
||||
|
||||
for (int i = 0; i < SET_COUNT; i++) {
|
||||
std::string action = actionPrefix + std::to_string(i);
|
||||
filter_->AddAction(action);
|
||||
}
|
||||
|
||||
EXPECT_EQ(SET_COUNT, filter_->CountAction());
|
||||
for (int i = 0; i < SET_COUNT; i++) {
|
||||
std::string action = actionPrefix + std::to_string(i);
|
||||
EXPECT_EQ(true, filter_->HasAction(action));
|
||||
EXPECT_EQ(action, filter_->GetAction(i));
|
||||
}
|
||||
|
||||
int remove = SET_COUNT / 2;
|
||||
for (int i = 0; i < remove; i++) {
|
||||
std::string action = actionPrefix + std::to_string(i);
|
||||
filter_->RemoveAction(action);
|
||||
}
|
||||
|
||||
EXPECT_EQ(remove, filter_->CountAction());
|
||||
for (int i = 0; i < remove; i++) {
|
||||
std::string action = actionPrefix + std::to_string(i);
|
||||
EXPECT_EQ(false, filter_->HasAction(action));
|
||||
}
|
||||
|
||||
for (int i = remove; i < SET_COUNT; i++) {
|
||||
std::string action = actionPrefix + std::to_string(i);
|
||||
EXPECT_EQ(true, filter_->HasAction(action));
|
||||
EXPECT_EQ(action, filter_->GetAction(i - remove));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: action
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: action
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify the function when actions are same
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Action_004, TestSize.Level1)
|
||||
{
|
||||
std::string action = "action.system.test";
|
||||
int actionCount = 1;
|
||||
|
||||
for (int i = 0; i < LOOP_TEST; i++) {
|
||||
filter_->AddAction(action);
|
||||
EXPECT_EQ(actionCount, filter_->CountAction());
|
||||
EXPECT_EQ(true, filter_->HasAction(action));
|
||||
EXPECT_EQ(action, filter_->GetAction(0));
|
||||
|
||||
filter_->RemoveAction(action);
|
||||
EXPECT_EQ(0, filter_->CountAction());
|
||||
EXPECT_EQ(false, filter_->HasAction(action));
|
||||
}
|
||||
}
|
||||
|
||||
void IntentFilterBaseTest::CompareFilter(IntentFilter &filter1, IntentFilter &filter2)
|
||||
{
|
||||
EXPECT_EQ(filter1.GetEntity(), filter2.GetEntity());
|
||||
EXPECT_EQ(filter1.CountAction(), filter2.CountAction());
|
||||
|
||||
int count = filter1.CountAction();
|
||||
for (int i = 0; i < count; i++) {
|
||||
EXPECT_EQ(filter1.GetAction(i), filter2.GetAction(i));
|
||||
}
|
||||
}
|
||||
|
||||
void IntentFilterBaseTest::SendParcelTest(IntentFilter &filter)
|
||||
{
|
||||
Parcel data;
|
||||
bool result;
|
||||
|
||||
result = data.WriteParcelable(&filter);
|
||||
EXPECT_EQ(result, true);
|
||||
|
||||
IntentFilter *filterNew = nullptr;
|
||||
filterNew = data.ReadParcelable<IntentFilter>();
|
||||
EXPECT_NE(filterNew, nullptr);
|
||||
|
||||
if (filterNew) {
|
||||
CompareFilter(filter, *filterNew);
|
||||
delete filterNew;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: marshall and unmarshall
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: marshall and unmarshall
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify marshall and unmarshall when filter is empty
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_parcelable_001, TestSize.Level0)
|
||||
{
|
||||
SendParcelTest(*filter_);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: marshall and unmarshall
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: marshall and unmarshall
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify marshall and unmarshall when filter has action and entity
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_parcelable_002, TestSize.Level0)
|
||||
{
|
||||
filter_->SetEntity("entity.system.test");
|
||||
filter_->AddAction("action.system.test1");
|
||||
filter_->AddAction("action.system.test2");
|
||||
|
||||
SendParcelTest(*filter_);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: marshall and unmarshall
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: marshall and unmarshall
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify marshall and unmarshall. Pressure test.
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_parcelable_003, TestSize.Level0)
|
||||
{
|
||||
filter_->SetEntity("entity.system.test");
|
||||
filter_->AddAction("action.system.test1");
|
||||
filter_->AddAction("action.system.test2");
|
||||
|
||||
for (int i = 0; i < LOOP_TEST; i++) {
|
||||
SendParcelTest(*filter_);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: Match
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Match
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify the function. Pressure test.
|
||||
*/
|
||||
HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_match_005, TestSize.Level1)
|
||||
{
|
||||
for (int i = 0; i < LOOP_TEST; i++) {
|
||||
Intent intent;
|
||||
intent.SetAction("action.system.action1");
|
||||
intent.SetEntity("entity.system.entity1");
|
||||
|
||||
filter_->SetEntity("entity.system.entity1");
|
||||
filter_->AddAction("action.system.action1");
|
||||
filter_->AddAction("action.system.action2");
|
||||
|
||||
EXPECT_EQ(true, filter_->Match(intent));
|
||||
}
|
||||
}
|
||||
|
||||
using testFilterMatchType = std::tuple<std::string, std::string, bool>;
|
||||
class IntentFilterMatchTest : public testing::TestWithParam<testFilterMatchType> {
|
||||
public:
|
||||
IntentFilterMatchTest() : filter_(nullptr)
|
||||
{}
|
||||
~IntentFilterMatchTest()
|
||||
{
|
||||
filter_ = nullptr;
|
||||
}
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
IntentFilter *filter_;
|
||||
};
|
||||
|
||||
void IntentFilterMatchTest::SetUpTestCase(void)
|
||||
{}
|
||||
|
||||
void IntentFilterMatchTest::TearDownTestCase(void)
|
||||
{}
|
||||
|
||||
void IntentFilterMatchTest::SetUp(void)
|
||||
{
|
||||
filter_ = new (std::nothrow) IntentFilter();
|
||||
}
|
||||
|
||||
void IntentFilterMatchTest::TearDown(void)
|
||||
{
|
||||
delete filter_;
|
||||
filter_ = nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: IntentFilter
|
||||
* Function: Match
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Match
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify whether parameter change.
|
||||
* AaFwk_IntentFilter_match_001
|
||||
* AaFwk_IntentFilter_match_002
|
||||
* AaFwk_IntentFilter_match_003
|
||||
* AaFwk_IntentFilter_match_004
|
||||
*/
|
||||
|
||||
HWTEST_P(IntentFilterMatchTest, AaFwk_IntentFilter_match, TestSize.Level0)
|
||||
{
|
||||
std::string filterEntity = "entity.system.entity1";
|
||||
std::string filterAction1 = "action.system.action1";
|
||||
std::string filterAction2 = "action.system.action2";
|
||||
std::string intentEntity = std::get<0>(GetParam());
|
||||
std::string intentAction = std::get<1>(GetParam());
|
||||
bool result = std::get<2>(GetParam());
|
||||
|
||||
filter_->SetEntity(filterEntity);
|
||||
filter_->AddAction(filterAction1);
|
||||
filter_->AddAction(filterAction2);
|
||||
|
||||
Intent intent;
|
||||
intent.SetEntity(intentEntity);
|
||||
intent.SetAction(intentAction);
|
||||
|
||||
EXPECT_EQ(result, filter_->Match(intent));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(IntentFilterMatchTestP, IntentFilterMatchTest,
|
||||
testing::Values(testFilterMatchType("entity.system.entityA", "action.system.actionA", false),
|
||||
testFilterMatchType("entity.system.entity1", "action.system.actionA", false),
|
||||
testFilterMatchType("entity.system.entityA", "action.system.action2", false),
|
||||
testFilterMatchType("entity.system.entity1", "action.system.action1", true)));
|
File diff suppressed because it is too large
Load Diff
@ -735,8 +735,8 @@ HWTEST_P(SkillsMatchTest, AaFwk_Skills_match_0100, Function | MediumTest | Level
|
||||
std::string filterEntity = "entity.system.entity1";
|
||||
std::string filterAction1 = "action.system.action1";
|
||||
std::string filterAction2 = "action.system.action2";
|
||||
std::string intentEntity = std::get<0>(GetParam());
|
||||
std::string intentAction = std::get<1>(GetParam());
|
||||
std::string wantEntity = std::get<0>(GetParam());
|
||||
std::string wantAction = std::get<1>(GetParam());
|
||||
bool result = std::get<2>(GetParam());
|
||||
|
||||
skills_->AddEntity(filterEntity);
|
||||
@ -744,8 +744,8 @@ HWTEST_P(SkillsMatchTest, AaFwk_Skills_match_0100, Function | MediumTest | Level
|
||||
skills_->AddAction(filterAction2);
|
||||
|
||||
Want want;
|
||||
want.AddEntity(intentEntity);
|
||||
want.SetAction(intentAction);
|
||||
want.AddEntity(wantEntity);
|
||||
want.SetAction(wantAction);
|
||||
|
||||
EXPECT_EQ(result, skills_->Match(want));
|
||||
}
|
||||
|
@ -17,8 +17,6 @@ import("//foundation/aafwk/standard/feature.gni")
|
||||
module_output_path = "ability_runtime/aafwk_L2"
|
||||
|
||||
###############################################################################
|
||||
#1. intent(c++) get/set test without transport
|
||||
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
cflags = []
|
||||
|
@ -17,7 +17,6 @@ group("innerkits_target") {
|
||||
"ability_manager:ability_manager",
|
||||
"app_manager:app_manager",
|
||||
"dataobs_manager:dataobs_manager",
|
||||
"intent:intent",
|
||||
"uri_permission:uri_permission_mgr",
|
||||
"want:want",
|
||||
]
|
||||
|
@ -1,71 +0,0 @@
|
||||
# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/aafwk/standard/aafwk.gni")
|
||||
|
||||
config("intent_config") {
|
||||
visibility = [ ":*" ]
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
defines = [
|
||||
"AMS_LOG_TAG = \"Ability\"",
|
||||
"AMS_LOG_DOMAIN = 0xD002200",
|
||||
]
|
||||
}
|
||||
|
||||
config("intent_public_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"//utils/native/base/include",
|
||||
"${innerkits_path}/intent/include",
|
||||
"${innerkits_path}/uri/include",
|
||||
"${services_path}/common/include",
|
||||
]
|
||||
}
|
||||
|
||||
intentImpl = "${kits_path}/content/cpp/src/ohos/aafwk/content"
|
||||
|
||||
ohos_shared_library("intent") {
|
||||
sources = [
|
||||
"${intentImpl}/intent.cpp",
|
||||
"${intentImpl}/intent_filter.cpp",
|
||||
"${intentImpl}/intent_params.cpp",
|
||||
|
||||
#"${intentImpl}/operation.cpp",
|
||||
#"${intentImpl}/patterns_matcher.cpp",
|
||||
#"${intentImpl}/skills.cpp",
|
||||
#"${intentImpl}/want_params.cpp",
|
||||
#"${intentImpl}/want.cpp",
|
||||
]
|
||||
|
||||
deps = []
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:lsamgr",
|
||||
"utils_base:utils",
|
||||
]
|
||||
|
||||
configs = [ ":intent_config" ]
|
||||
public_configs = [ ":intent_public_config" ]
|
||||
subsystem_name = "aafwk"
|
||||
part_name = "ability_runtime"
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef OHOS_AAFWK_INTENT_H
|
||||
#define OHOS_AAFWK_INTENT_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "intent_params.h"
|
||||
|
||||
#include "element_name.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
|
||||
class Intent final : public Parcelable {
|
||||
public:
|
||||
Intent();
|
||||
inline ~Intent()
|
||||
{}
|
||||
|
||||
static Intent *ParseUri(const std::string &uri);
|
||||
std::string ToUri();
|
||||
|
||||
std::string GetAction() const;
|
||||
Intent &SetAction(const std::string &action);
|
||||
|
||||
unsigned int GetFlags() const;
|
||||
Intent &SetFlag(const unsigned int flag);
|
||||
Intent &AddFlag(const unsigned int flag);
|
||||
void RemoveFlags(const unsigned int flag);
|
||||
|
||||
std::string GetEntity() const;
|
||||
Intent &SetEntity(const std::string &entity);
|
||||
|
||||
OHOS::AppExecFwk::ElementName GetElement() const;
|
||||
Intent &SetElement(const OHOS::AppExecFwk::ElementName &element);
|
||||
|
||||
bool GetBoolParam(const std::string &key, const bool defaultValue);
|
||||
Intent &SetBoolParam(const std::string &key, const bool value);
|
||||
std::vector<bool> GetBoolArrayParam(const std::string &key);
|
||||
Intent &SetBoolArrayParam(const std::string &key, const std::vector<bool> &value);
|
||||
|
||||
zchar GetCharParam(const std::string &key, const zchar defaultValue);
|
||||
Intent &SetCharParam(const std::string &key, const zchar value);
|
||||
std::vector<zchar> GetCharArrayParam(const std::string &key);
|
||||
Intent &SetCharArrayParam(const std::string &key, const std::vector<zchar> &value);
|
||||
|
||||
byte GetByteParam(const std::string &key, const byte defaultValue);
|
||||
Intent &SetByteParam(const std::string &key, const byte value);
|
||||
std::vector<byte> GetByteArrayParam(const std::string &key);
|
||||
Intent &SetByteArrayParam(const std::string &key, const std::vector<byte> &value);
|
||||
|
||||
short GetShortParam(const std::string &key, const short defaultValue);
|
||||
Intent &SetShortParam(const std::string &key, const short value);
|
||||
std::vector<short> GetShortArrayParam(const std::string &key);
|
||||
Intent &SetShortArrayParam(const std::string &key, const std::vector<short> &value);
|
||||
|
||||
int GetIntParam(const std::string &key, const int defaultValue);
|
||||
Intent &SetIntParam(const std::string &key, const int value);
|
||||
std::vector<int> GetIntArrayParam(const std::string &key);
|
||||
Intent &SetIntArrayParam(const std::string &key, const std::vector<int> &value);
|
||||
|
||||
long GetLongParam(const std::string &key, const long defaultValue);
|
||||
Intent &SetLongParam(const std::string &key, const long value);
|
||||
std::vector<long> GetLongArrayParam(const std::string &key);
|
||||
Intent &SetLongArrayParam(const std::string &key, const std::vector<long> &value);
|
||||
|
||||
float GetFloatParam(const std::string &key, const float defaultValue);
|
||||
Intent &SetFloatParam(const std::string &key, const float value);
|
||||
std::vector<float> GetFloatArrayParam(const std::string &key);
|
||||
Intent &SetFloatArrayParam(const std::string &key, const std::vector<float> &value);
|
||||
|
||||
double GetDoubleParam(const std::string &key, const double defaultValue);
|
||||
Intent &SetDoubleParam(const std::string &key, const double value);
|
||||
std::vector<double> GetDoubleArrayParam(const std::string &key);
|
||||
Intent &SetDoubleArrayParam(const std::string &key, const std::vector<double> &value);
|
||||
|
||||
std::string GetStringParam(const std::string &key);
|
||||
Intent &SetStringParam(const std::string &key, const std::string &value);
|
||||
std::vector<std::string> GetStringArrayParam(const std::string &key);
|
||||
Intent &SetStringArrayParam(const std::string &key, const std::vector<std::string> &value);
|
||||
|
||||
bool HasParameter(const std::string &key) const;
|
||||
|
||||
virtual bool Marshalling(Parcel &parcel) const;
|
||||
|
||||
static Intent *Unmarshalling(Parcel &parcel);
|
||||
|
||||
public:
|
||||
// action definition
|
||||
static const std::string ACTION_PLAY;
|
||||
|
||||
// entity definition
|
||||
static const std::string ENTITY_HOME;
|
||||
static const std::string ENTITY_VIDEO;
|
||||
|
||||
// flag definition
|
||||
static constexpr unsigned int FLAG_ABILITY_NEW_MISSION = 0x00000001;
|
||||
|
||||
private:
|
||||
std::string action_;
|
||||
unsigned int flags_;
|
||||
std::string entity_;
|
||||
IntentParams parameters_;
|
||||
|
||||
OHOS::AppExecFwk::ElementName element_;
|
||||
|
||||
static const std::string OCT_EQUALSTO;
|
||||
static const std::string OCT_SEMICOLON;
|
||||
|
||||
// no object in parcel
|
||||
static constexpr int VALUE_NULL = -1;
|
||||
// object exist in parcel
|
||||
static constexpr int VALUE_OBJECT = 1;
|
||||
|
||||
private:
|
||||
static bool ParseFlag(const std::string &content, Intent &intent);
|
||||
static std::string Decode(const std::string &str);
|
||||
static std::string Encode(const std::string &str);
|
||||
static bool ParseContent(const std::string &content, std::string &prop, std::string &value);
|
||||
static bool ParseUriInternal(const std::string &content, OHOS::AppExecFwk::ElementName &element, Intent &intent);
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
};
|
||||
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_AAFWK_INTENT_H
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_AAFWK_INTENT_FILTER_H
|
||||
#define OHOS_AAFWK_INTENT_FILTER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
|
||||
class Intent;
|
||||
class IntentFilter final : public Parcelable {
|
||||
public:
|
||||
IntentFilter();
|
||||
inline ~IntentFilter()
|
||||
{}
|
||||
|
||||
std::string GetEntity() const;
|
||||
|
||||
void SetEntity(const std::string &entity);
|
||||
|
||||
void AddAction(const std::string &action);
|
||||
|
||||
int CountAction() const;
|
||||
|
||||
std::string GetAction(int index) const;
|
||||
|
||||
void RemoveAction(const std::string &action);
|
||||
|
||||
bool HasAction(const std::string &action) const;
|
||||
|
||||
bool Match(const Intent &intent) const;
|
||||
|
||||
virtual bool Marshalling(Parcel &parcel) const;
|
||||
|
||||
static IntentFilter *Unmarshalling(Parcel &parcel);
|
||||
|
||||
private:
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
bool MatchAction(const std::string &action) const;
|
||||
bool MatchEntity(const std::string &entity) const;
|
||||
|
||||
std::string entity_;
|
||||
std::vector<std::string> actions_;
|
||||
};
|
||||
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_AAFWK_INTENT_FILTER_H
|
@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef OHOS_AAFWK_INTENT_PARAMS_H
|
||||
#define OHOS_AAFWK_INTENT_PARAMS_H
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "ohos/aafwk/base/base_interfaces.h"
|
||||
#include "refbase.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
|
||||
class IntentParams final : public Parcelable {
|
||||
public:
|
||||
void SetParam(const std::string &key, IInterface *value);
|
||||
|
||||
sptr<IInterface> GetParam(const std::string &key) const;
|
||||
|
||||
const std::map<std::string, sptr<IInterface>> &GetParams() const;
|
||||
|
||||
bool HasParam(const std::string &key) const;
|
||||
|
||||
virtual bool Marshalling(Parcel &parcel) const;
|
||||
|
||||
static IntentParams *Unmarshalling(Parcel &parcel);
|
||||
|
||||
private:
|
||||
// Java side should keep consistent.
|
||||
enum {
|
||||
VALUE_TYPE_NULL = -1,
|
||||
VALUE_TYPE_BOOLEAN = 1,
|
||||
VALUE_TYPE_BYTE = 2,
|
||||
VALUE_TYPE_CHAR = 3,
|
||||
VALUE_TYPE_SHORT = 4,
|
||||
VALUE_TYPE_INT = 5,
|
||||
VALUE_TYPE_LONG = 6,
|
||||
VALUE_TYPE_FLOAT = 7,
|
||||
VALUE_TYPE_DOUBLE = 8,
|
||||
VALUE_TYPE_STRING = 9,
|
||||
VALUE_TYPE_CHARSEQUENCE = 10,
|
||||
VALUE_TYPE_BOOLEANARRAY = 11,
|
||||
VALUE_TYPE_BYTEARRAY = 12,
|
||||
VALUE_TYPE_CHARARRAY = 13,
|
||||
VALUE_TYPE_SHORTARRAY = 14,
|
||||
VALUE_TYPE_INTARRAY = 15,
|
||||
VALUE_TYPE_LONGARRAY = 16,
|
||||
VALUE_TYPE_FLOATARRAY = 17,
|
||||
VALUE_TYPE_DOUBLEARRAY = 18,
|
||||
VALUE_TYPE_STRINGARRAY = 19,
|
||||
VALUE_TYPE_CHARSEQUENCEARRAY = 20,
|
||||
};
|
||||
|
||||
bool WriteArrayToParcel(Parcel &parcel, IArray *ao) const;
|
||||
bool ReadArrayToParcel(Parcel &parcel, int type, sptr<IArray> &ao);
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
|
||||
/* params_ has default construct function,
|
||||
no need explicit initialization in the construct function */
|
||||
std::map<std::string, sptr<IInterface>> params_;
|
||||
};
|
||||
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_AAFWK_INTENT_PARAMS_H
|
11
ohos.build
11
ohos.build
@ -19,17 +19,6 @@
|
||||
|
||||
],
|
||||
"inner_kits": [
|
||||
{
|
||||
"header": {
|
||||
"header_base": "//foundation/aafwk/standard/interfaces/innerkits/intent/include/",
|
||||
"header_files": [
|
||||
"ohos/aafwk/content/intent.h",
|
||||
"ohos/aafwk/content/intent_filter.h",
|
||||
"ohos/aafwk/content/intent_params.h"
|
||||
]
|
||||
},
|
||||
"name": "//foundation/aafwk/standard/interfaces/innerkits/intent:intent"
|
||||
},
|
||||
{
|
||||
"header": {
|
||||
"header_base": "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include",
|
||||
|
@ -41,8 +41,6 @@ config("abilityms_config") {
|
||||
"${innerkits_path}/uri/include",
|
||||
"${innerkits_path}/want/include",
|
||||
"${innerkits_path}/want/include/ohos/aafwk/content",
|
||||
"${innerkits_path}/intent/include/ohos/aafwk/content",
|
||||
"${innerkits_path}/want/include/ohos/aafwk/content",
|
||||
"${services_path}/common/include",
|
||||
"//utils/native/base/include",
|
||||
"//prebuilts/jdk/jdk8/linux-x86/include",
|
||||
|
@ -35,7 +35,7 @@ std::shared_ptr<MTDumpUtil> MTDumpUtil::GetInstance()
|
||||
|
||||
MTDumpUtil::MTDumpUtil()
|
||||
{
|
||||
findRgx_["Intent"] = regex(".*intent\\[(.+)\\].*");
|
||||
findRgx_["Want"] = regex(".*Want\\[(.+)\\].*");
|
||||
findRgx_["AbilityName"] = regex(".*main name \\[(.+)\\].*");
|
||||
findRgx_["AppName"] = regex(".*app name \\[(.+)\\].*");
|
||||
findRgx_["BundleName"] = regex(".*bundle name \\[(.+)\\].*");
|
||||
|
@ -21,7 +21,6 @@ group("fuzztest") {
|
||||
"CompelVerifyPermission_fuzzer:fuzztest",
|
||||
"FinishUserTest_fuzzer:fuzztest",
|
||||
"GetWantSender_fuzzer:fuzztest",
|
||||
"IntentParseUri_fuzzer:fuzztest",
|
||||
"MoveMissionToFloatingStack_fuzzer:fuzztest",
|
||||
"SetMissionLabel_fuzzer:fuzztest",
|
||||
"SetMissionStackSetting_fuzzer:fuzztest",
|
||||
|
@ -1,57 +0,0 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "developertest/ability_runtime"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("IntentParseUriFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
include_dirs =
|
||||
[ "//foundation/aafwk/standard/interfaces/innerkits/intent/include" ]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
|
||||
sources = [ "IntentParseUri_fuzzer.cpp" ]
|
||||
|
||||
deps = [
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/intent:intent",
|
||||
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"utils_base:utils",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":IntentParseUriFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "IntentParseUri_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "ohos/aafwk/content/intent.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
|
||||
namespace OHOS {
|
||||
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
|
||||
{
|
||||
Intent *ret = Intent::ParseUri(reinterpret_cast<const char*>(data));
|
||||
|
||||
if (ret) {
|
||||
delete ret;
|
||||
ret = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::DoSomethingInterestingWithMyAPI(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TEST_FUZZTEST_INTENTPARSEURI_FUZZER_INTENTPARSEURI_FUZZER_H
|
||||
#define TEST_FUZZTEST_INTENTPARSEURI_FUZZER_INTENTPARSEURI_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "IntentParseUri_fuzzer"
|
||||
|
||||
#endif
|
@ -1,25 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
@ -19,7 +19,6 @@ module_output_path = "appexecfwk_standard/ams/"
|
||||
config("system_test_ams_ability_state_age_manual_test_config") {
|
||||
include_dirs = [
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include",
|
||||
"${aafwk_path}/interfaces/innerkits/intent/include",
|
||||
"${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/bundlemgr",
|
||||
"${aafwk_path}/interfaces/innerkits/want/include",
|
||||
"${aafwk_path}/interfaces/innerkits/app_manager/include/appmgr",
|
||||
|
@ -19,7 +19,6 @@ module_output_path = "appexecfwk_standard/ams/"
|
||||
config("system_test_ams_ability_state_test_config") {
|
||||
include_dirs = [
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include",
|
||||
"${aafwk_path}/interfaces/innerkits/intent/include",
|
||||
"${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/bundlemgr",
|
||||
"${aafwk_path}/interfaces/innerkits/want/include",
|
||||
"${aafwk_path}/interfaces/innerkits/app_manager/include/appmgr",
|
||||
|
@ -19,7 +19,6 @@ module_output_path = "appexecfwk_standard/ams/"
|
||||
config("ams_check_service_config") {
|
||||
include_dirs = [
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include",
|
||||
"${aafwk_path}/interfaces/innerkits/intent/include",
|
||||
"${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/bundlemgr",
|
||||
"${aafwk_path}/interfaces/innerkits/want/include",
|
||||
"${aafwk_path}/interfaces/innerkits/app_manager/include/appmgr",
|
||||
|
@ -35,7 +35,7 @@ std::shared_ptr<MTDumpUtil> MTDumpUtil::GetInstance()
|
||||
|
||||
MTDumpUtil::MTDumpUtil()
|
||||
{
|
||||
findRgx_["Intent"] = regex(".*intent\\[(.+)\\].*");
|
||||
findRgx_["Want"] = regex(".*Want\\[(.+)\\].*");
|
||||
findRgx_["AbilityName"] = regex(".*main name \\[(.+)\\].*");
|
||||
findRgx_["AppName"] = regex(".*app name \\[(.+)\\].*");
|
||||
findRgx_["BundleName"] = regex(".*bundle name \\[(.+)\\].*");
|
||||
|
@ -21,7 +21,6 @@ config("system_test_task_dispatcher_config") {
|
||||
"//foundation/aafwk/standard/common/task_dispatcher/include/threading",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include/task",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include",
|
||||
"${aafwk_path}/interfaces/innerkits/intent/include",
|
||||
"${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/bundlemgr",
|
||||
"${aafwk_path}/interfaces/innerkits/want/include",
|
||||
"${aafwk_path}/interfaces/innerkits/app_manager/include/appmgr",
|
||||
|
Loading…
Reference in New Issue
Block a user