1 /* 2 * Copyright (c) 2020 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 "ability_main.h" 17 18 #include <cerrno> 19 #include <climits> 20 21 #include "ability_thread.h" 22 #include "ipc_skeleton_pri.h" 23 #include "log.h" 24 namespace { 25 constexpr int HEX = 10; 26 } 27 AbilityMain(const char * token)28int AbilityMain(const char *token) 29 { 30 if (token == nullptr) { 31 return -1; 32 } 33 ResetIpc(); 34 char *endPtr = nullptr; 35 errno = 0; 36 uint64_t tokenId = std::strtoull(token, &endPtr, HEX); 37 if ((errno == ERANGE && tokenId == ULLONG_MAX) || (errno != 0 && tokenId == 0) || 38 endPtr == nullptr || *endPtr != '\0') { 39 HILOG_ERROR(HILOG_MODULE_APP, "token is invalid"); 40 return -1; 41 } 42 43 OHOS::AbilityThread::ThreadMain(tokenId); 44 return 0; 45 } 46