• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_SCORE_H
17 #define NET_SCORE_H
18 
19 #include <unordered_map>
20 #include <vector>
21 
22 #include "net_supplier.h"
23 
24 namespace OHOS {
25 namespace NetManagerStandard {
26 using NetTypeScore = std::unordered_map<NetBearType, int32_t>;
27 constexpr int32_t NET_TYPE_SCORE_INTERVAL = 10;
28 constexpr int32_t NET_VALID_SCORE = 4 * NET_TYPE_SCORE_INTERVAL;
29 enum class NetTypeScoreValue : int32_t {
30     USB_VALUE               = 4 * NET_TYPE_SCORE_INTERVAL,
31     BLUETOOTH_VALUE         = 5 * NET_TYPE_SCORE_INTERVAL,
32     CELLULAR_VALUE          = 6 * NET_TYPE_SCORE_INTERVAL,
33     WIFI_VALUE              = 7 * NET_TYPE_SCORE_INTERVAL,
34     ETHERNET_VALUE          = 8 * NET_TYPE_SCORE_INTERVAL,
35     VPN_VALUE               = 9 * NET_TYPE_SCORE_INTERVAL,
36     WIFI_AWARE_VALUE        = 10 * NET_TYPE_SCORE_INTERVAL
37 };
38 
39 class NetScore {
40 public:
41     NetScore() = default;
42     ~NetScore() = default;
43     bool GetServiceScore(sptr<NetSupplier> &supplier);
44 
45 private:
46     NetTypeScore netTypeScore_ = {
47         {BEARER_CELLULAR, static_cast<int32_t>(NetTypeScoreValue::CELLULAR_VALUE)},
48         {BEARER_WIFI, static_cast<int32_t>(NetTypeScoreValue::WIFI_VALUE)},
49         {BEARER_BLUETOOTH, static_cast<int32_t>(NetTypeScoreValue::BLUETOOTH_VALUE)},
50         {BEARER_ETHERNET, static_cast<int32_t>(NetTypeScoreValue::ETHERNET_VALUE)},
51         {BEARER_VPN, static_cast<int32_t>(NetTypeScoreValue::VPN_VALUE)},
52         {BEARER_WIFI_AWARE, static_cast<int32_t>(NetTypeScoreValue::WIFI_AWARE_VALUE)}};
53 };
54 } // namespace NetManagerStandard
55 } // namespace OHOS
56 #endif // NET_SCORE_H
57