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 16 #define MLOG_TAG "Mediatool" 17 18 #include "control_main.h" 19 #include "media_log.h" 20 #include <string> 21 #include <sstream> 22 #include <unistd.h> 23 #include <vector> 24 25 using namespace std; 26 using namespace OHOS; 27 using namespace OHOS::Media; 28 using namespace OHOS::Media::MediaTool; 29 30 constexpr int32_t SHELL_UID = 2000; 31 constexpr int32_t ROOT_UID = 0; 32 BuildCommandLine(std::vector<std::string> args)33static string BuildCommandLine(std::vector<std::string> args) 34 { 35 std::ostringstream commandLine; 36 for (size_t i = 0; i < args.size(); ++i) { 37 commandLine << args[i]; 38 if (i != args.size() - 1) { 39 commandLine << " "; 40 } 41 } 42 return commandLine.str(); 43 } 44 main(int argc,char * argv[])45int main(int argc, char *argv[]) 46 { 47 int32_t id = getuid(); 48 if (id != ROOT_UID && id != SHELL_UID) { 49 MEDIA_ERR_LOG("Invalid uid"); 50 return 0; 51 } 52 std::vector<std::string> args; 53 for (int i = 0; i < argc; i++) { 54 args.push_back(std::string(argv[i])); 55 } 56 57 MEDIA_INFO_LOG("mediatool main start: %{public}s", BuildCommandLine(args).c_str()); 58 59 return ControlMain::Main(args); 60 } 61 62