1 /*
2  * Copyright (c) 2023 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 "fingerprint_auth_plugin.h"
17 
18 #include "edm_data_ability_utils.h"
19 #include "edm_ipc_interface_code.h"
20 #include "bool_serializer.h"
21 #include "parameters.h"
22 #include "plugin_manager.h"
23 
24 namespace OHOS {
25 namespace EDM {
26 const bool REGISTER_RESULT = PluginManager::GetInstance()->AddPlugin(FingerprintAuthPlugin::GetPlugin());
27 const std::string PERSIST_FINGERPRINTAUTH_CONTROL = "persist.useriam.enable.fingerprintauth";
InitPlugin(std::shared_ptr<IPluginTemplate<FingerprintAuthPlugin,bool>> ptr)28 void FingerprintAuthPlugin::InitPlugin(
29     std::shared_ptr<IPluginTemplate<FingerprintAuthPlugin, bool>> ptr)
30 {
31     EDMLOGI("FingerprintAuthPlugin InitPlugin...");
32     ptr->InitAttribute(EdmInterfaceCode::FINGERPRINT_AUTH, "fingerprint_auth",
33         "ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS", IPlugin::PermissionType::SUPER_DEVICE_ADMIN, false);
34     ptr->SetSerializer(BoolSerializer::GetInstance());
35     ptr->SetOnHandlePolicyListener(&FingerprintAuthPlugin::OnSetPolicy, FuncOperateType::SET);
36 }
37 
OnSetPolicy(bool & data)38 ErrCode FingerprintAuthPlugin::OnSetPolicy(bool &data)
39 {
40     EDMLOGI("FingerprintAuthPlugin OnSetPolicy %{public}d", data);
41     std::string value = data ? "false" : "true";
42     return OHOS::system::SetParameter(PERSIST_FINGERPRINTAUTH_CONTROL, value) ?
43         ERR_OK : EdmReturnErrCode::SYSTEM_ABNORMALLY;
44 }
45 
OnGetPolicy(std::string & value,MessageParcel & data,MessageParcel & reply,int32_t userId)46 ErrCode FingerprintAuthPlugin::OnGetPolicy(
47     std::string &value, MessageParcel &data, MessageParcel &reply, int32_t userId)
48 {
49     EDMLOGI("FingerprintAuthPlugin OnGetPolicy");
50     bool ret = OHOS::system::GetBoolParameter(PERSIST_FINGERPRINTAUTH_CONTROL, true);
51     reply.WriteInt32(ERR_OK);
52     reply.WriteBool(!ret);
53     return ERR_OK;
54 }
55 } // namespace EDM
56 } // namespace OHOS
57