1 /*
2  * Copyright (c) 2021-2023 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_SLITE_ABILITYMS_SLITE_CLIENT_H
17 #define OHOS_ABILITY_SLITE_ABILITYMS_SLITE_CLIENT_H
18 
19 #include "ability_service_interface.h"
20 #include "ability_record_observer.h"
21 #include "mission_info.h"
22 #include "nocopyable.h"
23 #include "want.h"
24 
25 namespace OHOS {
26 namespace AbilitySlite {
27 struct StartAbilityData {
28     Want *want = nullptr;
29     uint32_t curTask = 0;
30 };
31 
32 class AbilityMsClient {
33 public:
GetInstance()34     static AbilityMsClient &GetInstance()
35     {
36         static AbilityMsClient instance;
37         return instance;
38     }
39 
40     bool Initialize() const;
41 
42     int32_t StartAbility(const Want *want) const;
43 
44     int32_t TerminateAbility(uint64_t token) const;
45 
46     int32_t TerminateMission(uint32_t mission) const;
47 
48     int32_t TerminateAll(const char* excludedBundleName) const;
49 
50     int32_t SchedulerLifecycleDone(uint64_t token, int32_t state) const;
51 
52     int32_t ForceStopBundle(uint64_t token) const;
53 
54     int32_t ForceStop(const char *bundleName) const;
55 
56     int32_t ForceStop(const Want *want) const;
57 
58     ElementName *GetTopAbility() const;
59 
60     void SetServiceIdentity(const Identity *identity);
61 
62     int32_t AddAbilityRecordObserver(AbilityRecordObserver *observer);
63     int32_t RemoveAbilityRecordObserver(AbilityRecordObserver *observer);
64 
65     MissionInfoList *GetMissionInfos(uint32_t maxNum) const;
66 
67 private:
68     AbilityMsClient() = default;
69 
70     ~AbilityMsClient() = default;
71 
72     int32_t SendRequestToAms(Request &request) const;
73 
74     AmsSliteInterface *amsProxy_ { nullptr };
75     const Identity *identity_ { nullptr };
76 
77     DISALLOW_COPY_AND_MOVE(AbilityMsClient);
78 };
79 } // namespace AbilitySlite
80 } // namespace OHOS
81 
82 #endif // OHOS_ABILITY_SLITE_ABILITYMS_SLITE_CLIENT_H
83