• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ACCESS_APP_MANAGER_ACCESS_CLIENT_H
17 #define ACCESS_APP_MANAGER_ACCESS_CLIENT_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "app_status_change_callback.h"
23 #include "app_manager_death_callback.h"
24 #include "nocopyable.h"
25 
26 namespace OHOS {
27 namespace Security {
28 namespace AccessToken {
29 class AppManagerAccessClient final {
30 public:
31     static AppManagerAccessClient& GetInstance();
32     virtual ~AppManagerAccessClient();
33 
34     int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver>& observer);
35     int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver>& observer);
36     int32_t GetForegroundApplications(std::vector<AppStateData>& list);
37     void RegisterDeathCallback(const std::shared_ptr<AppManagerDeathCallback>& callback);
38     void OnRemoteDiedHandle();
39 
40     enum class Message {
41         REGISTER_APPLICATION_STATE_OBSERVER = 12,
42         UNREGISTER_APPLICATION_STATE_OBSERVER = 13,
43         GET_FOREGROUND_APPLICATIONS = 14,
44     };
45 
46 private:
47     AppManagerAccessClient();
48     DISALLOW_COPY_AND_MOVE(AppManagerAccessClient);
49 
50     class AppMgrDeathRecipient : public IRemoteObject::DeathRecipient {
51     public:
AppMgrDeathRecipient()52         AppMgrDeathRecipient() {}
53         virtual ~AppMgrDeathRecipient() override = default;
54         void OnRemoteDied(const wptr<IRemoteObject>& object) override;
55     };
56 
57     void InitProxy();
58     sptr<IRemoteObject> GetProxy();
59     void ReleaseProxy();
60 
61     sptr<AppMgrDeathRecipient> serviceDeathObserver_ = nullptr;
62     std::mutex proxyMutex_;
63     std::mutex deathCallbackMutex_;
64     sptr<IRemoteObject> proxy_ = nullptr;
65     std::vector<std::shared_ptr<AppManagerDeathCallback>> appManagerDeathCallbackList_;
66 };
67 } // namespace AccessToken
68 } // namespace Security
69 } // namespace OHOS
70 #endif // ACCESS_APP_MANAGER_ACCESS_CLIENT_H
71 
72