1 /*
2 * Copyright (c) 2021-2022 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 "screen_saver_feature.h"
17
18 #include <feature.h>
19 #include <ohos_init.h>
20 #include <samgr_lite.h>
21
22 #include "hilog_wrapper.h"
23 #include "power_mgr.h"
24 #include "screen_saver_intf_define.h"
25 #include "screen_saver_mgr.h"
26
GetScreenSaverFeatureName(Feature * feature)27 const char *GetScreenSaverFeatureName(Feature *feature)
28 {
29 (void)feature;
30 return POWER_SCREEN_SAVER_FEATURE;
31 }
32
OnScreenSaverFeatureInitialize(Feature * feature,Service * parent,Identity identity)33 void OnScreenSaverFeatureInitialize(Feature *feature, Service *parent, Identity identity)
34 {
35 (void)parent;
36 (void)identity;
37 if (feature == NULL) {
38 POWER_HILOGE("Invalid feature");
39 return;
40 }
41
42 ScreenSaverFeature *f = (ScreenSaverFeature *)feature;
43 f->identity = identity;
44 ScreenSaverMgrInit();
45 POWER_HILOGI("Init screen saver feature done");
46 }
47
OnScreenSaverFeatureStop(Feature * feature,Identity identity)48 void OnScreenSaverFeatureStop(Feature *feature, Identity identity)
49 {
50 (void)feature;
51 (void)identity;
52 ScreenSaverFeature *f = GetScreenSaverFeatureImpl();
53 if (f != NULL) {
54 f->identity.queueId = NULL;
55 f->identity.featureId = -1;
56 f->identity.serviceId = -1;
57 }
58 }
59
OnScreenSaverFeatureMessage(Feature * feature,Request * request)60 BOOL OnScreenSaverFeatureMessage(Feature *feature, Request *request)
61 {
62 return ((feature != NULL) && (request != NULL)) ? TRUE : FALSE;
63 }
64
OnSetScreenSaverState(IUnknown * iUnknown,BOOL enable)65 int32_t OnSetScreenSaverState(IUnknown *iUnknown, BOOL enable)
66 {
67 (void)iUnknown;
68 return ScreenSaverMgrSetState(enable);
69 }
70
Init(void)71 static void Init(void)
72 {
73 SamgrLite *sam = SAMGR_GetInstance();
74 if (sam == NULL) {
75 POWER_HILOGE("Failed to get samgr");
76 return;
77 }
78
79 ScreenSaverFeature *feature = GetScreenSaverFeatureImpl();
80 if (feature == NULL) {
81 POWER_HILOGE("Failed to get screen saver feature");
82 return;
83 }
84 BOOL result = sam->RegisterFeature(POWER_MANAGE_SERVICE, (Feature *)feature);
85 if (result == FALSE) {
86 POWER_HILOGE("Failed to register screen saver feature");
87 return;
88 }
89 result = sam->RegisterFeatureApi(POWER_MANAGE_SERVICE, POWER_SCREEN_SAVER_FEATURE, GET_IUNKNOWN(*feature));
90 if (result == FALSE) {
91 POWER_HILOGE("Failed to register screen saver feature api");
92 return;
93 }
94 POWER_HILOGI("Succeed to register screen saver feature");
95 }
96 SYS_FEATURE_INIT(Init);
97