1 /*
2  * Copyright (c) 2020 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 "ability_mgr_service.h"
17 
18 #include "ability_errors.h"
19 #ifdef __LITEOS_M__
20 #include "ability_record_manager.h"
21 #endif
22 #include "ability_service_interface.h"
23 #include "adapter.h"
24 #include "ohos_init.h"
25 #include "samgr_lite.h"
26 #include "util/abilityms_log.h"
27 
28 namespace OHOS {
29 const int QUEUE_SIZE = 20;
30 #ifdef __LITEOS_M__
31 const int BYTE_OFFSET = 16;
32 #endif
33 
AbilityMgrService()34 AbilityMgrService::AbilityMgrService() : Service(), identity_()
35 {
36     this->Service::GetName = AbilityMgrService::GetServiceName;
37     this->Service::Initialize = AbilityMgrService::ServiceInitialize;
38     this->Service::MessageHandle = AbilityMgrService::ServiceMessageHandle;
39     this->Service::GetTaskConfig = AbilityMgrService::GetServiceTaskConfig;
40 }
41 
Init()42 static void Init()
43 {
44     SamgrLite *sm = SAMGR_GetInstance();
45     CHECK_NULLPTR_RETURN(sm, "AbilityManagerService", "get samgr error");
46     BOOL result = sm->RegisterService(AbilityMgrService::GetInstance());
47     PRINTI("AbilityManagerService", "ams starts %{public}s", result ? "successfully" : "unsuccessfully");
48 }
49 SYSEX_SERVICE_INIT(Init);
50 
GetServiceName(Service * service)51 const char *AbilityMgrService::GetServiceName(Service *service)
52 {
53     (void)service;
54     return AMS_SERVICE;
55 }
56 
GetIdentity()57 const Identity *AbilityMgrService::GetIdentity()
58 {
59     return &identity_;
60 }
61 
ServiceInitialize(Service * service,Identity identity)62 BOOL AbilityMgrService::ServiceInitialize(Service *service, Identity identity)
63 {
64     if (service == nullptr) {
65         return FALSE;
66     }
67     AbilityMgrService *abilityManagerService = static_cast<AbilityMgrService *>(service);
68     abilityManagerService->identity_ = identity;
69     return TRUE;
70 }
71 
ServiceMessageHandle(Service * service,Request * request)72 BOOL AbilityMgrService::ServiceMessageHandle(Service *service, Request *request)
73 {
74     if (request == nullptr) {
75         return FALSE;
76     }
77     return TRUE;
78 }
79 
GetServiceTaskConfig(Service * service)80 TaskConfig AbilityMgrService::GetServiceTaskConfig(Service *service)
81 {
82     TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, AMS_TASK_STACK_SIZE, QUEUE_SIZE, SINGLE_TASK};
83     return config;
84 }
85 } // namespace OHOS
86