对应uitest连接返回值优化

Signed-off-by: Mupceet <laiguizhong@huawei.com>
This commit is contained in:
Mupceet 2022-05-17 16:46:24 +08:00
parent 4456c32502
commit 7a80a94a26
13 changed files with 39 additions and 28 deletions

View File

@ -46,9 +46,9 @@ public:
/**
* @brief Connect to AAMS. For UI test.
* @return Return true if the command of connection is sent successfully, else return false.
* @return Return RET_OK if the command of connection is sent successfully.
*/
virtual bool Connect() override;
virtual RetError Connect() override;
/**
* @brief disconnect to AAMS. For UI test.

View File

@ -78,18 +78,18 @@ bool AccessibilityUITestAbilityImpl::RegisterAbilityListener(const std::shared_p
return instance->RegisterAbilityListener(listener);
}
bool AccessibilityUITestAbilityImpl::Connect()
RetError AccessibilityUITestAbilityImpl::Connect()
{
HILOG_DEBUG("start.");
if (!serviceProxy_) {
HILOG_ERROR("Failed to get aams service");
return false;
return RET_ERR_SAMGR;
}
sptr<AccessibleAbilityClient> instance = AccessibleAbilityClient::GetInstance();
if (!instance) {
HILOG_ERROR("instance is nullptr");
return false;
return RET_ERR_NULLPTR;
}
return serviceProxy_->EnableUITestAbility(instance->GetRemoteObject());

View File

@ -94,7 +94,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, Connect_001, TestSize.Level1)
GTEST_LOG_(INFO) << "Cann't get AccessibilityUITestAbilityImpl instance_";
return;
}
EXPECT_TRUE(instance_->Connect());
EXPECT_EQ(instance_->Connect(), RET_OK);
GTEST_LOG_(INFO) << "Connect_001 end";
}

View File

@ -441,10 +441,10 @@ bool AccessibleAbilityManagerService::DisableAbilities(const std::string name)
return false;
}
bool AccessibleAbilityManagerService::EnableUITestAbility(const sptr<IRemoteObject>& obj)
RetError AccessibleAbilityManagerService::EnableUITestAbility(const sptr<IRemoteObject>& obj)
{
(void)obj;
return true;
return RET_OK;
}
bool AccessibleAbilityManagerService::DisableUITestAbility()

View File

@ -50,9 +50,9 @@ public:
/**
* @brief Connect to AAMS. For UI test.
* @return Return true if the command of connection is sent successfully, else return false.
* @return Return RET_OK if the command of connection is sent successfully.
*/
virtual bool Connect() = 0;
virtual RetError Connect() = 0;
/**
* @brief disconnect to AAMS. For UI test.

View File

@ -20,6 +20,15 @@
namespace OHOS {
namespace Accessibility {
enum RetError : int32_t {
RET_OK = 0,
RET_ERR_INVALID_PARAM = 1,
RET_ERR_NULLPTR = 2,
RET_ERR_CONNECTION_EXIST = 3,
RET_ERR_IPC_FAILED = 4,
RET_ERR_SAMGR = 5,
};
enum GlobalAction : uint32_t {
GLOBAL_ACTION_BACK = 0,
GLOBAL_ACTION_HOME = 1,

View File

@ -85,7 +85,7 @@ public:
std::vector<std::string> GetEnabledAbilities() override;
std::vector<AccessibilityAbilityInfo> GetInstalledAbilities() override;
bool DisableAbilities(const std::string name) override;
bool EnableUITestAbility(const sptr<IRemoteObject>& obj) override;
RetError EnableUITestAbility(const sptr<IRemoteObject>& obj) override;
bool DisableUITestAbility() override;
int32_t GetActiveWindow() override;

View File

@ -757,36 +757,36 @@ bool AccessibleAbilityManagerService::DisableAbilities(const std::string name)
return syncFuture.get();
}
bool AccessibleAbilityManagerService::EnableUITestAbility(const sptr<IRemoteObject> &obj)
RetError AccessibleAbilityManagerService::EnableUITestAbility(const sptr<IRemoteObject> &obj)
{
HILOG_DEBUG("start");
if (!handler_) {
HILOG_ERROR("handler_ is nullptr.");
return false;
return RET_ERR_NULLPTR;
}
std::promise<bool> syncPromise;
std::promise<RetError> syncPromise;
std::future syncFuture = syncPromise.get_future();
handler_->PostTask(std::bind([this, &syncPromise, obj]() -> void {
HILOG_DEBUG("start");
sptr<AccessibilityAccountData> accountData = GetCurrentAccountData();
if (!accountData) {
HILOG_ERROR("accountData is nullptr");
syncPromise.set_value(false);
syncPromise.set_value(RET_ERR_NULLPTR);
return;
}
std::string uiTestUri = "/" + UI_TEST_BUNDLE_NAME + "/" + UI_TEST_ABILITY_NAME;
sptr<AccessibleAbilityConnection> connection = accountData->GetAccessibleAbilityConnection(uiTestUri);
if (connection) {
HILOG_ERROR("connection is existed!!");
syncPromise.set_value(false);
syncPromise.set_value(RET_ERR_CONNECTION_EXIST);
return;
}
std::function<void()> addUITestClientFunc =
std::bind(&AccessibleAbilityManagerService::AddUITestClient, this, obj);
handler_->PostTask(addUITestClientFunc, "AddUITestClient");
syncPromise.set_value(true);
syncPromise.set_value(RET_OK);
}), "TASK_ENABLE_UI_TEST_ABILITIES");
return syncFuture.get();
}

View File

@ -630,10 +630,10 @@ bool AccessibleAbilityManagerService::DisableAbilities(const std::string name)
return syncFuture.get();
}
bool AccessibleAbilityManagerService::EnableUITestAbility(const sptr<IRemoteObject>& obj)
RetError AccessibleAbilityManagerService::EnableUITestAbility(const sptr<IRemoteObject>& obj)
{
(void)obj;
return true;
return RET_OK;
}
bool AccessibleAbilityManagerService::DisableUITestAbility()

View File

@ -103,7 +103,7 @@ public:
virtual bool DisableAbilities(const std::string name) override;
virtual int32_t GetActiveWindow() override;
virtual bool EnableUITestAbility(const sptr<IRemoteObject> &obj) override;
virtual RetError EnableUITestAbility(const sptr<IRemoteObject> &obj) override;
virtual bool DisableUITestAbility() override;
virtual bool SetScreenMagnificationState(const bool state) override;

View File

@ -101,7 +101,7 @@ public:
virtual bool DisableAbilities(const std::string name) = 0;
virtual int32_t GetActiveWindow() = 0;
virtual bool EnableUITestAbility(const sptr<IRemoteObject> &obj) = 0;
virtual RetError EnableUITestAbility(const sptr<IRemoteObject> &obj) = 0;
virtual bool DisableUITestAbility() = 0;
virtual bool SetScreenMagnificationState(const bool state) = 0;

View File

@ -537,7 +537,7 @@ int32_t AccessibleAbilityManagerServiceProxy::GetActiveWindow()
return reply.ReadInt32();
}
bool AccessibleAbilityManagerServiceProxy::EnableUITestAbility(const sptr<IRemoteObject> &obj)
RetError AccessibleAbilityManagerServiceProxy::EnableUITestAbility(const sptr<IRemoteObject> &obj)
{
HILOG_DEBUG("start");
MessageParcel data;
@ -546,20 +546,22 @@ bool AccessibleAbilityManagerServiceProxy::EnableUITestAbility(const sptr<IRemot
if (!WriteInterfaceToken(data)) {
HILOG_ERROR("fail, connection write Token");
return false;
return RET_ERR_IPC_FAILED;
}
if (!data.WriteRemoteObject(obj)) {
HILOG_ERROR("fail, connection write obj");
return false;
return RET_ERR_IPC_FAILED;
}
if (!SendTransactCmd(IAccessibleAbilityManagerService::Message::ENABLE_UI_TEST_ABILITY,
data, reply, option)) {
HILOG_ERROR("EnableUITestAbility fail");
return false;
return RET_ERR_IPC_FAILED;
}
return reply.ReadBool();
RetError result = static_cast<RetError>(reply.ReadInt32());
HILOG_DEBUG("enable result is %{public}d", result);
return result;
}
bool AccessibleAbilityManagerServiceProxy::DisableUITestAbility()

View File

@ -395,8 +395,8 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleEnableUITestAbility(
{
HILOG_DEBUG("start");
sptr<IRemoteObject> obj = data.ReadRemoteObject();
bool result = EnableUITestAbility(obj);
if (!reply.WriteBool(result)) {
int32_t result = EnableUITestAbility(obj);
if (!reply.WriteInt32(result)) {
HILOG_ERROR("WriteBool failed");
return TRANSACTION_ERR;
}