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_slite_feature.h"
17
18 #include "ability_errors.h"
19 #include "ability_info.h"
20 #include "ability_message_id.h"
21 #include "ability_service_interface.h"
22 #include "abilityms_log.h"
23 #include "adapter.h"
24 #include "ohos_init.h"
25 #include "samgr_lite.h"
26 #include "securec.h"
27 #include "utils.h"
28 #include "want_utils.h"
29
30 namespace OHOS {
31 AbilityMgrSliteFeatureImpl g_amsSliteImpl = {
32 DEFAULT_IUNKNOWN_ENTRY_BEGIN,
33 .StartAbility = AbilityMgrSliteFeature::StartAbility,
34 .TerminateAbility = AbilityMgrSliteFeature::TerminateAbility,
35 .SchedulerLifecycleDone = AbilityMgrSliteFeature::SchedulerLifecycleDone,
36 .ForceStopBundle = AbilityMgrSliteFeature::ForceStopBundle,
37 .GetTopAbility = AbilityMgrSliteFeature::GetTopAbility,
38 DEFAULT_IUNKNOWN_ENTRY_END
39 };
40
Init()41 static void Init()
42 {
43 SamgrLite *samgrLite = SAMGR_GetInstance();
44 CHECK_NULLPTR_RETURN(samgrLite, "AbilityMgrSliteFeature", "get samgr error");
45 BOOL result = samgrLite->RegisterFeature(AMS_SERVICE, AbilityMgrSliteFeature::GetInstance());
46 if (result == FALSE) {
47 PRINTE("AbilityMgrSliteFeature", "ams register feature failure");
48 return;
49 }
50 g_amsSliteImpl.ams = AbilityMgrSliteFeature::GetInstance();
51 auto publicApi = GET_IUNKNOWN(g_amsSliteImpl);
52 CHECK_NULLPTR_RETURN(publicApi, "AbilityMgrSliteFeatureLite", "publicApi is nullptr");
53 BOOL apiResult = samgrLite->RegisterFeatureApi(AMS_SERVICE, AMS_SLITE_FEATURE, publicApi);
54 PRINTI("AbilityMgrSliteFeature", "ams feature init %{public}s", apiResult ? "success" : "failure");
55 }
56 SYSEX_FEATURE_INIT(Init);
57
AbilityMgrSliteFeature()58 AbilityMgrSliteFeature::AbilityMgrSliteFeature() : Feature(), identity_()
59 {
60 this->Feature::GetName = AbilityMgrSliteFeature::GetFeatureName;
61 this->Feature::OnInitialize = AbilityMgrSliteFeature::OnFeatureInitialize;
62 this->Feature::OnStop = AbilityMgrSliteFeature::OnFeatureStop;
63 this->Feature::OnMessage = AbilityMgrSliteFeature::OnFeatureMessage;
64 }
65
GetFeatureName(Feature * feature)66 const char *AbilityMgrSliteFeature::GetFeatureName(Feature *feature)
67 {
68 (void) feature;
69 return AMS_SLITE_FEATURE;
70 }
71
OnFeatureInitialize(Feature * feature,Service * parent,Identity identity)72 void AbilityMgrSliteFeature::OnFeatureInitialize(Feature *feature, Service *parent, Identity identity)
73 {
74 CHECK_NULLPTR_RETURN(feature, "AbilityMgrSliteFeature", "initialize fail");
75 (static_cast<AbilityMgrSliteFeature *>(feature))->identity_ = identity;
76 AbilityService::GetInstance().StartLauncher();
77 }
78
OnFeatureStop(Feature * feature,Identity identity)79 void AbilityMgrSliteFeature::OnFeatureStop(Feature *feature, Identity identity)
80 {
81 (void) feature;
82 (void) identity;
83 }
84
OnFeatureMessage(Feature * feature,Request * request)85 BOOL AbilityMgrSliteFeature::OnFeatureMessage(Feature *feature, Request *request)
86 {
87 if (feature == nullptr || request == nullptr) {
88 return FALSE;
89 }
90 return TRUE;
91 }
92
StartAbility(const Want * want)93 int32 AbilityMgrSliteFeature::StartAbility(const Want *want)
94 {
95 int32 ret = AbilityService::GetInstance().StartAbility(want);
96 ClearWant(const_cast<Want *>(want));
97 return ret;
98 }
99
TerminateAbility(uint64_t token)100 int32 AbilityMgrSliteFeature::TerminateAbility(uint64_t token)
101 {
102 uint16_t slitToken = token & 0xFFFF;
103 return AbilityService::GetInstance().TerminateAbility(slitToken);
104 }
105
SchedulerLifecycleDone(uint64_t token,int state)106 int32 AbilityMgrSliteFeature::SchedulerLifecycleDone(uint64_t token, int state)
107 {
108 return AbilityService::GetInstance().SchedulerLifecycleDone(token, state);
109 }
110
ForceStopBundle(uint64_t token)111 int32 AbilityMgrSliteFeature::ForceStopBundle(uint64_t token)
112 {
113 uint16_t slitToken = token & 0xFFFF;
114 return AbilityService::GetInstance().ForceStopBundle(slitToken);
115 }
116
GetTopAbility()117 ElementName *AbilityMgrSliteFeature::GetTopAbility()
118 {
119 return AbilityService::GetInstance().GetTopAbility();
120 }
121 } // namespace OHOS
122