• 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 #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_ADAPTER_GET_SCHEMA_HELPER_H
16 #define OHOS_DISTRIBUTED_DATA_SERVICES_ADAPTER_GET_SCHEMA_HELPER_H
17 
18 #include <memory>
19 #include <string>
20 #include <mutex>
21 
22 #include "iremote_object.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 class IBundleMgr;
27 }
28 } // namespace OHOS
29 
30 namespace OHOS::DistributedData {
31 struct AppInfo {
32     std::string bundleName;
33     int32_t userId;
34     int32_t appIndex;
35 };
36 
37 class GetSchemaHelper final : public std::enable_shared_from_this<GetSchemaHelper> {
38 public:
39     static GetSchemaHelper &GetInstance();
40     std::vector<std::string> GetSchemaFromHap(const std::string &schemaPath, const AppInfo &info);
41 
42 private:
43     GetSchemaHelper() = default;
44     ~GetSchemaHelper();
45     class ServiceDeathRecipient : public IRemoteObject::DeathRecipient {
46     public:
ServiceDeathRecipient(std::weak_ptr<GetSchemaHelper> owner)47         explicit ServiceDeathRecipient(std::weak_ptr<GetSchemaHelper> owner) : owner_(owner)
48         {
49         }
OnRemoteDied(const wptr<IRemoteObject> & object)50         void OnRemoteDied(const wptr<IRemoteObject> &object) override
51         {
52             auto owner = owner_.lock();
53             if (owner != nullptr) {
54                 owner->OnRemoteDied();
55             }
56         }
57 
58     private:
59         std::weak_ptr<GetSchemaHelper> owner_;
60     };
61     void OnRemoteDied();
62     sptr<AppExecFwk::IBundleMgr> GetBundleMgr();
63     std::mutex mutex_;
64     sptr<IRemoteObject> object_;
65     sptr<GetSchemaHelper::ServiceDeathRecipient> deathRecipient_;
66 };
67 } // namespace OHOS::DistributedData
68 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_ADAPTER_GET_SCHEMA_HELPER_H