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 "basic_bool_plugin.h"
17
18 #include "parameters.h"
19
20 #include "bool_serializer.h"
21 #include "edm_log.h"
22
23 namespace OHOS {
24 namespace EDM {
OnSetPolicy(bool & data,bool & currentData,bool & mergePolicy,int32_t userId)25 ErrCode BasicBoolPlugin::OnSetPolicy(bool &data, bool ¤tData, bool &mergePolicy, int32_t userId)
26 {
27 EDMLOGE("BasicBoolPlugin %{public}d, %{public}d, %{public}d.", data, currentData, mergePolicy);
28 if (mergePolicy) {
29 currentData = data;
30 return ERR_OK;
31 }
32 ErrCode ret = SetOtherModulePolicy(data);
33 if (FAILED(ret)) {
34 return ret;
35 }
36 if (!persistParam_.empty() && !system::SetParameter(persistParam_, data ? "true" : "false")) {
37 EDMLOGE("DisableBluetoothPlugin set param failed.");
38 return EdmReturnErrCode::SYSTEM_ABNORMALLY;
39 }
40 currentData = data;
41 mergePolicy = data;
42 return ERR_OK;
43 }
44
SetOtherModulePolicy(bool data)45 ErrCode BasicBoolPlugin::SetOtherModulePolicy(bool data)
46 {
47 return ERR_OK;
48 }
49
OnAdminRemove(const std::string & adminName,bool & data,bool & mergeData,int32_t userId)50 ErrCode BasicBoolPlugin::OnAdminRemove(const std::string &adminName, bool &data, bool &mergeData, int32_t userId)
51 {
52 EDMLOGI("BasicBoolPlugin OnAdminRemove adminName : %{public}s, data : %{public}d, userId : %{public}d",
53 adminName.c_str(), data, userId);
54 if (!mergeData) {
55 ErrCode ret = RemoveOtherModulePolicy();
56 if (FAILED(ret)) {
57 return ret;
58 }
59 if (!persistParam_.empty() && !system::SetParameter(persistParam_, "false")) {
60 return EdmReturnErrCode::SYSTEM_ABNORMALLY;
61 }
62 }
63 return ERR_OK;
64 }
65
RemoveOtherModulePolicy()66 ErrCode BasicBoolPlugin::RemoveOtherModulePolicy()
67 {
68 return ERR_OK;
69 }
70 } // namespace EDM
71 } // namespace OHOS
72