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 "ipc_auth_lite.h"
17
18 #include <ohos_init.h>
19
20 #include "log.h"
21
22 #include "feature.h"
23 #include "iunknown.h"
24 #include "samgr_lite.h"
25
26 #include "ipc_auth.h"
27
28 static void Init(void);
29 static const char *GetName(Feature *feature);
30 static void OnInitialize(Feature *feature, Service *parent, Identity identity);
31 static void OnStop(Feature *feature, Identity identity);
32 static BOOL OnMessage(const Feature *feature, const Request *request);
33
34 static IpcAuthLite g_authLite = {
35 .GetName = GetName,
36 .OnInitialize = OnInitialize,
37 .OnStop = OnStop,
38 .OnMessage = OnMessage,
39 DEFAULT_IUNKNOWN_ENTRY_BEGIN,
40 .GetCommunicationStrategy = GetCommunicationStrategy,
41 .IsCommunicationAllowed = IsCommunicationAllowed,
42 DEFAULT_IUNKNOWN_ENTRY_END,
43 .identity = {-1, -1, NULL},
44 };
45
Init(void)46 static void Init(void)
47 {
48 SAMGR_GetInstance()->RegisterFeature(PERMISSION_SERVICE, (Feature *)&g_authLite);
49 SAMGR_GetInstance()->RegisterFeatureApi(PERMISSION_SERVICE, IPCAUTH, GET_IUNKNOWN(g_authLite));
50 HILOG_INFO(HILOG_MODULE_APP, "Init ipcAuth feature success");
51 }
52 APP_FEATURE_INIT(Init);
53
GetName(Feature * feature)54 static const char *GetName(Feature *feature)
55 {
56 (void)feature;
57 return IPCAUTH;
58 }
59
OnInitialize(Feature * feature,Service * parent,Identity identity)60 static void OnInitialize(Feature *feature, Service *parent, Identity identity)
61 {
62 (void)parent;
63 if (feature == NULL) {
64 return;
65 }
66 IpcAuthLite *authLite = (IpcAuthLite *)feature;
67 authLite->identity = identity;
68 HILOG_INFO(HILOG_MODULE_APP, "OnInitialize ipcAuth feature");
69 }
70
OnStop(Feature * feature,Identity identity)71 static void OnStop(Feature *feature, Identity identity)
72 {
73 (void)feature;
74 (void)identity;
75 }
76
OnMessage(const Feature * feature,const Request * request)77 static BOOL OnMessage(const Feature *feature, const Request *request)
78 {
79 if (feature == NULL || request == NULL) {
80 return FALSE;
81 }
82 // call func
83 return TRUE;
84 }
85