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 #ifndef ACCESS_POWER_MANAGER_ACCESS_CLIENT_H
17 #define ACCESS_POWER_MANAGER_ACCESS_CLIENT_H
18 
19 #include <mutex>
20 #include "nocopyable.h"
21 #include "power_manager_proxy.h"
22 
23 namespace OHOS {
24 namespace Security {
25 namespace AccessToken {
26 class PowerMgrDeathRecipient : public IRemoteObject::DeathRecipient {
27 public:
PowerMgrDeathRecipient()28     PowerMgrDeathRecipient() {}
29     virtual ~PowerMgrDeathRecipient() override = default;
30     void OnRemoteDied(const wptr<IRemoteObject>& object) override;
31 };
32 
33 class PowerMgrClient final {
34 public:
35     static PowerMgrClient& GetInstance();
36     virtual ~PowerMgrClient();
37     bool IsScreenOn();
38 
39     void OnRemoteDiedHandle();
40 private:
41     PowerMgrClient();
42     DISALLOW_COPY_AND_MOVE(PowerMgrClient);
43 
44     void InitProxy();
45     sptr<IPowerMgr> GetProxy();
46     void ReleaseProxy();
47 
48     sptr<PowerMgrDeathRecipient> serviceDeathObserver_ = nullptr;
49     std::mutex proxyMutex_;
50     sptr<IPowerMgr> proxy_ = nullptr;
51 };
52 } // namespace AccessToken
53 } // namespace Security
54 } // namespace OHOS
55 #endif // ACCESS_POWER_MANAGER_ACCESS_CLIENT_H
56