mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-27 09:21:28 +00:00
Functional fixes
Signed-off-by: njupthan <hanhaibin@huawei.com>
This commit is contained in:
parent
5152b2aae0
commit
280960d616
@ -40,6 +40,8 @@ public:
|
||||
|
||||
private:
|
||||
void CallObjectMethod(const char *name, NativeValue *const *argv = nullptr, size_t argc = 0);
|
||||
void ReportFinished(const std::string &msg);
|
||||
void ReportStatus(const std::string &msg);
|
||||
|
||||
JsRuntime &jsRuntime_;
|
||||
std::unique_ptr<NativeReference> jsTestRunnerObj_;
|
||||
|
@ -27,8 +27,8 @@ class Runtime;
|
||||
namespace AppExecFwk {
|
||||
class TestRunner {
|
||||
public:
|
||||
static std::unique_ptr<TestRunner> Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime,
|
||||
const std::shared_ptr<AbilityDelegatorArgs> &args);
|
||||
static std::unique_ptr<TestRunner> Create(
|
||||
const std::unique_ptr<AbilityRuntime::Runtime> &runtime, const std::shared_ptr<AbilityDelegatorArgs> &args);
|
||||
|
||||
TestRunner() = default;
|
||||
virtual ~TestRunner() = default;
|
||||
|
@ -516,7 +516,7 @@ 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, observer_);
|
||||
auto err = AAFwk::AbilityManagerClient::GetInstance()->FinishUserTest(msg, resultCode, bundleName);
|
||||
if (err) {
|
||||
APP_LOGE("MainThread::FinishUserTest is failed %{public}d", err);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ability_delegator_registry.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "runner_runtime/js_test_runner.h"
|
||||
@ -63,6 +64,7 @@ void JsTestRunner::CallObjectMethod(const char *name, NativeValue *const *argv,
|
||||
|
||||
if (!jsTestRunnerObj_) {
|
||||
APP_LOGE("Not found test_runner.js");
|
||||
ReportFinished("Not found test_runner.js");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -73,15 +75,41 @@ void JsTestRunner::CallObjectMethod(const char *name, NativeValue *const *argv,
|
||||
NativeObject *obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
APP_LOGE("Failed to get Test Runner object");
|
||||
ReportFinished("Failed to get Test Runner object");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue *methodOnCreate = obj->GetProperty(name);
|
||||
if (methodOnCreate == nullptr) {
|
||||
APP_LOGE("Failed to get '%{public}s' from Test Runner object", name);
|
||||
ReportStatus("Failed to get " + std::string(name) + " from Test Runner object");
|
||||
return;
|
||||
}
|
||||
nativeEngine.CallFunction(value, methodOnCreate, argv, argc);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
|
||||
void JsTestRunner::ReportFinished(const std::string &msg)
|
||||
{
|
||||
APP_LOGI("Enter");
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
APP_LOGE("delegator is null");
|
||||
return;
|
||||
}
|
||||
|
||||
delegator->FinishUserTest(msg, -1);
|
||||
}
|
||||
|
||||
void JsTestRunner::ReportStatus(const std::string &msg)
|
||||
{
|
||||
APP_LOGI("Enter");
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
APP_LOGE("delegator is null");
|
||||
return;
|
||||
}
|
||||
|
||||
delegator->Print(msg);
|
||||
}
|
||||
} // namespace RunnerRuntime
|
||||
} // namespace OHOS
|
||||
|
@ -19,8 +19,8 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
std::unique_ptr<TestRunner> TestRunner::Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime,
|
||||
const std::shared_ptr<AbilityDelegatorArgs> &args)
|
||||
std::unique_ptr<TestRunner> TestRunner::Create(
|
||||
const std::unique_ptr<AbilityRuntime::Runtime> &runtime, const std::shared_ptr<AbilityDelegatorArgs> &args)
|
||||
{
|
||||
if (!runtime) {
|
||||
return std::make_unique<TestRunner>();
|
||||
|
@ -403,10 +403,10 @@ private:
|
||||
*
|
||||
* @brief Ability Delegator Prepare.
|
||||
*
|
||||
* @param UserTestRecord User Test info.
|
||||
* @param record User Test info.
|
||||
*
|
||||
*/
|
||||
bool AbilityDelegatorPrepare(const UserTestRecord &record);
|
||||
bool PrepareAbilityDelegator(const std::shared_ptr<UserTestRecord> &record);
|
||||
|
||||
class MainHandler : public EventHandler {
|
||||
public:
|
||||
|
@ -723,12 +723,10 @@ public:
|
||||
* @param msg user test message.
|
||||
* @param resultCode user test result Code.
|
||||
* @param bundleName user test bundleName.
|
||||
* @param observer test observer callback.
|
||||
*
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FinishUserTest(const std::string &msg, const int &resultCode,
|
||||
const std::string &bundleName, const sptr<IRemoteObject> &observer);
|
||||
ErrCode FinishUserTest(const std::string &msg, const int &resultCode, const std::string &bundleName);
|
||||
|
||||
/**
|
||||
* GetCurrentTopAbility, get the token of current top ability.
|
||||
|
@ -675,8 +675,7 @@ public:
|
||||
|
||||
virtual int StartUserTest(const Want &want, const sptr<IRemoteObject> &observer) = 0;
|
||||
|
||||
virtual int FinishUserTest(const std::string &msg, const int &resultCode,
|
||||
const std::string &bundleName, const sptr<IRemoteObject> &observer) = 0;
|
||||
virtual int FinishUserTest(const std::string &msg, const int &resultCode, const std::string &bundleName) = 0;
|
||||
|
||||
/**
|
||||
* GetCurrentTopAbility, get the token of current top ability.
|
||||
|
@ -31,7 +31,8 @@ namespace AppExecFwk {
|
||||
struct UserTestRecord : public Parcelable {
|
||||
AAFwk::Want want;
|
||||
sptr<IRemoteObject> observer;
|
||||
UserTestRecord() : observer(nullptr)
|
||||
bool isFinished;
|
||||
UserTestRecord() : observer(nullptr), isFinished(false)
|
||||
{}
|
||||
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
@ -81,7 +82,7 @@ public:
|
||||
*
|
||||
* @param UserTestRecord, user test info.
|
||||
*/
|
||||
void SetUserTestInfo(const UserTestRecord &record);
|
||||
void SetUserTestInfo(const std::shared_ptr<UserTestRecord> &record);
|
||||
|
||||
/**
|
||||
* @brief Obtains the info of the application.
|
||||
@ -138,7 +139,7 @@ public:
|
||||
*
|
||||
* @return Returns user test info.
|
||||
*/
|
||||
inline const UserTestRecord &GetUserTestInfo() const
|
||||
inline std::shared_ptr<UserTestRecord> GetUserTestInfo() const
|
||||
{
|
||||
return userTestRecord_;
|
||||
}
|
||||
@ -171,7 +172,7 @@ private:
|
||||
ProcessInfo processInfo_;
|
||||
int32_t recordId_ = 0;
|
||||
int32_t uId_ = 0;
|
||||
UserTestRecord userTestRecord_;
|
||||
std::shared_ptr<UserTestRecord> userTestRecord_ = nullptr;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -218,6 +218,18 @@ public:
|
||||
virtual int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer,
|
||||
const BundleInfo &bundleInfo);
|
||||
|
||||
/**
|
||||
* @brief Finish user test.
|
||||
* @param msg user test message.
|
||||
* @param resultCode user test result Code.
|
||||
* @param bundleName user test bundleName.
|
||||
* @param pid the user test process id.
|
||||
*
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int FinishUserTest(
|
||||
const std::string &msg, const int &resultCode, const std::string &bundleName, const pid_t &pid);
|
||||
|
||||
virtual void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo);
|
||||
|
||||
virtual void RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response);
|
||||
|
@ -172,6 +172,18 @@ public:
|
||||
virtual int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer,
|
||||
const BundleInfo &bundleInfo) = 0;
|
||||
|
||||
/**
|
||||
* @brief Finish user test.
|
||||
* @param msg user test message.
|
||||
* @param resultCode user test result Code.
|
||||
* @param bundleName user test bundleName.
|
||||
* @param pid the user test process id.
|
||||
*
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int FinishUserTest(
|
||||
const std::string &msg, const int &resultCode, const std::string &bundleName, const pid_t &pid) = 0;
|
||||
|
||||
virtual void ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag) = 0;
|
||||
|
||||
/**
|
||||
@ -220,6 +232,7 @@ public:
|
||||
UNREGISTER_APPLICATION_STATE_OBSERVER,
|
||||
GET_FOREGROUND_APPLICATIONS,
|
||||
START_USER_TEST_PROCESS,
|
||||
FINISH_USER_TEST,
|
||||
SCHEDULE_ACCEPT_WANT_DONE,
|
||||
APP_GET_ABILITY_RECORDS_BY_PROCESS_ID,
|
||||
START_RENDER_PROCESS,
|
||||
|
@ -164,9 +164,21 @@ public:
|
||||
virtual int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer,
|
||||
const BundleInfo &bundleInfo) override;
|
||||
|
||||
/**
|
||||
* @brief Finish user test.
|
||||
* @param msg user test message.
|
||||
* @param resultCode user test result Code.
|
||||
* @param bundleName user test bundleName.
|
||||
* @param pid the user test process id.
|
||||
*
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int FinishUserTest(
|
||||
const std::string &msg, const int &resultCode, const std::string &bundleName, const pid_t &pid) override;
|
||||
|
||||
virtual void ScheduleAcceptWantDone(
|
||||
const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override;
|
||||
|
||||
|
||||
/**
|
||||
* Get the token of ability records by process ID.
|
||||
*
|
||||
|
@ -72,6 +72,7 @@ private:
|
||||
int32_t HandleUnregisterApplicationStateObserver(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleGetForegroundApplications(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleStartUserTestProcess(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleFinishUserTest(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleScheduleAcceptWantDone(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleGetAbilityRecordsByProcessID(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleStartRenderProcess(MessageParcel &data, MessageParcel &reply);
|
||||
|
@ -44,16 +44,41 @@ void AppLaunchData::SetUId(const int32_t uId)
|
||||
uId_ = uId;
|
||||
}
|
||||
|
||||
void AppLaunchData::SetUserTestInfo(const UserTestRecord &record)
|
||||
void AppLaunchData::SetUserTestInfo(const std::shared_ptr<UserTestRecord> &record)
|
||||
{
|
||||
userTestRecord_ = record;
|
||||
}
|
||||
|
||||
bool AppLaunchData::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
return (parcel.WriteParcelable(&applicationInfo_) && parcel.WriteParcelable(&profile_) &&
|
||||
parcel.WriteParcelable(&processInfo_) && parcel.WriteInt32(recordId_) &&
|
||||
parcel.WriteInt32(uId_) && parcel.WriteParcelable(&userTestRecord_));
|
||||
if (!parcel.WriteParcelable(&applicationInfo_)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteParcelable(&profile_)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteParcelable(&processInfo_)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt32(recordId_)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt32(uId_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool valid = userTestRecord_ ? true : false;
|
||||
if (!parcel.WriteBool(valid)) {
|
||||
APP_LOGE("Failed to write the flag which indicate whether userTestRecord_ is null");
|
||||
return false;
|
||||
}
|
||||
if (valid) {
|
||||
if (!parcel.WriteParcelable(userTestRecord_.get())) {
|
||||
APP_LOGE("Failed to write userTestRecord_");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AppLaunchData::ReadFromParcel(Parcel &parcel)
|
||||
@ -82,12 +107,14 @@ bool AppLaunchData::ReadFromParcel(Parcel &parcel)
|
||||
recordId_ = parcel.ReadInt32();
|
||||
uId_ = parcel.ReadInt32();
|
||||
|
||||
std::unique_ptr<UserTestRecord> userTestRecord(parcel.ReadParcelable<UserTestRecord>());
|
||||
if (!userTestRecord) {
|
||||
APP_LOGE("failed, userTestRecord is nullptr");
|
||||
return false;
|
||||
bool valid = parcel.ReadBool();
|
||||
if (valid) {
|
||||
userTestRecord_ = std::shared_ptr<UserTestRecord>(parcel.ReadParcelable<UserTestRecord>());
|
||||
if (!userTestRecord_) {
|
||||
APP_LOGE("failed, userTestRecord is nullptr");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
userTestRecord_ = *userTestRecord;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -121,6 +148,11 @@ bool UserTestRecord::Marshalling(Parcel &parcel) const
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(isFinished)) {
|
||||
APP_LOGE("Failed to write isFinished");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -153,6 +185,8 @@ bool UserTestRecord::ReadFromParcel(Parcel &parcel)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
isFinished = parcel.ReadBool();
|
||||
return true;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
|
@ -353,6 +353,17 @@ int AppMgrClient::StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemo
|
||||
return service->StartUserTestProcess(want, observer, bundleInfo);
|
||||
}
|
||||
|
||||
int AppMgrClient::FinishUserTest(
|
||||
const std::string &msg, const int &resultCode, const std::string &bundleName, const pid_t &pid)
|
||||
{
|
||||
sptr<IAppMgr> service = iface_cast<IAppMgr>(remote_);
|
||||
if (service == nullptr) {
|
||||
APP_LOGE("service is nullptr");
|
||||
return AppMgrResultCode::ERROR_SERVICE_NOT_READY;
|
||||
}
|
||||
return service->FinishUserTest(msg, resultCode, bundleName, pid);
|
||||
}
|
||||
|
||||
void AppMgrClient::StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo)
|
||||
{
|
||||
sptr<IAppMgr> service = iface_cast<IAppMgr>(remote_);
|
||||
|
@ -509,6 +509,41 @@ int AppMgrProxy::StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemot
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int AppMgrProxy::FinishUserTest(
|
||||
const std::string &msg, const int &resultCode, const std::string &bundleName, const pid_t &pid)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
return ERR_FLATTEN_OBJECT;
|
||||
}
|
||||
if (!data.WriteString(msg)) {
|
||||
APP_LOGE("msg write failed.");
|
||||
return ERR_FLATTEN_OBJECT;
|
||||
}
|
||||
if (!data.WriteInt32(resultCode)) {
|
||||
APP_LOGE("resultCode:WriteInt32 fail.");
|
||||
return ERR_FLATTEN_OBJECT;
|
||||
}
|
||||
if (!data.WriteString(bundleName)) {
|
||||
APP_LOGE("bundleName write failed.");
|
||||
return ERR_FLATTEN_OBJECT;
|
||||
}
|
||||
if (!data.WriteInt32(pid)) {
|
||||
APP_LOGE("pid write failed.");
|
||||
return ERR_FLATTEN_OBJECT;
|
||||
}
|
||||
int32_t ret =
|
||||
Remote()->SendRequest(static_cast<uint32_t>(IAppMgr::Message::FINISH_USER_TEST), data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
APP_LOGW("SendRequest is failed, error code: %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
void AppMgrProxy::ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag)
|
||||
{
|
||||
MessageParcel data;
|
||||
|
@ -66,6 +66,8 @@ AppMgrStub::AppMgrStub()
|
||||
&AppMgrStub::HandleGetForegroundApplications;
|
||||
memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::START_USER_TEST_PROCESS)] =
|
||||
&AppMgrStub::HandleStartUserTestProcess;
|
||||
memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::FINISH_USER_TEST)] =
|
||||
&AppMgrStub::HandleFinishUserTest;
|
||||
memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::SCHEDULE_ACCEPT_WANT_DONE)] =
|
||||
&AppMgrStub::HandleScheduleAcceptWantDone;
|
||||
memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_GET_ABILITY_RECORDS_BY_PROCESS_ID)] =
|
||||
@ -300,6 +302,17 @@ int32_t AppMgrStub::HandleStartUserTestProcess(MessageParcel &data, MessageParce
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t AppMgrStub::HandleFinishUserTest(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string msg = data.ReadString();
|
||||
int resultCode = data.ReadInt32();
|
||||
std::string bundleName = data.ReadString();
|
||||
auto pid = data.ReadInt32();
|
||||
int32_t result = FinishUserTest(msg, resultCode, bundleName, pid);
|
||||
reply.WriteInt32(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t AppMgrStub::RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer)
|
||||
{
|
||||
return NO_ERROR;
|
||||
|
@ -28,7 +28,7 @@ AbilityMonitor::AbilityMonitor(const std::string &name, const std::shared_ptr<JS
|
||||
|
||||
void AbilityMonitor::OnAbilityStart()
|
||||
{
|
||||
HILOG_INFO("onAbilityCreate is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (jsMonitor_ == nullptr) {
|
||||
return;
|
||||
@ -36,12 +36,12 @@ void AbilityMonitor::OnAbilityStart()
|
||||
|
||||
jsMonitor_->onAbilityCreate();
|
||||
|
||||
HILOG_INFO("onAbilityCreate is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
|
||||
void AbilityMonitor::OnAbilityForeground()
|
||||
{
|
||||
HILOG_INFO("onAbilityForeground is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (jsMonitor_ == nullptr) {
|
||||
return;
|
||||
@ -49,12 +49,12 @@ void AbilityMonitor::OnAbilityForeground()
|
||||
|
||||
jsMonitor_->onAbilityForeground();
|
||||
|
||||
HILOG_INFO("onAbilityForeground is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
|
||||
void AbilityMonitor::OnAbilityBackground()
|
||||
{
|
||||
HILOG_INFO("onAbilityBackground is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (jsMonitor_ == nullptr) {
|
||||
return;
|
||||
@ -62,12 +62,12 @@ void AbilityMonitor::OnAbilityBackground()
|
||||
|
||||
jsMonitor_->onAbilityBackground();
|
||||
|
||||
HILOG_INFO("onAbilityBackground is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
|
||||
void AbilityMonitor::OnAbilityStop()
|
||||
{
|
||||
HILOG_INFO("onAbilityDestroy is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (jsMonitor_ == nullptr) {
|
||||
return;
|
||||
@ -75,12 +75,12 @@ void AbilityMonitor::OnAbilityStop()
|
||||
|
||||
jsMonitor_->onAbilityDestroy();
|
||||
|
||||
HILOG_INFO("onAbilityDestroy is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
|
||||
void AbilityMonitor::OnWindowStageCreate()
|
||||
{
|
||||
HILOG_INFO("onWindowStageCreate is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (jsMonitor_ == nullptr) {
|
||||
return;
|
||||
@ -88,12 +88,12 @@ void AbilityMonitor::OnWindowStageCreate()
|
||||
|
||||
jsMonitor_->onWindowStageCreate();
|
||||
|
||||
HILOG_INFO("onWindowStageCreate is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
|
||||
void AbilityMonitor::OnWindowStageRestore()
|
||||
{
|
||||
HILOG_INFO("onWindowStageRestore is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (jsMonitor_ == nullptr) {
|
||||
return;
|
||||
@ -101,12 +101,12 @@ void AbilityMonitor::OnWindowStageRestore()
|
||||
|
||||
jsMonitor_->onWindowStageRestore();
|
||||
|
||||
HILOG_INFO("onWindowStageRestore is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
|
||||
void AbilityMonitor::OnWindowStageDestroy()
|
||||
{
|
||||
HILOG_INFO("onWindowStageDestroy is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (jsMonitor_ == nullptr) {
|
||||
return;
|
||||
@ -114,7 +114,7 @@ void AbilityMonitor::OnWindowStageDestroy()
|
||||
|
||||
jsMonitor_->onWindowStageDestroy();
|
||||
|
||||
HILOG_INFO("onWindowStageDestroy is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
} // namespace AbilityDelegatorJs
|
||||
} // namespace OHOS
|
||||
|
@ -28,18 +28,18 @@ namespace OHOS {
|
||||
namespace AbilityDelegatorJs {
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
constexpr size_t ARGC_THREE = 3;
|
||||
constexpr size_t INDEX_ZERO = 0;
|
||||
constexpr size_t INDEX_ONE = 1;
|
||||
constexpr size_t INDEX_TWO = 2;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
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::shared_ptr<NativeReference>, std::shared_ptr<AbilityMonitor>> monitorRecord_;
|
||||
std::map<std::shared_ptr<NativeReference>, sptr<IRemoteObject>> ablityRecord_;
|
||||
|
||||
void JSAbilityDelegator::Finalizer(NativeEngine *engine, void *data, void *hint)
|
||||
{
|
||||
HILOG_INFO("JSAbilityDelegator::Finalizer is called");
|
||||
HILOG_INFO("enter");
|
||||
std::unique_ptr<JSAbilityDelegator>(static_cast<JSAbilityDelegator *>(data));
|
||||
}
|
||||
|
||||
@ -111,201 +111,210 @@ NativeValue *JSAbilityDelegator::FinishTest(NativeEngine *engine, NativeCallback
|
||||
|
||||
NativeValue *JSAbilityDelegator::OnAddAbilityMonitor(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOG_INFO("OnAddAbilityMonitor is called, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
HILOG_INFO("enter, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
std::shared_ptr<AbilityMonitor> monitor = nullptr;
|
||||
if (!ParseJSMonitorPara(engine, info.argv[INDEX_ZERO], monitor)) {
|
||||
if (!ParseAbilityMonitorPara(engine, info, monitor)) {
|
||||
HILOG_ERROR("Parse addAbilityMonitor parameters failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete = [monitor](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
HILOG_INFO("OnAddAbilityMonitor AsyncTask is called");
|
||||
AbilityDelegatorRegistry::GetAbilityDelegator()->AddAbilityMonitor(monitor);
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
task.Reject(engine, CreateJsError(engine, ERROR, "addAbilityMonitor failed."));
|
||||
return;
|
||||
}
|
||||
delegator->AddAbilityMonitor(monitor);
|
||||
task.Resolve(engine, engine.CreateNull());
|
||||
};
|
||||
|
||||
NativeValue *lastParam = (info.argc == ARGC_TWO) ? info.argv[INDEX_ONE] : nullptr;
|
||||
NativeValue *lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
|
||||
NativeValue *result = nullptr;
|
||||
AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::OnRemoveAbilityMonitor(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOG_INFO("OnRemoveAbilityMonitor is called, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
HILOG_INFO("enter, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
std::shared_ptr<AbilityMonitor> monitor = nullptr;
|
||||
if (!ParseJSMonitorPara(engine, info.argv[INDEX_ZERO], monitor)) {
|
||||
if (!ParseAbilityMonitorPara(engine, info, monitor)) {
|
||||
HILOG_ERROR("Parse removeAbilityMonitor parameters failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[monitor](NativeEngine &engine, AsyncTask &task, int32_t status) mutable {
|
||||
HILOG_INFO("OnRemoveAbilityMonitor AsyncTask is called");
|
||||
AbilityDelegatorRegistry::GetAbilityDelegator()->RemoveAbilityMonitor(monitor);
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
task.Reject(engine, CreateJsError(engine, ERROR, "removeAbilityMonitor failed."));
|
||||
return;
|
||||
}
|
||||
delegator->RemoveAbilityMonitor(monitor);
|
||||
task.Resolve(engine, engine.CreateNull());
|
||||
};
|
||||
|
||||
NativeValue *lastParam = (info.argc == ARGC_TWO) ? info.argv[INDEX_ONE] : nullptr;
|
||||
NativeValue *lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
|
||||
NativeValue *result = nullptr;
|
||||
AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
|
||||
for (auto iter = monitorRecord.begin(); iter != monitorRecord.end(); ++iter) {
|
||||
std::shared_ptr<NativeReference> jsMonitor = iter->first;
|
||||
if ((info.argv[INDEX_ZERO])->StrictEquals(jsMonitor->Get())) {
|
||||
monitorRecord.erase(iter);
|
||||
break;
|
||||
if (AbilityDelegatorRegistry::GetAbilityDelegator()) {
|
||||
for (auto iter = monitorRecord_.begin(); iter != monitorRecord_.end(); ++iter) {
|
||||
std::shared_ptr<NativeReference> jsMonitor = iter->first;
|
||||
if ((info.argv[INDEX_ZERO])->StrictEquals(jsMonitor->Get())) {
|
||||
monitorRecord_.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::OnWaitAbilityMonitor(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOG_INFO("OnWaitAbilityMonitor is called, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
HILOG_INFO("enter, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
std::shared_ptr<AbilityMonitor> monitor = nullptr;
|
||||
if (!ParseJSMonitorPara(engine, info.argv[INDEX_ZERO], monitor)) {
|
||||
TimeoutCallback opt {false, false};
|
||||
int64_t timeout = 0;
|
||||
if (!ParseWaitAbilityMonitorPara(engine, info, monitor, opt, timeout)) {
|
||||
HILOG_ERROR("Parse waitAbilityMonitor parameters failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
bool hasTimeoutPara = false;
|
||||
int64_t timeout = 0;
|
||||
if (info.argc >= ARGC_TWO) {
|
||||
if (!ConvertFromJsValue(engine, info.argv[INDEX_ONE], timeout)) {
|
||||
HILOG_ERROR("Parse timeout failed");
|
||||
} else {
|
||||
hasTimeoutPara = true;
|
||||
}
|
||||
}
|
||||
|
||||
int argcnum = info.argc;
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[argcnum, monitor, timeout, hasTimeoutPara, this](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
[monitor, timeout, opt, this](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
HILOG_INFO("OnWaitAbilityMonitor AsyncTask is called");
|
||||
sptr<IRemoteObject> remoteObject = nullptr;
|
||||
if (((argcnum == ARGC_TWO) && !hasTimeoutPara) || (argcnum == ARGC_ONE)) {
|
||||
remoteObject = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator()->WaitAbilityMonitor(monitor);
|
||||
} else if (((argcnum == ARGC_TWO) && hasTimeoutPara) || (argcnum == ARGC_THREE)) {
|
||||
remoteObject =
|
||||
AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator()->WaitAbilityMonitor(monitor, timeout);
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
task.Reject(engine, CreateJsError(engine, ERROR, "waitAbilityMonitor failed."));
|
||||
return;
|
||||
}
|
||||
sptr<IRemoteObject> remoteObject = nullptr;
|
||||
if (opt.hasTimeoutPara) {
|
||||
remoteObject = delegator->WaitAbilityMonitor(monitor, timeout);
|
||||
} else {
|
||||
remoteObject = delegator->WaitAbilityMonitor(monitor);
|
||||
}
|
||||
NativeValue *ability = CreateAbilityObject(engine, remoteObject);
|
||||
if (ability) {
|
||||
task.Resolve(engine, ability);
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ERROR, "waitAbilityMonitor failed."));
|
||||
}
|
||||
task.Resolve(engine, CreateJsAbilityObject(engine, remoteObject));
|
||||
};
|
||||
|
||||
NativeValue *lastParam = nullptr;
|
||||
if ((argcnum == ARGC_ONE) || ((argcnum == ARGC_TWO) && hasTimeoutPara)) {
|
||||
if (opt.hasCallbackPara) {
|
||||
lastParam = opt.hasTimeoutPara ? info.argv[INDEX_TWO] : info.argv[INDEX_ONE];
|
||||
} else {
|
||||
lastParam = nullptr;
|
||||
} else if ((argcnum == ARGC_TWO) && !hasTimeoutPara) {
|
||||
lastParam = info.argv[INDEX_ONE];
|
||||
} else if (argcnum == ARGC_THREE) {
|
||||
lastParam = info.argv[INDEX_TWO];
|
||||
}
|
||||
|
||||
NativeValue *result = nullptr;
|
||||
AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NativeValue *JSAbilityDelegator::OnPrint(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOG_INFO("OnPrint is called, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
HILOG_INFO("enter, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
std::string msg;
|
||||
if (!ConvertFromJsValue(engine, info.argv[INDEX_ZERO], msg)) {
|
||||
HILOG_ERROR("Parse para failed");
|
||||
if (!ParsePrintPara(engine, info, msg)) {
|
||||
HILOG_ERROR("Parse print parameters failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete = [msg](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
HILOG_INFO("OnPrint AsyncTask is called");
|
||||
AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator()->Print(msg);
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
task.Reject(engine, CreateJsError(engine, ERROR, "print failed."));
|
||||
return;
|
||||
}
|
||||
delegator->Print(msg);
|
||||
task.Resolve(engine, engine.CreateNull());
|
||||
};
|
||||
|
||||
NativeValue *lastParam = (info.argc == ARGC_TWO) ? info.argv[INDEX_ONE] : nullptr;
|
||||
NativeValue *lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
|
||||
NativeValue *result = nullptr;
|
||||
AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::OnExecuteShellCommand(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOG_INFO("OnExecuteShellCommand is called, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
HILOG_INFO("enter, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
std::string cmd;
|
||||
bool hasTimeoutPara = false;
|
||||
TimeoutCallback opt {false, false};
|
||||
int64_t timeoutSecs = 0;
|
||||
if (!ParseJSExecuteShellCommandPara(engine, info, cmd, timeoutSecs, hasTimeoutPara)) {
|
||||
if (!ParseExecuteShellCommandPara(engine, info, cmd, opt, timeoutSecs)) {
|
||||
HILOG_ERROR("Parse executeShellCommand parameters failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete = [cmd, timeoutSecs](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
HILOG_INFO("OnExecuteShellCommand AsyncTask is called");
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
task.Reject(engine, CreateJsError(engine, ERROR, "executeShellCommand failed."));
|
||||
return;
|
||||
}
|
||||
std::unique_ptr<ShellCmdResult> shellResult =
|
||||
AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator()->ExecuteShellCommand(cmd, timeoutSecs);
|
||||
task.Resolve(engine, CreateJsShellCmdResult(engine, shellResult));
|
||||
delegator->ExecuteShellCommand(cmd, timeoutSecs);
|
||||
NativeValue *result = CreateJsShellCmdResult(engine, shellResult);
|
||||
if (result) {
|
||||
task.Resolve(engine, result);
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ERROR, "executeShellCommand failed."));
|
||||
}
|
||||
};
|
||||
|
||||
int argcnum = info.argc;
|
||||
NativeValue *lastParam = nullptr;
|
||||
if ((argcnum == ARGC_ONE) || ((argcnum == ARGC_TWO) && hasTimeoutPara)) {
|
||||
if (opt.hasCallbackPara) {
|
||||
lastParam = opt.hasTimeoutPara ? info.argv[INDEX_TWO] : info.argv[INDEX_ONE];
|
||||
} else {
|
||||
lastParam = nullptr;
|
||||
} else if ((argcnum == ARGC_TWO) && !hasTimeoutPara) {
|
||||
lastParam = info.argv[INDEX_ONE];
|
||||
} else if (argcnum == ARGC_THREE) {
|
||||
lastParam = info.argv[INDEX_TWO];
|
||||
}
|
||||
|
||||
NativeValue *result = nullptr;
|
||||
AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::OnGetAppContext(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOG_INFO("OnGetAppContext is called, argc = %{public}d", static_cast<int>(info.argc));
|
||||
HILOG_INFO("enter, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
AsyncTask::CompleteCallback complete = [](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
HILOG_INFO("OnGetAppContext AsyncTask is called");
|
||||
std::shared_ptr<AbilityRuntime::Context> context =
|
||||
AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator()->GetAppContext();
|
||||
task.Resolve(engine, CreateJsBaseContext(engine, context, false));
|
||||
};
|
||||
|
||||
NativeValue *lastParam = (info.argc == ARGC_ONE) ? info.argv[INDEX_ZERO] : nullptr;
|
||||
NativeValue *result = nullptr;
|
||||
AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
HILOG_ERROR("delegator is null");
|
||||
return engine.CreateNull();
|
||||
}
|
||||
std::shared_ptr<AbilityRuntime::Context> context = delegator->GetAppContext();
|
||||
if (!context) {
|
||||
HILOG_ERROR("context is null");
|
||||
return engine.CreateNull();
|
||||
}
|
||||
return CreateJsBaseContext(engine, context, false);
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::OnGetAbilityState(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOG_INFO("OnGetAbilityState is called, argc = %{public}d", static_cast<int>(info.argc));
|
||||
HILOG_INFO("enter, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
@ -313,130 +322,146 @@ NativeValue *JSAbilityDelegator::OnGetAbilityState(NativeEngine &engine, NativeC
|
||||
}
|
||||
|
||||
sptr<OHOS::IRemoteObject> remoteObject = nullptr;
|
||||
if (!ParseJSAbilityPara(engine, info.argv[INDEX_ZERO], remoteObject)) {
|
||||
if (!ParseAbilityPara(engine, info.argv[INDEX_ZERO], remoteObject)) {
|
||||
HILOG_ERROR("Parse ability parameter failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete = [remoteObject](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
HILOG_INFO("OnGetAbilityState AsyncTask is called");
|
||||
AbilityDelegator::AbilityState lifeState =
|
||||
AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator()->GetAbilityState(remoteObject);
|
||||
task.Resolve(engine, CreateJsAbilityState(engine, lifeState));
|
||||
};
|
||||
|
||||
NativeValue *lastParam = (info.argc == ARGC_TWO) ? info.argv[INDEX_ONE] : nullptr;
|
||||
NativeValue *result = nullptr;
|
||||
AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
HILOG_ERROR("delegator is null");
|
||||
return engine.CreateNull();
|
||||
}
|
||||
AbilityDelegator::AbilityState lifeState = delegator->GetAbilityState(remoteObject);
|
||||
AbilityLifecycleState abilityLifeState = AbilityLifecycleState::UNINITIALIZED;
|
||||
AbilityLifecycleStateToJs(lifeState, abilityLifeState);
|
||||
return engine.CreateNumber(static_cast<int>(abilityLifeState));
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::OnGetCurrentTopAbility(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOG_INFO("OnGetCurrentTopAbility is called, argc = %{public}d", static_cast<int>(info.argc));
|
||||
HILOG_INFO("enter, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
if (info.argc >= ARGC_ONE) {
|
||||
if (info.argv[INDEX_ZERO]->TypeOf() != NativeValueType::NATIVE_FUNCTION) {
|
||||
HILOG_ERROR("Parse getCurrentTopAbility parameter failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete = [this](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
HILOG_INFO("OnGetCurrentTopAbility AsyncTask is called");
|
||||
sptr<IRemoteObject> remoteObject =
|
||||
AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator()->GetCurrentTopAbility();
|
||||
task.Resolve(engine, CreateJsAbilityObject(engine, remoteObject));
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!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 {
|
||||
task.Reject(engine, CreateJsError(engine, ERROR, "getCurrentTopAbility failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue *lastParam = (info.argc == ARGC_ONE) ? info.argv[INDEX_ZERO] : nullptr;
|
||||
NativeValue *lastParam = (info.argc >= ARGC_ONE) ? info.argv[INDEX_ZERO] : nullptr;
|
||||
NativeValue *result = nullptr;
|
||||
AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::OnDoAbilityForeground(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOG_INFO("OnDoAbilityForeground is called, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
HILOG_INFO("enter, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
sptr<OHOS::IRemoteObject> remoteObject = nullptr;
|
||||
if (!ParseJSAbilityPara(engine, info.argv[INDEX_ZERO], remoteObject)) {
|
||||
if (!ParseAbilityCommonPara(engine, info, remoteObject)) {
|
||||
HILOG_ERROR("Parse doAbilityForeground parameters failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete = [remoteObject](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
HILOG_INFO("OnDoAbilityForeground AsyncTask is called");
|
||||
bool ret = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator()->DoAbilityForeground(remoteObject);
|
||||
task.Resolve(engine, CreateJsBool(engine, ret));
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
task.Reject(engine, CreateJsError(engine, ERROR, "doAbilityForeground failed."));
|
||||
return;
|
||||
}
|
||||
bool ret = delegator->DoAbilityForeground(remoteObject);
|
||||
task.Resolve(engine, engine.CreateBoolean(ret));
|
||||
};
|
||||
|
||||
NativeValue *lastParam = (info.argc == ARGC_TWO) ? info.argv[INDEX_ONE] : nullptr;
|
||||
NativeValue *lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
|
||||
NativeValue *result = nullptr;
|
||||
AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::OnDoAbilityBackground(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOG_INFO("OnDoAbilityBackground is called, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
HILOG_INFO("enter, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
sptr<OHOS::IRemoteObject> remoteObject = nullptr;
|
||||
if (!ParseJSAbilityPara(engine, info.argv[INDEX_ZERO], remoteObject)) {
|
||||
if (!ParseAbilityCommonPara(engine, info, remoteObject)) {
|
||||
HILOG_ERROR("Parse doAbilityBackground parameters failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete = [remoteObject](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
HILOG_INFO("OnDoAbilityBackground AsyncTask is called");
|
||||
bool ret = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator()->DoAbilityBackground(remoteObject);
|
||||
task.Resolve(engine, CreateJsBool(engine, ret));
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
task.Reject(engine, CreateJsError(engine, ERROR, "doAbilityBackground failed."));
|
||||
return;
|
||||
}
|
||||
bool ret = delegator->DoAbilityBackground(remoteObject);
|
||||
task.Resolve(engine, engine.CreateBoolean(ret));
|
||||
};
|
||||
|
||||
NativeValue *lastParam = (info.argc == ARGC_TWO) ? info.argv[INDEX_ONE] : nullptr;
|
||||
NativeValue *lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
|
||||
NativeValue *result = nullptr;
|
||||
AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::OnFinishTest(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOG_INFO("OnFinishTest is called, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
if (info.argc < ARGC_TWO) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
HILOG_INFO("enter, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
std::string msg;
|
||||
int64_t code = 0;
|
||||
if (!ConvertFromJsValue(engine, info.argv[INDEX_ZERO], msg)) {
|
||||
HILOG_ERROR("Parse para failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
if (!ConvertFromJsValue(engine, info.argv[INDEX_ONE], code)) {
|
||||
HILOG_ERROR("Parse para argv[1] failed");
|
||||
if (!ParseFinishTestPara(engine, info, msg, code)) {
|
||||
HILOG_ERROR("Parse finishTest parameters failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete = [msg, code](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
HILOG_INFO("OnFinishTest AsyncTask is called");
|
||||
AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator()->FinishUserTest(msg, code);
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
task.Reject(engine, CreateJsError(engine, ERROR, "finishTest failed."));
|
||||
return;
|
||||
}
|
||||
delegator->FinishUserTest(msg, code);
|
||||
task.Resolve(engine, engine.CreateNull());
|
||||
};
|
||||
NativeValue *lastParam = (info.argc == ARGC_THREE) ? info.argv[INDEX_TWO] : nullptr;
|
||||
NativeValue *lastParam = (info.argc > ARGC_TWO) ? info.argv[INDEX_TWO] : nullptr;
|
||||
NativeValue *result = nullptr;
|
||||
AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::ParseJSMonitorPara(
|
||||
NativeValue *JSAbilityDelegator::ParseMonitorPara(
|
||||
NativeEngine &engine, NativeValue *value, std::shared_ptr<AbilityMonitor> &monitor)
|
||||
{
|
||||
HILOG_INFO("ParseJSMonitorPara is called, monitorRecord size = %{public}zu", monitorRecord.size());
|
||||
HILOG_INFO("enter, monitorRecord size = %{public}zu", monitorRecord_.size());
|
||||
|
||||
for (auto iter = monitorRecord.begin(); iter != monitorRecord.end(); ++iter) {
|
||||
for (auto iter = monitorRecord_.begin(); iter != monitorRecord_.end(); ++iter) {
|
||||
std::shared_ptr<NativeReference> jsMonitor = iter->first;
|
||||
if (value->StrictEquals(jsMonitor->Get())) {
|
||||
HILOG_ERROR("monitor existed");
|
||||
@ -453,6 +478,7 @@ NativeValue *JSAbilityDelegator::ParseJSMonitorPara(
|
||||
|
||||
auto abilityNameValue = object->GetProperty("abilityName");
|
||||
if (abilityNameValue == nullptr) {
|
||||
HILOG_ERROR("Failed to get property abilityName");
|
||||
return nullptr;
|
||||
}
|
||||
std::string abilityName;
|
||||
@ -465,64 +491,41 @@ NativeValue *JSAbilityDelegator::ParseJSMonitorPara(
|
||||
|
||||
monitor = std::make_shared<AbilityMonitor>(abilityName, abilityMonitor);
|
||||
if (!monitor) {
|
||||
HILOG_INFO("Failed to create monitor");
|
||||
HILOG_ERROR("Failed to create monitor");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<NativeReference> reference = nullptr;
|
||||
reference.reset(engine.CreateReference(value, 1));
|
||||
monitorRecord.emplace(reference, monitor);
|
||||
monitorRecord_.emplace(reference, monitor);
|
||||
|
||||
return engine.CreateNull();
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::ParseJSAbilityPara(
|
||||
NativeValue *JSAbilityDelegator::ParseAbilityPara(
|
||||
NativeEngine &engine, NativeValue *value, sptr<OHOS::IRemoteObject> &remoteObject)
|
||||
{
|
||||
HILOG_INFO("ParseJSAbilityPara is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
for (auto iter = ablityRecord.begin(); iter != ablityRecord.end(); ++iter) {
|
||||
for (auto iter = ablityRecord_.begin(); iter != ablityRecord_.end(); ++iter) {
|
||||
if (value->StrictEquals(iter->first->Get())) {
|
||||
remoteObject = iter->second;
|
||||
HILOG_INFO("Ablity exist");
|
||||
return remoteObject ? engine.CreateNull() : nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
HILOG_ERROR("Ablity doesn't exist");
|
||||
remoteObject = nullptr;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::ParseJSExecuteShellCommandPara(
|
||||
NativeEngine &engine, NativeCallbackInfo &info, std::string &cmd, int64_t &timeoutSecs, bool &hasTimeoutPara)
|
||||
NativeValue *JSAbilityDelegator::CreateAbilityObject(NativeEngine &engine, const sptr<IRemoteObject> &remoteObject)
|
||||
{
|
||||
HILOG_INFO("ParseJSExecuteShellCommandPara is called");
|
||||
|
||||
if (!ConvertFromJsValue(engine, info.argv[INDEX_ZERO], cmd)) {
|
||||
HILOG_ERROR("Parse para argv[0] failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if ((info.argc >= ARGC_TWO) && ((info.argv[INDEX_ONE])->TypeOf() == NativeValueType::NATIVE_NUMBER)) {
|
||||
if (!ConvertFromJsValue(engine, info.argv[INDEX_ONE], timeoutSecs)) {
|
||||
HILOG_ERROR("Parse para argv[1] failed");
|
||||
return nullptr;
|
||||
}
|
||||
hasTimeoutPara = true;
|
||||
} else {
|
||||
hasTimeoutPara = false;
|
||||
}
|
||||
|
||||
return engine.CreateNull();
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::CreateJsAbilityObject(NativeEngine &engine, const sptr<IRemoteObject> &remoteObject)
|
||||
{
|
||||
HILOG_INFO("CreateJsAbilityObject is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (!remoteObject) {
|
||||
return engine.CreateUndefined();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
@ -532,11 +535,200 @@ NativeValue *JSAbilityDelegator::CreateJsAbilityObject(NativeEngine &engine, con
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<NativeReference> reference = nullptr;
|
||||
reference.reset(engine.CreateReference(objValue, 1));
|
||||
ablityRecord[reference] = remoteObject;
|
||||
|
||||
std::shared_ptr<NativeReference> refence = nullptr;
|
||||
refence.reset(engine.CreateReference(objValue, 1));
|
||||
ablityRecord_[refence] = remoteObject;
|
||||
return objValue;
|
||||
}
|
||||
|
||||
void JSAbilityDelegator::AbilityLifecycleStateToJs(const AbilityDelegator::AbilityState &lifeState,
|
||||
AbilityLifecycleState &abilityLifeState)
|
||||
{
|
||||
HILOG_INFO("enter and lifeState = %{public}d", (int32_t)lifeState);
|
||||
switch (lifeState) {
|
||||
case AbilityDelegator::AbilityState::STARTED:
|
||||
abilityLifeState = AbilityLifecycleState::CREATE;
|
||||
break;
|
||||
case AbilityDelegator::AbilityState::FOREGROUND:
|
||||
abilityLifeState = AbilityLifecycleState::FOREGROUND;
|
||||
break;
|
||||
case AbilityDelegator::AbilityState::BACKGROUND:
|
||||
abilityLifeState = AbilityLifecycleState::BACKGROUND;
|
||||
break;
|
||||
case AbilityDelegator::AbilityState::STOPPED:
|
||||
abilityLifeState = AbilityLifecycleState::DESTROY;
|
||||
break;
|
||||
default:
|
||||
abilityLifeState = AbilityLifecycleState::UNINITIALIZED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::ParseAbilityMonitorPara(
|
||||
NativeEngine &engine, NativeCallbackInfo &info, std::shared_ptr<AbilityMonitor> &monitor)
|
||||
{
|
||||
HILOG_INFO("enter");
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ParseMonitorPara(engine, info.argv[INDEX_ZERO], monitor)) {
|
||||
HILOG_ERROR("Parse monitor parameters failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (info.argc > ARGC_ONE) {
|
||||
if (info.argv[INDEX_ONE]->TypeOf() != NativeValueType::NATIVE_FUNCTION) {
|
||||
HILOG_ERROR("Parse callback parameters failed");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return engine.CreateNull();
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::ParseWaitAbilityMonitorPara(NativeEngine &engine, NativeCallbackInfo &info,
|
||||
std::shared_ptr<AbilityMonitor> &monitor, TimeoutCallback &opt, int64_t &timeout)
|
||||
{
|
||||
HILOG_INFO("enter");
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ParseMonitorPara(engine, info.argv[INDEX_ZERO], monitor)) {
|
||||
HILOG_ERROR("Monitor parse parameters failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ParseTimeoutCallbackPara(engine, info, opt, timeout)) {
|
||||
HILOG_ERROR("TimeoutCallback parse parameters failed");
|
||||
return nullptr;
|
||||
}
|
||||
return engine.CreateNull();
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::ParseTimeoutCallbackPara(
|
||||
NativeEngine &engine, NativeCallbackInfo &info, TimeoutCallback &opt, int64_t &timeout)
|
||||
{
|
||||
HILOG_INFO("enter");
|
||||
|
||||
opt.hasCallbackPara = false;
|
||||
opt.hasTimeoutPara = false;
|
||||
|
||||
if (info.argc >= ARGC_TWO) {
|
||||
if (!ConvertFromJsValue(engine, info.argv[INDEX_ONE], timeout)) {
|
||||
if (info.argv[INDEX_ONE]->TypeOf() != NativeValueType::NATIVE_FUNCTION) {
|
||||
HILOG_ERROR("Parse parameter argv[1] failed");
|
||||
return nullptr;
|
||||
}
|
||||
opt.hasCallbackPara = true;
|
||||
return engine.CreateNull();
|
||||
}
|
||||
opt.hasTimeoutPara = true;
|
||||
|
||||
if (info.argc > ARGC_TWO) {
|
||||
if (info.argv[INDEX_TWO]->TypeOf() != NativeValueType::NATIVE_FUNCTION) {
|
||||
HILOG_ERROR("Parse parameter argv[2] failed");
|
||||
return nullptr;
|
||||
}
|
||||
opt.hasCallbackPara = true;
|
||||
}
|
||||
}
|
||||
return engine.CreateNull();
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::ParsePrintPara(NativeEngine &engine, NativeCallbackInfo &info, std::string &msg)
|
||||
{
|
||||
HILOG_INFO("enter");
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ConvertFromJsValue(engine, info.argv[INDEX_ZERO], msg)) {
|
||||
HILOG_ERROR("Parse msg parameter failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (info.argc > ARGC_ONE) {
|
||||
if (info.argv[INDEX_ONE]->TypeOf() != NativeValueType::NATIVE_FUNCTION) {
|
||||
HILOG_ERROR("Parse callback parameter failed");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return engine.CreateNull();
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::ParseExecuteShellCommandPara(
|
||||
NativeEngine &engine, NativeCallbackInfo &info, std::string &cmd, TimeoutCallback &opt, int64_t &timeout)
|
||||
{
|
||||
HILOG_INFO("enter");
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ConvertFromJsValue(engine, info.argv[INDEX_ZERO], cmd)) {
|
||||
HILOG_ERROR("Parse cmd parameter failed");
|
||||
return nullptr;
|
||||
}
|
||||
if (!ParseTimeoutCallbackPara(engine, info, opt, timeout)) {
|
||||
HILOG_ERROR("Parse timeOut callback parameters failed");
|
||||
return nullptr;
|
||||
}
|
||||
return engine.CreateNull();
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::ParseAbilityCommonPara(NativeEngine &engine, NativeCallbackInfo &info,
|
||||
sptr<OHOS::IRemoteObject> &remoteObject)
|
||||
{
|
||||
HILOG_INFO("enter");
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ParseAbilityPara(engine, info.argv[INDEX_ZERO], remoteObject)) {
|
||||
HILOG_ERROR("Parse ability parameter failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (info.argc > ARGC_ONE) {
|
||||
if (info.argv[INDEX_ONE]->TypeOf() != NativeValueType::NATIVE_FUNCTION) {
|
||||
HILOG_ERROR("Parse ability callback parameters failed");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return engine.CreateNull();
|
||||
}
|
||||
|
||||
NativeValue *JSAbilityDelegator::ParseFinishTestPara(NativeEngine &engine,
|
||||
NativeCallbackInfo &info, std::string &msg, int64_t &code)
|
||||
{
|
||||
HILOG_INFO("enter");
|
||||
if (info.argc < ARGC_TWO) {
|
||||
HILOG_ERROR("Incorrect number of parameters");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ConvertFromJsValue(engine, info.argv[INDEX_ZERO], msg)) {
|
||||
HILOG_ERROR("Parse msg parameter failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ConvertFromJsValue(engine, info.argv[INDEX_ONE], code)) {
|
||||
HILOG_ERROR("Parse code para parameter failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (info.argc > ARGC_TWO) {
|
||||
if ((info.argv[INDEX_TWO])->TypeOf() != NativeValueType::NATIVE_FUNCTION) {
|
||||
HILOG_ERROR("Incorrect Callback Function type");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return engine.CreateNull();
|
||||
}
|
||||
} // namespace AbilityDelegatorJs
|
||||
} // namespace OHOS
|
||||
|
@ -17,13 +17,19 @@
|
||||
#define OHOS_ABILITY_DELEGATOR_JS_ABILITY_DELEGATOR_H
|
||||
|
||||
#include <string>
|
||||
#include "ability_delegator.h"
|
||||
#include "ability_monitor.h"
|
||||
#include "js_ability_delegator_registry.h"
|
||||
#include "js_ability_monitor.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityDelegatorJs {
|
||||
class JSAbilityDelegator {
|
||||
public:
|
||||
struct TimeoutCallback {
|
||||
bool hasTimeoutPara;
|
||||
bool hasCallbackPara;
|
||||
};
|
||||
JSAbilityDelegator() = default;
|
||||
~JSAbilityDelegator() = default;
|
||||
|
||||
@ -55,12 +61,24 @@ private:
|
||||
NativeValue *OnFinishTest(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
|
||||
private:
|
||||
NativeValue *CreateJsAbilityObject(NativeEngine &engine, const sptr<IRemoteObject> &remoteObject);
|
||||
NativeValue *ParseJSMonitorPara(NativeEngine &engine, NativeValue *value, std::shared_ptr<AbilityMonitor> &monitor);
|
||||
NativeValue *ParseJSAbilityPara(NativeEngine &engine, NativeValue *value, sptr<OHOS::IRemoteObject> &remoteObject);
|
||||
NativeValue *ParseJSExecuteShellCommandPara(
|
||||
NativeEngine& engine, NativeCallbackInfo &info, std::string &cmd, int64_t &timeoutSecs, bool &hasTimeoutPara);
|
||||
void SetJsAbilityMonitor(std::string jstring);
|
||||
NativeValue *CreateAbilityObject(NativeEngine &engine, const sptr<IRemoteObject> &remoteObject);
|
||||
NativeValue *ParseMonitorPara(NativeEngine &engine, NativeValue *value, std::shared_ptr<AbilityMonitor> &monitor);
|
||||
NativeValue *ParseAbilityPara(NativeEngine &engine, NativeValue *value, sptr<OHOS::IRemoteObject> &remoteObject);
|
||||
void AbilityLifecycleStateToJs(
|
||||
const AbilityDelegator::AbilityState &lifeState, AbilityLifecycleState &abilityLifeState);
|
||||
NativeValue *ParseAbilityMonitorPara(
|
||||
NativeEngine &engine, NativeCallbackInfo &info, std::shared_ptr<AbilityMonitor> &monitor);
|
||||
NativeValue *ParseWaitAbilityMonitorPara(NativeEngine &engine, NativeCallbackInfo &info,
|
||||
std::shared_ptr<AbilityMonitor> &monitor, TimeoutCallback &opt, int64_t &timeout);
|
||||
NativeValue *ParseTimeoutCallbackPara(
|
||||
NativeEngine &engine, NativeCallbackInfo &info, TimeoutCallback &opt, int64_t &timeout);
|
||||
NativeValue *ParsePrintPara(NativeEngine &engine, NativeCallbackInfo &info, std::string &msg);
|
||||
NativeValue *ParseExecuteShellCommandPara(
|
||||
NativeEngine &engine, NativeCallbackInfo &info, std::string &cmd, TimeoutCallback &opt, int64_t &timeout);
|
||||
NativeValue *ParseAbilityCommonPara(
|
||||
NativeEngine &engine, NativeCallbackInfo &info, sptr<OHOS::IRemoteObject> &remoteObject);
|
||||
NativeValue *ParseAbilityCommonRemainingPara(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue *ParseFinishTestPara(NativeEngine &engine, NativeCallbackInfo &info, std::string &msg, int64_t &code);
|
||||
};
|
||||
} // namespace AbilityDelegatorJs
|
||||
} // namespace OHOS
|
||||
|
@ -24,10 +24,8 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityDelegatorJs {
|
||||
using namespace OHOS::AppExecFwk;
|
||||
using namespace OHOS::AbilityRuntime;
|
||||
namespace {
|
||||
constexpr int32_t ARGC_ONE = 1;
|
||||
class JsAbilityDelegatorRegistry {
|
||||
public:
|
||||
JsAbilityDelegatorRegistry() = default;
|
||||
@ -35,7 +33,7 @@ public:
|
||||
|
||||
static void Finalizer(NativeEngine *engine, void *data, void *hint)
|
||||
{
|
||||
HILOG_INFO("JsAbilityDelegatorRegistry::Finalizer is called");
|
||||
HILOG_INFO("enter");
|
||||
std::unique_ptr<JsAbilityDelegatorRegistry>(static_cast<JsAbilityDelegatorRegistry *>(data));
|
||||
}
|
||||
|
||||
@ -54,41 +52,32 @@ public:
|
||||
private:
|
||||
NativeValue *OnGetAbilityDelegator(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOG_INFO("OnGetAbilityDelegator is called, argc = %{public}d", static_cast<int>(info.argc));
|
||||
|
||||
AsyncTask::CompleteCallback complete = [](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
HILOG_INFO("OnGetAbilityDelegator AsyncTask::CompleteCallback");
|
||||
task.Resolve(engine, CreateJsAbilityDelegator(engine));
|
||||
};
|
||||
NativeValue *lastParam = (info.argc == ARGC_ONE) ? info.argv[0] : nullptr;
|
||||
NativeValue *result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
HILOG_INFO("enter");
|
||||
if (!AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator()) {
|
||||
HILOG_ERROR("Failed to get delegator object");
|
||||
return engine.CreateNull();
|
||||
}
|
||||
return CreateJsAbilityDelegator(engine);
|
||||
}
|
||||
|
||||
NativeValue *OnGetArguments(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOG_INFO("OnGetArguments is called, argc = %{public}d", static_cast<int>(info.argc));
|
||||
HILOG_INFO("enter");
|
||||
|
||||
AsyncTask::CompleteCallback complete = [](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
std::shared_ptr<AppExecFwk::AbilityDelegatorArgs> abilityDelegatorArgs =
|
||||
AppExecFwk::AbilityDelegatorRegistry::GetArguments();
|
||||
task.Resolve(engine, CreateJsAbilityDelegatorArguments(engine, abilityDelegatorArgs));
|
||||
};
|
||||
|
||||
NativeValue *lastParam = (info.argc == ARGC_ONE) ? info.argv[0] : nullptr;
|
||||
NativeValue *result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
std::shared_ptr<AppExecFwk::AbilityDelegatorArgs> abilityDelegatorArgs =
|
||||
AppExecFwk::AbilityDelegatorRegistry::GetArguments();
|
||||
if (!abilityDelegatorArgs) {
|
||||
HILOG_ERROR("Failed to get delegator args object");
|
||||
return engine.CreateNull();
|
||||
}
|
||||
return CreateJsAbilityDelegatorArguments(engine, abilityDelegatorArgs);
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
NativeValue *JsAbilityDelegatorRegistryInit(NativeEngine *engine, NativeValue *exportObj)
|
||||
{
|
||||
HILOG_INFO("JsAbilityDelegatorManagerInit is called");
|
||||
HILOG_INFO("enter");
|
||||
if (engine == nullptr || exportObj == nullptr) {
|
||||
HILOG_ERROR("Invalid input parameters");
|
||||
return nullptr;
|
||||
@ -107,7 +96,34 @@ NativeValue *JsAbilityDelegatorRegistryInit(NativeEngine *engine, NativeValue *e
|
||||
BindNativeFunction(*engine, *object, "getAbilityDelegator", JsAbilityDelegatorRegistry::GetAbilityDelegator);
|
||||
BindNativeFunction(*engine, *object, "getArguments", JsAbilityDelegatorRegistry::GetArguments);
|
||||
|
||||
object->SetProperty("AbilityLifecycleState", AbilityLifecycleStateInit(engine));
|
||||
|
||||
return engine->CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue *AbilityLifecycleStateInit(NativeEngine *engine)
|
||||
{
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (engine == nullptr) {
|
||||
HILOG_ERROR("Invalid input parameters");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *objValue = engine->CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
object->SetProperty("CREATE", CreateJsValue(*engine, (int32_t)AbilityLifecycleState::CREATE));
|
||||
object->SetProperty("FOREGROUND", CreateJsValue(*engine, (int32_t)AbilityLifecycleState::FOREGROUND));
|
||||
object->SetProperty("BACKGROUND", CreateJsValue(*engine, (int32_t)AbilityLifecycleState::BACKGROUND));
|
||||
object->SetProperty("DESTROY", CreateJsValue(*engine, (int32_t)AbilityLifecycleState::DESTROY));
|
||||
|
||||
return objValue;
|
||||
}
|
||||
} // namespace AbilityDelegatorJs
|
||||
} // namespace OHOS
|
@ -20,7 +20,16 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityDelegatorJs {
|
||||
enum class AbilityLifecycleState {
|
||||
UNINITIALIZED,
|
||||
CREATE,
|
||||
FOREGROUND,
|
||||
BACKGROUND,
|
||||
DESTROY,
|
||||
};
|
||||
|
||||
NativeValue *JsAbilityDelegatorRegistryInit(NativeEngine *engine, NativeValue *exportObj);
|
||||
NativeValue *AbilityLifecycleStateInit(NativeEngine *engine);
|
||||
} // namespace AbilityDelegatorJs
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_DELEGATOR_ABILITY_DELEGATOR_REGISTRY_H
|
@ -26,13 +26,13 @@ namespace AbilityDelegatorJs {
|
||||
using namespace OHOS::AbilityRuntime;
|
||||
NativeValue *CreateJsAbilityDelegator(NativeEngine &engine)
|
||||
{
|
||||
HILOG_INFO("CreateJsAbilityDelegator is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return nullptr;
|
||||
return engine.CreateNull();
|
||||
}
|
||||
|
||||
std::unique_ptr<JSAbilityDelegator> jsAbilityDelegator = std::make_unique<JSAbilityDelegator>();
|
||||
@ -54,7 +54,7 @@ NativeValue *CreateJsAbilityDelegator(NativeEngine &engine)
|
||||
|
||||
NativeValue *SetAbilityDelegatorArgumentsPara(NativeEngine &engine, const std::map<std::string, std::string> ¶s)
|
||||
{
|
||||
HILOG_INFO("SetAbilityDelegatorArgumentsPara is called");
|
||||
HILOG_INFO("enter");
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
@ -72,13 +72,13 @@ NativeValue *SetAbilityDelegatorArgumentsPara(NativeEngine &engine, const std::m
|
||||
NativeValue *CreateJsAbilityDelegatorArguments(
|
||||
NativeEngine &engine, const std::shared_ptr<AbilityDelegatorArgs> &abilityDelegatorArgs)
|
||||
{
|
||||
HILOG_INFO("CreateJsAbilityDelegatorArguments is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return nullptr;
|
||||
return engine.CreateNull();
|
||||
}
|
||||
|
||||
object->SetProperty("bundleName", CreateJsValue(engine, abilityDelegatorArgs->GetTestBundleName()));
|
||||
@ -90,32 +90,15 @@ NativeValue *CreateJsAbilityDelegatorArguments(
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue *CreateJsAbilityState(NativeEngine &engine, AbilityDelegator::AbilityState &lifeState)
|
||||
{
|
||||
HILOG_INFO("CreateJsAbilityState is called");
|
||||
NativeValue *objValue = CreateJsValue(engine, static_cast<int>(lifeState));
|
||||
if (!objValue) {
|
||||
HILOG_ERROR("CreateJsAbilityState objValue is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue *CreateJsBool(NativeEngine &engine, bool &flag)
|
||||
{
|
||||
HILOG_INFO("CreateJsBool is called");
|
||||
NativeValue *objValue = CreateJsValue(engine, static_cast<bool>(flag));
|
||||
if (!objValue) {
|
||||
HILOG_ERROR("CreateJsBool objValue is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue *CreateJsShellCmdResult(NativeEngine &engine, std::unique_ptr<ShellCmdResult> &shellResult)
|
||||
{
|
||||
HILOG_INFO("CreateJsShellCmdResult is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (!shellResult) {
|
||||
HILOG_ERROR("shellResult is null");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
|
@ -25,12 +25,9 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityDelegatorJs {
|
||||
using namespace OHOS::AppExecFwk;
|
||||
NativeValue *CreateJsAbilityDelegator(NativeEngine &engine);
|
||||
NativeValue *CreateJsAbilityDelegatorArguments(
|
||||
NativeEngine &engine, const std::shared_ptr<AbilityDelegatorArgs> &abilityDelegatorArgs);
|
||||
NativeValue *CreateJsAbilityState(NativeEngine &engine, AbilityDelegator::AbilityState &lifeState);
|
||||
NativeValue *CreateJsBool(NativeEngine &engine, bool &flag);
|
||||
NativeValue *CreateJsShellCmdResult(NativeEngine &engine, std::unique_ptr<ShellCmdResult> &shellResult);
|
||||
} // namespace AbilityDelegatorJs
|
||||
} // namespace OHOS
|
||||
|
@ -26,7 +26,7 @@ JSAbilityMonitor::JSAbilityMonitor(const std::string &abilityName) : abilityName
|
||||
|
||||
void JSAbilityMonitor::onAbilityCreate()
|
||||
{
|
||||
HILOG_INFO("onAbilityCreate is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (jsAbilityMonitor_ == nullptr) {
|
||||
HILOG_ERROR("jsAbilityMonitor_ nullptr");
|
||||
@ -48,12 +48,12 @@ void JSAbilityMonitor::onAbilityCreate()
|
||||
|
||||
NativeValue* argv[] = {};
|
||||
engine_->CallFunction(value, method, argv, 0);
|
||||
HILOG_INFO("onAbilityCreate is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
|
||||
void JSAbilityMonitor::onAbilityForeground()
|
||||
{
|
||||
HILOG_INFO("onAbilityForeground is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (jsAbilityMonitor_ == nullptr) {
|
||||
HILOG_ERROR("jsAbilityMonitor_ nullptr");
|
||||
@ -75,12 +75,12 @@ void JSAbilityMonitor::onAbilityForeground()
|
||||
|
||||
NativeValue *argv[] = {};
|
||||
engine_->CallFunction(value, method, argv, 0);
|
||||
HILOG_INFO("onAbilityForeground is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
|
||||
void JSAbilityMonitor::onAbilityBackground()
|
||||
{
|
||||
HILOG_INFO("onAbilityBackground is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (jsAbilityMonitor_ == nullptr) {
|
||||
HILOG_ERROR("jsAbilityMonitor_ nullptr");
|
||||
@ -102,12 +102,12 @@ void JSAbilityMonitor::onAbilityBackground()
|
||||
|
||||
NativeValue *argv[] = {};
|
||||
engine_->CallFunction(value, method, argv, 0);
|
||||
HILOG_INFO("onAbilityBackground is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
|
||||
void JSAbilityMonitor::onAbilityDestroy()
|
||||
{
|
||||
HILOG_INFO("onAbilityDestroy is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (jsAbilityMonitor_ == nullptr) {
|
||||
HILOG_ERROR("jsAbilityMonitor_ nullptr");
|
||||
@ -129,12 +129,12 @@ void JSAbilityMonitor::onAbilityDestroy()
|
||||
|
||||
NativeValue *argv[] = {};
|
||||
engine_->CallFunction(value, method, argv, 0);
|
||||
HILOG_INFO("onAbilityDestroy is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
|
||||
void JSAbilityMonitor::onWindowStageCreate()
|
||||
{
|
||||
HILOG_INFO("onWindowStageCreate is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (jsAbilityMonitor_ == nullptr) {
|
||||
HILOG_ERROR("jsAbilityMonitor_ nullptr");
|
||||
@ -156,12 +156,12 @@ void JSAbilityMonitor::onWindowStageCreate()
|
||||
|
||||
NativeValue *argv[] = {};
|
||||
engine_->CallFunction(value, method, argv, 0);
|
||||
HILOG_INFO("onWindowStageCreate is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
|
||||
void JSAbilityMonitor::onWindowStageRestore()
|
||||
{
|
||||
HILOG_INFO("onWindowStageRestore is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
if (jsAbilityMonitor_ == nullptr) {
|
||||
HILOG_ERROR("jsAbilityMonitor_ nullptr");
|
||||
@ -183,12 +183,12 @@ void JSAbilityMonitor::onWindowStageRestore()
|
||||
|
||||
NativeValue *argv[] = {};
|
||||
engine_->CallFunction(value, method, argv, 0);
|
||||
HILOG_INFO("onWindowStageRestore is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
|
||||
void JSAbilityMonitor::onWindowStageDestroy()
|
||||
{
|
||||
HILOG_INFO("onWindowStageDestroy is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
NativeValue *value = jsAbilityMonitor_->Get();
|
||||
NativeObject *obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
@ -205,12 +205,12 @@ void JSAbilityMonitor::onWindowStageDestroy()
|
||||
|
||||
NativeValue *argv[] = {};
|
||||
engine_->CallFunction(value, method, argv, 0);
|
||||
HILOG_INFO("onWindowStageDestroy is called end");
|
||||
HILOG_INFO("end");
|
||||
}
|
||||
|
||||
void JSAbilityMonitor::SetJsAbilityMonitor(NativeValue *jsAbilityMonitor)
|
||||
{
|
||||
HILOG_INFO("SetJsAbilityMonitor is called");
|
||||
HILOG_INFO("enter");
|
||||
|
||||
jsAbilityMonitor_ = std::unique_ptr<NativeReference>(engine_->CreateReference(jsAbilityMonitor, 1));
|
||||
}
|
||||
|
@ -629,8 +629,7 @@ public:
|
||||
|
||||
virtual int StartUserTest(const Want &want, const sptr<IRemoteObject> &observer) override;
|
||||
|
||||
virtual int FinishUserTest(const std::string &msg, const int &resultCode,
|
||||
const std::string &bundleName, const sptr<IRemoteObject> &observer) override;
|
||||
virtual int FinishUserTest(const std::string &msg, const int &resultCode, const std::string &bundleName) override;
|
||||
|
||||
/**
|
||||
* GetCurrentTopAbility, get the token of current top ability.
|
||||
@ -655,7 +654,7 @@ public:
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int DelegatorDoAbilityBackground(const sptr<IRemoteObject> &token) override;
|
||||
|
||||
|
||||
/**
|
||||
* Calls this interface to move the ability to the foreground.
|
||||
*
|
||||
|
@ -811,8 +811,7 @@ public:
|
||||
|
||||
virtual int StartUserTest(const Want &want, const sptr<IRemoteObject> &observer) override;
|
||||
|
||||
virtual int FinishUserTest(const std::string &msg, const int &resultCode,
|
||||
const std::string &bundleName, const sptr<IRemoteObject> &observer) override;
|
||||
virtual int FinishUserTest(const std::string &msg, const int &resultCode, const std::string &bundleName) override;
|
||||
|
||||
/**
|
||||
* GetCurrentTopAbility, get the token of current top ability.
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include <unordered_set>
|
||||
|
||||
#include "ability_info.h"
|
||||
// #include "app_process_data.h"
|
||||
#include "appmgr/app_mgr_client.h"
|
||||
#include "appmgr/app_state_callback_host.h"
|
||||
#include "appmgr/start_specified_ability_response_stub.h"
|
||||
@ -254,6 +253,17 @@ public:
|
||||
*/
|
||||
int StartUserTest(const Want &want, const sptr<IRemoteObject> &observer, const AppExecFwk::BundleInfo &bundleInfo);
|
||||
|
||||
/**
|
||||
* @brief Finish user test.
|
||||
* @param msg user test message.
|
||||
* @param resultCode user test result Code.
|
||||
* @param bundleName user test bundleName.
|
||||
* @param pid the user test process id.
|
||||
*
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int FinishUserTest(const std::string &msg, const int &resultCode, const std::string &bundleName, const pid_t &pid);
|
||||
|
||||
int GetProcessRunningInfosByUserId(std::vector<AppExecFwk::RunningProcessInfo> &info, int32_t userId);
|
||||
std::string ConvertAppState(const AppState &state);
|
||||
|
||||
|
@ -893,13 +893,13 @@ ErrCode AbilityManagerClient::StartUserTest(const Want &want, const sptr<IRemote
|
||||
return abms->StartUserTest(want, observer);
|
||||
}
|
||||
|
||||
ErrCode AbilityManagerClient::FinishUserTest(const std::string &msg, const int &resultCode,
|
||||
const std::string &bundleName, const sptr<IRemoteObject> &observer)
|
||||
ErrCode AbilityManagerClient::FinishUserTest(
|
||||
const std::string &msg, const int &resultCode, const std::string &bundleName)
|
||||
{
|
||||
CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED);
|
||||
|
||||
sptr<IAbilityManager> abms = iface_cast<IAbilityManager>(remoteObject_);
|
||||
return abms->FinishUserTest(msg, resultCode, bundleName, observer);
|
||||
return abms->FinishUserTest(msg, resultCode, bundleName);
|
||||
}
|
||||
|
||||
ErrCode AbilityManagerClient::GetCurrentTopAbility(sptr<IRemoteObject> &token)
|
||||
|
@ -2486,8 +2486,7 @@ int AbilityManagerProxy::StartUserTest(const Want &want, const sptr<IRemoteObjec
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int AbilityManagerProxy::FinishUserTest(const std::string &msg, const int &resultCode,
|
||||
const std::string &bundleName, const sptr<IRemoteObject> &observer)
|
||||
int AbilityManagerProxy::FinishUserTest(const std::string &msg, const int &resultCode, const std::string &bundleName)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@ -2508,10 +2507,7 @@ int AbilityManagerProxy::FinishUserTest(const std::string &msg, const int &resul
|
||||
HILOG_ERROR("bundleName write failed.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
if (!data.WriteParcelable(observer)) {
|
||||
HILOG_ERROR("observer write failed.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
auto error = Remote()->SendRequest(IAbilityManager::FINISH_USER_TEST, data, reply, option);
|
||||
if (error != NO_ERROR) {
|
||||
HILOG_ERROR("Send request error: %{public}d", error);
|
||||
|
@ -4181,23 +4181,15 @@ int AbilityManagerService::StartUserTest(const Want &want, const sptr<IRemoteObj
|
||||
return DelayedSingleton<AppScheduler>::GetInstance()->StartUserTest(want, observer, bundleInfo);
|
||||
}
|
||||
|
||||
int AbilityManagerService::FinishUserTest(const std::string &msg, const int &resultCode,
|
||||
const std::string &bundleName, const sptr<IRemoteObject> &observer)
|
||||
int AbilityManagerService::FinishUserTest(const std::string &msg, const int &resultCode, const std::string &bundleName)
|
||||
{
|
||||
HILOG_DEBUG("enter");
|
||||
int ret = KillProcess(bundleName);
|
||||
if (ret) {
|
||||
HILOG_ERROR("Failed to kill process.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
sptr<ITestObserver> observerProxy = iface_cast<ITestObserver>(observer);
|
||||
if (!observerProxy) {
|
||||
HILOG_ERROR("Failed to get ITestObserver proxy");
|
||||
if (bundleName.empty()) {
|
||||
HILOG_ERROR("Invalid bundle name.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
observerProxy->TestFinished(msg, resultCode);
|
||||
return ERR_OK;
|
||||
pid_t callingPid = IPCSkeleton::GetCallingPid();
|
||||
return DelayedSingleton<AppScheduler>::GetInstance()->FinishUserTest(msg, resultCode, bundleName, callingPid);
|
||||
}
|
||||
|
||||
int AbilityManagerService::GetCurrentTopAbility(sptr<IRemoteObject> &token)
|
||||
|
@ -1461,8 +1461,7 @@ int AbilityManagerStub::FinishUserTestInner(MessageParcel &data, MessageParcel &
|
||||
std::string msg = data.ReadString();
|
||||
int resultCode = data.ReadInt32();
|
||||
std::string bundleName = data.ReadString();
|
||||
auto observer = data.ReadParcelable<IRemoteObject>();
|
||||
int32_t result = FinishUserTest(msg, resultCode, bundleName, observer);
|
||||
int32_t result = FinishUserTest(msg, resultCode, bundleName);
|
||||
reply.WriteInt32(result);
|
||||
return result;
|
||||
}
|
||||
|
@ -317,6 +317,18 @@ int AppScheduler::StartUserTest(const Want &want, const sptr<IRemoteObject> &obs
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int AppScheduler::FinishUserTest(
|
||||
const std::string &msg, const int &resultCode, const std::string &bundleName, const pid_t &pid)
|
||||
{
|
||||
CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
|
||||
int ret = appMgrClient_->FinishUserTest(msg, resultCode, bundleName, pid);
|
||||
if (ret != ERR_OK) {
|
||||
HILOG_ERROR("Fail to start user test.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int AppScheduler::UpdateConfiguration(const AppExecFwk::Configuration &config)
|
||||
{
|
||||
CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
|
||||
|
@ -25,6 +25,7 @@ config("appmgr_config") {
|
||||
"//base/notification/ces_standard/interfaces/innerkits/native/include",
|
||||
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include",
|
||||
"//base/global/i18n_standard/frameworks/intl/include",
|
||||
"//foundation/aafwk/standard/tools/aa/include",
|
||||
]
|
||||
}
|
||||
|
||||
@ -71,6 +72,7 @@ ohos_shared_library("libams") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
deps = [
|
||||
"${aafwk_path}/interfaces/innerkits/ability_manager:ability_manager",
|
||||
"${aafwk_path}/interfaces/innerkits/app_manager:app_manager",
|
||||
"${appexecfwk_path}/common:libappexecfwk_common",
|
||||
"${appexecfwk_path}/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
|
@ -185,6 +185,18 @@ public:
|
||||
virtual int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer,
|
||||
const AppExecFwk::BundleInfo &bundleInfo) override;
|
||||
|
||||
/**
|
||||
* @brief Finish user test.
|
||||
* @param msg user test message.
|
||||
* @param resultCode user test result Code.
|
||||
* @param bundleName user test bundleName.
|
||||
* @param pid the user test process id.
|
||||
*
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int FinishUserTest(
|
||||
const std::string &msg, const int &resultCode, const std::string &bundleName, const pid_t &pid) override;
|
||||
|
||||
virtual void ScheduleAcceptWantDone(
|
||||
const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override;
|
||||
|
||||
|
@ -433,7 +433,7 @@ public:
|
||||
void OnAppStateChanged(const std::shared_ptr<AppRunningRecord> &appRecord, const ApplicationState state);
|
||||
|
||||
void GetRunningProcessInfoByToken(const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info);
|
||||
|
||||
|
||||
/**
|
||||
* UpdateConfiguration, ANotify application update system environment changes.
|
||||
*
|
||||
@ -482,6 +482,17 @@ public:
|
||||
int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer,
|
||||
const AppExecFwk::BundleInfo &bundleInfo);
|
||||
|
||||
/**
|
||||
* @brief Finish user test.
|
||||
* @param msg user test message.
|
||||
* @param resultCode user test result Code.
|
||||
* @param bundleName user test bundleName.
|
||||
* @param pid the user test process id.
|
||||
*
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int FinishUserTest(const std::string &msg, const int &resultCode, const std::string &bundleName, const pid_t &pid);
|
||||
|
||||
void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo);
|
||||
|
||||
void RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response);
|
||||
@ -715,6 +726,8 @@ private:
|
||||
void NotifyAppStatus(const std::string &bundleName, const std::string &eventData);
|
||||
void KillApplicationByRecord(const std::shared_ptr<AppRunningRecord> &appRecord);
|
||||
void SendHiSysEvent(const int32_t innerEventId, const int64_t eventId);
|
||||
int FinishUserTestLocked(
|
||||
const std::string &msg, const int &resultCode, std::shared_ptr<AppRunningRecord> &appRecord);
|
||||
const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask";
|
||||
std::vector<sptr<IApplicationStateObserver>> appStateObservers_;
|
||||
std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>> recipientMap_;
|
||||
@ -725,7 +738,7 @@ private:
|
||||
std::shared_ptr<AppRunningManager> appRunningManager_;
|
||||
std::shared_ptr<AMSEventHandler> eventHandler_;
|
||||
std::shared_ptr<Configuration> configuration_;
|
||||
std::mutex serviceLock_;
|
||||
std::mutex userTestLock_;
|
||||
sptr<IStartSpecifiedAbilityResponse> startSpecifiedAbilityResponse_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
|
@ -478,7 +478,8 @@ public:
|
||||
|
||||
void GetBundleNames(std::vector<std::string> &bundleNames);
|
||||
|
||||
void SetUserTestInfo(const UserTestRecord &record);
|
||||
void SetUserTestInfo(const std::shared_ptr<UserTestRecord> &record);
|
||||
std::shared_ptr<UserTestRecord> GetUserTestInfo();
|
||||
|
||||
void SetSpecifiedAbilityFlagAndWant(const bool flag, const AAFwk::Want &want, const std::string &moduleName);
|
||||
bool IsStartSpecifiedAbility() const;
|
||||
@ -570,7 +571,7 @@ private:
|
||||
std::string moduleName_;
|
||||
bool isDebugApp_ = false;
|
||||
|
||||
UserTestRecord userTestRecord_;
|
||||
std::shared_ptr<UserTestRecord> userTestRecord_ = nullptr;
|
||||
|
||||
// render record
|
||||
std::shared_ptr<RenderRecord> renderRecord_ = nullptr;
|
||||
|
@ -44,6 +44,7 @@ const std::string TASK_CLEAR_UP_APPLICATION_DATA = "ClearUpApplicationDataTask";
|
||||
const std::string TASK_STARTUP_RESIDENT_PROCESS = "StartupResidentProcess";
|
||||
const std::string TASK_ADD_ABILITY_STAGE_DONE = "AddAbilityStageDone";
|
||||
const std::string TASK_START_USER_TEST_PROCESS = "StartUserTestProcess";
|
||||
const std::string TASK_FINISH_USER_TEST = "FinishUserTest";
|
||||
const std::string TASK_ATTACH_RENDER_PROCESS = "AttachRenderTask";
|
||||
} // namespace
|
||||
|
||||
@ -363,6 +364,18 @@ int AppMgrService::StartUserTestProcess(const AAFwk::Want &want, const sptr<IRem
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int AppMgrService::FinishUserTest(
|
||||
const std::string &msg, const int &resultCode, const std::string &bundleName, const pid_t &pid)
|
||||
{
|
||||
if (!IsReady()) {
|
||||
return ERR_INVALID_OPERATION;
|
||||
}
|
||||
std::function<void()> finishUserTestProcessFunc =
|
||||
std::bind(&AppMgrServiceInner::FinishUserTest, appMgrServiceInner_, msg, resultCode, bundleName, pid);
|
||||
handler_->PostTask(finishUserTestProcessFunc, TASK_FINISH_USER_TEST);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void AppMgrService::ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag)
|
||||
{
|
||||
if (!IsReady()) {
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "datetime_ex.h"
|
||||
#include "perf_profile.h"
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "app_process_data.h"
|
||||
#include "bundle_constants.h"
|
||||
#include "bytrace.h"
|
||||
@ -32,9 +33,10 @@
|
||||
#include "common_event_manager.h"
|
||||
#include "common_event_support.h"
|
||||
#include "hisysevent.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iremote_object.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "itest_observer.h"
|
||||
#include "os_account_manager.h"
|
||||
#include "permission/permission_kit.h"
|
||||
#include "permission_constants.h"
|
||||
@ -1350,31 +1352,33 @@ void AppMgrServiceInner::OnRemoteDied(const wptr<IRemoteObject> &remote, bool is
|
||||
}
|
||||
|
||||
auto appRecord = appRunningManager_->OnRemoteDied(remote);
|
||||
if (appRecord) {
|
||||
// clear uri permission
|
||||
auto upmClient = AAFwk::UriPermissionManagerClient::GetInstance();
|
||||
auto appInfo = appRecord->GetApplicationInfo();
|
||||
if (appInfo && upmClient) {
|
||||
upmClient->RemoveUriPermission(appInfo->accessTokenId);
|
||||
}
|
||||
|
||||
for (const auto &item : appRecord->GetAbilities()) {
|
||||
const auto &abilityRecord = item.second;
|
||||
appRecord->StateChangedNotifyObserver(abilityRecord,
|
||||
static_cast<int32_t>(AbilityState::ABILITY_STATE_TERMINATED), true);
|
||||
}
|
||||
RemoveAppFromRecentListById(appRecord->GetRecordId());
|
||||
OnProcessDied(appRecord);
|
||||
|
||||
// kill render if exist.
|
||||
auto renderRecord = appRecord->GetRenderRecord();
|
||||
if (renderRecord && renderRecord->GetPid() > 0) {
|
||||
APP_LOGD("Kill render process when webviehost died.");
|
||||
KillProcessByPid(renderRecord->GetPid());
|
||||
}
|
||||
if (!appRecord) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (appRecord && appRecord->IsKeepAliveApp()) {
|
||||
// clear uri permission
|
||||
auto upmClient = AAFwk::UriPermissionManagerClient::GetInstance();
|
||||
auto appInfo = appRecord->GetApplicationInfo();
|
||||
if (appInfo && upmClient) {
|
||||
upmClient->RemoveUriPermission(appInfo->accessTokenId);
|
||||
}
|
||||
|
||||
for (const auto &item : appRecord->GetAbilities()) {
|
||||
const auto &abilityRecord = item.second;
|
||||
appRecord->StateChangedNotifyObserver(abilityRecord,
|
||||
static_cast<int32_t>(AbilityState::ABILITY_STATE_TERMINATED), true);
|
||||
}
|
||||
RemoveAppFromRecentListById(appRecord->GetRecordId());
|
||||
OnProcessDied(appRecord);
|
||||
|
||||
// kill render if exist.
|
||||
auto renderRecord = appRecord->GetRenderRecord();
|
||||
if (renderRecord && renderRecord->GetPid() > 0) {
|
||||
APP_LOGD("Kill render process when webviehost died.");
|
||||
KillProcessByPid(renderRecord->GetPid());
|
||||
}
|
||||
|
||||
if (appRecord->IsKeepAliveApp()) {
|
||||
appRecord->DecRestartResidentProcCount();
|
||||
if (appRecord->CanRestartResidentProc()) {
|
||||
auto restartProcss = [appRecord, innerService = shared_from_this()]() {
|
||||
@ -1388,6 +1392,8 @@ void AppMgrServiceInner::OnRemoteDied(const wptr<IRemoteObject> &remote, bool is
|
||||
eventHandler_->PostTask(restartProcss, "RestartResidentProcess");
|
||||
}
|
||||
}
|
||||
|
||||
FinishUserTestLocked("App died", -1, appRecord);
|
||||
}
|
||||
|
||||
void AppMgrServiceInner::PushAppFront(const int32_t recordId)
|
||||
@ -1869,9 +1875,14 @@ int32_t AppMgrServiceInner::GetForegroundApplications(std::vector<AppStateData>
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int AppMgrServiceInner::StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer,
|
||||
const BundleInfo &bundleInfo)
|
||||
int AppMgrServiceInner::StartUserTestProcess(
|
||||
const AAFwk::Want &want, const sptr<IRemoteObject> &observer, const BundleInfo &bundleInfo)
|
||||
{
|
||||
APP_LOGI("Enter");
|
||||
if (!observer) {
|
||||
APP_LOGE("observer nullptr.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
if (!appRunningManager_) {
|
||||
APP_LOGE("appRunningManager_ is nullptr");
|
||||
return ERR_INVALID_VALUE;
|
||||
@ -1908,9 +1919,14 @@ int AppMgrServiceInner::StartEmptyProcess(const AAFwk::Want &want, const sptr<IR
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
UserTestRecord testRecord;
|
||||
testRecord.want = want;
|
||||
testRecord.observer = observer;
|
||||
std::shared_ptr<UserTestRecord> testRecord = std::make_shared<UserTestRecord>();
|
||||
if (!testRecord) {
|
||||
APP_LOGE("Failed to make UserTestRecord!");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
testRecord->want = want;
|
||||
testRecord->observer = observer;
|
||||
testRecord->isFinished = false;
|
||||
appRecord->SetUserTestInfo(testRecord);
|
||||
|
||||
StartProcess(appInfo->name, processName, false, appRecord, appInfo->uid, appInfo->bundleName);
|
||||
@ -1928,6 +1944,66 @@ int AppMgrServiceInner::StartEmptyProcess(const AAFwk::Want &want, const sptr<IR
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int AppMgrServiceInner::FinishUserTest(
|
||||
const std::string &msg, const int &resultCode, const std::string &bundleName, const pid_t &pid)
|
||||
{
|
||||
APP_LOGI("Enter");
|
||||
if (bundleName.empty()) {
|
||||
APP_LOGE("Invalid bundle name.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
auto appRecord = GetAppRunningRecordByPid(pid);
|
||||
if (!appRecord) {
|
||||
APP_LOGE("no such appRecord");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
auto userTestRecord = appRecord->GetUserTestInfo();
|
||||
if (!userTestRecord) {
|
||||
APP_LOGE("unstart user test");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
FinishUserTestLocked(msg, resultCode, appRecord);
|
||||
|
||||
int ret = AAFwk::AbilityManagerClient::GetInstance()->KillProcess(bundleName);
|
||||
if (ret) {
|
||||
APP_LOGE("Failed to kill process.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int AppMgrServiceInner::FinishUserTestLocked(
|
||||
const std::string &msg, const int &resultCode, std::shared_ptr<AppRunningRecord> &appRecord)
|
||||
{
|
||||
APP_LOGI("Enter");
|
||||
if (!appRecord) {
|
||||
APP_LOGE("Invalid appRecord");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lck(userTestLock_);
|
||||
auto userTestRecord = appRecord->GetUserTestInfo();
|
||||
if (!userTestRecord) {
|
||||
APP_LOGW("unstart user test");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
if (!userTestRecord->isFinished) {
|
||||
sptr<ITestObserver> observerProxy = iface_cast<ITestObserver>(userTestRecord->observer);
|
||||
if (!observerProxy) {
|
||||
APP_LOGE("Failed to get ITestObserver proxy");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
observerProxy->TestFinished(msg, resultCode);
|
||||
|
||||
userTestRecord->isFinished = true;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void AppMgrServiceInner::StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo)
|
||||
{
|
||||
APP_LOGD("Start specified ability.");
|
||||
|
@ -971,11 +971,16 @@ void AppRunningRecord::GetBundleNames(std::vector<std::string> &bundleNames)
|
||||
}
|
||||
}
|
||||
|
||||
void AppRunningRecord::SetUserTestInfo(const UserTestRecord &record)
|
||||
void AppRunningRecord::SetUserTestInfo(const std::shared_ptr<UserTestRecord> &record)
|
||||
{
|
||||
userTestRecord_ = record;
|
||||
}
|
||||
|
||||
std::shared_ptr<UserTestRecord> AppRunningRecord::GetUserTestInfo()
|
||||
{
|
||||
return userTestRecord_;
|
||||
}
|
||||
|
||||
void AppRunningRecord::SetSpecifiedAbilityFlagAndWant(
|
||||
const bool flag, const AAFwk::Want &want, const std::string &moduleName)
|
||||
{
|
||||
|
@ -56,8 +56,14 @@ public:
|
||||
void(const int32_t recordId, const AAFwk::Want &want, const std::string &flag));
|
||||
MOCK_METHOD2(GetAbilityRecordsByProcessID, int(const int pid, std::vector<sptr<IRemoteObject>> &tokens));
|
||||
|
||||
virtual int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer,
|
||||
const BundleInfo &bundleInfo)
|
||||
virtual int StartUserTestProcess(
|
||||
const AAFwk::Want &want, const sptr<IRemoteObject> &observer, const BundleInfo &bundleInfo)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int FinishUserTest(
|
||||
const std::string &msg, const int &resultCode, const std::string &bundleName, const pid_t &pid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
virtual void TestFinished(const std::string &msg, const int &resultCode) override;
|
||||
virtual ShellCommandResult ExecuteShellCommand(
|
||||
const std::string &cmd, const int64_t timeoutMs) override;
|
||||
bool waitForFinish(const int64_t &timeoutMs);
|
||||
bool WaitForFinish(const int64_t &timeoutMs);
|
||||
|
||||
private:
|
||||
bool isFinished_;
|
||||
|
@ -1311,7 +1311,7 @@ ErrCode AbilityManagerShellCommand::StartUserTest(const std::map<std::string, st
|
||||
int time = std::stoi(want.GetStringParam("-w"));
|
||||
timeMs = time * TIME_RATE_MS;
|
||||
}
|
||||
if (!observer->waitForFinish(timeMs)) {
|
||||
if (!observer->WaitForFinish(timeMs)) {
|
||||
resultReceiver_ = "Timeout: user test is not completed within the specified time.\n";
|
||||
return OHOS::ERR_INVALID_VALUE;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ ShellCommandResult TestObserver::ExecuteShellCommand(const std::string &cmd, con
|
||||
return result;
|
||||
}
|
||||
|
||||
bool TestObserver::waitForFinish(const int64_t &timeoutMs)
|
||||
bool TestObserver::WaitForFinish(const int64_t &timeoutMs)
|
||||
{
|
||||
HILOG_INFO("enter");
|
||||
int64_t startTime = SystemTime::GetNowSysTime();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* 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
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* 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
|
||||
|
@ -24,10 +24,6 @@ ErrCode ZidlTestServiceProxy::TestIntTransaction(
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
data.WriteInt32(_data);
|
||||
|
||||
int32_t st = Remote()->SendRequest(COMMAND_TEST_INT_TRANSACTION, data, reply, option);
|
||||
@ -51,10 +47,6 @@ ErrCode ZidlTestServiceProxy::TestStringTransaction(
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
data.WriteString16(Str8ToStr16(_data));
|
||||
|
||||
int32_t st = Remote()->SendRequest(COMMAND_TEST_STRING_TRANSACTION, data, reply, option);
|
||||
|
@ -22,9 +22,6 @@ int ZidlTestServiceStub::OnRemoteRequest(
|
||||
/* [out] */ MessageParcel& reply,
|
||||
/* [in] */ MessageOption& option)
|
||||
{
|
||||
if (data.ReadInterfaceToken() != GetDescriptor()) {
|
||||
return ERR_TRANSACTION_FAILED;
|
||||
}
|
||||
switch (code) {
|
||||
case COMMAND_TEST_INT_TRANSACTION: {
|
||||
int _data = data.ReadInt32();
|
||||
|
Loading…
Reference in New Issue
Block a user