1 /*
2  * Copyright (c) 2022 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 ABILITY_MANAGER_ADAPTER_H
17 #define ABILITY_MANAGER_ADAPTER_H
18 
19 #include <chrono>
20 #include <condition_variable>
21 #include <mutex>
22 #include <string>
23 #include <atomic>
24 
25 namespace OHOS::AVSession {
26 enum class Status {
27     ABILITY_STATUS_INIT = 0,
28     ABILITY_STATUS_RUNNING = 1,
29     ABILITY_STATUS_FAILED = 2,
30     ABILITY_STATUS_SUCCESS = 3,
31 };
32 
33 class AbilityManagerAdapter {
34 public:
35     AbilityManagerAdapter(const std::string& bundleName, const std::string& abilityName);
36     ~AbilityManagerAdapter();
37 
38     __attribute__((no_sanitize("cfi"))) int32_t StartAbilityByCall(std::string& sessionId);
39 
40     void StartAbilityByCallDone(const std::string& sessionId);
41 
42 private:
43     void WaitForTimeout(uint32_t timeout);
44 
45 private:
46     static constexpr int32_t ABILITY_START_TIMEOUT_MS = 5000;
47     static constexpr const char *DEFAULT_BUNDLE_NAME = "com.example.himusicdemo";
48     std::condition_variable syncCon_;
49     std::mutex syncMutex_;
50     std::atomic<Status> status_ = Status::ABILITY_STATUS_INIT;
51     std::string bundleName_;
52     std::string abilityName_;
53     std::string sessionId_;
54 };
55 } // namespace OHOS::AVSession
56 #endif // ABILITY_MANAGER_ADAPTER_H