• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "watermark_application_observer.h"
17 
18 #include "managed_event.h"
19 #include "os_account_manager.h"
20 #include "window_manager.h"
21 #include "wm_common.h"
22 
23 namespace OHOS {
24 namespace EDM {
OnProcessCreated(const AppExecFwk::ProcessData & processData)25 void WatermarkApplicationObserver::OnProcessCreated(const AppExecFwk::ProcessData &processData)
26 {
27     int32_t accountId = -1;
28     ErrCode ret = AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(processData.uid, accountId);
29     if (ret != ERR_OK) {
30         EDMLOGE("OnProcessCreated GetOsAccountLocalIdFromUid error");
31         return;
32     }
33     SetProcessWatermarkOnAppStart(processData.bundleName, accountId, processData.pid, true);
34 }
35 
SetProcessWatermarkOnAppStart(const std::string & bundleName,int32_t accountId,int32_t pid,bool enabled)36 void WatermarkApplicationObserver::SetProcessWatermarkOnAppStart(const std::string &bundleName, int32_t accountId,
37     int32_t pid, bool enabled)
38 {
39     if (bundleName.empty() || accountId <= 0 || pid <= 0) {
40         return;
41     }
42 
43     std::string policyData;
44     auto policyManager = IPolicyManager::GetInstance();
45     policyManager->GetPolicy("", PolicyName::POLICY_WATERMARK_IMAGE_POLICY, policyData, EdmConstants::DEFAULT_USER_ID);
46 
47     std::map<std::pair<std::string, int32_t>, WatermarkImageType> currentData;
48     auto serializer = WatermarkImageSerializer::GetInstance();
49     serializer->Deserialize(policyData, currentData);
50     auto iter = currentData.find(std::pair<std::string, int32_t>{bundleName, accountId});
51     if (iter == currentData.end() || iter->second.fileName.empty()) {
52         return;
53     }
54     Rosen::WMError ret = Rosen::WindowManager::GetInstance().SetProcessWatermark(pid, iter->second.fileName, enabled);
55     if (ret != Rosen::WMError::WM_OK) {
56         EDMLOGE("SetAllWatermarkImage SetProcessWatermarkOnAppStart error");
57     }
58 }
59 } // namespace EDM
60 } // namespace OHOS