• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "get_screen_off_time_plugin.h"
17 
18 #include "edm_data_ability_utils.h"
19 #include "edm_ipc_interface_code.h"
20 #include "int_serializer.h"
21 
22 namespace OHOS {
23 namespace EDM {
24 const std::string PREDICATES_STRING = "settings.display.screen_off_timeout";
25 
26 const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(GetScreenOffTimePlugin::GetPlugin());
27 
InitPlugin(std::shared_ptr<IPluginTemplate<GetScreenOffTimePlugin,int32_t>> ptr)28 void GetScreenOffTimePlugin::InitPlugin(std::shared_ptr<IPluginTemplate<GetScreenOffTimePlugin, int32_t>> ptr)
29 {
30     EDMLOGD("GetScreenOffTimePlugin InitPlugin...");
31     ptr->InitAttribute(EdmInterfaceCode::SCREEN_OFF_TIME, "screen_off_time", "ohos.permission.ENTERPRISE_GET_SETTINGS",
32         IPlugin::PermissionType::SUPER_DEVICE_ADMIN, false);
33     ptr->SetSerializer(IntSerializer::GetInstance());
34 }
35 
OnGetPolicy(std::string & value,MessageParcel & data,MessageParcel & reply,int32_t userId)36 ErrCode GetScreenOffTimePlugin::OnGetPolicy(std::string &value, MessageParcel &data, MessageParcel &reply,
37     int32_t userId)
38 {
39     EDMLOGI("GetScreenOffTimePlugin OnGetPolicy");
40     int32_t result = 0;
41     ErrCode code = EdmDataAbilityUtils::GetIntFromDataShare(EdmDataAbilityUtils::SETTINGS_DATA_BASE_URI,
42         PREDICATES_STRING, result);
43     if (code != ERR_OK) {
44         EDMLOGE("GetScreenOffTimePlugin::get screen off time from database failed : %{public}d.", code);
45         reply.WriteInt32(EdmReturnErrCode::SYSTEM_ABNORMALLY);
46         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
47     }
48     reply.WriteInt32(ERR_OK);
49     reply.WriteInt32(result);
50     return ERR_OK;
51 }
52 } // namespace EDM
53 } // namespace OHOS
54