1365d9939Sopenharmony_ci/* 2365d9939Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3365d9939Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4365d9939Sopenharmony_ci * you may not use this file except in compliance with the License. 5365d9939Sopenharmony_ci * You may obtain a copy of the License at 6365d9939Sopenharmony_ci * 7365d9939Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8365d9939Sopenharmony_ci * 9365d9939Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10365d9939Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11365d9939Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12365d9939Sopenharmony_ci * See the License for the specific language governing permissions and 13365d9939Sopenharmony_ci * limitations under the License. 14365d9939Sopenharmony_ci */ 15365d9939Sopenharmony_ci 16365d9939Sopenharmony_ci#ifndef SERVICES_INCLUDE_SCLOCK_MANAGER_H 17365d9939Sopenharmony_ci#define SERVICES_INCLUDE_SCLOCK_MANAGER_H 18365d9939Sopenharmony_ci 19365d9939Sopenharmony_ci#include <mutex> 20365d9939Sopenharmony_ci#include <string> 21365d9939Sopenharmony_ci 22365d9939Sopenharmony_ci#include "iremote_object.h" 23365d9939Sopenharmony_ci#include "refbase.h" 24365d9939Sopenharmony_ci#include "screenlock_callback_interface.h" 25365d9939Sopenharmony_ci#include "screenlock_common.h" 26365d9939Sopenharmony_ci#include "screenlock_manager_interface.h" 27365d9939Sopenharmony_ci#include "visibility.h" 28365d9939Sopenharmony_ci 29365d9939Sopenharmony_cinamespace OHOS { 30365d9939Sopenharmony_cinamespace ScreenLock { 31365d9939Sopenharmony_ciclass ScreenLockManager : public RefBase { 32365d9939Sopenharmony_cipublic: 33365d9939Sopenharmony_ci SCREENLOCK_API static sptr<ScreenLockManager> GetInstance(); 34365d9939Sopenharmony_ci /** 35365d9939Sopenharmony_ci * Lock the screen. 36365d9939Sopenharmony_ci * 37365d9939Sopenharmony_ci * @param userId Indicates the user ID. 38365d9939Sopenharmony_ci * @return Returns E_SCREENLOCK_OK if success; otherwise failed. 39365d9939Sopenharmony_ci */ 40365d9939Sopenharmony_ci SCREENLOCK_API int32_t Lock(int32_t userId); 41365d9939Sopenharmony_ci 42365d9939Sopenharmony_ci /** 43365d9939Sopenharmony_ci * Check whether the screen is currently locked. 44365d9939Sopenharmony_ci * 45365d9939Sopenharmony_ci * @param isLocked Indicates the screen lock state. 46365d9939Sopenharmony_ci * @return Returns E_SCREENLOCK_OK if success; otherwise failed. 47365d9939Sopenharmony_ci */ 48365d9939Sopenharmony_ci SCREENLOCK_API int32_t IsLocked(bool &isLocked); 49365d9939Sopenharmony_ci 50365d9939Sopenharmony_ci SCREENLOCK_API bool IsScreenLocked(); 51365d9939Sopenharmony_ci SCREENLOCK_API bool GetSecure(); 52365d9939Sopenharmony_ci SCREENLOCK_API int32_t Unlock(Action action, const sptr<ScreenLockCallbackInterface> &listener); 53365d9939Sopenharmony_ci SCREENLOCK_API int32_t RequestStrongAuth(int reasonFlag, int32_t userId); 54365d9939Sopenharmony_ci int32_t Lock(const sptr<ScreenLockCallbackInterface> &listener); 55365d9939Sopenharmony_ciprivate: 56365d9939Sopenharmony_ci class ScreenLockSaDeathRecipient : public IRemoteObject::DeathRecipient { 57365d9939Sopenharmony_ci public: 58365d9939Sopenharmony_ci explicit ScreenLockSaDeathRecipient(){}; 59365d9939Sopenharmony_ci ~ScreenLockSaDeathRecipient() = default; 60365d9939Sopenharmony_ci void OnRemoteDied(const wptr<IRemoteObject> &object) override 61365d9939Sopenharmony_ci { 62365d9939Sopenharmony_ci ScreenLockManager::GetInstance()->OnRemoteSaDied(object); 63365d9939Sopenharmony_ci } 64365d9939Sopenharmony_ci }; 65365d9939Sopenharmony_ci 66365d9939Sopenharmony_ci ScreenLockManager(); 67365d9939Sopenharmony_ci ~ScreenLockManager() override; 68365d9939Sopenharmony_ci void RemoveDeathRecipient(); 69365d9939Sopenharmony_ci void OnRemoteSaDied(const wptr<IRemoteObject> &object); 70365d9939Sopenharmony_ci sptr<ScreenLockManagerInterface> GetProxy(); 71365d9939Sopenharmony_ci sptr<ScreenLockManagerInterface> GetScreenLockManagerProxy(); 72365d9939Sopenharmony_ci static std::mutex instanceLock_; 73365d9939Sopenharmony_ci static sptr<ScreenLockManager> instance_; 74365d9939Sopenharmony_ci sptr<ScreenLockSaDeathRecipient> deathRecipient_; 75365d9939Sopenharmony_ci std::mutex managerProxyLock_; 76365d9939Sopenharmony_ci sptr<ScreenLockManagerInterface> screenlockManagerProxy_; 77365d9939Sopenharmony_ci}; 78365d9939Sopenharmony_ci} // namespace ScreenLock 79365d9939Sopenharmony_ci} // namespace OHOS 80365d9939Sopenharmony_ci#endif // SERVICES_INCLUDE_SCLOCK_SERVICES_MANAGER_H