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 <map> 21 #include <mutex> 22 #include <string> 23 24 #include "application_state_observer_stub.h" 25 #include "app_mgr_interface.h" 26 #include "context_callback.h" 27 #include "if_system_ability_manager.h" 28 #include "iservice_registry.h" 29 30 namespace OHOS { 31 namespace UserIam { 32 namespace UserAuth { 33 using namespace OHOS::AppExecFwk; 34 class ContextAppStateObserverManager { 35 public: 36 ContextAppStateObserverManager() = default; 37 ~ContextAppStateObserverManager() = default; 38 static ContextAppStateObserverManager &GetInstance(); 39 40 void SubscribeAppState(const std::shared_ptr<ContextCallback> &callback, const uint64_t contextId); 41 void UnSubscribeAppState(); 42 bool IsScreenLocked(); 43 44 protected: 45 sptr<ApplicationStateObserverStub> appStateObserver_ = nullptr; 46 47 private: 48 sptr<IAppMgr> GetAppManagerInstance(); 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 58 protected: 59 void ProcAppStateChanged(int32_t userId); 60 const uint64_t contextId_ = INVALID_CONTEXT_ID; 61 const std::string bundleName_; 62 }; 63 } // namespace UserAuth 64 } // namespace UserIam 65 } // namespace OHOS 66 #endif // IAM_CONTEXT_APPSTATE_OBSERVER_H