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, userId);
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,int32_t userId)45 ErrCode BasicBoolPlugin::SetOtherModulePolicy(bool data, int32_t userId)
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", adminName.c_str(), data);
53 if (!mergeData && data) {
54 ErrCode ret = RemoveOtherModulePolicy(userId);
55 if (FAILED(ret)) {
56 return ret;
57 }
58 if (!persistParam_.empty() && !system::SetParameter(persistParam_, "false")) {
59 return EdmReturnErrCode::SYSTEM_ABNORMALLY;
60 }
61 }
62 return ERR_OK;
63 }
64
RemoveOtherModulePolicy(int32_t userId)65 ErrCode BasicBoolPlugin::RemoveOtherModulePolicy(int32_t userId)
66 {
67 return ERR_OK;
68 }
69 } // namespace EDM
70 } // namespace OHOS
71