mirror of
https://gitee.com/openharmony/distributeddatamgr_datamgr_service
synced 2024-11-23 14:59:46 +00:00
fix:add screenlock
Signed-off-by: htt1997 <hutao105@huawei.com>
This commit is contained in:
parent
bd30f271d2
commit
40ef0560c6
@ -80,6 +80,7 @@
|
||||
"resource_management",
|
||||
"safwk",
|
||||
"samgr",
|
||||
"screenlock_mgr",
|
||||
"time_service",
|
||||
"udmf",
|
||||
"app_file_service",
|
||||
|
@ -59,6 +59,7 @@ ohos_shared_library("distributeddata_adapter") {
|
||||
"//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/communicator:distributeddata_communicator_static",
|
||||
"//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/dfx:distributeddata_dfx_static",
|
||||
"//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/permission:distributeddata_permission_static",
|
||||
"//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/screenlock:distributeddata_screenlock_static",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef DISTRIBUTEDDATAMGR_ADAPTER_SCREEN_LOCK_H
|
||||
#define DISTRIBUTEDDATAMGR_ADAPTER_SCREEN_LOCK_H
|
||||
|
||||
#include "visibility.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedData {
|
||||
class ScreenLock {
|
||||
public:
|
||||
API_EXPORT static ScreenLock &GetInstance();
|
||||
API_EXPORT bool IsLocked();
|
||||
};
|
||||
} // namespace DistributedData
|
||||
} // namespace OHOS
|
||||
#endif //DISTRIBUTEDDATAMGR_ADAPTER_SCREEN_LOCK_H
|
41
services/distributeddataservice/adapter/screenlock/BUILD.gn
Normal file
41
services/distributeddataservice/adapter/screenlock/BUILD.gn
Normal file
@ -0,0 +1,41 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni")
|
||||
|
||||
ohos_static_library("distributeddata_screenlock_static") {
|
||||
branch_protector_ret = "pac_ret"
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
boundary_sanitize = true
|
||||
ubsan = true
|
||||
}
|
||||
sources = [ "src/screen_lock.cpp" ]
|
||||
|
||||
cflags_cc = [ "-fvisibility=hidden" ]
|
||||
|
||||
include_dirs = [
|
||||
"../include/screenlock",
|
||||
"${kv_store_common_path}",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"screenlock_mgr:screenlock_client",
|
||||
]
|
||||
subsystem_name = "distributeddatamgr"
|
||||
part_name = "datamgr_service"
|
||||
defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "screen_lock"
|
||||
#include "screen_lock.h"
|
||||
|
||||
#include "screenlock_manager.h"
|
||||
|
||||
namespace OHOS::DistributedData {
|
||||
using namespace OHOS::ScreenLock;
|
||||
|
||||
ScreenLock &ScreenLock::GetInstance()
|
||||
{
|
||||
static ScreenLock instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool ScreenLock::IsLocked()
|
||||
{
|
||||
auto manager = ScreenLockManager::GetInstance();
|
||||
if (manager == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return manager->IsScreenLocked();
|
||||
}
|
||||
} // namespace OHOS::DistributedData
|
@ -50,9 +50,7 @@ public:
|
||||
|
||||
API_EXPORT Stores GetStoresIfPresent(uint32_t tokenId, const std::string &storeName = "");
|
||||
|
||||
API_EXPORT void CloseStore(uint32_t tokenId, const std::string &storeId);
|
||||
|
||||
API_EXPORT void CloseStore(uint32_t tokenId);
|
||||
API_EXPORT void CloseStore(uint32_t tokenId, const std::string &storeId = "");
|
||||
|
||||
API_EXPORT void CloseExcept(const std::set<int32_t> &users);
|
||||
|
||||
@ -74,6 +72,7 @@ private:
|
||||
bool operator<(const Time &time) const;
|
||||
bool Close();
|
||||
int32_t GetUser() const;
|
||||
int32_t GetArea() const;
|
||||
void SetObservers(const Watchers &watchers);
|
||||
int32_t OnChange(const Origin &origin, const PRIFields &primaryFields, ChangeInfo &&values) override;
|
||||
int32_t OnChange(const Origin &origin, const Fields &fields, ChangeData &&datas) override;
|
||||
@ -84,7 +83,7 @@ private:
|
||||
GeneralStore *store_ = nullptr;
|
||||
Watchers watchers_;
|
||||
int32_t user_;
|
||||
StoreMetaData meta_;
|
||||
const StoreMetaData meta_;
|
||||
std::shared_mutex mutex_;
|
||||
};
|
||||
|
||||
|
@ -60,6 +60,14 @@ public:
|
||||
CLEAN_MODE_BUTT
|
||||
};
|
||||
|
||||
enum Area : int32_t {
|
||||
EL0,
|
||||
EL1,
|
||||
EL2,
|
||||
EL3,
|
||||
EL4
|
||||
};
|
||||
|
||||
static inline uint32_t MixMode(uint32_t syncMode, uint32_t highMode)
|
||||
{
|
||||
return syncMode | highMode;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "changeevent/remote_change_event.h"
|
||||
#include "eventcenter/event_center.h"
|
||||
#include "log_print.h"
|
||||
#include "screenlock/screen_lock.h"
|
||||
#include "utils/anonymous.h"
|
||||
namespace OHOS::DistributedData {
|
||||
AutoCache &AutoCache::GetInstance()
|
||||
@ -60,9 +61,11 @@ AutoCache::~AutoCache()
|
||||
AutoCache::Store AutoCache::GetStore(const StoreMetaData &meta, const Watchers &watchers)
|
||||
{
|
||||
Store store;
|
||||
if (meta.storeType >= MAX_CREATOR_NUM || meta.storeType < 0 || !creators_[meta.storeType] ||
|
||||
disables_.ContainIf(meta.tokenId,
|
||||
[&meta](const std::set<std::string> &stores) -> bool { return stores.count(meta.storeId) != 0; })) {
|
||||
if ((meta.area >= GeneralStore::EL4 && ScreenLock::GetInstance().IsLocked()) ||
|
||||
meta.storeType >= MAX_CREATOR_NUM || meta.storeType < 0 || !creators_[meta.storeType] ||
|
||||
disables_.ContainIf(meta.tokenId, [&meta](const std::set<std::string> &stores) -> bool {
|
||||
return stores.count(meta.storeId) != 0;
|
||||
})) {
|
||||
return store;
|
||||
}
|
||||
|
||||
@ -134,31 +137,33 @@ void AutoCache::StartTimer()
|
||||
|
||||
void AutoCache::CloseStore(uint32_t tokenId, const std::string &storeId)
|
||||
{
|
||||
stores_.ComputeIfPresent(tokenId, [&storeId](auto &key, std::map<std::string, Delegate> &delegates) {
|
||||
auto it = delegates.find(storeId);
|
||||
if (it != delegates.end()) {
|
||||
it->second.Close();
|
||||
delegates.erase(it);
|
||||
bool isScreenLocked = ScreenLock::GetInstance().IsLocked();
|
||||
stores_.ComputeIfPresent(tokenId, [&storeId, isScreenLocked](auto &key, auto &delegates) {
|
||||
auto it = delegates.begin();
|
||||
while (it != delegates.end()) {
|
||||
if ((storeId == it->first || storeId.empty()) &&
|
||||
(!isScreenLocked || it->second.GetArea() < GeneralStore::EL4)) {
|
||||
it->second.Close();
|
||||
it = delegates.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
return !delegates.empty();
|
||||
});
|
||||
}
|
||||
|
||||
void AutoCache::CloseStore(uint32_t tokenId)
|
||||
{
|
||||
stores_.Erase(tokenId);
|
||||
}
|
||||
|
||||
void AutoCache::CloseExcept(const std::set<int32_t> &users)
|
||||
{
|
||||
stores_.EraseIf([&users](const auto &tokenId, std::map<std::string, Delegate> &delegates) {
|
||||
bool isScreenLocked = ScreenLock::GetInstance().IsLocked();
|
||||
stores_.EraseIf([&users, isScreenLocked](const auto &tokenId, std::map<std::string, Delegate> &delegates) {
|
||||
if (delegates.empty() || users.count(delegates.begin()->second.GetUser()) != 0) {
|
||||
return delegates.empty();
|
||||
}
|
||||
|
||||
for (auto it = delegates.begin(); it != delegates.end();) {
|
||||
// if the kv store is BUSY we wait more INTERVAL minutes again
|
||||
if (!it->second.Close()) {
|
||||
if ((isScreenLocked && it->second.GetArea() >= GeneralStore::EL4) || !it->second.Close()) {
|
||||
++it;
|
||||
} else {
|
||||
it = delegates.erase(it);
|
||||
@ -184,10 +189,12 @@ void AutoCache::SetObserver(uint32_t tokenId, const std::string &storeId, const
|
||||
void AutoCache::GarbageCollect(bool isForce)
|
||||
{
|
||||
auto current = std::chrono::steady_clock::now();
|
||||
stores_.EraseIf([¤t, isForce](auto &key, std::map<std::string, Delegate> &delegates) {
|
||||
bool isScreenLocked = ScreenLock::GetInstance().IsLocked();
|
||||
stores_.EraseIf([¤t, isForce, isScreenLocked](auto &key, std::map<std::string, Delegate> &delegates) {
|
||||
for (auto it = delegates.begin(); it != delegates.end();) {
|
||||
// if the store is BUSY we wait more INTERVAL minutes again
|
||||
if ((isForce || it->second < current) && it->second.Close()) {
|
||||
if ((!isScreenLocked || it->second.GetArea() < GeneralStore::EL4) && (isForce || it->second < current) &&
|
||||
it->second.Close()) {
|
||||
it = delegates.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
@ -272,6 +279,11 @@ int32_t AutoCache::Delegate::GetUser() const
|
||||
return user_;
|
||||
}
|
||||
|
||||
int32_t AutoCache::Delegate::GetArea() const
|
||||
{
|
||||
return meta_.area;
|
||||
}
|
||||
|
||||
int32_t AutoCache::Delegate::OnChange(const Origin &origin, const PRIFields &primaryFields, ChangeInfo &&values)
|
||||
{
|
||||
std::vector<std::string> tables;
|
||||
|
Loading…
Reference in New Issue
Block a user