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 FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_DISTRIBUTED_MANAGER_BUNDLE_DISTRIBUTED_MANAGER_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_DISTRIBUTED_MANAGER_BUNDLE_DISTRIBUTED_MANAGER_H
18 
19 #include <shared_mutex>
20 
21 #include "iremote_broker.h"
22 #include "query_rpc_id_params.h"
23 #include "rpc_id_result.h"
24 #include "serial_queue.h"
25 #include "target_ability_info.h"
26 #include "want.h"
27 
28 namespace OHOS {
29 namespace AppExecFwk {
30 using namespace OHOS::AAFwk;
31 class BundleDistributedManager : public std::enable_shared_from_this<BundleDistributedManager> {
32 public:
33     BundleDistributedManager();
34     ~BundleDistributedManager();
35 
36     bool CheckAbilityEnableInstall(
37         const Want &want, int32_t missionId, int32_t userId, const sptr<IRemoteObject> &callerToken);
38 
39     void OnQueryRpcIdFinished(const std::string &queryRpcIdResult);
40 private:
41     bool ConvertTargetAbilityInfo(const Want &want, TargetAbilityInfo &targetAbilityInfo);
42     bool QueryRpcIdByAbilityToServiceCenter(const TargetAbilityInfo &targetInfo);
43     void SendCallbackRequest(int32_t resultCode, const std::string &transactId);
44     void SendCallback(int32_t resultCode, const QueryRpcIdParams &queryRpcIdParams);
45     int32_t ComparePcIdString(const Want &want, const RpcIdResult &rpcIdResult);
46     void OutTimeMonitor(const std::string transactId);
GetTransactId()47     int GetTransactId() const
48     {
49         transactId_++;
50         return transactId_.load();
51     }
52     std::shared_mutex mutex_;
53 
54     mutable std::atomic<int> transactId_ = 0;
55     std::map<std::string, QueryRpcIdParams> queryAbilityParamsMap_;
56     std::shared_ptr<SerialQueue> serialQueue_;
57 };
58 }  // namespace AppExecFwk
59 }  // namespace OHOS
60 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_DISTRIBUTED_MANAGER_BUNDLE_DISTRIBUTED_MANAGER_H