1 /*
2  * Copyright (c) 2024 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_RUNTIME_CJ_ABILITY_OBJECT_H
17 #define OHOS_ABILITY_RUNTIME_CJ_ABILITY_OBJECT_H
18 
19 #include <memory>
20 
21 #include "ability.h"
22 #include "cj_runtime.h"
23 #include "configuration.h"
24 
25 #ifdef WINDOWS_PLATFORM
26 #define CJ_EXPORT __declspec(dllexport)
27 #else
28 #define CJ_EXPORT __attribute__((visibility("default")))
29 #endif
30 
31 using AbilityHandle = void*;
32 using WantHandle = void*;
33 using WindowStagePtr = void*;
34 using VectorStringHandle = void*;
35 
36 extern "C" {
37 struct CJConfiguration {
38     bool isValid;
39     const char* language;
40     int32_t colorMode;
41     int32_t direction;
42     int32_t screenDensity;
43     int32_t displayId;
44 };
45 }
46 
47 extern "C" {
48 struct CJLaunchParam {
49     int32_t launchReason;
50     int32_t lastExitReason;
51 };
52 
53 struct CJAbilityFuncs {
54     int64_t (*cjAbilityCreate)(const char* name);
55     void (*cjAbilityRelease)(int64_t id);
56     void (*cjAbilityOnStart)(int64_t id, WantHandle want, CJLaunchParam launchParam);
57     void (*cjAbilityOnStop)(int64_t id);
58     void (*cjAbilityOnSceneCreated)(int64_t id, WindowStagePtr cjWindowStage);
59     void (*cjAbilityOnSceneRestored)(int64_t id, WindowStagePtr cjWindowStage);
60     void (*cjAbilityOnSceneDestroyed)(int64_t id);
61     void (*cjAbilityOnForeground)(int64_t id, WantHandle want);
62     void (*cjAbilityOnBackground)(int64_t id);
63     void (*cjAbilityOnConfigurationUpdated)(int64_t id, CJConfiguration configuration);
64     void (*cjAbilityOnNewWant)(int64_t id, WantHandle want, CJLaunchParam launchParam);
65     VectorStringHandle (*cjAbilityDump)(int64_t id, VectorStringHandle params);
66     int32_t (*cjAbilityOnContinue)(int64_t id, const char* params);
67     void (*cjAbilityInit)(int64_t id, void* ability);
68 };
69 
70 CJ_EXPORT void RegisterCJAbilityFuncs(void (*registerFunc)(CJAbilityFuncs*));
71 }
72 
73 namespace OHOS {
74 
75 namespace Rosen {
76 class CJWindowStageImpl;
77 }
78 
79 namespace AbilityRuntime {
80 class CJAbilityObject {
81 public:
82     static std::shared_ptr<CJAbilityObject> LoadModule(const std::string& name);
83 
CJAbilityObject(int64_t id)84     explicit CJAbilityObject(int64_t id) : id_(id) {}
85     ~CJAbilityObject();
86     void OnStart(const AAFwk::Want& want, const AAFwk::LaunchParam& launchParam) const;
87     void OnStop() const;
88     void OnSceneCreated(OHOS::Rosen::CJWindowStageImpl* cjWindowStage) const;
89     void OnSceneRestored(OHOS::Rosen::CJWindowStageImpl* cjWindowStage) const;
90     void OnSceneDestroyed() const;
91     void OnForeground(const AAFwk::Want& want) const;
92     void OnBackground() const;
93     void OnConfigurationUpdated(const std::shared_ptr<AppExecFwk::Configuration>& configuration) const;
94     void OnNewWant(const AAFwk::Want& want, const AAFwk::LaunchParam& launchParam) const;
95     void Dump(const std::vector<std::string>& params, std::vector<std::string>& info) const;
96     int32_t OnContinue(AAFwk::WantParams &wantParams) const;
97     void Init(AbilityHandle ability) const;
98 
99 private:
100     int64_t id_ = 0;
101 };
102 } // namespace AbilityRuntime
103 } // namespace OHOS
104 
105 #endif // OHOS_ABILITY_RUNTIME_CJ_ABILITY_OBJECT_H
106