• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 EXTENSION_ABILITY_CONNECTION_H
17 #define EXTENSION_ABILITY_CONNECTION_H
18 
19 #include <condition_variable>
20 #include "ability_connect_callback_stub.h"
21 
22 namespace OHOS {
23 namespace Accessibility {
24 using namespace OHOS::AppExecFwk;
25 
26 class ExtensionAbilityConnection : public AAFwk::AbilityConnectionStub {
27 public:
28     void OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr <IRemoteObject> &remoteObject,
29         int32_t resultCode) override;
30 
31     void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
32 
33     sptr<IRemoteObject> GetRemoteObject();
34 
35 private:
36     sptr <IRemoteObject> remoteObject_;
37     std::mutex mutex_;
38     std::condition_variable cv_;
39     bool waitFlag_ = false;
40 };
41 
42 class ExtensionAbilityManager {
43 public:
44     static ExtensionAbilityManager &GetInstance();
45 
46     void VoiceRecognize(int32_t soundType);
47 
48     ExtensionAbilityManager(const ExtensionAbilityManager&) = delete;
49 
50     ExtensionAbilityManager(ExtensionAbilityManager&&) = delete;
51 
52     ExtensionAbilityManager& operator=(const ExtensionAbilityManager&) = delete;
53 
54     ExtensionAbilityManager& operator=(ExtensionAbilityManager&&) = delete;
55 
56 private:
57     ExtensionAbilityManager();
58 
59     ~ExtensionAbilityManager() = default;
60 
61     int32_t ConnectSettingsExtService();
62 
63     void DisconnectSettingsExtService();
64 
65     sptr<IRemoteObject> GetRemoteObject();
66 
67     std::string CreateJsonMessage(int32_t soundType);
68 
69     void SendRequestToSetting(const sptr<IRemoteObject> &remoteObject, const std::string &message);
70 
71     sptr <ExtensionAbilityConnection> connection_;
72 };
73 } // namespace Accessibility
74 } // namespace OHOS
75 #endif // EXTENSION_ABILITY_CONNECTION_H
76