屏幕朗读状态查询订阅接口

Signed-off-by: 13359243081 <lanshulei@huawei.com>
This commit is contained in:
13359243081 2024-11-09 18:14:27 +08:00
parent 52b51c6692
commit cfab68ded2
27 changed files with 181 additions and 1 deletions

View File

@ -143,6 +143,7 @@ namespace Accessibility {
GET_FOCUSED_WINDOW_ID,
REMOVE_REQUEST_ID,
SERVICE_CODE_END,
GET_SCREEN_READER_STATE,
ON_STATE_CHANGED = 900,
};

View File

@ -168,6 +168,7 @@ public:
virtual void RemoveRequestId(int32_t requestId) override;
virtual int64_t GetRootParentId(int32_t windowsId, int32_t treeId) override;
virtual RetError GetAllTreeId(int32_t windowId, std::vector<int32_t> &treeIds) override;
virtual bool GetScreenReaderState() override;
private:
/**
* @brief Write the descriptor of IPC.

View File

@ -191,6 +191,7 @@ private:
ErrCode HandleGetRootParentId(MessageParcel &data, MessageParcel &reply);
ErrCode HandleGetAllTreeId(MessageParcel &data, MessageParcel &reply);
ErrCode HandleGetScreenReaderState(MessageParcel &data, MessageParcel &reply);
};
} // namespace Accessibility
} // namespace OHOS

View File

@ -192,6 +192,7 @@ public:
virtual int64_t GetRootParentId(int32_t windowsId, int32_t treeId) = 0;
virtual RetError GetAllTreeId(int32_t windowId, std::vector<int32_t> &treeIds) = 0;
virtual bool GetScreenReaderState() = 0;
};
} // namespace Accessibility
} // namespace OHOS

View File

@ -514,6 +514,25 @@ bool AccessibleAbilityManagerServiceProxy::GetKeyEventObserverState()
return reply.ReadBool();
}
bool AccessibleAbilityManagerServiceProxy::GetScreenReaderState()
{
HILOG_DEBUG();
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(data)) {
HILOG_ERROR("fail, connection write Token");
return false;
}
if (!SendTransactCmd(AccessibilityInterfaceCode::GET_SCREEN_READER_STATE,
data, reply, option)) {
HILOG_ERROR("GetScreenReaderState fail");
return false;
}
return reply.ReadBool();
}
RetError AccessibleAbilityManagerServiceProxy::EnableAbility(const std::string &name, const uint32_t capabilities)
{
HILOG_DEBUG();

View File

@ -110,7 +110,8 @@
SWITCH_CASE(AccessibilityInterfaceCode::GET_FOCUSED_WINDOW_ID, HandleGetFocusedWindowId) \
SWITCH_CASE(AccessibilityInterfaceCode::REMOVE_REQUEST_ID, HandleRemoveRequestId) \
SWITCH_CASE(AccessibilityInterfaceCode::GET_ROOT_PARENT_ID, HandleGetRootParentId) \
SWITCH_CASE(AccessibilityInterfaceCode::GET_ALL_TREE_ID, HandleGetAllTreeId)
SWITCH_CASE(AccessibilityInterfaceCode::GET_ALL_TREE_ID, HandleGetAllTreeId) \
SWITCH_CASE(AccessibilityInterfaceCode::GET_SCREEN_READER_STATE, HandleGetScreenReaderState)
namespace OHOS {
namespace Accessibility {
@ -462,6 +463,17 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetKeyEventObserverState(
return NO_ERROR;
}
ErrCode AccessibleAbilityManagerServiceStub::HandleGetScreenReaderState(
MessageParcel &data, MessageParcel &reply)
{
HILOG_DEBUG();
bool result = GetScreenReaderState();
reply.WriteBool(result);
return NO_ERROR;
}
ErrCode AccessibleAbilityManagerServiceStub::HandleEnableAbility(MessageParcel &data, MessageParcel &reply)
{
HILOG_DEBUG();

View File

@ -111,6 +111,10 @@ public:
{
return true;
}
bool GetScreenReaderState() override
{
return true;
}
RetError SetCaptionProperty(const AccessibilityConfig::CaptionProperty &caption) override
{

View File

@ -78,6 +78,13 @@ public:
*/
virtual RetError DeregisterElementOperator(const int32_t windowId, const int32_t treeId) override;
/**
* @brief Checks whether screenreader ability is enabled.
* @param isEnabled true: enabled; false: disabled
* @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
*/
virtual RetError IsScreenReaderEnabled(bool &isEnabled) override;
/**
* @brief Checks whether accessibility ability is enabled.
* @param isEnabled true: enabled; false: disabled

View File

@ -233,6 +233,9 @@ void AccessibilitySystemAbilityClientImpl::Init()
if (stateType & STATE_GESTURE_ENABLED) {
stateArray_[AccessibilityStateEventType::EVENT_GESTURE_STATE_CHANGED] = true;
}
if (stateType & STATE_SCREENREADER_ENABLED) {
stateArray_[AccessibilityStateEventType::EVENT_SCREEN_READER_STATE_CHANGED] = true;
}
}
void AccessibilitySystemAbilityClientImpl::ResetService(const wptr<IRemoteObject> &remote)
@ -357,6 +360,19 @@ RetError AccessibilitySystemAbilityClientImpl::DeregisterElementOperator(const i
return serviceProxy_->DeregisterElementOperator(windowId, treeId);
}
RetError AccessibilitySystemAbilityClientImpl::IsScreenReaderEnabled(bool &isEnabled)
{
HILOG_DEBUG();
std::lock_guard<ffrt::mutex> lock(mutex_);
if (serviceProxy_ == nullptr) {
HILOG_ERROR("Failed to get aams service");
return RET_ERR_SAMGR;
}
isEnabled = serviceProxy_->GetScreenReaderState();
return RET_OK;
}
RetError AccessibilitySystemAbilityClientImpl::IsEnabled(bool &isEnabled)
{
HILOG_DEBUG();
@ -545,6 +561,9 @@ void AccessibilitySystemAbilityClientImpl::OnAccessibleAbilityManagerStateChange
NotifyStateChanged(AccessibilityStateEventType::EVENT_GESTURE_STATE_CHANGED,
!!(stateType & STATE_GESTURE_ENABLED));
NotifyStateChanged(AccessibilityStateEventType::EVENT_SCREEN_READER_STATE_CHANGED,
!!(stateType & STATE_SCREENREADER_ENABLED));
}
void AccessibilitySystemAbilityClientImpl::SetSearchElementInfoByAccessibilityIdResult(

View File

@ -105,6 +105,7 @@ const uint32_t STATE_ANIMATIONOFF_ENABLED = 0x00000400;
const uint32_t STATE_AUDIOMONO_ENABLED = 0x00000800;
const uint32_t STATE_DALTONIZATION_STATE_ENABLED = 0x00001000;
const uint32_t STATE_IGNORE_REPEAT_CLICK_ENABLED = 0x00002000;
const uint32_t STATE_SCREENREADER_ENABLED = 0x00004000;
const int32_t INVALID_CHANNEL_ID = 0xFFFFFFFF;
} // namespace Accessibility

View File

@ -28,6 +28,7 @@ enum AccessibilityStateEventType : uint32_t {
EVENT_SCREEN_MAGNIFIER_CHANGED,
EVENT_AUTO_CLICK_CHANGED,
EVENT_SHORT_KEY_CHANGED,
EVENT_SCREEN_READER_STATE_CHANGED,
EVENT_TYPE_MAX,
};

View File

@ -88,6 +88,13 @@ public:
*/
virtual RetError DeregisterElementOperator(const int32_t windowId, const int32_t treeId) = 0;
/**
* @brief Checks whether screenreader ability is enabled.
* @param isEnabled true: enabled; false: disabled
* @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
*/
virtual RetError IsScreenReaderEnabled(bool &isEnabled)= 0;
/**
* @brief Checks whether accessibility ability is enabled.
* @param isEnabled true: enabled; false: disabled

View File

@ -109,6 +109,7 @@ extern const uint32_t STATE_ANIMATIONOFF_ENABLED;
extern const uint32_t STATE_DALTONIZATION_STATE_ENABLED;
extern const uint32_t STATE_AUDIOMONO_ENABLED;
extern const uint32_t STATE_IGNORE_REPEAT_CLICK_ENABLED;
extern const uint32_t STATE_SCREENREADER_ENABLED;
extern const int32_t INVALID_CHANNEL_ID;
} // namespace Accessibility
} // namespace OHOS

View File

@ -99,6 +99,7 @@ public:
static napi_value IsOpenAccessibilitySync(napi_env env, napi_callback_info info);
static napi_value IsOpenTouchExploration(napi_env env, napi_callback_info info);
static napi_value IsOpenTouchExplorationSync(napi_env env, napi_callback_info info);
static napi_value IsOpenScreenReaderSync(napi_env env, napi_callback_info info);
static napi_value GetAbilityList(napi_env env, napi_callback_info info);
static napi_value GetAccessibilityExtensionList(napi_env env, napi_callback_info info);
static napi_value GetAccessibilityExtensionListSync(napi_env env, napi_callback_info info);
@ -136,6 +137,7 @@ public:
static napi_ref aaStyleConsRef_;
static std::shared_ptr<StateListenerImpl> accessibilityStateListeners_;
static std::shared_ptr<StateListenerImpl> touchGuideStateListeners_;
static std::shared_ptr<StateListenerImpl> screenReaderStateListeners_;
static std::shared_ptr<NAccessibilityConfigObserverImpl> captionListeners_;
private:

View File

@ -39,6 +39,8 @@ std::shared_ptr<StateListenerImpl> NAccessibilityClient::accessibilityStateListe
std::make_shared<StateListenerImpl>(AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED);
std::shared_ptr<StateListenerImpl> NAccessibilityClient::touchGuideStateListeners_ =
std::make_shared<StateListenerImpl>(AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED);
std::shared_ptr<StateListenerImpl> NAccessibilityClient::screenReaderStateListeners_ =
std::make_shared<StateListenerImpl>(AccessibilityStateEventType::EVENT_SCREEN_READER_STATE_CHANGED);
std::shared_ptr<NAccessibilityConfigObserverImpl> NAccessibilityClient::captionListeners_ =
std::make_shared<NAccessibilityConfigObserverImpl>();
@ -56,6 +58,24 @@ do { \
} \
} while (0)
napi_value NAccessibilityClient::IsOpenScreenReaderSync(napi_env env, napi_callback_info info)
{
HILOG_INFO();
size_t argc = ARGS_SIZE_ONE;
napi_value argv = nullptr;
napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr);
ACCESSIBILITY_NAPI_ASSERT(env, argc == ARGS_SIZE_ZERO, OHOS::Accessibility::RET_ERR_INVALID_PARAM);
auto asaClient = AccessibilitySystemAbilityClient::GetInstance();
ACCESSIBILITY_NAPI_ASSERT(env, asaClient != nullptr, OHOS::Accessibility::RET_ERR_NULLPTR);
bool status = false;
auto ret = asaClient->IsScreenReaderEnabled(status);
ACCESSIBILITY_NAPI_ASSERT(env, ret == RET_OK, OHOS::Accessibility::RET_ERR_FAILED);
napi_value result = nullptr;
napi_get_boolean(env, status, &result);
return result;
}
napi_value NAccessibilityClient::IsOpenAccessibilitySync(napi_env env, napi_callback_info info)
{
HILOG_INFO();
@ -673,6 +693,9 @@ napi_value NAccessibilityClient::SubscribeState(napi_env env, napi_callback_info
case AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED:
touchGuideStateListeners_->SubscribeObserver(env, args[PARAM1]);
break;
case AccessibilityStateEventType::EVENT_SCREEN_READER_STATE_CHANGED:
screenReaderStateListeners_->SubscribeObserver(env, args[PARAM1]);
break;
default:
break;
}
@ -692,6 +715,8 @@ void NAccessibilityClient::GetAccessibilityStateEventType(
type = AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED;
} else if (std::strcmp(eventType.c_str(), "touchGuideStateChange") == 0) {
type = AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED;
} else if (std::strcmp(eventType.c_str(), "screenReaderStateChange") == 0) {
type = AccessibilityStateEventType::EVENT_SCREEN_READER_STATE_CHANGED;
} else {
HILOG_ERROR("SubscribeState eventType[%{public}s] is error", eventType.c_str());
errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM;
@ -737,6 +762,13 @@ napi_value NAccessibilityClient::UnsubscribeState(napi_env env, napi_callback_in
touchGuideStateListeners_->UnsubscribeObservers();
}
break;
case AccessibilityStateEventType::EVENT_SCREEN_READER_STATE_CHANGED:
if (argc >= ARGS_SIZE_TWO && CheckJsFunction(env, args[PARAM1])) {
screenReaderStateListeners_->UnsubscribeObserver(env, args[PARAM1]);
} else {
screenReaderStateListeners_->UnsubscribeObservers();
}
break;
default:
break;
}

View File

@ -48,6 +48,7 @@ static napi_value Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("isOpenAccessibilitySync", NAccessibilityClient::IsOpenAccessibilitySync),
DECLARE_NAPI_FUNCTION("isOpenTouchGuide", NAccessibilityClient::IsOpenTouchExploration),
DECLARE_NAPI_FUNCTION("isOpenTouchGuideSync", NAccessibilityClient::IsOpenTouchExplorationSync),
DECLARE_NAPI_FUNCTION("isOpenScreenReaderSync", NAccessibilityClient::IsOpenScreenReaderSync),
DECLARE_NAPI_FUNCTION("getAbilityLists", NAccessibilityClient::GetAbilityList),
DECLARE_NAPI_FUNCTION("getAccessibilityExtensionList", NAccessibilityClient::GetAccessibilityExtensionList),
DECLARE_NAPI_FUNCTION("getAccessibilityExtensionListSync",

View File

@ -253,6 +253,7 @@ public:
RetError EnableAbility(const std::string &name, const uint32_t capabilities);
void SetScreenReaderState(const std::string &name, const std::string &state);
bool GetScreenReaderState();
bool GetDefaultUserScreenReaderState();
AccountSA::OsAccountType GetAccountType();

View File

@ -147,6 +147,7 @@ public:
int32_t GenerateRequestId();
void GetElementOperatorConnection(sptr<AccessibilityWindowConnection> &connection,
const int64_t elementId, sptr<IAccessibilityElementOperator> &elementOperator);
bool GetScreenReaderState() override;
private:
int32_t focusWindowId_ = -1;
int64_t focusElementId_ = -1;

View File

@ -103,6 +103,11 @@ uint32_t AccessibilityAccountData::GetAccessibilityState()
if (config_->GetGestureState()) {
state |= STATE_GESTURE_ENABLED;
}
bool screenReaderState = GetScreenReaderState();
if (screenReaderState) {
state |= STATE_SCREENREADER_ENABLED;
}
return state;
}
@ -520,6 +525,19 @@ void AccessibilityAccountData::SetScreenReaderState(const std::string &name, con
}
}
bool AccessibilityAccountData::GetScreenReaderState()
{
HILOG_DEBUG();
std::shared_ptr<AccessibilitySettingProvider> service =
AccessibilitySettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID);
if (service == nullptr) {
return false;
}
bool screenReaderValue = false;
service->GetBoolValue(screenReaderKey_, screenReaderValue);
return screenReaderValue;
}
bool AccessibilityAccountData::GetDefaultUserScreenReaderState()
{
HILOG_DEBUG();

View File

@ -1241,6 +1241,16 @@ bool AccessibleAbilityManagerService::SetTargetAbility(const int32_t targetAbili
}
}
bool AccessibleAbilityManagerService::GetScreenReaderState()
{
sptr<AccessibilityAccountData> accountData = GetCurrentAccountData();
if (!accountData) {
HILOG_ERROR("accountData is nullptr");
return false;
}
return accountData->GetScreenReaderState();
}
RetError AccessibleAbilityManagerService::InnerEnableAbility(const std::string &name, const uint32_t capabilities)
{
HILOG_DEBUG();

View File

@ -92,6 +92,7 @@ public:
MOCK_METHOD0(GetTouchGuideState, bool());
MOCK_METHOD0(GetGestureState, bool());
MOCK_METHOD0(GetKeyEventObserverState, bool());
MOCK_METHOD0(GetScreenReaderState, bool());
MOCK_METHOD1(SetTouchGuideState, bool(const bool state));
MOCK_METHOD1(SetGestureState, bool(const bool state));
MOCK_METHOD1(SetKeyEventObserverState, bool(const bool state));

View File

@ -288,6 +288,12 @@ bool AccessibilityAccountData::GetDefaultUserScreenReaderState()
return true;
}
bool AccessibilityAccountData::GetScreenReaderState()
{
HILOG_DEBUG("start.");
return true;
}
void AccessibilityAccountData::Init()
{
HILOG_DEBUG("start.");

View File

@ -208,6 +208,11 @@ bool AccessibleAbilityManagerService::GetKeyEventObserverState()
return true;
}
bool AccessibleAbilityManagerService::GetScreenReaderState()
{
return true;
}
RetError AccessibleAbilityManagerService::EnableAbility(const std::string &name, const uint32_t capabilities)
{
(void)name;

View File

@ -1832,6 +1832,22 @@ HWTEST_F(AccessibilityAccountDataTest, AccessibilityAccountData_Unittest_SetScre
GTEST_LOG_(INFO) << "AccessibilityAccountData_Unittest_SetScreenReaderState_002 end";
}
/**
* @tc.number: AccessibilityAccountData_Unittest_GetScreenReaderState_001
* @tc.name: GetScreenReaderState
* @tc.desc: Check GetScreenReaderState.
*/
HWTEST_F(AccessibilityAccountDataTest, AccessibilityAccountData_Unittest_GetScreenReaderState_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibilityAccountData_Unittest_GetScreenReaderState_001 start";
const int32_t accountId = 1;
sptr<AccessibilityAccountData> accountData = new AccessibilityAccountData(accountId);
accountData->Init();
accountData->GetScreenReaderState();
GTEST_LOG_(INFO) << "AccessibilityAccountData_Unittest_GetScreenReaderState_001 end";
}
/**
* @tc.number: AccessibilityAccountData_Unittest_GetAbilityAutoStartState_001
* @tc.name: GetAbilityAutoStartState

View File

@ -151,6 +151,11 @@ bool MockAccessibleAbilityManagerServiceStub::GetTouchGuideState()
return true;
}
bool MockAccessibleAbilityManagerServiceStub::GetScreenReaderState()
{
return true;
}
bool MockAccessibleAbilityManagerServiceStub::GetGestureState()
{
return true;

View File

@ -65,6 +65,7 @@ public:
bool GetTouchGuideState() override;
bool GetGestureState() override;
bool GetKeyEventObserverState() override;
bool GetScreenReaderState() override;
RetError EnableAbility(const std::string &name, const uint32_t capabilities) override;
RetError GetEnabledAbilities(std::vector<std::string> &enabledAbilities) override;

View File

@ -288,6 +288,12 @@ bool MockAccessibilityAccountData::GetDefaultUserScreenReaderState()
return true;
}
bool MockAccessibilityAccountData::GetScreenReaderState()
{
HILOG_DEBUG("start.");
return true;
}
void MockAccessibilityAccountData::Init()
{
HILOG_DEBUG("start.");