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 uint32_t curTask_ = 0; 65 66 private: 67 static uint16_t GenerateToken(); 68 AbilityService(); 69 int32_t StartAbility(AbilitySvcInfo *info); 70 int32_t StartRemoteAbility(const Want *want); 71 int32_t PreCheckStartAbility(const char *bundleName, const char *path, const void *data, uint16_t dataLength); 72 bool CheckResponse(const char *bundleName); 73 int32_t SchedulerLifecycle(uint64_t token, int32_t state); 74 int32_t SchedulerLifecycleInner(const AbilityRecord *record, int32_t state); 75 void SchedulerAbilityLifecycle(SliteAbility *ability, const Want &want, int32_t state); 76 int32_t CreateAppTask(AbilityRecord *record); 77 void OnActiveDone(uint16_t token); 78 void OnBackgroundDone(uint16_t token); 79 void OnDestroyDone(uint16_t token); 80 void DeleteRecordInfo(uint16_t token); 81 bool SendMsgToJsAbility(int32_t msgId, const AbilityRecord *record); 82 void SetAbilityState(uint64_t token, int32_t state); 83 void UpdateRecord(AbilitySvcInfo *info); 84 int32_t ForceStopBundleInner(uint16_t token); 85 bool IsValidAbility(AbilityInfo *abilityInfo); 86 87 uint16_t pendingToken_ { 0 }; 88 AbilityList abilityList_ {}; 89 AbilityStack abilityStack_ {}; 90 SliteAbility *nativeAbility_ = nullptr; 91 static LifecycleFuncStr lifecycleFuncList_[STATE_BACKGROUND + 1]; 92 }; 93 } // namespace OHOS 94 #endif // OHOS_ABILITY_SERVICE_H 95