• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "display_system_ability.h"
17 #include "delayed_sp_singleton.h"
18 #include "iremote_object.h"
19 #include "new"
20 #include "system_ability_definition.h"
21 #include "display_log.h"
22 
23 namespace OHOS {
24 namespace DisplayPowerMgr {
25 namespace {
26 REGISTER_SYSTEM_ABILITY_BY_ID(DisplaySystemAbility, DISPLAY_MANAGER_SERVICE_ID, true);
27 }
OnStart()28 void DisplaySystemAbility::OnStart()
29 {
30     DISPLAY_HILOGI(COMP_SVC, "DisplayPowerService On Start.");
31     AddSystemAbilityListener(DISPLAY_MANAGER_SERVICE_SA_ID);
32 }
33 
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)34 void DisplaySystemAbility::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
35 {
36     if (systemAbilityId == DISPLAY_MANAGER_SERVICE_SA_ID) {
37         DISPLAY_HILOGI(COMP_SVC, "Start service");
38         auto service = DelayedSpSingleton<DisplayPowerMgrService>::GetInstance();
39         service->Init();
40         if (!Publish(service)) {
41             DISPLAY_HILOGE(COMP_SVC, "Failed to publish service");
42         }
43     }
44 }
45 
OnStop()46 void DisplaySystemAbility::OnStop()
47 {
48     DISPLAY_HILOGW(COMP_SVC, "Stop service");
49     auto service = DelayedSpSingleton<DisplayPowerMgrService>::GetInstance();
50     service->Deinit();
51     RemoveSystemAbilityListener(DISPLAY_MANAGER_SERVICE_SA_ID);
52 }
53 } // OHOS
54 } // DisplayPowerMgr
55