• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_ABILITY_SERVICE_H
17 #define OHOS_ABILITY_SERVICE_H
18 
19 #include <stdlib.h>
20 
21 #include "ability_list.h"
22 #include "ability_record.h"
23 #include "ability_stack.h"
24 #include "adapter.h"
25 #include "js_app_host.h"
26 #include "nocopyable.h"
27 #include "want.h"
28 #include "slite_ability.h"
29 #include "ability_state.h"
30 
31 namespace OHOS {
32 struct AbilitySvcInfo {
33     char *bundleName;
34     char *path;
35     void *data;
36     uint16_t dataLength;
37 };
38 
39 class AbilityService : public NoCopyable {
40 public:
41     typedef void (AbilityService::*LifecycleFunc)(uint16_t token);
42 
43     struct LifecycleFuncStr {
44         int32_t state;
45         LifecycleFunc func_ptr;
46     };
47 
GetInstance()48     static AbilityService& GetInstance()
49     {
50         static AbilityService instance;
51         return instance;
52     }
53     ~AbilityService() override;
54     int32_t StartAbility(const Want *want);
55     int32_t TerminateAbility(uint16_t token);
56     int32_t ForceStop(char *bundlename);
57     int32_t ForceStopBundle(uint16_t token);
58     int32_t SchedulerLifecycleDone(uint64_t token, int32_t state);
59     ElementName *GetTopAbility();
60     void setNativeAbility(const SliteAbility *ability);
61     void StartLauncher();
62     void CleanWant();
63     Want *want_ = nullptr;
64 
65 private:
66     static uint16_t GenerateToken();
67     AbilityService();
68     int32_t StartAbility(AbilitySvcInfo *info);
69     int32_t PreCheckStartAbility(const char *bundleName, const char *path, const void *data, uint16_t dataLength);
70     bool CheckResponse(const char *bundleName);
71     int32_t SchedulerLifecycle(uint64_t token, int32_t state);
72     int32_t SchedulerLifecycleInner(const AbilityRecord *record, int32_t state);
73     void SchedulerAbilityLifecycle(SliteAbility *ability, const Want &want, int32_t state);
74     int32_t CreateAppTask(AbilityRecord *record);
75     void OnActiveDone(uint16_t token);
76     void OnBackgroundDone(uint16_t token);
77     void OnDestroyDone(uint16_t token);
78     void DeleteRecordInfo(uint16_t token);
79     bool SendMsgToJsAbility(int32_t msgId, const AbilityRecord *record);
80     void SetAbilityState(uint64_t token, int32_t state);
81     void UpdataRecord(AbilitySvcInfo *info);
82     int32_t ForceStopBundleInner(uint16_t token);
83     bool IsValidAbility(AbilityInfo *abilityInfo);
84 
85     uint16_t pendingToken_ { 0 };
86     AbilityList abilityList_ {};
87     AbilityStack abilityStack_ {};
88     SliteAbility *nativeAbility_ = nullptr;
89     static LifecycleFuncStr lifecycleFuncList_[STATE_BACKGROUND + 1];
90 };
91 } // namespace OHOS
92 #endif  // OHOS_ABILITY_SERVICE_H
93