• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 OHOS_ABILITY_RUNTIME_SA_INTERCEPTOR_MANAGER_H
17 #define OHOS_ABILITY_RUNTIME_SA_INTERCEPTOR_MANAGER_H
18 
19 #include <map>
20 #include <mutex>
21 #include <vector>
22 
23 #include "ability_info.h"
24 #include "ability_record.h"
25 #include "sa_interceptor_interface.h"
26 #include "singleton.h"
27 #include "want.h"
28 
29 namespace OHOS {
30 namespace AbilityRuntime {
31 class SAInterceptorManager {
32 public:
33     static SAInterceptorManager &GetInstance();
34 
35     int32_t AddSAInterceptor(sptr<ISAInterceptor> interceptor);
36     int32_t ExecuteSAInterceptor(const std::string &params, Rule &rule);
37 
38     void OnObserverDied(const wptr<IRemoteObject> &remote);
39     bool SAInterceptorListIsEmpty();
40     std::string GenerateSAInterceptorParams(const AAFwk::Want &want, sptr<IRemoteObject> callerToken,
41         const AppExecFwk::AbilityInfo &abilityInfo, const std::string &dialogSessionId);
42 
43 private:
44     SAInterceptorManager();
45     ~SAInterceptorManager();
46     bool ObserverExist(sptr<IRemoteBroker> observer);
47 private:
48     std::mutex saInterceptorLock_;
49     sptr<IRemoteObject::DeathRecipient> deathRecipient_;
50     std::vector<sptr<ISAInterceptor>> saInterceptors_;
51     DISALLOW_COPY_AND_MOVE(SAInterceptorManager);
52 };
53 
54 class SAInterceptorRecipient : public IRemoteObject::DeathRecipient {
55 public:
56     using RemoteDiedHandler = std::function<void(const wptr<IRemoteObject> &)>;
57     explicit SAInterceptorRecipient(RemoteDiedHandler handler);
58     virtual ~SAInterceptorRecipient();
59     virtual void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
60 
61 private:
62     RemoteDiedHandler handler_;
63 };
64 } // namespace AbilityRuntime
65 } // namespace OHOS
66 #endif // OHOS_ABILITY_RUNTIME_SA_INTERCEPTOR_MANAGER_H