1 /* 2 * Copyright (C) 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 #ifndef SERVICES_INCLUDE_SCLOCK_MANAGER_H 17 #define SERVICES_INCLUDE_SCLOCK_MANAGER_H 18 19 #include <mutex> 20 #include <string> 21 22 #include "iremote_object.h" 23 #include "refbase.h" 24 #include "screenlock_manager_interface.h" 25 #include "screenlock_system_ability_interface.h" 26 27 namespace OHOS { 28 namespace ScreenLock { 29 class ScreenLockSaDeathRecipient : public IRemoteObject::DeathRecipient { 30 public: 31 explicit ScreenLockSaDeathRecipient(); 32 ~ScreenLockSaDeathRecipient() = default; 33 void OnRemoteDied(const wptr<IRemoteObject> &object) override; 34 }; 35 36 class ScreenLockManager : public RefBase { 37 public: 38 ScreenLockManager(); 39 ~ScreenLockManager(); 40 static sptr<ScreenLockManager> GetInstance(); 41 bool IsScreenLocked(); 42 bool GetSecure(); 43 int32_t RequestUnlock(const sptr<ScreenLockSystemAbilityInterface> &listener); 44 int32_t RequestLock(const sptr<ScreenLockSystemAbilityInterface> &listener); 45 void OnRemoteSaDied(const wptr<IRemoteObject> &object); 46 sptr<ScreenLockManagerInterface> GetProxy(); 47 48 private: 49 static sptr<ScreenLockManagerInterface> GetScreenLockManagerProxy(); 50 static std::mutex instanceLock_; 51 static sptr<ScreenLockManager> instance_; 52 static sptr<ScreenLockSaDeathRecipient> deathRecipient_; 53 std::mutex managerProxyLock_; 54 sptr<ScreenLockManagerInterface> screenlockManagerProxy_; 55 }; 56 } // namespace ScreenLock 57 } // namespace OHOS 58 #endif // SERVICES_INCLUDE_SCLOCK_SERVICES_MANAGER_H