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 27 enum IntellVoicePermissionState { 28 INTELL_VOICE_PERMISSION_START = 0, 29 INTELL_VOICE_PERMISSION_STOP = 1, 30 }; 31 32 class IntellVoiceUtil final { 33 public: 34 static uint32_t GetHdiVersionId(uint32_t majorVer, uint32_t minorVer); 35 static bool DeinterleaveAudioData(const int16_t *buffer, uint32_t size, int32_t channelCnt, 36 std::vector<std::vector<uint8_t>> &audioData); 37 static int32_t VerifySystemPermission(const std::string &permissionName); 38 static bool ReadFile(const std::string &filePath, std::shared_ptr<uint8_t> &buffer, uint32_t &size); 39 static void SplitStringToKVPair(const std::string &inputStr, std::map<std::string, std::string> &kvpairs); 40 static bool IsFileExist(const std::string &filePath); 41 static bool RecordPermissionPrivacy(const std::string &permissionName, uint32_t targetTokenId, 42 IntellVoicePermissionState state); 43 44 private: 45 static bool VerifyClientPermission(const std::string &permissionName); 46 static bool CheckIsSystemApp(); 47 }; 48 } 49 } 50 #endif 51