• 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 NET_BUNDLE__H
17 #define NET_BUNDLE__H
18 
19 #include <string>
20 #include <optional>
21 
22 namespace OHOS {
23 namespace NetManagerStandard {
24 struct SampleBundleInfo {
25 public:
ValidSampleBundleInfo26     inline bool Valid() const
27     {
28         return uid_ > 0 && !bundleName_.empty();
29     }
ToStringSampleBundleInfo30     std::string ToString() const
31     {
32         std::string s;
33         s.append(std::to_string(uid_));
34         s.append(",");
35         s.append(bundleName_);
36         s.append(",");
37         s.append(installSource_);
38         s.append(",");
39         s.append(std::to_string(installTime_));
40         return s;
41     }
42 
43 public:
44     uint32_t uid_ = 0;
45     std::string bundleName_;
46     std::string installSource_;
47     int64_t installTime_ = -1;
48 };
49 
50 class INetBundle {
51 public:
52     virtual int32_t GetJsonFromBundle(std::string &jsonProfile) = 0;
53     virtual bool IsAtomicService(std::string &bundleName) = 0;
54     virtual std::optional<int32_t> ObtainTargetApiVersionForSelf() = 0;
55     virtual std::optional<std::string> ObtainBundleNameForSelf() = 0;
56     virtual std::optional<std::unordered_map<uint32_t, SampleBundleInfo>> ObtainBundleInfoForActive() = 0;
57     virtual std::optional<SampleBundleInfo> ObtainBundleInfoForUid(uint32_t uid) = 0;
58 };
59 extern "C" __attribute__((visibility("default"))) INetBundle *GetNetBundle();
60 extern "C" __attribute__((visibility("default"))) bool IsAtomicService(std::string &bundleName);
61 } // namespace NetManagerStandard
62 } // namespace OHOS
63 #endif // NET_BUNDLE__H