• 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_UTIL_H
16 #define INTELL_VOICE_UTIL_H
17 #include <cstdint>
18 #include <string>
19 #include <vector>
20 #include <memory>
21 #include <map>
22 
23 namespace OHOS {
24 namespace IntellVoiceUtils {
25 const std::string OHOS_MICROPHONE_PERMISSION = "ohos.permission.MICROPHONE";
26 const std::string KEY_WAKEUP_ENGINE_BUNDLE_NAME = "WakeupEngineBundleName";
27 const std::string KEY_WAKEUP_ENGINE_ABILITY_NAME = "WakeupEngineAbilityName";
28 
29 enum IntellVoicePermissionState {
30     INTELL_VOICE_PERMISSION_START = 0,
31     INTELL_VOICE_PERMISSION_STOP = 1,
32 };
33 
34 class IntellVoiceUtil final {
35 public:
36     static uint32_t GetHdiVersionId(uint32_t majorVer, uint32_t minorVer);
37     static bool DeinterleaveAudioData(const int16_t *buffer, uint32_t size, int32_t channelCnt,
38         std::vector<std::vector<uint8_t>> &audioData);
39     static int32_t VerifySystemPermission(const std::string &permissionName);
40     static bool ReadFile(const std::string &filePath, std::shared_ptr<uint8_t> &buffer, uint32_t &size);
41     static void SplitStringToKVPair(const std::string &inputStr, std::map<std::string, std::string> &kvpairs);
42     static bool IsFileExist(const std::string &filePath);
43     static bool RecordPermissionPrivacy(const std::string &permissionName, uint32_t targetTokenId,
44         IntellVoicePermissionState state);
45     static void StartAbility(const std::string &event);
46 
47 private:
48     static bool VerifyClientPermission(const std::string &permissionName);
49     static bool CheckIsSystemApp();
50 };
51 }
52 }
53 #endif
54