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 IAM_CONTEXT_APPSTATE_OBSERVER_H 17 #define IAM_CONTEXT_APPSTATE_OBSERVER_H 18 19 #include <cstdint> 20 #include <string> 21 22 #include "application_state_observer_stub.h" 23 #include "app_mgr_interface.h" 24 #include "context_callback.h" 25 #include "if_system_ability_manager.h" 26 #include "iservice_registry.h" 27 28 namespace OHOS { 29 namespace UserIam { 30 namespace UserAuth { 31 using namespace OHOS::AppExecFwk; 32 class ContextAppStateObserverManager { 33 public: 34 ContextAppStateObserverManager() = default; 35 ~ContextAppStateObserverManager() = default; 36 static ContextAppStateObserverManager &GetInstance(); 37 38 void SubscribeAppState(const std::shared_ptr<ContextCallback> &callback, const uint64_t contextId); 39 void UnSubscribeAppState(); 40 void SetScreenLockState(bool screenLockState); 41 bool GetScreenLockState(); 42 43 protected: 44 sptr<ApplicationStateObserverStub> appStateObserver_ = nullptr; 45 46 private: 47 sptr<IAppMgr> GetAppManagerInstance(); 48 bool isScreenLocked_ = false; 49 }; 50 51 class ContextAppStateObserver : public ApplicationStateObserverStub { 52 public: 53 ContextAppStateObserver(const uint64_t contextId, const std::string bundleName); 54 ~ContextAppStateObserver() override = default; 55 void OnAppStateChanged(const AppStateData &appStateData) override; 56 void OnForegroundApplicationChanged(const AppStateData &appStateData) override; 57 void OnAbilityStateChanged(const AbilityStateData &abilityStateData) override; 58 59 protected: 60 void ProcAppStateChanged(int32_t userId); 61 const uint64_t contextId_ = INVALID_CONTEXT_ID; 62 const std::string bundleName_; 63 }; 64 } // namespace UserAuth 65 } // namespace UserIam 66 } // namespace OHOS 67 #endif // IAM_CONTEXT_APPSTATE_OBSERVER_H