1 /* 2 * Copyright (c) 2022-2023 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_APP_MANAGER_ACCESS_PROXY_H 17 #define ACCESS_APP_MANAGER_ACCESS_PROXY_H 18 19 #include <iremote_proxy.h> 20 21 #include "app_state_data.h" 22 #include "process_data.h" 23 #include "service_ipc_interface_code.h" 24 25 namespace OHOS { 26 namespace Security { 27 namespace AccessToken { 28 class IApplicationStateObserver : public IRemoteBroker { 29 public: 30 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.IApplicationStateObserver"); 31 32 virtual void OnForegroundApplicationChanged(const AppStateData &appStateData) = 0; 33 virtual void OnProcessDied(const ProcessData &processData) = 0; 34 35 enum class Message { 36 TRANSACT_ON_FOREGROUND_APPLICATION_CHANGED = 0, 37 TRANSACT_ON_PROCESS_DIED = 5, 38 }; 39 }; 40 41 class IAppMgr : public IRemoteBroker { 42 public: 43 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.AppMgr"); 44 45 virtual int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver>& observer, 46 const std::vector<std::string>& bundleNameList = {}) = 0; 47 virtual int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver>& observer) = 0; 48 virtual int32_t GetForegroundApplications(std::vector<AppStateData>& list) = 0; 49 50 enum class Message { 51 REGISTER_APPLICATION_STATE_OBSERVER = 12, 52 UNREGISTER_APPLICATION_STATE_OBSERVER = 13, 53 GET_FOREGROUND_APPLICATIONS = 14, 54 }; 55 }; 56 57 class AppManagerAccessProxy : public IRemoteProxy<IAppMgr> { 58 public: AppManagerAccessProxy(const sptr<IRemoteObject> & impl)59 explicit AppManagerAccessProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<IAppMgr>(impl) {}; 60 61 virtual ~AppManagerAccessProxy() = default; 62 63 int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver>& observer, 64 const std::vector<std::string> &bundleNameList = {}) override; 65 int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver>& observer) override; 66 int32_t GetForegroundApplications(std::vector<AppStateData>& list) override; 67 private: 68 static inline BrokerDelegator<AppManagerAccessProxy> delegator_; 69 }; 70 } // namespace AccessToken 71 } // namespace Security 72 } // namespace OHOS 73 #endif // ACCESS_APP_MANAGER_ACCESS_PROXY_H 74