1/*
2 * Copyright (c) 2020-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#include <hilog_common.h>
17#include <log_utils.h>
18
19#include "log_domains.h"
20
21namespace OHOS {
22namespace HiviewDFX {
23using namespace std;
24
25static const KVMap<uint32_t, string> g_DomainList({
26    {0xD000100, "Bluetooth"},
27    {0xD000300, "NFC"},
28    {0xD000F00, "For test using"},
29    {0xD001100, "AppExecFwk"},
30    {0xD001200, "Notification"},
31    {0xD001300, "AAFwk"},
32    {0xD001400, "Graphics"},
33    {0xD001500, "Communication"},
34    {0xD001600, "DistributedData"},
35    {0xD001700, "Resource"},
36    {0xD001800, "SAMgr"},
37    {0xD001B00, "Account"},
38    {0xD001C00, "MiscService"},
39    {0xD001D00, "Barrierfree"},
40    {0xD001E00, "Global"},
41    {0xD001F00, "Telephony"},
42    {0xD002100, "AI"},
43    {0xD002200, "MSDP"},
44    {0xD002300, "Location"},
45    {0xD002400, "UserIAM"},
46    {0xD002500, "Drivers"},
47    {0xD002600, "Kernel"},
48    {0xD002700, "Sensors"},
49    {0xD002800, "MultiModelInput"},
50    {0xD002900, "Power"},
51    {0xD002A00, "USB"},
52    {0xD002B00, "MultiMedia"},
53    {0xD002C00, "StartUp"},
54    {0xD002D00, "DFX"},
55    {0xD002E00, "Update"},
56    {0xD002F00, "Security"},
57    {0xD003100, "TestSystem"},
58    {0xD003200, "TestSystem"},
59    {0xD003300, "DevelopmentToolchain"},
60    {0xD003900, "Ace"},
61    {0xD003B00, "JSConsole"},
62    {0xD003D00, "Utils"},
63    {0xD003F00, "CompilerRuntime"},
64    {0xD004100, "DistributedHardware"},
65    {0xD004200, "Windows"},
66    {0xD004300, "Storage"},
67    {0xD004400, "DeviceProfile"},
68    {0xD004500, "WebView"},
69    {0xD004600, "Interconnection"},
70    {0xD004700, "Cloud"},
71    {0xD004800, "Manufacture"},
72    {0xD004900, "HealthSport"},
73    {0xD005100, "PcService"},
74    {0xD005200, "WpaSupplicant"},
75    {0xD005300, "Push"},
76    {0xD005400, "CarService"},
77    {0xD005500, "DeviceCloudGateway"},
78    {0xD005600, "AppSecurityPrivacy"},
79    {0xD005700, "DSoftBus"},
80    {0xD005800, "FindNetwork"},
81    {0xD005900, "VirtService"},
82    {0xD005A00, "AccessControl"},
83    {0xD005B00, "Tee"},
84    {0xD005C00, "Connectivity"},
85    {0xD005D00, "XTS"},
86    {0xD00AD00, "ASystem"},
87}, __UINT32_MAX__, "Invalid");
88
89static const uint32_t APP_DOMAIN_MASK = 0xFFFF0000;
90static const uint32_t OS_SUB_DOMAIN_MASK = 0xFFFFFF00;
91bool IsValidDomain(LogType type, uint32_t domain)
92{
93    if (type == LOG_APP) {
94        if ((domain & APP_DOMAIN_MASK) == 0) {
95            return true;
96        }
97        return false;
98    } else {
99        if (domain >= DOMAIN_OS_MIN && domain <= DOMAIN_OS_MAX) {
100            return g_DomainList.IsValidKey((domain & OS_SUB_DOMAIN_MASK));
101        }
102        return false;
103    }
104}
105} // namespace HiviewDFX
106} // namespace OHOS