• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #include "recorder_napi_utils.h"
17 #include <map>
18 #include <string>
19 #include "tokenid_kit.h"
20 #include "ipc_skeleton.h"
21 #include "access_token.h"
22 #include "accesstoken_kit.h"
23 #include "media_errors.h"
24 
25 using namespace OHOS::Security::AccessToken;
26 
27 namespace OHOS {
28 namespace Media {
29 const std::map<std::string_view, int32_t> g_mimeStrToCodecFormat = {
30     { CodecMimeType::AUDIO_AAC, AudioCodecFormat::AAC_LC },
31     { CodecMimeType::VIDEO_AVC, VideoCodecFormat::H264 },
32     { CodecMimeType::VIDEO_MPEG4, VideoCodecFormat::MPEG4 },
33 };
34 
35 const std::map<std::string, OutputFormatType> g_extensionToOutputFormat = {
36     { "mp4", OutputFormatType::FORMAT_MPEG_4 },
37     { "m4a", OutputFormatType::FORMAT_M4A },
38 };
39 
IsSystemApp()40 bool IsSystemApp()
41 {
42     uint64_t accessTokenIDEx = IPCSkeleton::GetCallingFullTokenID();
43     bool isSystemApp = TokenIdKit::IsSystemAppByFullTokenID(accessTokenIDEx);
44     return isSystemApp;
45 }
46 
SystemPermission()47 bool SystemPermission()
48 {
49     auto tokenId = IPCSkeleton::GetCallingTokenID();
50     auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId);
51     if (tokenType == Security::AccessToken::TOKEN_NATIVE || tokenType == Security::AccessToken::TOKEN_SHELL) {
52         return true;
53     }
54     return IsSystemApp();
55 }
56 
MapMimeToAudioCodecFormat(const std::string & mime,AudioCodecFormat & codecFormat)57 int32_t MapMimeToAudioCodecFormat(const std::string &mime, AudioCodecFormat &codecFormat)
58 {
59     auto iter = g_mimeStrToCodecFormat.find(mime);
60     if (iter != g_mimeStrToCodecFormat.end()) {
61         codecFormat = static_cast<AudioCodecFormat>(iter->second);
62     }
63     return MSERR_INVALID_VAL;
64 }
65 
MapMimeToVideoCodecFormat(const std::string & mime,VideoCodecFormat & codecFormat)66 int32_t MapMimeToVideoCodecFormat(const std::string &mime, VideoCodecFormat &codecFormat)
67 {
68     auto iter = g_mimeStrToCodecFormat.find(mime);
69     if (iter != g_mimeStrToCodecFormat.end()) {
70         codecFormat = static_cast<VideoCodecFormat>(iter->second);
71     }
72     return MSERR_INVALID_VAL;
73 }
74 
MapExtensionNameToOutputFormat(const std::string & extension,OutputFormatType & type)75 int32_t MapExtensionNameToOutputFormat(const std::string &extension, OutputFormatType &type)
76 {
77     auto iter = g_extensionToOutputFormat.find(extension);
78     if (iter != g_extensionToOutputFormat.end()) {
79         type = iter->second;
80     }
81     return MSERR_INVALID_VAL;
82 }
83 } // namespace Media
84 } // namespace OHOS