Merge branch 'master' of gitee.com:openharmony/aafwk_standard into master

This commit is contained in:
jerry 2022-04-06 11:32:16 +00:00 committed by Gitee
commit 6016e2e8d1
72 changed files with 1245 additions and 5121 deletions

View File

@ -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,

View File

@ -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",

View File

@ -52,11 +52,12 @@ ohos_shared_library("task_dispatcher") {
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [ "${appexecfwk_path}/common:libappexecfwk_common" ]
deps = []
external_deps = [
"bundle_framework:appexecfwk_base",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"utils_base:utils",
]
subsystem_name = "aafwk"

View File

@ -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 = []

View File

@ -224,7 +224,6 @@ ohos_shared_library("abilitykit_native") {
deps = [
":static_subscriber_ipc",
"${appexecfwk_path}/common:libappexecfwk_common",
"${innerkits_path}/dataobs_manager:dataobs_manager",
"${kits_path}/appkit:app_context",
"${kits_path}/appkit:appkit_delegator",
@ -323,7 +322,7 @@ ohos_shared_library("dummy_classes") {
configs = [ ":ability_config" ]
public_configs = [ ":ability_public_config" ]
deps = [ "${appexecfwk_path}/common:libappexecfwk_common" ]
deps = []
external_deps = [
"ability_base:want",
@ -344,10 +343,7 @@ ohos_shared_library("service_extension_module") {
configs = [ ":ability_config" ]
public_configs = [ ":ability_public_config" ]
deps = [
":abilitykit_native",
"${appexecfwk_path}/common:libappexecfwk_common",
]
deps = [ ":abilitykit_native" ]
external_deps = [
"ability_base:want",
@ -369,10 +365,7 @@ ohos_shared_library("datashare_ext_ability_module") {
configs = [ ":ability_config" ]
public_configs = [ ":ability_public_config" ]
deps = [
":abilitykit_native",
"${appexecfwk_path}/common:libappexecfwk_common",
]
deps = [ ":abilitykit_native" ]
external_deps = [
"ability_base:want",

View File

@ -80,7 +80,7 @@ private:
JsRuntime &jsRuntime_;
std::shared_ptr<NativeReference> shellContextRef_;
std::unique_ptr<NativeReference> jsAbilityObj_;
std::shared_ptr<NativeReference> jsAbilityObj_;
sptr<IRemoteObject> remoteCallee_;
};
} // namespace AbilityRuntime

View File

@ -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.

View File

@ -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.

View File

@ -560,6 +560,7 @@ std::shared_ptr<AppExecFwk::ADelegatorAbilityProperty> JsAbility::CreateADelegat
property->token_ = GetAbilityContext()->GetToken();
property->name_ = GetAbilityName();
property->lifecycleState_ = GetState();
property->object_ = jsAbilityObj_;
return property;
}

View File

@ -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.

View File

@ -18,7 +18,7 @@
#include <memory>
#include "hilog_wrapper.h"
#include "parcel_macro.h"
#include "parcel_macro_ability.h"
namespace OHOS {
namespace AppExecFwk {

View File

@ -16,7 +16,9 @@
#ifndef FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_H
#define FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_H
#include <functional>
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <string>
@ -40,58 +42,243 @@ namespace AppExecFwk {
class AbilityDelegator : public std::enable_shared_from_this<AbilityDelegator> {
public:
enum class AbilityState : uint8_t {
/**
* Indicates that the ability has not been initialized.
*/
UNINITIALIZED = 0,
/**
* Indicates that the ability is in the started state.
*/
STARTED,
/**
* Indicates that the ability is in the foreground state.
*/
FOREGROUND,
/**
* Indicates that the ability is in the background state.
*/
BACKGROUND,
/**
* Indicates that the ability is in the stopped state.
*/
STOPPED
};
/**
* Definition of cleanup function.
*/
using ClearFunc = std::function<void(const std::shared_ptr<ADelegatorAbilityProperty> &)>;
public:
/**
* A constructor used to create a AbilityDelegator instance with the input parameter passed.
*
* @param context Indicates the ability runtime context.
* @param runner Indicates the TestRunner object.
* @param observer Indicates the TestObserver object.
*/
AbilityDelegator(const std::shared_ptr<AbilityRuntime::Context> &context, std::unique_ptr<TestRunner> runner,
const sptr<IRemoteObject> &observer);
/**
* Default deconstructor used to deconstruct.
*/
~AbilityDelegator();
/**
* Adds monitor for monitoring the lifecycle state changes of the ability.
*
* @param monitor, Indicates the monitor object.
*/
void AddAbilityMonitor(const std::shared_ptr<IAbilityMonitor> &monitor);
/**
* Removes ability monitor.
*
* @param monitor, Indicates the specified monitor object.
*/
void RemoveAbilityMonitor(const std::shared_ptr<IAbilityMonitor> &monitor);
/**
* Clears all monitors.
*/
void ClearAllMonitors();
/**
* Obtains the number of monitors.
*
* @return the number of monitors.
*/
size_t GetMonitorsNum();
sptr<IRemoteObject> WaitAbilityMonitor(const std::shared_ptr<IAbilityMonitor> &monitor);
sptr<IRemoteObject> WaitAbilityMonitor(
/**
* Waits for the specified monitor and return the obtained ability.
*
* @param monitor, Indicates the specified monitor object.
* @return the obtained ability.
*/
std::shared_ptr<ADelegatorAbilityProperty> WaitAbilityMonitor(const std::shared_ptr<IAbilityMonitor> &monitor);
/**
* Waits for the specified monitor within the timeout time and return the obtained ability.
*
* @param monitor, Indicates the specified monitor object.
* @param timeoutMs, Indicates the specified time out time, in milliseconds.
* @return the obtained ability.
*/
std::shared_ptr<ADelegatorAbilityProperty> WaitAbilityMonitor(
const std::shared_ptr<IAbilityMonitor> &monitor, const int64_t timeoutMs);
/**
* Obtains the application context.
*
* @return the application context.
*/
std::shared_ptr<AbilityRuntime::Context> GetAppContext() const;
/**
* Obtains the lifecycle state of the specified ability.
*
* @param token, Indicates the specified ability.
* @return the lifecycle state of the specified ability.
*/
AbilityDelegator::AbilityState GetAbilityState(const sptr<IRemoteObject> &token);
sptr<IRemoteObject> GetCurrentTopAbility();
/**
* Obtains the ability that is currently being displayed.
*
* @return the ability that is currently being displayed.
*/
std::shared_ptr<ADelegatorAbilityProperty> GetCurrentTopAbility();
/**
* Obtains the name of the thread.
*
* @return the name of the thread.
*/
std::string GetThreadName() const;
/**
* Notifies TestRunner to prepare.
*/
void Prepare();
/**
* Notifies TestRunner to run.
*/
void OnRun();
/**
* Starts an ability based on the given Want.
*
* @param want, Indicates the Want for starting the ability.
* @return the result code.
*/
ErrCode StartAbility(const AAFwk::Want &want);
/**
* Transits the specified ability to foreground.
*
* @param token, Indicates the specified ability.
* @return true if succeed; returns false otherwise.
*/
bool DoAbilityForeground(const sptr<IRemoteObject> &token);
/**
* Transits the specified ability to background.
*
* @param token, Indicates the specified ability.
* @return true if succeed; returns false otherwise.
*/
bool DoAbilityBackground(const sptr<IRemoteObject> &token);
/**
* Executes the specified shell command.
*
* @param cmd, Indicates the specified shell command.
* @param timeoutSec, Indicates the specified time out time, in seconds.
* @return the result of the specified shell command.
*/
std::unique_ptr<ShellCmdResult> ExecuteShellCommand(const std::string &cmd, const int64_t timeoutSec);
/**
* Prints log information to the console.
*
* @param msg, Indicates the log information to print.
*/
void Print(const std::string &msg);
/**
* Saves ability properties when ability is started and notify monitors of state changes.
*
* @param ability, Indicates the ability properties.
*/
void PostPerformStart(const std::shared_ptr<ADelegatorAbilityProperty> &ability);
/**
* Saves ability properties when scence is created and notify monitors of state changes.
*
* @param ability, Indicates the ability properties.
*/
void PostPerformScenceCreated(const std::shared_ptr<ADelegatorAbilityProperty> &ability);
/**
* Saves ability properties when scence is restored and notify monitors of state changes.
*
* @param ability, Indicates the ability properties.
*/
void PostPerformScenceRestored(const std::shared_ptr<ADelegatorAbilityProperty> &ability);
/**
* Saves ability properties when scence is destroyed and notify monitors of state changes.
*
* @param ability, Indicates the ability properties.
*/
void PostPerformScenceDestroyed(const std::shared_ptr<ADelegatorAbilityProperty> &ability);
/**
* Saves ability properties when ability is in the foreground and notify monitors of state changes.
*
* @param ability, Indicates the ability properties.
*/
void PostPerformForeground(const std::shared_ptr<ADelegatorAbilityProperty> &ability);
/**
* Saves ability properties when ability is in the background and notify monitors of state changes.
*
* @param ability, Indicates the ability properties.
*/
void PostPerformBackground(const std::shared_ptr<ADelegatorAbilityProperty> &ability);
/**
* Saves ability properties when ability is stopped and notify monitors of state changes.
*
* @param ability, Indicates the ability properties.
*/
void PostPerformStop(const std::shared_ptr<ADelegatorAbilityProperty> &ability);
/**
* Finishes user test.
*
* @param msg, Indicates the status information.
* @param resultCode, Indicates the result code.
*/
void FinishUserTest(const std::string &msg, const int32_t resultCode);
/**
* Registers a function for cleanup.
*
* @param func, Indicates the cleanup function, called when the ability is stopped.
*/
void RegisterClearFunc(ClearFunc func);
private:
AbilityDelegator::AbilityState ConvertAbilityState(const AbilityLifecycleExecutor::LifecycleState lifecycleState);
void ProcessAbilityProperties(const std::shared_ptr<ADelegatorAbilityProperty> &ability);
std::shared_ptr<ADelegatorAbilityProperty> DoesPropertyExist(const sptr<IRemoteObject> &token);
void RemoveAbilityProperty(const std::shared_ptr<ADelegatorAbilityProperty> &ability);
std::shared_ptr<ADelegatorAbilityProperty> FindPropertyByToken(const sptr<IRemoteObject> &token);
inline void CallClearFunc(const std::shared_ptr<ADelegatorAbilityProperty> &ability);
private:
std::shared_ptr<AbilityRuntime::Context> appContext_;
@ -102,6 +289,8 @@ private:
std::list<std::shared_ptr<ADelegatorAbilityProperty>> abilityProperties_;
std::vector<std::shared_ptr<IAbilityMonitor>> abilityMonitors_;
ClearFunc clearFunc_;
std::mutex mutexMonitor_;
std::mutex mutexAbilityProperties_;
};

View File

@ -25,28 +25,93 @@ namespace OHOS {
namespace AppExecFwk {
class AbilityDelegatorArgs {
public:
/**
* Indicates the key of test bundle name.
*/
static const std::string KEY_TEST_BUNDLE_NAME;
/**
* Indicates the key of test package name.
*/
static const std::string KEY_TEST_PACKAGE_NAME;
/**
* Indicates the key of test module name.
*/
static const std::string KEY_TEST_MODULE_NAME;
/**
* Indicates the key of test runner class name.
*/
static const std::string KEY_TEST_RUNNER_CLASS;
/**
* Indicates the key of test case name.
*/
static const std::string KEY_TEST_CASE;
/**
* Indicates the key of test wait timeout.
*/
static const std::string KEY_TEST_WAIT_TIMEOUT;
public:
/**
* Default constructor used to create a AbilityDelegatorArgs instance.
*/
AbilityDelegatorArgs();
/**
* A constructor used to create a AbilityDelegatorArgs instance with the input parameter passed.
*
* @param want Indicates the Want that contains parameters.
*/
explicit AbilityDelegatorArgs(const AAFwk::Want &want);
/**
* Default deconstructor used to deconstruct.
*/
~AbilityDelegatorArgs();
void SetTestBundleName(const std::string &bundleName);
/**
* Obtains the bundle name of the application being tested.
*
* @return the application bundle name.
*/
std::string GetTestBundleName() const;
/**
* Obtains the package name of the application being tested.
*
* @return the application package name.
*/
std::string GetTestPackageName() const;
/**
* Obtains the module name of the application being tested.
*
* @return the application module name.
*/
std::string GetTestModuleName() const;
/**
* Obtains the class name of the test runner used to execute test cases.
*
* @return the class name of the test runner.
*/
std::string GetTestRunnerClassName() const;
/**
* Obtains the test cases name.
*
* @return the test cases name.
*/
std::string GetTestCaseName() const;
void SetTestParam(const std::map<std::string, std::string> &params);
/**
* Obtains the test parameters.
*
* @return the test parameters.
*/
std::map<std::string, std::string> GetTestParam() const;
private:

View File

@ -20,12 +20,19 @@
#include "ability_lifecycle_executor.h"
#include "iremote_object.h"
class NativeReference;
namespace OHOS {
namespace AppExecFwk {
struct ADelegatorAbilityProperty {
// token of ability
sptr<IRemoteObject> token_;
// name of ability
std::string name_;
// lifecycle state of ability
AbilityLifecycleExecutor::LifecycleState lifecycleState_ {AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED};
// ability object in jsruntime
std::weak_ptr<NativeReference> object_;
};
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -24,8 +24,27 @@ namespace OHOS {
namespace AppExecFwk {
class AbilityDelegatorRegistry {
public:
/**
* Obtains the AbilityDelegator object of the application.
*
* @return the AbilityDelegator object initialized when the application is started.
*/
static std::shared_ptr<AbilityDelegator> GetAbilityDelegator();
/**
* Obtains test parameters stored in the AbilityDelegatorArgs object.
*
* @return the previously registered AbilityDelegatorArgs object.
*/
static std::shared_ptr<AbilityDelegatorArgs> GetArguments();
/**
* Registers the instances of AbilityDelegator and AbilityDelegatorArgs as globally unique instances.
* This method is called during application startup to initialize the test environment.
*
* @param delegator, Indicates the AbilityDelegator object.
* @param args, Indicates the AbilityDelegatorArgs object.
*/
static void RegisterInstance(
const std::shared_ptr<AbilityDelegator> &delegator, const std::shared_ptr<AbilityDelegatorArgs> &args);

View File

@ -26,13 +26,37 @@ namespace OHOS {
namespace AppExecFwk {
class DelegatorThread {
public:
/**
* Definition of thread task.
*/
using DTask = std::function<void()>;
public:
/**
* A constructor used to create a DelegatorThread instance with the input parameter passed.
*
* @param isMain Indicates whether to use main thread.
*/
explicit DelegatorThread(bool isMain = false);
/**
* Default deconstructor used to deconstruct.
*/
~DelegatorThread() = default;
/**
* Runs specified task.
*
* @param task, Indicates the specified task.
* @return true if succeed, false otherwise.
*/
bool Run(const DTask &task);
/**
* Obtains the name of the thread.
*
* @return the name of the thread.
*/
std::string GetThreadName() const;
private:

View File

@ -27,24 +27,89 @@ namespace OHOS {
namespace AppExecFwk {
class IAbilityMonitor {
public:
/**
* Indicates that the default timeout is 5 seconds.
*/
static constexpr int64_t MAX_TIME_OUT {5000};
public:
/**
* A constructor used to create a IAbilityMonitor instance with the input parameter passed.
*
* @param abilityName Indicates the specified ability name for monitoring the lifecycle state changes
* of the ability.
*/
explicit IAbilityMonitor(const std::string &abilityName);
/**
* Default deconstructor used to deconstruct.
*/
virtual ~IAbilityMonitor() = default;
/**
* Match the monitored Ability objects when newAbility objects are started or
* the lifecycle states of monitored abilities have changed.
*
* @param ability Indicates the ability.
* @param isNotify Indicates whether to notify the matched ability to the object who waited.
* @return true if match is successful; returns false otherwise.
*/
virtual bool Match(const std::shared_ptr<ADelegatorAbilityProperty> &ability, bool isNotify = false);
/**
* Waits for and returns the started Ability object that matches the conditions specified in this monitor
* within 5 seconds.
* The current thread will be blocked until the 5-second default timer expires.
*
* @return the Ability object if any object has started is matched within 5 seconds; returns null otherwise.
*/
virtual std::shared_ptr<ADelegatorAbilityProperty> WaitForAbility();
/**
* Waits for and returns the started Ability object that matches the conditions specified in this monitor
* within the specified time.
* The current thread will be blocked until the timer specified by timeoutMillisecond expires.
*
* @param timeoutMs Indicates the maximum amount of time to wait, in milliseconds.
* The value must be a positive integer.
* @return the Ability object if any object has started is matched within the specified time;
* returns null otherwise.
*/
virtual std::shared_ptr<ADelegatorAbilityProperty> WaitForAbility(const int64_t timeoutMs);
/**
* Called when ability is started.
*/
virtual void OnAbilityStart();
/**
* Called when ability is in foreground.
*/
virtual void OnAbilityForeground();
/**
* Called when ability is in background.
*/
virtual void OnAbilityBackground();
/**
* Called when ability is stopped.
*/
virtual void OnAbilityStop();
/**
* Called when window stage is created.
*/
virtual void OnWindowStageCreate();
/**
* Called when window stage is restored.
*/
virtual void OnWindowStageRestore();
/**
* Called when window stage is destroyed.
*/
virtual void OnWindowStageDestroy();
private:

View File

@ -30,12 +30,30 @@ using namespace AbilityRuntime;
class JsTestRunner : public TestRunner {
public:
/**
* Creates a TestRunner instance with the input parameter passed.
*
* @param runtime Indicates the ability runtime.
* @param args Indicates the AbilityDelegatorArgs object.
* @param bundleInfo Indicates the bundle info.
* @return the TestRunner object if JsTestRunner object is created successfully; returns null otherwise.
*/
static std::unique_ptr<TestRunner> Create(const std::unique_ptr<Runtime> &runtime,
const std::shared_ptr<AbilityDelegatorArgs> &args, const AppExecFwk::BundleInfo &bundleInfo);
/**
* Default deconstructor used to deconstruct.
*/
~JsTestRunner() override;
/**
* Prepares the testing environment for running test code.
*/
void Prepare() override;
/**
* Runs all test code.
*/
void Run() override;
private:

View File

@ -23,17 +23,64 @@ namespace OHOS {
namespace AppExecFwk {
class ShellCmdResult {
public:
/**
* Default constructor used to create a ShellCmdResult instance.
*/
ShellCmdResult() = default;
/**
* A constructor used to create a ShellCmdResult instance with the input parameter passed.
*
* @param exitCode Indicates the shell cmd exec result.
* @param stdResult Indicates the cmd standard result.
*/
ShellCmdResult(const int32_t exitCode, const std::string &stdResult);
/**
* Copy constructor used to create a ShellCmdResult instance with the input parameter passed.
*
* @param result Indicates the ShellCommandResult object that already exists.
*/
ShellCmdResult(const AAFwk::ShellCommandResult &result);
/**
* Default deconstructor used to deconstruct.
*/
~ShellCmdResult() = default;
/**
* Sets exit code.
*
* @param exitCode Indicates the exit code.
*/
void SetExitCode(const int32_t exitCode);
/**
* Obtains the exit code.
*
* @return the exit code.
*/
int32_t GetExitCode() const;
/**
* Sets standard result.
*
* @param stdResult Indicates the standard result.
*/
void SetStdResult(const std::string &stdResult);
/**
* Obtains the standard result.
*
* @return the standard result.
*/
std::string GetStdResult() const;
/**
* Returns a string representation of the object.
*
* @return a string representation of the object.
*/
std::string Dump();
private:

View File

@ -27,13 +27,34 @@ class Runtime;
namespace AppExecFwk {
class TestRunner {
public:
/**
* Creates a TestRunner instance with the input parameter passed.
*
* @param runtime Indicates the ability runtime.
* @param args Indicates the AbilityDelegatorArgs object.
* @return the TestRunner object if TestRunner object is created successfully; returns null otherwise.
*/
static std::unique_ptr<TestRunner> Create(
const std::unique_ptr<AbilityRuntime::Runtime> &runtime, const std::shared_ptr<AbilityDelegatorArgs> &args);
/**
* Default constructor used to create a TestRunner instance.
*/
TestRunner() = default;
/**
* Default deconstructor used to deconstruct.
*/
virtual ~TestRunner() = default;
/**
* Prepares the testing environment for running test code.
*/
virtual void Prepare();
/**
* Runs all test code.
*/
virtual void Run();
};
} // namespace AppExecFwk

View File

@ -74,7 +74,8 @@ size_t AbilityDelegator::GetMonitorsNum()
return abilityMonitors_.size();
}
sptr<IRemoteObject> AbilityDelegator::WaitAbilityMonitor(const std::shared_ptr<IAbilityMonitor> &monitor)
std::shared_ptr<ADelegatorAbilityProperty> AbilityDelegator::WaitAbilityMonitor(
const std::shared_ptr<IAbilityMonitor> &monitor)
{
if (!monitor) {
HILOG_WARN("Invalid input parameter");
@ -89,10 +90,10 @@ sptr<IRemoteObject> AbilityDelegator::WaitAbilityMonitor(const std::shared_ptr<I
return {};
}
return obtainedAbility->token_;
return obtainedAbility;
}
sptr<IRemoteObject> AbilityDelegator::WaitAbilityMonitor(
std::shared_ptr<ADelegatorAbilityProperty> AbilityDelegator::WaitAbilityMonitor(
const std::shared_ptr<IAbilityMonitor> &monitor, const int64_t timeoutMs)
{
if (!monitor) {
@ -108,7 +109,7 @@ sptr<IRemoteObject> AbilityDelegator::WaitAbilityMonitor(
return {};
}
return obtainedAbility->token_;
return obtainedAbility;
}
std::shared_ptr<AbilityRuntime::Context> AbilityDelegator::GetAppContext() const
@ -124,7 +125,7 @@ AbilityDelegator::AbilityState AbilityDelegator::GetAbilityState(const sptr<IRem
}
std::unique_lock<std::mutex> lck(mutexAbilityProperties_);
auto existedProperty = DoesPropertyExist(token);
auto existedProperty = FindPropertyByToken(token);
if (!existedProperty) {
HILOG_WARN("Unknown ability token");
return AbilityDelegator::AbilityState::UNINITIALIZED;
@ -133,7 +134,7 @@ AbilityDelegator::AbilityState AbilityDelegator::GetAbilityState(const sptr<IRem
return ConvertAbilityState(existedProperty->lifecycleState_);
}
sptr<IRemoteObject> AbilityDelegator::GetCurrentTopAbility()
std::shared_ptr<ADelegatorAbilityProperty> AbilityDelegator::GetCurrentTopAbility()
{
sptr<IRemoteObject> topAbilityToken;
if (AAFwk::AbilityManagerClient::GetInstance()->GetCurrentTopAbility(topAbilityToken)) {
@ -141,7 +142,14 @@ sptr<IRemoteObject> AbilityDelegator::GetCurrentTopAbility()
return {};
}
return topAbilityToken;
std::unique_lock<std::mutex> lck(mutexAbilityProperties_);
auto existedProperty = FindPropertyByToken(topAbilityToken);
if (!existedProperty) {
HILOG_WARN("Unknown ability token");
return {};
}
return existedProperty;
}
std::string AbilityDelegator::GetThreadName() const
@ -455,6 +463,9 @@ void AbilityDelegator::PostPerformStop(const std::shared_ptr<ADelegatorAbilityPr
monitor->OnAbilityStop();
}
}
RemoveAbilityProperty(ability);
CallClearFunc(ability);
}
AbilityDelegator::AbilityState AbilityDelegator::ConvertAbilityState(
@ -495,7 +506,7 @@ void AbilityDelegator::ProcessAbilityProperties(const std::shared_ptr<ADelegator
ability->name_.data(), ability->lifecycleState_);
std::unique_lock<std::mutex> lck(mutexAbilityProperties_);
auto existedProperty = DoesPropertyExist(ability->token_);
auto existedProperty = FindPropertyByToken(ability->token_);
if (existedProperty) {
// update
existedProperty->lifecycleState_ = ability->lifecycleState_;
@ -505,7 +516,23 @@ void AbilityDelegator::ProcessAbilityProperties(const std::shared_ptr<ADelegator
abilityProperties_.emplace_back(ability);
}
std::shared_ptr<ADelegatorAbilityProperty> AbilityDelegator::DoesPropertyExist(const sptr<IRemoteObject> &token)
void AbilityDelegator::RemoveAbilityProperty(const std::shared_ptr<ADelegatorAbilityProperty> &ability)
{
HILOG_INFO("Enter");
if (!ability) {
HILOG_WARN("Invalid ability property");
return;
}
HILOG_INFO("ability property { name : %{public}s, state : %{public}d }",
ability->name_.data(), ability->lifecycleState_);
std::unique_lock<std::mutex> lck(mutexAbilityProperties_);
abilityProperties_.remove(ability);
}
std::shared_ptr<ADelegatorAbilityProperty> AbilityDelegator::FindPropertyByToken(const sptr<IRemoteObject> &token)
{
HILOG_INFO("Enter");
@ -547,7 +574,26 @@ void AbilityDelegator::FinishUserTest(const std::string &msg, const int32_t resu
const auto &bundleName = delegatorArgs->GetTestBundleName();
auto err = AAFwk::AbilityManagerClient::GetInstance()->FinishUserTest(msg, resultCode, bundleName);
if (err) {
HILOG_ERROR("MainThread::FinishUserTest is failed %{public}d", err);
HILOG_ERROR("FinishUserTest is failed %{public}d", err);
}
}
void AbilityDelegator::RegisterClearFunc(ClearFunc func)
{
HILOG_INFO("Enter");
if (!func) {
HILOG_ERROR("Invalid func");
return;
}
clearFunc_ = func;
}
inline void AbilityDelegator::CallClearFunc(const std::shared_ptr<ADelegatorAbilityProperty> &ability)
{
HILOG_INFO("Enter");
if (clearFunc_) {
clearFunc_(ability);
}
}
} // namespace AppExecFwk

View File

@ -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(&parameters_)) {
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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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",

View File

@ -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)));

View File

@ -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));
}

View File

@ -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 = []

View File

@ -434,8 +434,16 @@ HWTEST_F(PendingWantTest, PendingWant_1800, Function | MediumTest | Level1)
*/
HWTEST_F(PendingWantTest, PendingWant_1900, Function | MediumTest | Level1)
{
sptr<AAFwk::IWantSender> target(new (std::nothrow) WantSender());
std::shared_ptr<PendingWant> pendingWant = std::make_shared<PendingWant>(target);
int requestCode = 10;
std::shared_ptr<Want> want = std::make_shared<Want>();
ElementName element("device", "bundleName", "abilityName");
want->SetElement(element);
unsigned int flags = 1;
flags |= FLAG_NO_CREATE;
WantAgentConstant::OperationType type = WantAgentConstant::OperationType::START_FOREGROUND_SERVICE;
std::shared_ptr<PendingWant> pendingWant =
PendingWant::BuildServicePendingWant(nullptr, requestCode, want, flags, type);
sptr<AAFwk::IWantSender> target2(nullptr);
std::shared_ptr<PendingWant> pendingWant2 = std::make_shared<PendingWant>(target2);
EXPECT_EQ(pendingWant->Equals(pendingWant, pendingWant2), false);
@ -477,19 +485,6 @@ HWTEST_F(PendingWantTest, PendingWant_2100, Function | MediumTest | Level1)
pendingWant.SendAndReturnResult(requestCode, want, nullptr, "Permission", nullptr, nullptr));
}
/*
* @tc.number : PendingWant_2300
* @tc.name : PendingWant Equals
* @tc.desc : Equals
*/
HWTEST_F(PendingWantTest, PendingWant_2300, Function | MediumTest | Level1)
{
sptr<AAFwk::IWantSender> target(new (std::nothrow) WantSender());
std::shared_ptr<PendingWant> pendingWant = std::make_shared<PendingWant>(target);
std::shared_ptr<PendingWant> pendingWant2 = std::make_shared<PendingWant>(target);
EXPECT_EQ(pendingWant->Equals(pendingWant, pendingWant2), true);
}
/*
* @tc.number : PendingWant_2400
* @tc.name : PendingWant GetTarget

View File

@ -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",
]

View File

@ -96,7 +96,6 @@ ohos_shared_library("ability_manager") {
]
deps = [
"${appexecfwk_path}/common:libappexecfwk_common",
"${kits_path}/ability/native:dummy_classes",
"//third_party/jsoncpp:jsoncpp",
]

View File

@ -80,7 +80,7 @@ ohos_shared_library("app_manager") {
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [ "${appexecfwk_path}/common:libappexecfwk_common" ]
deps = []
external_deps = [
"ability_base:base",

View File

@ -289,23 +289,20 @@ int32_t AppMgrStub::HandleGetForegroundApplications(MessageParcel &data, Message
int32_t AppMgrStub::HandleStartUserTestProcess(MessageParcel &data, MessageParcel &reply)
{
AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
if (want == nullptr) {
HILOG_ERROR("want is nullptr");
return ERR_INVALID_VALUE;
}
BundleInfo *bundleInfo = data.ReadParcelable<BundleInfo>();
std::unique_ptr<BundleInfo> bundleInfo(data.ReadParcelable<BundleInfo>());
if (bundleInfo == nullptr) {
HILOG_ERROR("want is nullptr");
delete want;
return ERR_INVALID_VALUE;
}
auto observer = data.ReadRemoteObject();
int32_t userId = data.ReadInt32();
int32_t result = StartUserTestProcess(*want, observer, *bundleInfo, userId);
reply.WriteInt32(result);
delete want;
delete bundleInfo;
return result;
}

View File

@ -19,7 +19,7 @@
#include "nlohmann/json.hpp"
#include "string_ex.h"
#include "parcel_macro.h"
#include "parcel_macro_ability.h"
namespace OHOS {
namespace AppExecFwk {

View File

@ -19,7 +19,7 @@
#include "string_ex.h"
#include "hilog_wrapper.h"
#include "parcel_macro.h"
#include "parcel_macro_ability.h"
namespace OHOS {
namespace AppExecFwk {

View File

@ -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"
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -29,15 +29,52 @@ namespace AbilityDelegatorJs {
using namespace OHOS::AppExecFwk;
class AbilityMonitor : public IAbilityMonitor {
public:
/**
* A constructor used to create a AbilityMonitor instance with the input parameter passed.
*
* @param name Indicates the specified ability name.
* @param jsAbilityMonitor Indicates the JSAbilityMonitor object.
*/
AbilityMonitor(const std::string &name, const std::shared_ptr<JSAbilityMonitor> &jsAbilityMonitor);
/**
* Default deconstructor used to deconstruct.
*/
~AbilityMonitor() = default;
/**
* Called when ability is started.
*/
void OnAbilityStart() override;
/**
* Called when ability is in foreground.
*/
void OnAbilityForeground() override;
/**
* Called when ability is in background.
*/
void OnAbilityBackground() override;
/**
* Called when ability is stopped.
*/
void OnAbilityStop() override;
/**
* Called when window stage is created.
*/
void OnWindowStageCreate() override;
/**
* Called when window stage is restored.
*/
void OnWindowStageRestore() override;
/**
* Called when window stage is destroyed.
*/
void OnWindowStageDestroy() override;
private:

View File

@ -15,6 +15,7 @@
#include "js_ability_delegator.h"
#include <mutex>
#include "ability_delegator_registry.h"
#include "ability_runtime/js_ability.h"
#include "hilog_wrapper.h"
@ -27,8 +28,8 @@
namespace OHOS {
namespace AbilityDelegatorJs {
struct AbilityTokenBox {
sptr<IRemoteObject> token_;
struct AbilityObjectBox {
std::weak_ptr<NativeReference> object_;
};
struct ShellCmdResultBox {
@ -44,7 +45,33 @@ constexpr int ERROR = -1;
using namespace OHOS::AbilityRuntime;
std::map<std::shared_ptr<NativeReference>, std::shared_ptr<AbilityMonitor>> monitorRecord_;
std::map<std::shared_ptr<NativeReference>, sptr<IRemoteObject>> ablityRecord_;
std::map<std::weak_ptr<NativeReference>, sptr<IRemoteObject>, std::owner_less<>> ablityRecord_;
std::mutex mutexAblityRecord_;
JSAbilityDelegator::JSAbilityDelegator()
{
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
if (delegator) {
auto clearFunc = [](const std::shared_ptr<ADelegatorAbilityProperty> &property) {
HILOG_INFO("Clear function is called");
if (!property) {
HILOG_ERROR("Invalid property");
return;
}
std::unique_lock<std::mutex> lck(mutexAblityRecord_);
for (auto it = ablityRecord_.begin(); it != ablityRecord_.end();) {
if (it->second == property->token_) {
it = ablityRecord_.erase(it);
continue;
}
++it;
}
};
delegator->RegisterClearFunc(clearFunc);
}
}
void JSAbilityDelegator::Finalizer(NativeEngine *engine, void *data, void *hint)
{
@ -203,38 +230,50 @@ NativeValue *JSAbilityDelegator::OnWaitAbilityMonitor(NativeEngine &engine, Nati
return engine.CreateUndefined();
}
auto abilityTokenBox = std::make_shared<AbilityTokenBox>();
AsyncTask::ExecuteCallback execute = [monitor, timeout, opt, abilityTokenBox]() {
auto abilityObjectBox = std::make_shared<AbilityObjectBox>();
AsyncTask::ExecuteCallback execute = [monitor, timeout, opt, abilityObjectBox]() {
HILOG_INFO("OnWaitAbilityMonitor AsyncTask ExecuteCallback is called");
if (!abilityObjectBox) {
HILOG_ERROR("OnWaitAbilityMonitor AsyncTask ExecuteCallback, Invalid abilityObjectBox");
return;
}
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
if (!delegator) {
HILOG_ERROR("OnWaitAbilityMonitor AsyncTask ExecuteCallback, Invalid delegator");
return;
}
std::shared_ptr<ADelegatorAbilityProperty> property;
if (opt.hasTimeoutPara) {
abilityTokenBox->token_ = delegator->WaitAbilityMonitor(monitor, timeout);
property = delegator->WaitAbilityMonitor(monitor, timeout);
} else {
abilityTokenBox->token_ = delegator->WaitAbilityMonitor(monitor);
property = delegator->WaitAbilityMonitor(monitor);
}
if (!property || property->object_.expired()) {
HILOG_ERROR("Invalid property");
return;
}
abilityObjectBox->object_ = property->object_;
std::unique_lock<std::mutex> lck(mutexAblityRecord_);
ablityRecord_.emplace(property->object_, property->token_);
};
AsyncTask::CompleteCallback complete =
[abilityTokenBox, this](NativeEngine &engine, AsyncTask &task, int32_t status) {
HILOG_INFO("OnWaitAbilityMonitor AsyncTask CompleteCallback is called");
NativeValue *ability = CreateAbilityObject(engine, abilityTokenBox->token_);
if (ability) {
task.Resolve(engine, ability);
} else {
task.Reject(engine, CreateJsError(engine, ERROR, "waitAbilityMonitor failed."));
}
};
AsyncTask::CompleteCallback complete = [abilityObjectBox](NativeEngine &engine, AsyncTask &task, int32_t status) {
HILOG_INFO("OnWaitAbilityMonitor AsyncTask CompleteCallback is called");
if (abilityObjectBox && !abilityObjectBox->object_.expired()) {
task.Resolve(engine, abilityObjectBox->object_.lock()->Get());
} else {
task.Reject(engine, CreateJsError(engine, ERROR, "waitAbilityMonitor failed."));
}
};
NativeValue *lastParam = nullptr;
if (opt.hasCallbackPara) {
lastParam = opt.hasTimeoutPara ? info.argv[INDEX_TWO] : info.argv[INDEX_ONE];
} else {
lastParam = nullptr;
}
NativeValue *result = nullptr;
@ -286,6 +325,11 @@ NativeValue *JSAbilityDelegator::OnExecuteShellCommand(NativeEngine &engine, Nat
auto shellCmdResultBox = std::make_shared<ShellCmdResultBox>();
AsyncTask::ExecuteCallback execute = [cmd, timeoutSecs, shellCmdResultBox]() {
HILOG_INFO("OnExecuteShellCommand AsyncTask ExecuteCallback is called");
if (!shellCmdResultBox) {
HILOG_ERROR("OnExecuteShellCommand AsyncTask ExecuteCallback, Invalid shellCmdResultBox");
return;
}
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
if (!delegator) {
HILOG_ERROR("OnExecuteShellCommand AsyncTask ExecuteCallback, Invalid delegator");
@ -297,6 +341,12 @@ NativeValue *JSAbilityDelegator::OnExecuteShellCommand(NativeEngine &engine, Nat
AsyncTask::CompleteCallback complete = [shellCmdResultBox](NativeEngine &engine, AsyncTask &task, int32_t status) {
HILOG_INFO("OnExecuteShellCommand AsyncTask CompleteCallback is called");
if (!shellCmdResultBox) {
HILOG_ERROR("OnExecuteShellCommand AsyncTask CompleteCallback, Invalid shellCmdResultBox");
task.Reject(engine, CreateJsError(engine, ERROR, "executeShellCommand failed."));
return;
}
NativeValue *result = CreateJsShellCmdResult(engine, shellCmdResultBox->shellCmdResult_);
if (result) {
task.Resolve(engine, result);
@ -308,8 +358,6 @@ NativeValue *JSAbilityDelegator::OnExecuteShellCommand(NativeEngine &engine, Nat
NativeValue *lastParam = nullptr;
if (opt.hasCallbackPara) {
lastParam = opt.hasTimeoutPara ? info.argv[INDEX_TWO] : info.argv[INDEX_ONE];
} else {
lastParam = nullptr;
}
NativeValue *result = nullptr;
@ -376,15 +424,21 @@ NativeValue *JSAbilityDelegator::OnGetCurrentTopAbility(NativeEngine &engine, Na
HILOG_INFO("OnGetCurrentTopAbility AsyncTask is called");
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
if (!delegator) {
HILOG_ERROR("Invalid delegator");
task.Reject(engine, CreateJsError(engine, ERROR, "getCurrentTopAbility failed."));
return;
}
sptr<IRemoteObject> remoteObject = delegator->GetCurrentTopAbility();
NativeValue *ability = CreateAbilityObject(engine, remoteObject);
if (ability) {
task.Resolve(engine, ability);
} else {
auto property = delegator->GetCurrentTopAbility();
if (!property || property->object_.expired()) {
HILOG_ERROR("Invalid property");
task.Reject(engine, CreateJsError(engine, ERROR, "getCurrentTopAbility failed."));
} else {
{
std::unique_lock<std::mutex> lck(mutexAblityRecord_);
ablityRecord_.emplace(property->object_, property->token_);
}
task.Resolve(engine, property->object_.lock()->Get());
}
};
@ -562,12 +616,20 @@ NativeValue *JSAbilityDelegator::ParseAbilityPara(
{
HILOG_INFO("enter");
for (auto iter = ablityRecord_.begin(); iter != ablityRecord_.end(); ++iter) {
if (value->StrictEquals(iter->first->Get())) {
std::unique_lock<std::mutex> lck(mutexAblityRecord_);
for (auto iter = ablityRecord_.begin(); iter != ablityRecord_.end();) {
if (iter->first.expired()) {
iter = ablityRecord_.erase(iter);
continue;
}
if (value->StrictEquals(iter->first.lock()->Get())) {
remoteObject = iter->second;
HILOG_INFO("Ablity exist");
return remoteObject ? engine.CreateNull() : nullptr;
}
++iter;
}
HILOG_ERROR("Ablity doesn't exist");
@ -592,6 +654,8 @@ NativeValue *JSAbilityDelegator::CreateAbilityObject(NativeEngine &engine, const
std::shared_ptr<NativeReference> refence = nullptr;
refence.reset(engine.CreateReference(objValue, 1));
std::unique_lock<std::mutex> lck(mutexAblityRecord_);
ablityRecord_[refence] = remoteObject;
return objValue;
}

View File

@ -31,22 +31,132 @@ public:
bool hasTimeoutPara;
bool hasCallbackPara;
};
JSAbilityDelegator() = default;
/**
* Default constructor used to create a JSAbilityDelegator instance.
*/
JSAbilityDelegator();
/**
* Default deconstructor used to deconstruct.
*/
~JSAbilityDelegator() = default;
/**
* Destory object.
*
* @param engine Indicates the native engine.
* @param data Indicates the object to be destroyed.
* @param hint Indicates the hint.
*/
static void Finalizer(NativeEngine *engine, void *data, void *hint);
/**
* Adds ability monitor.
*
* @param engine Indicates the native engine.
* @param info Indicates the parameters from js.
* @return exec result.
*/
static NativeValue *AddAbilityMonitor(NativeEngine *engine, NativeCallbackInfo *info);
/**
* Removes ability monitor.
*
* @param engine Indicates the native engine.
* @param info Indicates the parameters from js.
* @return exec result.
*/
static NativeValue *RemoveAbilityMonitor(NativeEngine *engine, NativeCallbackInfo *info);
/**
* Waits for the specified monitor.
*
* @param engine Indicates the native engine.
* @param info Indicates the parameters from js.
* @return exec result.
*/
static NativeValue *WaitAbilityMonitor(NativeEngine *engine, NativeCallbackInfo *info);
/**
* Prints log information to the console.
*
* @param engine Indicates the native engine.
* @param info Indicates the parameters from js.
* @return exec result.
*/
static NativeValue *Print(NativeEngine *engine, NativeCallbackInfo *info);
/**
* Execute the specified shell command.
*
* @param engine Indicates the native engine.
* @param info Indicates the parameters from js.
* @return exec result.
*/
static NativeValue *ExecuteShellCommand(NativeEngine *engine, NativeCallbackInfo *info);
/**
* Obtains the application context.
*
* @param engine Indicates the native engine.
* @param info Indicates the parameters from js.
* @return exec result.
*/
static NativeValue *GetAppContext(NativeEngine *engine, NativeCallbackInfo *info);
/**
* Obtains the lifecycle state of the specified ability.
*
* @param engine Indicates the native engine.
* @param info Indicates the parameters from js.
* @return exec result.
*/
static NativeValue *GetAbilityState(NativeEngine *engine, NativeCallbackInfo *info);
/**
* Obtains the ability that is currently being displayed.
*
* @param engine Indicates the native engine.
* @param info Indicates the parameters from js.
* @return exec result.
*/
static NativeValue *GetCurrentTopAbility(NativeEngine *engine, NativeCallbackInfo *info);
/**
* Starts an ability based on the given parameters.
*
* @param engine Indicates the native engine.
* @param info Indicates the parameters from js.
* @return exec result.
*/
static NativeValue *StartAbility(NativeEngine *engine, NativeCallbackInfo *info);
/**
* Transits the specified ability to foreground.
*
* @param engine Indicates the native engine.
* @param info Indicates the parameters from js.
* @return exec result.
*/
static NativeValue *DoAbilityForeground(NativeEngine *engine, NativeCallbackInfo *info);
/**
* Transits the specified ability to background.
*
* @param engine Indicates the native engine.
* @param info Indicates the parameters from js.
* @return exec result.
*/
static NativeValue *DoAbilityBackground(NativeEngine *engine, NativeCallbackInfo *info);
/**
* Finishes user test.
*
* @param engine Indicates the native engine.
* @param info Indicates the parameters from js.
* @return exec result.
*/
static NativeValue *FinishTest(NativeEngine *engine, NativeCallbackInfo *info);
private:

View File

@ -15,6 +15,7 @@
#include "js_ability_delegator_registry.h"
#include <memory>
#include "ability_delegator.h"
#include "ability_delegator_registry.h"
#include "hilog_wrapper.h"
@ -57,7 +58,14 @@ private:
HILOG_ERROR("Failed to get delegator object");
return engine.CreateNull();
}
return CreateJsAbilityDelegator(engine);
static std::unique_ptr<NativeReference> reference;
if (!reference) {
auto value = CreateJsAbilityDelegator(engine);
reference.reset(engine.CreateReference(value, 1));
}
return reference->Get();
}
NativeValue *OnGetArguments(NativeEngine &engine, NativeCallbackInfo &info)

View File

@ -21,10 +21,25 @@
namespace OHOS {
namespace AbilityDelegatorJs {
enum class AbilityLifecycleState {
/**
* Indicates that the ability has not been initialized.
*/
UNINITIALIZED,
/**
* Indicates that the ability is in the created state.
*/
CREATE,
/**
* Indicates that the ability is in the foreground state.
*/
FOREGROUND,
/**
* Indicates that the ability is in the background state.
*/
BACKGROUND,
/**
* Indicates that the ability is in the destroyed state.
*/
DESTROY,
};

View File

@ -29,22 +29,83 @@ namespace AbilityDelegatorJs {
using namespace OHOS::AppExecFwk;
class JSAbilityMonitor {
public:
/**
* A constructor used to create a JSAbilityMonitor instance with the input parameter passed.
*
* @param abilityName Indicates the specified ability name for monitoring the lifecycle state changes
* of the ability.
*/
explicit JSAbilityMonitor(const std::string &abilityName);
/**
* Default deconstructor used to deconstruct.
*/
~JSAbilityMonitor() = default;
/**
* Called when ability is started.
* Then call the corresponding method on the js side through the saved js object.
*/
void onAbilityCreate();
/**
* Called when ability is in foreground.
* Then call the corresponding method on the js side through the saved js object.
*/
void onAbilityForeground();
/**
* Called when ability is in background.
* Then call the corresponding method on the js side through the saved js object.
*/
void onAbilityBackground();
/**
* Called when ability is stopped.
* Then call the corresponding method on the js side through the saved js object.
*/
void onAbilityDestroy();
/**
* Called when window stage is created.
* Then call the corresponding method on the js side through the saved js object.
*/
void onWindowStageCreate();
/**
* Called when window stage is restored.
* Then call the corresponding method on the js side through the saved js object.
*/
void onWindowStageRestore();
/**
* Called when window stage is destroyed.
* Then call the corresponding method on the js side through the saved js object.
*/
void onWindowStageDestroy();
/**
* Sets the js object.
*
* @param jsAbilityMonitor Indicates the js object.
*/
void SetJsAbilityMonitor(NativeValue *jsAbilityMonitor);
/**
* Sets the native engine.
*
* @param engine Indicates the native engine.
*/
void SetJsAbilityMonitorEnv(NativeEngine *engine)
{
engine_ = engine;
}
/**
* Obtains the saved js object.
*
* @return the saved js object.
*/
std::unique_ptr<NativeReference> &GetJsAbilityMonitor()
{
return jsAbilityMonitor_;

View File

@ -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",

View File

@ -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",

View File

@ -1250,7 +1250,7 @@ int AbilityManagerStub::IsRunningInStabilityTestInner(MessageParcel &data, Messa
int AbilityManagerStub::StartUserTestInner(MessageParcel &data, MessageParcel &reply)
{
Want *want = data.ReadParcelable<Want>();
std::unique_ptr<Want> want(data.ReadParcelable<Want>());
if (want == nullptr) {
HILOG_ERROR("want is nullptr");
return ERR_INVALID_VALUE;
@ -1258,7 +1258,6 @@ int AbilityManagerStub::StartUserTestInner(MessageParcel &data, MessageParcel &r
auto observer = data.ReadRemoteObject();
int32_t result = StartUserTest(*want, observer);
reply.WriteInt32(result);
delete want;
return result;
}

View File

@ -53,8 +53,6 @@ ohos_shared_library("libams") {
]
defines = [
"APP_LOG_TAG = \"AppMgrService\"",
"LOG_DOMAIN = 0xD001110",
"AMS_LOG_TAG = \"AppMgrService\"",
"AMS_LOG_DOMAIN = 0xD001110",
]
@ -65,7 +63,6 @@ ohos_shared_library("libams") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${appexecfwk_path}/common:libappexecfwk_common",
"${innerkits_path}/uri_permission:uri_permission_mgr",
"${services_path}/common:perm_verification",
]

View File

@ -2341,7 +2341,7 @@ int AppMgrServiceInner::VerifyProcessPermission()
auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission(
AAFwk::PermissionConstants::PERMISSION_CLEAN_BACKGROUND_PROCESSES);
if (isCallingPerm) {
HILOG_ERROR("%{public}s: Permission verification succeeded", __func__);
HILOG_INFO("%{public}s: Permission verification succeeded", __func__);
return ERR_OK;
}
HILOG_ERROR("%{public}s: Permission verification failed", __func__);

View File

@ -0,0 +1,42 @@
/*
* 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 PARCEL_MACRO_ABILITY_H
#define PARCEL_MACRO_ABILITY_H
#include "parcel.h"
#include "hilog_wrapper.h"
namespace OHOS {
namespace AppExecFwk {
#define READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(type, parcel, data) \
do { \
if (!(parcel).Read##type(data)) { \
HILOG_ERROR("fail to read %{public}s type from parcel", #type); \
return false; \
} \
} while (0)
#define WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(type, parcel, data) \
do { \
if (!(parcel).Write##type(data)) { \
HILOG_ERROR("fail to write %{public}s type into parcel", #type); \
return false; \
} \
} while (0)
} // namespace AppExecFwk
} // namespace OHOS
#endif // PARCEL_MACRO_ABILITY_H

View File

@ -72,8 +72,6 @@ ohos_shared_library("libfms") {
]
defines = [
"APP_LOG_TAG = \"FormMgrService\"",
"LOG_DOMAIN = 0xD001120",
"AMS_LOG_TAG = \"FormMgrService\"",
"AMS_LOG_DOMAIN = 0xD001120",
]
@ -87,7 +85,6 @@ ohos_shared_library("libfms") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${appexecfwk_path}/common:libappexecfwk_common",
"${kits_path}/appkit:app_context",
"${services_path}/common:perm_verification",

View File

@ -0,0 +1,187 @@
/*
* 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 FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_JSON_UTIL_FORM_H
#define FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_JSON_UTIL_FORM_H
#include <string>
#include "appexecfwk_errors.h"
#include "hilog_wrapper.h"
#include "json_serializer.h"
namespace OHOS {
namespace AppExecFwk {
enum class JsonType {
NULLABLE,
BOOLEAN,
NUMBER,
OBJECT,
ARRAY,
STRING,
};
enum class ArrayType {
NUMBER,
OBJECT,
STRING,
NOT_ARRAY,
};
template<typename T, typename dataType>
void CheckArrayType(
const nlohmann::json &jsonObject, const std::string &key, dataType &data, ArrayType arrayType, int32_t &parseResult)
{
auto arrays = jsonObject.at(key);
if (arrays.empty()) {
HILOG_DEBUG("array is empty");
return;
}
switch (arrayType) {
case ArrayType::STRING:
for (const auto &array : arrays) {
if (!array.is_string()) {
HILOG_ERROR("array %{public}s is not string type", key.c_str());
parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
}
}
if (parseResult == ERR_OK) {
data = jsonObject.at(key).get<T>();
}
break;
case ArrayType::OBJECT:
for (const auto &array : arrays) {
if (!array.is_object()) {
HILOG_ERROR("array %{public}s is not object type", key.c_str());
parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
break;
}
}
if (parseResult == ERR_OK) {
data = jsonObject.at(key).get<T>();
}
break;
case ArrayType::NUMBER:
for (const auto &array : arrays) {
if (!array.is_number()) {
HILOG_ERROR("array %{public}s is not number type", key.c_str());
parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
}
}
if (parseResult == ERR_OK) {
data = jsonObject.at(key).get<T>();
}
break;
case ArrayType::NOT_ARRAY:
HILOG_ERROR("array %{public}s is not string type", key.c_str());
break;
default:
HILOG_ERROR("array %{public}s type error", key.c_str());
break;
}
}
template<typename T, typename dataType>
void GetValueIfFindKey(const nlohmann::json &jsonObject, const nlohmann::detail::iter_impl<const nlohmann::json> &end,
const std::string &key, dataType &data, JsonType jsonType, bool isNecessary, int32_t &parseResult,
ArrayType arrayType)
{
if (parseResult) {
return;
}
if (jsonObject.find(key) != end) {
switch (jsonType) {
case JsonType::BOOLEAN:
if (!jsonObject.at(key).is_boolean()) {
HILOG_ERROR("type is error %{public}s is not boolean", key.c_str());
parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
break;
}
data = jsonObject.at(key).get<T>();
break;
case JsonType::NUMBER:
if (!jsonObject.at(key).is_number()) {
HILOG_ERROR("type is error %{public}s is not number", key.c_str());
parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
break;
}
data = jsonObject.at(key).get<T>();
break;
case JsonType::OBJECT:
if (!jsonObject.at(key).is_object()) {
HILOG_ERROR("type is error %{public}s is not object", key.c_str());
parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
break;
}
data = jsonObject.at(key).get<T>();
break;
case JsonType::ARRAY:
if (!jsonObject.at(key).is_array()) {
HILOG_ERROR("type is error %{public}s is not array", key.c_str());
parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
break;
}
CheckArrayType<T>(jsonObject, key, data, arrayType, parseResult);
break;
case JsonType::STRING:
if (!jsonObject.at(key).is_string()) {
HILOG_ERROR("type is error %{public}s is not string", key.c_str());
parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
break;
}
data = jsonObject.at(key).get<T>();
break;
case JsonType::NULLABLE:
HILOG_ERROR("type is error %{public}s is nullable", key.c_str());
break;
default:
HILOG_ERROR("type is error %{public}s is not jsonType", key.c_str());
parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
}
return;
}
if (isNecessary) {
HILOG_ERROR("profile prop %{public}s is mission", key.c_str());
parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP;
}
}
template<typename T>
const std::string GetJsonStrFromInfo(T &t)
{
nlohmann::json json = t;
return json.dump();
}
template<typename T>
bool ParseInfoFromJsonStr(const char *data, T &t)
{
if (data == nullptr) {
HILOG_ERROR("%{public}s faile due to data is nullptr", __func__);
return false;
}
nlohmann::json jsonObject = nlohmann::json::parse(data, nullptr, false);
if (jsonObject.is_discarded()) {
HILOG_ERROR("%{public}s faile due to data is discarded", __func__);
return false;
}
t = jsonObject.get<T>();
return true;
}
} // namespace AppExecFwk
} // namespace OHOS
#endif // FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_JSON_UTIL_FORM_H

View File

@ -15,7 +15,7 @@
#include "form_db_info.h"
#include "json_util.h"
#include "json_util_form.h"
namespace OHOS {
namespace AppExecFwk {

View File

@ -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 \\[(.+)\\].*");

View File

@ -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",
]
}
###############################################################################

View File

@ -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;
}

View File

@ -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

View File

@ -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>

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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 \\[(.+)\\].*");

View File

@ -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",

View File

@ -25,14 +25,37 @@ class ITestObserver : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.ITestObserver");
/**
* Outputs test status.
*
* @param msg, Indicates the status information.
* @param resultCode, Indicates the result code.
*/
virtual void TestStatus(const std::string &msg, const int &resultCode) = 0;
/**
* Outputs information and result code that the test has finished.
*
* @param msg, Indicates the status information.
* @param resultCode, Indicates the result code.
*/
virtual void TestFinished(const std::string &msg, const int &resultCode) = 0;
virtual ShellCommandResult ExecuteShellCommand(
const std::string &cmd, const int64_t timeoutSec) = 0;
/**
* Executes the specified shell command.
*
* @param cmd, Indicates the specified shell command.
* @param timeoutSec, Indicates the specified time out time, in seconds.
* @return the result of the specified shell command.
*/
virtual ShellCommandResult ExecuteShellCommand(const std::string &cmd, const int64_t timeoutSec) = 0;
enum class Message {
// ipc id for test status (1)
AA_TEST_STATUS = 1,
// ipc id for test finished (2)
AA_TEST_FINISHED = 2,
// ipc id for execute shell command (3)
AA_EXECUTE_SHELL_COMMAND = 3,
};
};

View File

@ -22,15 +22,47 @@ namespace OHOS {
namespace AAFwk {
class TestObserver : public TestObserverStub {
public:
/**
* Default constructor used to create a TestObserver instance.
*/
TestObserver();
/**
* Deconstructor used to deconstruct.
*/
virtual ~TestObserver() override;
/**
* Outputs test status.
*
* @param msg, Indicates the status information.
* @param resultCode, Indicates the result code.
*/
virtual void TestStatus(const std::string &msg, const int &resultCode) override;
/**
* Outputs information and result code that the test has finished.
*
* @param msg, Indicates the status information.
* @param resultCode, Indicates the result code.
*/
virtual void TestFinished(const std::string &msg, const int &resultCode) override;
virtual ShellCommandResult ExecuteShellCommand(
const std::string &cmd, const int64_t timeoutSec) override;
/**
* Executes the specified shell command.
*
* @param cmd, Indicates the specified shell command.
* @param timeoutSec, Indicates the specified time out time, in seconds.
* @return the result of the specified shell command.
*/
virtual ShellCommandResult ExecuteShellCommand(const std::string &cmd, const int64_t timeoutSec) override;
/**
* Waits for the test to finish.
*
* @param timeoutMs, Indicates the specified time out time, in milliseconds.
* @return true if the test finish within the specified time; returns false otherwise.
*/
bool WaitForFinish(const int64_t &timeoutMs);
private:

View File

@ -23,12 +23,41 @@ namespace OHOS {
namespace AAFwk {
class TestObserverProxy : public IRemoteProxy<ITestObserver> {
public:
/**
* A constructor used to create a TestObserverProxy instance with the input parameter object passed.
* @param object Indicates remote object.
*/
explicit TestObserverProxy(const sptr<IRemoteObject> &object);
/**
* Deconstructor used to deconstruct.
*/
virtual ~TestObserverProxy() override;
/**
* Outputs test status.
*
* @param msg, Indicates the status information.
* @param resultCode, Indicates the result code.
*/
virtual void TestStatus(const std::string &msg, const int &resultCode) override;
/**
* Outputs information and result code that the test has finished.
*
* @param msg, Indicates the status information.
* @param resultCode, Indicates the result code.
*/
virtual void TestFinished(const std::string &msg, const int &resultCode) override;
virtual ShellCommandResult ExecuteShellCommand(
const std::string &cmd, const int64_t timeoutSec) override;
/**
* Executes the specified shell command.
*
* @param cmd, Indicates the specified shell command.
* @param timeoutSec, Indicates the specified time out time, in seconds.
* @return the result of the specified shell command.
*/
virtual ShellCommandResult ExecuteShellCommand(const std::string &cmd, const int64_t timeoutSec) override;
private:
static inline BrokerDelegator<TestObserverProxy> delegator_;

View File

@ -23,8 +23,25 @@ namespace OHOS {
namespace AAFwk {
class TestObserverStub : public IRemoteStub<ITestObserver> {
public:
/**
* Default constructor.
*/
TestObserverStub();
/**
* Deconstructor used to deconstruct.
*/
virtual ~TestObserverStub() override;
/**
* Handles ipc request.
*
* @param code, Indicates the ipc id.
* @param data, Indicates the input data.
* @param reply, Indicates the reply data.
* @param option, Indicates the option.
* @return the result of execution.
*/
virtual int OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
};

View File

@ -1205,10 +1205,10 @@ ErrCode AbilityManagerShellCommand::RunAsTestCommand()
for (int i = USER_TEST_COMMAND_START_INDEX; i < argc_; i++) {
HILOG_INFO("argv_[%{public}d]: %{public}s", i, argv_[i]);
std::string opt = argv_[i];
if (opt == "-h" || opt == "--help") {
if ((opt == "-h") || (opt == "--help")) {
resultReceiver_.append(HELP_MSG_TEST);
return OHOS::ERR_OK;
} else if (opt == "-b" || opt == "-w" || opt == "-p" || opt == "-m") {
} else if ((opt == "-b") || (opt == "-w") || (opt == "-p") || (opt == "-m")) {
if (i >= argc_ - 1) {
return TestCommandError("error: option [" + opt + "] requires a value.\n");
}