• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef INTELL_VOICE_SERVICE_H
16 #define INTELL_VOICE_SERVICE_H
17 #include <map>
18 #include <functional>
19 #include "accesstoken_kit.h"
20 #include "ipc_skeleton.h"
21 #include "system_ability.h"
22 #include "intell_voice_service_stub.h"
23 #include "i_intell_voice_engine.h"
24 #include "system_event_observer.h"
25 #include "i_intell_voice_service.h"
26 
27 #include "trigger_manager.h"
28 
29 namespace OHOS {
30 namespace IntellVoiceEngine {
31 class IntellVoiceService : public SystemAbility, public IntellVoiceServiceStub {
32     DECLARE_SYSTEM_ABILITY(IntellVoiceService);
33 public:
34     explicit IntellVoiceService(int32_t systemAbilityId, bool runOnCreate = true);
35     ~IntellVoiceService();
36     int32_t CreateIntellVoiceEngine(IntellVoiceEngineType type, sptr<IIntellVoiceEngine> &inst) override;
37     int32_t ReleaseIntellVoiceEngine(IntellVoiceEngineType type) override;
38 
39     bool RegisterDeathRecipient(IntellVoiceEngineType type, const sptr<IRemoteObject> &object) override;
40     bool DeregisterDeathRecipient(IntellVoiceEngineType type) override;
41 
42     int32_t GetUploadFiles(int numMax, std::vector<UploadHdiFile> &files) override;
43 
44     int32_t SetParameter(const std::string &keyValueList) override;
45     std::string GetParameter(const std::string &key) override;
46     int32_t GetWakeupSourceFilesList(std::vector<std::string>& cloneFiles) override;
47     int32_t GetWakeupSourceFile(const std::string &filePath, std::vector<uint8_t> &buffer) override;
48     int32_t SendWakeupFile(const std::string &filePath, const std::vector<uint8_t> &buffer) override;
49     int32_t EnrollWithWakeupFilesForResult(const std::string &wakeupInfo, const sptr<IRemoteObject> object) override;
50     int32_t ClearUserData() override;
51 
52     class PerStateChangeCbCustomizeCallback : public Security::AccessToken::PermStateChangeCallbackCustomize {
53     public:
PerStateChangeCbCustomizeCallback(const Security::AccessToken::PermStateChangeScope & scopeInfo)54         explicit PerStateChangeCbCustomizeCallback(const Security::AccessToken::PermStateChangeScope &scopeInfo)
55             : PermStateChangeCallbackCustomize(scopeInfo) {}
~PerStateChangeCbCustomizeCallback()56         ~PerStateChangeCbCustomizeCallback() {}
57 
58         void PermStateChangeCallback(Security::AccessToken::PermStateChangeInfo& result) override;
59     };
60 
61 protected:
62     void OnStart(const SystemAbilityOnDemandReason &startReason) override;
63     void OnStop() override;
64     int32_t OnIdle(const SystemAbilityOnDemandReason &idleReason) override;
65     void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
66     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
67 
68 private:
69     void CreateSystemEventObserver();
70     void RegisterPermissionCallback(const std::string &permissionName);
71     void LoadIntellVoiceHost();
72     void UnloadIntellVoiceHost();
73     void OnCommonEventServiceChange(bool isAdded);
74     void OnDistributedKvDataServiceChange(bool isAdded);
75 #ifdef SUPPORT_TELEPHONY_SERVICE
76     void OnTelephonyStateRegistryServiceChange(bool isAdded);
77 #endif
78     void OnAudioDistributedServiceChange(bool isAdded);
79     void OnAudioPolicyServiceChange(bool isAdded);
80     void OnPowerManagerServiceChange(bool isAdded);
81 
82 private:
83     int32_t reasonId_ = -1;
84     std::shared_ptr<SystemEventObserver> systemEventObserver_ = nullptr;
85     std::map<int32_t, std::function<void(bool)>> systemAbilityChangeMap_;
86 };
87 }
88 }
89 #endif
90